blob: 8127eaea340f3689e5d074d0f544fa35dda95939 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger7e934f52017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
45import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070046import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070047import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070048import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080049import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070050import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080051import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080052import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070053import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070054import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070057import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070058import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080059import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070060import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070061import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070062import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080064import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070065import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080066import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080067import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070068import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070069import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000070import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070071import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070072import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080074import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080076import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080077import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080078
Andrew Lee312e8172014-10-23 17:01:36 -070079import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080080import com.android.ims.internal.IImsMMTelFeature;
81import com.android.ims.internal.IImsRcsFeature;
Brad Ebinger7e934f52017-12-14 14:26:15 -080082import com.android.ims.internal.IImsRegistration;
Brad Ebinger34bef922017-11-09 10:27:08 -080083import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070084import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070085import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070086import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070087import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080090import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010091import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070092import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070093import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080095import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070096import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070097import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070098import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070099import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700100import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800101import com.android.internal.telephony.SubscriptionController;
Jonathan Basseri03923952017-07-19 12:22:35 -0700102import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700103import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700104import com.android.internal.telephony.uicc.IccIoResult;
105import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800106import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700107import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800108import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700109import com.android.internal.telephony.uicc.UiccController;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000110import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700111import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800112import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700113import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800114import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700115import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700116import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800117
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700118import java.io.FileDescriptor;
119import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800122import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800123import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100124import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800125import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126
127/**
128 * Implementation of the ITelephony interface.
129 */
Santos Cordon117fee72014-05-16 17:56:12 -0700130public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131 private static final String LOG_TAG = "PhoneInterfaceManager";
132 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
133 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800134 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135
136 // Message codes used with mMainThreadHandler
137 private static final int CMD_HANDLE_PIN_MMI = 1;
138 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
139 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
140 private static final int CMD_ANSWER_RINGING_CALL = 4;
141 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700142 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
143 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700144 private static final int CMD_OPEN_CHANNEL = 9;
145 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
146 private static final int CMD_CLOSE_CHANNEL = 11;
147 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800148 private static final int CMD_NV_READ_ITEM = 13;
149 private static final int EVENT_NV_READ_ITEM_DONE = 14;
150 private static final int CMD_NV_WRITE_ITEM = 15;
151 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
152 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
153 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
154 private static final int CMD_NV_RESET_CONFIG = 19;
155 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800156 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
157 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
158 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
159 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800160 private static final int CMD_SEND_ENVELOPE = 25;
161 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700162 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
163 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
164 private static final int CMD_EXCHANGE_SIM_IO = 31;
165 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800166 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
167 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700168 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
169 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700170 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
171 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700172 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
173 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
174 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
175 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700176 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
177 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
178 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
179 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700180 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800181 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
182 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000183 private static final int CMD_SWITCH_SLOTS = 50;
184 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185
186 /** The singleton instance. */
187 private static PhoneInterfaceManager sInstance;
188
Wink Saville3ab207e2014-11-20 13:07:20 -0800189 private PhoneGlobals mApp;
190 private Phone mPhone;
191 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700192 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800193 private AppOpsManager mAppOps;
194 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800195 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800196 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197
Derek Tan97ebb422014-09-05 16:55:38 -0700198 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
199 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800200 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700201
Derek Tan740e1672017-06-27 14:56:27 -0700202 // The AID of ISD-R.
203 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
204
yinxub1bed742017-04-17 11:45:04 -0700205 private NetworkScanRequestTracker mNetworkScanRequestTracker;
206
Derek Tan89e89d42014-07-08 17:00:10 -0700207 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700208 * A request object to use for transmitting data to an ICC.
209 */
210 private static final class IccAPDUArgument {
211 public int channel, cla, command, p1, p2, p3;
212 public String data;
213
214 public IccAPDUArgument(int channel, int cla, int command,
215 int p1, int p2, int p3, String data) {
216 this.channel = channel;
217 this.cla = cla;
218 this.command = command;
219 this.p1 = p1;
220 this.p2 = p2;
221 this.p3 = p3;
222 this.data = data;
223 }
224 }
225
226 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700227 * A request object to use for transmitting data to an ICC.
228 */
229 private static final class ManualNetworkSelectionArgument {
230 public OperatorInfo operatorInfo;
231 public boolean persistSelection;
232
233 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
234 this.operatorInfo = operatorInfo;
235 this.persistSelection = persistSelection;
236 }
237 }
238
239 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700240 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
241 * request after sending. The main thread will notify the request when it is complete.
242 */
243 private static final class MainThreadRequest {
244 /** The argument to use for the request */
245 public Object argument;
246 /** The result of the request that is run on the main thread */
247 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800248 // The subscriber id that this request applies to. Defaults to
249 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
250 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251
252 public MainThreadRequest(Object argument) {
253 this.argument = argument;
254 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800255
256 public MainThreadRequest(Object argument, Integer subId) {
257 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800258 if (subId != null) {
259 this.subId = subId;
260 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262 }
263
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800264 private static final class IncomingThirdPartyCallArgs {
265 public final ComponentName component;
266 public final String callId;
267 public final String callerDisplayName;
268
269 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
270 String callerDisplayName) {
271 this.component = component;
272 this.callId = callId;
273 this.callerDisplayName = callerDisplayName;
274 }
275 }
276
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277 /**
278 * A handler that processes messages on the main thread in the phone process. Since many
279 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
280 * inbound binder threads to the main thread in the phone process. The Binder thread
281 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
282 * on, which will be notified when the operation completes and will contain the result of the
283 * request.
284 *
285 * <p>If a MainThreadRequest object is provided in the msg.obj field,
286 * note that request.result must be set to something non-null for the calling thread to
287 * unblock.
288 */
289 private final class MainThreadHandler extends Handler {
290 @Override
291 public void handleMessage(Message msg) {
292 MainThreadRequest request;
293 Message onCompleted;
294 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800295 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700296 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297
298 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700299 case CMD_HANDLE_USSD_REQUEST: {
300 request = (MainThreadRequest) msg.obj;
301 final Phone phone = getPhoneFromRequest(request);
302 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
303 String ussdRequest = ussdObject.first;
304 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700305
306 if (!isUssdApiAllowed(request.subId)) {
307 // Carrier does not support use of this API, return failure.
308 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
309 UssdResponse response = new UssdResponse(ussdRequest, null);
310 Bundle returnData = new Bundle();
311 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
312 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
313
314 request.result = true;
315 synchronized (request) {
316 request.notifyAll();
317 }
318 return;
319 }
320
Tyler Gunn52dcf772017-04-26 11:30:31 -0700321 try {
322 request.result = phone != null ?
323 phone.handleUssdRequest(ussdRequest, wrappedCallback)
324 : false;
325 } catch (CallStateException cse) {
326 request.result = false;
327 }
pkanwar32d516d2016-10-14 19:37:38 -0700328 // Wake up the requesting thread
329 synchronized (request) {
330 request.notifyAll();
331 }
332 break;
333 }
334
Yorke Lee716f67e2015-06-17 15:39:16 -0700335 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700337 final Phone phone = getPhoneFromRequest(request);
338 request.result = phone != null ?
339 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
340 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341 // Wake up the requesting thread
342 synchronized (request) {
343 request.notifyAll();
344 }
345 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347
348 case CMD_HANDLE_NEIGHBORING_CELL:
349 request = (MainThreadRequest) msg.obj;
350 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
351 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700352 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353 break;
354
355 case EVENT_NEIGHBORING_CELL_DONE:
356 ar = (AsyncResult) msg.obj;
357 request = (MainThreadRequest) ar.userObj;
358 if (ar.exception == null && ar.result != null) {
359 request.result = ar.result;
360 } else {
361 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800362 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 }
364 // Wake up the requesting thread
365 synchronized (request) {
366 request.notifyAll();
367 }
368 break;
369
370 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700371 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800372 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700373 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 break;
375
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 case CMD_END_CALL:
377 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800378 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700379 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700380 Phone phone = getPhone(end_subId);
381 if (phone == null) {
382 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
383 break;
384 }
385 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
387 // CDMA: If the user presses the Power button we treat it as
388 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700389 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
391 // GSM: End the call as per the Phone state
392 hungUp = PhoneUtils.hangup(mCM);
393 } else {
394 throw new IllegalStateException("Unexpected phone type: " + phoneType);
395 }
396 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
397 request.result = hungUp;
398 // Wake up the requesting thread
399 synchronized (request) {
400 request.notifyAll();
401 }
402 break;
403
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700404 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700405 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700406 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800407 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700408 if (uiccCard == null) {
409 loge("iccTransmitApduLogicalChannel: No UICC");
410 request.result = new IccIoResult(0x6F, 0, (byte[])null);
411 synchronized (request) {
412 request.notifyAll();
413 }
414 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
416 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700417 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700418 iccArgument.channel, iccArgument.cla, iccArgument.command,
419 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700420 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700421 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700422 break;
423
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700424 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700425 ar = (AsyncResult) msg.obj;
426 request = (MainThreadRequest) ar.userObj;
427 if (ar.exception == null && ar.result != null) {
428 request.result = ar.result;
429 } else {
430 request.result = new IccIoResult(0x6F, 0, (byte[])null);
431 if (ar.result == null) {
432 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800433 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700434 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800435 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 } else {
437 loge("iccTransmitApduLogicalChannel: Unknown exception");
438 }
439 }
440 synchronized (request) {
441 request.notifyAll();
442 }
443 break;
444
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
446 request = (MainThreadRequest) msg.obj;
447 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800448 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700449 if (uiccCard == null) {
450 loge("iccTransmitApduBasicChannel: No UICC");
451 request.result = new IccIoResult(0x6F, 0, (byte[])null);
452 synchronized (request) {
453 request.notifyAll();
454 }
455 } else {
456 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
457 request);
458 uiccCard.iccTransmitApduBasicChannel(
459 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
460 iccArgument.p3, iccArgument.data, onCompleted);
461 }
462 break;
463
464 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
465 ar = (AsyncResult) msg.obj;
466 request = (MainThreadRequest) ar.userObj;
467 if (ar.exception == null && ar.result != null) {
468 request.result = ar.result;
469 } else {
470 request.result = new IccIoResult(0x6F, 0, (byte[])null);
471 if (ar.result == null) {
472 loge("iccTransmitApduBasicChannel: Empty response");
473 } else if (ar.exception instanceof CommandException) {
474 loge("iccTransmitApduBasicChannel: CommandException: " +
475 ar.exception);
476 } else {
477 loge("iccTransmitApduBasicChannel: Unknown exception");
478 }
479 }
480 synchronized (request) {
481 request.notifyAll();
482 }
483 break;
484
485 case CMD_EXCHANGE_SIM_IO:
486 request = (MainThreadRequest) msg.obj;
487 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800488 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 if (uiccCard == null) {
490 loge("iccExchangeSimIO: No UICC");
491 request.result = new IccIoResult(0x6F, 0, (byte[])null);
492 synchronized (request) {
493 request.notifyAll();
494 }
495 } else {
496 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
497 request);
498 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
499 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
500 iccArgument.data, onCompleted);
501 }
502 break;
503
504 case EVENT_EXCHANGE_SIM_IO_DONE:
505 ar = (AsyncResult) msg.obj;
506 request = (MainThreadRequest) ar.userObj;
507 if (ar.exception == null && ar.result != null) {
508 request.result = ar.result;
509 } else {
510 request.result = new IccIoResult(0x6f, 0, (byte[])null);
511 }
512 synchronized (request) {
513 request.notifyAll();
514 }
515 break;
516
Derek Tan4d5e5c12014-02-04 11:54:58 -0800517 case CMD_SEND_ENVELOPE:
518 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800519 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700520 if (uiccCard == null) {
521 loge("sendEnvelopeWithStatus: No UICC");
522 request.result = new IccIoResult(0x6F, 0, (byte[])null);
523 synchronized (request) {
524 request.notifyAll();
525 }
526 } else {
527 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
528 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
529 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800530 break;
531
532 case EVENT_SEND_ENVELOPE_DONE:
533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700535 if (ar.exception == null && ar.result != null) {
536 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800537 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
539 if (ar.result == null) {
540 loge("sendEnvelopeWithStatus: Empty response");
541 } else if (ar.exception instanceof CommandException) {
542 loge("sendEnvelopeWithStatus: CommandException: " +
543 ar.exception);
544 } else {
545 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
546 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 }
548 synchronized (request) {
549 request.notifyAll();
550 }
551 break;
552
Shishir Agrawal566b7612013-10-28 14:41:00 -0700553 case CMD_OPEN_CHANNEL:
554 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800555 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800556 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 if (uiccCard == null) {
558 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800559 request.result = new IccOpenLogicalChannelResponse(-1,
560 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 synchronized (request) {
562 request.notifyAll();
563 }
564 } else {
565 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800566 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
567 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700569 break;
570
571 case EVENT_OPEN_CHANNEL_DONE:
572 ar = (AsyncResult) msg.obj;
573 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700575 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700576 int[] result = (int[]) ar.result;
577 int channelId = result[0];
578 byte[] selectResponse = null;
579 if (result.length > 1) {
580 selectResponse = new byte[result.length - 1];
581 for (int i = 1; i < result.length; ++i) {
582 selectResponse[i - 1] = (byte) result[i];
583 }
584 }
585 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700586 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 if (ar.result == null) {
589 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 if (ar.exception != null) {
592 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
593 }
594
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700595 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700596 if (ar.exception instanceof CommandException) {
597 CommandException.Error error =
598 ((CommandException) (ar.exception)).getCommandError();
599 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700600 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700601 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700602 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 }
604 }
605 openChannelResp = new IccOpenLogicalChannelResponse(
606 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700608 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700609 synchronized (request) {
610 request.notifyAll();
611 }
612 break;
613
614 case CMD_CLOSE_CHANNEL:
615 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800616 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700617 if (uiccCard == null) {
618 loge("iccCloseLogicalChannel: No UICC");
619 request.result = new IccIoResult(0x6F, 0, (byte[])null);
620 synchronized (request) {
621 request.notifyAll();
622 }
623 } else {
624 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
625 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
626 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 break;
628
629 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800630 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
631 break;
632
633 case CMD_NV_READ_ITEM:
634 request = (MainThreadRequest) msg.obj;
635 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
636 mPhone.nvReadItem((Integer) request.argument, onCompleted);
637 break;
638
639 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 ar = (AsyncResult) msg.obj;
641 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800642 if (ar.exception == null && ar.result != null) {
643 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800645 request.result = "";
646 if (ar.result == null) {
647 loge("nvReadItem: Empty response");
648 } else if (ar.exception instanceof CommandException) {
649 loge("nvReadItem: CommandException: " +
650 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800652 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 }
654 }
655 synchronized (request) {
656 request.notifyAll();
657 }
658 break;
659
Jake Hambye994d462014-02-03 13:10:13 -0800660 case CMD_NV_WRITE_ITEM:
661 request = (MainThreadRequest) msg.obj;
662 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
663 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
664 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
665 break;
666
667 case EVENT_NV_WRITE_ITEM_DONE:
668 handleNullReturnEvent(msg, "nvWriteItem");
669 break;
670
671 case CMD_NV_WRITE_CDMA_PRL:
672 request = (MainThreadRequest) msg.obj;
673 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
674 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
675 break;
676
677 case EVENT_NV_WRITE_CDMA_PRL_DONE:
678 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
679 break;
680
681 case CMD_NV_RESET_CONFIG:
682 request = (MainThreadRequest) msg.obj;
683 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
684 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
685 break;
686
687 case EVENT_NV_RESET_CONFIG_DONE:
688 handleNullReturnEvent(msg, "nvResetConfig");
689 break;
690
Jake Hamby7c27be32014-03-03 13:25:59 -0800691 case CMD_GET_PREFERRED_NETWORK_TYPE:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700694 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800695 break;
696
697 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
698 ar = (AsyncResult) msg.obj;
699 request = (MainThreadRequest) ar.userObj;
700 if (ar.exception == null && ar.result != null) {
701 request.result = ar.result; // Integer
702 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800703 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 if (ar.result == null) {
705 loge("getPreferredNetworkType: Empty response");
706 } else if (ar.exception instanceof CommandException) {
707 loge("getPreferredNetworkType: CommandException: " +
708 ar.exception);
709 } else {
710 loge("getPreferredNetworkType: Unknown exception");
711 }
712 }
713 synchronized (request) {
714 request.notifyAll();
715 }
716 break;
717
718 case CMD_SET_PREFERRED_NETWORK_TYPE:
719 request = (MainThreadRequest) msg.obj;
720 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
721 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700722 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 break;
724
725 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
726 handleNullReturnEvent(msg, "setPreferredNetworkType");
727 break;
728
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800729 case CMD_SET_VOICEMAIL_NUMBER:
730 request = (MainThreadRequest) msg.obj;
731 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
732 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800733 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
734 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800735 break;
736
737 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
738 handleNullReturnEvent(msg, "setVoicemailNumber");
739 break;
740
Stuart Scott54788802015-03-30 13:18:01 -0700741 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
742 request = (MainThreadRequest) msg.obj;
743 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
744 request);
745 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
746 break;
747
748 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
749 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
750 break;
751
Shishir Agrawal302c8692015-06-19 13:49:39 -0700752 case CMD_PERFORM_NETWORK_SCAN:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
755 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
756 break;
757
758 case EVENT_PERFORM_NETWORK_SCAN_DONE:
759 ar = (AsyncResult) msg.obj;
760 request = (MainThreadRequest) ar.userObj;
761 CellNetworkScanResult cellScanResult;
762 if (ar.exception == null && ar.result != null) {
763 cellScanResult = new CellNetworkScanResult(
764 CellNetworkScanResult.STATUS_SUCCESS,
765 (List<OperatorInfo>) ar.result);
766 } else {
767 if (ar.result == null) {
768 loge("getCellNetworkScanResults: Empty response");
769 }
770 if (ar.exception != null) {
771 loge("getCellNetworkScanResults: Exception: " + ar.exception);
772 }
773 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
774 if (ar.exception instanceof CommandException) {
775 CommandException.Error error =
776 ((CommandException) (ar.exception)).getCommandError();
777 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
778 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
779 } else if (error == CommandException.Error.GENERIC_FAILURE) {
780 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
781 }
782 }
783 cellScanResult = new CellNetworkScanResult(errorCode, null);
784 }
785 request.result = cellScanResult;
786 synchronized (request) {
787 request.notifyAll();
788 }
789 break;
790
791 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
792 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700793 ManualNetworkSelectionArgument selArg =
794 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700795 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
796 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700797 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
798 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700799 break;
800
801 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
802 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
803 break;
804
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700805 case CMD_GET_MODEM_ACTIVITY_INFO:
806 request = (MainThreadRequest) msg.obj;
807 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700808 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700809 break;
810
811 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
812 ar = (AsyncResult) msg.obj;
813 request = (MainThreadRequest) ar.userObj;
814 if (ar.exception == null && ar.result != null) {
815 request.result = ar.result;
816 } else {
817 if (ar.result == null) {
818 loge("queryModemActivityInfo: Empty response");
819 } else if (ar.exception instanceof CommandException) {
820 loge("queryModemActivityInfo: CommandException: " +
821 ar.exception);
822 } else {
823 loge("queryModemActivityInfo: Unknown exception");
824 }
825 }
Amit Mahajand4766222016-01-28 15:28:28 -0800826 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
827 if (request.result == null) {
828 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
829 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700830 synchronized (request) {
831 request.notifyAll();
832 }
833 break;
834
Meng Wang1a7c35a2016-05-05 20:56:15 -0700835 case CMD_SET_ALLOWED_CARRIERS:
836 request = (MainThreadRequest) msg.obj;
837 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
838 mPhone.setAllowedCarriers(
839 (List<CarrierIdentifier>) request.argument,
840 onCompleted);
841 break;
842
843 case EVENT_SET_ALLOWED_CARRIERS_DONE:
844 ar = (AsyncResult) msg.obj;
845 request = (MainThreadRequest) ar.userObj;
846 if (ar.exception == null && ar.result != null) {
847 request.result = ar.result;
848 } else {
849 if (ar.result == null) {
850 loge("setAllowedCarriers: Empty response");
851 } else if (ar.exception instanceof CommandException) {
852 loge("setAllowedCarriers: CommandException: " +
853 ar.exception);
854 } else {
855 loge("setAllowedCarriers: Unknown exception");
856 }
857 }
858 // Result cannot be null. Return -1 on error.
859 if (request.result == null) {
860 request.result = new int[]{-1};
861 }
862 synchronized (request) {
863 request.notifyAll();
864 }
865 break;
866
867 case CMD_GET_ALLOWED_CARRIERS:
868 request = (MainThreadRequest) msg.obj;
869 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
870 mPhone.getAllowedCarriers(onCompleted);
871 break;
872
873 case EVENT_GET_ALLOWED_CARRIERS_DONE:
874 ar = (AsyncResult) msg.obj;
875 request = (MainThreadRequest) ar.userObj;
876 if (ar.exception == null && ar.result != null) {
877 request.result = ar.result;
878 } else {
879 if (ar.result == null) {
880 loge("getAllowedCarriers: Empty response");
881 } else if (ar.exception instanceof CommandException) {
882 loge("getAllowedCarriers: CommandException: " +
883 ar.exception);
884 } else {
885 loge("getAllowedCarriers: Unknown exception");
886 }
887 }
888 // Result cannot be null. Return empty list of CarrierIdentifier.
889 if (request.result == null) {
890 request.result = new ArrayList<CarrierIdentifier>(0);
891 }
892 synchronized (request) {
893 request.notifyAll();
894 }
895 break;
896
Nathan Haroldb3014052017-01-25 15:57:32 -0800897 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
898 ar = (AsyncResult) msg.obj;
899 request = (MainThreadRequest) ar.userObj;
900 if (ar.exception == null && ar.result != null) {
901 request.result = ar.result;
902 } else {
903 request.result = new IllegalArgumentException(
904 "Failed to retrieve Forbidden Plmns");
905 if (ar.result == null) {
906 loge("getForbiddenPlmns: Empty response");
907 } else {
908 loge("getForbiddenPlmns: Unknown exception");
909 }
910 }
911 synchronized (request) {
912 request.notifyAll();
913 }
914 break;
915
916 case CMD_GET_FORBIDDEN_PLMNS:
917 request = (MainThreadRequest) msg.obj;
918 uiccCard = getUiccCardFromRequest(request);
919 if (uiccCard == null) {
920 loge("getForbiddenPlmns() UiccCard is null");
921 request.result = new IllegalArgumentException(
922 "getForbiddenPlmns() UiccCard is null");
923 synchronized (request) {
924 request.notifyAll();
925 }
926 break;
927 }
928 Integer appType = (Integer) request.argument;
929 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
930 if (uiccApp == null) {
931 loge("getForbiddenPlmns() no app with specified type -- "
932 + appType);
933 request.result = new IllegalArgumentException("Failed to get UICC App");
934 synchronized (request) {
935 request.notifyAll();
936 }
937 break;
938 } else {
939 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
940 + " specified type -- " + appType);
941 }
942 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
943 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
944 onCompleted);
945 break;
946
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000947 case CMD_SWITCH_SLOTS:
948 request = (MainThreadRequest) msg.obj;
949 int[] physicalSlots = (int[]) request.argument;
950 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
951 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
952 break;
953
954 case EVENT_SWITCH_SLOTS_DONE:
955 ar = (AsyncResult) msg.obj;
956 request = (MainThreadRequest) ar.userObj;
957 request.result = (ar.exception == null);
958 synchronized (request) {
959 request.notifyAll();
960 }
961 break;
962
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700963 default:
964 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
965 break;
966 }
967 }
Jake Hambye994d462014-02-03 13:10:13 -0800968
969 private void handleNullReturnEvent(Message msg, String command) {
970 AsyncResult ar = (AsyncResult) msg.obj;
971 MainThreadRequest request = (MainThreadRequest) ar.userObj;
972 if (ar.exception == null) {
973 request.result = true;
974 } else {
975 request.result = false;
976 if (ar.exception instanceof CommandException) {
977 loge(command + ": CommandException: " + ar.exception);
978 } else {
979 loge(command + ": Unknown exception");
980 }
981 }
982 synchronized (request) {
983 request.notifyAll();
984 }
985 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700986 }
987
988 /**
989 * Posts the specified command to be executed on the main thread,
990 * waits for the request to complete, and returns the result.
991 * @see #sendRequestAsync
992 */
993 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800994 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700995 }
996
997 /**
998 * Posts the specified command to be executed on the main thread,
999 * waits for the request to complete, and returns the result.
1000 * @see #sendRequestAsync
1001 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001002 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001003 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1004 throw new RuntimeException("This method will deadlock if called from the main thread.");
1005 }
1006
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001007 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001008 Message msg = mMainThreadHandler.obtainMessage(command, request);
1009 msg.sendToTarget();
1010
1011 // Wait for the request to complete
1012 synchronized (request) {
1013 while (request.result == null) {
1014 try {
1015 request.wait();
1016 } catch (InterruptedException e) {
1017 // Do nothing, go back and wait until the request is complete
1018 }
1019 }
1020 }
1021 return request.result;
1022 }
1023
1024 /**
1025 * Asynchronous ("fire and forget") version of sendRequest():
1026 * Posts the specified command to be executed on the main thread, and
1027 * returns immediately.
1028 * @see #sendRequest
1029 */
1030 private void sendRequestAsync(int command) {
1031 mMainThreadHandler.sendEmptyMessage(command);
1032 }
1033
1034 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001035 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1036 * @see {@link #sendRequest(int,Object)}
1037 */
1038 private void sendRequestAsync(int command, Object argument) {
1039 MainThreadRequest request = new MainThreadRequest(argument);
1040 Message msg = mMainThreadHandler.obtainMessage(command, request);
1041 msg.sendToTarget();
1042 }
1043
1044 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001045 * Initialize the singleton PhoneInterfaceManager instance.
1046 * This is only done once, at startup, from PhoneApp.onCreate().
1047 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001048 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001049 synchronized (PhoneInterfaceManager.class) {
1050 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001051 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001052 } else {
1053 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1054 }
1055 return sInstance;
1056 }
1057 }
1058
1059 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001060 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001061 mApp = app;
1062 mPhone = phone;
1063 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001064 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001065 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1066 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001067 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001068 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001069 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001070 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001071
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001072 publish();
1073 }
1074
1075 private void publish() {
1076 if (DBG) log("publish: " + this);
1077
1078 ServiceManager.addService("phone", this);
1079 }
1080
Stuart Scott584921c2015-01-15 17:10:34 -08001081 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001082 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1083 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001084 }
1085
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001086 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1087 Phone phone = getPhoneFromRequest(request);
1088 return phone == null ? null :
1089 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1090 }
1091
Wink Saville36469e72014-06-11 15:17:00 -07001092 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001093 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001094 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001095 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001096 //
1097 // Implementation of the ITelephony interface.
1098 //
1099
1100 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001101 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001102 }
1103
Wink Savilleb564aae2014-10-23 10:18:09 -07001104 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001105 if (DBG) log("dial: " + number);
1106 // No permission check needed here: This is just a wrapper around the
1107 // ACTION_DIAL intent, which is available to any app since it puts up
1108 // the UI before it does anything.
1109
1110 String url = createTelUrl(number);
1111 if (url == null) {
1112 return;
1113 }
1114
1115 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001116 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001117 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1118 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1119 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1120 mApp.startActivity(intent);
1121 }
1122 }
1123
1124 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001125 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001126 }
1127
Wink Savilleb564aae2014-10-23 10:18:09 -07001128 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001129 if (DBG) log("call: " + number);
1130
1131 // This is just a wrapper around the ACTION_CALL intent, but we still
1132 // need to do a permission check since we're calling startActivity()
1133 // from the context of the phone app.
1134 enforceCallPermission();
1135
1136 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1137 != AppOpsManager.MODE_ALLOWED) {
1138 return;
1139 }
1140
1141 String url = createTelUrl(number);
1142 if (url == null) {
1143 return;
1144 }
1145
Wink Saville08874612014-08-31 19:19:58 -07001146 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001147 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001148 if (slist != null) {
1149 for (SubscriptionInfo subInfoRecord : slist) {
1150 if (subInfoRecord.getSubscriptionId() == subId) {
1151 isValid = true;
1152 break;
1153 }
Wink Saville08874612014-08-31 19:19:58 -07001154 }
1155 }
1156 if (isValid == false) {
1157 return;
1158 }
1159
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001160 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001161 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001162 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1163 mApp.startActivity(intent);
1164 }
1165
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001166 /**
1167 * End a call based on call state
1168 * @return true is a call was ended
1169 */
1170 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001171 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001172 }
1173
1174 /**
1175 * End a call based on the call state of the subId
1176 * @return true is a call was ended
1177 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001178 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001179 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001180 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001181 }
1182
1183 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001184 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001185 }
1186
Wink Savilleb564aae2014-10-23 10:18:09 -07001187 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001188 if (DBG) log("answerRingingCall...");
1189 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1190 // but that can probably wait till the big TelephonyManager API overhaul.
1191 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1192 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001193 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001194 }
1195
1196 /**
1197 * Make the actual telephony calls to implement answerRingingCall().
1198 * This should only be called from the main thread of the Phone app.
1199 * @see #answerRingingCall
1200 *
1201 * TODO: it would be nice to return true if we answered the call, or
1202 * false if there wasn't actually a ringing incoming call, or some
1203 * other error occurred. (In other words, pass back the return value
1204 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1205 * But that would require calling this method via sendRequest() rather
1206 * than sendRequestAsync(), and right now we don't actually *need* that
1207 * return value, so let's just return void for now.
1208 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001209 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001210 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001211 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001212 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1213 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001214 if (hasActiveCall && hasHoldingCall) {
1215 // Both lines are in use!
1216 // TODO: provide a flag to let the caller specify what
1217 // policy to use if both lines are in use. (The current
1218 // behavior is hardwired to "answer incoming, end ongoing",
1219 // which is how the CALL button is specced to behave.)
1220 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1221 return;
1222 } else {
1223 // answerCall() will automatically hold the current active
1224 // call, if there is one.
1225 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1226 return;
1227 }
1228 } else {
1229 // No call was ringing.
1230 return;
1231 }
1232 }
1233
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001235 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001236 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001237 public void silenceRinger() {
1238 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001239 }
1240
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001241 @Override
1242 public boolean isOffhook(String callingPackage) {
1243 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001244 }
1245
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001246 @Override
1247 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1248 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1249 return false;
1250 }
1251
Sanket Padawe356d7632015-06-22 14:03:32 -07001252 final Phone phone = getPhone(subId);
1253 if (phone != null) {
1254 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1255 } else {
1256 return false;
1257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 }
1259
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001260 @Override
1261 public boolean isRinging(String callingPackage) {
1262 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001263 }
1264
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001265 @Override
1266 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1267 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1268 return false;
1269 }
1270
Sanket Padawe356d7632015-06-22 14:03:32 -07001271 final Phone phone = getPhone(subId);
1272 if (phone != null) {
1273 return (phone.getState() == PhoneConstants.State.RINGING);
1274 } else {
1275 return false;
1276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 }
1278
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001279 @Override
1280 public boolean isIdle(String callingPackage) {
1281 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001282 }
1283
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001284 @Override
1285 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1286 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1287 return false;
1288 }
1289
Sanket Padawe356d7632015-06-22 14:03:32 -07001290 final Phone phone = getPhone(subId);
1291 if (phone != null) {
1292 return (phone.getState() == PhoneConstants.State.IDLE);
1293 } else {
1294 return false;
1295 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001296 }
1297
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001298 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001299 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001300 }
1301
Wink Savilleb564aae2014-10-23 10:18:09 -07001302 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001303 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001304 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1305 }
1306
1307 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001308 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001309 }
1310
Wink Savilleb564aae2014-10-23 10:18:09 -07001311 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001312 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001313 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1314 }
1315
1316 /** {@hide} */
1317 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001318 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001319 }
1320
Wink Savilleb564aae2014-10-23 10:18:09 -07001321 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001322 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001323 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 checkSimPin.start();
1325 return checkSimPin.unlockSim(null, pin);
1326 }
1327
Wink Saville9de0f752013-10-22 19:04:03 -07001328 /** {@hide} */
1329 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001330 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001331 }
1332
Wink Savilleb564aae2014-10-23 10:18:09 -07001333 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001334 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001335 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336 checkSimPuk.start();
1337 return checkSimPuk.unlockSim(puk, pin);
1338 }
1339
1340 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001341 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 * a synchronous one.
1343 */
1344 private static class UnlockSim extends Thread {
1345
1346 private final IccCard mSimCard;
1347
1348 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001349 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1350 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001351
1352 // For replies from SimCard interface
1353 private Handler mHandler;
1354
1355 // For async handler to identify request type
1356 private static final int SUPPLY_PIN_COMPLETE = 100;
1357
1358 public UnlockSim(IccCard simCard) {
1359 mSimCard = simCard;
1360 }
1361
1362 @Override
1363 public void run() {
1364 Looper.prepare();
1365 synchronized (UnlockSim.this) {
1366 mHandler = new Handler() {
1367 @Override
1368 public void handleMessage(Message msg) {
1369 AsyncResult ar = (AsyncResult) msg.obj;
1370 switch (msg.what) {
1371 case SUPPLY_PIN_COMPLETE:
1372 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1373 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001374 mRetryCount = msg.arg1;
1375 if (ar.exception != null) {
1376 if (ar.exception instanceof CommandException &&
1377 ((CommandException)(ar.exception)).getCommandError()
1378 == CommandException.Error.PASSWORD_INCORRECT) {
1379 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1380 } else {
1381 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1382 }
1383 } else {
1384 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1385 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001386 mDone = true;
1387 UnlockSim.this.notifyAll();
1388 }
1389 break;
1390 }
1391 }
1392 };
1393 UnlockSim.this.notifyAll();
1394 }
1395 Looper.loop();
1396 }
1397
1398 /*
1399 * Use PIN or PUK to unlock SIM card
1400 *
1401 * If PUK is null, unlock SIM card with PIN
1402 *
1403 * If PUK is not null, unlock SIM card with PUK and set PIN code
1404 */
Wink Saville9de0f752013-10-22 19:04:03 -07001405 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406
1407 while (mHandler == null) {
1408 try {
1409 wait();
1410 } catch (InterruptedException e) {
1411 Thread.currentThread().interrupt();
1412 }
1413 }
1414 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1415
1416 if (puk == null) {
1417 mSimCard.supplyPin(pin, callback);
1418 } else {
1419 mSimCard.supplyPuk(puk, pin, callback);
1420 }
1421
1422 while (!mDone) {
1423 try {
1424 Log.d(LOG_TAG, "wait for done");
1425 wait();
1426 } catch (InterruptedException e) {
1427 // Restore the interrupted status
1428 Thread.currentThread().interrupt();
1429 }
1430 }
1431 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001432 int[] resultArray = new int[2];
1433 resultArray[0] = mResult;
1434 resultArray[1] = mRetryCount;
1435 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001436 }
1437 }
1438
1439 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001440 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001441
1442 }
1443
Wink Savilleb564aae2014-10-23 10:18:09 -07001444 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001445 // No permission check needed here: this call is harmless, and it's
1446 // needed for the ServiceState.requestStateUpdate() call (which is
1447 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001448 final Phone phone = getPhone(subId);
1449 if (phone != null) {
1450 phone.updateServiceLocation();
1451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001452 }
1453
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001454 @Override
1455 public boolean isRadioOn(String callingPackage) {
1456 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001457 }
1458
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001459 @Override
1460 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1461 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1462 return false;
1463 }
1464 return isRadioOnForSubscriber(subId);
1465 }
1466
1467 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001468 final Phone phone = getPhone(subId);
1469 if (phone != null) {
1470 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1471 } else {
1472 return false;
1473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474 }
1475
1476 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001477 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001478
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479 }
Wink Saville36469e72014-06-11 15:17:00 -07001480
Wink Savilleb564aae2014-10-23 10:18:09 -07001481 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001483 final Phone phone = getPhone(subId);
1484 if (phone != null) {
1485 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1486 }
Wink Saville36469e72014-06-11 15:17:00 -07001487 }
1488
1489 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001490 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001491 }
1492
Wink Savilleb564aae2014-10-23 10:18:09 -07001493 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001494 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001495 final Phone phone = getPhone(subId);
1496 if (phone == null) {
1497 return false;
1498 }
1499 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001500 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001501 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001502 }
1503 return true;
1504 }
Wink Saville36469e72014-06-11 15:17:00 -07001505
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001506 public boolean needMobileRadioShutdown() {
1507 /*
1508 * If any of the Radios are available, it will need to be
1509 * shutdown. So return true if any Radio is available.
1510 */
1511 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1512 Phone phone = PhoneFactory.getPhone(i);
1513 if (phone != null && phone.isRadioAvailable()) return true;
1514 }
1515 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1516 return false;
1517 }
1518
1519 public void shutdownMobileRadios() {
1520 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1521 logv("Shutting down Phone " + i);
1522 shutdownRadioUsingPhoneId(i);
1523 }
1524 }
1525
1526 private void shutdownRadioUsingPhoneId(int phoneId) {
1527 enforceModifyPermission();
1528 Phone phone = PhoneFactory.getPhone(phoneId);
1529 if (phone != null && phone.isRadioAvailable()) {
1530 phone.shutdownRadio();
1531 }
1532 }
1533
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001535 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001536 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1537 if (defaultPhone != null) {
1538 defaultPhone.setRadioPower(turnOn);
1539 return true;
1540 } else {
1541 loge("There's no default phone.");
1542 return false;
1543 }
Wink Saville36469e72014-06-11 15:17:00 -07001544 }
1545
Wink Savilleb564aae2014-10-23 10:18:09 -07001546 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001547 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001548 final Phone phone = getPhone(subId);
1549 if (phone != null) {
1550 phone.setRadioPower(turnOn);
1551 return true;
1552 } else {
1553 return false;
1554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 }
1556
Wink Saville36469e72014-06-11 15:17:00 -07001557 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001558 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001559 public boolean enableDataConnectivity() {
1560 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001561 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001562 final Phone phone = getPhone(subId);
1563 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001564 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001565 return true;
1566 } else {
1567 return false;
1568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 }
1570
Wink Saville36469e72014-06-11 15:17:00 -07001571 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001572 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 public boolean disableDataConnectivity() {
1574 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001575 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001576 final Phone phone = getPhone(subId);
1577 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001578 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001579 return true;
1580 } else {
1581 return false;
1582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
Sanket Padawe356d7632015-06-22 14:03:32 -07001585 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001586 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001587 final Phone phone = getPhone(subId);
1588 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001589 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001590 } else {
1591 return false;
1592 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001593 }
1594
1595 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001596 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001597 }
1598
pkanwarae03a6b2016-11-06 20:37:09 -08001599 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001600 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001601 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1602 return;
1603 }
1604 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1605 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1606 };
1607
Wink Savilleb564aae2014-10-23 10:18:09 -07001608 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001610 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1611 return false;
1612 }
Wink Saville36469e72014-06-11 15:17:00 -07001613 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001614 }
1615
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001616 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001617 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001618 }
1619
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001620 public int getCallStateForSlot(int slotIndex) {
1621 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001622 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001623 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 }
1625
Sanket Padawe356d7632015-06-22 14:03:32 -07001626 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001627 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001628 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001629 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001630 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001631 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001632 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 }
1635
Sanket Padawe356d7632015-06-22 14:03:32 -07001636 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001637 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001638 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001639 if (phone != null) {
1640 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1641 } else {
1642 return TelephonyManager.DATA_ACTIVITY_NONE;
1643 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 }
1645
1646 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001647 public Bundle getCellLocation(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001648 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001649 callingPackage, Binder.getCallingUid(), "getCellLocation")) {
Svetoslav64fad262015-04-14 14:35:21 -07001650 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 }
1652
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001653 if (DBG_LOC) log("getCellLocation: is active user");
1654 Bundle data = new Bundle();
1655 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1656 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 return null;
1658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001660 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1661 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1662 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001663 }
1664
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001666 public String getNetworkCountryIsoForPhone(int phoneId) {
1667 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1668 // registered cell info, so return a NULL country instead.
1669 final long identity = Binder.clearCallingIdentity();
1670 try {
1671 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1672 if (TelephonyManager.NETWORK_TYPE_IWLAN
1673 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1674 return "";
1675 }
1676 } finally {
1677 Binder.restoreCallingIdentity(identity);
1678 }
1679 return TelephonyManager.getTelephonyProperty(
1680 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1681 }
1682
1683 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001685 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001686 }
1687
Sanket Padawe356d7632015-06-22 14:03:32 -07001688 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001689 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 mApp.enforceCallingOrSelfPermission(
1691 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001692 final Phone phone = getPhone(subId);
1693 if (phone != null) {
1694 phone.enableLocationUpdates();
1695 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001696 }
1697
1698 @Override
1699 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001700 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001701 }
1702
Sanket Padawe356d7632015-06-22 14:03:32 -07001703 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001704 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 mApp.enforceCallingOrSelfPermission(
1706 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001707 final Phone phone = getPhone(subId);
1708 if (phone != null) {
1709 phone.disableLocationUpdates();
1710 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 }
1712
1713 @Override
1714 @SuppressWarnings("unchecked")
1715 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001716 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001717 callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001718 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 }
1720
1721 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1722 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1723 return null;
1724 }
Svetoslav64fad262015-04-14 14:35:21 -07001725
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001726 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001727
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001728 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001730 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1731 try {
1732 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1733 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1734 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1735 } catch (RuntimeException e) {
1736 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001738 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739 }
1740
1741
1742 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001743 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001744 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001745 callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001746 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 }
1748
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001749 if (DBG_LOC) log("getAllCellInfo: is active user");
1750 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1751 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1752 for (Phone phone : PhoneFactory.getPhones()) {
1753 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1754 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001756 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 }
1758
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001759 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001761 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001762 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1763 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001764 }
1765
Shishir Agrawala9f32182016-04-12 12:00:16 -07001766 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001767 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001768 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1769 return null;
1770 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001771 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001772 return phone == null ? null : phone.getImei();
1773 }
1774
1775 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001776 public String getMeidForSlot(int slotIndex, String callingPackage) {
1777 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1778 return null;
1779 }
1780 Phone phone = PhoneFactory.getPhone(slotIndex);
1781 return phone == null ? null : phone.getMeid();
1782 }
1783
1784 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001785 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001786 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1787 return null;
1788 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001789 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001790 return phone == null ? null : phone.getDeviceSvn();
1791 }
1792
fionaxuf32acdf2017-11-27 22:51:16 -08001793 @Override
1794 public int getSubscriptionCarrierId(int subId) {
1795 final Phone phone = getPhone(subId);
1796 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1797 }
1798
1799 @Override
1800 public String getSubscriptionCarrierName(int subId) {
1801 final Phone phone = getPhone(subId);
1802 return phone == null ? null : phone.getCarrierName();
1803 }
1804
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 //
1806 // Internal helper methods.
1807 //
1808
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001809 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1811 *
1812 * @throws SecurityException if the caller does not have the required permission
1813 */
1814 private void enforceModifyPermission() {
1815 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1816 }
1817
1818 /**
Junda Liua2e36012014-07-09 18:30:01 -07001819 * Make sure either system app or the caller has carrier privilege.
1820 *
1821 * @throws SecurityException if the caller does not have the required permission/privilege
1822 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001823 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001824 int permission = mApp.checkCallingOrSelfPermission(
1825 android.Manifest.permission.MODIFY_PHONE_STATE);
1826 if (permission == PackageManager.PERMISSION_GRANTED) {
1827 return;
1828 }
1829
1830 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001831 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001832 }
1833
1834 /**
1835 * Make sure the caller has carrier privilege.
1836 *
1837 * @throws SecurityException if the caller does not have the required permission
1838 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001839 private void enforceCarrierPrivilege(int subId) {
1840 if (getCarrierPrivilegeStatus(subId) !=
1841 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001842 loge("No Carrier Privilege.");
1843 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001844 }
1845 }
1846
1847 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 * Make sure the caller has the CALL_PHONE permission.
1849 *
1850 * @throws SecurityException if the caller does not have the required permission
1851 */
1852 private void enforceCallPermission() {
1853 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1854 }
1855
Stuart Scott8eef64f2015-04-08 15:13:54 -07001856 private void enforceConnectivityInternalPermission() {
1857 mApp.enforceCallingOrSelfPermission(
1858 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1859 "ConnectivityService");
1860 }
1861
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001862 private String createTelUrl(String number) {
1863 if (TextUtils.isEmpty(number)) {
1864 return null;
1865 }
1866
Jake Hambye994d462014-02-03 13:10:13 -08001867 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 }
1869
Ihab Awadf9e92732013-12-05 18:02:52 -08001870 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1872 }
1873
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001874 private static void logv(String msg) {
1875 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1876 }
1877
Ihab Awadf9e92732013-12-05 18:02:52 -08001878 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1880 }
1881
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001882 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001883 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001884 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001885 }
1886
Sanket Padawe356d7632015-06-22 14:03:32 -07001887 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001888 public int getActivePhoneTypeForSlot(int slotIndex) {
1889 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001890 if (phone == null) {
1891 return PhoneConstants.PHONE_TYPE_NONE;
1892 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001893 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895 }
1896
1897 /**
1898 * Returns the CDMA ERI icon index to display
1899 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001900 @Override
1901 public int getCdmaEriIconIndex(String callingPackage) {
1902 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001903 }
1904
Sanket Padawe356d7632015-06-22 14:03:32 -07001905 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001906 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1907 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1908 return -1;
1909 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001910 final Phone phone = getPhone(subId);
1911 if (phone != null) {
1912 return phone.getCdmaEriIconIndex();
1913 } else {
1914 return -1;
1915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 }
1917
1918 /**
1919 * Returns the CDMA ERI icon mode,
1920 * 0 - ON
1921 * 1 - FLASHING
1922 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001923 @Override
1924 public int getCdmaEriIconMode(String callingPackage) {
1925 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001926 }
1927
Sanket Padawe356d7632015-06-22 14:03:32 -07001928 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001929 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1930 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1931 return -1;
1932 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001933 final Phone phone = getPhone(subId);
1934 if (phone != null) {
1935 return phone.getCdmaEriIconMode();
1936 } else {
1937 return -1;
1938 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 }
1940
1941 /**
1942 * Returns the CDMA ERI text,
1943 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001944 @Override
1945 public String getCdmaEriText(String callingPackage) {
1946 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001947 }
1948
Sanket Padawe356d7632015-06-22 14:03:32 -07001949 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001950 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1951 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1952 return null;
1953 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001954 final Phone phone = getPhone(subId);
1955 if (phone != null) {
1956 return phone.getCdmaEriText();
1957 } else {
1958 return null;
1959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001960 }
1961
1962 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001963 * Returns the CDMA MDN.
1964 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001965 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001966 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001967 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001968 final Phone phone = getPhone(subId);
1969 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1970 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001971 } else {
1972 return null;
1973 }
1974 }
1975
1976 /**
1977 * Returns the CDMA MIN.
1978 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001979 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001980 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001981 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001982 final Phone phone = getPhone(subId);
1983 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1984 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001985 } else {
1986 return null;
1987 }
1988 }
1989
1990 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 * Returns true if CDMA provisioning needs to run.
1992 */
1993 public boolean needsOtaServiceProvisioning() {
1994 return mPhone.needsOtaServiceProvisioning();
1995 }
1996
1997 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001998 * Sets the voice mail number of a given subId.
1999 */
2000 @Override
2001 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002002 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002003 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2004 new Pair<String, String>(alphaTag, number), new Integer(subId));
2005 return success;
2006 }
2007
Ta-wei Yen87c49842016-05-13 21:19:52 -07002008 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002009 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2010 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2011 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2012 if (!TextUtils.equals(callingPackage, systemDialer)) {
2013 throw new SecurityException("caller must be system dialer");
2014 }
2015 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2016 if (phoneAccountHandle == null){
2017 return null;
2018 }
2019 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2020 }
2021
2022 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002023 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002024 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2025 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2026 return null;
2027 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002028 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2029 }
2030
2031 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002032 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2033 VisualVoicemailSmsFilterSettings settings) {
2034 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002035 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002036 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2037 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002038 }
2039
2040 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002041 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002043 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002044 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002045 }
2046
2047 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002048 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2049 String callingPackage, int subId) {
2050 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002051 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002052 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002053 }
2054
2055 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002056 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002057 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002058 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002059 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2060 }
2061
2062 @Override
2063 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2064 String number, int port, String text, PendingIntent sentIntent) {
2065 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002066 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002067 enforceSendSmsPermission();
2068 // Make the calls as the phone process.
2069 final long identity = Binder.clearCallingIdentity();
2070 try {
2071 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2072 if (port == 0) {
2073 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2074 sentIntent, null, false);
2075 } else {
2076 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2077 smsManager.sendDataMessageWithSelfPermissions(number, null,
2078 (short) port, data, sentIntent, null);
2079 }
2080 } finally {
2081 Binder.restoreCallingIdentity(identity);
2082 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002083 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002084 /**
fionaxu0152e512016-11-14 13:36:14 -08002085 * Sets the voice activation state of a given subId.
2086 */
2087 @Override
2088 public void setVoiceActivationState(int subId, int activationState) {
2089 enforceModifyPermissionOrCarrierPrivilege(subId);
2090 final Phone phone = getPhone(subId);
2091 if (phone != null) {
2092 phone.setVoiceActivationState(activationState);
2093 } else {
2094 loge("setVoiceActivationState fails with invalid subId: " + subId);
2095 }
2096 }
2097
2098 /**
2099 * Sets the data activation state of a given subId.
2100 */
2101 @Override
2102 public void setDataActivationState(int subId, int activationState) {
2103 enforceModifyPermissionOrCarrierPrivilege(subId);
2104 final Phone phone = getPhone(subId);
2105 if (phone != null) {
2106 phone.setDataActivationState(activationState);
2107 } else {
2108 loge("setVoiceActivationState fails with invalid subId: " + subId);
2109 }
2110 }
2111
2112 /**
2113 * Returns the voice activation state of a given subId.
2114 */
2115 @Override
2116 public int getVoiceActivationState(int subId, String callingPackage) {
2117 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2118 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2119 }
2120 final Phone phone = getPhone(subId);
2121 if (phone != null) {
2122 return phone.getVoiceActivationState();
2123 } else {
2124 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2125 }
2126 }
2127
2128 /**
2129 * Returns the data activation state of a given subId.
2130 */
2131 @Override
2132 public int getDataActivationState(int subId, String callingPackage) {
2133 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2134 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2135 }
2136 final Phone phone = getPhone(subId);
2137 if (phone != null) {
2138 return phone.getDataActivationState();
2139 } else {
2140 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2141 }
2142 }
2143
2144 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002145 * Returns the unread count of voicemails
2146 */
2147 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002148 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002149 }
2150
2151 /**
2152 * Returns the unread count of voicemails for a subId
2153 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002154 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002155 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002156 final Phone phone = getPhone(subId);
2157 if (phone != null) {
2158 return phone.getVoiceMessageCount();
2159 } else {
2160 return 0;
2161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 }
2163
2164 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002165 * returns true, if the device is in a state where both voice and data
2166 * are supported simultaneously. This can change based on location or network condition.
2167 */
2168 @Override
2169 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2170 final Phone phone = getPhone(subId);
2171 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2172 }
2173
2174 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002175 * Send the dialer code if called from the current default dialer or the caller has
2176 * carrier privilege.
2177 * @param inputCode The dialer code to send
2178 */
2179 @Override
2180 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2181 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2182 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2183 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2184 enforceCarrierPrivilege(getDefaultSubscription());
2185 }
2186 mPhone.sendDialerSpecialCode(inputCode);
2187 }
2188
2189 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002190 * Returns the data network type.
2191 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 *
2193 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2194 */
2195 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002196 public int getNetworkType() {
2197 final Phone phone = getPhone(getDefaultSubscription());
2198 if (phone != null) {
2199 return phone.getServiceState().getDataNetworkType();
2200 } else {
2201 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2202 }
Wink Saville36469e72014-06-11 15:17:00 -07002203 }
2204
2205 /**
2206 * Returns the network type for a subId
2207 */
2208 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002209 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2210 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2211 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2212 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002213
Sanket Padawe356d7632015-06-22 14:03:32 -07002214 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002215 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002216 return phone.getServiceState().getDataNetworkType();
2217 } else {
2218 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221
2222 /**
2223 * Returns the data network type
2224 */
2225 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002226 public int getDataNetworkType(String callingPackage) {
2227 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002228 }
2229
2230 /**
2231 * Returns the data network type for a subId
2232 */
2233 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002234 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2235 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2236 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2237 }
2238
Sanket Padawe356d7632015-06-22 14:03:32 -07002239 final Phone phone = getPhone(subId);
2240 if (phone != null) {
2241 return phone.getServiceState().getDataNetworkType();
2242 } else {
2243 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 }
2246
2247 /**
Wink Saville36469e72014-06-11 15:17:00 -07002248 * Returns the Voice network type for a subId
2249 */
2250 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002251 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2252 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2253 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2254 }
2255
Sanket Padawe356d7632015-06-22 14:03:32 -07002256 final Phone phone = getPhone(subId);
2257 if (phone != null) {
2258 return phone.getServiceState().getVoiceNetworkType();
2259 } else {
2260 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2261 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 }
2263
2264 /**
2265 * @return true if a ICC card is present
2266 */
2267 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002268 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002269 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2270 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002271 }
2272
2273 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002274 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002275 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002276 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002277 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2278 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002279 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002280 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002281 } else {
2282 return false;
2283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 }
2285
2286 /**
2287 * Return if the current radio is LTE on CDMA. This
2288 * is a tri-state return value as for a period of time
2289 * the mode may be unknown.
2290 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002291 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002293 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002295 @Override
2296 public int getLteOnCdmaMode(String callingPackage) {
2297 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002298 }
2299
Sanket Padawe356d7632015-06-22 14:03:32 -07002300 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002301 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2302 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2303 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2304 }
2305
Sanket Padawe356d7632015-06-22 14:03:32 -07002306 final Phone phone = getPhone(subId);
2307 if (phone == null) {
2308 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2309 } else {
2310 return phone.getLteOnCdmaMode();
2311 }
Wink Saville36469e72014-06-11 15:17:00 -07002312 }
2313
2314 public void setPhone(Phone phone) {
2315 mPhone = phone;
2316 }
2317
2318 /**
2319 * {@hide}
2320 * Returns Default subId, 0 in the case of single standby.
2321 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002322 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002323 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002324 }
2325
Shishir Agrawala9f32182016-04-12 12:00:16 -07002326 private int getSlotForDefaultSubscription() {
2327 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2328 }
2329
Wink Savilleb564aae2014-10-23 10:18:09 -07002330 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002331 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002333
2334 /**
2335 * @see android.telephony.TelephonyManager.WifiCallingChoices
2336 */
2337 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002338 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2339 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002340 }
2341
2342 /**
2343 * @see android.telephony.TelephonyManager.WifiCallingChoices
2344 */
2345 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002346 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2347 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2348 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002349 }
2350
Sailesh Nepald1e68152013-12-12 19:08:02 -08002351 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002352 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002353 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002354 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002355
Shishir Agrawal566b7612013-10-28 14:41:00 -07002356 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002357 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2358 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002359 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002360
Derek Tan740e1672017-06-27 14:56:27 -07002361 if (TextUtils.equals(ISDR_AID, aid)) {
2362 // Only allows LPA to open logical channel to ISD-R.
2363 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2364 ComponentInfo bestComponent =
2365 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2366 if (bestComponent == null
2367 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2368 loge("The calling package is not allowed to access ISD-R.");
2369 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2370 }
2371 }
2372
2373 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002374 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002375 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002376 if (DBG) log("iccOpenLogicalChannel: " + response);
2377 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002378 }
2379
2380 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002381 public boolean iccCloseLogicalChannel(int subId, int channel) {
2382 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002383
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002384 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002385 if (channel < 0) {
2386 return false;
2387 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002388 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002389 if (DBG) log("iccCloseLogicalChannel: " + success);
2390 return success;
2391 }
2392
2393 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002394 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002395 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002396 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002397
2398 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002399 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2400 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002401 " data=" + data);
2402 }
2403
2404 if (channel < 0) {
2405 return "";
2406 }
2407
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002408 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002409 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002410 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2411
Shishir Agrawal566b7612013-10-28 14:41:00 -07002412 // Append the returned status code to the end of the response payload.
2413 String s = Integer.toHexString(
2414 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002415 if (response.payload != null) {
2416 s = IccUtils.bytesToHexString(response.payload) + s;
2417 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002418 return s;
2419 }
Jake Hambye994d462014-02-03 13:10:13 -08002420
Evan Charltonc66da362014-05-16 14:06:40 -07002421 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002422 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002423 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002424 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002425
2426 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002427 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2428 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002429 }
2430
2431 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002432 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002433 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2434
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002435 // Append the returned status code to the end of the response payload.
2436 String s = Integer.toHexString(
2437 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002438 if (response.payload != null) {
2439 s = IccUtils.bytesToHexString(response.payload) + s;
2440 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002441 return s;
2442 }
2443
2444 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002445 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002446 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002447 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002448
2449 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002450 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002451 p1 + " " + p2 + " " + p3 + ":" + filePath);
2452 }
2453
2454 IccIoResult response =
2455 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002456 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2457 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002458
2459 if (DBG) {
2460 log("Exchange SIM_IO [R]" + response);
2461 }
2462
2463 byte[] result = null;
2464 int length = 2;
2465 if (response.payload != null) {
2466 length = 2 + response.payload.length;
2467 result = new byte[length];
2468 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2469 } else {
2470 result = new byte[length];
2471 }
2472
2473 result[length - 1] = (byte) response.sw2;
2474 result[length - 2] = (byte) response.sw1;
2475 return result;
2476 }
2477
Nathan Haroldb3014052017-01-25 15:57:32 -08002478 /**
2479 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2480 * on a particular subscription
2481 */
2482 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002483 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2484 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002485 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2486 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2487 return null;
2488 }
2489 Object response = sendRequest(
2490 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2491 if (response instanceof String[]) {
2492 return (String[]) response;
2493 }
2494 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2495 return null;
2496 }
2497
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002498 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002499 public String sendEnvelopeWithStatus(int subId, String content) {
2500 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002501
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002502 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002503 if (response.payload == null) {
2504 return "";
2505 }
2506
2507 // Append the returned status code to the end of the response payload.
2508 String s = Integer.toHexString(
2509 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2510 s = IccUtils.bytesToHexString(response.payload) + s;
2511 return s;
2512 }
2513
Jake Hambye994d462014-02-03 13:10:13 -08002514 /**
2515 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2516 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2517 *
2518 * @param itemID the ID of the item to read
2519 * @return the NV item as a String, or null on error.
2520 */
2521 @Override
2522 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002523 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002524 if (DBG) log("nvReadItem: item " + itemID);
2525 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2526 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2527 return value;
2528 }
2529
2530 /**
2531 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2532 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2533 *
2534 * @param itemID the ID of the item to read
2535 * @param itemValue the value to write, as a String
2536 * @return true on success; false on any failure
2537 */
2538 @Override
2539 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002540 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002541 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2542 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2543 new Pair<Integer, String>(itemID, itemValue));
2544 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2545 return success;
2546 }
2547
2548 /**
2549 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2550 * Used for device configuration by some CDMA operators.
2551 *
2552 * @param preferredRoamingList byte array containing the new PRL
2553 * @return true on success; false on any failure
2554 */
2555 @Override
2556 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002557 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002558 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2559 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2560 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2561 return success;
2562 }
2563
2564 /**
2565 * Perform the specified type of NV config reset.
2566 * Used for device configuration by some CDMA operators.
2567 *
2568 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2569 * @return true on success; false on any failure
2570 */
2571 @Override
2572 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002573 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002574 if (DBG) log("nvResetConfig: type " + resetType);
2575 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2576 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2577 return success;
2578 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002579
2580 /**
Wink Saville36469e72014-06-11 15:17:00 -07002581 * {@hide}
2582 * Returns Default sim, 0 in the case of single standby.
2583 */
2584 public int getDefaultSim() {
2585 //TODO Need to get it from Telephony Devcontroller
2586 return 0;
2587 }
2588
Svet Ganovb320e182015-04-16 12:30:10 -07002589 public String[] getPcscfAddress(String apnType, String callingPackage) {
2590 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2591 return new String[0];
2592 }
2593
2594
ram87fca6f2014-07-18 18:58:44 +05302595 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002596 }
2597
Brad Ebinger51f743a2017-01-23 13:50:20 -08002598 /**
Brad Ebinger34bef922017-11-09 10:27:08 -08002599 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2600 * feature or {@link null} if the service is not available. If the feature is available, the
2601 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002602 */
Brad Ebinger34bef922017-11-09 10:27:08 -08002603 public IImsMMTelFeature getMMTelFeatureAndListen(int slotId,
2604 IImsServiceFeatureCallback callback) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002605 enforceModifyPermission();
Brad Ebinger34bef922017-11-09 10:27:08 -08002606 return PhoneFactory.getImsResolver().getMMTelFeatureAndListen(slotId, callback);
2607 }
2608
2609 /**
2610 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2611 * feature during emergency calling or {@link null} if the service is not available. If the
2612 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2613 * listener for feature updates.
2614 */
2615 public IImsMMTelFeature getEmergencyMMTelFeatureAndListen(int slotId,
2616 IImsServiceFeatureCallback callback) {
2617 enforceModifyPermission();
2618 return PhoneFactory.getImsResolver().getEmergencyMMTelFeatureAndListen(slotId, callback);
2619 }
2620
2621 /**
2622 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2623 * feature during emergency calling or {@link null} if the service is not available. If the
2624 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2625 * listener for feature updates.
2626 */
2627 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2628 enforceModifyPermission();
2629 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002630 }
2631
Brad Ebinger7e934f52017-12-14 14:26:15 -08002632 /**
2633 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2634 * specified.
2635 */
2636 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2637 enforceModifyPermission();
2638 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2639 }
2640
Wink Saville36469e72014-06-11 15:17:00 -07002641 public void setImsRegistrationState(boolean registered) {
2642 enforceModifyPermission();
2643 mPhone.setImsRegistrationState(registered);
2644 }
2645
2646 /**
Stuart Scott54788802015-03-30 13:18:01 -07002647 * Set the network selection mode to automatic.
2648 *
2649 */
2650 @Override
2651 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002652 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002653 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2654 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2655 }
2656
2657 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002658 * Set the network selection mode to manual with the selected carrier.
2659 */
2660 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002661 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002662 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002663 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002664 OperatorInfo operator = new OperatorInfo(
2665 /* operatorAlphaLong */ "",
2666 /* operatorAlphaShort */ "",
2667 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002668 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002669 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2670 persistSelection);
2671 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002672 }
2673
2674 /**
2675 * Scans for available networks.
2676 */
2677 @Override
2678 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002679 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002680 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2681 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2682 CMD_PERFORM_NETWORK_SCAN, null, subId);
2683 return result;
2684 }
2685
2686 /**
yinxub1bed742017-04-17 11:45:04 -07002687 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002688 *
yinxub1bed742017-04-17 11:45:04 -07002689 * @param subId id of the subscription
2690 * @param request contains the radio access networks with bands/channels to scan
2691 * @param messenger callback messenger for scan results or errors
2692 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002693 * @return the id of the requested scan which can be used to stop the scan.
2694 */
2695 @Override
2696 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2697 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002698 enforceModifyPermissionOrCarrierPrivilege(subId);
2699 return mNetworkScanRequestTracker.startNetworkScan(
2700 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002701 }
2702
2703 /**
2704 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002705 *
2706 * @param subId id of the subscription
2707 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002708 */
2709 @Override
2710 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002711 enforceModifyPermissionOrCarrierPrivilege(subId);
2712 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002713 }
2714
2715 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002716 * Get the calculated preferred network type.
2717 * Used for debugging incorrect network type.
2718 *
2719 * @return the preferred network type, defined in RILConstants.java.
2720 */
2721 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002722 public int getCalculatedPreferredNetworkType(String callingPackage) {
2723 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2724 return RILConstants.PREFERRED_NETWORK_MODE;
2725 }
2726
Amit Mahajan43330e02014-11-18 11:54:45 -08002727 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002728 }
2729
2730 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002731 * Get the preferred network type.
2732 * Used for device configuration by some CDMA operators.
2733 *
2734 * @return the preferred network type, defined in RILConstants.java.
2735 */
2736 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002737 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002738 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002739 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002740 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002741 int networkType = (result != null ? result[0] : -1);
2742 if (DBG) log("getPreferredNetworkType: " + networkType);
2743 return networkType;
2744 }
2745
2746 /**
2747 * Set the preferred network type.
2748 * Used for device configuration by some CDMA operators.
2749 *
2750 * @param networkType the preferred network type, defined in RILConstants.java.
2751 * @return true on success; false on any failure.
2752 */
2753 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002754 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002755 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002756 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2757 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002758 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002759 if (success) {
2760 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002761 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002762 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002763 return success;
2764 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002765
2766 /**
Junda Liu475951f2014-11-07 16:45:03 -08002767 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2768 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2769 * tethering.
2770 *
2771 * @return 0: Not required. 1: required. 2: Not set.
2772 * @hide
2773 */
2774 @Override
2775 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002776 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002777 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2778 Settings.Global.TETHER_DUN_REQUIRED, 2);
2779 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2780 // config_tether_apndata.
2781 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2782 dunRequired = 1;
2783 }
2784 return dunRequired;
2785 }
2786
2787 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002788 * Set mobile data enabled
2789 * Used by the user through settings etc to turn on/off mobile data
2790 *
2791 * @param enable {@code true} turn turn data on, else {@code false}
2792 */
2793 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002794 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002795 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002796 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002797 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002798 Phone phone = PhoneFactory.getPhone(phoneId);
2799 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002800 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2801 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002802 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002803 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002804 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002805 }
2806
2807 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002808 * Get the user enabled state of Mobile Data.
2809 *
2810 * TODO: remove and use isUserDataEnabled.
2811 * This can't be removed now because some vendor codes
2812 * calls through ITelephony directly while they should
2813 * use TelephonyManager.
2814 *
2815 * @return true on enabled
2816 */
2817 @Override
2818 public boolean getDataEnabled(int subId) {
2819 return isUserDataEnabled(subId);
2820 }
2821
2822 /**
2823 * Get whether mobile data is enabled per user setting.
2824 *
2825 * There are other factors deciding whether mobile data is actually enabled, but they are
2826 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002827 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002828 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002829 *
2830 * @return {@code true} if data is enabled else {@code false}
2831 */
2832 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002833 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002834 try {
2835 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2836 null);
2837 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002838 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002839 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002840 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002841 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002842 Phone phone = PhoneFactory.getPhone(phoneId);
2843 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002844 boolean retVal = phone.isUserDataEnabled();
2845 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002846 return retVal;
2847 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002848 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2849 return false;
2850 }
2851 }
2852
2853 /**
2854 * Get whether mobile data is enabled.
2855 *
2856 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2857 * whether mobile data is actually enabled.
2858 *
2859 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2860 *
2861 * @return {@code true} if data is enabled else {@code false}
2862 */
2863 @Override
2864 public boolean isDataEnabled(int subId) {
2865 try {
2866 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2867 null);
2868 } catch (Exception e) {
2869 enforceModifyPermissionOrCarrierPrivilege(subId);
2870 }
2871 int phoneId = mSubscriptionController.getPhoneId(subId);
2872 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2873 Phone phone = PhoneFactory.getPhone(phoneId);
2874 if (phone != null) {
2875 boolean retVal = phone.isDataEnabled();
2876 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2877 return retVal;
2878 } else {
2879 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002880 return false;
2881 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002882 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002883
2884 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002885 public int getCarrierPrivilegeStatus(int subId) {
2886 final Phone phone = getPhone(subId);
2887 if (phone == null) {
2888 loge("getCarrierPrivilegeStatus: Invalid subId");
2889 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2890 }
2891 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002892 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002893 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002894 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2895 }
2896 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002897 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002898 }
Junda Liu29340342014-07-10 15:23:27 -07002899
2900 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002901 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002902 if (TextUtils.isEmpty(pkgName))
2903 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002904 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002905 if (card == null) {
2906 loge("checkCarrierPrivilegesForPackage: No UICC");
2907 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2908 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002909 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2910 }
2911
2912 @Override
2913 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002914 if (TextUtils.isEmpty(pkgName))
2915 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002916 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2917 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2918 UiccCard card = UiccController.getInstance().getUiccCard(i);
2919 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002920 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002921 continue;
2922 }
2923
2924 result = card.getCarrierPrivilegeStatus(
2925 mPhone.getContext().getPackageManager(), pkgName);
2926 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2927 break;
2928 }
2929 }
2930
2931 return result;
Junda Liu29340342014-07-10 15:23:27 -07002932 }
Derek Tan89e89d42014-07-08 17:00:10 -07002933
2934 @Override
Junda Liue64de782015-04-16 17:19:16 -07002935 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2936 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2937 loge("phoneId " + phoneId + " is not valid.");
2938 return null;
2939 }
2940 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002941 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002942 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002943 return null ;
2944 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002945 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002946 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002947 }
2948
Amith Yamasani6e118872016-02-19 12:53:51 -08002949 @Override
2950 public List<String> getPackagesWithCarrierPrivileges() {
2951 PackageManager pm = mPhone.getContext().getPackageManager();
2952 List<String> privilegedPackages = new ArrayList<>();
2953 List<PackageInfo> packages = null;
2954 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2955 UiccCard card = UiccController.getInstance().getUiccCard(i);
2956 if (card == null) {
2957 // No UICC in that slot.
2958 continue;
2959 }
2960 if (card.hasCarrierPrivilegeRules()) {
2961 if (packages == null) {
2962 // Only check packages in user 0 for now
2963 packages = pm.getInstalledPackagesAsUser(
2964 PackageManager.MATCH_DISABLED_COMPONENTS
2965 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2966 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2967 }
2968 for (int p = packages.size() - 1; p >= 0; p--) {
2969 PackageInfo pkgInfo = packages.get(p);
2970 if (pkgInfo != null && pkgInfo.packageName != null
2971 && card.getCarrierPrivilegeStatus(pkgInfo)
2972 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2973 privilegedPackages.add(pkgInfo.packageName);
2974 }
2975 }
2976 }
2977 }
2978 return privilegedPackages;
2979 }
2980
Wink Savilleb564aae2014-10-23 10:18:09 -07002981 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002982 final Phone phone = getPhone(subId);
2983 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002984 if (card == null) {
2985 loge("getIccId: No UICC");
2986 return null;
2987 }
2988 String iccId = card.getIccId();
2989 if (TextUtils.isEmpty(iccId)) {
2990 loge("getIccId: ICC ID is null or empty.");
2991 return null;
2992 }
2993 return iccId;
2994 }
2995
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002996 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002997 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2998 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002999 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07003000
Jeff Sharkey85190e62014-12-05 09:40:12 -08003001 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003002 final Phone phone = getPhone(subId);
3003 if (phone == null) {
3004 return false;
3005 }
3006 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003007
3008 if (DBG_MERGE) {
3009 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3010 + subscriberId + " to " + number);
3011 }
3012
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003013 if (TextUtils.isEmpty(iccId)) {
3014 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003015 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003016
Jeff Sharkey85190e62014-12-05 09:40:12 -08003017 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3018
3019 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003020 if (alphaTag == null) {
3021 editor.remove(alphaTagPrefKey);
3022 } else {
3023 editor.putString(alphaTagPrefKey, alphaTag);
3024 }
3025
Jeff Sharkey85190e62014-12-05 09:40:12 -08003026 // Record both the line number and IMSI for this ICCID, since we need to
3027 // track all merged IMSIs based on line number
3028 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3029 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003030 if (number == null) {
3031 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003032 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003033 } else {
3034 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003035 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003036 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003037
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003038 editor.commit();
3039 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003040 }
3041
3042 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003043 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003044 // This is open to apps with WRITE_SMS.
3045 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003046 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003047 return null;
3048 }
Derek Tan97ebb422014-09-05 16:55:38 -07003049
3050 String iccId = getIccId(subId);
3051 if (iccId != null) {
3052 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003053 if (DBG_MERGE) {
3054 log("getLine1NumberForDisplay returning " +
3055 mTelephonySharedPreferences.getString(numberPrefKey, null));
3056 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003057 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003058 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003059 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003060 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003061 }
3062
3063 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003064 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3065 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3066 return null;
3067 }
Derek Tan97ebb422014-09-05 16:55:38 -07003068
3069 String iccId = getIccId(subId);
3070 if (iccId != null) {
3071 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003072 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003073 }
Derek Tan97ebb422014-09-05 16:55:38 -07003074 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003075 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003076
3077 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003078 public String[] getMergedSubscriberIds(String callingPackage) {
3079 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3080 return null;
3081 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003082 final Context context = mPhone.getContext();
3083 final TelephonyManager tele = TelephonyManager.from(context);
3084 final SubscriptionManager sub = SubscriptionManager.from(context);
3085
3086 // Figure out what subscribers are currently active
3087 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003088 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3089 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 final int[] subIds = sub.getActiveSubscriptionIdList();
3093 for (int subId : subIds) {
3094 activeSubscriberIds.add(tele.getSubscriberId(subId));
3095 }
3096 } finally {
3097 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003098 }
3099
3100 // First pass, find a number override for an active subscriber
3101 String mergeNumber = null;
3102 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3103 for (String key : prefs.keySet()) {
3104 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3105 final String subscriberId = (String) prefs.get(key);
3106 if (activeSubscriberIds.contains(subscriberId)) {
3107 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3108 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3109 mergeNumber = (String) prefs.get(numberKey);
3110 if (DBG_MERGE) {
3111 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3112 + " for active subscriber " + subscriberId);
3113 }
3114 if (!TextUtils.isEmpty(mergeNumber)) {
3115 break;
3116 }
3117 }
3118 }
3119 }
3120
3121 // Shortcut when no active merged subscribers
3122 if (TextUtils.isEmpty(mergeNumber)) {
3123 return null;
3124 }
3125
3126 // Second pass, find all subscribers under that line override
3127 final ArraySet<String> result = new ArraySet<>();
3128 for (String key : prefs.keySet()) {
3129 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3130 final String number = (String) prefs.get(key);
3131 if (mergeNumber.equals(number)) {
3132 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3133 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3134 final String subscriberId = (String) prefs.get(subscriberKey);
3135 if (!TextUtils.isEmpty(subscriberId)) {
3136 result.add(subscriberId);
3137 }
3138 }
3139 }
3140 }
3141
3142 final String[] resultArray = result.toArray(new String[result.size()]);
3143 Arrays.sort(resultArray);
3144 if (DBG_MERGE) {
3145 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3146 }
3147 return resultArray;
3148 }
3149
3150 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003151 public boolean setOperatorBrandOverride(int subId, String brand) {
3152 enforceCarrierPrivilege(subId);
3153 final Phone phone = getPhone(subId);
3154 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003155 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003156
3157 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003158 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003159 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3160 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003161 enforceCarrierPrivilege(subId);
3162 final Phone phone = getPhone(subId);
3163 if (phone == null) {
3164 return false;
3165 }
3166 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003167 cdmaNonRoamingList);
3168 }
3169
3170 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003171 public void setRadioCapability(RadioAccessFamily[] rafs) {
3172 try {
3173 ProxyController.getInstance().setRadioCapability(rafs);
3174 } catch (RuntimeException e) {
3175 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3176 }
3177 }
3178
3179 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003180 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3181 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3182 return RadioAccessFamily.RAF_UNKNOWN;
3183 }
3184
Wink Saville5d475dd2014-10-17 15:00:58 -07003185 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3186 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003187
3188 @Override
3189 public void enableVideoCalling(boolean enable) {
3190 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003191 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003192 }
3193
3194 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003195 public boolean isVideoCallingEnabled(String callingPackage) {
3196 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3197 return false;
3198 }
3199
Andrew Lee77527ac2014-10-21 16:57:39 -07003200 // Check the user preference and the system-level IMS setting. Even if the user has
3201 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3202 // In the long run, we may instead need to check if there exists a connection service
3203 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003204 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3205 return imsManager.isVtEnabledByPlatform()
3206 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3207 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003208 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003209
Andrew Leea1239f22015-03-02 17:44:07 -08003210 @Override
3211 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003212 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003213 }
3214
3215 @Override
3216 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003217 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003218 }
3219
Andrew Lee9431b832015-03-09 18:46:45 -07003220 @Override
3221 public boolean isTtyModeSupported() {
3222 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3223 TelephonyManager telephonyManager =
3224 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003225 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003226 }
3227
3228 @Override
3229 public boolean isHearingAidCompatibilitySupported() {
3230 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3231 }
3232
Sanket Padawe7310cc72015-01-14 09:53:20 -08003233 /**
3234 * Returns the unique device ID of phone, for example, the IMEI for
3235 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3236 *
3237 * <p>Requires Permission:
3238 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3239 */
3240 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003241 public String getDeviceId(String callingPackage) {
3242 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3243 return null;
3244 }
3245
Sanket Padawe7310cc72015-01-14 09:53:20 -08003246 final Phone phone = PhoneFactory.getPhone(0);
3247 if (phone != null) {
3248 return phone.getDeviceId();
3249 } else {
3250 return null;
3251 }
3252 }
3253
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003254 /*
3255 * {@hide}
3256 * Returns the IMS Registration Status
3257 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003258 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003259 public boolean isImsRegistered() {
3260 return mPhone.isImsRegistered();
3261 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003262
Ping Sun014fe8e2016-03-02 19:16:45 +08003263 /**
3264 * {@hide}
3265 * Returns the IMS Registration Status on a particular subid
3266 *
3267 * @param subId
3268 */
3269 public boolean isImsRegisteredForSubscriber(int subId) {
3270 Phone phone = getPhone(subId);
3271 if (phone != null) {
3272 return phone.isImsRegistered();
3273 } else {
3274 return false;
3275 }
3276 }
3277
Santos Cordon7a1885b2015-02-03 11:15:19 -08003278 @Override
3279 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3280 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3281 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003282
Nathan Haroldc55097a2015-03-11 18:14:50 -07003283 /*
3284 * {@hide}
3285 * Returns the IMS Registration Status
3286 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003287 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003288 return mPhone.isWifiCallingEnabled();
3289 }
3290
3291 /*
3292 * {@hide}
3293 * Returns the IMS Registration Status
3294 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003295 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003296 return mPhone.isVolteEnabled();
3297 }
Svet Ganovb320e182015-04-16 12:30:10 -07003298
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003299 /*
3300 * {@hide} Returns the IMS Registration Status
3301 */
3302 public boolean isVideoTelephonyAvailable() {
3303 return mPhone.isVideoEnabled();
3304 }
3305
Svet Ganovb320e182015-04-16 12:30:10 -07003306 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003307 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003308 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003309 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3310
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003311 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003312 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003313 } catch (SecurityException e) {
3314 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3315 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003316 }
Svet Ganovb320e182015-04-16 12:30:10 -07003317
3318 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3319 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3320 return false;
3321 }
3322
3323 return true;
3324 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003325
Makoto Onukifee69342015-06-29 14:44:50 -07003326 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003327 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003328 */
3329 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003330 // Default SMS app can always read it.
3331 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3332 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3333 return true;
3334 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003335
Makoto Onukie4072d12015-08-03 15:12:23 -07003336 try {
3337 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003338 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003339 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003340 // Can be read with READ_SMS too.
3341 try {
3342 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3343 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3344 if (opCode != AppOpsManager.OP_NONE) {
3345 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3346 == AppOpsManager.MODE_ALLOWED;
3347 } else {
3348 return true;
3349 }
3350 } catch (SecurityException readSmsSecurityException) {
3351 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003352 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003353 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003354 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003355 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003356 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003357 if (opCode != AppOpsManager.OP_NONE) {
3358 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3359 == AppOpsManager.MODE_ALLOWED;
3360 } else {
3361 return true;
3362 }
3363 } catch (SecurityException readPhoneNumberSecurityException) {
3364 }
3365
3366 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3367 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3368 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003369 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003370 }
3371
Stuart Scott8eef64f2015-04-08 15:13:54 -07003372 @Override
3373 public void factoryReset(int subId) {
3374 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003375 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3376 return;
3377 }
3378
Svet Ganovcc087f82015-05-12 20:35:54 -07003379 final long identity = Binder.clearCallingIdentity();
3380 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003381 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3382 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003383 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003384 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003385 // Set network selection mode to automatic
3386 setNetworkSelectionModeAutomatic(subId);
3387 // Set preferred mobile network type to the best available
3388 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3389 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003390 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003391 }
3392 } finally {
3393 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003394 }
3395 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003396
3397 @Override
3398 public String getLocaleFromDefaultSim() {
3399 // We query all subscriptions instead of just the active ones, because
3400 // this might be called early on in the provisioning flow when the
3401 // subscriptions potentially aren't active yet.
3402 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3403 if (slist == null || slist.isEmpty()) {
3404 return null;
3405 }
3406
3407 // This function may be called very early, say, from the setup wizard, at
3408 // which point we won't have a default subscription set. If that's the case
3409 // we just choose the first, which will be valid in "most cases".
3410 final int defaultSubId = getDefaultSubscription();
3411 SubscriptionInfo info = null;
3412 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3413 info = slist.get(0);
3414 } else {
3415 for (SubscriptionInfo item : slist) {
3416 if (item.getSubscriptionId() == defaultSubId) {
3417 info = item;
3418 break;
3419 }
3420 }
3421
3422 if (info == null) {
3423 return null;
3424 }
3425 }
3426
3427 // Try and fetch the locale from the carrier properties or from the SIM language
3428 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003429 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003430 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003431 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003432 if (defaultPhone != null) {
3433 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3434 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003435 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003436 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3437 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003438 } else {
3439 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003440 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003441 }
3442 }
3443
Narayan Kamath011676f2015-07-29 12:04:08 +01003444 // The SIM language preferences only store a language (e.g. fr = French), not an
3445 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3446 // the SIM and carrier preferences does not include a country we add the country
3447 // determined from the SIM MCC to provide an exact locale.
3448 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003449 if (mccLocale != null) {
3450 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3451 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003452 }
3453
Tony Hill183b2de2015-06-24 14:53:58 +01003454 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003455 return null;
3456 }
3457
3458 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3459 final long identity = Binder.clearCallingIdentity();
3460 try {
3461 return mSubscriptionController.getAllSubInfoList(
3462 mPhone.getContext().getOpPackageName());
3463 } finally {
3464 Binder.restoreCallingIdentity(identity);
3465 }
3466 }
3467
3468 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3469 final long identity = Binder.clearCallingIdentity();
3470 try {
3471 return mSubscriptionController.getActiveSubscriptionInfoList(
3472 mPhone.getContext().getOpPackageName());
3473 } finally {
3474 Binder.restoreCallingIdentity(identity);
3475 }
3476 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003477
3478 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003479 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3480 * representing the state of the modem.
3481 *
3482 * NOTE: This clears the modem state, so there should only every be one caller.
3483 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003484 */
3485 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003486 public void requestModemActivityInfo(ResultReceiver result) {
3487 enforceModifyPermission();
3488
3489 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3490 Bundle bundle = new Bundle();
3491 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3492 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003493 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003494
3495 /**
3496 * {@hide}
3497 * Returns the service state information on specified subscription.
3498 */
3499 @Override
3500 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3501
3502 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3503 return null;
3504 }
3505
3506 final Phone phone = getPhone(subId);
3507 if (phone == null) {
3508 return null;
3509 }
3510
3511 return phone.getServiceState();
3512 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003513
3514 /**
3515 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3516 *
3517 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3518 * voicemail ringtone.
3519 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3520 * PhoneAccount.
3521 */
3522 @Override
3523 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003524 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003525 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003526 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003527 }
3528
fionaxu7ed723d2017-05-30 18:58:54 -07003529 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003530 }
3531
3532 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003533 * Sets the per-account voicemail ringtone.
3534 *
3535 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3536 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3537 *
3538 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3539 * voicemail ringtone.
3540 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3541 * PhoneAccount.
3542 */
3543 @Override
3544 public void setVoicemailRingtoneUri(String callingPackage,
3545 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3546 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3547 if (!TextUtils.equals(callingPackage,
3548 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3549 enforceModifyPermissionOrCarrierPrivilege(
3550 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3551 }
3552 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3553 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003554 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003555 }
fionaxu7ed723d2017-05-30 18:58:54 -07003556 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003557 }
3558
3559 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003560 * Returns whether vibration is set for voicemail notification in Phone settings.
3561 *
3562 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3563 * voicemail vibration setting.
3564 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3565 */
3566 @Override
3567 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003568 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003569 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003570 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003571 }
3572
fionaxu7ed723d2017-05-30 18:58:54 -07003573 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003574 }
3575
Youhan Wange64578a2016-05-02 15:32:42 -07003576 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003577 * Sets the per-account voicemail vibration.
3578 *
3579 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3580 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3581 *
3582 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3583 * voicemail vibration setting.
3584 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3585 * specific PhoneAccount.
3586 */
3587 @Override
3588 public void setVoicemailVibrationEnabled(String callingPackage,
3589 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3590 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3591 if (!TextUtils.equals(callingPackage,
3592 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3593 enforceModifyPermissionOrCarrierPrivilege(
3594 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3595 }
3596
3597 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3598 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003599 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003600 }
fionaxu7ed723d2017-05-30 18:58:54 -07003601 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003602 }
3603
3604 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003605 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3606 *
3607 * @throws SecurityException if the caller does not have the required permission
3608 */
3609 private void enforceReadPrivilegedPermission() {
3610 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3611 null);
3612 }
3613
3614 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003615 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3616 * permission.
3617 *
3618 * @throws SecurityException if the caller does not have the required permission
3619 */
3620 private void enforceSendSmsPermission() {
3621 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3622 }
3623
3624 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003625 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003626 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003627 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003628 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003629 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003630 ComponentName componentName =
3631 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3632 if(componentName == null) {
3633 throw new SecurityException("Caller not current active visual voicemail package[null]");
3634 }
3635 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003636 if (!callingPackage.equals(vvmPackage)) {
3637 throw new SecurityException("Caller not current active visual voicemail package[" +
3638 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003639 }
3640 }
3641
3642 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003643 * Return the application ID for the app type.
3644 *
3645 * @param subId the subscription ID that this request applies to.
3646 * @param appType the uicc app type.
3647 * @return Application ID for specificied app type, or null if no uicc.
3648 */
3649 @Override
3650 public String getAidForAppType(int subId, int appType) {
3651 enforceReadPrivilegedPermission();
3652 Phone phone = getPhone(subId);
3653 if (phone == null) {
3654 return null;
3655 }
3656 String aid = null;
3657 try {
3658 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3659 .getApplicationByType(appType).getAid();
3660 } catch (Exception e) {
3661 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3662 }
3663 return aid;
3664 }
3665
Youhan Wang4001d252016-05-11 10:29:41 -07003666 /**
3667 * Return the Electronic Serial Number.
3668 *
3669 * @param subId the subscription ID that this request applies to.
3670 * @return ESN or null if error.
3671 */
3672 @Override
3673 public String getEsn(int subId) {
3674 enforceReadPrivilegedPermission();
3675 Phone phone = getPhone(subId);
3676 if (phone == null) {
3677 return null;
3678 }
3679 String esn = null;
3680 try {
3681 esn = phone.getEsn();
3682 } catch (Exception e) {
3683 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3684 }
3685 return esn;
3686 }
3687
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003688 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003689 * Return the Preferred Roaming List Version.
3690 *
3691 * @param subId the subscription ID that this request applies to.
3692 * @return PRLVersion or null if error.
3693 */
3694 @Override
3695 public String getCdmaPrlVersion(int subId) {
3696 enforceReadPrivilegedPermission();
3697 Phone phone = getPhone(subId);
3698 if (phone == null) {
3699 return null;
3700 }
3701 String cdmaPrlVersion = null;
3702 try {
3703 cdmaPrlVersion = phone.getCdmaPrlVersion();
3704 } catch (Exception e) {
3705 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3706 }
3707 return cdmaPrlVersion;
3708 }
3709
3710 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003711 * Get snapshot of Telephony histograms
3712 * @return List of Telephony histograms
3713 * @hide
3714 */
3715 @Override
3716 public List<TelephonyHistogram> getTelephonyHistograms() {
3717 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3718 return RIL.getTelephonyRILTimingHistograms();
3719 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003720
3721 /**
3722 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003723 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003724 * Require system privileges. In the future we may add this to carrier APIs.
3725 *
3726 * @return The number of carriers set successfully, should match length of carriers
3727 */
3728 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003729 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003730 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003731
Meng Wang9b7c4e92017-02-17 11:41:27 -08003732 if (carriers == null) {
3733 throw new NullPointerException("carriers cannot be null");
3734 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003735
3736 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003737 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3738 return retVal[0];
3739 }
3740
3741 /**
3742 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003743 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003744 * Require system privileges. In the future we may add this to carrier APIs.
3745 *
3746 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3747 * means all carriers are allowed.
3748 */
3749 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003750 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003751 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003752 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003753 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3754 }
3755
fionaxu59545b42016-05-25 15:53:37 -07003756 /**
3757 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3758 * @param subId the subscription ID that this action applies to.
3759 * @param enabled control enable or disable metered apns.
3760 * {@hide}
3761 */
3762 @Override
3763 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3764 enforceModifyPermission();
3765 final Phone phone = getPhone(subId);
3766 if (phone == null) {
3767 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3768 return;
3769 }
3770 try {
3771 phone.carrierActionSetMeteredApnsEnabled(enabled);
3772 } catch (Exception e) {
3773 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3774 }
3775 }
3776
3777 /**
3778 * Action set from carrier signalling broadcast receivers to enable/disable radio
3779 * @param subId the subscription ID that this action applies to.
3780 * @param enabled control enable or disable radio.
3781 * {@hide}
3782 */
3783 @Override
3784 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3785 enforceModifyPermission();
3786 final Phone phone = getPhone(subId);
3787 if (phone == null) {
3788 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3789 return;
3790 }
3791 try {
3792 phone.carrierActionSetRadioEnabled(enabled);
3793 } catch (Exception e) {
3794 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3795 }
3796 }
3797
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003798 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003799 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3800 * network status based on which carrier apps could apply actions accordingly,
3801 * enable/disable default url handler for example.
3802 *
3803 * @param subId the subscription ID that this action applies to.
3804 * @param report control start/stop reporting the default network status.
3805 * {@hide}
3806 */
3807 @Override
3808 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3809 enforceModifyPermission();
3810 final Phone phone = getPhone(subId);
3811 if (phone == null) {
3812 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3813 return;
3814 }
3815 try {
3816 phone.carrierActionReportDefaultNetworkStatus(report);
3817 } catch (Exception e) {
3818 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3819 }
3820 }
3821
3822 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003823 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3824 * bug report is being generated.
3825 */
3826 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003827 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003828 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3829 != PackageManager.PERMISSION_GRANTED) {
3830 writer.println("Permission Denial: can't dump Phone from pid="
3831 + Binder.getCallingPid()
3832 + ", uid=" + Binder.getCallingUid()
3833 + "without permission "
3834 + android.Manifest.permission.DUMP);
3835 return;
3836 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003837 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003838 }
Jack Yueb89b242016-06-22 13:27:47 -07003839
3840 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003841 * Get aggregated video call data usage since boot.
3842 *
3843 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3844 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003845 * {@hide}
3846 */
3847 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003848 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003849 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3850 null);
3851
Jack Yu84291ec2017-05-26 16:07:50 -07003852 // NetworkStatsService keeps tracking the active network interface and identity. It
3853 // records the delta with the corresponding network identity. We just return the total video
3854 // call data usage snapshot since boot.
3855 Phone phone = getPhone(subId);
3856 if (phone != null) {
3857 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003858 }
Jack Yu84291ec2017-05-26 16:07:50 -07003859 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003860 }
Jack Yu75ab2952016-07-08 14:29:33 -07003861
3862 /**
3863 * Policy control of data connection. Usually used when data limit is passed.
3864 * @param enabled True if enabling the data, otherwise disabling.
3865 * @param subId Subscription index
3866 * {@hide}
3867 */
3868 @Override
3869 public void setPolicyDataEnabled(boolean enabled, int subId) {
3870 enforceModifyPermission();
3871 Phone phone = getPhone(subId);
3872 if (phone != null) {
3873 phone.setPolicyDataEnabled(enabled);
3874 }
3875 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003876
3877 /**
3878 * Get Client request stats
3879 * @return List of Client Request Stats
3880 * @hide
3881 */
3882 @Override
3883 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3884 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3885 return null;
3886 }
3887
3888 Phone phone = getPhone(subId);
3889 if (phone != null) {
3890 return phone.getClientRequestStats();
3891 }
3892
3893 return null;
3894 }
3895
3896 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3897 if (workSource != null) {
3898 return workSource;
3899 }
3900
3901 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3902 workSource = new WorkSource(uid, packageName);
3903 return workSource;
3904 }
Jack Yueb4124c2017-02-16 15:32:43 -08003905
3906 /**
Grace Chen70990072017-03-24 17:21:30 -07003907 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003908 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003909 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003910 * @param state State of SIM (power down, power up, pass through)
3911 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3912 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3913 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003914 *
3915 **/
3916 @Override
Grace Chen70990072017-03-24 17:21:30 -07003917 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003918 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003919 Phone phone = PhoneFactory.getPhone(slotIndex);
3920
Jack Yueb4124c2017-02-16 15:32:43 -08003921 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003922 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003923 }
3924 }
Shuo Qiandd210312017-04-12 22:11:33 +00003925
Tyler Gunn65d45c22017-06-05 11:22:26 -07003926 private boolean isUssdApiAllowed(int subId) {
3927 CarrierConfigManager configManager =
3928 (CarrierConfigManager) mPhone.getContext().getSystemService(
3929 Context.CARRIER_CONFIG_SERVICE);
3930 if (configManager == null) {
3931 return false;
3932 }
3933 PersistableBundle pb = configManager.getConfigForSubId(subId);
3934 if (pb == null) {
3935 return false;
3936 }
3937 return pb.getBoolean(
3938 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3939 }
3940
Shuo Qiandd210312017-04-12 22:11:33 +00003941 /**
3942 * Check if phone is in emergency callback mode
3943 * @return true if phone is in emergency callback mode
3944 * @param subId sub id
3945 */
3946 public boolean getEmergencyCallbackMode(int subId) {
3947 final Phone phone = getPhone(subId);
3948 if (phone != null) {
3949 return phone.isInEcm();
3950 } else {
3951 return false;
3952 }
3953 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003954
3955 /**
3956 * Get the current signal strength information for the given subscription.
3957 * Because this information is not updated when the device is in a low power state
3958 * it should not be relied-upon to be current.
3959 * @param subId Subscription index
3960 * @return the most recent cached signal strength info from the modem
3961 */
3962 @Override
3963 public SignalStrength getSignalStrength(int subId) {
3964 Phone p = getPhone(subId);
3965 if (p == null) {
3966 return null;
3967 }
3968
3969 return p.getSignalStrength();
3970 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00003971
3972 @Override
3973 public UiccSlotInfo[] getUiccSlotsInfo() {
3974 enforceReadPrivilegedPermission();
3975
3976 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
3977 if (slots == null) return null;
3978 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
3979 for (int i = 0; i < slots.length; i++) {
3980 UiccSlot slot = slots[i];
3981
3982 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
3983
3984 int cardState = 0;
3985 switch (slot.getCardState()) {
3986 case CARDSTATE_ABSENT:
3987 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
3988 break;
3989 case CARDSTATE_PRESENT:
3990 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
3991 break;
3992 case CARDSTATE_ERROR:
3993 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
3994 break;
3995 case CARDSTATE_RESTRICTED:
3996 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
3997 break;
3998 default:
3999 break;
4000
4001 }
4002
4003 infos[i] = new UiccSlotInfo(slot.isActive(), slot.isEuicc(), cardId, cardState);
4004 }
4005 return infos;
4006 }
4007
4008 @Override
4009 public boolean switchSlots(int[] physicalSlots) {
4010 enforceModifyPermission();
4011 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004013}