blob: 9d7605f83b6c90fc4070391698eee131ca2f51ea [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;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000070import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070071import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070072import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080074import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080076import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080077import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080078
Andrew Lee312e8172014-10-23 17:01:36 -070079import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080080import com.android.ims.internal.IImsMMTelFeature;
81import com.android.ims.internal.IImsRcsFeature;
Brad Ebinger7e934f52017-12-14 14:26:15 -080082import com.android.ims.internal.IImsRegistration;
Brad Ebinger34bef922017-11-09 10:27:08 -080083import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070084import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070085import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070086import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070087import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080090import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010091import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070092import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070093import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080095import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070096import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070097import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070098import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070099import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700100import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800101import com.android.internal.telephony.SubscriptionController;
Jonathan Basseri03923952017-07-19 12:22:35 -0700102import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700103import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700104import com.android.internal.telephony.uicc.IccIoResult;
105import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800106import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700107import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800108import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700109import com.android.internal.telephony.uicc.UiccController;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000110import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700111import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800112import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700113import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800114import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700115import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700116import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800117
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700118import java.io.FileDescriptor;
119import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800122import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800123import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100124import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800125import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126
127/**
128 * Implementation of the ITelephony interface.
129 */
Santos Cordon117fee72014-05-16 17:56:12 -0700130public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131 private static final String LOG_TAG = "PhoneInterfaceManager";
132 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
133 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800134 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135
136 // Message codes used with mMainThreadHandler
137 private static final int CMD_HANDLE_PIN_MMI = 1;
138 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
139 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
140 private static final int CMD_ANSWER_RINGING_CALL = 4;
141 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700142 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
143 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700144 private static final int CMD_OPEN_CHANNEL = 9;
145 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
146 private static final int CMD_CLOSE_CHANNEL = 11;
147 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800148 private static final int CMD_NV_READ_ITEM = 13;
149 private static final int EVENT_NV_READ_ITEM_DONE = 14;
150 private static final int CMD_NV_WRITE_ITEM = 15;
151 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
152 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
153 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
154 private static final int CMD_NV_RESET_CONFIG = 19;
155 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800156 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
157 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
158 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
159 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800160 private static final int CMD_SEND_ENVELOPE = 25;
161 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700162 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
163 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
164 private static final int CMD_EXCHANGE_SIM_IO = 31;
165 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800166 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
167 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700168 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
169 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700170 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
171 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700172 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
173 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
174 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
175 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700176 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
177 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
178 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
179 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700180 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800181 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
182 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000183 private static final int CMD_SWITCH_SLOTS = 50;
184 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800186 // Parameters of select command.
187 private static final int SELECT_COMMAND = 0xA4;
188 private static final int SELECT_P1 = 0x04;
189 private static final int SELECT_P2 = 0;
190 private static final int SELECT_P3 = 0x10;
191
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 /** The singleton instance. */
193 private static PhoneInterfaceManager sInstance;
194
Wink Saville3ab207e2014-11-20 13:07:20 -0800195 private PhoneGlobals mApp;
196 private Phone mPhone;
197 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700198 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800199 private AppOpsManager mAppOps;
200 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800201 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800202 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700203
Derek Tan97ebb422014-09-05 16:55:38 -0700204 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
205 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800206 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700207
Derek Tan740e1672017-06-27 14:56:27 -0700208 // The AID of ISD-R.
209 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
210
yinxub1bed742017-04-17 11:45:04 -0700211 private NetworkScanRequestTracker mNetworkScanRequestTracker;
212
Derek Tan89e89d42014-07-08 17:00:10 -0700213 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700214 * A request object to use for transmitting data to an ICC.
215 */
216 private static final class IccAPDUArgument {
217 public int channel, cla, command, p1, p2, p3;
218 public String data;
219
220 public IccAPDUArgument(int channel, int cla, int command,
221 int p1, int p2, int p3, String data) {
222 this.channel = channel;
223 this.cla = cla;
224 this.command = command;
225 this.p1 = p1;
226 this.p2 = p2;
227 this.p3 = p3;
228 this.data = data;
229 }
230 }
231
232 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700233 * A request object to use for transmitting data to an ICC.
234 */
235 private static final class ManualNetworkSelectionArgument {
236 public OperatorInfo operatorInfo;
237 public boolean persistSelection;
238
239 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
240 this.operatorInfo = operatorInfo;
241 this.persistSelection = persistSelection;
242 }
243 }
244
245 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
247 * request after sending. The main thread will notify the request when it is complete.
248 */
249 private static final class MainThreadRequest {
250 /** The argument to use for the request */
251 public Object argument;
252 /** The result of the request that is run on the main thread */
253 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800254 // The subscriber id that this request applies to. Defaults to
255 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
256 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257
258 public MainThreadRequest(Object argument) {
259 this.argument = argument;
260 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800261
262 public MainThreadRequest(Object argument, Integer subId) {
263 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800264 if (subId != null) {
265 this.subId = subId;
266 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268 }
269
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800270 private static final class IncomingThirdPartyCallArgs {
271 public final ComponentName component;
272 public final String callId;
273 public final String callerDisplayName;
274
275 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
276 String callerDisplayName) {
277 this.component = component;
278 this.callId = callId;
279 this.callerDisplayName = callerDisplayName;
280 }
281 }
282
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700283 /**
284 * A handler that processes messages on the main thread in the phone process. Since many
285 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
286 * inbound binder threads to the main thread in the phone process. The Binder thread
287 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
288 * on, which will be notified when the operation completes and will contain the result of the
289 * request.
290 *
291 * <p>If a MainThreadRequest object is provided in the msg.obj field,
292 * note that request.result must be set to something non-null for the calling thread to
293 * unblock.
294 */
295 private final class MainThreadHandler extends Handler {
296 @Override
297 public void handleMessage(Message msg) {
298 MainThreadRequest request;
299 Message onCompleted;
300 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800301 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700302 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303
304 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700305 case CMD_HANDLE_USSD_REQUEST: {
306 request = (MainThreadRequest) msg.obj;
307 final Phone phone = getPhoneFromRequest(request);
308 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
309 String ussdRequest = ussdObject.first;
310 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700311
312 if (!isUssdApiAllowed(request.subId)) {
313 // Carrier does not support use of this API, return failure.
314 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
315 UssdResponse response = new UssdResponse(ussdRequest, null);
316 Bundle returnData = new Bundle();
317 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
318 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
319
320 request.result = true;
321 synchronized (request) {
322 request.notifyAll();
323 }
324 return;
325 }
326
Tyler Gunn52dcf772017-04-26 11:30:31 -0700327 try {
328 request.result = phone != null ?
329 phone.handleUssdRequest(ussdRequest, wrappedCallback)
330 : false;
331 } catch (CallStateException cse) {
332 request.result = false;
333 }
pkanwar32d516d2016-10-14 19:37:38 -0700334 // Wake up the requesting thread
335 synchronized (request) {
336 request.notifyAll();
337 }
338 break;
339 }
340
Yorke Lee716f67e2015-06-17 15:39:16 -0700341 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700343 final Phone phone = getPhoneFromRequest(request);
344 request.result = phone != null ?
345 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
346 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347 // Wake up the requesting thread
348 synchronized (request) {
349 request.notifyAll();
350 }
351 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353
354 case CMD_HANDLE_NEIGHBORING_CELL:
355 request = (MainThreadRequest) msg.obj;
356 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
357 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700358 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 break;
360
361 case EVENT_NEIGHBORING_CELL_DONE:
362 ar = (AsyncResult) msg.obj;
363 request = (MainThreadRequest) ar.userObj;
364 if (ar.exception == null && ar.result != null) {
365 request.result = ar.result;
366 } else {
367 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800368 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 }
370 // Wake up the requesting thread
371 synchronized (request) {
372 request.notifyAll();
373 }
374 break;
375
376 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700377 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800378 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700379 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380 break;
381
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 case CMD_END_CALL:
383 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800384 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700385 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700386 Phone phone = getPhone(end_subId);
387 if (phone == null) {
388 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
389 break;
390 }
391 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
393 // CDMA: If the user presses the Power button we treat it as
394 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700395 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
397 // GSM: End the call as per the Phone state
398 hungUp = PhoneUtils.hangup(mCM);
399 } else {
400 throw new IllegalStateException("Unexpected phone type: " + phoneType);
401 }
402 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
403 request.result = hungUp;
404 // Wake up the requesting thread
405 synchronized (request) {
406 request.notifyAll();
407 }
408 break;
409
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700410 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700411 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800413 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700414 if (uiccCard == null) {
415 loge("iccTransmitApduLogicalChannel: No UICC");
416 request.result = new IccIoResult(0x6F, 0, (byte[])null);
417 synchronized (request) {
418 request.notifyAll();
419 }
420 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700421 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
422 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700423 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700424 iccArgument.channel, iccArgument.cla, iccArgument.command,
425 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700426 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700427 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700428 break;
429
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700430 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 ar = (AsyncResult) msg.obj;
432 request = (MainThreadRequest) ar.userObj;
433 if (ar.exception == null && ar.result != null) {
434 request.result = ar.result;
435 } else {
436 request.result = new IccIoResult(0x6F, 0, (byte[])null);
437 if (ar.result == null) {
438 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800439 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700440 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800441 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 } else {
443 loge("iccTransmitApduLogicalChannel: Unknown exception");
444 }
445 }
446 synchronized (request) {
447 request.notifyAll();
448 }
449 break;
450
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
452 request = (MainThreadRequest) msg.obj;
453 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800454 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 if (uiccCard == null) {
456 loge("iccTransmitApduBasicChannel: No UICC");
457 request.result = new IccIoResult(0x6F, 0, (byte[])null);
458 synchronized (request) {
459 request.notifyAll();
460 }
461 } else {
462 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
463 request);
464 uiccCard.iccTransmitApduBasicChannel(
465 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
466 iccArgument.p3, iccArgument.data, onCompleted);
467 }
468 break;
469
470 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
471 ar = (AsyncResult) msg.obj;
472 request = (MainThreadRequest) ar.userObj;
473 if (ar.exception == null && ar.result != null) {
474 request.result = ar.result;
475 } else {
476 request.result = new IccIoResult(0x6F, 0, (byte[])null);
477 if (ar.result == null) {
478 loge("iccTransmitApduBasicChannel: Empty response");
479 } else if (ar.exception instanceof CommandException) {
480 loge("iccTransmitApduBasicChannel: CommandException: " +
481 ar.exception);
482 } else {
483 loge("iccTransmitApduBasicChannel: Unknown exception");
484 }
485 }
486 synchronized (request) {
487 request.notifyAll();
488 }
489 break;
490
491 case CMD_EXCHANGE_SIM_IO:
492 request = (MainThreadRequest) msg.obj;
493 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800494 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 if (uiccCard == null) {
496 loge("iccExchangeSimIO: No UICC");
497 request.result = new IccIoResult(0x6F, 0, (byte[])null);
498 synchronized (request) {
499 request.notifyAll();
500 }
501 } else {
502 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
503 request);
504 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
505 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
506 iccArgument.data, onCompleted);
507 }
508 break;
509
510 case EVENT_EXCHANGE_SIM_IO_DONE:
511 ar = (AsyncResult) msg.obj;
512 request = (MainThreadRequest) ar.userObj;
513 if (ar.exception == null && ar.result != null) {
514 request.result = ar.result;
515 } else {
516 request.result = new IccIoResult(0x6f, 0, (byte[])null);
517 }
518 synchronized (request) {
519 request.notifyAll();
520 }
521 break;
522
Derek Tan4d5e5c12014-02-04 11:54:58 -0800523 case CMD_SEND_ENVELOPE:
524 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800525 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700526 if (uiccCard == null) {
527 loge("sendEnvelopeWithStatus: No UICC");
528 request.result = new IccIoResult(0x6F, 0, (byte[])null);
529 synchronized (request) {
530 request.notifyAll();
531 }
532 } else {
533 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
534 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
535 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800536 break;
537
538 case EVENT_SEND_ENVELOPE_DONE:
539 ar = (AsyncResult) msg.obj;
540 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700541 if (ar.exception == null && ar.result != null) {
542 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800543 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700544 request.result = new IccIoResult(0x6F, 0, (byte[])null);
545 if (ar.result == null) {
546 loge("sendEnvelopeWithStatus: Empty response");
547 } else if (ar.exception instanceof CommandException) {
548 loge("sendEnvelopeWithStatus: CommandException: " +
549 ar.exception);
550 } else {
551 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
552 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800553 }
554 synchronized (request) {
555 request.notifyAll();
556 }
557 break;
558
Shishir Agrawal566b7612013-10-28 14:41:00 -0700559 case CMD_OPEN_CHANNEL:
560 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800561 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800562 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 if (uiccCard == null) {
564 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800565 request.result = new IccOpenLogicalChannelResponse(-1,
566 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700567 synchronized (request) {
568 request.notifyAll();
569 }
570 } else {
571 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800572 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
573 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700574 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 break;
576
577 case EVENT_OPEN_CHANNEL_DONE:
578 ar = (AsyncResult) msg.obj;
579 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700580 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 int[] result = (int[]) ar.result;
583 int channelId = result[0];
584 byte[] selectResponse = null;
585 if (result.length > 1) {
586 selectResponse = new byte[result.length - 1];
587 for (int i = 1; i < result.length; ++i) {
588 selectResponse[i - 1] = (byte) result[i];
589 }
590 }
591 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700592 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 if (ar.result == null) {
595 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 if (ar.exception != null) {
598 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
599 }
600
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700601 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700602 if (ar.exception instanceof CommandException) {
603 CommandException.Error error =
604 ((CommandException) (ar.exception)).getCommandError();
605 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700606 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700607 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700608 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 }
610 }
611 openChannelResp = new IccOpenLogicalChannelResponse(
612 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700614 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 synchronized (request) {
616 request.notifyAll();
617 }
618 break;
619
620 case CMD_CLOSE_CHANNEL:
621 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800622 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700623 if (uiccCard == null) {
624 loge("iccCloseLogicalChannel: No UICC");
625 request.result = new IccIoResult(0x6F, 0, (byte[])null);
626 synchronized (request) {
627 request.notifyAll();
628 }
629 } else {
630 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
631 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
632 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 break;
634
635 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800636 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
637 break;
638
639 case CMD_NV_READ_ITEM:
640 request = (MainThreadRequest) msg.obj;
641 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
642 mPhone.nvReadItem((Integer) request.argument, onCompleted);
643 break;
644
645 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 ar = (AsyncResult) msg.obj;
647 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800648 if (ar.exception == null && ar.result != null) {
649 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800651 request.result = "";
652 if (ar.result == null) {
653 loge("nvReadItem: Empty response");
654 } else if (ar.exception instanceof CommandException) {
655 loge("nvReadItem: CommandException: " +
656 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800658 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 }
660 }
661 synchronized (request) {
662 request.notifyAll();
663 }
664 break;
665
Jake Hambye994d462014-02-03 13:10:13 -0800666 case CMD_NV_WRITE_ITEM:
667 request = (MainThreadRequest) msg.obj;
668 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
669 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
670 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
671 break;
672
673 case EVENT_NV_WRITE_ITEM_DONE:
674 handleNullReturnEvent(msg, "nvWriteItem");
675 break;
676
677 case CMD_NV_WRITE_CDMA_PRL:
678 request = (MainThreadRequest) msg.obj;
679 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
680 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
681 break;
682
683 case EVENT_NV_WRITE_CDMA_PRL_DONE:
684 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
685 break;
686
687 case CMD_NV_RESET_CONFIG:
688 request = (MainThreadRequest) msg.obj;
689 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
690 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
691 break;
692
693 case EVENT_NV_RESET_CONFIG_DONE:
694 handleNullReturnEvent(msg, "nvResetConfig");
695 break;
696
Jake Hamby7c27be32014-03-03 13:25:59 -0800697 case CMD_GET_PREFERRED_NETWORK_TYPE:
698 request = (MainThreadRequest) msg.obj;
699 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700700 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800701 break;
702
703 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
706 if (ar.exception == null && ar.result != null) {
707 request.result = ar.result; // Integer
708 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800709 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800710 if (ar.result == null) {
711 loge("getPreferredNetworkType: Empty response");
712 } else if (ar.exception instanceof CommandException) {
713 loge("getPreferredNetworkType: CommandException: " +
714 ar.exception);
715 } else {
716 loge("getPreferredNetworkType: Unknown exception");
717 }
718 }
719 synchronized (request) {
720 request.notifyAll();
721 }
722 break;
723
724 case CMD_SET_PREFERRED_NETWORK_TYPE:
725 request = (MainThreadRequest) msg.obj;
726 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
727 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700728 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800729 break;
730
731 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
732 handleNullReturnEvent(msg, "setPreferredNetworkType");
733 break;
734
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800735 case CMD_SET_VOICEMAIL_NUMBER:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
738 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800739 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
740 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800741 break;
742
743 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
744 handleNullReturnEvent(msg, "setVoicemailNumber");
745 break;
746
Stuart Scott54788802015-03-30 13:18:01 -0700747 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
748 request = (MainThreadRequest) msg.obj;
749 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
750 request);
751 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
752 break;
753
754 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
755 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
756 break;
757
Shishir Agrawal302c8692015-06-19 13:49:39 -0700758 case CMD_PERFORM_NETWORK_SCAN:
759 request = (MainThreadRequest) msg.obj;
760 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
761 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
762 break;
763
764 case EVENT_PERFORM_NETWORK_SCAN_DONE:
765 ar = (AsyncResult) msg.obj;
766 request = (MainThreadRequest) ar.userObj;
767 CellNetworkScanResult cellScanResult;
768 if (ar.exception == null && ar.result != null) {
769 cellScanResult = new CellNetworkScanResult(
770 CellNetworkScanResult.STATUS_SUCCESS,
771 (List<OperatorInfo>) ar.result);
772 } else {
773 if (ar.result == null) {
774 loge("getCellNetworkScanResults: Empty response");
775 }
776 if (ar.exception != null) {
777 loge("getCellNetworkScanResults: Exception: " + ar.exception);
778 }
779 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
780 if (ar.exception instanceof CommandException) {
781 CommandException.Error error =
782 ((CommandException) (ar.exception)).getCommandError();
783 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
784 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
785 } else if (error == CommandException.Error.GENERIC_FAILURE) {
786 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
787 }
788 }
789 cellScanResult = new CellNetworkScanResult(errorCode, null);
790 }
791 request.result = cellScanResult;
792 synchronized (request) {
793 request.notifyAll();
794 }
795 break;
796
797 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
798 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700799 ManualNetworkSelectionArgument selArg =
800 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700801 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
802 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700803 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
804 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700805 break;
806
807 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
808 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
809 break;
810
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700811 case CMD_GET_MODEM_ACTIVITY_INFO:
812 request = (MainThreadRequest) msg.obj;
813 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700814 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700815 break;
816
817 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
818 ar = (AsyncResult) msg.obj;
819 request = (MainThreadRequest) ar.userObj;
820 if (ar.exception == null && ar.result != null) {
821 request.result = ar.result;
822 } else {
823 if (ar.result == null) {
824 loge("queryModemActivityInfo: Empty response");
825 } else if (ar.exception instanceof CommandException) {
826 loge("queryModemActivityInfo: CommandException: " +
827 ar.exception);
828 } else {
829 loge("queryModemActivityInfo: Unknown exception");
830 }
831 }
Amit Mahajand4766222016-01-28 15:28:28 -0800832 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
833 if (request.result == null) {
834 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
835 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700836 synchronized (request) {
837 request.notifyAll();
838 }
839 break;
840
Meng Wang1a7c35a2016-05-05 20:56:15 -0700841 case CMD_SET_ALLOWED_CARRIERS:
842 request = (MainThreadRequest) msg.obj;
843 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
844 mPhone.setAllowedCarriers(
845 (List<CarrierIdentifier>) request.argument,
846 onCompleted);
847 break;
848
849 case EVENT_SET_ALLOWED_CARRIERS_DONE:
850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null && ar.result != null) {
853 request.result = ar.result;
854 } else {
855 if (ar.result == null) {
856 loge("setAllowedCarriers: Empty response");
857 } else if (ar.exception instanceof CommandException) {
858 loge("setAllowedCarriers: CommandException: " +
859 ar.exception);
860 } else {
861 loge("setAllowedCarriers: Unknown exception");
862 }
863 }
864 // Result cannot be null. Return -1 on error.
865 if (request.result == null) {
866 request.result = new int[]{-1};
867 }
868 synchronized (request) {
869 request.notifyAll();
870 }
871 break;
872
873 case CMD_GET_ALLOWED_CARRIERS:
874 request = (MainThreadRequest) msg.obj;
875 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
876 mPhone.getAllowedCarriers(onCompleted);
877 break;
878
879 case EVENT_GET_ALLOWED_CARRIERS_DONE:
880 ar = (AsyncResult) msg.obj;
881 request = (MainThreadRequest) ar.userObj;
882 if (ar.exception == null && ar.result != null) {
883 request.result = ar.result;
884 } else {
885 if (ar.result == null) {
886 loge("getAllowedCarriers: Empty response");
887 } else if (ar.exception instanceof CommandException) {
888 loge("getAllowedCarriers: CommandException: " +
889 ar.exception);
890 } else {
891 loge("getAllowedCarriers: Unknown exception");
892 }
893 }
894 // Result cannot be null. Return empty list of CarrierIdentifier.
895 if (request.result == null) {
896 request.result = new ArrayList<CarrierIdentifier>(0);
897 }
898 synchronized (request) {
899 request.notifyAll();
900 }
901 break;
902
Nathan Haroldb3014052017-01-25 15:57:32 -0800903 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
904 ar = (AsyncResult) msg.obj;
905 request = (MainThreadRequest) ar.userObj;
906 if (ar.exception == null && ar.result != null) {
907 request.result = ar.result;
908 } else {
909 request.result = new IllegalArgumentException(
910 "Failed to retrieve Forbidden Plmns");
911 if (ar.result == null) {
912 loge("getForbiddenPlmns: Empty response");
913 } else {
914 loge("getForbiddenPlmns: Unknown exception");
915 }
916 }
917 synchronized (request) {
918 request.notifyAll();
919 }
920 break;
921
922 case CMD_GET_FORBIDDEN_PLMNS:
923 request = (MainThreadRequest) msg.obj;
924 uiccCard = getUiccCardFromRequest(request);
925 if (uiccCard == null) {
926 loge("getForbiddenPlmns() UiccCard is null");
927 request.result = new IllegalArgumentException(
928 "getForbiddenPlmns() UiccCard is null");
929 synchronized (request) {
930 request.notifyAll();
931 }
932 break;
933 }
934 Integer appType = (Integer) request.argument;
935 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
936 if (uiccApp == null) {
937 loge("getForbiddenPlmns() no app with specified type -- "
938 + appType);
939 request.result = new IllegalArgumentException("Failed to get UICC App");
940 synchronized (request) {
941 request.notifyAll();
942 }
943 break;
944 } else {
945 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
946 + " specified type -- " + appType);
947 }
948 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
949 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
950 onCompleted);
951 break;
952
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000953 case CMD_SWITCH_SLOTS:
954 request = (MainThreadRequest) msg.obj;
955 int[] physicalSlots = (int[]) request.argument;
956 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
957 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
958 break;
959
960 case EVENT_SWITCH_SLOTS_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 request.result = (ar.exception == null);
964 synchronized (request) {
965 request.notifyAll();
966 }
967 break;
968
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700969 default:
970 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
971 break;
972 }
973 }
Jake Hambye994d462014-02-03 13:10:13 -0800974
975 private void handleNullReturnEvent(Message msg, String command) {
976 AsyncResult ar = (AsyncResult) msg.obj;
977 MainThreadRequest request = (MainThreadRequest) ar.userObj;
978 if (ar.exception == null) {
979 request.result = true;
980 } else {
981 request.result = false;
982 if (ar.exception instanceof CommandException) {
983 loge(command + ": CommandException: " + ar.exception);
984 } else {
985 loge(command + ": Unknown exception");
986 }
987 }
988 synchronized (request) {
989 request.notifyAll();
990 }
991 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700992 }
993
994 /**
995 * Posts the specified command to be executed on the main thread,
996 * waits for the request to complete, and returns the result.
997 * @see #sendRequestAsync
998 */
999 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001000 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001001 }
1002
1003 /**
1004 * Posts the specified command to be executed on the main thread,
1005 * waits for the request to complete, and returns the result.
1006 * @see #sendRequestAsync
1007 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001008 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001009 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1010 throw new RuntimeException("This method will deadlock if called from the main thread.");
1011 }
1012
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001013 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001014 Message msg = mMainThreadHandler.obtainMessage(command, request);
1015 msg.sendToTarget();
1016
1017 // Wait for the request to complete
1018 synchronized (request) {
1019 while (request.result == null) {
1020 try {
1021 request.wait();
1022 } catch (InterruptedException e) {
1023 // Do nothing, go back and wait until the request is complete
1024 }
1025 }
1026 }
1027 return request.result;
1028 }
1029
1030 /**
1031 * Asynchronous ("fire and forget") version of sendRequest():
1032 * Posts the specified command to be executed on the main thread, and
1033 * returns immediately.
1034 * @see #sendRequest
1035 */
1036 private void sendRequestAsync(int command) {
1037 mMainThreadHandler.sendEmptyMessage(command);
1038 }
1039
1040 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001041 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1042 * @see {@link #sendRequest(int,Object)}
1043 */
1044 private void sendRequestAsync(int command, Object argument) {
1045 MainThreadRequest request = new MainThreadRequest(argument);
1046 Message msg = mMainThreadHandler.obtainMessage(command, request);
1047 msg.sendToTarget();
1048 }
1049
1050 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001051 * Initialize the singleton PhoneInterfaceManager instance.
1052 * This is only done once, at startup, from PhoneApp.onCreate().
1053 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001054 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001055 synchronized (PhoneInterfaceManager.class) {
1056 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001057 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001058 } else {
1059 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1060 }
1061 return sInstance;
1062 }
1063 }
1064
1065 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001066 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001067 mApp = app;
1068 mPhone = phone;
1069 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001070 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001071 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1072 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001073 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001074 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001075 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001076 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001077
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001078 publish();
1079 }
1080
1081 private void publish() {
1082 if (DBG) log("publish: " + this);
1083
1084 ServiceManager.addService("phone", this);
1085 }
1086
Stuart Scott584921c2015-01-15 17:10:34 -08001087 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001088 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1089 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001090 }
1091
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001092 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1093 Phone phone = getPhoneFromRequest(request);
1094 return phone == null ? null :
1095 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1096 }
1097
Wink Saville36469e72014-06-11 15:17:00 -07001098 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001099 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001100 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001101 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001102 //
1103 // Implementation of the ITelephony interface.
1104 //
1105
1106 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001107 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001108 }
1109
Wink Savilleb564aae2014-10-23 10:18:09 -07001110 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001111 if (DBG) log("dial: " + number);
1112 // No permission check needed here: This is just a wrapper around the
1113 // ACTION_DIAL intent, which is available to any app since it puts up
1114 // the UI before it does anything.
1115
1116 String url = createTelUrl(number);
1117 if (url == null) {
1118 return;
1119 }
1120
1121 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001122 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001123 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1124 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1125 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1126 mApp.startActivity(intent);
1127 }
1128 }
1129
1130 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001131 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001132 }
1133
Wink Savilleb564aae2014-10-23 10:18:09 -07001134 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001135 if (DBG) log("call: " + number);
1136
1137 // This is just a wrapper around the ACTION_CALL intent, but we still
1138 // need to do a permission check since we're calling startActivity()
1139 // from the context of the phone app.
1140 enforceCallPermission();
1141
1142 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1143 != AppOpsManager.MODE_ALLOWED) {
1144 return;
1145 }
1146
1147 String url = createTelUrl(number);
1148 if (url == null) {
1149 return;
1150 }
1151
Wink Saville08874612014-08-31 19:19:58 -07001152 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001153 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001154 if (slist != null) {
1155 for (SubscriptionInfo subInfoRecord : slist) {
1156 if (subInfoRecord.getSubscriptionId() == subId) {
1157 isValid = true;
1158 break;
1159 }
Wink Saville08874612014-08-31 19:19:58 -07001160 }
1161 }
1162 if (isValid == false) {
1163 return;
1164 }
1165
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001166 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001167 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001168 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1169 mApp.startActivity(intent);
1170 }
1171
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001172 /**
1173 * End a call based on call state
1174 * @return true is a call was ended
1175 */
1176 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001177 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001178 }
1179
1180 /**
1181 * End a call based on the call state of the subId
1182 * @return true is a call was ended
1183 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001184 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001185 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001186 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001187 }
1188
1189 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001190 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001191 }
1192
Wink Savilleb564aae2014-10-23 10:18:09 -07001193 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001194 if (DBG) log("answerRingingCall...");
1195 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1196 // but that can probably wait till the big TelephonyManager API overhaul.
1197 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1198 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001199 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001200 }
1201
1202 /**
1203 * Make the actual telephony calls to implement answerRingingCall().
1204 * This should only be called from the main thread of the Phone app.
1205 * @see #answerRingingCall
1206 *
1207 * TODO: it would be nice to return true if we answered the call, or
1208 * false if there wasn't actually a ringing incoming call, or some
1209 * other error occurred. (In other words, pass back the return value
1210 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1211 * But that would require calling this method via sendRequest() rather
1212 * than sendRequestAsync(), and right now we don't actually *need* that
1213 * return value, so let's just return void for now.
1214 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001215 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001216 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001217 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001218 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1219 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001220 if (hasActiveCall && hasHoldingCall) {
1221 // Both lines are in use!
1222 // TODO: provide a flag to let the caller specify what
1223 // policy to use if both lines are in use. (The current
1224 // behavior is hardwired to "answer incoming, end ongoing",
1225 // which is how the CALL button is specced to behave.)
1226 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1227 return;
1228 } else {
1229 // answerCall() will automatically hold the current active
1230 // call, if there is one.
1231 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1232 return;
1233 }
1234 } else {
1235 // No call was ringing.
1236 return;
1237 }
1238 }
1239
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001240 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001241 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001242 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001243 public void silenceRinger() {
1244 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 }
1246
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001247 @Override
1248 public boolean isOffhook(String callingPackage) {
1249 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001250 }
1251
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001252 @Override
1253 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1254 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1255 return false;
1256 }
1257
Sanket Padawe356d7632015-06-22 14:03:32 -07001258 final Phone phone = getPhone(subId);
1259 if (phone != null) {
1260 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1261 } else {
1262 return false;
1263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 }
1265
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001266 @Override
1267 public boolean isRinging(String callingPackage) {
1268 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001269 }
1270
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001271 @Override
1272 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1273 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1274 return false;
1275 }
1276
Sanket Padawe356d7632015-06-22 14:03:32 -07001277 final Phone phone = getPhone(subId);
1278 if (phone != null) {
1279 return (phone.getState() == PhoneConstants.State.RINGING);
1280 } else {
1281 return false;
1282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 }
1284
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001285 @Override
1286 public boolean isIdle(String callingPackage) {
1287 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001288 }
1289
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001290 @Override
1291 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1292 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1293 return false;
1294 }
1295
Sanket Padawe356d7632015-06-22 14:03:32 -07001296 final Phone phone = getPhone(subId);
1297 if (phone != null) {
1298 return (phone.getState() == PhoneConstants.State.IDLE);
1299 } else {
1300 return false;
1301 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001302 }
1303
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001305 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001306 }
1307
Wink Savilleb564aae2014-10-23 10:18:09 -07001308 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001309 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001310 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1311 }
1312
1313 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001314 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001315 }
1316
Wink Savilleb564aae2014-10-23 10:18:09 -07001317 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001318 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001319 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1320 }
1321
1322 /** {@hide} */
1323 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001324 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001325 }
1326
Wink Savilleb564aae2014-10-23 10:18:09 -07001327 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001329 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330 checkSimPin.start();
1331 return checkSimPin.unlockSim(null, pin);
1332 }
1333
Wink Saville9de0f752013-10-22 19:04:03 -07001334 /** {@hide} */
1335 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001336 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001337 }
1338
Wink Savilleb564aae2014-10-23 10:18:09 -07001339 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001340 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001341 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 checkSimPuk.start();
1343 return checkSimPuk.unlockSim(puk, pin);
1344 }
1345
1346 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001347 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001348 * a synchronous one.
1349 */
1350 private static class UnlockSim extends Thread {
1351
1352 private final IccCard mSimCard;
1353
1354 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001355 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1356 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001357
1358 // For replies from SimCard interface
1359 private Handler mHandler;
1360
1361 // For async handler to identify request type
1362 private static final int SUPPLY_PIN_COMPLETE = 100;
1363
1364 public UnlockSim(IccCard simCard) {
1365 mSimCard = simCard;
1366 }
1367
1368 @Override
1369 public void run() {
1370 Looper.prepare();
1371 synchronized (UnlockSim.this) {
1372 mHandler = new Handler() {
1373 @Override
1374 public void handleMessage(Message msg) {
1375 AsyncResult ar = (AsyncResult) msg.obj;
1376 switch (msg.what) {
1377 case SUPPLY_PIN_COMPLETE:
1378 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1379 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001380 mRetryCount = msg.arg1;
1381 if (ar.exception != null) {
1382 if (ar.exception instanceof CommandException &&
1383 ((CommandException)(ar.exception)).getCommandError()
1384 == CommandException.Error.PASSWORD_INCORRECT) {
1385 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1386 } else {
1387 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1388 }
1389 } else {
1390 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1391 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 mDone = true;
1393 UnlockSim.this.notifyAll();
1394 }
1395 break;
1396 }
1397 }
1398 };
1399 UnlockSim.this.notifyAll();
1400 }
1401 Looper.loop();
1402 }
1403
1404 /*
1405 * Use PIN or PUK to unlock SIM card
1406 *
1407 * If PUK is null, unlock SIM card with PIN
1408 *
1409 * If PUK is not null, unlock SIM card with PUK and set PIN code
1410 */
Wink Saville9de0f752013-10-22 19:04:03 -07001411 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412
1413 while (mHandler == null) {
1414 try {
1415 wait();
1416 } catch (InterruptedException e) {
1417 Thread.currentThread().interrupt();
1418 }
1419 }
1420 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1421
1422 if (puk == null) {
1423 mSimCard.supplyPin(pin, callback);
1424 } else {
1425 mSimCard.supplyPuk(puk, pin, callback);
1426 }
1427
1428 while (!mDone) {
1429 try {
1430 Log.d(LOG_TAG, "wait for done");
1431 wait();
1432 } catch (InterruptedException e) {
1433 // Restore the interrupted status
1434 Thread.currentThread().interrupt();
1435 }
1436 }
1437 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001438 int[] resultArray = new int[2];
1439 resultArray[0] = mResult;
1440 resultArray[1] = mRetryCount;
1441 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442 }
1443 }
1444
1445 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001446 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001447
1448 }
1449
Wink Savilleb564aae2014-10-23 10:18:09 -07001450 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 // No permission check needed here: this call is harmless, and it's
1452 // needed for the ServiceState.requestStateUpdate() call (which is
1453 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001454 final Phone phone = getPhone(subId);
1455 if (phone != null) {
1456 phone.updateServiceLocation();
1457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458 }
1459
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001460 @Override
1461 public boolean isRadioOn(String callingPackage) {
1462 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001463 }
1464
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001465 @Override
1466 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1467 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1468 return false;
1469 }
1470 return isRadioOnForSubscriber(subId);
1471 }
1472
1473 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001474 final Phone phone = getPhone(subId);
1475 if (phone != null) {
1476 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1477 } else {
1478 return false;
1479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001480 }
1481
1482 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001483 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001484
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001485 }
Wink Saville36469e72014-06-11 15:17:00 -07001486
Wink Savilleb564aae2014-10-23 10:18:09 -07001487 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001489 final Phone phone = getPhone(subId);
1490 if (phone != null) {
1491 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1492 }
Wink Saville36469e72014-06-11 15:17:00 -07001493 }
1494
1495 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001496 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001497 }
1498
Wink Savilleb564aae2014-10-23 10:18:09 -07001499 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001500 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001501 final Phone phone = getPhone(subId);
1502 if (phone == null) {
1503 return false;
1504 }
1505 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001506 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001507 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001508 }
1509 return true;
1510 }
Wink Saville36469e72014-06-11 15:17:00 -07001511
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001512 public boolean needMobileRadioShutdown() {
1513 /*
1514 * If any of the Radios are available, it will need to be
1515 * shutdown. So return true if any Radio is available.
1516 */
1517 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1518 Phone phone = PhoneFactory.getPhone(i);
1519 if (phone != null && phone.isRadioAvailable()) return true;
1520 }
1521 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1522 return false;
1523 }
1524
1525 public void shutdownMobileRadios() {
1526 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1527 logv("Shutting down Phone " + i);
1528 shutdownRadioUsingPhoneId(i);
1529 }
1530 }
1531
1532 private void shutdownRadioUsingPhoneId(int phoneId) {
1533 enforceModifyPermission();
1534 Phone phone = PhoneFactory.getPhone(phoneId);
1535 if (phone != null && phone.isRadioAvailable()) {
1536 phone.shutdownRadio();
1537 }
1538 }
1539
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001540 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001541 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001542 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1543 if (defaultPhone != null) {
1544 defaultPhone.setRadioPower(turnOn);
1545 return true;
1546 } else {
1547 loge("There's no default phone.");
1548 return false;
1549 }
Wink Saville36469e72014-06-11 15:17:00 -07001550 }
1551
Wink Savilleb564aae2014-10-23 10:18:09 -07001552 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001554 final Phone phone = getPhone(subId);
1555 if (phone != null) {
1556 phone.setRadioPower(turnOn);
1557 return true;
1558 } else {
1559 return false;
1560 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001561 }
1562
Wink Saville36469e72014-06-11 15:17:00 -07001563 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001564 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 public boolean enableDataConnectivity() {
1566 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001567 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001568 final Phone phone = getPhone(subId);
1569 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001570 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001571 return true;
1572 } else {
1573 return false;
1574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001575 }
1576
Wink Saville36469e72014-06-11 15:17:00 -07001577 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001578 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 public boolean disableDataConnectivity() {
1580 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001581 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001582 final Phone phone = getPhone(subId);
1583 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001584 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001585 return true;
1586 } else {
1587 return false;
1588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 }
1590
Sanket Padawe356d7632015-06-22 14:03:32 -07001591 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001592 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001593 final Phone phone = getPhone(subId);
1594 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001595 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001596 } else {
1597 return false;
1598 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 }
1600
1601 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001602 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001603 }
1604
pkanwarae03a6b2016-11-06 20:37:09 -08001605 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001606 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001607 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1608 return;
1609 }
1610 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1611 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1612 };
1613
Wink Savilleb564aae2014-10-23 10:18:09 -07001614 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001616 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1617 return false;
1618 }
Wink Saville36469e72014-06-11 15:17:00 -07001619 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 }
1621
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001623 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001624 }
1625
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001626 public int getCallStateForSlot(int slotIndex) {
1627 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001628 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001629 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 }
1631
Sanket Padawe356d7632015-06-22 14:03:32 -07001632 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001633 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001634 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001635 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001636 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001637 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001638 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001640 }
1641
Sanket Padawe356d7632015-06-22 14:03:32 -07001642 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001644 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001645 if (phone != null) {
1646 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1647 } else {
1648 return TelephonyManager.DATA_ACTIVITY_NONE;
1649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650 }
1651
1652 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001653 public Bundle getCellLocation(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001654 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001655 callingPackage, Binder.getCallingUid(), "getCellLocation")) {
Svetoslav64fad262015-04-14 14:35:21 -07001656 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 }
1658
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001659 if (DBG_LOC) log("getCellLocation: is active user");
1660 Bundle data = new Bundle();
1661 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1662 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001663 return null;
1664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001666 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1667 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1668 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001669 }
1670
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001672 public String getNetworkCountryIsoForPhone(int phoneId) {
1673 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1674 // registered cell info, so return a NULL country instead.
1675 final long identity = Binder.clearCallingIdentity();
1676 try {
1677 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1678 if (TelephonyManager.NETWORK_TYPE_IWLAN
1679 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1680 return "";
1681 }
1682 } finally {
1683 Binder.restoreCallingIdentity(identity);
1684 }
1685 return TelephonyManager.getTelephonyProperty(
1686 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1687 }
1688
1689 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001691 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001692 }
1693
Sanket Padawe356d7632015-06-22 14:03:32 -07001694 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001695 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001696 mApp.enforceCallingOrSelfPermission(
1697 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001698 final Phone phone = getPhone(subId);
1699 if (phone != null) {
1700 phone.enableLocationUpdates();
1701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 }
1703
1704 @Override
1705 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001706 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001707 }
1708
Sanket Padawe356d7632015-06-22 14:03:32 -07001709 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001710 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 mApp.enforceCallingOrSelfPermission(
1712 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001713 final Phone phone = getPhone(subId);
1714 if (phone != null) {
1715 phone.disableLocationUpdates();
1716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717 }
1718
1719 @Override
1720 @SuppressWarnings("unchecked")
1721 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001722 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001723 callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001724 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
1727 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1728 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1729 return null;
1730 }
Svetoslav64fad262015-04-14 14:35:21 -07001731
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001732 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001734 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001736 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1737 try {
1738 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1739 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1740 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1741 } catch (RuntimeException e) {
1742 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001744 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
1746
1747
1748 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001749 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001750 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001751 callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001752 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753 }
1754
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001755 if (DBG_LOC) log("getAllCellInfo: is active user");
1756 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1757 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1758 for (Phone phone : PhoneFactory.getPhones()) {
1759 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1760 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001762 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001763 }
1764
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001765 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001767 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001768 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1769 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
1771
Shishir Agrawala9f32182016-04-12 12:00:16 -07001772 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001773 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001774 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1775 return null;
1776 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001777 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001778 return phone == null ? null : phone.getImei();
1779 }
1780
1781 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001782 public String getMeidForSlot(int slotIndex, String callingPackage) {
1783 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1784 return null;
1785 }
1786 Phone phone = PhoneFactory.getPhone(slotIndex);
1787 return phone == null ? null : phone.getMeid();
1788 }
1789
1790 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001791 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001792 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1793 return null;
1794 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001795 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001796 return phone == null ? null : phone.getDeviceSvn();
1797 }
1798
fionaxuf32acdf2017-11-27 22:51:16 -08001799 @Override
1800 public int getSubscriptionCarrierId(int subId) {
1801 final Phone phone = getPhone(subId);
1802 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1803 }
1804
1805 @Override
1806 public String getSubscriptionCarrierName(int subId) {
1807 final Phone phone = getPhone(subId);
1808 return phone == null ? null : phone.getCarrierName();
1809 }
1810
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 //
1812 // Internal helper methods.
1813 //
1814
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001815 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1817 *
1818 * @throws SecurityException if the caller does not have the required permission
1819 */
1820 private void enforceModifyPermission() {
1821 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1822 }
1823
1824 /**
Junda Liua2e36012014-07-09 18:30:01 -07001825 * Make sure either system app or the caller has carrier privilege.
1826 *
1827 * @throws SecurityException if the caller does not have the required permission/privilege
1828 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001829 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001830 int permission = mApp.checkCallingOrSelfPermission(
1831 android.Manifest.permission.MODIFY_PHONE_STATE);
1832 if (permission == PackageManager.PERMISSION_GRANTED) {
1833 return;
1834 }
1835
1836 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001837 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001838 }
1839
1840 /**
1841 * Make sure the caller has carrier privilege.
1842 *
1843 * @throws SecurityException if the caller does not have the required permission
1844 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001845 private void enforceCarrierPrivilege(int subId) {
1846 if (getCarrierPrivilegeStatus(subId) !=
1847 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001848 loge("No Carrier Privilege.");
1849 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001850 }
1851 }
1852
1853 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 * Make sure the caller has the CALL_PHONE permission.
1855 *
1856 * @throws SecurityException if the caller does not have the required permission
1857 */
1858 private void enforceCallPermission() {
1859 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1860 }
1861
Stuart Scott8eef64f2015-04-08 15:13:54 -07001862 private void enforceConnectivityInternalPermission() {
1863 mApp.enforceCallingOrSelfPermission(
1864 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1865 "ConnectivityService");
1866 }
1867
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 private String createTelUrl(String number) {
1869 if (TextUtils.isEmpty(number)) {
1870 return null;
1871 }
1872
Jake Hambye994d462014-02-03 13:10:13 -08001873 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 }
1875
Ihab Awadf9e92732013-12-05 18:02:52 -08001876 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1878 }
1879
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001880 private static void logv(String msg) {
1881 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1882 }
1883
Ihab Awadf9e92732013-12-05 18:02:52 -08001884 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1886 }
1887
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001888 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001890 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001891 }
1892
Sanket Padawe356d7632015-06-22 14:03:32 -07001893 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001894 public int getActivePhoneTypeForSlot(int slotIndex) {
1895 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001896 if (phone == null) {
1897 return PhoneConstants.PHONE_TYPE_NONE;
1898 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001899 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001900 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901 }
1902
1903 /**
1904 * Returns the CDMA ERI icon index to display
1905 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001906 @Override
1907 public int getCdmaEriIconIndex(String callingPackage) {
1908 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001909 }
1910
Sanket Padawe356d7632015-06-22 14:03:32 -07001911 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001912 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1913 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1914 return -1;
1915 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001916 final Phone phone = getPhone(subId);
1917 if (phone != null) {
1918 return phone.getCdmaEriIconIndex();
1919 } else {
1920 return -1;
1921 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 }
1923
1924 /**
1925 * Returns the CDMA ERI icon mode,
1926 * 0 - ON
1927 * 1 - FLASHING
1928 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001929 @Override
1930 public int getCdmaEriIconMode(String callingPackage) {
1931 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001932 }
1933
Sanket Padawe356d7632015-06-22 14:03:32 -07001934 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001935 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1936 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1937 return -1;
1938 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001939 final Phone phone = getPhone(subId);
1940 if (phone != null) {
1941 return phone.getCdmaEriIconMode();
1942 } else {
1943 return -1;
1944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 }
1946
1947 /**
1948 * Returns the CDMA ERI text,
1949 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001950 @Override
1951 public String getCdmaEriText(String callingPackage) {
1952 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001953 }
1954
Sanket Padawe356d7632015-06-22 14:03:32 -07001955 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001956 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1957 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1958 return null;
1959 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001960 final Phone phone = getPhone(subId);
1961 if (phone != null) {
1962 return phone.getCdmaEriText();
1963 } else {
1964 return null;
1965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 }
1967
1968 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001969 * Returns the CDMA MDN.
1970 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001971 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001972 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001973 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001974 final Phone phone = getPhone(subId);
1975 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1976 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001977 } else {
1978 return null;
1979 }
1980 }
1981
1982 /**
1983 * Returns the CDMA MIN.
1984 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001985 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001986 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001987 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001988 final Phone phone = getPhone(subId);
1989 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1990 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001991 } else {
1992 return null;
1993 }
1994 }
1995
1996 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 * Returns true if CDMA provisioning needs to run.
1998 */
1999 public boolean needsOtaServiceProvisioning() {
2000 return mPhone.needsOtaServiceProvisioning();
2001 }
2002
2003 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002004 * Sets the voice mail number of a given subId.
2005 */
2006 @Override
2007 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002008 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002009 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2010 new Pair<String, String>(alphaTag, number), new Integer(subId));
2011 return success;
2012 }
2013
Ta-wei Yen87c49842016-05-13 21:19:52 -07002014 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002015 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2016 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2017 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2018 if (!TextUtils.equals(callingPackage, systemDialer)) {
2019 throw new SecurityException("caller must be system dialer");
2020 }
2021 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2022 if (phoneAccountHandle == null){
2023 return null;
2024 }
2025 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2026 }
2027
2028 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002029 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2031 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2032 return null;
2033 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002034 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2035 }
2036
2037 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002038 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2039 VisualVoicemailSmsFilterSettings settings) {
2040 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002041 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002042 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2043 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002044 }
2045
2046 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002047 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2048 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002049 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002050 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002051 }
2052
2053 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002054 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2055 String callingPackage, int subId) {
2056 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002057 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002058 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002059 }
2060
2061 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002062 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002063 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002064 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002065 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2066 }
2067
2068 @Override
2069 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2070 String number, int port, String text, PendingIntent sentIntent) {
2071 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002072 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002073 enforceSendSmsPermission();
2074 // Make the calls as the phone process.
2075 final long identity = Binder.clearCallingIdentity();
2076 try {
2077 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2078 if (port == 0) {
2079 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2080 sentIntent, null, false);
2081 } else {
2082 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2083 smsManager.sendDataMessageWithSelfPermissions(number, null,
2084 (short) port, data, sentIntent, null);
2085 }
2086 } finally {
2087 Binder.restoreCallingIdentity(identity);
2088 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002089 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002090 /**
fionaxu0152e512016-11-14 13:36:14 -08002091 * Sets the voice activation state of a given subId.
2092 */
2093 @Override
2094 public void setVoiceActivationState(int subId, int activationState) {
2095 enforceModifyPermissionOrCarrierPrivilege(subId);
2096 final Phone phone = getPhone(subId);
2097 if (phone != null) {
2098 phone.setVoiceActivationState(activationState);
2099 } else {
2100 loge("setVoiceActivationState fails with invalid subId: " + subId);
2101 }
2102 }
2103
2104 /**
2105 * Sets the data activation state of a given subId.
2106 */
2107 @Override
2108 public void setDataActivationState(int subId, int activationState) {
2109 enforceModifyPermissionOrCarrierPrivilege(subId);
2110 final Phone phone = getPhone(subId);
2111 if (phone != null) {
2112 phone.setDataActivationState(activationState);
2113 } else {
2114 loge("setVoiceActivationState fails with invalid subId: " + subId);
2115 }
2116 }
2117
2118 /**
2119 * Returns the voice activation state of a given subId.
2120 */
2121 @Override
2122 public int getVoiceActivationState(int subId, String callingPackage) {
2123 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2124 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2125 }
2126 final Phone phone = getPhone(subId);
2127 if (phone != null) {
2128 return phone.getVoiceActivationState();
2129 } else {
2130 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2131 }
2132 }
2133
2134 /**
2135 * Returns the data activation state of a given subId.
2136 */
2137 @Override
2138 public int getDataActivationState(int subId, String callingPackage) {
2139 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2140 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2141 }
2142 final Phone phone = getPhone(subId);
2143 if (phone != null) {
2144 return phone.getDataActivationState();
2145 } else {
2146 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2147 }
2148 }
2149
2150 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 * Returns the unread count of voicemails
2152 */
2153 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002154 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002155 }
2156
2157 /**
2158 * Returns the unread count of voicemails for a subId
2159 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002160 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002161 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002162 final Phone phone = getPhone(subId);
2163 if (phone != null) {
2164 return phone.getVoiceMessageCount();
2165 } else {
2166 return 0;
2167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
2170 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002171 * returns true, if the device is in a state where both voice and data
2172 * are supported simultaneously. This can change based on location or network condition.
2173 */
2174 @Override
2175 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2176 final Phone phone = getPhone(subId);
2177 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2178 }
2179
2180 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002181 * Send the dialer code if called from the current default dialer or the caller has
2182 * carrier privilege.
2183 * @param inputCode The dialer code to send
2184 */
2185 @Override
2186 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2187 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2188 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2189 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2190 enforceCarrierPrivilege(getDefaultSubscription());
2191 }
2192 mPhone.sendDialerSpecialCode(inputCode);
2193 }
2194
2195 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002196 * Returns the data network type.
2197 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 *
2199 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2200 */
2201 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002202 public int getNetworkType() {
2203 final Phone phone = getPhone(getDefaultSubscription());
2204 if (phone != null) {
2205 return phone.getServiceState().getDataNetworkType();
2206 } else {
2207 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2208 }
Wink Saville36469e72014-06-11 15:17:00 -07002209 }
2210
2211 /**
2212 * Returns the network type for a subId
2213 */
2214 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002215 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2216 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2217 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2218 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002219
Sanket Padawe356d7632015-06-22 14:03:32 -07002220 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002221 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002222 return phone.getServiceState().getDataNetworkType();
2223 } else {
2224 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2225 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002226 }
2227
2228 /**
2229 * Returns the data network type
2230 */
2231 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002232 public int getDataNetworkType(String callingPackage) {
2233 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002234 }
2235
2236 /**
2237 * Returns the data network type for a subId
2238 */
2239 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002240 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2241 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2242 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2243 }
2244
Sanket Padawe356d7632015-06-22 14:03:32 -07002245 final Phone phone = getPhone(subId);
2246 if (phone != null) {
2247 return phone.getServiceState().getDataNetworkType();
2248 } else {
2249 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 }
2252
2253 /**
Wink Saville36469e72014-06-11 15:17:00 -07002254 * Returns the Voice network type for a subId
2255 */
2256 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002257 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2258 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2259 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2260 }
2261
Sanket Padawe356d7632015-06-22 14:03:32 -07002262 final Phone phone = getPhone(subId);
2263 if (phone != null) {
2264 return phone.getServiceState().getVoiceNetworkType();
2265 } else {
2266 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 }
2269
2270 /**
2271 * @return true if a ICC card is present
2272 */
2273 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002274 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002275 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2276 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002277 }
2278
2279 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002280 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002281 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002282 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002283 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2284 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002285 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002286 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002287 } else {
2288 return false;
2289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290 }
2291
2292 /**
2293 * Return if the current radio is LTE on CDMA. This
2294 * is a tri-state return value as for a period of time
2295 * the mode may be unknown.
2296 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002297 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002299 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002301 @Override
2302 public int getLteOnCdmaMode(String callingPackage) {
2303 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002304 }
2305
Sanket Padawe356d7632015-06-22 14:03:32 -07002306 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002307 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2308 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2309 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2310 }
2311
Sanket Padawe356d7632015-06-22 14:03:32 -07002312 final Phone phone = getPhone(subId);
2313 if (phone == null) {
2314 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2315 } else {
2316 return phone.getLteOnCdmaMode();
2317 }
Wink Saville36469e72014-06-11 15:17:00 -07002318 }
2319
2320 public void setPhone(Phone phone) {
2321 mPhone = phone;
2322 }
2323
2324 /**
2325 * {@hide}
2326 * Returns Default subId, 0 in the case of single standby.
2327 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002328 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002329 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002330 }
2331
Shishir Agrawala9f32182016-04-12 12:00:16 -07002332 private int getSlotForDefaultSubscription() {
2333 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2334 }
2335
Wink Savilleb564aae2014-10-23 10:18:09 -07002336 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002337 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002338 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002339
2340 /**
2341 * @see android.telephony.TelephonyManager.WifiCallingChoices
2342 */
2343 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002344 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2345 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002346 }
2347
2348 /**
2349 * @see android.telephony.TelephonyManager.WifiCallingChoices
2350 */
2351 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002352 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2353 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2354 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002355 }
2356
Sailesh Nepald1e68152013-12-12 19:08:02 -08002357 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002358 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002359 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002360 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002361
Shishir Agrawal566b7612013-10-28 14:41:00 -07002362 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002363 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2364 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002365 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002366
Derek Tan740e1672017-06-27 14:56:27 -07002367 if (TextUtils.equals(ISDR_AID, aid)) {
2368 // Only allows LPA to open logical channel to ISD-R.
2369 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2370 ComponentInfo bestComponent =
2371 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2372 if (bestComponent == null
2373 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2374 loge("The calling package is not allowed to access ISD-R.");
2375 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2376 }
2377 }
2378
2379 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002380 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002381 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002382 if (DBG) log("iccOpenLogicalChannel: " + response);
2383 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002384 }
2385
2386 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002387 public boolean iccCloseLogicalChannel(int subId, int channel) {
2388 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002389
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002390 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002391 if (channel < 0) {
2392 return false;
2393 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002394 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002395 if (DBG) log("iccCloseLogicalChannel: " + success);
2396 return success;
2397 }
2398
2399 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002400 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002401 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002402 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002403
2404 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002405 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2406 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002407 " data=" + data);
2408 }
2409
2410 if (channel < 0) {
2411 return "";
2412 }
2413
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002414 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002415 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002416 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2417
Shishir Agrawal566b7612013-10-28 14:41:00 -07002418 // Append the returned status code to the end of the response payload.
2419 String s = Integer.toHexString(
2420 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002421 if (response.payload != null) {
2422 s = IccUtils.bytesToHexString(response.payload) + s;
2423 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002424 return s;
2425 }
Jake Hambye994d462014-02-03 13:10:13 -08002426
Evan Charltonc66da362014-05-16 14:06:40 -07002427 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002428 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2429 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002430 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002431
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002432 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2433 && TextUtils.equals(ISDR_AID, data)) {
2434 // Only allows LPA to select ISD-R.
2435 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2436 ComponentInfo bestComponent =
2437 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2438 if (bestComponent == null
2439 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2440 loge("The calling package is not allowed to select ISD-R.");
2441 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2442 }
2443 }
2444
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002445 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002446 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2447 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002448 }
2449
2450 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002451 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002452 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2453
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002454 // Append the returned status code to the end of the response payload.
2455 String s = Integer.toHexString(
2456 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002457 if (response.payload != null) {
2458 s = IccUtils.bytesToHexString(response.payload) + s;
2459 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002460 return s;
2461 }
2462
2463 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002464 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002465 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002466 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002467
2468 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002469 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002470 p1 + " " + p2 + " " + p3 + ":" + filePath);
2471 }
2472
2473 IccIoResult response =
2474 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002475 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2476 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002477
2478 if (DBG) {
2479 log("Exchange SIM_IO [R]" + response);
2480 }
2481
2482 byte[] result = null;
2483 int length = 2;
2484 if (response.payload != null) {
2485 length = 2 + response.payload.length;
2486 result = new byte[length];
2487 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2488 } else {
2489 result = new byte[length];
2490 }
2491
2492 result[length - 1] = (byte) response.sw2;
2493 result[length - 2] = (byte) response.sw1;
2494 return result;
2495 }
2496
Nathan Haroldb3014052017-01-25 15:57:32 -08002497 /**
2498 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2499 * on a particular subscription
2500 */
2501 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002502 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2503 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002504 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2505 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2506 return null;
2507 }
2508 Object response = sendRequest(
2509 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2510 if (response instanceof String[]) {
2511 return (String[]) response;
2512 }
2513 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2514 return null;
2515 }
2516
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002517 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002518 public String sendEnvelopeWithStatus(int subId, String content) {
2519 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002520
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002521 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002522 if (response.payload == null) {
2523 return "";
2524 }
2525
2526 // Append the returned status code to the end of the response payload.
2527 String s = Integer.toHexString(
2528 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2529 s = IccUtils.bytesToHexString(response.payload) + s;
2530 return s;
2531 }
2532
Jake Hambye994d462014-02-03 13:10:13 -08002533 /**
2534 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2535 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2536 *
2537 * @param itemID the ID of the item to read
2538 * @return the NV item as a String, or null on error.
2539 */
2540 @Override
2541 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002542 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002543 if (DBG) log("nvReadItem: item " + itemID);
2544 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2545 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2546 return value;
2547 }
2548
2549 /**
2550 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2551 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2552 *
2553 * @param itemID the ID of the item to read
2554 * @param itemValue the value to write, as a String
2555 * @return true on success; false on any failure
2556 */
2557 @Override
2558 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002559 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002560 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2561 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2562 new Pair<Integer, String>(itemID, itemValue));
2563 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2564 return success;
2565 }
2566
2567 /**
2568 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2569 * Used for device configuration by some CDMA operators.
2570 *
2571 * @param preferredRoamingList byte array containing the new PRL
2572 * @return true on success; false on any failure
2573 */
2574 @Override
2575 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002576 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002577 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2578 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2579 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2580 return success;
2581 }
2582
2583 /**
2584 * Perform the specified type of NV config reset.
2585 * Used for device configuration by some CDMA operators.
2586 *
2587 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2588 * @return true on success; false on any failure
2589 */
2590 @Override
2591 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002592 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002593 if (DBG) log("nvResetConfig: type " + resetType);
2594 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2595 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2596 return success;
2597 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002598
2599 /**
Wink Saville36469e72014-06-11 15:17:00 -07002600 * {@hide}
2601 * Returns Default sim, 0 in the case of single standby.
2602 */
2603 public int getDefaultSim() {
2604 //TODO Need to get it from Telephony Devcontroller
2605 return 0;
2606 }
2607
Svet Ganovb320e182015-04-16 12:30:10 -07002608 public String[] getPcscfAddress(String apnType, String callingPackage) {
2609 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2610 return new String[0];
2611 }
2612
2613
ram87fca6f2014-07-18 18:58:44 +05302614 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002615 }
2616
Brad Ebinger51f743a2017-01-23 13:50:20 -08002617 /**
Brad Ebinger34bef922017-11-09 10:27:08 -08002618 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2619 * feature or {@link null} if the service is not available. If the feature is available, the
2620 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002621 */
Brad Ebinger34bef922017-11-09 10:27:08 -08002622 public IImsMMTelFeature getMMTelFeatureAndListen(int slotId,
2623 IImsServiceFeatureCallback callback) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002624 enforceModifyPermission();
Brad Ebinger34bef922017-11-09 10:27:08 -08002625 return PhoneFactory.getImsResolver().getMMTelFeatureAndListen(slotId, callback);
2626 }
2627
2628 /**
2629 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2630 * feature during emergency calling or {@link null} if the service is not available. If the
2631 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2632 * listener for feature updates.
2633 */
2634 public IImsMMTelFeature getEmergencyMMTelFeatureAndListen(int slotId,
2635 IImsServiceFeatureCallback callback) {
2636 enforceModifyPermission();
2637 return PhoneFactory.getImsResolver().getEmergencyMMTelFeatureAndListen(slotId, callback);
2638 }
2639
2640 /**
2641 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2642 * feature during emergency calling or {@link null} if the service is not available. If the
2643 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2644 * listener for feature updates.
2645 */
2646 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2647 enforceModifyPermission();
2648 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002649 }
2650
Brad Ebinger7e934f52017-12-14 14:26:15 -08002651 /**
2652 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2653 * specified.
2654 */
2655 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2656 enforceModifyPermission();
2657 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2658 }
2659
Wink Saville36469e72014-06-11 15:17:00 -07002660 public void setImsRegistrationState(boolean registered) {
2661 enforceModifyPermission();
2662 mPhone.setImsRegistrationState(registered);
2663 }
2664
2665 /**
Stuart Scott54788802015-03-30 13:18:01 -07002666 * Set the network selection mode to automatic.
2667 *
2668 */
2669 @Override
2670 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002671 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002672 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2673 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2674 }
2675
2676 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002677 * Set the network selection mode to manual with the selected carrier.
2678 */
2679 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002680 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002681 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002682 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002683 OperatorInfo operator = new OperatorInfo(
2684 /* operatorAlphaLong */ "",
2685 /* operatorAlphaShort */ "",
2686 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002687 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002688 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2689 persistSelection);
2690 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002691 }
2692
2693 /**
2694 * Scans for available networks.
2695 */
2696 @Override
2697 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002698 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002699 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2700 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2701 CMD_PERFORM_NETWORK_SCAN, null, subId);
2702 return result;
2703 }
2704
2705 /**
yinxub1bed742017-04-17 11:45:04 -07002706 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002707 *
yinxub1bed742017-04-17 11:45:04 -07002708 * @param subId id of the subscription
2709 * @param request contains the radio access networks with bands/channels to scan
2710 * @param messenger callback messenger for scan results or errors
2711 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002712 * @return the id of the requested scan which can be used to stop the scan.
2713 */
2714 @Override
2715 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2716 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002717 enforceModifyPermissionOrCarrierPrivilege(subId);
2718 return mNetworkScanRequestTracker.startNetworkScan(
2719 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002720 }
2721
2722 /**
2723 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002724 *
2725 * @param subId id of the subscription
2726 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002727 */
2728 @Override
2729 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002730 enforceModifyPermissionOrCarrierPrivilege(subId);
2731 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002732 }
2733
2734 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002735 * Get the calculated preferred network type.
2736 * Used for debugging incorrect network type.
2737 *
2738 * @return the preferred network type, defined in RILConstants.java.
2739 */
2740 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002741 public int getCalculatedPreferredNetworkType(String callingPackage) {
2742 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2743 return RILConstants.PREFERRED_NETWORK_MODE;
2744 }
2745
Amit Mahajan43330e02014-11-18 11:54:45 -08002746 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002747 }
2748
2749 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002750 * Get the preferred network type.
2751 * Used for device configuration by some CDMA operators.
2752 *
2753 * @return the preferred network type, defined in RILConstants.java.
2754 */
2755 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002756 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002757 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002758 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002759 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002760 int networkType = (result != null ? result[0] : -1);
2761 if (DBG) log("getPreferredNetworkType: " + networkType);
2762 return networkType;
2763 }
2764
2765 /**
2766 * Set the preferred network type.
2767 * Used for device configuration by some CDMA operators.
2768 *
2769 * @param networkType the preferred network type, defined in RILConstants.java.
2770 * @return true on success; false on any failure.
2771 */
2772 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002773 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002774 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002775 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2776 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002777 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002778 if (success) {
2779 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002780 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002781 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002782 return success;
2783 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002784
2785 /**
Junda Liu475951f2014-11-07 16:45:03 -08002786 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2787 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2788 * tethering.
2789 *
2790 * @return 0: Not required. 1: required. 2: Not set.
2791 * @hide
2792 */
2793 @Override
2794 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002795 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002796 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2797 Settings.Global.TETHER_DUN_REQUIRED, 2);
2798 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2799 // config_tether_apndata.
2800 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2801 dunRequired = 1;
2802 }
2803 return dunRequired;
2804 }
2805
2806 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002807 * Set mobile data enabled
2808 * Used by the user through settings etc to turn on/off mobile data
2809 *
2810 * @param enable {@code true} turn turn data on, else {@code false}
2811 */
2812 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002813 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002814 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002815 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002816 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002817 Phone phone = PhoneFactory.getPhone(phoneId);
2818 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002819 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2820 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002821 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002822 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002823 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002824 }
2825
2826 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002827 * Get the user enabled state of Mobile Data.
2828 *
2829 * TODO: remove and use isUserDataEnabled.
2830 * This can't be removed now because some vendor codes
2831 * calls through ITelephony directly while they should
2832 * use TelephonyManager.
2833 *
2834 * @return true on enabled
2835 */
2836 @Override
2837 public boolean getDataEnabled(int subId) {
2838 return isUserDataEnabled(subId);
2839 }
2840
2841 /**
2842 * Get whether mobile data is enabled per user setting.
2843 *
2844 * There are other factors deciding whether mobile data is actually enabled, but they are
2845 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002846 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002847 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002848 *
2849 * @return {@code true} if data is enabled else {@code false}
2850 */
2851 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002852 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002853 try {
2854 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2855 null);
2856 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002857 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002858 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002859 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002860 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002861 Phone phone = PhoneFactory.getPhone(phoneId);
2862 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002863 boolean retVal = phone.isUserDataEnabled();
2864 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002865 return retVal;
2866 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002867 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2868 return false;
2869 }
2870 }
2871
2872 /**
2873 * Get whether mobile data is enabled.
2874 *
2875 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2876 * whether mobile data is actually enabled.
2877 *
2878 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2879 *
2880 * @return {@code true} if data is enabled else {@code false}
2881 */
2882 @Override
2883 public boolean isDataEnabled(int subId) {
2884 try {
2885 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2886 null);
2887 } catch (Exception e) {
2888 enforceModifyPermissionOrCarrierPrivilege(subId);
2889 }
2890 int phoneId = mSubscriptionController.getPhoneId(subId);
2891 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2892 Phone phone = PhoneFactory.getPhone(phoneId);
2893 if (phone != null) {
2894 boolean retVal = phone.isDataEnabled();
2895 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2896 return retVal;
2897 } else {
2898 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002899 return false;
2900 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002901 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002902
2903 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002904 public int getCarrierPrivilegeStatus(int subId) {
2905 final Phone phone = getPhone(subId);
2906 if (phone == null) {
2907 loge("getCarrierPrivilegeStatus: Invalid subId");
2908 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2909 }
2910 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002911 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002912 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002913 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2914 }
2915 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002916 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002917 }
Junda Liu29340342014-07-10 15:23:27 -07002918
2919 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002920 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002921 if (TextUtils.isEmpty(pkgName))
2922 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002923 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002924 if (card == null) {
2925 loge("checkCarrierPrivilegesForPackage: No UICC");
2926 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2927 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002928 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2929 }
2930
2931 @Override
2932 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002933 if (TextUtils.isEmpty(pkgName))
2934 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002935 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2936 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2937 UiccCard card = UiccController.getInstance().getUiccCard(i);
2938 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002939 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002940 continue;
2941 }
2942
2943 result = card.getCarrierPrivilegeStatus(
2944 mPhone.getContext().getPackageManager(), pkgName);
2945 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2946 break;
2947 }
2948 }
2949
2950 return result;
Junda Liu29340342014-07-10 15:23:27 -07002951 }
Derek Tan89e89d42014-07-08 17:00:10 -07002952
2953 @Override
Junda Liue64de782015-04-16 17:19:16 -07002954 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2955 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2956 loge("phoneId " + phoneId + " is not valid.");
2957 return null;
2958 }
2959 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002960 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002961 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002962 return null ;
2963 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002964 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002965 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002966 }
2967
Amith Yamasani6e118872016-02-19 12:53:51 -08002968 @Override
2969 public List<String> getPackagesWithCarrierPrivileges() {
2970 PackageManager pm = mPhone.getContext().getPackageManager();
2971 List<String> privilegedPackages = new ArrayList<>();
2972 List<PackageInfo> packages = null;
2973 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2974 UiccCard card = UiccController.getInstance().getUiccCard(i);
2975 if (card == null) {
2976 // No UICC in that slot.
2977 continue;
2978 }
2979 if (card.hasCarrierPrivilegeRules()) {
2980 if (packages == null) {
2981 // Only check packages in user 0 for now
2982 packages = pm.getInstalledPackagesAsUser(
2983 PackageManager.MATCH_DISABLED_COMPONENTS
2984 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2985 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2986 }
2987 for (int p = packages.size() - 1; p >= 0; p--) {
2988 PackageInfo pkgInfo = packages.get(p);
2989 if (pkgInfo != null && pkgInfo.packageName != null
2990 && card.getCarrierPrivilegeStatus(pkgInfo)
2991 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2992 privilegedPackages.add(pkgInfo.packageName);
2993 }
2994 }
2995 }
2996 }
2997 return privilegedPackages;
2998 }
2999
Wink Savilleb564aae2014-10-23 10:18:09 -07003000 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003001 final Phone phone = getPhone(subId);
3002 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003003 if (card == null) {
3004 loge("getIccId: No UICC");
3005 return null;
3006 }
3007 String iccId = card.getIccId();
3008 if (TextUtils.isEmpty(iccId)) {
3009 loge("getIccId: ICC ID is null or empty.");
3010 return null;
3011 }
3012 return iccId;
3013 }
3014
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003015 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003016 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3017 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003018 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07003019
Jeff Sharkey85190e62014-12-05 09:40:12 -08003020 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003021 final Phone phone = getPhone(subId);
3022 if (phone == null) {
3023 return false;
3024 }
3025 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003026
3027 if (DBG_MERGE) {
3028 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3029 + subscriberId + " to " + number);
3030 }
3031
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003032 if (TextUtils.isEmpty(iccId)) {
3033 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003034 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003035
Jeff Sharkey85190e62014-12-05 09:40:12 -08003036 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3037
3038 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003039 if (alphaTag == null) {
3040 editor.remove(alphaTagPrefKey);
3041 } else {
3042 editor.putString(alphaTagPrefKey, alphaTag);
3043 }
3044
Jeff Sharkey85190e62014-12-05 09:40:12 -08003045 // Record both the line number and IMSI for this ICCID, since we need to
3046 // track all merged IMSIs based on line number
3047 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3048 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003049 if (number == null) {
3050 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003051 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003052 } else {
3053 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003054 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003055 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003056
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003057 editor.commit();
3058 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003059 }
3060
3061 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003062 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003063 // This is open to apps with WRITE_SMS.
3064 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003065 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003066 return null;
3067 }
Derek Tan97ebb422014-09-05 16:55:38 -07003068
3069 String iccId = getIccId(subId);
3070 if (iccId != null) {
3071 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003072 if (DBG_MERGE) {
3073 log("getLine1NumberForDisplay returning " +
3074 mTelephonySharedPreferences.getString(numberPrefKey, null));
3075 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003076 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003077 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003078 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003079 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003080 }
3081
3082 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003083 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3084 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3085 return null;
3086 }
Derek Tan97ebb422014-09-05 16:55:38 -07003087
3088 String iccId = getIccId(subId);
3089 if (iccId != null) {
3090 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003091 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003092 }
Derek Tan97ebb422014-09-05 16:55:38 -07003093 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003094 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003095
3096 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003097 public String[] getMergedSubscriberIds(String callingPackage) {
3098 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3099 return null;
3100 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003101 final Context context = mPhone.getContext();
3102 final TelephonyManager tele = TelephonyManager.from(context);
3103 final SubscriptionManager sub = SubscriptionManager.from(context);
3104
3105 // Figure out what subscribers are currently active
3106 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003107 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3108 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3109 final long identity = Binder.clearCallingIdentity();
3110 try {
3111 final int[] subIds = sub.getActiveSubscriptionIdList();
3112 for (int subId : subIds) {
3113 activeSubscriberIds.add(tele.getSubscriberId(subId));
3114 }
3115 } finally {
3116 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003117 }
3118
3119 // First pass, find a number override for an active subscriber
3120 String mergeNumber = null;
3121 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3122 for (String key : prefs.keySet()) {
3123 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3124 final String subscriberId = (String) prefs.get(key);
3125 if (activeSubscriberIds.contains(subscriberId)) {
3126 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3127 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3128 mergeNumber = (String) prefs.get(numberKey);
3129 if (DBG_MERGE) {
3130 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3131 + " for active subscriber " + subscriberId);
3132 }
3133 if (!TextUtils.isEmpty(mergeNumber)) {
3134 break;
3135 }
3136 }
3137 }
3138 }
3139
3140 // Shortcut when no active merged subscribers
3141 if (TextUtils.isEmpty(mergeNumber)) {
3142 return null;
3143 }
3144
3145 // Second pass, find all subscribers under that line override
3146 final ArraySet<String> result = new ArraySet<>();
3147 for (String key : prefs.keySet()) {
3148 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3149 final String number = (String) prefs.get(key);
3150 if (mergeNumber.equals(number)) {
3151 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3152 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3153 final String subscriberId = (String) prefs.get(subscriberKey);
3154 if (!TextUtils.isEmpty(subscriberId)) {
3155 result.add(subscriberId);
3156 }
3157 }
3158 }
3159 }
3160
3161 final String[] resultArray = result.toArray(new String[result.size()]);
3162 Arrays.sort(resultArray);
3163 if (DBG_MERGE) {
3164 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3165 }
3166 return resultArray;
3167 }
3168
3169 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003170 public boolean setOperatorBrandOverride(int subId, String brand) {
3171 enforceCarrierPrivilege(subId);
3172 final Phone phone = getPhone(subId);
3173 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003174 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003175
3176 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003177 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003178 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3179 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003180 enforceCarrierPrivilege(subId);
3181 final Phone phone = getPhone(subId);
3182 if (phone == null) {
3183 return false;
3184 }
3185 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003186 cdmaNonRoamingList);
3187 }
3188
3189 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003190 public void setRadioCapability(RadioAccessFamily[] rafs) {
3191 try {
3192 ProxyController.getInstance().setRadioCapability(rafs);
3193 } catch (RuntimeException e) {
3194 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3195 }
3196 }
3197
3198 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003199 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3200 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3201 return RadioAccessFamily.RAF_UNKNOWN;
3202 }
3203
Wink Saville5d475dd2014-10-17 15:00:58 -07003204 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3205 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003206
3207 @Override
3208 public void enableVideoCalling(boolean enable) {
3209 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003210 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003211 }
3212
3213 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003214 public boolean isVideoCallingEnabled(String callingPackage) {
3215 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3216 return false;
3217 }
3218
Andrew Lee77527ac2014-10-21 16:57:39 -07003219 // Check the user preference and the system-level IMS setting. Even if the user has
3220 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3221 // In the long run, we may instead need to check if there exists a connection service
3222 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003223 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3224 return imsManager.isVtEnabledByPlatform()
3225 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3226 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003227 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003228
Andrew Leea1239f22015-03-02 17:44:07 -08003229 @Override
3230 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003231 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003232 }
3233
3234 @Override
3235 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003236 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003237 }
3238
Andrew Lee9431b832015-03-09 18:46:45 -07003239 @Override
3240 public boolean isTtyModeSupported() {
3241 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3242 TelephonyManager telephonyManager =
3243 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003244 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003245 }
3246
3247 @Override
3248 public boolean isHearingAidCompatibilitySupported() {
3249 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3250 }
3251
Sanket Padawe7310cc72015-01-14 09:53:20 -08003252 /**
3253 * Returns the unique device ID of phone, for example, the IMEI for
3254 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3255 *
3256 * <p>Requires Permission:
3257 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3258 */
3259 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003260 public String getDeviceId(String callingPackage) {
3261 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3262 return null;
3263 }
3264
Sanket Padawe7310cc72015-01-14 09:53:20 -08003265 final Phone phone = PhoneFactory.getPhone(0);
3266 if (phone != null) {
3267 return phone.getDeviceId();
3268 } else {
3269 return null;
3270 }
3271 }
3272
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003273 /*
3274 * {@hide}
3275 * Returns the IMS Registration Status
3276 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003277 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003278 public boolean isImsRegistered() {
3279 return mPhone.isImsRegistered();
3280 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003281
Ping Sun014fe8e2016-03-02 19:16:45 +08003282 /**
3283 * {@hide}
3284 * Returns the IMS Registration Status on a particular subid
3285 *
3286 * @param subId
3287 */
3288 public boolean isImsRegisteredForSubscriber(int subId) {
3289 Phone phone = getPhone(subId);
3290 if (phone != null) {
3291 return phone.isImsRegistered();
3292 } else {
3293 return false;
3294 }
3295 }
3296
Santos Cordon7a1885b2015-02-03 11:15:19 -08003297 @Override
3298 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3299 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3300 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003301
Nathan Haroldc55097a2015-03-11 18:14:50 -07003302 /*
3303 * {@hide}
3304 * Returns the IMS Registration Status
3305 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003306 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003307 return mPhone.isWifiCallingEnabled();
3308 }
3309
3310 /*
3311 * {@hide}
3312 * Returns the IMS Registration Status
3313 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003314 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003315 return mPhone.isVolteEnabled();
3316 }
Svet Ganovb320e182015-04-16 12:30:10 -07003317
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003318 /*
3319 * {@hide} Returns the IMS Registration Status
3320 */
3321 public boolean isVideoTelephonyAvailable() {
3322 return mPhone.isVideoEnabled();
3323 }
3324
Svet Ganovb320e182015-04-16 12:30:10 -07003325 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003326 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003327 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003328 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3329
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003330 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003331 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003332 } catch (SecurityException e) {
3333 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3334 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003335 }
Svet Ganovb320e182015-04-16 12:30:10 -07003336
3337 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3338 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3339 return false;
3340 }
3341
3342 return true;
3343 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003344
Makoto Onukifee69342015-06-29 14:44:50 -07003345 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003346 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003347 */
3348 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003349 // Default SMS app can always read it.
3350 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3351 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3352 return true;
3353 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003354
Makoto Onukie4072d12015-08-03 15:12:23 -07003355 try {
3356 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003357 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003358 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003359 // Can be read with READ_SMS too.
3360 try {
3361 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3362 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3363 if (opCode != AppOpsManager.OP_NONE) {
3364 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3365 == AppOpsManager.MODE_ALLOWED;
3366 } else {
3367 return true;
3368 }
3369 } catch (SecurityException readSmsSecurityException) {
3370 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003371 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003372 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003373 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003374 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003375 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003376 if (opCode != AppOpsManager.OP_NONE) {
3377 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3378 == AppOpsManager.MODE_ALLOWED;
3379 } else {
3380 return true;
3381 }
3382 } catch (SecurityException readPhoneNumberSecurityException) {
3383 }
3384
3385 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3386 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3387 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003388 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003389 }
3390
Stuart Scott8eef64f2015-04-08 15:13:54 -07003391 @Override
3392 public void factoryReset(int subId) {
3393 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003394 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3395 return;
3396 }
3397
Svet Ganovcc087f82015-05-12 20:35:54 -07003398 final long identity = Binder.clearCallingIdentity();
3399 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003400 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3401 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003402 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003403 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003404 // Set network selection mode to automatic
3405 setNetworkSelectionModeAutomatic(subId);
3406 // Set preferred mobile network type to the best available
3407 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3408 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003409 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003410 }
3411 } finally {
3412 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003413 }
3414 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003415
3416 @Override
3417 public String getLocaleFromDefaultSim() {
3418 // We query all subscriptions instead of just the active ones, because
3419 // this might be called early on in the provisioning flow when the
3420 // subscriptions potentially aren't active yet.
3421 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3422 if (slist == null || slist.isEmpty()) {
3423 return null;
3424 }
3425
3426 // This function may be called very early, say, from the setup wizard, at
3427 // which point we won't have a default subscription set. If that's the case
3428 // we just choose the first, which will be valid in "most cases".
3429 final int defaultSubId = getDefaultSubscription();
3430 SubscriptionInfo info = null;
3431 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3432 info = slist.get(0);
3433 } else {
3434 for (SubscriptionInfo item : slist) {
3435 if (item.getSubscriptionId() == defaultSubId) {
3436 info = item;
3437 break;
3438 }
3439 }
3440
3441 if (info == null) {
3442 return null;
3443 }
3444 }
3445
3446 // Try and fetch the locale from the carrier properties or from the SIM language
3447 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003448 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003449 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003450 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003451 if (defaultPhone != null) {
3452 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3453 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003454 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003455 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3456 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003457 } else {
3458 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003459 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003460 }
3461 }
3462
Narayan Kamath011676f2015-07-29 12:04:08 +01003463 // The SIM language preferences only store a language (e.g. fr = French), not an
3464 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3465 // the SIM and carrier preferences does not include a country we add the country
3466 // determined from the SIM MCC to provide an exact locale.
3467 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003468 if (mccLocale != null) {
3469 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3470 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003471 }
3472
Tony Hill183b2de2015-06-24 14:53:58 +01003473 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003474 return null;
3475 }
3476
3477 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3478 final long identity = Binder.clearCallingIdentity();
3479 try {
3480 return mSubscriptionController.getAllSubInfoList(
3481 mPhone.getContext().getOpPackageName());
3482 } finally {
3483 Binder.restoreCallingIdentity(identity);
3484 }
3485 }
3486
3487 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3488 final long identity = Binder.clearCallingIdentity();
3489 try {
3490 return mSubscriptionController.getActiveSubscriptionInfoList(
3491 mPhone.getContext().getOpPackageName());
3492 } finally {
3493 Binder.restoreCallingIdentity(identity);
3494 }
3495 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003496
3497 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003498 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3499 * representing the state of the modem.
3500 *
3501 * NOTE: This clears the modem state, so there should only every be one caller.
3502 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003503 */
3504 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003505 public void requestModemActivityInfo(ResultReceiver result) {
3506 enforceModifyPermission();
3507
3508 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3509 Bundle bundle = new Bundle();
3510 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3511 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003512 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003513
3514 /**
3515 * {@hide}
3516 * Returns the service state information on specified subscription.
3517 */
3518 @Override
3519 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3520
3521 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3522 return null;
3523 }
3524
3525 final Phone phone = getPhone(subId);
3526 if (phone == null) {
3527 return null;
3528 }
3529
3530 return phone.getServiceState();
3531 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003532
3533 /**
3534 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3535 *
3536 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3537 * voicemail ringtone.
3538 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3539 * PhoneAccount.
3540 */
3541 @Override
3542 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003543 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003544 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003545 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003546 }
3547
fionaxu7ed723d2017-05-30 18:58:54 -07003548 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003549 }
3550
3551 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003552 * Sets the per-account voicemail ringtone.
3553 *
3554 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3555 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3556 *
3557 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3558 * voicemail ringtone.
3559 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3560 * PhoneAccount.
3561 */
3562 @Override
3563 public void setVoicemailRingtoneUri(String callingPackage,
3564 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3565 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3566 if (!TextUtils.equals(callingPackage,
3567 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3568 enforceModifyPermissionOrCarrierPrivilege(
3569 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3570 }
3571 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3572 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003573 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003574 }
fionaxu7ed723d2017-05-30 18:58:54 -07003575 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003576 }
3577
3578 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003579 * Returns whether vibration is set for voicemail notification in Phone settings.
3580 *
3581 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3582 * voicemail vibration setting.
3583 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3584 */
3585 @Override
3586 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003587 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003588 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003589 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003590 }
3591
fionaxu7ed723d2017-05-30 18:58:54 -07003592 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003593 }
3594
Youhan Wange64578a2016-05-02 15:32:42 -07003595 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003596 * Sets the per-account voicemail vibration.
3597 *
3598 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3599 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3600 *
3601 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3602 * voicemail vibration setting.
3603 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3604 * specific PhoneAccount.
3605 */
3606 @Override
3607 public void setVoicemailVibrationEnabled(String callingPackage,
3608 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3609 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3610 if (!TextUtils.equals(callingPackage,
3611 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3612 enforceModifyPermissionOrCarrierPrivilege(
3613 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3614 }
3615
3616 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3617 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003618 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003619 }
fionaxu7ed723d2017-05-30 18:58:54 -07003620 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003621 }
3622
3623 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003624 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3625 *
3626 * @throws SecurityException if the caller does not have the required permission
3627 */
3628 private void enforceReadPrivilegedPermission() {
3629 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3630 null);
3631 }
3632
3633 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003634 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3635 * permission.
3636 *
3637 * @throws SecurityException if the caller does not have the required permission
3638 */
3639 private void enforceSendSmsPermission() {
3640 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3641 }
3642
3643 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003644 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003645 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003646 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003647 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003648 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003649 ComponentName componentName =
3650 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3651 if(componentName == null) {
3652 throw new SecurityException("Caller not current active visual voicemail package[null]");
3653 }
3654 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003655 if (!callingPackage.equals(vvmPackage)) {
3656 throw new SecurityException("Caller not current active visual voicemail package[" +
3657 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003658 }
3659 }
3660
3661 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003662 * Return the application ID for the app type.
3663 *
3664 * @param subId the subscription ID that this request applies to.
3665 * @param appType the uicc app type.
3666 * @return Application ID for specificied app type, or null if no uicc.
3667 */
3668 @Override
3669 public String getAidForAppType(int subId, int appType) {
3670 enforceReadPrivilegedPermission();
3671 Phone phone = getPhone(subId);
3672 if (phone == null) {
3673 return null;
3674 }
3675 String aid = null;
3676 try {
3677 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3678 .getApplicationByType(appType).getAid();
3679 } catch (Exception e) {
3680 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3681 }
3682 return aid;
3683 }
3684
Youhan Wang4001d252016-05-11 10:29:41 -07003685 /**
3686 * Return the Electronic Serial Number.
3687 *
3688 * @param subId the subscription ID that this request applies to.
3689 * @return ESN or null if error.
3690 */
3691 @Override
3692 public String getEsn(int subId) {
3693 enforceReadPrivilegedPermission();
3694 Phone phone = getPhone(subId);
3695 if (phone == null) {
3696 return null;
3697 }
3698 String esn = null;
3699 try {
3700 esn = phone.getEsn();
3701 } catch (Exception e) {
3702 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3703 }
3704 return esn;
3705 }
3706
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003707 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003708 * Return the Preferred Roaming List Version.
3709 *
3710 * @param subId the subscription ID that this request applies to.
3711 * @return PRLVersion or null if error.
3712 */
3713 @Override
3714 public String getCdmaPrlVersion(int subId) {
3715 enforceReadPrivilegedPermission();
3716 Phone phone = getPhone(subId);
3717 if (phone == null) {
3718 return null;
3719 }
3720 String cdmaPrlVersion = null;
3721 try {
3722 cdmaPrlVersion = phone.getCdmaPrlVersion();
3723 } catch (Exception e) {
3724 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3725 }
3726 return cdmaPrlVersion;
3727 }
3728
3729 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003730 * Get snapshot of Telephony histograms
3731 * @return List of Telephony histograms
3732 * @hide
3733 */
3734 @Override
3735 public List<TelephonyHistogram> getTelephonyHistograms() {
3736 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3737 return RIL.getTelephonyRILTimingHistograms();
3738 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003739
3740 /**
3741 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003742 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003743 * Require system privileges. In the future we may add this to carrier APIs.
3744 *
3745 * @return The number of carriers set successfully, should match length of carriers
3746 */
3747 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003748 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003749 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003750
Meng Wang9b7c4e92017-02-17 11:41:27 -08003751 if (carriers == null) {
3752 throw new NullPointerException("carriers cannot be null");
3753 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003754
3755 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003756 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3757 return retVal[0];
3758 }
3759
3760 /**
3761 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003762 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003763 * Require system privileges. In the future we may add this to carrier APIs.
3764 *
3765 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3766 * means all carriers are allowed.
3767 */
3768 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003769 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003770 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003771 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003772 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3773 }
3774
fionaxu59545b42016-05-25 15:53:37 -07003775 /**
3776 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3777 * @param subId the subscription ID that this action applies to.
3778 * @param enabled control enable or disable metered apns.
3779 * {@hide}
3780 */
3781 @Override
3782 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3783 enforceModifyPermission();
3784 final Phone phone = getPhone(subId);
3785 if (phone == null) {
3786 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3787 return;
3788 }
3789 try {
3790 phone.carrierActionSetMeteredApnsEnabled(enabled);
3791 } catch (Exception e) {
3792 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3793 }
3794 }
3795
3796 /**
3797 * Action set from carrier signalling broadcast receivers to enable/disable radio
3798 * @param subId the subscription ID that this action applies to.
3799 * @param enabled control enable or disable radio.
3800 * {@hide}
3801 */
3802 @Override
3803 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3804 enforceModifyPermission();
3805 final Phone phone = getPhone(subId);
3806 if (phone == null) {
3807 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3808 return;
3809 }
3810 try {
3811 phone.carrierActionSetRadioEnabled(enabled);
3812 } catch (Exception e) {
3813 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3814 }
3815 }
3816
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003817 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003818 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3819 * network status based on which carrier apps could apply actions accordingly,
3820 * enable/disable default url handler for example.
3821 *
3822 * @param subId the subscription ID that this action applies to.
3823 * @param report control start/stop reporting the default network status.
3824 * {@hide}
3825 */
3826 @Override
3827 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3828 enforceModifyPermission();
3829 final Phone phone = getPhone(subId);
3830 if (phone == null) {
3831 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3832 return;
3833 }
3834 try {
3835 phone.carrierActionReportDefaultNetworkStatus(report);
3836 } catch (Exception e) {
3837 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3838 }
3839 }
3840
3841 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003842 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3843 * bug report is being generated.
3844 */
3845 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003846 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003847 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3848 != PackageManager.PERMISSION_GRANTED) {
3849 writer.println("Permission Denial: can't dump Phone from pid="
3850 + Binder.getCallingPid()
3851 + ", uid=" + Binder.getCallingUid()
3852 + "without permission "
3853 + android.Manifest.permission.DUMP);
3854 return;
3855 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003856 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003857 }
Jack Yueb89b242016-06-22 13:27:47 -07003858
3859 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003860 * Get aggregated video call data usage since boot.
3861 *
3862 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3863 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003864 * {@hide}
3865 */
3866 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003867 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003868 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3869 null);
3870
Jack Yu84291ec2017-05-26 16:07:50 -07003871 // NetworkStatsService keeps tracking the active network interface and identity. It
3872 // records the delta with the corresponding network identity. We just return the total video
3873 // call data usage snapshot since boot.
3874 Phone phone = getPhone(subId);
3875 if (phone != null) {
3876 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003877 }
Jack Yu84291ec2017-05-26 16:07:50 -07003878 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003879 }
Jack Yu75ab2952016-07-08 14:29:33 -07003880
3881 /**
3882 * Policy control of data connection. Usually used when data limit is passed.
3883 * @param enabled True if enabling the data, otherwise disabling.
3884 * @param subId Subscription index
3885 * {@hide}
3886 */
3887 @Override
3888 public void setPolicyDataEnabled(boolean enabled, int subId) {
3889 enforceModifyPermission();
3890 Phone phone = getPhone(subId);
3891 if (phone != null) {
3892 phone.setPolicyDataEnabled(enabled);
3893 }
3894 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003895
3896 /**
3897 * Get Client request stats
3898 * @return List of Client Request Stats
3899 * @hide
3900 */
3901 @Override
3902 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3903 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3904 return null;
3905 }
3906
3907 Phone phone = getPhone(subId);
3908 if (phone != null) {
3909 return phone.getClientRequestStats();
3910 }
3911
3912 return null;
3913 }
3914
3915 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3916 if (workSource != null) {
3917 return workSource;
3918 }
3919
3920 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3921 workSource = new WorkSource(uid, packageName);
3922 return workSource;
3923 }
Jack Yueb4124c2017-02-16 15:32:43 -08003924
3925 /**
Grace Chen70990072017-03-24 17:21:30 -07003926 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003927 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003928 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003929 * @param state State of SIM (power down, power up, pass through)
3930 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3931 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3932 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003933 *
3934 **/
3935 @Override
Grace Chen70990072017-03-24 17:21:30 -07003936 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003937 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003938 Phone phone = PhoneFactory.getPhone(slotIndex);
3939
Jack Yueb4124c2017-02-16 15:32:43 -08003940 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003941 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003942 }
3943 }
Shuo Qiandd210312017-04-12 22:11:33 +00003944
Tyler Gunn65d45c22017-06-05 11:22:26 -07003945 private boolean isUssdApiAllowed(int subId) {
3946 CarrierConfigManager configManager =
3947 (CarrierConfigManager) mPhone.getContext().getSystemService(
3948 Context.CARRIER_CONFIG_SERVICE);
3949 if (configManager == null) {
3950 return false;
3951 }
3952 PersistableBundle pb = configManager.getConfigForSubId(subId);
3953 if (pb == null) {
3954 return false;
3955 }
3956 return pb.getBoolean(
3957 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3958 }
3959
Shuo Qiandd210312017-04-12 22:11:33 +00003960 /**
3961 * Check if phone is in emergency callback mode
3962 * @return true if phone is in emergency callback mode
3963 * @param subId sub id
3964 */
3965 public boolean getEmergencyCallbackMode(int subId) {
3966 final Phone phone = getPhone(subId);
3967 if (phone != null) {
3968 return phone.isInEcm();
3969 } else {
3970 return false;
3971 }
3972 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003973
3974 /**
3975 * Get the current signal strength information for the given subscription.
3976 * Because this information is not updated when the device is in a low power state
3977 * it should not be relied-upon to be current.
3978 * @param subId Subscription index
3979 * @return the most recent cached signal strength info from the modem
3980 */
3981 @Override
3982 public SignalStrength getSignalStrength(int subId) {
3983 Phone p = getPhone(subId);
3984 if (p == null) {
3985 return null;
3986 }
3987
3988 return p.getSignalStrength();
3989 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00003990
3991 @Override
3992 public UiccSlotInfo[] getUiccSlotsInfo() {
3993 enforceReadPrivilegedPermission();
3994
3995 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
3996 if (slots == null) return null;
3997 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
3998 for (int i = 0; i < slots.length; i++) {
3999 UiccSlot slot = slots[i];
4000
4001 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4002
4003 int cardState = 0;
4004 switch (slot.getCardState()) {
4005 case CARDSTATE_ABSENT:
4006 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4007 break;
4008 case CARDSTATE_PRESENT:
4009 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4010 break;
4011 case CARDSTATE_ERROR:
4012 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4013 break;
4014 case CARDSTATE_RESTRICTED:
4015 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4016 break;
4017 default:
4018 break;
4019
4020 }
4021
4022 infos[i] = new UiccSlotInfo(slot.isActive(), slot.isEuicc(), cardId, cardState);
4023 }
4024 return infos;
4025 }
4026
4027 @Override
4028 public boolean switchSlots(int[] physicalSlots) {
4029 enforceModifyPermission();
4030 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4031 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004032}