blob: fd7caaaafc3400e0a037f68248ba056e39ffc317 [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 Ebinger5f64b052017-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 Ebinger5f64b052017-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;
pkanwar79ec0542017-07-31 14:10:01 -070086import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070087import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070088import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080091import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010092import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070093import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070094import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080096import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070097import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070098import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070099import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700100import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700101import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800102import com.android.internal.telephony.SubscriptionController;
Jonathan Basseribf5362b2017-07-19 12:22:35 -0700103import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700104import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700105import com.android.internal.telephony.uicc.IccIoResult;
106import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800107import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700108import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800109import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700110import com.android.internal.telephony.uicc.UiccController;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000111import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700112import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800113import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700114import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800115import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700116import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700117import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800118
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700119import java.io.FileDescriptor;
120import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800123import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800124import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100125import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800126import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127
128/**
129 * Implementation of the ITelephony interface.
130 */
Santos Cordon117fee72014-05-16 17:56:12 -0700131public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132 private static final String LOG_TAG = "PhoneInterfaceManager";
133 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
134 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800135 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136
137 // Message codes used with mMainThreadHandler
138 private static final int CMD_HANDLE_PIN_MMI = 1;
139 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
140 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
141 private static final int CMD_ANSWER_RINGING_CALL = 4;
142 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700143 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
144 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700145 private static final int CMD_OPEN_CHANNEL = 9;
146 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
147 private static final int CMD_CLOSE_CHANNEL = 11;
148 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800149 private static final int CMD_NV_READ_ITEM = 13;
150 private static final int EVENT_NV_READ_ITEM_DONE = 14;
151 private static final int CMD_NV_WRITE_ITEM = 15;
152 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
153 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
154 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
155 private static final int CMD_NV_RESET_CONFIG = 19;
156 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800157 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
158 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
159 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
160 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800161 private static final int CMD_SEND_ENVELOPE = 25;
162 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700163 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
164 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
165 private static final int CMD_EXCHANGE_SIM_IO = 31;
166 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800167 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
168 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700169 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
170 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700171 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
172 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700173 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
174 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
175 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
176 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700177 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
178 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
179 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
180 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700181 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800182 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
183 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000184 private static final int CMD_SWITCH_SLOTS = 50;
185 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186
187 /** The singleton instance. */
188 private static PhoneInterfaceManager sInstance;
189
Wink Saville3ab207e2014-11-20 13:07:20 -0800190 private PhoneGlobals mApp;
191 private Phone mPhone;
192 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700193 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800194 private AppOpsManager mAppOps;
195 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800196 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800197 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198
Derek Tan97ebb422014-09-05 16:55:38 -0700199 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
200 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800201 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700202
Derek Tan740e1672017-06-27 14:56:27 -0700203 // The AID of ISD-R.
204 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
205
yinxub1bed742017-04-17 11:45:04 -0700206 private NetworkScanRequestTracker mNetworkScanRequestTracker;
207
Derek Tan89e89d42014-07-08 17:00:10 -0700208 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700209 * A request object to use for transmitting data to an ICC.
210 */
211 private static final class IccAPDUArgument {
212 public int channel, cla, command, p1, p2, p3;
213 public String data;
214
215 public IccAPDUArgument(int channel, int cla, int command,
216 int p1, int p2, int p3, String data) {
217 this.channel = channel;
218 this.cla = cla;
219 this.command = command;
220 this.p1 = p1;
221 this.p2 = p2;
222 this.p3 = p3;
223 this.data = data;
224 }
225 }
226
227 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700228 * A request object to use for transmitting data to an ICC.
229 */
230 private static final class ManualNetworkSelectionArgument {
231 public OperatorInfo operatorInfo;
232 public boolean persistSelection;
233
234 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
235 this.operatorInfo = operatorInfo;
236 this.persistSelection = persistSelection;
237 }
238 }
239
240 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700241 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
242 * request after sending. The main thread will notify the request when it is complete.
243 */
244 private static final class MainThreadRequest {
245 /** The argument to use for the request */
246 public Object argument;
247 /** The result of the request that is run on the main thread */
248 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800249 // The subscriber id that this request applies to. Defaults to
250 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
251 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700252
253 public MainThreadRequest(Object argument) {
254 this.argument = argument;
255 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800256
257 public MainThreadRequest(Object argument, Integer subId) {
258 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800259 if (subId != null) {
260 this.subId = subId;
261 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700263 }
264
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800265 private static final class IncomingThirdPartyCallArgs {
266 public final ComponentName component;
267 public final String callId;
268 public final String callerDisplayName;
269
270 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
271 String callerDisplayName) {
272 this.component = component;
273 this.callId = callId;
274 this.callerDisplayName = callerDisplayName;
275 }
276 }
277
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700278 /**
279 * A handler that processes messages on the main thread in the phone process. Since many
280 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
281 * inbound binder threads to the main thread in the phone process. The Binder thread
282 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
283 * on, which will be notified when the operation completes and will contain the result of the
284 * request.
285 *
286 * <p>If a MainThreadRequest object is provided in the msg.obj field,
287 * note that request.result must be set to something non-null for the calling thread to
288 * unblock.
289 */
290 private final class MainThreadHandler extends Handler {
291 @Override
292 public void handleMessage(Message msg) {
293 MainThreadRequest request;
294 Message onCompleted;
295 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800296 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700297 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298
299 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700300 case CMD_HANDLE_USSD_REQUEST: {
301 request = (MainThreadRequest) msg.obj;
302 final Phone phone = getPhoneFromRequest(request);
303 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
304 String ussdRequest = ussdObject.first;
305 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700306
307 if (!isUssdApiAllowed(request.subId)) {
308 // Carrier does not support use of this API, return failure.
309 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
310 UssdResponse response = new UssdResponse(ussdRequest, null);
311 Bundle returnData = new Bundle();
312 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
313 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
314
315 request.result = true;
316 synchronized (request) {
317 request.notifyAll();
318 }
319 return;
320 }
321
Tyler Gunn52dcf772017-04-26 11:30:31 -0700322 try {
323 request.result = phone != null ?
324 phone.handleUssdRequest(ussdRequest, wrappedCallback)
325 : false;
326 } catch (CallStateException cse) {
327 request.result = false;
328 }
pkanwar32d516d2016-10-14 19:37:38 -0700329 // Wake up the requesting thread
330 synchronized (request) {
331 request.notifyAll();
332 }
333 break;
334 }
335
Yorke Lee716f67e2015-06-17 15:39:16 -0700336 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700338 final Phone phone = getPhoneFromRequest(request);
339 request.result = phone != null ?
340 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
341 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 // Wake up the requesting thread
343 synchronized (request) {
344 request.notifyAll();
345 }
346 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348
349 case CMD_HANDLE_NEIGHBORING_CELL:
350 request = (MainThreadRequest) msg.obj;
351 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
352 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700353 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 break;
355
356 case EVENT_NEIGHBORING_CELL_DONE:
357 ar = (AsyncResult) msg.obj;
358 request = (MainThreadRequest) ar.userObj;
359 if (ar.exception == null && ar.result != null) {
360 request.result = ar.result;
361 } else {
362 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800363 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 }
365 // Wake up the requesting thread
366 synchronized (request) {
367 request.notifyAll();
368 }
369 break;
370
371 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700372 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800373 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700374 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700375 break;
376
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377 case CMD_END_CALL:
378 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800379 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700380 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700381 Phone phone = getPhone(end_subId);
382 if (phone == null) {
383 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
384 break;
385 }
386 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
388 // CDMA: If the user presses the Power button we treat it as
389 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700390 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
392 // GSM: End the call as per the Phone state
393 hungUp = PhoneUtils.hangup(mCM);
394 } else {
395 throw new IllegalStateException("Unexpected phone type: " + phoneType);
396 }
397 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
398 request.result = hungUp;
399 // Wake up the requesting thread
400 synchronized (request) {
401 request.notifyAll();
402 }
403 break;
404
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700405 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700406 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700407 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800408 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700409 if (uiccCard == null) {
410 loge("iccTransmitApduLogicalChannel: No UICC");
411 request.result = new IccIoResult(0x6F, 0, (byte[])null);
412 synchronized (request) {
413 request.notifyAll();
414 }
415 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
417 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700418 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700419 iccArgument.channel, iccArgument.cla, iccArgument.command,
420 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700421 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700422 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700423 break;
424
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700426 ar = (AsyncResult) msg.obj;
427 request = (MainThreadRequest) ar.userObj;
428 if (ar.exception == null && ar.result != null) {
429 request.result = ar.result;
430 } else {
431 request.result = new IccIoResult(0x6F, 0, (byte[])null);
432 if (ar.result == null) {
433 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800434 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800436 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700437 } else {
438 loge("iccTransmitApduLogicalChannel: Unknown exception");
439 }
440 }
441 synchronized (request) {
442 request.notifyAll();
443 }
444 break;
445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
447 request = (MainThreadRequest) msg.obj;
448 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800449 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700450 if (uiccCard == null) {
451 loge("iccTransmitApduBasicChannel: No UICC");
452 request.result = new IccIoResult(0x6F, 0, (byte[])null);
453 synchronized (request) {
454 request.notifyAll();
455 }
456 } else {
457 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
458 request);
459 uiccCard.iccTransmitApduBasicChannel(
460 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
461 iccArgument.p3, iccArgument.data, onCompleted);
462 }
463 break;
464
465 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
466 ar = (AsyncResult) msg.obj;
467 request = (MainThreadRequest) ar.userObj;
468 if (ar.exception == null && ar.result != null) {
469 request.result = ar.result;
470 } else {
471 request.result = new IccIoResult(0x6F, 0, (byte[])null);
472 if (ar.result == null) {
473 loge("iccTransmitApduBasicChannel: Empty response");
474 } else if (ar.exception instanceof CommandException) {
475 loge("iccTransmitApduBasicChannel: CommandException: " +
476 ar.exception);
477 } else {
478 loge("iccTransmitApduBasicChannel: Unknown exception");
479 }
480 }
481 synchronized (request) {
482 request.notifyAll();
483 }
484 break;
485
486 case CMD_EXCHANGE_SIM_IO:
487 request = (MainThreadRequest) msg.obj;
488 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 if (uiccCard == null) {
491 loge("iccExchangeSimIO: No UICC");
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
493 synchronized (request) {
494 request.notifyAll();
495 }
496 } else {
497 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
498 request);
499 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
500 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
501 iccArgument.data, onCompleted);
502 }
503 break;
504
505 case EVENT_EXCHANGE_SIM_IO_DONE:
506 ar = (AsyncResult) msg.obj;
507 request = (MainThreadRequest) ar.userObj;
508 if (ar.exception == null && ar.result != null) {
509 request.result = ar.result;
510 } else {
511 request.result = new IccIoResult(0x6f, 0, (byte[])null);
512 }
513 synchronized (request) {
514 request.notifyAll();
515 }
516 break;
517
Derek Tan4d5e5c12014-02-04 11:54:58 -0800518 case CMD_SEND_ENVELOPE:
519 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800520 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700521 if (uiccCard == null) {
522 loge("sendEnvelopeWithStatus: No UICC");
523 request.result = new IccIoResult(0x6F, 0, (byte[])null);
524 synchronized (request) {
525 request.notifyAll();
526 }
527 } else {
528 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
529 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
530 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800531 break;
532
533 case EVENT_SEND_ENVELOPE_DONE:
534 ar = (AsyncResult) msg.obj;
535 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700536 if (ar.exception == null && ar.result != null) {
537 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800538 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700539 request.result = new IccIoResult(0x6F, 0, (byte[])null);
540 if (ar.result == null) {
541 loge("sendEnvelopeWithStatus: Empty response");
542 } else if (ar.exception instanceof CommandException) {
543 loge("sendEnvelopeWithStatus: CommandException: " +
544 ar.exception);
545 } else {
546 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
547 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800548 }
549 synchronized (request) {
550 request.notifyAll();
551 }
552 break;
553
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 case CMD_OPEN_CHANNEL:
555 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800556 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800557 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 if (uiccCard == null) {
559 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800560 request.result = new IccOpenLogicalChannelResponse(-1,
561 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 synchronized (request) {
563 request.notifyAll();
564 }
565 } else {
566 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800567 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
568 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 break;
571
572 case EVENT_OPEN_CHANNEL_DONE:
573 ar = (AsyncResult) msg.obj;
574 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700575 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700577 int[] result = (int[]) ar.result;
578 int channelId = result[0];
579 byte[] selectResponse = null;
580 if (result.length > 1) {
581 selectResponse = new byte[result.length - 1];
582 for (int i = 1; i < result.length; ++i) {
583 selectResponse[i - 1] = (byte) result[i];
584 }
585 }
586 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700587 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 if (ar.result == null) {
590 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 if (ar.exception != null) {
593 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
594 }
595
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700597 if (ar.exception instanceof CommandException) {
598 CommandException.Error error =
599 ((CommandException) (ar.exception)).getCommandError();
600 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700601 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700602 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700603 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 }
605 }
606 openChannelResp = new IccOpenLogicalChannelResponse(
607 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700609 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 synchronized (request) {
611 request.notifyAll();
612 }
613 break;
614
615 case CMD_CLOSE_CHANNEL:
616 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800617 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700618 if (uiccCard == null) {
619 loge("iccCloseLogicalChannel: No UICC");
620 request.result = new IccIoResult(0x6F, 0, (byte[])null);
621 synchronized (request) {
622 request.notifyAll();
623 }
624 } else {
625 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
626 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
627 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 break;
629
630 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800631 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
632 break;
633
634 case CMD_NV_READ_ITEM:
635 request = (MainThreadRequest) msg.obj;
636 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
637 mPhone.nvReadItem((Integer) request.argument, onCompleted);
638 break;
639
640 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800646 request.result = "";
647 if (ar.result == null) {
648 loge("nvReadItem: Empty response");
649 } else if (ar.exception instanceof CommandException) {
650 loge("nvReadItem: CommandException: " +
651 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800653 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 }
655 }
656 synchronized (request) {
657 request.notifyAll();
658 }
659 break;
660
Jake Hambye994d462014-02-03 13:10:13 -0800661 case CMD_NV_WRITE_ITEM:
662 request = (MainThreadRequest) msg.obj;
663 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
664 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
665 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
666 break;
667
668 case EVENT_NV_WRITE_ITEM_DONE:
669 handleNullReturnEvent(msg, "nvWriteItem");
670 break;
671
672 case CMD_NV_WRITE_CDMA_PRL:
673 request = (MainThreadRequest) msg.obj;
674 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
675 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
676 break;
677
678 case EVENT_NV_WRITE_CDMA_PRL_DONE:
679 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
680 break;
681
682 case CMD_NV_RESET_CONFIG:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
685 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
686 break;
687
688 case EVENT_NV_RESET_CONFIG_DONE:
689 handleNullReturnEvent(msg, "nvResetConfig");
690 break;
691
Jake Hamby7c27be32014-03-03 13:25:59 -0800692 case CMD_GET_PREFERRED_NETWORK_TYPE:
693 request = (MainThreadRequest) msg.obj;
694 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700695 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800696 break;
697
698 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
699 ar = (AsyncResult) msg.obj;
700 request = (MainThreadRequest) ar.userObj;
701 if (ar.exception == null && ar.result != null) {
702 request.result = ar.result; // Integer
703 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800704 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800705 if (ar.result == null) {
706 loge("getPreferredNetworkType: Empty response");
707 } else if (ar.exception instanceof CommandException) {
708 loge("getPreferredNetworkType: CommandException: " +
709 ar.exception);
710 } else {
711 loge("getPreferredNetworkType: Unknown exception");
712 }
713 }
714 synchronized (request) {
715 request.notifyAll();
716 }
717 break;
718
719 case CMD_SET_PREFERRED_NETWORK_TYPE:
720 request = (MainThreadRequest) msg.obj;
721 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
722 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700723 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 break;
725
726 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
727 handleNullReturnEvent(msg, "setPreferredNetworkType");
728 break;
729
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800730 case CMD_SET_VOICEMAIL_NUMBER:
731 request = (MainThreadRequest) msg.obj;
732 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
733 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800734 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
735 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800736 break;
737
738 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
739 handleNullReturnEvent(msg, "setVoicemailNumber");
740 break;
741
Stuart Scott54788802015-03-30 13:18:01 -0700742 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
745 request);
746 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
747 break;
748
749 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
750 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
751 break;
752
Shishir Agrawal302c8692015-06-19 13:49:39 -0700753 case CMD_PERFORM_NETWORK_SCAN:
754 request = (MainThreadRequest) msg.obj;
755 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
756 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
757 break;
758
759 case EVENT_PERFORM_NETWORK_SCAN_DONE:
760 ar = (AsyncResult) msg.obj;
761 request = (MainThreadRequest) ar.userObj;
762 CellNetworkScanResult cellScanResult;
763 if (ar.exception == null && ar.result != null) {
764 cellScanResult = new CellNetworkScanResult(
765 CellNetworkScanResult.STATUS_SUCCESS,
766 (List<OperatorInfo>) ar.result);
767 } else {
768 if (ar.result == null) {
769 loge("getCellNetworkScanResults: Empty response");
770 }
771 if (ar.exception != null) {
772 loge("getCellNetworkScanResults: Exception: " + ar.exception);
773 }
774 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
775 if (ar.exception instanceof CommandException) {
776 CommandException.Error error =
777 ((CommandException) (ar.exception)).getCommandError();
778 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
779 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
780 } else if (error == CommandException.Error.GENERIC_FAILURE) {
781 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
782 }
783 }
784 cellScanResult = new CellNetworkScanResult(errorCode, null);
785 }
786 request.result = cellScanResult;
787 synchronized (request) {
788 request.notifyAll();
789 }
790 break;
791
792 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
793 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700794 ManualNetworkSelectionArgument selArg =
795 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700796 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
797 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700798 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
799 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700800 break;
801
802 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
803 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
804 break;
805
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700806 case CMD_GET_MODEM_ACTIVITY_INFO:
807 request = (MainThreadRequest) msg.obj;
808 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700809 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700810 break;
811
812 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
813 ar = (AsyncResult) msg.obj;
814 request = (MainThreadRequest) ar.userObj;
815 if (ar.exception == null && ar.result != null) {
816 request.result = ar.result;
817 } else {
818 if (ar.result == null) {
819 loge("queryModemActivityInfo: Empty response");
820 } else if (ar.exception instanceof CommandException) {
821 loge("queryModemActivityInfo: CommandException: " +
822 ar.exception);
823 } else {
824 loge("queryModemActivityInfo: Unknown exception");
825 }
826 }
Amit Mahajand4766222016-01-28 15:28:28 -0800827 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
828 if (request.result == null) {
829 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
830 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700831 synchronized (request) {
832 request.notifyAll();
833 }
834 break;
835
Meng Wang1a7c35a2016-05-05 20:56:15 -0700836 case CMD_SET_ALLOWED_CARRIERS:
837 request = (MainThreadRequest) msg.obj;
838 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
839 mPhone.setAllowedCarriers(
840 (List<CarrierIdentifier>) request.argument,
841 onCompleted);
842 break;
843
844 case EVENT_SET_ALLOWED_CARRIERS_DONE:
845 ar = (AsyncResult) msg.obj;
846 request = (MainThreadRequest) ar.userObj;
847 if (ar.exception == null && ar.result != null) {
848 request.result = ar.result;
849 } else {
850 if (ar.result == null) {
851 loge("setAllowedCarriers: Empty response");
852 } else if (ar.exception instanceof CommandException) {
853 loge("setAllowedCarriers: CommandException: " +
854 ar.exception);
855 } else {
856 loge("setAllowedCarriers: Unknown exception");
857 }
858 }
859 // Result cannot be null. Return -1 on error.
860 if (request.result == null) {
861 request.result = new int[]{-1};
862 }
863 synchronized (request) {
864 request.notifyAll();
865 }
866 break;
867
868 case CMD_GET_ALLOWED_CARRIERS:
869 request = (MainThreadRequest) msg.obj;
870 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
871 mPhone.getAllowedCarriers(onCompleted);
872 break;
873
874 case EVENT_GET_ALLOWED_CARRIERS_DONE:
875 ar = (AsyncResult) msg.obj;
876 request = (MainThreadRequest) ar.userObj;
877 if (ar.exception == null && ar.result != null) {
878 request.result = ar.result;
879 } else {
880 if (ar.result == null) {
881 loge("getAllowedCarriers: Empty response");
882 } else if (ar.exception instanceof CommandException) {
883 loge("getAllowedCarriers: CommandException: " +
884 ar.exception);
885 } else {
886 loge("getAllowedCarriers: Unknown exception");
887 }
888 }
889 // Result cannot be null. Return empty list of CarrierIdentifier.
890 if (request.result == null) {
891 request.result = new ArrayList<CarrierIdentifier>(0);
892 }
893 synchronized (request) {
894 request.notifyAll();
895 }
896 break;
897
Nathan Haroldb3014052017-01-25 15:57:32 -0800898 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
899 ar = (AsyncResult) msg.obj;
900 request = (MainThreadRequest) ar.userObj;
901 if (ar.exception == null && ar.result != null) {
902 request.result = ar.result;
903 } else {
904 request.result = new IllegalArgumentException(
905 "Failed to retrieve Forbidden Plmns");
906 if (ar.result == null) {
907 loge("getForbiddenPlmns: Empty response");
908 } else {
909 loge("getForbiddenPlmns: Unknown exception");
910 }
911 }
912 synchronized (request) {
913 request.notifyAll();
914 }
915 break;
916
917 case CMD_GET_FORBIDDEN_PLMNS:
918 request = (MainThreadRequest) msg.obj;
919 uiccCard = getUiccCardFromRequest(request);
920 if (uiccCard == null) {
921 loge("getForbiddenPlmns() UiccCard is null");
922 request.result = new IllegalArgumentException(
923 "getForbiddenPlmns() UiccCard is null");
924 synchronized (request) {
925 request.notifyAll();
926 }
927 break;
928 }
929 Integer appType = (Integer) request.argument;
930 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
931 if (uiccApp == null) {
932 loge("getForbiddenPlmns() no app with specified type -- "
933 + appType);
934 request.result = new IllegalArgumentException("Failed to get UICC App");
935 synchronized (request) {
936 request.notifyAll();
937 }
938 break;
939 } else {
940 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
941 + " specified type -- " + appType);
942 }
943 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
944 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
945 onCompleted);
946 break;
947
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000948 case CMD_SWITCH_SLOTS:
949 request = (MainThreadRequest) msg.obj;
950 int[] physicalSlots = (int[]) request.argument;
951 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
952 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
953 break;
954
955 case EVENT_SWITCH_SLOTS_DONE:
956 ar = (AsyncResult) msg.obj;
957 request = (MainThreadRequest) ar.userObj;
958 request.result = (ar.exception == null);
959 synchronized (request) {
960 request.notifyAll();
961 }
962 break;
963
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700964 default:
965 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
966 break;
967 }
968 }
Jake Hambye994d462014-02-03 13:10:13 -0800969
970 private void handleNullReturnEvent(Message msg, String command) {
971 AsyncResult ar = (AsyncResult) msg.obj;
972 MainThreadRequest request = (MainThreadRequest) ar.userObj;
973 if (ar.exception == null) {
974 request.result = true;
975 } else {
976 request.result = false;
977 if (ar.exception instanceof CommandException) {
978 loge(command + ": CommandException: " + ar.exception);
979 } else {
980 loge(command + ": Unknown exception");
981 }
982 }
983 synchronized (request) {
984 request.notifyAll();
985 }
986 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700987 }
988
989 /**
990 * Posts the specified command to be executed on the main thread,
991 * waits for the request to complete, and returns the result.
992 * @see #sendRequestAsync
993 */
994 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800995 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700996 }
997
998 /**
999 * Posts the specified command to be executed on the main thread,
1000 * waits for the request to complete, and returns the result.
1001 * @see #sendRequestAsync
1002 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001003 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001004 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1005 throw new RuntimeException("This method will deadlock if called from the main thread.");
1006 }
1007
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001008 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001009 Message msg = mMainThreadHandler.obtainMessage(command, request);
1010 msg.sendToTarget();
1011
1012 // Wait for the request to complete
1013 synchronized (request) {
1014 while (request.result == null) {
1015 try {
1016 request.wait();
1017 } catch (InterruptedException e) {
1018 // Do nothing, go back and wait until the request is complete
1019 }
1020 }
1021 }
1022 return request.result;
1023 }
1024
1025 /**
1026 * Asynchronous ("fire and forget") version of sendRequest():
1027 * Posts the specified command to be executed on the main thread, and
1028 * returns immediately.
1029 * @see #sendRequest
1030 */
1031 private void sendRequestAsync(int command) {
1032 mMainThreadHandler.sendEmptyMessage(command);
1033 }
1034
1035 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001036 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1037 * @see {@link #sendRequest(int,Object)}
1038 */
1039 private void sendRequestAsync(int command, Object argument) {
1040 MainThreadRequest request = new MainThreadRequest(argument);
1041 Message msg = mMainThreadHandler.obtainMessage(command, request);
1042 msg.sendToTarget();
1043 }
1044
1045 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001046 * Initialize the singleton PhoneInterfaceManager instance.
1047 * This is only done once, at startup, from PhoneApp.onCreate().
1048 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001049 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001050 synchronized (PhoneInterfaceManager.class) {
1051 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001052 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001053 } else {
1054 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1055 }
1056 return sInstance;
1057 }
1058 }
1059
1060 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001061 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001062 mApp = app;
1063 mPhone = phone;
1064 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001065 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001066 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1067 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001068 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001069 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001070 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001071 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001072
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001073 publish();
1074 }
1075
1076 private void publish() {
1077 if (DBG) log("publish: " + this);
1078
1079 ServiceManager.addService("phone", this);
1080 }
1081
Stuart Scott584921c2015-01-15 17:10:34 -08001082 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001083 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1084 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001085 }
1086
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001087 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1088 Phone phone = getPhoneFromRequest(request);
1089 return phone == null ? null :
1090 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1091 }
1092
Wink Saville36469e72014-06-11 15:17:00 -07001093 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001094 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001095 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001097 //
1098 // Implementation of the ITelephony interface.
1099 //
1100
1101 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001102 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001103 }
1104
Wink Savilleb564aae2014-10-23 10:18:09 -07001105 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001106 if (DBG) log("dial: " + number);
1107 // No permission check needed here: This is just a wrapper around the
1108 // ACTION_DIAL intent, which is available to any app since it puts up
1109 // the UI before it does anything.
1110
1111 String url = createTelUrl(number);
1112 if (url == null) {
1113 return;
1114 }
1115
1116 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001117 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001118 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1119 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1120 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1121 mApp.startActivity(intent);
1122 }
1123 }
1124
1125 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001126 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001127 }
1128
Wink Savilleb564aae2014-10-23 10:18:09 -07001129 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001130 if (DBG) log("call: " + number);
1131
1132 // This is just a wrapper around the ACTION_CALL intent, but we still
1133 // need to do a permission check since we're calling startActivity()
1134 // from the context of the phone app.
1135 enforceCallPermission();
1136
1137 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1138 != AppOpsManager.MODE_ALLOWED) {
1139 return;
1140 }
1141
1142 String url = createTelUrl(number);
1143 if (url == null) {
1144 return;
1145 }
1146
Wink Saville08874612014-08-31 19:19:58 -07001147 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001148 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001149 if (slist != null) {
1150 for (SubscriptionInfo subInfoRecord : slist) {
1151 if (subInfoRecord.getSubscriptionId() == subId) {
1152 isValid = true;
1153 break;
1154 }
Wink Saville08874612014-08-31 19:19:58 -07001155 }
1156 }
1157 if (isValid == false) {
1158 return;
1159 }
1160
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001161 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001162 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001163 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1164 mApp.startActivity(intent);
1165 }
1166
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001167 /**
1168 * End a call based on call state
1169 * @return true is a call was ended
1170 */
1171 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001172 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001173 }
1174
1175 /**
1176 * End a call based on the call state of the subId
1177 * @return true is a call was ended
1178 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001179 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001180 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001181 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001182 }
1183
1184 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001185 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001186 }
1187
Wink Savilleb564aae2014-10-23 10:18:09 -07001188 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001189 if (DBG) log("answerRingingCall...");
1190 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1191 // but that can probably wait till the big TelephonyManager API overhaul.
1192 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1193 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001194 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 }
1196
1197 /**
1198 * Make the actual telephony calls to implement answerRingingCall().
1199 * This should only be called from the main thread of the Phone app.
1200 * @see #answerRingingCall
1201 *
1202 * TODO: it would be nice to return true if we answered the call, or
1203 * false if there wasn't actually a ringing incoming call, or some
1204 * other error occurred. (In other words, pass back the return value
1205 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1206 * But that would require calling this method via sendRequest() rather
1207 * than sendRequestAsync(), and right now we don't actually *need* that
1208 * return value, so let's just return void for now.
1209 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001210 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001211 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001212 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001213 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1214 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001215 if (hasActiveCall && hasHoldingCall) {
1216 // Both lines are in use!
1217 // TODO: provide a flag to let the caller specify what
1218 // policy to use if both lines are in use. (The current
1219 // behavior is hardwired to "answer incoming, end ongoing",
1220 // which is how the CALL button is specced to behave.)
1221 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1222 return;
1223 } else {
1224 // answerCall() will automatically hold the current active
1225 // call, if there is one.
1226 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1227 return;
1228 }
1229 } else {
1230 // No call was ringing.
1231 return;
1232 }
1233 }
1234
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001235 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001236 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001237 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001238 public void silenceRinger() {
1239 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001240 }
1241
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001242 @Override
1243 public boolean isOffhook(String callingPackage) {
1244 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001245 }
1246
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001247 @Override
1248 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1249 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1250 return false;
1251 }
1252
Sanket Padawe356d7632015-06-22 14:03:32 -07001253 final Phone phone = getPhone(subId);
1254 if (phone != null) {
1255 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1256 } else {
1257 return false;
1258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259 }
1260
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001261 @Override
1262 public boolean isRinging(String callingPackage) {
1263 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001264 }
1265
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001266 @Override
1267 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1268 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1269 return false;
1270 }
1271
Sanket Padawe356d7632015-06-22 14:03:32 -07001272 final Phone phone = getPhone(subId);
1273 if (phone != null) {
1274 return (phone.getState() == PhoneConstants.State.RINGING);
1275 } else {
1276 return false;
1277 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 }
1279
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001280 @Override
1281 public boolean isIdle(String callingPackage) {
1282 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001283 }
1284
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001285 @Override
1286 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1287 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1288 return false;
1289 }
1290
Sanket Padawe356d7632015-06-22 14:03:32 -07001291 final Phone phone = getPhone(subId);
1292 if (phone != null) {
1293 return (phone.getState() == PhoneConstants.State.IDLE);
1294 } else {
1295 return false;
1296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001297 }
1298
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001299 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001300 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001301 }
1302
Wink Savilleb564aae2014-10-23 10:18:09 -07001303 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001304 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001305 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1306 }
1307
1308 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001309 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001310 }
1311
Wink Savilleb564aae2014-10-23 10:18:09 -07001312 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001313 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001314 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1315 }
1316
1317 /** {@hide} */
1318 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001319 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001320 }
1321
Wink Savilleb564aae2014-10-23 10:18:09 -07001322 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001323 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001324 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001325 checkSimPin.start();
1326 return checkSimPin.unlockSim(null, pin);
1327 }
1328
Wink Saville9de0f752013-10-22 19:04:03 -07001329 /** {@hide} */
1330 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001331 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001332 }
1333
Wink Savilleb564aae2014-10-23 10:18:09 -07001334 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001336 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001337 checkSimPuk.start();
1338 return checkSimPuk.unlockSim(puk, pin);
1339 }
1340
1341 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001342 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 * a synchronous one.
1344 */
1345 private static class UnlockSim extends Thread {
1346
1347 private final IccCard mSimCard;
1348
1349 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001350 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1351 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001352
1353 // For replies from SimCard interface
1354 private Handler mHandler;
1355
1356 // For async handler to identify request type
1357 private static final int SUPPLY_PIN_COMPLETE = 100;
1358
1359 public UnlockSim(IccCard simCard) {
1360 mSimCard = simCard;
1361 }
1362
1363 @Override
1364 public void run() {
1365 Looper.prepare();
1366 synchronized (UnlockSim.this) {
1367 mHandler = new Handler() {
1368 @Override
1369 public void handleMessage(Message msg) {
1370 AsyncResult ar = (AsyncResult) msg.obj;
1371 switch (msg.what) {
1372 case SUPPLY_PIN_COMPLETE:
1373 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1374 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001375 mRetryCount = msg.arg1;
1376 if (ar.exception != null) {
1377 if (ar.exception instanceof CommandException &&
1378 ((CommandException)(ar.exception)).getCommandError()
1379 == CommandException.Error.PASSWORD_INCORRECT) {
1380 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1381 } else {
1382 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1383 }
1384 } else {
1385 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001387 mDone = true;
1388 UnlockSim.this.notifyAll();
1389 }
1390 break;
1391 }
1392 }
1393 };
1394 UnlockSim.this.notifyAll();
1395 }
1396 Looper.loop();
1397 }
1398
1399 /*
1400 * Use PIN or PUK to unlock SIM card
1401 *
1402 * If PUK is null, unlock SIM card with PIN
1403 *
1404 * If PUK is not null, unlock SIM card with PUK and set PIN code
1405 */
Wink Saville9de0f752013-10-22 19:04:03 -07001406 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407
1408 while (mHandler == null) {
1409 try {
1410 wait();
1411 } catch (InterruptedException e) {
1412 Thread.currentThread().interrupt();
1413 }
1414 }
1415 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1416
1417 if (puk == null) {
1418 mSimCard.supplyPin(pin, callback);
1419 } else {
1420 mSimCard.supplyPuk(puk, pin, callback);
1421 }
1422
1423 while (!mDone) {
1424 try {
1425 Log.d(LOG_TAG, "wait for done");
1426 wait();
1427 } catch (InterruptedException e) {
1428 // Restore the interrupted status
1429 Thread.currentThread().interrupt();
1430 }
1431 }
1432 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001433 int[] resultArray = new int[2];
1434 resultArray[0] = mResult;
1435 resultArray[1] = mRetryCount;
1436 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001437 }
1438 }
1439
1440 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001441 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001442
1443 }
1444
Wink Savilleb564aae2014-10-23 10:18:09 -07001445 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001446 // No permission check needed here: this call is harmless, and it's
1447 // needed for the ServiceState.requestStateUpdate() call (which is
1448 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001449 final Phone phone = getPhone(subId);
1450 if (phone != null) {
1451 phone.updateServiceLocation();
1452 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001453 }
1454
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001455 @Override
1456 public boolean isRadioOn(String callingPackage) {
1457 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001458 }
1459
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001460 @Override
1461 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1462 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1463 return false;
1464 }
1465 return isRadioOnForSubscriber(subId);
1466 }
1467
1468 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001469 final Phone phone = getPhone(subId);
1470 if (phone != null) {
1471 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1472 } else {
1473 return false;
1474 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475 }
1476
1477 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001478 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001479
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001480 }
Wink Saville36469e72014-06-11 15:17:00 -07001481
Wink Savilleb564aae2014-10-23 10:18:09 -07001482 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001484 final Phone phone = getPhone(subId);
1485 if (phone != null) {
1486 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1487 }
Wink Saville36469e72014-06-11 15:17:00 -07001488 }
1489
1490 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001491 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001492 }
1493
Wink Savilleb564aae2014-10-23 10:18:09 -07001494 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001495 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001496 final Phone phone = getPhone(subId);
1497 if (phone == null) {
1498 return false;
1499 }
1500 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001501 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001502 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001503 }
1504 return true;
1505 }
Wink Saville36469e72014-06-11 15:17:00 -07001506
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001507 public boolean needMobileRadioShutdown() {
1508 /*
1509 * If any of the Radios are available, it will need to be
1510 * shutdown. So return true if any Radio is available.
1511 */
1512 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1513 Phone phone = PhoneFactory.getPhone(i);
1514 if (phone != null && phone.isRadioAvailable()) return true;
1515 }
1516 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1517 return false;
1518 }
1519
1520 public void shutdownMobileRadios() {
1521 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1522 logv("Shutting down Phone " + i);
1523 shutdownRadioUsingPhoneId(i);
1524 }
1525 }
1526
1527 private void shutdownRadioUsingPhoneId(int phoneId) {
1528 enforceModifyPermission();
1529 Phone phone = PhoneFactory.getPhone(phoneId);
1530 if (phone != null && phone.isRadioAvailable()) {
1531 phone.shutdownRadio();
1532 }
1533 }
1534
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001535 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001536 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001537 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1538 if (defaultPhone != null) {
1539 defaultPhone.setRadioPower(turnOn);
1540 return true;
1541 } else {
1542 loge("There's no default phone.");
1543 return false;
1544 }
Wink Saville36469e72014-06-11 15:17:00 -07001545 }
1546
Wink Savilleb564aae2014-10-23 10:18:09 -07001547 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001549 final Phone phone = getPhone(subId);
1550 if (phone != null) {
1551 phone.setRadioPower(turnOn);
1552 return true;
1553 } else {
1554 return false;
1555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 }
1557
Wink Saville36469e72014-06-11 15:17:00 -07001558 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001559 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001560 public boolean enableDataConnectivity() {
1561 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001562 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001563 final Phone phone = getPhone(subId);
1564 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001565 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001566 return true;
1567 } else {
1568 return false;
1569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 }
1571
Wink Saville36469e72014-06-11 15:17:00 -07001572 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001573 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 public boolean disableDataConnectivity() {
1575 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001576 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001577 final Phone phone = getPhone(subId);
1578 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001579 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 return true;
1581 } else {
1582 return false;
1583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001584 }
1585
Sanket Padawe356d7632015-06-22 14:03:32 -07001586 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001587 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001588 final Phone phone = getPhone(subId);
1589 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001590 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001591 } else {
1592 return false;
1593 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594 }
1595
1596 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001597 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001598 }
1599
pkanwarae03a6b2016-11-06 20:37:09 -08001600 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001601 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001602 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1603 return;
1604 }
1605 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1606 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1607 };
1608
Wink Savilleb564aae2014-10-23 10:18:09 -07001609 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001611 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1612 return false;
1613 }
Wink Saville36469e72014-06-11 15:17:00 -07001614 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 }
1616
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001617 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001618 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001619 }
1620
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001621 public int getCallStateForSlot(int slotIndex) {
1622 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001623 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001624 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 }
1626
Sanket Padawe356d7632015-06-22 14:03:32 -07001627 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001628 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001629 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001630 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001631 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001632 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001633 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 }
1636
Sanket Padawe356d7632015-06-22 14:03:32 -07001637 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001639 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001640 if (phone != null) {
1641 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1642 } else {
1643 return TelephonyManager.DATA_ACTIVITY_NONE;
1644 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 }
1646
1647 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001648 public Bundle getCellLocation(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001649 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001650 callingPackage, Binder.getCallingUid(), "getCellLocation")) {
Svetoslav64fad262015-04-14 14:35:21 -07001651 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 }
1653
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001654 if (DBG_LOC) log("getCellLocation: is active user");
1655 Bundle data = new Bundle();
1656 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1657 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 return null;
1659 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001661 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001662 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1663 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001664 }
1665
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001667 public String getNetworkCountryIsoForPhone(int phoneId) {
1668 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1669 // registered cell info, so return a NULL country instead.
1670 final long identity = Binder.clearCallingIdentity();
1671 try {
1672 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1673 if (TelephonyManager.NETWORK_TYPE_IWLAN
1674 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1675 return "";
1676 }
1677 } finally {
1678 Binder.restoreCallingIdentity(identity);
1679 }
1680 return TelephonyManager.getTelephonyProperty(
1681 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1682 }
1683
1684 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001686 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001687 }
1688
Sanket Padawe356d7632015-06-22 14:03:32 -07001689 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001690 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 mApp.enforceCallingOrSelfPermission(
1692 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 final Phone phone = getPhone(subId);
1694 if (phone != null) {
1695 phone.enableLocationUpdates();
1696 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 }
1698
1699 @Override
1700 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001701 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001702 }
1703
Sanket Padawe356d7632015-06-22 14:03:32 -07001704 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001705 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 mApp.enforceCallingOrSelfPermission(
1707 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001708 final Phone phone = getPhone(subId);
1709 if (phone != null) {
1710 phone.disableLocationUpdates();
1711 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712 }
1713
1714 @Override
1715 @SuppressWarnings("unchecked")
1716 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001717 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001718 callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001719 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 }
1721
1722 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1723 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1724 return null;
1725 }
Svetoslav64fad262015-04-14 14:35:21 -07001726
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001727 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001729 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001731 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001732 try {
1733 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1734 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1735 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1736 } catch (RuntimeException e) {
1737 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001739 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 }
1741
1742
1743 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001744 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001745 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001746 callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001747 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 }
1749
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001750 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001751 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001752 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1753 for (Phone phone : PhoneFactory.getPhones()) {
1754 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1755 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001757 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 }
1759
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001760 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001762 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001763 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001764 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 }
1766
Shishir Agrawala9f32182016-04-12 12:00:16 -07001767 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001768 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001769 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1770 return null;
1771 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001772 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001773 return phone == null ? null : phone.getImei();
1774 }
1775
1776 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001777 public String getMeidForSlot(int slotIndex, String callingPackage) {
1778 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1779 return null;
1780 }
1781 Phone phone = PhoneFactory.getPhone(slotIndex);
1782 return phone == null ? null : phone.getMeid();
1783 }
1784
1785 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001786 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001787 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1788 return null;
1789 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001790 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001791 return phone == null ? null : phone.getDeviceSvn();
1792 }
1793
fionaxu43304da2017-11-27 22:51:16 -08001794 @Override
1795 public int getSubscriptionCarrierId(int subId) {
1796 final Phone phone = getPhone(subId);
1797 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1798 }
1799
1800 @Override
1801 public String getSubscriptionCarrierName(int subId) {
1802 final Phone phone = getPhone(subId);
1803 return phone == null ? null : phone.getCarrierName();
1804 }
1805
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 //
1807 // Internal helper methods.
1808 //
1809
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001810 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1812 *
1813 * @throws SecurityException if the caller does not have the required permission
1814 */
1815 private void enforceModifyPermission() {
1816 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1817 }
1818
1819 /**
Junda Liua2e36012014-07-09 18:30:01 -07001820 * Make sure either system app or the caller has carrier privilege.
1821 *
1822 * @throws SecurityException if the caller does not have the required permission/privilege
1823 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001824 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001825 int permission = mApp.checkCallingOrSelfPermission(
1826 android.Manifest.permission.MODIFY_PHONE_STATE);
1827 if (permission == PackageManager.PERMISSION_GRANTED) {
1828 return;
1829 }
1830
1831 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001832 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001833 }
1834
1835 /**
1836 * Make sure the caller has carrier privilege.
1837 *
1838 * @throws SecurityException if the caller does not have the required permission
1839 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001840 private void enforceCarrierPrivilege(int subId) {
1841 if (getCarrierPrivilegeStatus(subId) !=
1842 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001843 loge("No Carrier Privilege.");
1844 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001845 }
1846 }
1847
1848 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 * Make sure the caller has the CALL_PHONE permission.
1850 *
1851 * @throws SecurityException if the caller does not have the required permission
1852 */
1853 private void enforceCallPermission() {
1854 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1855 }
1856
Stuart Scott8eef64f2015-04-08 15:13:54 -07001857 private void enforceConnectivityInternalPermission() {
1858 mApp.enforceCallingOrSelfPermission(
1859 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1860 "ConnectivityService");
1861 }
1862
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 private String createTelUrl(String number) {
1864 if (TextUtils.isEmpty(number)) {
1865 return null;
1866 }
1867
Jake Hambye994d462014-02-03 13:10:13 -08001868 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 }
1870
Ihab Awadf9e92732013-12-05 18:02:52 -08001871 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1873 }
1874
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001875 private static void logv(String msg) {
1876 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1877 }
1878
Ihab Awadf9e92732013-12-05 18:02:52 -08001879 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1881 }
1882
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001883 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001885 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001886 }
1887
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001889 public int getActivePhoneTypeForSlot(int slotIndex) {
1890 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 if (phone == null) {
1892 return PhoneConstants.PHONE_TYPE_NONE;
1893 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001894 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 }
1897
1898 /**
1899 * Returns the CDMA ERI icon index to display
1900 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001901 @Override
1902 public int getCdmaEriIconIndex(String callingPackage) {
1903 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001904 }
1905
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001907 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1908 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1909 return -1;
1910 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001911 final Phone phone = getPhone(subId);
1912 if (phone != null) {
1913 return phone.getCdmaEriIconIndex();
1914 } else {
1915 return -1;
1916 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917 }
1918
1919 /**
1920 * Returns the CDMA ERI icon mode,
1921 * 0 - ON
1922 * 1 - FLASHING
1923 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001924 @Override
1925 public int getCdmaEriIconMode(String callingPackage) {
1926 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001927 }
1928
Sanket Padawe356d7632015-06-22 14:03:32 -07001929 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001930 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1931 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1932 return -1;
1933 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001934 final Phone phone = getPhone(subId);
1935 if (phone != null) {
1936 return phone.getCdmaEriIconMode();
1937 } else {
1938 return -1;
1939 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001940 }
1941
1942 /**
1943 * Returns the CDMA ERI text,
1944 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001945 @Override
1946 public String getCdmaEriText(String callingPackage) {
1947 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001948 }
1949
Sanket Padawe356d7632015-06-22 14:03:32 -07001950 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001951 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1952 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1953 return null;
1954 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001955 final Phone phone = getPhone(subId);
1956 if (phone != null) {
1957 return phone.getCdmaEriText();
1958 } else {
1959 return null;
1960 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001961 }
1962
1963 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001964 * Returns the CDMA MDN.
1965 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001966 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001967 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001968 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001969 final Phone phone = getPhone(subId);
1970 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1971 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001972 } else {
1973 return null;
1974 }
1975 }
1976
1977 /**
1978 * Returns the CDMA MIN.
1979 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001980 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001981 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001982 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001983 final Phone phone = getPhone(subId);
1984 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1985 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001986 } else {
1987 return null;
1988 }
1989 }
1990
1991 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001992 * Returns true if CDMA provisioning needs to run.
1993 */
1994 public boolean needsOtaServiceProvisioning() {
1995 return mPhone.needsOtaServiceProvisioning();
1996 }
1997
1998 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001999 * Sets the voice mail number of a given subId.
2000 */
2001 @Override
2002 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002003 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002004 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2005 new Pair<String, String>(alphaTag, number), new Integer(subId));
2006 return success;
2007 }
2008
Ta-wei Yen87c49842016-05-13 21:19:52 -07002009 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002010 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2011 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2012 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2013 if (!TextUtils.equals(callingPackage, systemDialer)) {
2014 throw new SecurityException("caller must be system dialer");
2015 }
2016 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2017 if (phoneAccountHandle == null){
2018 return null;
2019 }
2020 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2021 }
2022
2023 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002024 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002025 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2026 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2027 return null;
2028 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002029 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2030 }
2031
2032 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002033 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2034 VisualVoicemailSmsFilterSettings settings) {
2035 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002036 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002037 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2038 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002039 }
2040
2041 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002042 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2043 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002044 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002045 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002046 }
2047
2048 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002049 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2050 String callingPackage, int subId) {
2051 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002052 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002053 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002054 }
2055
2056 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002057 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002058 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002059 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002060 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2061 }
2062
2063 @Override
2064 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2065 String number, int port, String text, PendingIntent sentIntent) {
2066 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002067 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002068 enforceSendSmsPermission();
2069 // Make the calls as the phone process.
2070 final long identity = Binder.clearCallingIdentity();
2071 try {
2072 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2073 if (port == 0) {
2074 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2075 sentIntent, null, false);
2076 } else {
2077 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2078 smsManager.sendDataMessageWithSelfPermissions(number, null,
2079 (short) port, data, sentIntent, null);
2080 }
2081 } finally {
2082 Binder.restoreCallingIdentity(identity);
2083 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002084 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002085 /**
fionaxu0152e512016-11-14 13:36:14 -08002086 * Sets the voice activation state of a given subId.
2087 */
2088 @Override
2089 public void setVoiceActivationState(int subId, int activationState) {
2090 enforceModifyPermissionOrCarrierPrivilege(subId);
2091 final Phone phone = getPhone(subId);
2092 if (phone != null) {
2093 phone.setVoiceActivationState(activationState);
2094 } else {
2095 loge("setVoiceActivationState fails with invalid subId: " + subId);
2096 }
2097 }
2098
2099 /**
2100 * Sets the data activation state of a given subId.
2101 */
2102 @Override
2103 public void setDataActivationState(int subId, int activationState) {
2104 enforceModifyPermissionOrCarrierPrivilege(subId);
2105 final Phone phone = getPhone(subId);
2106 if (phone != null) {
2107 phone.setDataActivationState(activationState);
2108 } else {
2109 loge("setVoiceActivationState fails with invalid subId: " + subId);
2110 }
2111 }
2112
2113 /**
2114 * Returns the voice activation state of a given subId.
2115 */
2116 @Override
2117 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002118 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002119 final Phone phone = getPhone(subId);
2120 if (phone != null) {
2121 return phone.getVoiceActivationState();
2122 } else {
2123 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2124 }
2125 }
2126
2127 /**
2128 * Returns the data activation state of a given subId.
2129 */
2130 @Override
2131 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002132 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002133 final Phone phone = getPhone(subId);
2134 if (phone != null) {
2135 return phone.getDataActivationState();
2136 } else {
2137 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2138 }
2139 }
2140
2141 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002142 * Returns the unread count of voicemails
2143 */
2144 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002145 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002146 }
2147
2148 /**
2149 * Returns the unread count of voicemails for a subId
2150 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002151 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002152 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002153 final Phone phone = getPhone(subId);
2154 if (phone != null) {
2155 return phone.getVoiceMessageCount();
2156 } else {
2157 return 0;
2158 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002159 }
2160
2161 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002162 * returns true, if the device is in a state where both voice and data
2163 * are supported simultaneously. This can change based on location or network condition.
2164 */
2165 @Override
2166 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2167 final Phone phone = getPhone(subId);
2168 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2169 }
2170
2171 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002172 * Send the dialer code if called from the current default dialer or the caller has
2173 * carrier privilege.
2174 * @param inputCode The dialer code to send
2175 */
2176 @Override
2177 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2178 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2179 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2180 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2181 enforceCarrierPrivilege(getDefaultSubscription());
2182 }
2183 mPhone.sendDialerSpecialCode(inputCode);
2184 }
2185
2186 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002187 * Returns the data network type.
2188 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 *
2190 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2191 */
2192 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002193 public int getNetworkType() {
2194 final Phone phone = getPhone(getDefaultSubscription());
2195 if (phone != null) {
2196 return phone.getServiceState().getDataNetworkType();
2197 } else {
2198 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2199 }
Wink Saville36469e72014-06-11 15:17:00 -07002200 }
2201
2202 /**
2203 * Returns the network type for a subId
2204 */
2205 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002206 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2207 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2208 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2209 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002210
Sanket Padawe356d7632015-06-22 14:03:32 -07002211 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002212 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002213 return phone.getServiceState().getDataNetworkType();
2214 } else {
2215 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218
2219 /**
2220 * Returns the data network type
2221 */
2222 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002223 public int getDataNetworkType(String callingPackage) {
2224 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002225 }
2226
2227 /**
2228 * Returns the data network type for a subId
2229 */
2230 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002231 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2232 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2233 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2234 }
2235
Sanket Padawe356d7632015-06-22 14:03:32 -07002236 final Phone phone = getPhone(subId);
2237 if (phone != null) {
2238 return phone.getServiceState().getDataNetworkType();
2239 } else {
2240 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 }
2243
2244 /**
Wink Saville36469e72014-06-11 15:17:00 -07002245 * Returns the Voice network type for a subId
2246 */
2247 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002248 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2249 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2250 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2251 }
2252
Sanket Padawe356d7632015-06-22 14:03:32 -07002253 final Phone phone = getPhone(subId);
2254 if (phone != null) {
2255 return phone.getServiceState().getVoiceNetworkType();
2256 } else {
2257 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260
2261 /**
2262 * @return true if a ICC card is present
2263 */
2264 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002265 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002266 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2267 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002268 }
2269
2270 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002271 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002272 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002273 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002274 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2275 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002276 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002277 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002278 } else {
2279 return false;
2280 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 }
2282
2283 /**
2284 * Return if the current radio is LTE on CDMA. This
2285 * is a tri-state return value as for a period of time
2286 * the mode may be unknown.
2287 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002288 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002290 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002292 @Override
2293 public int getLteOnCdmaMode(String callingPackage) {
2294 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002295 }
2296
Sanket Padawe356d7632015-06-22 14:03:32 -07002297 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002298 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2299 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2300 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2301 }
2302
Sanket Padawe356d7632015-06-22 14:03:32 -07002303 final Phone phone = getPhone(subId);
2304 if (phone == null) {
2305 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2306 } else {
2307 return phone.getLteOnCdmaMode();
2308 }
Wink Saville36469e72014-06-11 15:17:00 -07002309 }
2310
2311 public void setPhone(Phone phone) {
2312 mPhone = phone;
2313 }
2314
2315 /**
2316 * {@hide}
2317 * Returns Default subId, 0 in the case of single standby.
2318 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002319 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002320 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002321 }
2322
Shishir Agrawala9f32182016-04-12 12:00:16 -07002323 private int getSlotForDefaultSubscription() {
2324 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2325 }
2326
Wink Savilleb564aae2014-10-23 10:18:09 -07002327 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002328 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002330
2331 /**
2332 * @see android.telephony.TelephonyManager.WifiCallingChoices
2333 */
2334 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002335 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2336 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002337 }
2338
2339 /**
2340 * @see android.telephony.TelephonyManager.WifiCallingChoices
2341 */
2342 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002343 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2344 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2345 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002346 }
2347
Sailesh Nepald1e68152013-12-12 19:08:02 -08002348 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002349 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002350 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002351 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002352
Shishir Agrawal566b7612013-10-28 14:41:00 -07002353 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002354 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2355 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002356 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002357
Derek Tan740e1672017-06-27 14:56:27 -07002358 if (TextUtils.equals(ISDR_AID, aid)) {
2359 // Only allows LPA to open logical channel to ISD-R.
2360 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2361 ComponentInfo bestComponent =
2362 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2363 if (bestComponent == null
2364 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2365 loge("The calling package is not allowed to access ISD-R.");
2366 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2367 }
2368 }
2369
2370 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002371 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002372 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002373 if (DBG) log("iccOpenLogicalChannel: " + response);
2374 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002375 }
2376
2377 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002378 public boolean iccCloseLogicalChannel(int subId, int channel) {
2379 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002380
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002381 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002382 if (channel < 0) {
2383 return false;
2384 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002385 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002386 if (DBG) log("iccCloseLogicalChannel: " + success);
2387 return success;
2388 }
2389
2390 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002391 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002392 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002393 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002394
2395 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002396 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2397 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002398 " data=" + data);
2399 }
2400
2401 if (channel < 0) {
2402 return "";
2403 }
2404
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002405 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002406 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002407 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2408
Shishir Agrawal566b7612013-10-28 14:41:00 -07002409 // Append the returned status code to the end of the response payload.
2410 String s = Integer.toHexString(
2411 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002412 if (response.payload != null) {
2413 s = IccUtils.bytesToHexString(response.payload) + s;
2414 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002415 return s;
2416 }
Jake Hambye994d462014-02-03 13:10:13 -08002417
Evan Charltonc66da362014-05-16 14:06:40 -07002418 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002419 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002420 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002421 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002422
2423 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002424 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2425 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002426 }
2427
2428 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002429 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002430 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2431
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002432 // Append the returned status code to the end of the response payload.
2433 String s = Integer.toHexString(
2434 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002435 if (response.payload != null) {
2436 s = IccUtils.bytesToHexString(response.payload) + s;
2437 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002438 return s;
2439 }
2440
2441 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002442 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002443 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002444 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002445
2446 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002447 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002448 p1 + " " + p2 + " " + p3 + ":" + filePath);
2449 }
2450
2451 IccIoResult response =
2452 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002453 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2454 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002455
2456 if (DBG) {
2457 log("Exchange SIM_IO [R]" + response);
2458 }
2459
2460 byte[] result = null;
2461 int length = 2;
2462 if (response.payload != null) {
2463 length = 2 + response.payload.length;
2464 result = new byte[length];
2465 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2466 } else {
2467 result = new byte[length];
2468 }
2469
2470 result[length - 1] = (byte) response.sw2;
2471 result[length - 2] = (byte) response.sw1;
2472 return result;
2473 }
2474
Nathan Haroldb3014052017-01-25 15:57:32 -08002475 /**
2476 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2477 * on a particular subscription
2478 */
2479 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002480 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2481 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002482 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2483 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2484 return null;
2485 }
2486 Object response = sendRequest(
2487 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2488 if (response instanceof String[]) {
2489 return (String[]) response;
2490 }
2491 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2492 return null;
2493 }
2494
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002495 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002496 public String sendEnvelopeWithStatus(int subId, String content) {
2497 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002498
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002499 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002500 if (response.payload == null) {
2501 return "";
2502 }
2503
2504 // Append the returned status code to the end of the response payload.
2505 String s = Integer.toHexString(
2506 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2507 s = IccUtils.bytesToHexString(response.payload) + s;
2508 return s;
2509 }
2510
Jake Hambye994d462014-02-03 13:10:13 -08002511 /**
2512 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2513 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2514 *
2515 * @param itemID the ID of the item to read
2516 * @return the NV item as a String, or null on error.
2517 */
2518 @Override
2519 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002520 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002521 if (DBG) log("nvReadItem: item " + itemID);
2522 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2523 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2524 return value;
2525 }
2526
2527 /**
2528 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2529 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2530 *
2531 * @param itemID the ID of the item to read
2532 * @param itemValue the value to write, as a String
2533 * @return true on success; false on any failure
2534 */
2535 @Override
2536 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002537 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002538 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2539 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2540 new Pair<Integer, String>(itemID, itemValue));
2541 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2542 return success;
2543 }
2544
2545 /**
2546 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2547 * Used for device configuration by some CDMA operators.
2548 *
2549 * @param preferredRoamingList byte array containing the new PRL
2550 * @return true on success; false on any failure
2551 */
2552 @Override
2553 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002554 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002555 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2556 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2557 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2558 return success;
2559 }
2560
2561 /**
2562 * Perform the specified type of NV config reset.
2563 * Used for device configuration by some CDMA operators.
2564 *
2565 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2566 * @return true on success; false on any failure
2567 */
2568 @Override
2569 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002570 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002571 if (DBG) log("nvResetConfig: type " + resetType);
2572 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2573 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2574 return success;
2575 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002576
2577 /**
Wink Saville36469e72014-06-11 15:17:00 -07002578 * {@hide}
2579 * Returns Default sim, 0 in the case of single standby.
2580 */
2581 public int getDefaultSim() {
2582 //TODO Need to get it from Telephony Devcontroller
2583 return 0;
2584 }
2585
Svet Ganovb320e182015-04-16 12:30:10 -07002586 public String[] getPcscfAddress(String apnType, String callingPackage) {
2587 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2588 return new String[0];
2589 }
2590
2591
ram87fca6f2014-07-18 18:58:44 +05302592 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002593 }
2594
Brad Ebinger51f743a2017-01-23 13:50:20 -08002595 /**
Brad Ebinger34bef922017-11-09 10:27:08 -08002596 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2597 * feature or {@link null} if the service is not available. If the feature is available, the
2598 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002599 */
Brad Ebinger34bef922017-11-09 10:27:08 -08002600 public IImsMMTelFeature getMMTelFeatureAndListen(int slotId,
2601 IImsServiceFeatureCallback callback) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002602 enforceModifyPermission();
Brad Ebinger34bef922017-11-09 10:27:08 -08002603 return PhoneFactory.getImsResolver().getMMTelFeatureAndListen(slotId, callback);
2604 }
2605
2606 /**
2607 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2608 * feature during emergency calling or {@link null} if the service is not available. If the
2609 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2610 * listener for feature updates.
2611 */
2612 public IImsMMTelFeature getEmergencyMMTelFeatureAndListen(int slotId,
2613 IImsServiceFeatureCallback callback) {
2614 enforceModifyPermission();
2615 return PhoneFactory.getImsResolver().getEmergencyMMTelFeatureAndListen(slotId, callback);
2616 }
2617
2618 /**
2619 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2620 * feature during emergency calling or {@link null} if the service is not available. If the
2621 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2622 * listener for feature updates.
2623 */
2624 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2625 enforceModifyPermission();
2626 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002627 }
2628
Brad Ebinger5f64b052017-12-14 14:26:15 -08002629 /**
2630 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2631 * specified.
2632 */
2633 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2634 enforceModifyPermission();
2635 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2636 }
2637
Wink Saville36469e72014-06-11 15:17:00 -07002638 public void setImsRegistrationState(boolean registered) {
2639 enforceModifyPermission();
2640 mPhone.setImsRegistrationState(registered);
2641 }
2642
2643 /**
Stuart Scott54788802015-03-30 13:18:01 -07002644 * Set the network selection mode to automatic.
2645 *
2646 */
2647 @Override
2648 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002649 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002650 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2651 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2652 }
2653
2654 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002655 * Set the network selection mode to manual with the selected carrier.
2656 */
2657 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002658 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002659 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002660 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002661 OperatorInfo operator = new OperatorInfo(
2662 /* operatorAlphaLong */ "",
2663 /* operatorAlphaShort */ "",
2664 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002665 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002666 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2667 persistSelection);
2668 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002669 }
2670
2671 /**
2672 * Scans for available networks.
2673 */
2674 @Override
2675 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002676 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002677 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2678 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2679 CMD_PERFORM_NETWORK_SCAN, null, subId);
2680 return result;
2681 }
2682
2683 /**
yinxub1bed742017-04-17 11:45:04 -07002684 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002685 *
yinxub1bed742017-04-17 11:45:04 -07002686 * @param subId id of the subscription
2687 * @param request contains the radio access networks with bands/channels to scan
2688 * @param messenger callback messenger for scan results or errors
2689 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002690 * @return the id of the requested scan which can be used to stop the scan.
2691 */
2692 @Override
2693 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2694 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002695 enforceModifyPermissionOrCarrierPrivilege(subId);
2696 return mNetworkScanRequestTracker.startNetworkScan(
2697 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002698 }
2699
2700 /**
2701 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002702 *
2703 * @param subId id of the subscription
2704 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002705 */
2706 @Override
2707 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002708 enforceModifyPermissionOrCarrierPrivilege(subId);
2709 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002710 }
2711
2712 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002713 * Get the calculated preferred network type.
2714 * Used for debugging incorrect network type.
2715 *
2716 * @return the preferred network type, defined in RILConstants.java.
2717 */
2718 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002719 public int getCalculatedPreferredNetworkType(String callingPackage) {
2720 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2721 return RILConstants.PREFERRED_NETWORK_MODE;
2722 }
2723
Amit Mahajan43330e02014-11-18 11:54:45 -08002724 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002725 }
2726
2727 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002728 * Get the preferred network type.
2729 * Used for device configuration by some CDMA operators.
2730 *
2731 * @return the preferred network type, defined in RILConstants.java.
2732 */
2733 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002734 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002735 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002736 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002737 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002738 int networkType = (result != null ? result[0] : -1);
2739 if (DBG) log("getPreferredNetworkType: " + networkType);
2740 return networkType;
2741 }
2742
2743 /**
2744 * Set the preferred network type.
2745 * Used for device configuration by some CDMA operators.
2746 *
2747 * @param networkType the preferred network type, defined in RILConstants.java.
2748 * @return true on success; false on any failure.
2749 */
2750 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002751 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002752 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002753 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2754 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002755 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002756 if (success) {
2757 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002758 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002759 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002760 return success;
2761 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002762
2763 /**
Junda Liu475951f2014-11-07 16:45:03 -08002764 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2765 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2766 * tethering.
2767 *
2768 * @return 0: Not required. 1: required. 2: Not set.
2769 * @hide
2770 */
2771 @Override
2772 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002773 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002774 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2775 Settings.Global.TETHER_DUN_REQUIRED, 2);
2776 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2777 // config_tether_apndata.
2778 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2779 dunRequired = 1;
2780 }
2781 return dunRequired;
2782 }
2783
2784 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002785 * Set mobile data enabled
2786 * Used by the user through settings etc to turn on/off mobile data
2787 *
2788 * @param enable {@code true} turn turn data on, else {@code false}
2789 */
2790 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002791 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002792 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002793 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002794 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002795 Phone phone = PhoneFactory.getPhone(phoneId);
2796 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002797 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2798 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002799 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002800 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002801 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002802 }
2803
2804 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002805 * Get the user enabled state of Mobile Data.
2806 *
2807 * TODO: remove and use isUserDataEnabled.
2808 * This can't be removed now because some vendor codes
2809 * calls through ITelephony directly while they should
2810 * use TelephonyManager.
2811 *
2812 * @return true on enabled
2813 */
2814 @Override
2815 public boolean getDataEnabled(int subId) {
2816 return isUserDataEnabled(subId);
2817 }
2818
2819 /**
2820 * Get whether mobile data is enabled per user setting.
2821 *
2822 * There are other factors deciding whether mobile data is actually enabled, but they are
2823 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002824 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002825 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002826 *
2827 * @return {@code true} if data is enabled else {@code false}
2828 */
2829 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002830 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002831 try {
2832 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2833 null);
2834 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002835 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002836 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002837 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002838 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002839 Phone phone = PhoneFactory.getPhone(phoneId);
2840 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002841 boolean retVal = phone.isUserDataEnabled();
2842 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002843 return retVal;
2844 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002845 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2846 return false;
2847 }
2848 }
2849
2850 /**
2851 * Get whether mobile data is enabled.
2852 *
2853 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2854 * whether mobile data is actually enabled.
2855 *
2856 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2857 *
2858 * @return {@code true} if data is enabled else {@code false}
2859 */
2860 @Override
2861 public boolean isDataEnabled(int subId) {
2862 try {
2863 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2864 null);
2865 } catch (Exception e) {
2866 enforceModifyPermissionOrCarrierPrivilege(subId);
2867 }
2868 int phoneId = mSubscriptionController.getPhoneId(subId);
2869 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2870 Phone phone = PhoneFactory.getPhone(phoneId);
2871 if (phone != null) {
2872 boolean retVal = phone.isDataEnabled();
2873 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2874 return retVal;
2875 } else {
2876 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002877 return false;
2878 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002879 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002880
2881 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002882 public int getCarrierPrivilegeStatus(int subId) {
2883 final Phone phone = getPhone(subId);
2884 if (phone == null) {
2885 loge("getCarrierPrivilegeStatus: Invalid subId");
2886 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2887 }
2888 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002889 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002890 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002891 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2892 }
2893 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002894 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002895 }
Junda Liu29340342014-07-10 15:23:27 -07002896
2897 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002898 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002899 if (TextUtils.isEmpty(pkgName))
2900 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002901 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002902 if (card == null) {
2903 loge("checkCarrierPrivilegesForPackage: No UICC");
2904 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2905 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002906 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2907 }
2908
2909 @Override
2910 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002911 if (TextUtils.isEmpty(pkgName))
2912 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002913 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2914 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2915 UiccCard card = UiccController.getInstance().getUiccCard(i);
2916 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002917 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002918 continue;
2919 }
2920
2921 result = card.getCarrierPrivilegeStatus(
2922 mPhone.getContext().getPackageManager(), pkgName);
2923 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2924 break;
2925 }
2926 }
2927
2928 return result;
Junda Liu29340342014-07-10 15:23:27 -07002929 }
Derek Tan89e89d42014-07-08 17:00:10 -07002930
2931 @Override
Junda Liue64de782015-04-16 17:19:16 -07002932 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2933 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2934 loge("phoneId " + phoneId + " is not valid.");
2935 return null;
2936 }
2937 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002938 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002939 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002940 return null ;
2941 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002942 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002943 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002944 }
2945
Amith Yamasani6e118872016-02-19 12:53:51 -08002946 @Override
2947 public List<String> getPackagesWithCarrierPrivileges() {
2948 PackageManager pm = mPhone.getContext().getPackageManager();
2949 List<String> privilegedPackages = new ArrayList<>();
2950 List<PackageInfo> packages = null;
2951 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2952 UiccCard card = UiccController.getInstance().getUiccCard(i);
2953 if (card == null) {
2954 // No UICC in that slot.
2955 continue;
2956 }
2957 if (card.hasCarrierPrivilegeRules()) {
2958 if (packages == null) {
2959 // Only check packages in user 0 for now
2960 packages = pm.getInstalledPackagesAsUser(
2961 PackageManager.MATCH_DISABLED_COMPONENTS
2962 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2963 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2964 }
2965 for (int p = packages.size() - 1; p >= 0; p--) {
2966 PackageInfo pkgInfo = packages.get(p);
2967 if (pkgInfo != null && pkgInfo.packageName != null
2968 && card.getCarrierPrivilegeStatus(pkgInfo)
2969 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2970 privilegedPackages.add(pkgInfo.packageName);
2971 }
2972 }
2973 }
2974 }
2975 return privilegedPackages;
2976 }
2977
Wink Savilleb564aae2014-10-23 10:18:09 -07002978 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002979 final Phone phone = getPhone(subId);
2980 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002981 if (card == null) {
2982 loge("getIccId: No UICC");
2983 return null;
2984 }
2985 String iccId = card.getIccId();
2986 if (TextUtils.isEmpty(iccId)) {
2987 loge("getIccId: ICC ID is null or empty.");
2988 return null;
2989 }
2990 return iccId;
2991 }
2992
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002993 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002994 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2995 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002996 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002997
Jeff Sharkey85190e62014-12-05 09:40:12 -08002998 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002999 final Phone phone = getPhone(subId);
3000 if (phone == null) {
3001 return false;
3002 }
3003 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003004
3005 if (DBG_MERGE) {
3006 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3007 + subscriberId + " to " + number);
3008 }
3009
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003010 if (TextUtils.isEmpty(iccId)) {
3011 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003012 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003013
Jeff Sharkey85190e62014-12-05 09:40:12 -08003014 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3015
3016 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003017 if (alphaTag == null) {
3018 editor.remove(alphaTagPrefKey);
3019 } else {
3020 editor.putString(alphaTagPrefKey, alphaTag);
3021 }
3022
Jeff Sharkey85190e62014-12-05 09:40:12 -08003023 // Record both the line number and IMSI for this ICCID, since we need to
3024 // track all merged IMSIs based on line number
3025 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3026 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003027 if (number == null) {
3028 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003029 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003030 } else {
3031 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003032 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003033 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003034
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003035 editor.commit();
3036 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003037 }
3038
3039 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003040 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003041 // This is open to apps with WRITE_SMS.
3042 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003043 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003044 return null;
3045 }
Derek Tan97ebb422014-09-05 16:55:38 -07003046
3047 String iccId = getIccId(subId);
3048 if (iccId != null) {
3049 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003050 if (DBG_MERGE) {
3051 log("getLine1NumberForDisplay returning " +
3052 mTelephonySharedPreferences.getString(numberPrefKey, null));
3053 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003054 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003055 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003056 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003057 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003058 }
3059
3060 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003061 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3062 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3063 return null;
3064 }
Derek Tan97ebb422014-09-05 16:55:38 -07003065
3066 String iccId = getIccId(subId);
3067 if (iccId != null) {
3068 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003069 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003070 }
Derek Tan97ebb422014-09-05 16:55:38 -07003071 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003072 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003073
3074 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003075 public String[] getMergedSubscriberIds(String callingPackage) {
3076 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3077 return null;
3078 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003079 final Context context = mPhone.getContext();
3080 final TelephonyManager tele = TelephonyManager.from(context);
3081 final SubscriptionManager sub = SubscriptionManager.from(context);
3082
3083 // Figure out what subscribers are currently active
3084 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003085 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3086 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3087 final long identity = Binder.clearCallingIdentity();
3088 try {
3089 final int[] subIds = sub.getActiveSubscriptionIdList();
3090 for (int subId : subIds) {
3091 activeSubscriberIds.add(tele.getSubscriberId(subId));
3092 }
3093 } finally {
3094 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003095 }
3096
3097 // First pass, find a number override for an active subscriber
3098 String mergeNumber = null;
3099 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3100 for (String key : prefs.keySet()) {
3101 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3102 final String subscriberId = (String) prefs.get(key);
3103 if (activeSubscriberIds.contains(subscriberId)) {
3104 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3105 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3106 mergeNumber = (String) prefs.get(numberKey);
3107 if (DBG_MERGE) {
3108 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3109 + " for active subscriber " + subscriberId);
3110 }
3111 if (!TextUtils.isEmpty(mergeNumber)) {
3112 break;
3113 }
3114 }
3115 }
3116 }
3117
3118 // Shortcut when no active merged subscribers
3119 if (TextUtils.isEmpty(mergeNumber)) {
3120 return null;
3121 }
3122
3123 // Second pass, find all subscribers under that line override
3124 final ArraySet<String> result = new ArraySet<>();
3125 for (String key : prefs.keySet()) {
3126 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3127 final String number = (String) prefs.get(key);
3128 if (mergeNumber.equals(number)) {
3129 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3130 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3131 final String subscriberId = (String) prefs.get(subscriberKey);
3132 if (!TextUtils.isEmpty(subscriberId)) {
3133 result.add(subscriberId);
3134 }
3135 }
3136 }
3137 }
3138
3139 final String[] resultArray = result.toArray(new String[result.size()]);
3140 Arrays.sort(resultArray);
3141 if (DBG_MERGE) {
3142 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3143 }
3144 return resultArray;
3145 }
3146
3147 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003148 public boolean setOperatorBrandOverride(int subId, String brand) {
3149 enforceCarrierPrivilege(subId);
3150 final Phone phone = getPhone(subId);
3151 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003152 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003153
3154 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003155 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003156 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3157 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003158 enforceCarrierPrivilege(subId);
3159 final Phone phone = getPhone(subId);
3160 if (phone == null) {
3161 return false;
3162 }
3163 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003164 cdmaNonRoamingList);
3165 }
3166
3167 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003168 public void setRadioCapability(RadioAccessFamily[] rafs) {
3169 try {
3170 ProxyController.getInstance().setRadioCapability(rafs);
3171 } catch (RuntimeException e) {
3172 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3173 }
3174 }
3175
3176 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003177 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3178 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3179 return RadioAccessFamily.RAF_UNKNOWN;
3180 }
3181
Wink Saville5d475dd2014-10-17 15:00:58 -07003182 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3183 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003184
3185 @Override
3186 public void enableVideoCalling(boolean enable) {
3187 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003188 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003189 }
3190
3191 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003192 public boolean isVideoCallingEnabled(String callingPackage) {
3193 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3194 return false;
3195 }
3196
Andrew Lee77527ac2014-10-21 16:57:39 -07003197 // Check the user preference and the system-level IMS setting. Even if the user has
3198 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3199 // In the long run, we may instead need to check if there exists a connection service
3200 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003201 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3202 return imsManager.isVtEnabledByPlatform()
3203 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3204 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003205 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003206
Andrew Leea1239f22015-03-02 17:44:07 -08003207 @Override
3208 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003209 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003210 }
3211
3212 @Override
3213 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003214 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003215 }
3216
Andrew Lee9431b832015-03-09 18:46:45 -07003217 @Override
3218 public boolean isTtyModeSupported() {
3219 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3220 TelephonyManager telephonyManager =
3221 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003222 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003223 }
3224
3225 @Override
3226 public boolean isHearingAidCompatibilitySupported() {
3227 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3228 }
3229
Sanket Padawe7310cc72015-01-14 09:53:20 -08003230 /**
3231 * Returns the unique device ID of phone, for example, the IMEI for
3232 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3233 *
3234 * <p>Requires Permission:
3235 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3236 */
3237 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003238 public String getDeviceId(String callingPackage) {
3239 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3240 return null;
3241 }
3242
Sanket Padawe7310cc72015-01-14 09:53:20 -08003243 final Phone phone = PhoneFactory.getPhone(0);
3244 if (phone != null) {
3245 return phone.getDeviceId();
3246 } else {
3247 return null;
3248 }
3249 }
3250
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003251 /*
3252 * {@hide}
3253 * Returns the IMS Registration Status
3254 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003255 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003256 public boolean isImsRegistered() {
3257 return mPhone.isImsRegistered();
3258 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003259
Ping Sunc67b7c22016-03-02 19:16:45 +08003260 /**
3261 * {@hide}
3262 * Returns the IMS Registration Status on a particular subid
3263 *
3264 * @param subId
3265 */
3266 public boolean isImsRegisteredForSubscriber(int subId) {
3267 Phone phone = getPhone(subId);
3268 if (phone != null) {
3269 return phone.isImsRegistered();
3270 } else {
3271 return false;
3272 }
3273 }
3274
Santos Cordon7a1885b2015-02-03 11:15:19 -08003275 @Override
3276 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3277 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3278 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003279
Nathan Haroldc55097a2015-03-11 18:14:50 -07003280 /*
3281 * {@hide}
3282 * Returns the IMS Registration Status
3283 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003284 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003285 return mPhone.isWifiCallingEnabled();
3286 }
3287
3288 /*
3289 * {@hide}
3290 * Returns the IMS Registration Status
3291 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003292 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003293 return mPhone.isVolteEnabled();
3294 }
Svet Ganovb320e182015-04-16 12:30:10 -07003295
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003296 /*
3297 * {@hide} Returns the IMS Registration Status
3298 */
3299 public boolean isVideoTelephonyAvailable() {
3300 return mPhone.isVideoEnabled();
3301 }
3302
Svet Ganovb320e182015-04-16 12:30:10 -07003303 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003304 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003305 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003306 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3307
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003308 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003309 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003310 } catch (SecurityException e) {
3311 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3312 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003313 }
Svet Ganovb320e182015-04-16 12:30:10 -07003314
3315 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3316 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3317 return false;
3318 }
3319
3320 return true;
3321 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003322
Makoto Onukifee69342015-06-29 14:44:50 -07003323 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003324 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003325 */
3326 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003327 // Default SMS app can always read it.
3328 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3329 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3330 return true;
3331 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003332
Makoto Onukie4072d12015-08-03 15:12:23 -07003333 try {
3334 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003335 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003336 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003337 // Can be read with READ_SMS too.
3338 try {
3339 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3340 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3341 if (opCode != AppOpsManager.OP_NONE) {
3342 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3343 == AppOpsManager.MODE_ALLOWED;
3344 } else {
3345 return true;
3346 }
3347 } catch (SecurityException readSmsSecurityException) {
3348 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003349 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003350 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003351 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003352 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003353 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003354 if (opCode != AppOpsManager.OP_NONE) {
3355 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3356 == AppOpsManager.MODE_ALLOWED;
3357 } else {
3358 return true;
3359 }
3360 } catch (SecurityException readPhoneNumberSecurityException) {
3361 }
3362
3363 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3364 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3365 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003366 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003367 }
3368
Stuart Scott8eef64f2015-04-08 15:13:54 -07003369 @Override
3370 public void factoryReset(int subId) {
3371 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003372 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3373 return;
3374 }
3375
Svet Ganovcc087f82015-05-12 20:35:54 -07003376 final long identity = Binder.clearCallingIdentity();
3377 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003378 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3379 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003380 // Enable data
Malcolm Chen964682d2017-11-28 16:20:07 -08003381 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003382 // Set network selection mode to automatic
3383 setNetworkSelectionModeAutomatic(subId);
3384 // Set preferred mobile network type to the best available
3385 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3386 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003387 mPhone.setDataRoamingEnabled(false);
pkanwar79ec0542017-07-31 14:10:01 -07003388 // Remove IMSI encryption keys from Carrier DB.
3389 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003390 }
3391 } finally {
3392 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003393 }
3394 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003395
3396 @Override
3397 public String getLocaleFromDefaultSim() {
3398 // We query all subscriptions instead of just the active ones, because
3399 // this might be called early on in the provisioning flow when the
3400 // subscriptions potentially aren't active yet.
3401 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3402 if (slist == null || slist.isEmpty()) {
3403 return null;
3404 }
3405
3406 // This function may be called very early, say, from the setup wizard, at
3407 // which point we won't have a default subscription set. If that's the case
3408 // we just choose the first, which will be valid in "most cases".
3409 final int defaultSubId = getDefaultSubscription();
3410 SubscriptionInfo info = null;
3411 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3412 info = slist.get(0);
3413 } else {
3414 for (SubscriptionInfo item : slist) {
3415 if (item.getSubscriptionId() == defaultSubId) {
3416 info = item;
3417 break;
3418 }
3419 }
3420
3421 if (info == null) {
3422 return null;
3423 }
3424 }
3425
3426 // Try and fetch the locale from the carrier properties or from the SIM language
3427 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003428 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003429 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003430 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003431 if (defaultPhone != null) {
3432 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3433 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003434 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003435 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3436 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003437 } else {
3438 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003439 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003440 }
3441 }
3442
Narayan Kamath011676f2015-07-29 12:04:08 +01003443 // The SIM language preferences only store a language (e.g. fr = French), not an
3444 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3445 // the SIM and carrier preferences does not include a country we add the country
3446 // determined from the SIM MCC to provide an exact locale.
3447 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003448 if (mccLocale != null) {
3449 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3450 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003451 }
3452
Tony Hill183b2de2015-06-24 14:53:58 +01003453 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003454 return null;
3455 }
3456
3457 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3458 final long identity = Binder.clearCallingIdentity();
3459 try {
3460 return mSubscriptionController.getAllSubInfoList(
3461 mPhone.getContext().getOpPackageName());
3462 } finally {
3463 Binder.restoreCallingIdentity(identity);
3464 }
3465 }
3466
3467 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3468 final long identity = Binder.clearCallingIdentity();
3469 try {
3470 return mSubscriptionController.getActiveSubscriptionInfoList(
3471 mPhone.getContext().getOpPackageName());
3472 } finally {
3473 Binder.restoreCallingIdentity(identity);
3474 }
3475 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003476
3477 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003478 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3479 * representing the state of the modem.
3480 *
3481 * NOTE: This clears the modem state, so there should only every be one caller.
3482 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003483 */
3484 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003485 public void requestModemActivityInfo(ResultReceiver result) {
3486 enforceModifyPermission();
3487
3488 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3489 Bundle bundle = new Bundle();
3490 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3491 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003492 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003493
3494 /**
3495 * {@hide}
3496 * Returns the service state information on specified subscription.
3497 */
3498 @Override
3499 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3500
3501 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3502 return null;
3503 }
3504
3505 final Phone phone = getPhone(subId);
3506 if (phone == null) {
3507 return null;
3508 }
3509
3510 return phone.getServiceState();
3511 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003512
3513 /**
3514 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3515 *
3516 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3517 * voicemail ringtone.
3518 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3519 * PhoneAccount.
3520 */
3521 @Override
3522 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003523 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003524 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003525 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003526 }
3527
fionaxu7ed723d2017-05-30 18:58:54 -07003528 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003529 }
3530
3531 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003532 * Sets the per-account voicemail ringtone.
3533 *
3534 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3535 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3536 *
3537 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3538 * voicemail ringtone.
3539 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3540 * PhoneAccount.
3541 */
3542 @Override
3543 public void setVoicemailRingtoneUri(String callingPackage,
3544 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3545 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3546 if (!TextUtils.equals(callingPackage,
3547 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3548 enforceModifyPermissionOrCarrierPrivilege(
3549 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3550 }
3551 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3552 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003553 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003554 }
fionaxu7ed723d2017-05-30 18:58:54 -07003555 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003556 }
3557
3558 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003559 * Returns whether vibration is set for voicemail notification in Phone settings.
3560 *
3561 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3562 * voicemail vibration setting.
3563 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3564 */
3565 @Override
3566 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003567 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003568 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003569 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003570 }
3571
fionaxu7ed723d2017-05-30 18:58:54 -07003572 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003573 }
3574
Youhan Wange64578a2016-05-02 15:32:42 -07003575 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003576 * Sets the per-account voicemail vibration.
3577 *
3578 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3579 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3580 *
3581 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3582 * voicemail vibration setting.
3583 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3584 * specific PhoneAccount.
3585 */
3586 @Override
3587 public void setVoicemailVibrationEnabled(String callingPackage,
3588 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3589 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3590 if (!TextUtils.equals(callingPackage,
3591 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3592 enforceModifyPermissionOrCarrierPrivilege(
3593 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3594 }
3595
3596 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3597 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003598 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003599 }
fionaxu7ed723d2017-05-30 18:58:54 -07003600 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003601 }
3602
3603 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003604 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3605 *
3606 * @throws SecurityException if the caller does not have the required permission
3607 */
3608 private void enforceReadPrivilegedPermission() {
3609 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3610 null);
3611 }
3612
3613 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003614 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3615 * permission.
3616 *
3617 * @throws SecurityException if the caller does not have the required permission
3618 */
3619 private void enforceSendSmsPermission() {
3620 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3621 }
3622
3623 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003624 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003625 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003626 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003627 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003628 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003629 ComponentName componentName =
3630 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3631 if(componentName == null) {
3632 throw new SecurityException("Caller not current active visual voicemail package[null]");
3633 }
3634 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003635 if (!callingPackage.equals(vvmPackage)) {
3636 throw new SecurityException("Caller not current active visual voicemail package[" +
3637 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003638 }
3639 }
3640
3641 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003642 * Return the application ID for the app type.
3643 *
3644 * @param subId the subscription ID that this request applies to.
3645 * @param appType the uicc app type.
3646 * @return Application ID for specificied app type, or null if no uicc.
3647 */
3648 @Override
3649 public String getAidForAppType(int subId, int appType) {
3650 enforceReadPrivilegedPermission();
3651 Phone phone = getPhone(subId);
3652 if (phone == null) {
3653 return null;
3654 }
3655 String aid = null;
3656 try {
3657 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3658 .getApplicationByType(appType).getAid();
3659 } catch (Exception e) {
3660 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3661 }
3662 return aid;
3663 }
3664
Youhan Wang4001d252016-05-11 10:29:41 -07003665 /**
3666 * Return the Electronic Serial Number.
3667 *
3668 * @param subId the subscription ID that this request applies to.
3669 * @return ESN or null if error.
3670 */
3671 @Override
3672 public String getEsn(int subId) {
3673 enforceReadPrivilegedPermission();
3674 Phone phone = getPhone(subId);
3675 if (phone == null) {
3676 return null;
3677 }
3678 String esn = null;
3679 try {
3680 esn = phone.getEsn();
3681 } catch (Exception e) {
3682 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3683 }
3684 return esn;
3685 }
3686
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003687 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003688 * Return the Preferred Roaming List Version.
3689 *
3690 * @param subId the subscription ID that this request applies to.
3691 * @return PRLVersion or null if error.
3692 */
3693 @Override
3694 public String getCdmaPrlVersion(int subId) {
3695 enforceReadPrivilegedPermission();
3696 Phone phone = getPhone(subId);
3697 if (phone == null) {
3698 return null;
3699 }
3700 String cdmaPrlVersion = null;
3701 try {
3702 cdmaPrlVersion = phone.getCdmaPrlVersion();
3703 } catch (Exception e) {
3704 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3705 }
3706 return cdmaPrlVersion;
3707 }
3708
3709 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003710 * Get snapshot of Telephony histograms
3711 * @return List of Telephony histograms
3712 * @hide
3713 */
3714 @Override
3715 public List<TelephonyHistogram> getTelephonyHistograms() {
3716 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3717 return RIL.getTelephonyRILTimingHistograms();
3718 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003719
3720 /**
3721 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003722 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003723 * Require system privileges. In the future we may add this to carrier APIs.
3724 *
3725 * @return The number of carriers set successfully, should match length of carriers
3726 */
3727 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003728 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003729 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003730
Meng Wang9b7c4e92017-02-17 11:41:27 -08003731 if (carriers == null) {
3732 throw new NullPointerException("carriers cannot be null");
3733 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003734
3735 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003736 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3737 return retVal[0];
3738 }
3739
3740 /**
3741 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003742 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003743 * Require system privileges. In the future we may add this to carrier APIs.
3744 *
3745 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3746 * means all carriers are allowed.
3747 */
3748 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003749 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003750 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003751 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003752 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3753 }
3754
fionaxu59545b42016-05-25 15:53:37 -07003755 /**
3756 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3757 * @param subId the subscription ID that this action applies to.
3758 * @param enabled control enable or disable metered apns.
3759 * {@hide}
3760 */
3761 @Override
3762 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3763 enforceModifyPermission();
3764 final Phone phone = getPhone(subId);
3765 if (phone == null) {
3766 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3767 return;
3768 }
3769 try {
3770 phone.carrierActionSetMeteredApnsEnabled(enabled);
3771 } catch (Exception e) {
3772 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3773 }
3774 }
3775
3776 /**
3777 * Action set from carrier signalling broadcast receivers to enable/disable radio
3778 * @param subId the subscription ID that this action applies to.
3779 * @param enabled control enable or disable radio.
3780 * {@hide}
3781 */
3782 @Override
3783 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3784 enforceModifyPermission();
3785 final Phone phone = getPhone(subId);
3786 if (phone == null) {
3787 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3788 return;
3789 }
3790 try {
3791 phone.carrierActionSetRadioEnabled(enabled);
3792 } catch (Exception e) {
3793 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3794 }
3795 }
3796
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003797 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003798 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3799 * network status based on which carrier apps could apply actions accordingly,
3800 * enable/disable default url handler for example.
3801 *
3802 * @param subId the subscription ID that this action applies to.
3803 * @param report control start/stop reporting the default network status.
3804 * {@hide}
3805 */
3806 @Override
3807 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3808 enforceModifyPermission();
3809 final Phone phone = getPhone(subId);
3810 if (phone == null) {
3811 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3812 return;
3813 }
3814 try {
3815 phone.carrierActionReportDefaultNetworkStatus(report);
3816 } catch (Exception e) {
3817 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3818 }
3819 }
3820
3821 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003822 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3823 * bug report is being generated.
3824 */
3825 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003826 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003827 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3828 != PackageManager.PERMISSION_GRANTED) {
3829 writer.println("Permission Denial: can't dump Phone from pid="
3830 + Binder.getCallingPid()
3831 + ", uid=" + Binder.getCallingUid()
3832 + "without permission "
3833 + android.Manifest.permission.DUMP);
3834 return;
3835 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003836 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003837 }
Jack Yueb89b242016-06-22 13:27:47 -07003838
3839 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003840 * Get aggregated video call data usage since boot.
3841 *
3842 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3843 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003844 * {@hide}
3845 */
3846 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003847 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003848 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3849 null);
3850
Jack Yu84291ec2017-05-26 16:07:50 -07003851 // NetworkStatsService keeps tracking the active network interface and identity. It
3852 // records the delta with the corresponding network identity. We just return the total video
3853 // call data usage snapshot since boot.
3854 Phone phone = getPhone(subId);
3855 if (phone != null) {
3856 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003857 }
Jack Yu84291ec2017-05-26 16:07:50 -07003858 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003859 }
Jack Yu75ab2952016-07-08 14:29:33 -07003860
3861 /**
3862 * Policy control of data connection. Usually used when data limit is passed.
3863 * @param enabled True if enabling the data, otherwise disabling.
3864 * @param subId Subscription index
3865 * {@hide}
3866 */
3867 @Override
3868 public void setPolicyDataEnabled(boolean enabled, int subId) {
3869 enforceModifyPermission();
3870 Phone phone = getPhone(subId);
3871 if (phone != null) {
3872 phone.setPolicyDataEnabled(enabled);
3873 }
3874 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003875
3876 /**
3877 * Get Client request stats
3878 * @return List of Client Request Stats
3879 * @hide
3880 */
3881 @Override
3882 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3883 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3884 return null;
3885 }
3886
3887 Phone phone = getPhone(subId);
3888 if (phone != null) {
3889 return phone.getClientRequestStats();
3890 }
3891
3892 return null;
3893 }
3894
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003895 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003896 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003897 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003898 }
Jack Yueb4124c2017-02-16 15:32:43 -08003899
3900 /**
Grace Chen70990072017-03-24 17:21:30 -07003901 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003902 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003903 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003904 * @param state State of SIM (power down, power up, pass through)
3905 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3906 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3907 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003908 *
3909 **/
3910 @Override
Grace Chen70990072017-03-24 17:21:30 -07003911 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003912 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003913 Phone phone = PhoneFactory.getPhone(slotIndex);
3914
Jack Yueb4124c2017-02-16 15:32:43 -08003915 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003916 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003917 }
3918 }
Shuo Qiandd210312017-04-12 22:11:33 +00003919
Tyler Gunn65d45c22017-06-05 11:22:26 -07003920 private boolean isUssdApiAllowed(int subId) {
3921 CarrierConfigManager configManager =
3922 (CarrierConfigManager) mPhone.getContext().getSystemService(
3923 Context.CARRIER_CONFIG_SERVICE);
3924 if (configManager == null) {
3925 return false;
3926 }
3927 PersistableBundle pb = configManager.getConfigForSubId(subId);
3928 if (pb == null) {
3929 return false;
3930 }
3931 return pb.getBoolean(
3932 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3933 }
3934
Shuo Qiandd210312017-04-12 22:11:33 +00003935 /**
3936 * Check if phone is in emergency callback mode
3937 * @return true if phone is in emergency callback mode
3938 * @param subId sub id
3939 */
goneil9c5f4872017-12-05 14:07:56 -08003940 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00003941 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08003942 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00003943 final Phone phone = getPhone(subId);
3944 if (phone != null) {
3945 return phone.isInEcm();
3946 } else {
3947 return false;
3948 }
3949 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003950
3951 /**
3952 * Get the current signal strength information for the given subscription.
3953 * Because this information is not updated when the device is in a low power state
3954 * it should not be relied-upon to be current.
3955 * @param subId Subscription index
3956 * @return the most recent cached signal strength info from the modem
3957 */
3958 @Override
3959 public SignalStrength getSignalStrength(int subId) {
3960 Phone p = getPhone(subId);
3961 if (p == null) {
3962 return null;
3963 }
3964
3965 return p.getSignalStrength();
3966 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00003967
3968 @Override
3969 public UiccSlotInfo[] getUiccSlotsInfo() {
3970 enforceReadPrivilegedPermission();
3971
3972 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
3973 if (slots == null) return null;
3974 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
3975 for (int i = 0; i < slots.length; i++) {
3976 UiccSlot slot = slots[i];
3977
3978 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
3979
3980 int cardState = 0;
3981 switch (slot.getCardState()) {
3982 case CARDSTATE_ABSENT:
3983 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
3984 break;
3985 case CARDSTATE_PRESENT:
3986 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
3987 break;
3988 case CARDSTATE_ERROR:
3989 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
3990 break;
3991 case CARDSTATE_RESTRICTED:
3992 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
3993 break;
3994 default:
3995 break;
3996
3997 }
3998
3999 infos[i] = new UiccSlotInfo(slot.isActive(), slot.isEuicc(), cardId, cardState);
4000 }
4001 return infos;
4002 }
4003
4004 @Override
4005 public boolean switchSlots(int[] physicalSlots) {
4006 enforceModifyPermission();
4007 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004009}