blob: f10a609d51c574745b6d594318b92389d2f1a2a2 [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;
Brad Ebingera12246d2018-01-16 09:39:35 -080073import android.telephony.ims.aidl.IImsConfig;
74import android.telephony.ims.aidl.IImsMmTelFeature;
75import android.telephony.ims.aidl.IImsRcsFeature;
76import android.telephony.ims.aidl.IImsRegistration;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080080import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080081import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080082
Andrew Lee312e8172014-10-23 17:01:36 -070083import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080084import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070085import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070086import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070087import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070088import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080091import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010092import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070093import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070094import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080096import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070097import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070098import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070099import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700100import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700101import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800102import com.android.internal.telephony.SubscriptionController;
Jonathan Basseri03923952017-07-19 12:22:35 -0700103import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700104import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700105import com.android.internal.telephony.uicc.IccIoResult;
106import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800107import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700108import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800109import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700110import com.android.internal.telephony.uicc.UiccController;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000111import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700112import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800113import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700114import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800115import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700116import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700117import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800118
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700119import java.io.FileDescriptor;
120import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800123import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800124import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100125import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800126import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127
128/**
129 * Implementation of the ITelephony interface.
130 */
Santos Cordon117fee72014-05-16 17:56:12 -0700131public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132 private static final String LOG_TAG = "PhoneInterfaceManager";
133 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
134 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800135 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136
137 // Message codes used with mMainThreadHandler
138 private static final int CMD_HANDLE_PIN_MMI = 1;
139 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
140 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
141 private static final int CMD_ANSWER_RINGING_CALL = 4;
142 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700143 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
144 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700145 private static final int CMD_OPEN_CHANNEL = 9;
146 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
147 private static final int CMD_CLOSE_CHANNEL = 11;
148 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800149 private static final int CMD_NV_READ_ITEM = 13;
150 private static final int EVENT_NV_READ_ITEM_DONE = 14;
151 private static final int CMD_NV_WRITE_ITEM = 15;
152 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
153 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
154 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
155 private static final int CMD_NV_RESET_CONFIG = 19;
156 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800157 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
158 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
159 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
160 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800161 private static final int CMD_SEND_ENVELOPE = 25;
162 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700163 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
164 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
165 private static final int CMD_EXCHANGE_SIM_IO = 31;
166 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800167 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
168 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700169 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
170 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700171 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
172 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700173 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
174 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
175 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
176 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700177 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
178 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
179 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
180 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700181 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800182 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
183 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000184 private static final int CMD_SWITCH_SLOTS = 50;
185 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800187 // Parameters of select command.
188 private static final int SELECT_COMMAND = 0xA4;
189 private static final int SELECT_P1 = 0x04;
190 private static final int SELECT_P2 = 0;
191 private static final int SELECT_P3 = 0x10;
192
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193 /** The singleton instance. */
194 private static PhoneInterfaceManager sInstance;
195
Wink Saville3ab207e2014-11-20 13:07:20 -0800196 private PhoneGlobals mApp;
197 private Phone mPhone;
198 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700199 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800200 private AppOpsManager mAppOps;
201 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800202 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800203 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204
Derek Tan97ebb422014-09-05 16:55:38 -0700205 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
206 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800207 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700208
Derek Tan740e1672017-06-27 14:56:27 -0700209 // The AID of ISD-R.
210 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
211
yinxub1bed742017-04-17 11:45:04 -0700212 private NetworkScanRequestTracker mNetworkScanRequestTracker;
213
Derek Tan89e89d42014-07-08 17:00:10 -0700214 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700215 * A request object to use for transmitting data to an ICC.
216 */
217 private static final class IccAPDUArgument {
218 public int channel, cla, command, p1, p2, p3;
219 public String data;
220
221 public IccAPDUArgument(int channel, int cla, int command,
222 int p1, int p2, int p3, String data) {
223 this.channel = channel;
224 this.cla = cla;
225 this.command = command;
226 this.p1 = p1;
227 this.p2 = p2;
228 this.p3 = p3;
229 this.data = data;
230 }
231 }
232
233 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700234 * A request object to use for transmitting data to an ICC.
235 */
236 private static final class ManualNetworkSelectionArgument {
237 public OperatorInfo operatorInfo;
238 public boolean persistSelection;
239
240 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
241 this.operatorInfo = operatorInfo;
242 this.persistSelection = persistSelection;
243 }
244 }
245
246 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
248 * request after sending. The main thread will notify the request when it is complete.
249 */
250 private static final class MainThreadRequest {
251 /** The argument to use for the request */
252 public Object argument;
253 /** The result of the request that is run on the main thread */
254 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800255 // The subscriber id that this request applies to. Defaults to
256 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
257 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258
259 public MainThreadRequest(Object argument) {
260 this.argument = argument;
261 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800262
263 public MainThreadRequest(Object argument, Integer subId) {
264 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800265 if (subId != null) {
266 this.subId = subId;
267 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800268 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269 }
270
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800271 private static final class IncomingThirdPartyCallArgs {
272 public final ComponentName component;
273 public final String callId;
274 public final String callerDisplayName;
275
276 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
277 String callerDisplayName) {
278 this.component = component;
279 this.callId = callId;
280 this.callerDisplayName = callerDisplayName;
281 }
282 }
283
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284 /**
285 * A handler that processes messages on the main thread in the phone process. Since many
286 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
287 * inbound binder threads to the main thread in the phone process. The Binder thread
288 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
289 * on, which will be notified when the operation completes and will contain the result of the
290 * request.
291 *
292 * <p>If a MainThreadRequest object is provided in the msg.obj field,
293 * note that request.result must be set to something non-null for the calling thread to
294 * unblock.
295 */
296 private final class MainThreadHandler extends Handler {
297 @Override
298 public void handleMessage(Message msg) {
299 MainThreadRequest request;
300 Message onCompleted;
301 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800302 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700303 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700304
305 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700306 case CMD_HANDLE_USSD_REQUEST: {
307 request = (MainThreadRequest) msg.obj;
308 final Phone phone = getPhoneFromRequest(request);
309 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
310 String ussdRequest = ussdObject.first;
311 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700312
313 if (!isUssdApiAllowed(request.subId)) {
314 // Carrier does not support use of this API, return failure.
315 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
316 UssdResponse response = new UssdResponse(ussdRequest, null);
317 Bundle returnData = new Bundle();
318 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
319 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
320
321 request.result = true;
322 synchronized (request) {
323 request.notifyAll();
324 }
325 return;
326 }
327
Tyler Gunn52dcf772017-04-26 11:30:31 -0700328 try {
329 request.result = phone != null ?
330 phone.handleUssdRequest(ussdRequest, wrappedCallback)
331 : false;
332 } catch (CallStateException cse) {
333 request.result = false;
334 }
pkanwar32d516d2016-10-14 19:37:38 -0700335 // Wake up the requesting thread
336 synchronized (request) {
337 request.notifyAll();
338 }
339 break;
340 }
341
Yorke Lee716f67e2015-06-17 15:39:16 -0700342 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700344 final Phone phone = getPhoneFromRequest(request);
345 request.result = phone != null ?
346 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
347 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 // Wake up the requesting thread
349 synchronized (request) {
350 request.notifyAll();
351 }
352 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354
355 case CMD_HANDLE_NEIGHBORING_CELL:
356 request = (MainThreadRequest) msg.obj;
357 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
358 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700359 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360 break;
361
362 case EVENT_NEIGHBORING_CELL_DONE:
363 ar = (AsyncResult) msg.obj;
364 request = (MainThreadRequest) ar.userObj;
365 if (ar.exception == null && ar.result != null) {
366 request.result = ar.result;
367 } else {
368 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800369 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 }
371 // Wake up the requesting thread
372 synchronized (request) {
373 request.notifyAll();
374 }
375 break;
376
377 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700378 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800379 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700380 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 break;
382
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 case CMD_END_CALL:
384 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800385 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700386 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700387 Phone phone = getPhone(end_subId);
388 if (phone == null) {
389 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
390 break;
391 }
392 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
394 // CDMA: If the user presses the Power button we treat it as
395 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700396 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
398 // GSM: End the call as per the Phone state
399 hungUp = PhoneUtils.hangup(mCM);
400 } else {
401 throw new IllegalStateException("Unexpected phone type: " + phoneType);
402 }
403 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
404 request.result = hungUp;
405 // Wake up the requesting thread
406 synchronized (request) {
407 request.notifyAll();
408 }
409 break;
410
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700411 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700412 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800414 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700415 if (uiccCard == null) {
416 loge("iccTransmitApduLogicalChannel: No UICC");
417 request.result = new IccIoResult(0x6F, 0, (byte[])null);
418 synchronized (request) {
419 request.notifyAll();
420 }
421 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700422 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
423 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700424 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 iccArgument.channel, iccArgument.cla, iccArgument.command,
426 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700427 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700428 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 break;
430
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 ar = (AsyncResult) msg.obj;
433 request = (MainThreadRequest) ar.userObj;
434 if (ar.exception == null && ar.result != null) {
435 request.result = ar.result;
436 } else {
437 request.result = new IccIoResult(0x6F, 0, (byte[])null);
438 if (ar.result == null) {
439 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800440 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700441 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800442 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 } else {
444 loge("iccTransmitApduLogicalChannel: Unknown exception");
445 }
446 }
447 synchronized (request) {
448 request.notifyAll();
449 }
450 break;
451
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700452 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
453 request = (MainThreadRequest) msg.obj;
454 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800455 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700456 if (uiccCard == null) {
457 loge("iccTransmitApduBasicChannel: No UICC");
458 request.result = new IccIoResult(0x6F, 0, (byte[])null);
459 synchronized (request) {
460 request.notifyAll();
461 }
462 } else {
463 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
464 request);
465 uiccCard.iccTransmitApduBasicChannel(
466 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
467 iccArgument.p3, iccArgument.data, onCompleted);
468 }
469 break;
470
471 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
472 ar = (AsyncResult) msg.obj;
473 request = (MainThreadRequest) ar.userObj;
474 if (ar.exception == null && ar.result != null) {
475 request.result = ar.result;
476 } else {
477 request.result = new IccIoResult(0x6F, 0, (byte[])null);
478 if (ar.result == null) {
479 loge("iccTransmitApduBasicChannel: Empty response");
480 } else if (ar.exception instanceof CommandException) {
481 loge("iccTransmitApduBasicChannel: CommandException: " +
482 ar.exception);
483 } else {
484 loge("iccTransmitApduBasicChannel: Unknown exception");
485 }
486 }
487 synchronized (request) {
488 request.notifyAll();
489 }
490 break;
491
492 case CMD_EXCHANGE_SIM_IO:
493 request = (MainThreadRequest) msg.obj;
494 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800495 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 if (uiccCard == null) {
497 loge("iccExchangeSimIO: No UICC");
498 request.result = new IccIoResult(0x6F, 0, (byte[])null);
499 synchronized (request) {
500 request.notifyAll();
501 }
502 } else {
503 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
504 request);
505 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
506 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
507 iccArgument.data, onCompleted);
508 }
509 break;
510
511 case EVENT_EXCHANGE_SIM_IO_DONE:
512 ar = (AsyncResult) msg.obj;
513 request = (MainThreadRequest) ar.userObj;
514 if (ar.exception == null && ar.result != null) {
515 request.result = ar.result;
516 } else {
517 request.result = new IccIoResult(0x6f, 0, (byte[])null);
518 }
519 synchronized (request) {
520 request.notifyAll();
521 }
522 break;
523
Derek Tan4d5e5c12014-02-04 11:54:58 -0800524 case CMD_SEND_ENVELOPE:
525 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800526 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700527 if (uiccCard == null) {
528 loge("sendEnvelopeWithStatus: No UICC");
529 request.result = new IccIoResult(0x6F, 0, (byte[])null);
530 synchronized (request) {
531 request.notifyAll();
532 }
533 } else {
534 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
535 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
536 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800537 break;
538
539 case EVENT_SEND_ENVELOPE_DONE:
540 ar = (AsyncResult) msg.obj;
541 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700542 if (ar.exception == null && ar.result != null) {
543 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800544 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700545 request.result = new IccIoResult(0x6F, 0, (byte[])null);
546 if (ar.result == null) {
547 loge("sendEnvelopeWithStatus: Empty response");
548 } else if (ar.exception instanceof CommandException) {
549 loge("sendEnvelopeWithStatus: CommandException: " +
550 ar.exception);
551 } else {
552 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
553 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800554 }
555 synchronized (request) {
556 request.notifyAll();
557 }
558 break;
559
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 case CMD_OPEN_CHANNEL:
561 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800562 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800563 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700564 if (uiccCard == null) {
565 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800566 request.result = new IccOpenLogicalChannelResponse(-1,
567 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 synchronized (request) {
569 request.notifyAll();
570 }
571 } else {
572 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800573 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
574 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700575 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 break;
577
578 case EVENT_OPEN_CHANNEL_DONE:
579 ar = (AsyncResult) msg.obj;
580 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700581 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 int[] result = (int[]) ar.result;
584 int channelId = result[0];
585 byte[] selectResponse = null;
586 if (result.length > 1) {
587 selectResponse = new byte[result.length - 1];
588 for (int i = 1; i < result.length; ++i) {
589 selectResponse[i - 1] = (byte) result[i];
590 }
591 }
592 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700593 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 if (ar.result == null) {
596 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 if (ar.exception != null) {
599 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
600 }
601
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700602 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700603 if (ar.exception instanceof CommandException) {
604 CommandException.Error error =
605 ((CommandException) (ar.exception)).getCommandError();
606 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700607 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700608 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700609 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 }
611 }
612 openChannelResp = new IccOpenLogicalChannelResponse(
613 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700615 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 synchronized (request) {
617 request.notifyAll();
618 }
619 break;
620
621 case CMD_CLOSE_CHANNEL:
622 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800623 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 if (uiccCard == null) {
625 loge("iccCloseLogicalChannel: No UICC");
626 request.result = new IccIoResult(0x6F, 0, (byte[])null);
627 synchronized (request) {
628 request.notifyAll();
629 }
630 } else {
631 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
632 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
633 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800637 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
638 break;
639
640 case CMD_NV_READ_ITEM:
641 request = (MainThreadRequest) msg.obj;
642 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
643 mPhone.nvReadItem((Integer) request.argument, onCompleted);
644 break;
645
646 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 ar = (AsyncResult) msg.obj;
648 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800649 if (ar.exception == null && ar.result != null) {
650 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800652 request.result = "";
653 if (ar.result == null) {
654 loge("nvReadItem: Empty response");
655 } else if (ar.exception instanceof CommandException) {
656 loge("nvReadItem: CommandException: " +
657 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800659 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 }
661 }
662 synchronized (request) {
663 request.notifyAll();
664 }
665 break;
666
Jake Hambye994d462014-02-03 13:10:13 -0800667 case CMD_NV_WRITE_ITEM:
668 request = (MainThreadRequest) msg.obj;
669 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
670 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
671 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
672 break;
673
674 case EVENT_NV_WRITE_ITEM_DONE:
675 handleNullReturnEvent(msg, "nvWriteItem");
676 break;
677
678 case CMD_NV_WRITE_CDMA_PRL:
679 request = (MainThreadRequest) msg.obj;
680 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
681 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
682 break;
683
684 case EVENT_NV_WRITE_CDMA_PRL_DONE:
685 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
686 break;
687
688 case CMD_NV_RESET_CONFIG:
689 request = (MainThreadRequest) msg.obj;
690 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
691 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
692 break;
693
694 case EVENT_NV_RESET_CONFIG_DONE:
695 handleNullReturnEvent(msg, "nvResetConfig");
696 break;
697
Jake Hamby7c27be32014-03-03 13:25:59 -0800698 case CMD_GET_PREFERRED_NETWORK_TYPE:
699 request = (MainThreadRequest) msg.obj;
700 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700701 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800702 break;
703
704 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
705 ar = (AsyncResult) msg.obj;
706 request = (MainThreadRequest) ar.userObj;
707 if (ar.exception == null && ar.result != null) {
708 request.result = ar.result; // Integer
709 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800710 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 if (ar.result == null) {
712 loge("getPreferredNetworkType: Empty response");
713 } else if (ar.exception instanceof CommandException) {
714 loge("getPreferredNetworkType: CommandException: " +
715 ar.exception);
716 } else {
717 loge("getPreferredNetworkType: Unknown exception");
718 }
719 }
720 synchronized (request) {
721 request.notifyAll();
722 }
723 break;
724
725 case CMD_SET_PREFERRED_NETWORK_TYPE:
726 request = (MainThreadRequest) msg.obj;
727 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
728 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700729 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800730 break;
731
732 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
733 handleNullReturnEvent(msg, "setPreferredNetworkType");
734 break;
735
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800736 case CMD_SET_VOICEMAIL_NUMBER:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
739 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800740 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
741 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800742 break;
743
744 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
745 handleNullReturnEvent(msg, "setVoicemailNumber");
746 break;
747
Stuart Scott54788802015-03-30 13:18:01 -0700748 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
751 request);
752 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
753 break;
754
755 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
756 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
757 break;
758
Shishir Agrawal302c8692015-06-19 13:49:39 -0700759 case CMD_PERFORM_NETWORK_SCAN:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
762 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
763 break;
764
765 case EVENT_PERFORM_NETWORK_SCAN_DONE:
766 ar = (AsyncResult) msg.obj;
767 request = (MainThreadRequest) ar.userObj;
768 CellNetworkScanResult cellScanResult;
769 if (ar.exception == null && ar.result != null) {
770 cellScanResult = new CellNetworkScanResult(
771 CellNetworkScanResult.STATUS_SUCCESS,
772 (List<OperatorInfo>) ar.result);
773 } else {
774 if (ar.result == null) {
775 loge("getCellNetworkScanResults: Empty response");
776 }
777 if (ar.exception != null) {
778 loge("getCellNetworkScanResults: Exception: " + ar.exception);
779 }
780 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
781 if (ar.exception instanceof CommandException) {
782 CommandException.Error error =
783 ((CommandException) (ar.exception)).getCommandError();
784 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
785 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
786 } else if (error == CommandException.Error.GENERIC_FAILURE) {
787 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
788 }
789 }
790 cellScanResult = new CellNetworkScanResult(errorCode, null);
791 }
792 request.result = cellScanResult;
793 synchronized (request) {
794 request.notifyAll();
795 }
796 break;
797
798 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
799 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700800 ManualNetworkSelectionArgument selArg =
801 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700802 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
803 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700804 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
805 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700806 break;
807
808 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
809 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
810 break;
811
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700812 case CMD_GET_MODEM_ACTIVITY_INFO:
813 request = (MainThreadRequest) msg.obj;
814 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700815 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700816 break;
817
818 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
819 ar = (AsyncResult) msg.obj;
820 request = (MainThreadRequest) ar.userObj;
821 if (ar.exception == null && ar.result != null) {
822 request.result = ar.result;
823 } else {
824 if (ar.result == null) {
825 loge("queryModemActivityInfo: Empty response");
826 } else if (ar.exception instanceof CommandException) {
827 loge("queryModemActivityInfo: CommandException: " +
828 ar.exception);
829 } else {
830 loge("queryModemActivityInfo: Unknown exception");
831 }
832 }
Amit Mahajand4766222016-01-28 15:28:28 -0800833 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
834 if (request.result == null) {
835 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
836 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700837 synchronized (request) {
838 request.notifyAll();
839 }
840 break;
841
Meng Wang1a7c35a2016-05-05 20:56:15 -0700842 case CMD_SET_ALLOWED_CARRIERS:
843 request = (MainThreadRequest) msg.obj;
844 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
845 mPhone.setAllowedCarriers(
846 (List<CarrierIdentifier>) request.argument,
847 onCompleted);
848 break;
849
850 case EVENT_SET_ALLOWED_CARRIERS_DONE:
851 ar = (AsyncResult) msg.obj;
852 request = (MainThreadRequest) ar.userObj;
853 if (ar.exception == null && ar.result != null) {
854 request.result = ar.result;
855 } else {
856 if (ar.result == null) {
857 loge("setAllowedCarriers: Empty response");
858 } else if (ar.exception instanceof CommandException) {
859 loge("setAllowedCarriers: CommandException: " +
860 ar.exception);
861 } else {
862 loge("setAllowedCarriers: Unknown exception");
863 }
864 }
865 // Result cannot be null. Return -1 on error.
866 if (request.result == null) {
867 request.result = new int[]{-1};
868 }
869 synchronized (request) {
870 request.notifyAll();
871 }
872 break;
873
874 case CMD_GET_ALLOWED_CARRIERS:
875 request = (MainThreadRequest) msg.obj;
876 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
877 mPhone.getAllowedCarriers(onCompleted);
878 break;
879
880 case EVENT_GET_ALLOWED_CARRIERS_DONE:
881 ar = (AsyncResult) msg.obj;
882 request = (MainThreadRequest) ar.userObj;
883 if (ar.exception == null && ar.result != null) {
884 request.result = ar.result;
885 } else {
886 if (ar.result == null) {
887 loge("getAllowedCarriers: Empty response");
888 } else if (ar.exception instanceof CommandException) {
889 loge("getAllowedCarriers: CommandException: " +
890 ar.exception);
891 } else {
892 loge("getAllowedCarriers: Unknown exception");
893 }
894 }
895 // Result cannot be null. Return empty list of CarrierIdentifier.
896 if (request.result == null) {
897 request.result = new ArrayList<CarrierIdentifier>(0);
898 }
899 synchronized (request) {
900 request.notifyAll();
901 }
902 break;
903
Nathan Haroldb3014052017-01-25 15:57:32 -0800904 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
905 ar = (AsyncResult) msg.obj;
906 request = (MainThreadRequest) ar.userObj;
907 if (ar.exception == null && ar.result != null) {
908 request.result = ar.result;
909 } else {
910 request.result = new IllegalArgumentException(
911 "Failed to retrieve Forbidden Plmns");
912 if (ar.result == null) {
913 loge("getForbiddenPlmns: Empty response");
914 } else {
915 loge("getForbiddenPlmns: Unknown exception");
916 }
917 }
918 synchronized (request) {
919 request.notifyAll();
920 }
921 break;
922
923 case CMD_GET_FORBIDDEN_PLMNS:
924 request = (MainThreadRequest) msg.obj;
925 uiccCard = getUiccCardFromRequest(request);
926 if (uiccCard == null) {
927 loge("getForbiddenPlmns() UiccCard is null");
928 request.result = new IllegalArgumentException(
929 "getForbiddenPlmns() UiccCard is null");
930 synchronized (request) {
931 request.notifyAll();
932 }
933 break;
934 }
935 Integer appType = (Integer) request.argument;
936 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
937 if (uiccApp == null) {
938 loge("getForbiddenPlmns() no app with specified type -- "
939 + appType);
940 request.result = new IllegalArgumentException("Failed to get UICC App");
941 synchronized (request) {
942 request.notifyAll();
943 }
944 break;
945 } else {
946 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
947 + " specified type -- " + appType);
948 }
949 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
950 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
951 onCompleted);
952 break;
953
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000954 case CMD_SWITCH_SLOTS:
955 request = (MainThreadRequest) msg.obj;
956 int[] physicalSlots = (int[]) request.argument;
957 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
958 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
959 break;
960
961 case EVENT_SWITCH_SLOTS_DONE:
962 ar = (AsyncResult) msg.obj;
963 request = (MainThreadRequest) ar.userObj;
964 request.result = (ar.exception == null);
965 synchronized (request) {
966 request.notifyAll();
967 }
968 break;
969
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700970 default:
971 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
972 break;
973 }
974 }
Jake Hambye994d462014-02-03 13:10:13 -0800975
976 private void handleNullReturnEvent(Message msg, String command) {
977 AsyncResult ar = (AsyncResult) msg.obj;
978 MainThreadRequest request = (MainThreadRequest) ar.userObj;
979 if (ar.exception == null) {
980 request.result = true;
981 } else {
982 request.result = false;
983 if (ar.exception instanceof CommandException) {
984 loge(command + ": CommandException: " + ar.exception);
985 } else {
986 loge(command + ": Unknown exception");
987 }
988 }
989 synchronized (request) {
990 request.notifyAll();
991 }
992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700993 }
994
995 /**
996 * Posts the specified command to be executed on the main thread,
997 * waits for the request to complete, and returns the result.
998 * @see #sendRequestAsync
999 */
1000 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001001 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001002 }
1003
1004 /**
1005 * Posts the specified command to be executed on the main thread,
1006 * waits for the request to complete, and returns the result.
1007 * @see #sendRequestAsync
1008 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001009 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001010 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1011 throw new RuntimeException("This method will deadlock if called from the main thread.");
1012 }
1013
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001014 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001015 Message msg = mMainThreadHandler.obtainMessage(command, request);
1016 msg.sendToTarget();
1017
1018 // Wait for the request to complete
1019 synchronized (request) {
1020 while (request.result == null) {
1021 try {
1022 request.wait();
1023 } catch (InterruptedException e) {
1024 // Do nothing, go back and wait until the request is complete
1025 }
1026 }
1027 }
1028 return request.result;
1029 }
1030
1031 /**
1032 * Asynchronous ("fire and forget") version of sendRequest():
1033 * Posts the specified command to be executed on the main thread, and
1034 * returns immediately.
1035 * @see #sendRequest
1036 */
1037 private void sendRequestAsync(int command) {
1038 mMainThreadHandler.sendEmptyMessage(command);
1039 }
1040
1041 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001042 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1043 * @see {@link #sendRequest(int,Object)}
1044 */
1045 private void sendRequestAsync(int command, Object argument) {
1046 MainThreadRequest request = new MainThreadRequest(argument);
1047 Message msg = mMainThreadHandler.obtainMessage(command, request);
1048 msg.sendToTarget();
1049 }
1050
1051 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001052 * Initialize the singleton PhoneInterfaceManager instance.
1053 * This is only done once, at startup, from PhoneApp.onCreate().
1054 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001055 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001056 synchronized (PhoneInterfaceManager.class) {
1057 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001058 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001059 } else {
1060 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1061 }
1062 return sInstance;
1063 }
1064 }
1065
1066 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001067 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001068 mApp = app;
1069 mPhone = phone;
1070 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001071 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001072 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1073 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001074 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001075 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001076 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001077 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001078
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001079 publish();
1080 }
1081
1082 private void publish() {
1083 if (DBG) log("publish: " + this);
1084
1085 ServiceManager.addService("phone", this);
1086 }
1087
Stuart Scott584921c2015-01-15 17:10:34 -08001088 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001089 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1090 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001091 }
1092
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001093 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1094 Phone phone = getPhoneFromRequest(request);
1095 return phone == null ? null :
1096 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1097 }
1098
Wink Saville36469e72014-06-11 15:17:00 -07001099 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001100 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001101 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001102 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001103 //
1104 // Implementation of the ITelephony interface.
1105 //
1106
1107 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001108 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001109 }
1110
Wink Savilleb564aae2014-10-23 10:18:09 -07001111 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001112 if (DBG) log("dial: " + number);
1113 // No permission check needed here: This is just a wrapper around the
1114 // ACTION_DIAL intent, which is available to any app since it puts up
1115 // the UI before it does anything.
1116
1117 String url = createTelUrl(number);
1118 if (url == null) {
1119 return;
1120 }
1121
1122 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001123 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001124 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1125 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1126 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1127 mApp.startActivity(intent);
1128 }
1129 }
1130
1131 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001132 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001133 }
1134
Wink Savilleb564aae2014-10-23 10:18:09 -07001135 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001136 if (DBG) log("call: " + number);
1137
1138 // This is just a wrapper around the ACTION_CALL intent, but we still
1139 // need to do a permission check since we're calling startActivity()
1140 // from the context of the phone app.
1141 enforceCallPermission();
1142
1143 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1144 != AppOpsManager.MODE_ALLOWED) {
1145 return;
1146 }
1147
1148 String url = createTelUrl(number);
1149 if (url == null) {
1150 return;
1151 }
1152
Wink Saville08874612014-08-31 19:19:58 -07001153 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001154 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001155 if (slist != null) {
1156 for (SubscriptionInfo subInfoRecord : slist) {
1157 if (subInfoRecord.getSubscriptionId() == subId) {
1158 isValid = true;
1159 break;
1160 }
Wink Saville08874612014-08-31 19:19:58 -07001161 }
1162 }
1163 if (isValid == false) {
1164 return;
1165 }
1166
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001167 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001168 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001169 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1170 mApp.startActivity(intent);
1171 }
1172
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001173 /**
1174 * End a call based on call state
1175 * @return true is a call was ended
1176 */
1177 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001178 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001179 }
1180
1181 /**
1182 * End a call based on the call state of the subId
1183 * @return true is a call was ended
1184 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001185 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001186 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001187 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001188 }
1189
1190 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001191 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001192 }
1193
Wink Savilleb564aae2014-10-23 10:18:09 -07001194 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 if (DBG) log("answerRingingCall...");
1196 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1197 // but that can probably wait till the big TelephonyManager API overhaul.
1198 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1199 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001200 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001201 }
1202
1203 /**
1204 * Make the actual telephony calls to implement answerRingingCall().
1205 * This should only be called from the main thread of the Phone app.
1206 * @see #answerRingingCall
1207 *
1208 * TODO: it would be nice to return true if we answered the call, or
1209 * false if there wasn't actually a ringing incoming call, or some
1210 * other error occurred. (In other words, pass back the return value
1211 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1212 * But that would require calling this method via sendRequest() rather
1213 * than sendRequestAsync(), and right now we don't actually *need* that
1214 * return value, so let's just return void for now.
1215 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001216 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001217 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001219 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1220 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001221 if (hasActiveCall && hasHoldingCall) {
1222 // Both lines are in use!
1223 // TODO: provide a flag to let the caller specify what
1224 // policy to use if both lines are in use. (The current
1225 // behavior is hardwired to "answer incoming, end ongoing",
1226 // which is how the CALL button is specced to behave.)
1227 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1228 return;
1229 } else {
1230 // answerCall() will automatically hold the current active
1231 // call, if there is one.
1232 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1233 return;
1234 }
1235 } else {
1236 // No call was ringing.
1237 return;
1238 }
1239 }
1240
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001241 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001242 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001243 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001244 public void silenceRinger() {
1245 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001246 }
1247
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001248 @Override
1249 public boolean isOffhook(String callingPackage) {
1250 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001251 }
1252
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001253 @Override
1254 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1255 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1256 return false;
1257 }
1258
Sanket Padawe356d7632015-06-22 14:03:32 -07001259 final Phone phone = getPhone(subId);
1260 if (phone != null) {
1261 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1262 } else {
1263 return false;
1264 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001265 }
1266
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001267 @Override
1268 public boolean isRinging(String callingPackage) {
1269 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001270 }
1271
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001272 @Override
1273 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1274 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1275 return false;
1276 }
1277
Sanket Padawe356d7632015-06-22 14:03:32 -07001278 final Phone phone = getPhone(subId);
1279 if (phone != null) {
1280 return (phone.getState() == PhoneConstants.State.RINGING);
1281 } else {
1282 return false;
1283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284 }
1285
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001286 @Override
1287 public boolean isIdle(String callingPackage) {
1288 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001289 }
1290
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001291 @Override
1292 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1293 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1294 return false;
1295 }
1296
Sanket Padawe356d7632015-06-22 14:03:32 -07001297 final Phone phone = getPhone(subId);
1298 if (phone != null) {
1299 return (phone.getState() == PhoneConstants.State.IDLE);
1300 } else {
1301 return false;
1302 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303 }
1304
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001306 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001307 }
1308
Wink Savilleb564aae2014-10-23 10:18:09 -07001309 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001310 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001311 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1312 }
1313
1314 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001315 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001316 }
1317
Wink Savilleb564aae2014-10-23 10:18:09 -07001318 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001319 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001320 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1321 }
1322
1323 /** {@hide} */
1324 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001325 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001326 }
1327
Wink Savilleb564aae2014-10-23 10:18:09 -07001328 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001330 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 checkSimPin.start();
1332 return checkSimPin.unlockSim(null, pin);
1333 }
1334
Wink Saville9de0f752013-10-22 19:04:03 -07001335 /** {@hide} */
1336 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001337 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001338 }
1339
Wink Savilleb564aae2014-10-23 10:18:09 -07001340 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001341 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001342 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 checkSimPuk.start();
1344 return checkSimPuk.unlockSim(puk, pin);
1345 }
1346
1347 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001348 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349 * a synchronous one.
1350 */
1351 private static class UnlockSim extends Thread {
1352
1353 private final IccCard mSimCard;
1354
1355 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001356 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1357 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001358
1359 // For replies from SimCard interface
1360 private Handler mHandler;
1361
1362 // For async handler to identify request type
1363 private static final int SUPPLY_PIN_COMPLETE = 100;
1364
1365 public UnlockSim(IccCard simCard) {
1366 mSimCard = simCard;
1367 }
1368
1369 @Override
1370 public void run() {
1371 Looper.prepare();
1372 synchronized (UnlockSim.this) {
1373 mHandler = new Handler() {
1374 @Override
1375 public void handleMessage(Message msg) {
1376 AsyncResult ar = (AsyncResult) msg.obj;
1377 switch (msg.what) {
1378 case SUPPLY_PIN_COMPLETE:
1379 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1380 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001381 mRetryCount = msg.arg1;
1382 if (ar.exception != null) {
1383 if (ar.exception instanceof CommandException &&
1384 ((CommandException)(ar.exception)).getCommandError()
1385 == CommandException.Error.PASSWORD_INCORRECT) {
1386 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1387 } else {
1388 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1389 }
1390 } else {
1391 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 mDone = true;
1394 UnlockSim.this.notifyAll();
1395 }
1396 break;
1397 }
1398 }
1399 };
1400 UnlockSim.this.notifyAll();
1401 }
1402 Looper.loop();
1403 }
1404
1405 /*
1406 * Use PIN or PUK to unlock SIM card
1407 *
1408 * If PUK is null, unlock SIM card with PIN
1409 *
1410 * If PUK is not null, unlock SIM card with PUK and set PIN code
1411 */
Wink Saville9de0f752013-10-22 19:04:03 -07001412 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413
1414 while (mHandler == null) {
1415 try {
1416 wait();
1417 } catch (InterruptedException e) {
1418 Thread.currentThread().interrupt();
1419 }
1420 }
1421 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1422
1423 if (puk == null) {
1424 mSimCard.supplyPin(pin, callback);
1425 } else {
1426 mSimCard.supplyPuk(puk, pin, callback);
1427 }
1428
1429 while (!mDone) {
1430 try {
1431 Log.d(LOG_TAG, "wait for done");
1432 wait();
1433 } catch (InterruptedException e) {
1434 // Restore the interrupted status
1435 Thread.currentThread().interrupt();
1436 }
1437 }
1438 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001439 int[] resultArray = new int[2];
1440 resultArray[0] = mResult;
1441 resultArray[1] = mRetryCount;
1442 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001443 }
1444 }
1445
1446 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001447 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001448
1449 }
1450
Wink Savilleb564aae2014-10-23 10:18:09 -07001451 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001452 // No permission check needed here: this call is harmless, and it's
1453 // needed for the ServiceState.requestStateUpdate() call (which is
1454 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001455 final Phone phone = getPhone(subId);
1456 if (phone != null) {
1457 phone.updateServiceLocation();
1458 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 }
1460
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001461 @Override
1462 public boolean isRadioOn(String callingPackage) {
1463 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001464 }
1465
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001466 @Override
1467 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1468 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1469 return false;
1470 }
1471 return isRadioOnForSubscriber(subId);
1472 }
1473
1474 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001475 final Phone phone = getPhone(subId);
1476 if (phone != null) {
1477 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1478 } else {
1479 return false;
1480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 }
1482
1483 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001484 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001485
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486 }
Wink Saville36469e72014-06-11 15:17:00 -07001487
Wink Savilleb564aae2014-10-23 10:18:09 -07001488 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001490 final Phone phone = getPhone(subId);
1491 if (phone != null) {
1492 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1493 }
Wink Saville36469e72014-06-11 15:17:00 -07001494 }
1495
1496 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001497 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001498 }
1499
Wink Savilleb564aae2014-10-23 10:18:09 -07001500 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001501 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001502 final Phone phone = getPhone(subId);
1503 if (phone == null) {
1504 return false;
1505 }
1506 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001507 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001508 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 }
1510 return true;
1511 }
Wink Saville36469e72014-06-11 15:17:00 -07001512
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001513 public boolean needMobileRadioShutdown() {
1514 /*
1515 * If any of the Radios are available, it will need to be
1516 * shutdown. So return true if any Radio is available.
1517 */
1518 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1519 Phone phone = PhoneFactory.getPhone(i);
1520 if (phone != null && phone.isRadioAvailable()) return true;
1521 }
1522 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1523 return false;
1524 }
1525
1526 public void shutdownMobileRadios() {
1527 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1528 logv("Shutting down Phone " + i);
1529 shutdownRadioUsingPhoneId(i);
1530 }
1531 }
1532
1533 private void shutdownRadioUsingPhoneId(int phoneId) {
1534 enforceModifyPermission();
1535 Phone phone = PhoneFactory.getPhone(phoneId);
1536 if (phone != null && phone.isRadioAvailable()) {
1537 phone.shutdownRadio();
1538 }
1539 }
1540
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001541 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001542 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001543 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1544 if (defaultPhone != null) {
1545 defaultPhone.setRadioPower(turnOn);
1546 return true;
1547 } else {
1548 loge("There's no default phone.");
1549 return false;
1550 }
Wink Saville36469e72014-06-11 15:17:00 -07001551 }
1552
Wink Savilleb564aae2014-10-23 10:18:09 -07001553 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001555 final Phone phone = getPhone(subId);
1556 if (phone != null) {
1557 phone.setRadioPower(turnOn);
1558 return true;
1559 } else {
1560 return false;
1561 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001562 }
1563
Wink Saville36469e72014-06-11 15:17:00 -07001564 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001565 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 public boolean enableDataConnectivity() {
1567 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001568 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001569 final Phone phone = getPhone(subId);
1570 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001571 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001572 return true;
1573 } else {
1574 return false;
1575 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001576 }
1577
Wink Saville36469e72014-06-11 15:17:00 -07001578 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001579 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 public boolean disableDataConnectivity() {
1581 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001582 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001583 final Phone phone = getPhone(subId);
1584 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001585 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001586 return true;
1587 } else {
1588 return false;
1589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 }
1591
Sanket Padawe356d7632015-06-22 14:03:32 -07001592 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001593 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 final Phone phone = getPhone(subId);
1595 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001596 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001597 } else {
1598 return false;
1599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 }
1601
1602 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001603 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001604 }
1605
pkanwarae03a6b2016-11-06 20:37:09 -08001606 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001607 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001608 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1609 return;
1610 }
1611 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1612 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1613 };
1614
Wink Savilleb564aae2014-10-23 10:18:09 -07001615 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001616 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001617 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1618 return false;
1619 }
Wink Saville36469e72014-06-11 15:17:00 -07001620 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
1622
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001624 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001625 }
1626
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001627 public int getCallStateForSlot(int slotIndex) {
1628 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001629 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001630 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 }
1632
Sanket Padawe356d7632015-06-22 14:03:32 -07001633 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001635 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001636 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001637 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001638 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001639 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 }
1642
Sanket Padawe356d7632015-06-22 14:03:32 -07001643 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001645 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001646 if (phone != null) {
1647 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1648 } else {
1649 return TelephonyManager.DATA_ACTIVITY_NONE;
1650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 }
1652
1653 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001654 public Bundle getCellLocation(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001655 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001656 callingPackage, Binder.getCallingUid(), "getCellLocation")) {
Svetoslav64fad262015-04-14 14:35:21 -07001657 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
1659
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001660 if (DBG_LOC) log("getCellLocation: is active user");
1661 Bundle data = new Bundle();
1662 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1663 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 return null;
1665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001667 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1668 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1669 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001670 }
1671
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001673 public String getNetworkCountryIsoForPhone(int phoneId) {
1674 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1675 // registered cell info, so return a NULL country instead.
1676 final long identity = Binder.clearCallingIdentity();
1677 try {
1678 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1679 if (TelephonyManager.NETWORK_TYPE_IWLAN
1680 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1681 return "";
1682 }
1683 } finally {
1684 Binder.restoreCallingIdentity(identity);
1685 }
1686 return TelephonyManager.getTelephonyProperty(
1687 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1688 }
1689
1690 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001692 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001693 }
1694
Sanket Padawe356d7632015-06-22 14:03:32 -07001695 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001696 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 mApp.enforceCallingOrSelfPermission(
1698 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001699 final Phone phone = getPhone(subId);
1700 if (phone != null) {
1701 phone.enableLocationUpdates();
1702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 }
1704
1705 @Override
1706 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001707 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001708 }
1709
Sanket Padawe356d7632015-06-22 14:03:32 -07001710 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001711 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712 mApp.enforceCallingOrSelfPermission(
1713 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001714 final Phone phone = getPhone(subId);
1715 if (phone != null) {
1716 phone.disableLocationUpdates();
1717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 }
1719
1720 @Override
1721 @SuppressWarnings("unchecked")
1722 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001723 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001724 callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001725 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
1728 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1729 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1730 return null;
1731 }
Svetoslav64fad262015-04-14 14:35:21 -07001732
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001733 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001735 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001737 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1738 try {
1739 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1740 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1741 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1742 } catch (RuntimeException e) {
1743 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001745 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 }
1747
1748
1749 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001750 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001751 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001752 callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001753 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001754 }
1755
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001756 if (DBG_LOC) log("getAllCellInfo: is active user");
1757 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1758 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1759 for (Phone phone : PhoneFactory.getPhones()) {
1760 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1761 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001763 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001764 }
1765
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001766 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001767 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001768 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001769 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1770 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 }
1772
Shishir Agrawala9f32182016-04-12 12:00:16 -07001773 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001774 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001775 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1776 return null;
1777 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001778 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001779 return phone == null ? null : phone.getImei();
1780 }
1781
1782 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001783 public String getMeidForSlot(int slotIndex, String callingPackage) {
1784 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1785 return null;
1786 }
1787 Phone phone = PhoneFactory.getPhone(slotIndex);
1788 return phone == null ? null : phone.getMeid();
1789 }
1790
1791 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001792 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001793 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1794 return null;
1795 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001796 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001797 return phone == null ? null : phone.getDeviceSvn();
1798 }
1799
fionaxuf32acdf2017-11-27 22:51:16 -08001800 @Override
1801 public int getSubscriptionCarrierId(int subId) {
1802 final Phone phone = getPhone(subId);
1803 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1804 }
1805
1806 @Override
1807 public String getSubscriptionCarrierName(int subId) {
1808 final Phone phone = getPhone(subId);
1809 return phone == null ? null : phone.getCarrierName();
1810 }
1811
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 //
1813 // Internal helper methods.
1814 //
1815
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001816 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1818 *
1819 * @throws SecurityException if the caller does not have the required permission
1820 */
1821 private void enforceModifyPermission() {
1822 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1823 }
1824
1825 /**
Junda Liua2e36012014-07-09 18:30:01 -07001826 * Make sure either system app or the caller has carrier privilege.
1827 *
1828 * @throws SecurityException if the caller does not have the required permission/privilege
1829 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001830 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001831 int permission = mApp.checkCallingOrSelfPermission(
1832 android.Manifest.permission.MODIFY_PHONE_STATE);
1833 if (permission == PackageManager.PERMISSION_GRANTED) {
1834 return;
1835 }
1836
1837 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001838 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001839 }
1840
1841 /**
1842 * Make sure the caller has carrier privilege.
1843 *
1844 * @throws SecurityException if the caller does not have the required permission
1845 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001846 private void enforceCarrierPrivilege(int subId) {
1847 if (getCarrierPrivilegeStatus(subId) !=
1848 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001849 loge("No Carrier Privilege.");
1850 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001851 }
1852 }
1853
1854 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001855 * Make sure the caller has the CALL_PHONE permission.
1856 *
1857 * @throws SecurityException if the caller does not have the required permission
1858 */
1859 private void enforceCallPermission() {
1860 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1861 }
1862
Stuart Scott8eef64f2015-04-08 15:13:54 -07001863 private void enforceConnectivityInternalPermission() {
1864 mApp.enforceCallingOrSelfPermission(
1865 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1866 "ConnectivityService");
1867 }
1868
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 private String createTelUrl(String number) {
1870 if (TextUtils.isEmpty(number)) {
1871 return null;
1872 }
1873
Jake Hambye994d462014-02-03 13:10:13 -08001874 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 }
1876
Ihab Awadf9e92732013-12-05 18:02:52 -08001877 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1879 }
1880
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001881 private static void logv(String msg) {
1882 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1883 }
1884
Ihab Awadf9e92732013-12-05 18:02:52 -08001885 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1887 }
1888
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001889 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001891 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001892 }
1893
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001895 public int getActivePhoneTypeForSlot(int slotIndex) {
1896 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001897 if (phone == null) {
1898 return PhoneConstants.PHONE_TYPE_NONE;
1899 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001900 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 }
1903
1904 /**
1905 * Returns the CDMA ERI icon index to display
1906 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001907 @Override
1908 public int getCdmaEriIconIndex(String callingPackage) {
1909 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001910 }
1911
Sanket Padawe356d7632015-06-22 14:03:32 -07001912 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001913 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1914 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1915 return -1;
1916 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001917 final Phone phone = getPhone(subId);
1918 if (phone != null) {
1919 return phone.getCdmaEriIconIndex();
1920 } else {
1921 return -1;
1922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923 }
1924
1925 /**
1926 * Returns the CDMA ERI icon mode,
1927 * 0 - ON
1928 * 1 - FLASHING
1929 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001930 @Override
1931 public int getCdmaEriIconMode(String callingPackage) {
1932 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001933 }
1934
Sanket Padawe356d7632015-06-22 14:03:32 -07001935 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001936 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1937 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1938 return -1;
1939 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001940 final Phone phone = getPhone(subId);
1941 if (phone != null) {
1942 return phone.getCdmaEriIconMode();
1943 } else {
1944 return -1;
1945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 }
1947
1948 /**
1949 * Returns the CDMA ERI text,
1950 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001951 @Override
1952 public String getCdmaEriText(String callingPackage) {
1953 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001954 }
1955
Sanket Padawe356d7632015-06-22 14:03:32 -07001956 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001957 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1958 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1959 return null;
1960 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 final Phone phone = getPhone(subId);
1962 if (phone != null) {
1963 return phone.getCdmaEriText();
1964 } else {
1965 return null;
1966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 }
1968
1969 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001970 * Returns the CDMA MDN.
1971 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001972 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001973 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001974 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001975 final Phone phone = getPhone(subId);
1976 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1977 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001978 } else {
1979 return null;
1980 }
1981 }
1982
1983 /**
1984 * Returns the CDMA MIN.
1985 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001986 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001987 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001988 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001989 final Phone phone = getPhone(subId);
1990 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1991 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001992 } else {
1993 return null;
1994 }
1995 }
1996
1997 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 * Returns true if CDMA provisioning needs to run.
1999 */
2000 public boolean needsOtaServiceProvisioning() {
2001 return mPhone.needsOtaServiceProvisioning();
2002 }
2003
2004 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002005 * Sets the voice mail number of a given subId.
2006 */
2007 @Override
2008 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002009 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002010 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2011 new Pair<String, String>(alphaTag, number), new Integer(subId));
2012 return success;
2013 }
2014
Ta-wei Yen87c49842016-05-13 21:19:52 -07002015 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002016 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2017 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2018 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2019 if (!TextUtils.equals(callingPackage, systemDialer)) {
2020 throw new SecurityException("caller must be system dialer");
2021 }
2022 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2023 if (phoneAccountHandle == null){
2024 return null;
2025 }
2026 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2027 }
2028
2029 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002030 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002031 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2032 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2033 return null;
2034 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002035 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2036 }
2037
2038 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002039 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2040 VisualVoicemailSmsFilterSettings settings) {
2041 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002042 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002043 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2044 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002045 }
2046
2047 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002048 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2049 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002050 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002051 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002052 }
2053
2054 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002055 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2056 String callingPackage, int subId) {
2057 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002058 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002059 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002060 }
2061
2062 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002063 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002064 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002065 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002066 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2067 }
2068
2069 @Override
2070 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2071 String number, int port, String text, PendingIntent sentIntent) {
2072 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002073 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002074 enforceSendSmsPermission();
2075 // Make the calls as the phone process.
2076 final long identity = Binder.clearCallingIdentity();
2077 try {
2078 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2079 if (port == 0) {
2080 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2081 sentIntent, null, false);
2082 } else {
2083 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2084 smsManager.sendDataMessageWithSelfPermissions(number, null,
2085 (short) port, data, sentIntent, null);
2086 }
2087 } finally {
2088 Binder.restoreCallingIdentity(identity);
2089 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002090 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002091 /**
fionaxu0152e512016-11-14 13:36:14 -08002092 * Sets the voice activation state of a given subId.
2093 */
2094 @Override
2095 public void setVoiceActivationState(int subId, int activationState) {
2096 enforceModifyPermissionOrCarrierPrivilege(subId);
2097 final Phone phone = getPhone(subId);
2098 if (phone != null) {
2099 phone.setVoiceActivationState(activationState);
2100 } else {
2101 loge("setVoiceActivationState fails with invalid subId: " + subId);
2102 }
2103 }
2104
2105 /**
2106 * Sets the data activation state of a given subId.
2107 */
2108 @Override
2109 public void setDataActivationState(int subId, int activationState) {
2110 enforceModifyPermissionOrCarrierPrivilege(subId);
2111 final Phone phone = getPhone(subId);
2112 if (phone != null) {
2113 phone.setDataActivationState(activationState);
2114 } else {
2115 loge("setVoiceActivationState fails with invalid subId: " + subId);
2116 }
2117 }
2118
2119 /**
2120 * Returns the voice activation state of a given subId.
2121 */
2122 @Override
2123 public int getVoiceActivationState(int subId, String callingPackage) {
2124 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2125 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2126 }
2127 final Phone phone = getPhone(subId);
2128 if (phone != null) {
2129 return phone.getVoiceActivationState();
2130 } else {
2131 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2132 }
2133 }
2134
2135 /**
2136 * Returns the data activation state of a given subId.
2137 */
2138 @Override
2139 public int getDataActivationState(int subId, String callingPackage) {
2140 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2141 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2142 }
2143 final Phone phone = getPhone(subId);
2144 if (phone != null) {
2145 return phone.getDataActivationState();
2146 } else {
2147 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2148 }
2149 }
2150
2151 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 * Returns the unread count of voicemails
2153 */
2154 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002155 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002156 }
2157
2158 /**
2159 * Returns the unread count of voicemails for a subId
2160 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002161 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002162 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002163 final Phone phone = getPhone(subId);
2164 if (phone != null) {
2165 return phone.getVoiceMessageCount();
2166 } else {
2167 return 0;
2168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 }
2170
2171 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002172 * returns true, if the device is in a state where both voice and data
2173 * are supported simultaneously. This can change based on location or network condition.
2174 */
2175 @Override
2176 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2177 final Phone phone = getPhone(subId);
2178 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2179 }
2180
2181 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002182 * Send the dialer code if called from the current default dialer or the caller has
2183 * carrier privilege.
2184 * @param inputCode The dialer code to send
2185 */
2186 @Override
2187 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2188 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2189 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2190 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2191 enforceCarrierPrivilege(getDefaultSubscription());
2192 }
2193 mPhone.sendDialerSpecialCode(inputCode);
2194 }
2195
2196 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002197 * Returns the data network type.
2198 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 *
2200 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2201 */
2202 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002203 public int getNetworkType() {
2204 final Phone phone = getPhone(getDefaultSubscription());
2205 if (phone != null) {
2206 return phone.getServiceState().getDataNetworkType();
2207 } else {
2208 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2209 }
Wink Saville36469e72014-06-11 15:17:00 -07002210 }
2211
2212 /**
2213 * Returns the network type for a subId
2214 */
2215 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002216 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2217 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2218 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2219 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002220
Sanket Padawe356d7632015-06-22 14:03:32 -07002221 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002222 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002223 return phone.getServiceState().getDataNetworkType();
2224 } else {
2225 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 }
2228
2229 /**
2230 * Returns the data network type
2231 */
2232 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002233 public int getDataNetworkType(String callingPackage) {
2234 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002235 }
2236
2237 /**
2238 * Returns the data network type for a subId
2239 */
2240 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002241 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2242 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2243 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2244 }
2245
Sanket Padawe356d7632015-06-22 14:03:32 -07002246 final Phone phone = getPhone(subId);
2247 if (phone != null) {
2248 return phone.getServiceState().getDataNetworkType();
2249 } else {
2250 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 }
2253
2254 /**
Wink Saville36469e72014-06-11 15:17:00 -07002255 * Returns the Voice network type for a subId
2256 */
2257 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002258 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2259 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2260 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2261 }
2262
Sanket Padawe356d7632015-06-22 14:03:32 -07002263 final Phone phone = getPhone(subId);
2264 if (phone != null) {
2265 return phone.getServiceState().getVoiceNetworkType();
2266 } else {
2267 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2268 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 }
2270
2271 /**
2272 * @return true if a ICC card is present
2273 */
2274 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002275 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002276 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2277 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002278 }
2279
2280 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002281 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002282 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002283 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002284 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2285 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002286 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002287 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002288 } else {
2289 return false;
2290 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 }
2292
2293 /**
2294 * Return if the current radio is LTE on CDMA. This
2295 * is a tri-state return value as for a period of time
2296 * the mode may be unknown.
2297 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002298 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002300 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002302 @Override
2303 public int getLteOnCdmaMode(String callingPackage) {
2304 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002305 }
2306
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002308 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2309 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2310 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2311 }
2312
Sanket Padawe356d7632015-06-22 14:03:32 -07002313 final Phone phone = getPhone(subId);
2314 if (phone == null) {
2315 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2316 } else {
2317 return phone.getLteOnCdmaMode();
2318 }
Wink Saville36469e72014-06-11 15:17:00 -07002319 }
2320
2321 public void setPhone(Phone phone) {
2322 mPhone = phone;
2323 }
2324
2325 /**
2326 * {@hide}
2327 * Returns Default subId, 0 in the case of single standby.
2328 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002329 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002330 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002331 }
2332
Shishir Agrawala9f32182016-04-12 12:00:16 -07002333 private int getSlotForDefaultSubscription() {
2334 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2335 }
2336
Wink Savilleb564aae2014-10-23 10:18:09 -07002337 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002338 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002340
2341 /**
2342 * @see android.telephony.TelephonyManager.WifiCallingChoices
2343 */
2344 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002345 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2346 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002347 }
2348
2349 /**
2350 * @see android.telephony.TelephonyManager.WifiCallingChoices
2351 */
2352 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002353 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2354 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2355 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002356 }
2357
Sailesh Nepald1e68152013-12-12 19:08:02 -08002358 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002359 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002360 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002361 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002362
Shishir Agrawal566b7612013-10-28 14:41:00 -07002363 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002364 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2365 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002366 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002367
Derek Tan740e1672017-06-27 14:56:27 -07002368 if (TextUtils.equals(ISDR_AID, aid)) {
2369 // Only allows LPA to open logical channel to ISD-R.
2370 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2371 ComponentInfo bestComponent =
2372 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2373 if (bestComponent == null
2374 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2375 loge("The calling package is not allowed to access ISD-R.");
2376 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2377 }
2378 }
2379
2380 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002381 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002382 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002383 if (DBG) log("iccOpenLogicalChannel: " + response);
2384 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002385 }
2386
2387 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002388 public boolean iccCloseLogicalChannel(int subId, int channel) {
2389 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002390
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002391 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002392 if (channel < 0) {
2393 return false;
2394 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002395 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002396 if (DBG) log("iccCloseLogicalChannel: " + success);
2397 return success;
2398 }
2399
2400 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002401 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002402 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002403 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002404
2405 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002406 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2407 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002408 " data=" + data);
2409 }
2410
2411 if (channel < 0) {
2412 return "";
2413 }
2414
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002415 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002416 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002417 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2418
Shishir Agrawal566b7612013-10-28 14:41:00 -07002419 // Append the returned status code to the end of the response payload.
2420 String s = Integer.toHexString(
2421 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002422 if (response.payload != null) {
2423 s = IccUtils.bytesToHexString(response.payload) + s;
2424 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002425 return s;
2426 }
Jake Hambye994d462014-02-03 13:10:13 -08002427
Evan Charltonc66da362014-05-16 14:06:40 -07002428 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002429 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2430 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002431 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002432
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002433 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2434 && TextUtils.equals(ISDR_AID, data)) {
2435 // Only allows LPA to select ISD-R.
2436 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2437 ComponentInfo bestComponent =
2438 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2439 if (bestComponent == null
2440 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2441 loge("The calling package is not allowed to select ISD-R.");
2442 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2443 }
2444 }
2445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002446 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002447 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2448 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002449 }
2450
2451 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002452 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002453 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2454
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002455 // Append the returned status code to the end of the response payload.
2456 String s = Integer.toHexString(
2457 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002458 if (response.payload != null) {
2459 s = IccUtils.bytesToHexString(response.payload) + s;
2460 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002461 return s;
2462 }
2463
2464 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002465 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002466 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002467 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002468
2469 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002470 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002471 p1 + " " + p2 + " " + p3 + ":" + filePath);
2472 }
2473
2474 IccIoResult response =
2475 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002476 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2477 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002478
2479 if (DBG) {
2480 log("Exchange SIM_IO [R]" + response);
2481 }
2482
2483 byte[] result = null;
2484 int length = 2;
2485 if (response.payload != null) {
2486 length = 2 + response.payload.length;
2487 result = new byte[length];
2488 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2489 } else {
2490 result = new byte[length];
2491 }
2492
2493 result[length - 1] = (byte) response.sw2;
2494 result[length - 2] = (byte) response.sw1;
2495 return result;
2496 }
2497
Nathan Haroldb3014052017-01-25 15:57:32 -08002498 /**
2499 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2500 * on a particular subscription
2501 */
2502 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002503 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2504 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002505 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2506 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2507 return null;
2508 }
2509 Object response = sendRequest(
2510 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2511 if (response instanceof String[]) {
2512 return (String[]) response;
2513 }
2514 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2515 return null;
2516 }
2517
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002518 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002519 public String sendEnvelopeWithStatus(int subId, String content) {
2520 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002521
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002522 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002523 if (response.payload == null) {
2524 return "";
2525 }
2526
2527 // Append the returned status code to the end of the response payload.
2528 String s = Integer.toHexString(
2529 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2530 s = IccUtils.bytesToHexString(response.payload) + s;
2531 return s;
2532 }
2533
Jake Hambye994d462014-02-03 13:10:13 -08002534 /**
2535 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2536 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2537 *
2538 * @param itemID the ID of the item to read
2539 * @return the NV item as a String, or null on error.
2540 */
2541 @Override
2542 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002543 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002544 if (DBG) log("nvReadItem: item " + itemID);
2545 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2546 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2547 return value;
2548 }
2549
2550 /**
2551 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2552 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2553 *
2554 * @param itemID the ID of the item to read
2555 * @param itemValue the value to write, as a String
2556 * @return true on success; false on any failure
2557 */
2558 @Override
2559 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002560 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002561 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2562 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2563 new Pair<Integer, String>(itemID, itemValue));
2564 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2565 return success;
2566 }
2567
2568 /**
2569 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2570 * Used for device configuration by some CDMA operators.
2571 *
2572 * @param preferredRoamingList byte array containing the new PRL
2573 * @return true on success; false on any failure
2574 */
2575 @Override
2576 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002577 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002578 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2579 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2580 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2581 return success;
2582 }
2583
2584 /**
2585 * Perform the specified type of NV config reset.
2586 * Used for device configuration by some CDMA operators.
2587 *
2588 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2589 * @return true on success; false on any failure
2590 */
2591 @Override
2592 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002593 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002594 if (DBG) log("nvResetConfig: type " + resetType);
2595 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2596 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2597 return success;
2598 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002599
2600 /**
Wink Saville36469e72014-06-11 15:17:00 -07002601 * {@hide}
2602 * Returns Default sim, 0 in the case of single standby.
2603 */
2604 public int getDefaultSim() {
2605 //TODO Need to get it from Telephony Devcontroller
2606 return 0;
2607 }
2608
Svet Ganovb320e182015-04-16 12:30:10 -07002609 public String[] getPcscfAddress(String apnType, String callingPackage) {
2610 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2611 return new String[0];
2612 }
2613
2614
ram87fca6f2014-07-18 18:58:44 +05302615 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002616 }
2617
Brad Ebinger51f743a2017-01-23 13:50:20 -08002618 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002619 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2620 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002621 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002622 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002623 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002624 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002625 }
2626
2627 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002628 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2629 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002630 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002631 public void disableIms(int slotId) {
2632 enforceModifyPermission();
2633 PhoneFactory.getImsResolver().disableIms(slotId);
2634 }
2635
2636 /**
2637 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2638 * feature or {@link null} if the service is not available. If the feature is available, the
2639 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2640 */
2641 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002642 IImsServiceFeatureCallback callback) {
2643 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002644 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002645 }
2646
2647 /**
2648 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2649 * feature during emergency calling or {@link null} if the service is not available. If the
2650 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2651 * listener for feature updates.
2652 */
2653 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2654 enforceModifyPermission();
2655 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002656 }
2657
Brad Ebinger7e934f52017-12-14 14:26:15 -08002658 /**
2659 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2660 * specified.
2661 */
2662 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2663 enforceModifyPermission();
2664 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2665 }
2666
Brad Ebingera12246d2018-01-16 09:39:35 -08002667 /**
2668 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2669 * specified.
2670 */
2671 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2672 enforceModifyPermission();
2673 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2674 }
2675
Wink Saville36469e72014-06-11 15:17:00 -07002676 public void setImsRegistrationState(boolean registered) {
2677 enforceModifyPermission();
2678 mPhone.setImsRegistrationState(registered);
2679 }
2680
2681 /**
Stuart Scott54788802015-03-30 13:18:01 -07002682 * Set the network selection mode to automatic.
2683 *
2684 */
2685 @Override
2686 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002687 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002688 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2689 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2690 }
2691
2692 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002693 * Set the network selection mode to manual with the selected carrier.
2694 */
2695 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002696 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002697 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002698 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002699 OperatorInfo operator = new OperatorInfo(
2700 /* operatorAlphaLong */ "",
2701 /* operatorAlphaShort */ "",
2702 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002703 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002704 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2705 persistSelection);
2706 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002707 }
2708
2709 /**
2710 * Scans for available networks.
2711 */
2712 @Override
2713 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002714 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002715 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2716 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2717 CMD_PERFORM_NETWORK_SCAN, null, subId);
2718 return result;
2719 }
2720
2721 /**
yinxub1bed742017-04-17 11:45:04 -07002722 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002723 *
yinxub1bed742017-04-17 11:45:04 -07002724 * @param subId id of the subscription
2725 * @param request contains the radio access networks with bands/channels to scan
2726 * @param messenger callback messenger for scan results or errors
2727 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002728 * @return the id of the requested scan which can be used to stop the scan.
2729 */
2730 @Override
2731 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2732 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002733 enforceModifyPermissionOrCarrierPrivilege(subId);
2734 return mNetworkScanRequestTracker.startNetworkScan(
2735 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002736 }
2737
2738 /**
2739 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002740 *
2741 * @param subId id of the subscription
2742 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002743 */
2744 @Override
2745 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002746 enforceModifyPermissionOrCarrierPrivilege(subId);
2747 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002748 }
2749
2750 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002751 * Get the calculated preferred network type.
2752 * Used for debugging incorrect network type.
2753 *
2754 * @return the preferred network type, defined in RILConstants.java.
2755 */
2756 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002757 public int getCalculatedPreferredNetworkType(String callingPackage) {
2758 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2759 return RILConstants.PREFERRED_NETWORK_MODE;
2760 }
2761
Amit Mahajan43330e02014-11-18 11:54:45 -08002762 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002763 }
2764
2765 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002766 * Get the preferred network type.
2767 * Used for device configuration by some CDMA operators.
2768 *
2769 * @return the preferred network type, defined in RILConstants.java.
2770 */
2771 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002772 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002773 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002774 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002775 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002776 int networkType = (result != null ? result[0] : -1);
2777 if (DBG) log("getPreferredNetworkType: " + networkType);
2778 return networkType;
2779 }
2780
2781 /**
2782 * Set the preferred network type.
2783 * Used for device configuration by some CDMA operators.
2784 *
2785 * @param networkType the preferred network type, defined in RILConstants.java.
2786 * @return true on success; false on any failure.
2787 */
2788 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002789 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002790 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002791 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2792 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002793 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002794 if (success) {
2795 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002796 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002797 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002798 return success;
2799 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002800
2801 /**
Junda Liu475951f2014-11-07 16:45:03 -08002802 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2803 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2804 * tethering.
2805 *
2806 * @return 0: Not required. 1: required. 2: Not set.
2807 * @hide
2808 */
2809 @Override
2810 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002811 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002812 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2813 Settings.Global.TETHER_DUN_REQUIRED, 2);
2814 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2815 // config_tether_apndata.
2816 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2817 dunRequired = 1;
2818 }
2819 return dunRequired;
2820 }
2821
2822 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002823 * Set mobile data enabled
2824 * Used by the user through settings etc to turn on/off mobile data
2825 *
2826 * @param enable {@code true} turn turn data on, else {@code false}
2827 */
2828 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002829 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002830 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002831 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002832 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002833 Phone phone = PhoneFactory.getPhone(phoneId);
2834 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002835 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2836 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002837 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002838 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002839 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002840 }
2841
2842 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002843 * Get the user enabled state of Mobile Data.
2844 *
2845 * TODO: remove and use isUserDataEnabled.
2846 * This can't be removed now because some vendor codes
2847 * calls through ITelephony directly while they should
2848 * use TelephonyManager.
2849 *
2850 * @return true on enabled
2851 */
2852 @Override
2853 public boolean getDataEnabled(int subId) {
2854 return isUserDataEnabled(subId);
2855 }
2856
2857 /**
2858 * Get whether mobile data is enabled per user setting.
2859 *
2860 * There are other factors deciding whether mobile data is actually enabled, but they are
2861 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002862 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002863 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002864 *
2865 * @return {@code true} if data is enabled else {@code false}
2866 */
2867 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002868 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002869 try {
2870 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2871 null);
2872 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002873 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002874 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002875 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002876 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002877 Phone phone = PhoneFactory.getPhone(phoneId);
2878 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002879 boolean retVal = phone.isUserDataEnabled();
2880 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002881 return retVal;
2882 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002883 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2884 return false;
2885 }
2886 }
2887
2888 /**
2889 * Get whether mobile data is enabled.
2890 *
2891 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2892 * whether mobile data is actually enabled.
2893 *
2894 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2895 *
2896 * @return {@code true} if data is enabled else {@code false}
2897 */
2898 @Override
2899 public boolean isDataEnabled(int subId) {
2900 try {
2901 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2902 null);
2903 } catch (Exception e) {
2904 enforceModifyPermissionOrCarrierPrivilege(subId);
2905 }
2906 int phoneId = mSubscriptionController.getPhoneId(subId);
2907 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2908 Phone phone = PhoneFactory.getPhone(phoneId);
2909 if (phone != null) {
2910 boolean retVal = phone.isDataEnabled();
2911 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2912 return retVal;
2913 } else {
2914 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002915 return false;
2916 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002917 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002918
2919 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002920 public int getCarrierPrivilegeStatus(int subId) {
2921 final Phone phone = getPhone(subId);
2922 if (phone == null) {
2923 loge("getCarrierPrivilegeStatus: Invalid subId");
2924 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2925 }
2926 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002927 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002928 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002929 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2930 }
2931 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002932 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002933 }
Junda Liu29340342014-07-10 15:23:27 -07002934
2935 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002936 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002937 if (TextUtils.isEmpty(pkgName))
2938 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002939 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002940 if (card == null) {
2941 loge("checkCarrierPrivilegesForPackage: No UICC");
2942 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2943 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002944 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2945 }
2946
2947 @Override
2948 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002949 if (TextUtils.isEmpty(pkgName))
2950 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002951 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2952 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2953 UiccCard card = UiccController.getInstance().getUiccCard(i);
2954 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002955 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002956 continue;
2957 }
2958
2959 result = card.getCarrierPrivilegeStatus(
2960 mPhone.getContext().getPackageManager(), pkgName);
2961 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2962 break;
2963 }
2964 }
2965
2966 return result;
Junda Liu29340342014-07-10 15:23:27 -07002967 }
Derek Tan89e89d42014-07-08 17:00:10 -07002968
2969 @Override
Junda Liue64de782015-04-16 17:19:16 -07002970 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2971 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2972 loge("phoneId " + phoneId + " is not valid.");
2973 return null;
2974 }
2975 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002976 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002977 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002978 return null ;
2979 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002980 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002981 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002982 }
2983
Amith Yamasani6e118872016-02-19 12:53:51 -08002984 @Override
2985 public List<String> getPackagesWithCarrierPrivileges() {
2986 PackageManager pm = mPhone.getContext().getPackageManager();
2987 List<String> privilegedPackages = new ArrayList<>();
2988 List<PackageInfo> packages = null;
2989 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2990 UiccCard card = UiccController.getInstance().getUiccCard(i);
2991 if (card == null) {
2992 // No UICC in that slot.
2993 continue;
2994 }
2995 if (card.hasCarrierPrivilegeRules()) {
2996 if (packages == null) {
2997 // Only check packages in user 0 for now
2998 packages = pm.getInstalledPackagesAsUser(
2999 PackageManager.MATCH_DISABLED_COMPONENTS
3000 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3001 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3002 }
3003 for (int p = packages.size() - 1; p >= 0; p--) {
3004 PackageInfo pkgInfo = packages.get(p);
3005 if (pkgInfo != null && pkgInfo.packageName != null
3006 && card.getCarrierPrivilegeStatus(pkgInfo)
3007 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3008 privilegedPackages.add(pkgInfo.packageName);
3009 }
3010 }
3011 }
3012 }
3013 return privilegedPackages;
3014 }
3015
Wink Savilleb564aae2014-10-23 10:18:09 -07003016 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003017 final Phone phone = getPhone(subId);
3018 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003019 if (card == null) {
3020 loge("getIccId: No UICC");
3021 return null;
3022 }
3023 String iccId = card.getIccId();
3024 if (TextUtils.isEmpty(iccId)) {
3025 loge("getIccId: ICC ID is null or empty.");
3026 return null;
3027 }
3028 return iccId;
3029 }
3030
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003031 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003032 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3033 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003034 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07003035
Jeff Sharkey85190e62014-12-05 09:40:12 -08003036 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003037 final Phone phone = getPhone(subId);
3038 if (phone == null) {
3039 return false;
3040 }
3041 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003042
3043 if (DBG_MERGE) {
3044 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3045 + subscriberId + " to " + number);
3046 }
3047
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003048 if (TextUtils.isEmpty(iccId)) {
3049 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003050 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003051
Jeff Sharkey85190e62014-12-05 09:40:12 -08003052 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3053
3054 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003055 if (alphaTag == null) {
3056 editor.remove(alphaTagPrefKey);
3057 } else {
3058 editor.putString(alphaTagPrefKey, alphaTag);
3059 }
3060
Jeff Sharkey85190e62014-12-05 09:40:12 -08003061 // Record both the line number and IMSI for this ICCID, since we need to
3062 // track all merged IMSIs based on line number
3063 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3064 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003065 if (number == null) {
3066 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003067 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003068 } else {
3069 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003070 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003071 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003072
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003073 editor.commit();
3074 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003075 }
3076
3077 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003078 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003079 // This is open to apps with WRITE_SMS.
3080 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003081 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003082 return null;
3083 }
Derek Tan97ebb422014-09-05 16:55:38 -07003084
3085 String iccId = getIccId(subId);
3086 if (iccId != null) {
3087 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003088 if (DBG_MERGE) {
3089 log("getLine1NumberForDisplay returning " +
3090 mTelephonySharedPreferences.getString(numberPrefKey, null));
3091 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003092 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003093 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003094 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003095 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003096 }
3097
3098 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003099 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3100 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3101 return null;
3102 }
Derek Tan97ebb422014-09-05 16:55:38 -07003103
3104 String iccId = getIccId(subId);
3105 if (iccId != null) {
3106 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003107 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003108 }
Derek Tan97ebb422014-09-05 16:55:38 -07003109 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003110 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003111
3112 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003113 public String[] getMergedSubscriberIds(String callingPackage) {
3114 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3115 return null;
3116 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003117 final Context context = mPhone.getContext();
3118 final TelephonyManager tele = TelephonyManager.from(context);
3119 final SubscriptionManager sub = SubscriptionManager.from(context);
3120
3121 // Figure out what subscribers are currently active
3122 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003123 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3124 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3125 final long identity = Binder.clearCallingIdentity();
3126 try {
3127 final int[] subIds = sub.getActiveSubscriptionIdList();
3128 for (int subId : subIds) {
3129 activeSubscriberIds.add(tele.getSubscriberId(subId));
3130 }
3131 } finally {
3132 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003133 }
3134
3135 // First pass, find a number override for an active subscriber
3136 String mergeNumber = null;
3137 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3138 for (String key : prefs.keySet()) {
3139 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3140 final String subscriberId = (String) prefs.get(key);
3141 if (activeSubscriberIds.contains(subscriberId)) {
3142 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3143 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3144 mergeNumber = (String) prefs.get(numberKey);
3145 if (DBG_MERGE) {
3146 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3147 + " for active subscriber " + subscriberId);
3148 }
3149 if (!TextUtils.isEmpty(mergeNumber)) {
3150 break;
3151 }
3152 }
3153 }
3154 }
3155
3156 // Shortcut when no active merged subscribers
3157 if (TextUtils.isEmpty(mergeNumber)) {
3158 return null;
3159 }
3160
3161 // Second pass, find all subscribers under that line override
3162 final ArraySet<String> result = new ArraySet<>();
3163 for (String key : prefs.keySet()) {
3164 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3165 final String number = (String) prefs.get(key);
3166 if (mergeNumber.equals(number)) {
3167 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3168 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3169 final String subscriberId = (String) prefs.get(subscriberKey);
3170 if (!TextUtils.isEmpty(subscriberId)) {
3171 result.add(subscriberId);
3172 }
3173 }
3174 }
3175 }
3176
3177 final String[] resultArray = result.toArray(new String[result.size()]);
3178 Arrays.sort(resultArray);
3179 if (DBG_MERGE) {
3180 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3181 }
3182 return resultArray;
3183 }
3184
3185 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003186 public boolean setOperatorBrandOverride(int subId, String brand) {
3187 enforceCarrierPrivilege(subId);
3188 final Phone phone = getPhone(subId);
3189 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003190 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003191
3192 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003193 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003194 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3195 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003196 enforceCarrierPrivilege(subId);
3197 final Phone phone = getPhone(subId);
3198 if (phone == null) {
3199 return false;
3200 }
3201 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003202 cdmaNonRoamingList);
3203 }
3204
3205 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003206 public void setRadioCapability(RadioAccessFamily[] rafs) {
3207 try {
3208 ProxyController.getInstance().setRadioCapability(rafs);
3209 } catch (RuntimeException e) {
3210 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3211 }
3212 }
3213
3214 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003215 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3216 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3217 return RadioAccessFamily.RAF_UNKNOWN;
3218 }
3219
Wink Saville5d475dd2014-10-17 15:00:58 -07003220 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3221 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003222
3223 @Override
3224 public void enableVideoCalling(boolean enable) {
3225 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003226 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003227 }
3228
3229 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003230 public boolean isVideoCallingEnabled(String callingPackage) {
3231 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3232 return false;
3233 }
3234
Andrew Lee77527ac2014-10-21 16:57:39 -07003235 // Check the user preference and the system-level IMS setting. Even if the user has
3236 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3237 // In the long run, we may instead need to check if there exists a connection service
3238 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003239 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3240 return imsManager.isVtEnabledByPlatform()
3241 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3242 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003243 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003244
Andrew Leea1239f22015-03-02 17:44:07 -08003245 @Override
3246 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003247 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003248 }
3249
3250 @Override
3251 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003252 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003253 }
3254
Andrew Lee9431b832015-03-09 18:46:45 -07003255 @Override
3256 public boolean isTtyModeSupported() {
3257 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3258 TelephonyManager telephonyManager =
3259 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003260 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003261 }
3262
3263 @Override
3264 public boolean isHearingAidCompatibilitySupported() {
3265 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3266 }
3267
Sanket Padawe7310cc72015-01-14 09:53:20 -08003268 /**
3269 * Returns the unique device ID of phone, for example, the IMEI for
3270 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3271 *
3272 * <p>Requires Permission:
3273 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3274 */
3275 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003276 public String getDeviceId(String callingPackage) {
3277 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3278 return null;
3279 }
3280
Sanket Padawe7310cc72015-01-14 09:53:20 -08003281 final Phone phone = PhoneFactory.getPhone(0);
3282 if (phone != null) {
3283 return phone.getDeviceId();
3284 } else {
3285 return null;
3286 }
3287 }
3288
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003289 /*
3290 * {@hide}
3291 * Returns the IMS Registration Status
3292 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003293 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003294 public boolean isImsRegistered() {
3295 return mPhone.isImsRegistered();
3296 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003297
Ping Sun014fe8e2016-03-02 19:16:45 +08003298 /**
3299 * {@hide}
3300 * Returns the IMS Registration Status on a particular subid
3301 *
3302 * @param subId
3303 */
3304 public boolean isImsRegisteredForSubscriber(int subId) {
3305 Phone phone = getPhone(subId);
3306 if (phone != null) {
3307 return phone.isImsRegistered();
3308 } else {
3309 return false;
3310 }
3311 }
3312
Santos Cordon7a1885b2015-02-03 11:15:19 -08003313 @Override
3314 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3315 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3316 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003317
Nathan Haroldc55097a2015-03-11 18:14:50 -07003318 /*
3319 * {@hide}
3320 * Returns the IMS Registration Status
3321 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003322 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003323 return mPhone.isWifiCallingEnabled();
3324 }
3325
3326 /*
3327 * {@hide}
3328 * Returns the IMS Registration Status
3329 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003330 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003331 return mPhone.isVolteEnabled();
3332 }
Svet Ganovb320e182015-04-16 12:30:10 -07003333
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003334 /*
3335 * {@hide} Returns the IMS Registration Status
3336 */
3337 public boolean isVideoTelephonyAvailable() {
3338 return mPhone.isVideoEnabled();
3339 }
3340
Svet Ganovb320e182015-04-16 12:30:10 -07003341 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003342 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003343 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003344 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3345
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003346 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003347 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003348 } catch (SecurityException e) {
3349 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3350 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003351 }
Svet Ganovb320e182015-04-16 12:30:10 -07003352
3353 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3354 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3355 return false;
3356 }
3357
3358 return true;
3359 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003360
Makoto Onukifee69342015-06-29 14:44:50 -07003361 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003362 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003363 */
3364 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003365 // Default SMS app can always read it.
3366 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3367 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3368 return true;
3369 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003370
Makoto Onukie4072d12015-08-03 15:12:23 -07003371 try {
3372 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003373 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003374 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003375 // Can be read with READ_SMS too.
3376 try {
3377 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3378 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3379 if (opCode != AppOpsManager.OP_NONE) {
3380 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3381 == AppOpsManager.MODE_ALLOWED;
3382 } else {
3383 return true;
3384 }
3385 } catch (SecurityException readSmsSecurityException) {
3386 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003387 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003388 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003389 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003390 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003391 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003392 if (opCode != AppOpsManager.OP_NONE) {
3393 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3394 == AppOpsManager.MODE_ALLOWED;
3395 } else {
3396 return true;
3397 }
3398 } catch (SecurityException readPhoneNumberSecurityException) {
3399 }
3400
3401 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3402 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3403 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003404 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003405 }
3406
Stuart Scott8eef64f2015-04-08 15:13:54 -07003407 @Override
3408 public void factoryReset(int subId) {
3409 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003410 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3411 return;
3412 }
3413
Svet Ganovcc087f82015-05-12 20:35:54 -07003414 final long identity = Binder.clearCallingIdentity();
3415 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003416 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3417 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003418 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003419 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003420 // Set network selection mode to automatic
3421 setNetworkSelectionModeAutomatic(subId);
3422 // Set preferred mobile network type to the best available
3423 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3424 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003425 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003426 }
3427 } finally {
3428 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003429 }
3430 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003431
3432 @Override
3433 public String getLocaleFromDefaultSim() {
3434 // We query all subscriptions instead of just the active ones, because
3435 // this might be called early on in the provisioning flow when the
3436 // subscriptions potentially aren't active yet.
3437 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3438 if (slist == null || slist.isEmpty()) {
3439 return null;
3440 }
3441
3442 // This function may be called very early, say, from the setup wizard, at
3443 // which point we won't have a default subscription set. If that's the case
3444 // we just choose the first, which will be valid in "most cases".
3445 final int defaultSubId = getDefaultSubscription();
3446 SubscriptionInfo info = null;
3447 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3448 info = slist.get(0);
3449 } else {
3450 for (SubscriptionInfo item : slist) {
3451 if (item.getSubscriptionId() == defaultSubId) {
3452 info = item;
3453 break;
3454 }
3455 }
3456
3457 if (info == null) {
3458 return null;
3459 }
3460 }
3461
3462 // Try and fetch the locale from the carrier properties or from the SIM language
3463 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003464 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003465 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003466 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003467 if (defaultPhone != null) {
3468 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3469 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003470 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003471 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3472 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003473 } else {
3474 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003475 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003476 }
3477 }
3478
Narayan Kamath011676f2015-07-29 12:04:08 +01003479 // The SIM language preferences only store a language (e.g. fr = French), not an
3480 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3481 // the SIM and carrier preferences does not include a country we add the country
3482 // determined from the SIM MCC to provide an exact locale.
3483 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003484 if (mccLocale != null) {
3485 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3486 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003487 }
3488
Tony Hill183b2de2015-06-24 14:53:58 +01003489 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003490 return null;
3491 }
3492
3493 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3494 final long identity = Binder.clearCallingIdentity();
3495 try {
3496 return mSubscriptionController.getAllSubInfoList(
3497 mPhone.getContext().getOpPackageName());
3498 } finally {
3499 Binder.restoreCallingIdentity(identity);
3500 }
3501 }
3502
3503 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3504 final long identity = Binder.clearCallingIdentity();
3505 try {
3506 return mSubscriptionController.getActiveSubscriptionInfoList(
3507 mPhone.getContext().getOpPackageName());
3508 } finally {
3509 Binder.restoreCallingIdentity(identity);
3510 }
3511 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003512
3513 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003514 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3515 * representing the state of the modem.
3516 *
3517 * NOTE: This clears the modem state, so there should only every be one caller.
3518 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003519 */
3520 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003521 public void requestModemActivityInfo(ResultReceiver result) {
3522 enforceModifyPermission();
3523
3524 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3525 Bundle bundle = new Bundle();
3526 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3527 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003528 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003529
3530 /**
3531 * {@hide}
3532 * Returns the service state information on specified subscription.
3533 */
3534 @Override
3535 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3536
3537 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3538 return null;
3539 }
3540
3541 final Phone phone = getPhone(subId);
3542 if (phone == null) {
3543 return null;
3544 }
3545
3546 return phone.getServiceState();
3547 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003548
3549 /**
3550 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3551 *
3552 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3553 * voicemail ringtone.
3554 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3555 * PhoneAccount.
3556 */
3557 @Override
3558 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003559 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003560 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003561 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003562 }
3563
fionaxu7ed723d2017-05-30 18:58:54 -07003564 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003565 }
3566
3567 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003568 * Sets the per-account voicemail ringtone.
3569 *
3570 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3571 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3572 *
3573 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3574 * voicemail ringtone.
3575 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3576 * PhoneAccount.
3577 */
3578 @Override
3579 public void setVoicemailRingtoneUri(String callingPackage,
3580 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3581 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3582 if (!TextUtils.equals(callingPackage,
3583 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3584 enforceModifyPermissionOrCarrierPrivilege(
3585 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3586 }
3587 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3588 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003589 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003590 }
fionaxu7ed723d2017-05-30 18:58:54 -07003591 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003592 }
3593
3594 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003595 * Returns whether vibration is set for voicemail notification in Phone settings.
3596 *
3597 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3598 * voicemail vibration setting.
3599 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3600 */
3601 @Override
3602 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003603 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003604 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003605 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003606 }
3607
fionaxu7ed723d2017-05-30 18:58:54 -07003608 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003609 }
3610
Youhan Wange64578a2016-05-02 15:32:42 -07003611 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003612 * Sets the per-account voicemail vibration.
3613 *
3614 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3615 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3616 *
3617 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3618 * voicemail vibration setting.
3619 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3620 * specific PhoneAccount.
3621 */
3622 @Override
3623 public void setVoicemailVibrationEnabled(String callingPackage,
3624 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3625 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3626 if (!TextUtils.equals(callingPackage,
3627 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3628 enforceModifyPermissionOrCarrierPrivilege(
3629 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3630 }
3631
3632 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3633 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003634 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003635 }
fionaxu7ed723d2017-05-30 18:58:54 -07003636 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003637 }
3638
3639 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003640 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3641 *
3642 * @throws SecurityException if the caller does not have the required permission
3643 */
3644 private void enforceReadPrivilegedPermission() {
3645 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3646 null);
3647 }
3648
3649 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003650 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3651 * permission.
3652 *
3653 * @throws SecurityException if the caller does not have the required permission
3654 */
3655 private void enforceSendSmsPermission() {
3656 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3657 }
3658
3659 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003660 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003661 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003662 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003663 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003664 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003665 ComponentName componentName =
3666 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3667 if(componentName == null) {
3668 throw new SecurityException("Caller not current active visual voicemail package[null]");
3669 }
3670 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003671 if (!callingPackage.equals(vvmPackage)) {
3672 throw new SecurityException("Caller not current active visual voicemail package[" +
3673 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003674 }
3675 }
3676
3677 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003678 * Return the application ID for the app type.
3679 *
3680 * @param subId the subscription ID that this request applies to.
3681 * @param appType the uicc app type.
3682 * @return Application ID for specificied app type, or null if no uicc.
3683 */
3684 @Override
3685 public String getAidForAppType(int subId, int appType) {
3686 enforceReadPrivilegedPermission();
3687 Phone phone = getPhone(subId);
3688 if (phone == null) {
3689 return null;
3690 }
3691 String aid = null;
3692 try {
3693 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3694 .getApplicationByType(appType).getAid();
3695 } catch (Exception e) {
3696 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3697 }
3698 return aid;
3699 }
3700
Youhan Wang4001d252016-05-11 10:29:41 -07003701 /**
3702 * Return the Electronic Serial Number.
3703 *
3704 * @param subId the subscription ID that this request applies to.
3705 * @return ESN or null if error.
3706 */
3707 @Override
3708 public String getEsn(int subId) {
3709 enforceReadPrivilegedPermission();
3710 Phone phone = getPhone(subId);
3711 if (phone == null) {
3712 return null;
3713 }
3714 String esn = null;
3715 try {
3716 esn = phone.getEsn();
3717 } catch (Exception e) {
3718 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3719 }
3720 return esn;
3721 }
3722
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003723 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003724 * Return the Preferred Roaming List Version.
3725 *
3726 * @param subId the subscription ID that this request applies to.
3727 * @return PRLVersion or null if error.
3728 */
3729 @Override
3730 public String getCdmaPrlVersion(int subId) {
3731 enforceReadPrivilegedPermission();
3732 Phone phone = getPhone(subId);
3733 if (phone == null) {
3734 return null;
3735 }
3736 String cdmaPrlVersion = null;
3737 try {
3738 cdmaPrlVersion = phone.getCdmaPrlVersion();
3739 } catch (Exception e) {
3740 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3741 }
3742 return cdmaPrlVersion;
3743 }
3744
3745 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003746 * Get snapshot of Telephony histograms
3747 * @return List of Telephony histograms
3748 * @hide
3749 */
3750 @Override
3751 public List<TelephonyHistogram> getTelephonyHistograms() {
3752 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3753 return RIL.getTelephonyRILTimingHistograms();
3754 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003755
3756 /**
3757 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003758 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003759 * Require system privileges. In the future we may add this to carrier APIs.
3760 *
3761 * @return The number of carriers set successfully, should match length of carriers
3762 */
3763 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003764 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003765 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003766
Meng Wang9b7c4e92017-02-17 11:41:27 -08003767 if (carriers == null) {
3768 throw new NullPointerException("carriers cannot be null");
3769 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003770
3771 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003772 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3773 return retVal[0];
3774 }
3775
3776 /**
3777 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003778 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003779 * Require system privileges. In the future we may add this to carrier APIs.
3780 *
3781 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3782 * means all carriers are allowed.
3783 */
3784 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003785 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003786 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003787 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003788 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3789 }
3790
fionaxu59545b42016-05-25 15:53:37 -07003791 /**
3792 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3793 * @param subId the subscription ID that this action applies to.
3794 * @param enabled control enable or disable metered apns.
3795 * {@hide}
3796 */
3797 @Override
3798 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3799 enforceModifyPermission();
3800 final Phone phone = getPhone(subId);
3801 if (phone == null) {
3802 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3803 return;
3804 }
3805 try {
3806 phone.carrierActionSetMeteredApnsEnabled(enabled);
3807 } catch (Exception e) {
3808 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3809 }
3810 }
3811
3812 /**
3813 * Action set from carrier signalling broadcast receivers to enable/disable radio
3814 * @param subId the subscription ID that this action applies to.
3815 * @param enabled control enable or disable radio.
3816 * {@hide}
3817 */
3818 @Override
3819 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3820 enforceModifyPermission();
3821 final Phone phone = getPhone(subId);
3822 if (phone == null) {
3823 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3824 return;
3825 }
3826 try {
3827 phone.carrierActionSetRadioEnabled(enabled);
3828 } catch (Exception e) {
3829 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3830 }
3831 }
3832
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003833 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003834 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3835 * network status based on which carrier apps could apply actions accordingly,
3836 * enable/disable default url handler for example.
3837 *
3838 * @param subId the subscription ID that this action applies to.
3839 * @param report control start/stop reporting the default network status.
3840 * {@hide}
3841 */
3842 @Override
3843 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3844 enforceModifyPermission();
3845 final Phone phone = getPhone(subId);
3846 if (phone == null) {
3847 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3848 return;
3849 }
3850 try {
3851 phone.carrierActionReportDefaultNetworkStatus(report);
3852 } catch (Exception e) {
3853 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3854 }
3855 }
3856
3857 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003858 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3859 * bug report is being generated.
3860 */
3861 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003862 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003863 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3864 != PackageManager.PERMISSION_GRANTED) {
3865 writer.println("Permission Denial: can't dump Phone from pid="
3866 + Binder.getCallingPid()
3867 + ", uid=" + Binder.getCallingUid()
3868 + "without permission "
3869 + android.Manifest.permission.DUMP);
3870 return;
3871 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003872 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003873 }
Jack Yueb89b242016-06-22 13:27:47 -07003874
3875 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003876 * Get aggregated video call data usage since boot.
3877 *
3878 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3879 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003880 * {@hide}
3881 */
3882 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003883 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003884 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3885 null);
3886
Jack Yu84291ec2017-05-26 16:07:50 -07003887 // NetworkStatsService keeps tracking the active network interface and identity. It
3888 // records the delta with the corresponding network identity. We just return the total video
3889 // call data usage snapshot since boot.
3890 Phone phone = getPhone(subId);
3891 if (phone != null) {
3892 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003893 }
Jack Yu84291ec2017-05-26 16:07:50 -07003894 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003895 }
Jack Yu75ab2952016-07-08 14:29:33 -07003896
3897 /**
3898 * Policy control of data connection. Usually used when data limit is passed.
3899 * @param enabled True if enabling the data, otherwise disabling.
3900 * @param subId Subscription index
3901 * {@hide}
3902 */
3903 @Override
3904 public void setPolicyDataEnabled(boolean enabled, int subId) {
3905 enforceModifyPermission();
3906 Phone phone = getPhone(subId);
3907 if (phone != null) {
3908 phone.setPolicyDataEnabled(enabled);
3909 }
3910 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003911
3912 /**
3913 * Get Client request stats
3914 * @return List of Client Request Stats
3915 * @hide
3916 */
3917 @Override
3918 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3919 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3920 return null;
3921 }
3922
3923 Phone phone = getPhone(subId);
3924 if (phone != null) {
3925 return phone.getClientRequestStats();
3926 }
3927
3928 return null;
3929 }
3930
3931 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3932 if (workSource != null) {
3933 return workSource;
3934 }
3935
3936 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3937 workSource = new WorkSource(uid, packageName);
3938 return workSource;
3939 }
Jack Yueb4124c2017-02-16 15:32:43 -08003940
3941 /**
Grace Chen70990072017-03-24 17:21:30 -07003942 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003943 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003944 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003945 * @param state State of SIM (power down, power up, pass through)
3946 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3947 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3948 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003949 *
3950 **/
3951 @Override
Grace Chen70990072017-03-24 17:21:30 -07003952 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003953 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003954 Phone phone = PhoneFactory.getPhone(slotIndex);
3955
Jack Yueb4124c2017-02-16 15:32:43 -08003956 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003957 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003958 }
3959 }
Shuo Qiandd210312017-04-12 22:11:33 +00003960
Tyler Gunn65d45c22017-06-05 11:22:26 -07003961 private boolean isUssdApiAllowed(int subId) {
3962 CarrierConfigManager configManager =
3963 (CarrierConfigManager) mPhone.getContext().getSystemService(
3964 Context.CARRIER_CONFIG_SERVICE);
3965 if (configManager == null) {
3966 return false;
3967 }
3968 PersistableBundle pb = configManager.getConfigForSubId(subId);
3969 if (pb == null) {
3970 return false;
3971 }
3972 return pb.getBoolean(
3973 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3974 }
3975
Shuo Qiandd210312017-04-12 22:11:33 +00003976 /**
3977 * Check if phone is in emergency callback mode
3978 * @return true if phone is in emergency callback mode
3979 * @param subId sub id
3980 */
3981 public boolean getEmergencyCallbackMode(int subId) {
3982 final Phone phone = getPhone(subId);
3983 if (phone != null) {
3984 return phone.isInEcm();
3985 } else {
3986 return false;
3987 }
3988 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003989
3990 /**
3991 * Get the current signal strength information for the given subscription.
3992 * Because this information is not updated when the device is in a low power state
3993 * it should not be relied-upon to be current.
3994 * @param subId Subscription index
3995 * @return the most recent cached signal strength info from the modem
3996 */
3997 @Override
3998 public SignalStrength getSignalStrength(int subId) {
3999 Phone p = getPhone(subId);
4000 if (p == null) {
4001 return null;
4002 }
4003
4004 return p.getSignalStrength();
4005 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004006
4007 @Override
4008 public UiccSlotInfo[] getUiccSlotsInfo() {
4009 enforceReadPrivilegedPermission();
4010
4011 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4012 if (slots == null) return null;
4013 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4014 for (int i = 0; i < slots.length; i++) {
4015 UiccSlot slot = slots[i];
4016
4017 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4018
4019 int cardState = 0;
4020 switch (slot.getCardState()) {
4021 case CARDSTATE_ABSENT:
4022 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4023 break;
4024 case CARDSTATE_PRESENT:
4025 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4026 break;
4027 case CARDSTATE_ERROR:
4028 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4029 break;
4030 case CARDSTATE_RESTRICTED:
4031 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4032 break;
4033 default:
4034 break;
4035
4036 }
4037
Qingxi Li63668902018-01-31 13:43:27 -08004038 infos[i] = new UiccSlotInfo(
4039 slot.isActive(), slot.isEuicc(), cardId, cardState, slot.getPhoneId());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004040 }
4041 return infos;
4042 }
4043
4044 @Override
4045 public boolean switchSlots(int[] physicalSlots) {
4046 enforceModifyPermission();
4047 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004049}