blob: 31d4642369a2be81f36200513d78f36331c23d22 [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;
Tyler Gunn65d45c22017-06-05 11:22:26 -070070import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070071import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080073import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080075import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080076import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080077
Andrew Lee312e8172014-10-23 17:01:36 -070078import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080079import com.android.ims.internal.IImsMMTelFeature;
80import com.android.ims.internal.IImsRcsFeature;
Brad Ebinger5f64b052017-12-14 14:26:15 -080081import com.android.ims.internal.IImsRegistration;
Brad Ebinger34bef922017-11-09 10:27:08 -080082import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070083import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070084import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070085import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070086import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070087import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080090import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010091import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070092import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070093import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080095import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070096import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070097import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070098import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070099import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700100import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800101import com.android.internal.telephony.SubscriptionController;
Jonathan Basseribf5362b2017-07-19 12:22:35 -0700102import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700103import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700104import com.android.internal.telephony.uicc.IccIoResult;
105import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800106import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700107import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800108import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700109import com.android.internal.telephony.uicc.UiccController;
fionaxu7ed723d2017-05-30 18:58:54 -0700110import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800111import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700112import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800113import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700114import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700115import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800116
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700117import java.io.FileDescriptor;
118import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800119import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800121import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800122import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100123import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800124import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125
126/**
127 * Implementation of the ITelephony interface.
128 */
Santos Cordon117fee72014-05-16 17:56:12 -0700129public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130 private static final String LOG_TAG = "PhoneInterfaceManager";
131 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
132 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800133 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134
135 // Message codes used with mMainThreadHandler
136 private static final int CMD_HANDLE_PIN_MMI = 1;
137 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
138 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
139 private static final int CMD_ANSWER_RINGING_CALL = 4;
140 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700141 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
142 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700143 private static final int CMD_OPEN_CHANNEL = 9;
144 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
145 private static final int CMD_CLOSE_CHANNEL = 11;
146 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800147 private static final int CMD_NV_READ_ITEM = 13;
148 private static final int EVENT_NV_READ_ITEM_DONE = 14;
149 private static final int CMD_NV_WRITE_ITEM = 15;
150 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
151 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
152 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
153 private static final int CMD_NV_RESET_CONFIG = 19;
154 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800155 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
156 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
157 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
158 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800159 private static final int CMD_SEND_ENVELOPE = 25;
160 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700161 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
162 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
163 private static final int CMD_EXCHANGE_SIM_IO = 31;
164 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800165 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
166 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700167 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
168 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700169 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
170 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700171 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
172 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
173 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
174 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700175 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
176 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
177 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
178 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700179 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800180 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
181 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182
183 /** The singleton instance. */
184 private static PhoneInterfaceManager sInstance;
185
Wink Saville3ab207e2014-11-20 13:07:20 -0800186 private PhoneGlobals mApp;
187 private Phone mPhone;
188 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700189 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800190 private AppOpsManager mAppOps;
191 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800192 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800193 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194
Derek Tan97ebb422014-09-05 16:55:38 -0700195 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
196 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800197 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700198
Derek Tan740e1672017-06-27 14:56:27 -0700199 // The AID of ISD-R.
200 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
201
yinxub1bed742017-04-17 11:45:04 -0700202 private NetworkScanRequestTracker mNetworkScanRequestTracker;
203
Derek Tan89e89d42014-07-08 17:00:10 -0700204 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700205 * A request object to use for transmitting data to an ICC.
206 */
207 private static final class IccAPDUArgument {
208 public int channel, cla, command, p1, p2, p3;
209 public String data;
210
211 public IccAPDUArgument(int channel, int cla, int command,
212 int p1, int p2, int p3, String data) {
213 this.channel = channel;
214 this.cla = cla;
215 this.command = command;
216 this.p1 = p1;
217 this.p2 = p2;
218 this.p3 = p3;
219 this.data = data;
220 }
221 }
222
223 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700224 * A request object to use for transmitting data to an ICC.
225 */
226 private static final class ManualNetworkSelectionArgument {
227 public OperatorInfo operatorInfo;
228 public boolean persistSelection;
229
230 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
231 this.operatorInfo = operatorInfo;
232 this.persistSelection = persistSelection;
233 }
234 }
235
236 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700237 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
238 * request after sending. The main thread will notify the request when it is complete.
239 */
240 private static final class MainThreadRequest {
241 /** The argument to use for the request */
242 public Object argument;
243 /** The result of the request that is run on the main thread */
244 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800245 // The subscriber id that this request applies to. Defaults to
246 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
247 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248
249 public MainThreadRequest(Object argument) {
250 this.argument = argument;
251 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800252
253 public MainThreadRequest(Object argument, Integer subId) {
254 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800255 if (subId != null) {
256 this.subId = subId;
257 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700259 }
260
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800261 private static final class IncomingThirdPartyCallArgs {
262 public final ComponentName component;
263 public final String callId;
264 public final String callerDisplayName;
265
266 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
267 String callerDisplayName) {
268 this.component = component;
269 this.callId = callId;
270 this.callerDisplayName = callerDisplayName;
271 }
272 }
273
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274 /**
275 * A handler that processes messages on the main thread in the phone process. Since many
276 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
277 * inbound binder threads to the main thread in the phone process. The Binder thread
278 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
279 * on, which will be notified when the operation completes and will contain the result of the
280 * request.
281 *
282 * <p>If a MainThreadRequest object is provided in the msg.obj field,
283 * note that request.result must be set to something non-null for the calling thread to
284 * unblock.
285 */
286 private final class MainThreadHandler extends Handler {
287 @Override
288 public void handleMessage(Message msg) {
289 MainThreadRequest request;
290 Message onCompleted;
291 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800292 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700293 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700294
295 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700296 case CMD_HANDLE_USSD_REQUEST: {
297 request = (MainThreadRequest) msg.obj;
298 final Phone phone = getPhoneFromRequest(request);
299 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
300 String ussdRequest = ussdObject.first;
301 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700302
303 if (!isUssdApiAllowed(request.subId)) {
304 // Carrier does not support use of this API, return failure.
305 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
306 UssdResponse response = new UssdResponse(ussdRequest, null);
307 Bundle returnData = new Bundle();
308 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
309 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
310
311 request.result = true;
312 synchronized (request) {
313 request.notifyAll();
314 }
315 return;
316 }
317
Tyler Gunn52dcf772017-04-26 11:30:31 -0700318 try {
319 request.result = phone != null ?
320 phone.handleUssdRequest(ussdRequest, wrappedCallback)
321 : false;
322 } catch (CallStateException cse) {
323 request.result = false;
324 }
pkanwar32d516d2016-10-14 19:37:38 -0700325 // Wake up the requesting thread
326 synchronized (request) {
327 request.notifyAll();
328 }
329 break;
330 }
331
Yorke Lee716f67e2015-06-17 15:39:16 -0700332 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700334 final Phone phone = getPhoneFromRequest(request);
335 request.result = phone != null ?
336 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
337 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 // Wake up the requesting thread
339 synchronized (request) {
340 request.notifyAll();
341 }
342 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
345 case CMD_HANDLE_NEIGHBORING_CELL:
346 request = (MainThreadRequest) msg.obj;
347 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
348 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700349 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 break;
351
352 case EVENT_NEIGHBORING_CELL_DONE:
353 ar = (AsyncResult) msg.obj;
354 request = (MainThreadRequest) ar.userObj;
355 if (ar.exception == null && ar.result != null) {
356 request.result = ar.result;
357 } else {
358 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800359 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360 }
361 // Wake up the requesting thread
362 synchronized (request) {
363 request.notifyAll();
364 }
365 break;
366
367 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700368 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800369 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700370 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 break;
372
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 case CMD_END_CALL:
374 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800375 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700376 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700377 Phone phone = getPhone(end_subId);
378 if (phone == null) {
379 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
380 break;
381 }
382 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
384 // CDMA: If the user presses the Power button we treat it as
385 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700386 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
388 // GSM: End the call as per the Phone state
389 hungUp = PhoneUtils.hangup(mCM);
390 } else {
391 throw new IllegalStateException("Unexpected phone type: " + phoneType);
392 }
393 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
394 request.result = hungUp;
395 // Wake up the requesting thread
396 synchronized (request) {
397 request.notifyAll();
398 }
399 break;
400
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700401 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700402 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700403 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800404 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700405 if (uiccCard == null) {
406 loge("iccTransmitApduLogicalChannel: No UICC");
407 request.result = new IccIoResult(0x6F, 0, (byte[])null);
408 synchronized (request) {
409 request.notifyAll();
410 }
411 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
413 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700414 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 iccArgument.channel, iccArgument.cla, iccArgument.command,
416 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700417 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700418 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700419 break;
420
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700421 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700422 ar = (AsyncResult) msg.obj;
423 request = (MainThreadRequest) ar.userObj;
424 if (ar.exception == null && ar.result != null) {
425 request.result = ar.result;
426 } else {
427 request.result = new IccIoResult(0x6F, 0, (byte[])null);
428 if (ar.result == null) {
429 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800430 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800432 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 } else {
434 loge("iccTransmitApduLogicalChannel: Unknown exception");
435 }
436 }
437 synchronized (request) {
438 request.notifyAll();
439 }
440 break;
441
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
443 request = (MainThreadRequest) msg.obj;
444 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800445 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 if (uiccCard == null) {
447 loge("iccTransmitApduBasicChannel: No UICC");
448 request.result = new IccIoResult(0x6F, 0, (byte[])null);
449 synchronized (request) {
450 request.notifyAll();
451 }
452 } else {
453 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
454 request);
455 uiccCard.iccTransmitApduBasicChannel(
456 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
457 iccArgument.p3, iccArgument.data, onCompleted);
458 }
459 break;
460
461 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
462 ar = (AsyncResult) msg.obj;
463 request = (MainThreadRequest) ar.userObj;
464 if (ar.exception == null && ar.result != null) {
465 request.result = ar.result;
466 } else {
467 request.result = new IccIoResult(0x6F, 0, (byte[])null);
468 if (ar.result == null) {
469 loge("iccTransmitApduBasicChannel: Empty response");
470 } else if (ar.exception instanceof CommandException) {
471 loge("iccTransmitApduBasicChannel: CommandException: " +
472 ar.exception);
473 } else {
474 loge("iccTransmitApduBasicChannel: Unknown exception");
475 }
476 }
477 synchronized (request) {
478 request.notifyAll();
479 }
480 break;
481
482 case CMD_EXCHANGE_SIM_IO:
483 request = (MainThreadRequest) msg.obj;
484 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800485 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 if (uiccCard == null) {
487 loge("iccExchangeSimIO: No UICC");
488 request.result = new IccIoResult(0x6F, 0, (byte[])null);
489 synchronized (request) {
490 request.notifyAll();
491 }
492 } else {
493 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
494 request);
495 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
496 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
497 iccArgument.data, onCompleted);
498 }
499 break;
500
501 case EVENT_EXCHANGE_SIM_IO_DONE:
502 ar = (AsyncResult) msg.obj;
503 request = (MainThreadRequest) ar.userObj;
504 if (ar.exception == null && ar.result != null) {
505 request.result = ar.result;
506 } else {
507 request.result = new IccIoResult(0x6f, 0, (byte[])null);
508 }
509 synchronized (request) {
510 request.notifyAll();
511 }
512 break;
513
Derek Tan4d5e5c12014-02-04 11:54:58 -0800514 case CMD_SEND_ENVELOPE:
515 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800516 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700517 if (uiccCard == null) {
518 loge("sendEnvelopeWithStatus: No UICC");
519 request.result = new IccIoResult(0x6F, 0, (byte[])null);
520 synchronized (request) {
521 request.notifyAll();
522 }
523 } else {
524 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
525 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
526 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800527 break;
528
529 case EVENT_SEND_ENVELOPE_DONE:
530 ar = (AsyncResult) msg.obj;
531 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700532 if (ar.exception == null && ar.result != null) {
533 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800534 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700535 request.result = new IccIoResult(0x6F, 0, (byte[])null);
536 if (ar.result == null) {
537 loge("sendEnvelopeWithStatus: Empty response");
538 } else if (ar.exception instanceof CommandException) {
539 loge("sendEnvelopeWithStatus: CommandException: " +
540 ar.exception);
541 } else {
542 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
543 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800544 }
545 synchronized (request) {
546 request.notifyAll();
547 }
548 break;
549
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 case CMD_OPEN_CHANNEL:
551 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800552 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800553 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 if (uiccCard == null) {
555 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800556 request.result = new IccOpenLogicalChannelResponse(-1,
557 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700558 synchronized (request) {
559 request.notifyAll();
560 }
561 } else {
562 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800563 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
564 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 break;
567
568 case EVENT_OPEN_CHANNEL_DONE:
569 ar = (AsyncResult) msg.obj;
570 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700572 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700573 int[] result = (int[]) ar.result;
574 int channelId = result[0];
575 byte[] selectResponse = null;
576 if (result.length > 1) {
577 selectResponse = new byte[result.length - 1];
578 for (int i = 1; i < result.length; ++i) {
579 selectResponse[i - 1] = (byte) result[i];
580 }
581 }
582 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700583 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 if (ar.result == null) {
586 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 if (ar.exception != null) {
589 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
590 }
591
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700592 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700593 if (ar.exception instanceof CommandException) {
594 CommandException.Error error =
595 ((CommandException) (ar.exception)).getCommandError();
596 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700597 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700598 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700599 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 }
601 }
602 openChannelResp = new IccOpenLogicalChannelResponse(
603 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700605 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 synchronized (request) {
607 request.notifyAll();
608 }
609 break;
610
611 case CMD_CLOSE_CHANNEL:
612 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800613 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700614 if (uiccCard == null) {
615 loge("iccCloseLogicalChannel: No UICC");
616 request.result = new IccIoResult(0x6F, 0, (byte[])null);
617 synchronized (request) {
618 request.notifyAll();
619 }
620 } else {
621 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
622 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
623 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 break;
625
626 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800627 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
628 break;
629
630 case CMD_NV_READ_ITEM:
631 request = (MainThreadRequest) msg.obj;
632 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
633 mPhone.nvReadItem((Integer) request.argument, onCompleted);
634 break;
635
636 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800639 if (ar.exception == null && ar.result != null) {
640 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800642 request.result = "";
643 if (ar.result == null) {
644 loge("nvReadItem: Empty response");
645 } else if (ar.exception instanceof CommandException) {
646 loge("nvReadItem: CommandException: " +
647 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800649 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 }
651 }
652 synchronized (request) {
653 request.notifyAll();
654 }
655 break;
656
Jake Hambye994d462014-02-03 13:10:13 -0800657 case CMD_NV_WRITE_ITEM:
658 request = (MainThreadRequest) msg.obj;
659 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
660 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
661 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
662 break;
663
664 case EVENT_NV_WRITE_ITEM_DONE:
665 handleNullReturnEvent(msg, "nvWriteItem");
666 break;
667
668 case CMD_NV_WRITE_CDMA_PRL:
669 request = (MainThreadRequest) msg.obj;
670 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
671 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
672 break;
673
674 case EVENT_NV_WRITE_CDMA_PRL_DONE:
675 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
676 break;
677
678 case CMD_NV_RESET_CONFIG:
679 request = (MainThreadRequest) msg.obj;
680 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
681 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
682 break;
683
684 case EVENT_NV_RESET_CONFIG_DONE:
685 handleNullReturnEvent(msg, "nvResetConfig");
686 break;
687
Jake Hamby7c27be32014-03-03 13:25:59 -0800688 case CMD_GET_PREFERRED_NETWORK_TYPE:
689 request = (MainThreadRequest) msg.obj;
690 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700691 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800692 break;
693
694 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
695 ar = (AsyncResult) msg.obj;
696 request = (MainThreadRequest) ar.userObj;
697 if (ar.exception == null && ar.result != null) {
698 request.result = ar.result; // Integer
699 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800700 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800701 if (ar.result == null) {
702 loge("getPreferredNetworkType: Empty response");
703 } else if (ar.exception instanceof CommandException) {
704 loge("getPreferredNetworkType: CommandException: " +
705 ar.exception);
706 } else {
707 loge("getPreferredNetworkType: Unknown exception");
708 }
709 }
710 synchronized (request) {
711 request.notifyAll();
712 }
713 break;
714
715 case CMD_SET_PREFERRED_NETWORK_TYPE:
716 request = (MainThreadRequest) msg.obj;
717 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
718 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700719 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800720 break;
721
722 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
723 handleNullReturnEvent(msg, "setPreferredNetworkType");
724 break;
725
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800726 case CMD_SET_VOICEMAIL_NUMBER:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
729 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800730 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
731 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800732 break;
733
734 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
735 handleNullReturnEvent(msg, "setVoicemailNumber");
736 break;
737
Stuart Scott54788802015-03-30 13:18:01 -0700738 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
739 request = (MainThreadRequest) msg.obj;
740 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
741 request);
742 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
743 break;
744
745 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
746 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
747 break;
748
Shishir Agrawal302c8692015-06-19 13:49:39 -0700749 case CMD_PERFORM_NETWORK_SCAN:
750 request = (MainThreadRequest) msg.obj;
751 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
752 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
753 break;
754
755 case EVENT_PERFORM_NETWORK_SCAN_DONE:
756 ar = (AsyncResult) msg.obj;
757 request = (MainThreadRequest) ar.userObj;
758 CellNetworkScanResult cellScanResult;
759 if (ar.exception == null && ar.result != null) {
760 cellScanResult = new CellNetworkScanResult(
761 CellNetworkScanResult.STATUS_SUCCESS,
762 (List<OperatorInfo>) ar.result);
763 } else {
764 if (ar.result == null) {
765 loge("getCellNetworkScanResults: Empty response");
766 }
767 if (ar.exception != null) {
768 loge("getCellNetworkScanResults: Exception: " + ar.exception);
769 }
770 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
771 if (ar.exception instanceof CommandException) {
772 CommandException.Error error =
773 ((CommandException) (ar.exception)).getCommandError();
774 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
775 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
776 } else if (error == CommandException.Error.GENERIC_FAILURE) {
777 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
778 }
779 }
780 cellScanResult = new CellNetworkScanResult(errorCode, null);
781 }
782 request.result = cellScanResult;
783 synchronized (request) {
784 request.notifyAll();
785 }
786 break;
787
788 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
789 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700790 ManualNetworkSelectionArgument selArg =
791 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700792 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
793 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700794 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
795 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700796 break;
797
798 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
799 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
800 break;
801
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700802 case CMD_GET_MODEM_ACTIVITY_INFO:
803 request = (MainThreadRequest) msg.obj;
804 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700805 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700806 break;
807
808 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
809 ar = (AsyncResult) msg.obj;
810 request = (MainThreadRequest) ar.userObj;
811 if (ar.exception == null && ar.result != null) {
812 request.result = ar.result;
813 } else {
814 if (ar.result == null) {
815 loge("queryModemActivityInfo: Empty response");
816 } else if (ar.exception instanceof CommandException) {
817 loge("queryModemActivityInfo: CommandException: " +
818 ar.exception);
819 } else {
820 loge("queryModemActivityInfo: Unknown exception");
821 }
822 }
Amit Mahajand4766222016-01-28 15:28:28 -0800823 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
824 if (request.result == null) {
825 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
826 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700827 synchronized (request) {
828 request.notifyAll();
829 }
830 break;
831
Meng Wang1a7c35a2016-05-05 20:56:15 -0700832 case CMD_SET_ALLOWED_CARRIERS:
833 request = (MainThreadRequest) msg.obj;
834 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
835 mPhone.setAllowedCarriers(
836 (List<CarrierIdentifier>) request.argument,
837 onCompleted);
838 break;
839
840 case EVENT_SET_ALLOWED_CARRIERS_DONE:
841 ar = (AsyncResult) msg.obj;
842 request = (MainThreadRequest) ar.userObj;
843 if (ar.exception == null && ar.result != null) {
844 request.result = ar.result;
845 } else {
846 if (ar.result == null) {
847 loge("setAllowedCarriers: Empty response");
848 } else if (ar.exception instanceof CommandException) {
849 loge("setAllowedCarriers: CommandException: " +
850 ar.exception);
851 } else {
852 loge("setAllowedCarriers: Unknown exception");
853 }
854 }
855 // Result cannot be null. Return -1 on error.
856 if (request.result == null) {
857 request.result = new int[]{-1};
858 }
859 synchronized (request) {
860 request.notifyAll();
861 }
862 break;
863
864 case CMD_GET_ALLOWED_CARRIERS:
865 request = (MainThreadRequest) msg.obj;
866 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
867 mPhone.getAllowedCarriers(onCompleted);
868 break;
869
870 case EVENT_GET_ALLOWED_CARRIERS_DONE:
871 ar = (AsyncResult) msg.obj;
872 request = (MainThreadRequest) ar.userObj;
873 if (ar.exception == null && ar.result != null) {
874 request.result = ar.result;
875 } else {
876 if (ar.result == null) {
877 loge("getAllowedCarriers: Empty response");
878 } else if (ar.exception instanceof CommandException) {
879 loge("getAllowedCarriers: CommandException: " +
880 ar.exception);
881 } else {
882 loge("getAllowedCarriers: Unknown exception");
883 }
884 }
885 // Result cannot be null. Return empty list of CarrierIdentifier.
886 if (request.result == null) {
887 request.result = new ArrayList<CarrierIdentifier>(0);
888 }
889 synchronized (request) {
890 request.notifyAll();
891 }
892 break;
893
Nathan Haroldb3014052017-01-25 15:57:32 -0800894 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
895 ar = (AsyncResult) msg.obj;
896 request = (MainThreadRequest) ar.userObj;
897 if (ar.exception == null && ar.result != null) {
898 request.result = ar.result;
899 } else {
900 request.result = new IllegalArgumentException(
901 "Failed to retrieve Forbidden Plmns");
902 if (ar.result == null) {
903 loge("getForbiddenPlmns: Empty response");
904 } else {
905 loge("getForbiddenPlmns: Unknown exception");
906 }
907 }
908 synchronized (request) {
909 request.notifyAll();
910 }
911 break;
912
913 case CMD_GET_FORBIDDEN_PLMNS:
914 request = (MainThreadRequest) msg.obj;
915 uiccCard = getUiccCardFromRequest(request);
916 if (uiccCard == null) {
917 loge("getForbiddenPlmns() UiccCard is null");
918 request.result = new IllegalArgumentException(
919 "getForbiddenPlmns() UiccCard is null");
920 synchronized (request) {
921 request.notifyAll();
922 }
923 break;
924 }
925 Integer appType = (Integer) request.argument;
926 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
927 if (uiccApp == null) {
928 loge("getForbiddenPlmns() no app with specified type -- "
929 + appType);
930 request.result = new IllegalArgumentException("Failed to get UICC App");
931 synchronized (request) {
932 request.notifyAll();
933 }
934 break;
935 } else {
936 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
937 + " specified type -- " + appType);
938 }
939 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
940 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
941 onCompleted);
942 break;
943
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700944 default:
945 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
946 break;
947 }
948 }
Jake Hambye994d462014-02-03 13:10:13 -0800949
950 private void handleNullReturnEvent(Message msg, String command) {
951 AsyncResult ar = (AsyncResult) msg.obj;
952 MainThreadRequest request = (MainThreadRequest) ar.userObj;
953 if (ar.exception == null) {
954 request.result = true;
955 } else {
956 request.result = false;
957 if (ar.exception instanceof CommandException) {
958 loge(command + ": CommandException: " + ar.exception);
959 } else {
960 loge(command + ": Unknown exception");
961 }
962 }
963 synchronized (request) {
964 request.notifyAll();
965 }
966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700967 }
968
969 /**
970 * Posts the specified command to be executed on the main thread,
971 * waits for the request to complete, and returns the result.
972 * @see #sendRequestAsync
973 */
974 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800975 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700976 }
977
978 /**
979 * Posts the specified command to be executed on the main thread,
980 * waits for the request to complete, and returns the result.
981 * @see #sendRequestAsync
982 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800983 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700984 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
985 throw new RuntimeException("This method will deadlock if called from the main thread.");
986 }
987
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800988 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700989 Message msg = mMainThreadHandler.obtainMessage(command, request);
990 msg.sendToTarget();
991
992 // Wait for the request to complete
993 synchronized (request) {
994 while (request.result == null) {
995 try {
996 request.wait();
997 } catch (InterruptedException e) {
998 // Do nothing, go back and wait until the request is complete
999 }
1000 }
1001 }
1002 return request.result;
1003 }
1004
1005 /**
1006 * Asynchronous ("fire and forget") version of sendRequest():
1007 * Posts the specified command to be executed on the main thread, and
1008 * returns immediately.
1009 * @see #sendRequest
1010 */
1011 private void sendRequestAsync(int command) {
1012 mMainThreadHandler.sendEmptyMessage(command);
1013 }
1014
1015 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001016 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1017 * @see {@link #sendRequest(int,Object)}
1018 */
1019 private void sendRequestAsync(int command, Object argument) {
1020 MainThreadRequest request = new MainThreadRequest(argument);
1021 Message msg = mMainThreadHandler.obtainMessage(command, request);
1022 msg.sendToTarget();
1023 }
1024
1025 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001026 * Initialize the singleton PhoneInterfaceManager instance.
1027 * This is only done once, at startup, from PhoneApp.onCreate().
1028 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001029 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001030 synchronized (PhoneInterfaceManager.class) {
1031 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001032 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001033 } else {
1034 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1035 }
1036 return sInstance;
1037 }
1038 }
1039
1040 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001041 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001042 mApp = app;
1043 mPhone = phone;
1044 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001045 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001046 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1047 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001048 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001049 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001050 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001051 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001052
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001053 publish();
1054 }
1055
1056 private void publish() {
1057 if (DBG) log("publish: " + this);
1058
1059 ServiceManager.addService("phone", this);
1060 }
1061
Stuart Scott584921c2015-01-15 17:10:34 -08001062 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001063 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1064 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001065 }
1066
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001067 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1068 Phone phone = getPhoneFromRequest(request);
1069 return phone == null ? null :
1070 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1071 }
1072
Wink Saville36469e72014-06-11 15:17:00 -07001073 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001074 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001075 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001076 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001077 //
1078 // Implementation of the ITelephony interface.
1079 //
1080
1081 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001082 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001083 }
1084
Wink Savilleb564aae2014-10-23 10:18:09 -07001085 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001086 if (DBG) log("dial: " + number);
1087 // No permission check needed here: This is just a wrapper around the
1088 // ACTION_DIAL intent, which is available to any app since it puts up
1089 // the UI before it does anything.
1090
1091 String url = createTelUrl(number);
1092 if (url == null) {
1093 return;
1094 }
1095
1096 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001097 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001098 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1099 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1100 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1101 mApp.startActivity(intent);
1102 }
1103 }
1104
1105 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001106 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001107 }
1108
Wink Savilleb564aae2014-10-23 10:18:09 -07001109 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001110 if (DBG) log("call: " + number);
1111
1112 // This is just a wrapper around the ACTION_CALL intent, but we still
1113 // need to do a permission check since we're calling startActivity()
1114 // from the context of the phone app.
1115 enforceCallPermission();
1116
1117 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1118 != AppOpsManager.MODE_ALLOWED) {
1119 return;
1120 }
1121
1122 String url = createTelUrl(number);
1123 if (url == null) {
1124 return;
1125 }
1126
Wink Saville08874612014-08-31 19:19:58 -07001127 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001128 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001129 if (slist != null) {
1130 for (SubscriptionInfo subInfoRecord : slist) {
1131 if (subInfoRecord.getSubscriptionId() == subId) {
1132 isValid = true;
1133 break;
1134 }
Wink Saville08874612014-08-31 19:19:58 -07001135 }
1136 }
1137 if (isValid == false) {
1138 return;
1139 }
1140
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001141 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001142 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001143 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1144 mApp.startActivity(intent);
1145 }
1146
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001147 /**
1148 * End a call based on call state
1149 * @return true is a call was ended
1150 */
1151 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001152 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001153 }
1154
1155 /**
1156 * End a call based on the call state of the subId
1157 * @return true is a call was ended
1158 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001159 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001160 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001161 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001162 }
1163
1164 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001165 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001166 }
1167
Wink Savilleb564aae2014-10-23 10:18:09 -07001168 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001169 if (DBG) log("answerRingingCall...");
1170 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1171 // but that can probably wait till the big TelephonyManager API overhaul.
1172 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1173 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001174 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001175 }
1176
1177 /**
1178 * Make the actual telephony calls to implement answerRingingCall().
1179 * This should only be called from the main thread of the Phone app.
1180 * @see #answerRingingCall
1181 *
1182 * TODO: it would be nice to return true if we answered the call, or
1183 * false if there wasn't actually a ringing incoming call, or some
1184 * other error occurred. (In other words, pass back the return value
1185 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1186 * But that would require calling this method via sendRequest() rather
1187 * than sendRequestAsync(), and right now we don't actually *need* that
1188 * return value, so let's just return void for now.
1189 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001190 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001191 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001193 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1194 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 if (hasActiveCall && hasHoldingCall) {
1196 // Both lines are in use!
1197 // TODO: provide a flag to let the caller specify what
1198 // policy to use if both lines are in use. (The current
1199 // behavior is hardwired to "answer incoming, end ongoing",
1200 // which is how the CALL button is specced to behave.)
1201 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1202 return;
1203 } else {
1204 // answerCall() will automatically hold the current active
1205 // call, if there is one.
1206 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1207 return;
1208 }
1209 } else {
1210 // No call was ringing.
1211 return;
1212 }
1213 }
1214
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001215 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001216 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001217 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001218 public void silenceRinger() {
1219 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001220 }
1221
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001222 @Override
1223 public boolean isOffhook(String callingPackage) {
1224 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001225 }
1226
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001227 @Override
1228 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1229 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1230 return false;
1231 }
1232
Sanket Padawe356d7632015-06-22 14:03:32 -07001233 final Phone phone = getPhone(subId);
1234 if (phone != null) {
1235 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1236 } else {
1237 return false;
1238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001239 }
1240
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001241 @Override
1242 public boolean isRinging(String callingPackage) {
1243 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001244 }
1245
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001246 @Override
1247 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1248 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1249 return false;
1250 }
1251
Sanket Padawe356d7632015-06-22 14:03:32 -07001252 final Phone phone = getPhone(subId);
1253 if (phone != null) {
1254 return (phone.getState() == PhoneConstants.State.RINGING);
1255 } else {
1256 return false;
1257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 }
1259
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001260 @Override
1261 public boolean isIdle(String callingPackage) {
1262 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001263 }
1264
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001265 @Override
1266 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1267 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1268 return false;
1269 }
1270
Sanket Padawe356d7632015-06-22 14:03:32 -07001271 final Phone phone = getPhone(subId);
1272 if (phone != null) {
1273 return (phone.getState() == PhoneConstants.State.IDLE);
1274 } else {
1275 return false;
1276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 }
1278
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001279 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001280 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001281 }
1282
Wink Savilleb564aae2014-10-23 10:18:09 -07001283 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001284 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001285 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1286 }
1287
1288 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001289 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001290 }
1291
Wink Savilleb564aae2014-10-23 10:18:09 -07001292 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001293 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001294 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1295 }
1296
1297 /** {@hide} */
1298 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001299 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001300 }
1301
Wink Savilleb564aae2014-10-23 10:18:09 -07001302 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001303 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001304 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305 checkSimPin.start();
1306 return checkSimPin.unlockSim(null, pin);
1307 }
1308
Wink Saville9de0f752013-10-22 19:04:03 -07001309 /** {@hide} */
1310 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001311 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001312 }
1313
Wink Savilleb564aae2014-10-23 10:18:09 -07001314 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001316 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 checkSimPuk.start();
1318 return checkSimPuk.unlockSim(puk, pin);
1319 }
1320
1321 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001322 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001323 * a synchronous one.
1324 */
1325 private static class UnlockSim extends Thread {
1326
1327 private final IccCard mSimCard;
1328
1329 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001330 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1331 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001332
1333 // For replies from SimCard interface
1334 private Handler mHandler;
1335
1336 // For async handler to identify request type
1337 private static final int SUPPLY_PIN_COMPLETE = 100;
1338
1339 public UnlockSim(IccCard simCard) {
1340 mSimCard = simCard;
1341 }
1342
1343 @Override
1344 public void run() {
1345 Looper.prepare();
1346 synchronized (UnlockSim.this) {
1347 mHandler = new Handler() {
1348 @Override
1349 public void handleMessage(Message msg) {
1350 AsyncResult ar = (AsyncResult) msg.obj;
1351 switch (msg.what) {
1352 case SUPPLY_PIN_COMPLETE:
1353 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1354 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001355 mRetryCount = msg.arg1;
1356 if (ar.exception != null) {
1357 if (ar.exception instanceof CommandException &&
1358 ((CommandException)(ar.exception)).getCommandError()
1359 == CommandException.Error.PASSWORD_INCORRECT) {
1360 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1361 } else {
1362 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1363 }
1364 } else {
1365 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001367 mDone = true;
1368 UnlockSim.this.notifyAll();
1369 }
1370 break;
1371 }
1372 }
1373 };
1374 UnlockSim.this.notifyAll();
1375 }
1376 Looper.loop();
1377 }
1378
1379 /*
1380 * Use PIN or PUK to unlock SIM card
1381 *
1382 * If PUK is null, unlock SIM card with PIN
1383 *
1384 * If PUK is not null, unlock SIM card with PUK and set PIN code
1385 */
Wink Saville9de0f752013-10-22 19:04:03 -07001386 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001387
1388 while (mHandler == null) {
1389 try {
1390 wait();
1391 } catch (InterruptedException e) {
1392 Thread.currentThread().interrupt();
1393 }
1394 }
1395 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1396
1397 if (puk == null) {
1398 mSimCard.supplyPin(pin, callback);
1399 } else {
1400 mSimCard.supplyPuk(puk, pin, callback);
1401 }
1402
1403 while (!mDone) {
1404 try {
1405 Log.d(LOG_TAG, "wait for done");
1406 wait();
1407 } catch (InterruptedException e) {
1408 // Restore the interrupted status
1409 Thread.currentThread().interrupt();
1410 }
1411 }
1412 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001413 int[] resultArray = new int[2];
1414 resultArray[0] = mResult;
1415 resultArray[1] = mRetryCount;
1416 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001417 }
1418 }
1419
1420 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001421 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001422
1423 }
1424
Wink Savilleb564aae2014-10-23 10:18:09 -07001425 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426 // No permission check needed here: this call is harmless, and it's
1427 // needed for the ServiceState.requestStateUpdate() call (which is
1428 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001429 final Phone phone = getPhone(subId);
1430 if (phone != null) {
1431 phone.updateServiceLocation();
1432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001433 }
1434
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001435 @Override
1436 public boolean isRadioOn(String callingPackage) {
1437 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001438 }
1439
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001440 @Override
1441 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1442 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1443 return false;
1444 }
1445 return isRadioOnForSubscriber(subId);
1446 }
1447
1448 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001449 final Phone phone = getPhone(subId);
1450 if (phone != null) {
1451 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1452 } else {
1453 return false;
1454 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001455 }
1456
1457 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001458 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001459
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 }
Wink Saville36469e72014-06-11 15:17:00 -07001461
Wink Savilleb564aae2014-10-23 10:18:09 -07001462 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001463 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001464 final Phone phone = getPhone(subId);
1465 if (phone != null) {
1466 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1467 }
Wink Saville36469e72014-06-11 15:17:00 -07001468 }
1469
1470 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001471 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001472 }
1473
Wink Savilleb564aae2014-10-23 10:18:09 -07001474 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001475 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001476 final Phone phone = getPhone(subId);
1477 if (phone == null) {
1478 return false;
1479 }
1480 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001481 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001482 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484 return true;
1485 }
Wink Saville36469e72014-06-11 15:17:00 -07001486
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001487 public boolean needMobileRadioShutdown() {
1488 /*
1489 * If any of the Radios are available, it will need to be
1490 * shutdown. So return true if any Radio is available.
1491 */
1492 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1493 Phone phone = PhoneFactory.getPhone(i);
1494 if (phone != null && phone.isRadioAvailable()) return true;
1495 }
1496 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1497 return false;
1498 }
1499
1500 public void shutdownMobileRadios() {
1501 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1502 logv("Shutting down Phone " + i);
1503 shutdownRadioUsingPhoneId(i);
1504 }
1505 }
1506
1507 private void shutdownRadioUsingPhoneId(int phoneId) {
1508 enforceModifyPermission();
1509 Phone phone = PhoneFactory.getPhone(phoneId);
1510 if (phone != null && phone.isRadioAvailable()) {
1511 phone.shutdownRadio();
1512 }
1513 }
1514
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001515 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001516 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001517 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1518 if (defaultPhone != null) {
1519 defaultPhone.setRadioPower(turnOn);
1520 return true;
1521 } else {
1522 loge("There's no default phone.");
1523 return false;
1524 }
Wink Saville36469e72014-06-11 15:17:00 -07001525 }
1526
Wink Savilleb564aae2014-10-23 10:18:09 -07001527 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001529 final Phone phone = getPhone(subId);
1530 if (phone != null) {
1531 phone.setRadioPower(turnOn);
1532 return true;
1533 } else {
1534 return false;
1535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 }
1537
Wink Saville36469e72014-06-11 15:17:00 -07001538 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001539 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001540 public boolean enableDataConnectivity() {
1541 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001542 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001543 final Phone phone = getPhone(subId);
1544 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001545 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001546 return true;
1547 } else {
1548 return false;
1549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001550 }
1551
Wink Saville36469e72014-06-11 15:17:00 -07001552 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001553 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 public boolean disableDataConnectivity() {
1555 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001556 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001557 final Phone phone = getPhone(subId);
1558 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001559 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001560 return true;
1561 } else {
1562 return false;
1563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
1565
Sanket Padawe356d7632015-06-22 14:03:32 -07001566 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001567 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001568 final Phone phone = getPhone(subId);
1569 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001570 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001571 } else {
1572 return false;
1573 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 }
1575
1576 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001577 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001578 }
1579
pkanwarae03a6b2016-11-06 20:37:09 -08001580 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001581 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001582 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1583 return;
1584 }
1585 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1586 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1587 };
1588
Wink Savilleb564aae2014-10-23 10:18:09 -07001589 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001591 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1592 return false;
1593 }
Wink Saville36469e72014-06-11 15:17:00 -07001594 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 }
1596
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001598 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001599 }
1600
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001601 public int getCallStateForSlot(int slotIndex) {
1602 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001603 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001604 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 }
1606
Sanket Padawe356d7632015-06-22 14:03:32 -07001607 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001609 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001610 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001611 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001612 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001613 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 }
1616
Sanket Padawe356d7632015-06-22 14:03:32 -07001617 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001619 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001620 if (phone != null) {
1621 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1622 } else {
1623 return TelephonyManager.DATA_ACTIVITY_NONE;
1624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 }
1626
1627 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001628 public Bundle getCellLocation(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001629 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001630 callingPackage, Binder.getCallingUid(), "getCellLocation")) {
Svetoslav64fad262015-04-14 14:35:21 -07001631 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001632 }
1633
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001634 if (DBG_LOC) log("getCellLocation: is active user");
1635 Bundle data = new Bundle();
1636 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1637 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 return null;
1639 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001640
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001641 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1642 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1643 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001644 }
1645
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001647 public String getNetworkCountryIsoForPhone(int phoneId) {
1648 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1649 // registered cell info, so return a NULL country instead.
1650 final long identity = Binder.clearCallingIdentity();
1651 try {
1652 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1653 if (TelephonyManager.NETWORK_TYPE_IWLAN
1654 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1655 return "";
1656 }
1657 } finally {
1658 Binder.restoreCallingIdentity(identity);
1659 }
1660 return TelephonyManager.getTelephonyProperty(
1661 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1662 }
1663
1664 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001666 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001667 }
1668
Sanket Padawe356d7632015-06-22 14:03:32 -07001669 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001670 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 mApp.enforceCallingOrSelfPermission(
1672 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001673 final Phone phone = getPhone(subId);
1674 if (phone != null) {
1675 phone.enableLocationUpdates();
1676 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001677 }
1678
1679 @Override
1680 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001681 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001682 }
1683
Sanket Padawe356d7632015-06-22 14:03:32 -07001684 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001685 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 mApp.enforceCallingOrSelfPermission(
1687 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001688 final Phone phone = getPhone(subId);
1689 if (phone != null) {
1690 phone.disableLocationUpdates();
1691 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 }
1693
1694 @Override
1695 @SuppressWarnings("unchecked")
1696 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001697 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001698 callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001699 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001700 }
1701
1702 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1703 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1704 return null;
1705 }
Svetoslav64fad262015-04-14 14:35:21 -07001706
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001707 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001709 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001711 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1712 try {
1713 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1714 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1715 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1716 } catch (RuntimeException e) {
1717 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001719 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 }
1721
1722
1723 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001724 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001725 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganove4ae9412017-09-28 12:45:30 -07001726 callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001727 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 }
1729
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001730 if (DBG_LOC) log("getAllCellInfo: is active user");
1731 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1732 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1733 for (Phone phone : PhoneFactory.getPhones()) {
1734 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1735 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001737 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
1739
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001740 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001742 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001743 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1744 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
1746
Shishir Agrawala9f32182016-04-12 12:00:16 -07001747 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001748 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001749 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1750 return null;
1751 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001752 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001753 return phone == null ? null : phone.getImei();
1754 }
1755
1756 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001757 public String getMeidForSlot(int slotIndex, String callingPackage) {
1758 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1759 return null;
1760 }
1761 Phone phone = PhoneFactory.getPhone(slotIndex);
1762 return phone == null ? null : phone.getMeid();
1763 }
1764
1765 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001766 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001767 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1768 return null;
1769 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001770 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001771 return phone == null ? null : phone.getDeviceSvn();
1772 }
1773
fionaxu43304da2017-11-27 22:51:16 -08001774 @Override
1775 public int getSubscriptionCarrierId(int subId) {
1776 final Phone phone = getPhone(subId);
1777 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1778 }
1779
1780 @Override
1781 public String getSubscriptionCarrierName(int subId) {
1782 final Phone phone = getPhone(subId);
1783 return phone == null ? null : phone.getCarrierName();
1784 }
1785
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 //
1787 // Internal helper methods.
1788 //
1789
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001790 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1792 *
1793 * @throws SecurityException if the caller does not have the required permission
1794 */
1795 private void enforceModifyPermission() {
1796 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1797 }
1798
1799 /**
Junda Liua2e36012014-07-09 18:30:01 -07001800 * Make sure either system app or the caller has carrier privilege.
1801 *
1802 * @throws SecurityException if the caller does not have the required permission/privilege
1803 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001804 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001805 int permission = mApp.checkCallingOrSelfPermission(
1806 android.Manifest.permission.MODIFY_PHONE_STATE);
1807 if (permission == PackageManager.PERMISSION_GRANTED) {
1808 return;
1809 }
1810
1811 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001812 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001813 }
1814
1815 /**
1816 * Make sure the caller has carrier privilege.
1817 *
1818 * @throws SecurityException if the caller does not have the required permission
1819 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001820 private void enforceCarrierPrivilege(int subId) {
1821 if (getCarrierPrivilegeStatus(subId) !=
1822 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001823 loge("No Carrier Privilege.");
1824 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001825 }
1826 }
1827
1828 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 * Make sure the caller has the CALL_PHONE permission.
1830 *
1831 * @throws SecurityException if the caller does not have the required permission
1832 */
1833 private void enforceCallPermission() {
1834 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1835 }
1836
Stuart Scott8eef64f2015-04-08 15:13:54 -07001837 private void enforceConnectivityInternalPermission() {
1838 mApp.enforceCallingOrSelfPermission(
1839 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1840 "ConnectivityService");
1841 }
1842
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 private String createTelUrl(String number) {
1844 if (TextUtils.isEmpty(number)) {
1845 return null;
1846 }
1847
Jake Hambye994d462014-02-03 13:10:13 -08001848 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 }
1850
Ihab Awadf9e92732013-12-05 18:02:52 -08001851 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001852 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1853 }
1854
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001855 private static void logv(String msg) {
1856 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1857 }
1858
Ihab Awadf9e92732013-12-05 18:02:52 -08001859 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1861 }
1862
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001863 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001864 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001865 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001866 }
1867
Sanket Padawe356d7632015-06-22 14:03:32 -07001868 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001869 public int getActivePhoneTypeForSlot(int slotIndex) {
1870 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001871 if (phone == null) {
1872 return PhoneConstants.PHONE_TYPE_NONE;
1873 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001874 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 }
1877
1878 /**
1879 * Returns the CDMA ERI icon index to display
1880 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001881 @Override
1882 public int getCdmaEriIconIndex(String callingPackage) {
1883 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001884 }
1885
Sanket Padawe356d7632015-06-22 14:03:32 -07001886 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001887 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1888 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1889 return -1;
1890 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001891 final Phone phone = getPhone(subId);
1892 if (phone != null) {
1893 return phone.getCdmaEriIconIndex();
1894 } else {
1895 return -1;
1896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 }
1898
1899 /**
1900 * Returns the CDMA ERI icon mode,
1901 * 0 - ON
1902 * 1 - FLASHING
1903 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001904 @Override
1905 public int getCdmaEriIconMode(String callingPackage) {
1906 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001907 }
1908
Sanket Padawe356d7632015-06-22 14:03:32 -07001909 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001910 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1911 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1912 return -1;
1913 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 final Phone phone = getPhone(subId);
1915 if (phone != null) {
1916 return phone.getCdmaEriIconMode();
1917 } else {
1918 return -1;
1919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 }
1921
1922 /**
1923 * Returns the CDMA ERI text,
1924 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001925 @Override
1926 public String getCdmaEriText(String callingPackage) {
1927 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001928 }
1929
Sanket Padawe356d7632015-06-22 14:03:32 -07001930 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001931 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1932 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1933 return null;
1934 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001935 final Phone phone = getPhone(subId);
1936 if (phone != null) {
1937 return phone.getCdmaEriText();
1938 } else {
1939 return null;
1940 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
1942
1943 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001944 * Returns the CDMA MDN.
1945 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001946 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001947 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001948 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001949 final Phone phone = getPhone(subId);
1950 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1951 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001952 } else {
1953 return null;
1954 }
1955 }
1956
1957 /**
1958 * Returns the CDMA MIN.
1959 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001960 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001961 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001962 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001963 final Phone phone = getPhone(subId);
1964 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1965 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001966 } else {
1967 return null;
1968 }
1969 }
1970
1971 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001972 * Returns true if CDMA provisioning needs to run.
1973 */
1974 public boolean needsOtaServiceProvisioning() {
1975 return mPhone.needsOtaServiceProvisioning();
1976 }
1977
1978 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001979 * Sets the voice mail number of a given subId.
1980 */
1981 @Override
1982 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001983 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001984 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1985 new Pair<String, String>(alphaTag, number), new Integer(subId));
1986 return success;
1987 }
1988
Ta-wei Yen87c49842016-05-13 21:19:52 -07001989 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07001990 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
1991 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
1992 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
1993 if (!TextUtils.equals(callingPackage, systemDialer)) {
1994 throw new SecurityException("caller must be system dialer");
1995 }
1996 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
1997 if (phoneAccountHandle == null){
1998 return null;
1999 }
2000 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2001 }
2002
2003 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002004 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002005 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2006 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2007 return null;
2008 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002009 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2010 }
2011
2012 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002013 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2014 VisualVoicemailSmsFilterSettings settings) {
2015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002016 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002017 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2018 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002019 }
2020
2021 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002022 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2023 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002024 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002025 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002026 }
2027
2028 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002029 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2030 String callingPackage, int subId) {
2031 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002032 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002033 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002034 }
2035
2036 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002037 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002038 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002039 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002040 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2041 }
2042
2043 @Override
2044 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2045 String number, int port, String text, PendingIntent sentIntent) {
2046 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002047 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002048 enforceSendSmsPermission();
2049 // Make the calls as the phone process.
2050 final long identity = Binder.clearCallingIdentity();
2051 try {
2052 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2053 if (port == 0) {
2054 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2055 sentIntent, null, false);
2056 } else {
2057 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2058 smsManager.sendDataMessageWithSelfPermissions(number, null,
2059 (short) port, data, sentIntent, null);
2060 }
2061 } finally {
2062 Binder.restoreCallingIdentity(identity);
2063 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002064 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002065 /**
fionaxu0152e512016-11-14 13:36:14 -08002066 * Sets the voice activation state of a given subId.
2067 */
2068 @Override
2069 public void setVoiceActivationState(int subId, int activationState) {
2070 enforceModifyPermissionOrCarrierPrivilege(subId);
2071 final Phone phone = getPhone(subId);
2072 if (phone != null) {
2073 phone.setVoiceActivationState(activationState);
2074 } else {
2075 loge("setVoiceActivationState fails with invalid subId: " + subId);
2076 }
2077 }
2078
2079 /**
2080 * Sets the data activation state of a given subId.
2081 */
2082 @Override
2083 public void setDataActivationState(int subId, int activationState) {
2084 enforceModifyPermissionOrCarrierPrivilege(subId);
2085 final Phone phone = getPhone(subId);
2086 if (phone != null) {
2087 phone.setDataActivationState(activationState);
2088 } else {
2089 loge("setVoiceActivationState fails with invalid subId: " + subId);
2090 }
2091 }
2092
2093 /**
2094 * Returns the voice activation state of a given subId.
2095 */
2096 @Override
2097 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002098 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002099 final Phone phone = getPhone(subId);
2100 if (phone != null) {
2101 return phone.getVoiceActivationState();
2102 } else {
2103 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2104 }
2105 }
2106
2107 /**
2108 * Returns the data activation state of a given subId.
2109 */
2110 @Override
2111 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002112 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002113 final Phone phone = getPhone(subId);
2114 if (phone != null) {
2115 return phone.getDataActivationState();
2116 } else {
2117 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2118 }
2119 }
2120
2121 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002122 * Returns the unread count of voicemails
2123 */
2124 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002125 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002126 }
2127
2128 /**
2129 * Returns the unread count of voicemails for a subId
2130 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002131 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002132 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002133 final Phone phone = getPhone(subId);
2134 if (phone != null) {
2135 return phone.getVoiceMessageCount();
2136 } else {
2137 return 0;
2138 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002139 }
2140
2141 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002142 * returns true, if the device is in a state where both voice and data
2143 * are supported simultaneously. This can change based on location or network condition.
2144 */
2145 @Override
2146 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2147 final Phone phone = getPhone(subId);
2148 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2149 }
2150
2151 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002152 * Send the dialer code if called from the current default dialer or the caller has
2153 * carrier privilege.
2154 * @param inputCode The dialer code to send
2155 */
2156 @Override
2157 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2158 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2159 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2160 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2161 enforceCarrierPrivilege(getDefaultSubscription());
2162 }
2163 mPhone.sendDialerSpecialCode(inputCode);
2164 }
2165
2166 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002167 * Returns the data network type.
2168 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 *
2170 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2171 */
2172 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002173 public int getNetworkType() {
2174 final Phone phone = getPhone(getDefaultSubscription());
2175 if (phone != null) {
2176 return phone.getServiceState().getDataNetworkType();
2177 } else {
2178 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2179 }
Wink Saville36469e72014-06-11 15:17:00 -07002180 }
2181
2182 /**
2183 * Returns the network type for a subId
2184 */
2185 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002186 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2187 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2188 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2189 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002190
Sanket Padawe356d7632015-06-22 14:03:32 -07002191 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002192 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002193 return phone.getServiceState().getDataNetworkType();
2194 } else {
2195 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 }
2198
2199 /**
2200 * Returns the data network type
2201 */
2202 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002203 public int getDataNetworkType(String callingPackage) {
2204 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002205 }
2206
2207 /**
2208 * Returns the data network type for a subId
2209 */
2210 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002211 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2212 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2213 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2214 }
2215
Sanket Padawe356d7632015-06-22 14:03:32 -07002216 final Phone phone = getPhone(subId);
2217 if (phone != null) {
2218 return phone.getServiceState().getDataNetworkType();
2219 } else {
2220 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2221 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002222 }
2223
2224 /**
Wink Saville36469e72014-06-11 15:17:00 -07002225 * Returns the Voice network type for a subId
2226 */
2227 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002228 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2229 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2230 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2231 }
2232
Sanket Padawe356d7632015-06-22 14:03:32 -07002233 final Phone phone = getPhone(subId);
2234 if (phone != null) {
2235 return phone.getServiceState().getVoiceNetworkType();
2236 } else {
2237 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 }
2240
2241 /**
2242 * @return true if a ICC card is present
2243 */
2244 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002245 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002246 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2247 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002248 }
2249
2250 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002251 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002252 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002253 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002254 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2255 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002256 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002257 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002258 } else {
2259 return false;
2260 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 }
2262
2263 /**
2264 * Return if the current radio is LTE on CDMA. This
2265 * is a tri-state return value as for a period of time
2266 * the mode may be unknown.
2267 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002268 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002269 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002270 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002272 @Override
2273 public int getLteOnCdmaMode(String callingPackage) {
2274 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002275 }
2276
Sanket Padawe356d7632015-06-22 14:03:32 -07002277 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002278 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2279 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2280 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2281 }
2282
Sanket Padawe356d7632015-06-22 14:03:32 -07002283 final Phone phone = getPhone(subId);
2284 if (phone == null) {
2285 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2286 } else {
2287 return phone.getLteOnCdmaMode();
2288 }
Wink Saville36469e72014-06-11 15:17:00 -07002289 }
2290
2291 public void setPhone(Phone phone) {
2292 mPhone = phone;
2293 }
2294
2295 /**
2296 * {@hide}
2297 * Returns Default subId, 0 in the case of single standby.
2298 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002299 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002300 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002301 }
2302
Shishir Agrawala9f32182016-04-12 12:00:16 -07002303 private int getSlotForDefaultSubscription() {
2304 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2305 }
2306
Wink Savilleb564aae2014-10-23 10:18:09 -07002307 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002308 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002310
2311 /**
2312 * @see android.telephony.TelephonyManager.WifiCallingChoices
2313 */
2314 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002315 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2316 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002317 }
2318
2319 /**
2320 * @see android.telephony.TelephonyManager.WifiCallingChoices
2321 */
2322 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002323 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2324 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2325 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002326 }
2327
Sailesh Nepald1e68152013-12-12 19:08:02 -08002328 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002329 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002330 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002331 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002332
Shishir Agrawal566b7612013-10-28 14:41:00 -07002333 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002334 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2335 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002336 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002337
Derek Tan740e1672017-06-27 14:56:27 -07002338 if (TextUtils.equals(ISDR_AID, aid)) {
2339 // Only allows LPA to open logical channel to ISD-R.
2340 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2341 ComponentInfo bestComponent =
2342 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2343 if (bestComponent == null
2344 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2345 loge("The calling package is not allowed to access ISD-R.");
2346 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2347 }
2348 }
2349
2350 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002351 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002352 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002353 if (DBG) log("iccOpenLogicalChannel: " + response);
2354 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002355 }
2356
2357 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002358 public boolean iccCloseLogicalChannel(int subId, int channel) {
2359 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002360
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002361 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002362 if (channel < 0) {
2363 return false;
2364 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002365 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002366 if (DBG) log("iccCloseLogicalChannel: " + success);
2367 return success;
2368 }
2369
2370 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002371 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002372 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002373 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002374
2375 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002376 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2377 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002378 " data=" + data);
2379 }
2380
2381 if (channel < 0) {
2382 return "";
2383 }
2384
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002385 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002386 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002387 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2388
Shishir Agrawal566b7612013-10-28 14:41:00 -07002389 // Append the returned status code to the end of the response payload.
2390 String s = Integer.toHexString(
2391 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002392 if (response.payload != null) {
2393 s = IccUtils.bytesToHexString(response.payload) + s;
2394 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002395 return s;
2396 }
Jake Hambye994d462014-02-03 13:10:13 -08002397
Evan Charltonc66da362014-05-16 14:06:40 -07002398 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002399 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002400 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002401 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002402
2403 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002404 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2405 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002406 }
2407
2408 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002409 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002410 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2411
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002412 // Append the returned status code to the end of the response payload.
2413 String s = Integer.toHexString(
2414 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002415 if (response.payload != null) {
2416 s = IccUtils.bytesToHexString(response.payload) + s;
2417 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002418 return s;
2419 }
2420
2421 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002422 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002423 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002424 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002425
2426 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002427 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002428 p1 + " " + p2 + " " + p3 + ":" + filePath);
2429 }
2430
2431 IccIoResult response =
2432 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002433 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2434 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002435
2436 if (DBG) {
2437 log("Exchange SIM_IO [R]" + response);
2438 }
2439
2440 byte[] result = null;
2441 int length = 2;
2442 if (response.payload != null) {
2443 length = 2 + response.payload.length;
2444 result = new byte[length];
2445 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2446 } else {
2447 result = new byte[length];
2448 }
2449
2450 result[length - 1] = (byte) response.sw2;
2451 result[length - 2] = (byte) response.sw1;
2452 return result;
2453 }
2454
Nathan Haroldb3014052017-01-25 15:57:32 -08002455 /**
2456 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2457 * on a particular subscription
2458 */
2459 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002460 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2461 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002462 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2463 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2464 return null;
2465 }
2466 Object response = sendRequest(
2467 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2468 if (response instanceof String[]) {
2469 return (String[]) response;
2470 }
2471 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2472 return null;
2473 }
2474
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002475 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002476 public String sendEnvelopeWithStatus(int subId, String content) {
2477 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002478
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002479 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002480 if (response.payload == null) {
2481 return "";
2482 }
2483
2484 // Append the returned status code to the end of the response payload.
2485 String s = Integer.toHexString(
2486 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2487 s = IccUtils.bytesToHexString(response.payload) + s;
2488 return s;
2489 }
2490
Jake Hambye994d462014-02-03 13:10:13 -08002491 /**
2492 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2493 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2494 *
2495 * @param itemID the ID of the item to read
2496 * @return the NV item as a String, or null on error.
2497 */
2498 @Override
2499 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002500 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002501 if (DBG) log("nvReadItem: item " + itemID);
2502 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2503 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2504 return value;
2505 }
2506
2507 /**
2508 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2509 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2510 *
2511 * @param itemID the ID of the item to read
2512 * @param itemValue the value to write, as a String
2513 * @return true on success; false on any failure
2514 */
2515 @Override
2516 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002517 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002518 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2519 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2520 new Pair<Integer, String>(itemID, itemValue));
2521 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2522 return success;
2523 }
2524
2525 /**
2526 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2527 * Used for device configuration by some CDMA operators.
2528 *
2529 * @param preferredRoamingList byte array containing the new PRL
2530 * @return true on success; false on any failure
2531 */
2532 @Override
2533 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002534 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002535 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2536 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2537 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2538 return success;
2539 }
2540
2541 /**
2542 * Perform the specified type of NV config reset.
2543 * Used for device configuration by some CDMA operators.
2544 *
2545 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2546 * @return true on success; false on any failure
2547 */
2548 @Override
2549 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002550 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002551 if (DBG) log("nvResetConfig: type " + resetType);
2552 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2553 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2554 return success;
2555 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002556
2557 /**
Wink Saville36469e72014-06-11 15:17:00 -07002558 * {@hide}
2559 * Returns Default sim, 0 in the case of single standby.
2560 */
2561 public int getDefaultSim() {
2562 //TODO Need to get it from Telephony Devcontroller
2563 return 0;
2564 }
2565
Svet Ganovb320e182015-04-16 12:30:10 -07002566 public String[] getPcscfAddress(String apnType, String callingPackage) {
2567 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2568 return new String[0];
2569 }
2570
2571
ram87fca6f2014-07-18 18:58:44 +05302572 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002573 }
2574
Brad Ebinger51f743a2017-01-23 13:50:20 -08002575 /**
Brad Ebinger34bef922017-11-09 10:27:08 -08002576 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2577 * feature or {@link null} if the service is not available. If the feature is available, the
2578 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002579 */
Brad Ebinger34bef922017-11-09 10:27:08 -08002580 public IImsMMTelFeature getMMTelFeatureAndListen(int slotId,
2581 IImsServiceFeatureCallback callback) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002582 enforceModifyPermission();
Brad Ebinger34bef922017-11-09 10:27:08 -08002583 return PhoneFactory.getImsResolver().getMMTelFeatureAndListen(slotId, callback);
2584 }
2585
2586 /**
2587 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2588 * feature during emergency calling or {@link null} if the service is not available. If the
2589 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2590 * listener for feature updates.
2591 */
2592 public IImsMMTelFeature getEmergencyMMTelFeatureAndListen(int slotId,
2593 IImsServiceFeatureCallback callback) {
2594 enforceModifyPermission();
2595 return PhoneFactory.getImsResolver().getEmergencyMMTelFeatureAndListen(slotId, callback);
2596 }
2597
2598 /**
2599 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2600 * feature during emergency calling or {@link null} if the service is not available. If the
2601 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2602 * listener for feature updates.
2603 */
2604 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2605 enforceModifyPermission();
2606 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002607 }
2608
Brad Ebinger5f64b052017-12-14 14:26:15 -08002609 /**
2610 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2611 * specified.
2612 */
2613 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2614 enforceModifyPermission();
2615 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2616 }
2617
Wink Saville36469e72014-06-11 15:17:00 -07002618 public void setImsRegistrationState(boolean registered) {
2619 enforceModifyPermission();
2620 mPhone.setImsRegistrationState(registered);
2621 }
2622
2623 /**
Stuart Scott54788802015-03-30 13:18:01 -07002624 * Set the network selection mode to automatic.
2625 *
2626 */
2627 @Override
2628 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002629 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002630 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2631 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2632 }
2633
2634 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002635 * Set the network selection mode to manual with the selected carrier.
2636 */
2637 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002638 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002639 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002640 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002641 OperatorInfo operator = new OperatorInfo(
2642 /* operatorAlphaLong */ "",
2643 /* operatorAlphaShort */ "",
2644 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002645 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002646 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2647 persistSelection);
2648 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002649 }
2650
2651 /**
2652 * Scans for available networks.
2653 */
2654 @Override
2655 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002656 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002657 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2658 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2659 CMD_PERFORM_NETWORK_SCAN, null, subId);
2660 return result;
2661 }
2662
2663 /**
yinxub1bed742017-04-17 11:45:04 -07002664 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002665 *
yinxub1bed742017-04-17 11:45:04 -07002666 * @param subId id of the subscription
2667 * @param request contains the radio access networks with bands/channels to scan
2668 * @param messenger callback messenger for scan results or errors
2669 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002670 * @return the id of the requested scan which can be used to stop the scan.
2671 */
2672 @Override
2673 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2674 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002675 enforceModifyPermissionOrCarrierPrivilege(subId);
2676 return mNetworkScanRequestTracker.startNetworkScan(
2677 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002678 }
2679
2680 /**
2681 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002682 *
2683 * @param subId id of the subscription
2684 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002685 */
2686 @Override
2687 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002688 enforceModifyPermissionOrCarrierPrivilege(subId);
2689 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002690 }
2691
2692 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002693 * Get the calculated preferred network type.
2694 * Used for debugging incorrect network type.
2695 *
2696 * @return the preferred network type, defined in RILConstants.java.
2697 */
2698 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002699 public int getCalculatedPreferredNetworkType(String callingPackage) {
2700 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2701 return RILConstants.PREFERRED_NETWORK_MODE;
2702 }
2703
Amit Mahajan43330e02014-11-18 11:54:45 -08002704 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002705 }
2706
2707 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002708 * Get the preferred network type.
2709 * Used for device configuration by some CDMA operators.
2710 *
2711 * @return the preferred network type, defined in RILConstants.java.
2712 */
2713 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002714 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002715 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002716 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002717 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002718 int networkType = (result != null ? result[0] : -1);
2719 if (DBG) log("getPreferredNetworkType: " + networkType);
2720 return networkType;
2721 }
2722
2723 /**
2724 * Set the preferred network type.
2725 * Used for device configuration by some CDMA operators.
2726 *
2727 * @param networkType the preferred network type, defined in RILConstants.java.
2728 * @return true on success; false on any failure.
2729 */
2730 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002731 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002732 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002733 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2734 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002735 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002736 if (success) {
2737 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002738 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002739 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002740 return success;
2741 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002742
2743 /**
Junda Liu475951f2014-11-07 16:45:03 -08002744 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2745 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2746 * tethering.
2747 *
2748 * @return 0: Not required. 1: required. 2: Not set.
2749 * @hide
2750 */
2751 @Override
2752 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002753 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002754 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2755 Settings.Global.TETHER_DUN_REQUIRED, 2);
2756 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2757 // config_tether_apndata.
2758 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2759 dunRequired = 1;
2760 }
2761 return dunRequired;
2762 }
2763
2764 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002765 * Set mobile data enabled
2766 * Used by the user through settings etc to turn on/off mobile data
2767 *
2768 * @param enable {@code true} turn turn data on, else {@code false}
2769 */
2770 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002771 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002772 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002773 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002774 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002775 Phone phone = PhoneFactory.getPhone(phoneId);
2776 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002777 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2778 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002779 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002780 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002781 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002782 }
2783
2784 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002785 * Get the user enabled state of Mobile Data.
2786 *
2787 * TODO: remove and use isUserDataEnabled.
2788 * This can't be removed now because some vendor codes
2789 * calls through ITelephony directly while they should
2790 * use TelephonyManager.
2791 *
2792 * @return true on enabled
2793 */
2794 @Override
2795 public boolean getDataEnabled(int subId) {
2796 return isUserDataEnabled(subId);
2797 }
2798
2799 /**
2800 * Get whether mobile data is enabled per user setting.
2801 *
2802 * There are other factors deciding whether mobile data is actually enabled, but they are
2803 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002804 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002805 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002806 *
2807 * @return {@code true} if data is enabled else {@code false}
2808 */
2809 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002810 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002811 try {
2812 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2813 null);
2814 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002815 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002816 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002817 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002818 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002819 Phone phone = PhoneFactory.getPhone(phoneId);
2820 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002821 boolean retVal = phone.isUserDataEnabled();
2822 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002823 return retVal;
2824 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002825 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2826 return false;
2827 }
2828 }
2829
2830 /**
2831 * Get whether mobile data is enabled.
2832 *
2833 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2834 * whether mobile data is actually enabled.
2835 *
2836 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2837 *
2838 * @return {@code true} if data is enabled else {@code false}
2839 */
2840 @Override
2841 public boolean isDataEnabled(int subId) {
2842 try {
2843 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2844 null);
2845 } catch (Exception e) {
2846 enforceModifyPermissionOrCarrierPrivilege(subId);
2847 }
2848 int phoneId = mSubscriptionController.getPhoneId(subId);
2849 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2850 Phone phone = PhoneFactory.getPhone(phoneId);
2851 if (phone != null) {
2852 boolean retVal = phone.isDataEnabled();
2853 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2854 return retVal;
2855 } else {
2856 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002857 return false;
2858 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002859 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002860
2861 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002862 public int getCarrierPrivilegeStatus(int subId) {
2863 final Phone phone = getPhone(subId);
2864 if (phone == null) {
2865 loge("getCarrierPrivilegeStatus: Invalid subId");
2866 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2867 }
2868 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002869 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002870 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002871 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2872 }
2873 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002874 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002875 }
Junda Liu29340342014-07-10 15:23:27 -07002876
2877 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002878 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002879 if (TextUtils.isEmpty(pkgName))
2880 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002881 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002882 if (card == null) {
2883 loge("checkCarrierPrivilegesForPackage: No UICC");
2884 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2885 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002886 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2887 }
2888
2889 @Override
2890 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002891 if (TextUtils.isEmpty(pkgName))
2892 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002893 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2894 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2895 UiccCard card = UiccController.getInstance().getUiccCard(i);
2896 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002897 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002898 continue;
2899 }
2900
2901 result = card.getCarrierPrivilegeStatus(
2902 mPhone.getContext().getPackageManager(), pkgName);
2903 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2904 break;
2905 }
2906 }
2907
2908 return result;
Junda Liu29340342014-07-10 15:23:27 -07002909 }
Derek Tan89e89d42014-07-08 17:00:10 -07002910
2911 @Override
Junda Liue64de782015-04-16 17:19:16 -07002912 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2913 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2914 loge("phoneId " + phoneId + " is not valid.");
2915 return null;
2916 }
2917 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002918 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002919 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002920 return null ;
2921 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002922 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002923 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002924 }
2925
Amith Yamasani6e118872016-02-19 12:53:51 -08002926 @Override
2927 public List<String> getPackagesWithCarrierPrivileges() {
2928 PackageManager pm = mPhone.getContext().getPackageManager();
2929 List<String> privilegedPackages = new ArrayList<>();
2930 List<PackageInfo> packages = null;
2931 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2932 UiccCard card = UiccController.getInstance().getUiccCard(i);
2933 if (card == null) {
2934 // No UICC in that slot.
2935 continue;
2936 }
2937 if (card.hasCarrierPrivilegeRules()) {
2938 if (packages == null) {
2939 // Only check packages in user 0 for now
2940 packages = pm.getInstalledPackagesAsUser(
2941 PackageManager.MATCH_DISABLED_COMPONENTS
2942 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2943 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2944 }
2945 for (int p = packages.size() - 1; p >= 0; p--) {
2946 PackageInfo pkgInfo = packages.get(p);
2947 if (pkgInfo != null && pkgInfo.packageName != null
2948 && card.getCarrierPrivilegeStatus(pkgInfo)
2949 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2950 privilegedPackages.add(pkgInfo.packageName);
2951 }
2952 }
2953 }
2954 }
2955 return privilegedPackages;
2956 }
2957
Wink Savilleb564aae2014-10-23 10:18:09 -07002958 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002959 final Phone phone = getPhone(subId);
2960 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002961 if (card == null) {
2962 loge("getIccId: No UICC");
2963 return null;
2964 }
2965 String iccId = card.getIccId();
2966 if (TextUtils.isEmpty(iccId)) {
2967 loge("getIccId: ICC ID is null or empty.");
2968 return null;
2969 }
2970 return iccId;
2971 }
2972
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002973 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08002974 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
2975 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002976 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07002977
Jeff Sharkey85190e62014-12-05 09:40:12 -08002978 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002979 final Phone phone = getPhone(subId);
2980 if (phone == null) {
2981 return false;
2982 }
2983 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08002984
2985 if (DBG_MERGE) {
2986 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
2987 + subscriberId + " to " + number);
2988 }
2989
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002990 if (TextUtils.isEmpty(iccId)) {
2991 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07002992 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002993
Jeff Sharkey85190e62014-12-05 09:40:12 -08002994 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
2995
2996 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08002997 if (alphaTag == null) {
2998 editor.remove(alphaTagPrefKey);
2999 } else {
3000 editor.putString(alphaTagPrefKey, alphaTag);
3001 }
3002
Jeff Sharkey85190e62014-12-05 09:40:12 -08003003 // Record both the line number and IMSI for this ICCID, since we need to
3004 // track all merged IMSIs based on line number
3005 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3006 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003007 if (number == null) {
3008 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003009 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003010 } else {
3011 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003012 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003013 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003014
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003015 editor.commit();
3016 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003017 }
3018
3019 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003020 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003021 // This is open to apps with WRITE_SMS.
3022 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003023 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003024 return null;
3025 }
Derek Tan97ebb422014-09-05 16:55:38 -07003026
3027 String iccId = getIccId(subId);
3028 if (iccId != null) {
3029 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003030 if (DBG_MERGE) {
3031 log("getLine1NumberForDisplay returning " +
3032 mTelephonySharedPreferences.getString(numberPrefKey, null));
3033 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003034 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003035 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003036 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003037 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003038 }
3039
3040 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003041 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3042 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3043 return null;
3044 }
Derek Tan97ebb422014-09-05 16:55:38 -07003045
3046 String iccId = getIccId(subId);
3047 if (iccId != null) {
3048 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003049 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003050 }
Derek Tan97ebb422014-09-05 16:55:38 -07003051 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003052 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003053
3054 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003055 public String[] getMergedSubscriberIds(String callingPackage) {
3056 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3057 return null;
3058 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003059 final Context context = mPhone.getContext();
3060 final TelephonyManager tele = TelephonyManager.from(context);
3061 final SubscriptionManager sub = SubscriptionManager.from(context);
3062
3063 // Figure out what subscribers are currently active
3064 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003065 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3066 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3067 final long identity = Binder.clearCallingIdentity();
3068 try {
3069 final int[] subIds = sub.getActiveSubscriptionIdList();
3070 for (int subId : subIds) {
3071 activeSubscriberIds.add(tele.getSubscriberId(subId));
3072 }
3073 } finally {
3074 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003075 }
3076
3077 // First pass, find a number override for an active subscriber
3078 String mergeNumber = null;
3079 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3080 for (String key : prefs.keySet()) {
3081 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3082 final String subscriberId = (String) prefs.get(key);
3083 if (activeSubscriberIds.contains(subscriberId)) {
3084 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3085 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3086 mergeNumber = (String) prefs.get(numberKey);
3087 if (DBG_MERGE) {
3088 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3089 + " for active subscriber " + subscriberId);
3090 }
3091 if (!TextUtils.isEmpty(mergeNumber)) {
3092 break;
3093 }
3094 }
3095 }
3096 }
3097
3098 // Shortcut when no active merged subscribers
3099 if (TextUtils.isEmpty(mergeNumber)) {
3100 return null;
3101 }
3102
3103 // Second pass, find all subscribers under that line override
3104 final ArraySet<String> result = new ArraySet<>();
3105 for (String key : prefs.keySet()) {
3106 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3107 final String number = (String) prefs.get(key);
3108 if (mergeNumber.equals(number)) {
3109 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3110 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3111 final String subscriberId = (String) prefs.get(subscriberKey);
3112 if (!TextUtils.isEmpty(subscriberId)) {
3113 result.add(subscriberId);
3114 }
3115 }
3116 }
3117 }
3118
3119 final String[] resultArray = result.toArray(new String[result.size()]);
3120 Arrays.sort(resultArray);
3121 if (DBG_MERGE) {
3122 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3123 }
3124 return resultArray;
3125 }
3126
3127 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003128 public boolean setOperatorBrandOverride(int subId, String brand) {
3129 enforceCarrierPrivilege(subId);
3130 final Phone phone = getPhone(subId);
3131 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003132 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003133
3134 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003135 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003136 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3137 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003138 enforceCarrierPrivilege(subId);
3139 final Phone phone = getPhone(subId);
3140 if (phone == null) {
3141 return false;
3142 }
3143 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003144 cdmaNonRoamingList);
3145 }
3146
3147 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003148 public void setRadioCapability(RadioAccessFamily[] rafs) {
3149 try {
3150 ProxyController.getInstance().setRadioCapability(rafs);
3151 } catch (RuntimeException e) {
3152 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3153 }
3154 }
3155
3156 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003157 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3158 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3159 return RadioAccessFamily.RAF_UNKNOWN;
3160 }
3161
Wink Saville5d475dd2014-10-17 15:00:58 -07003162 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3163 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003164
3165 @Override
3166 public void enableVideoCalling(boolean enable) {
3167 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003168 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003169 }
3170
3171 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003172 public boolean isVideoCallingEnabled(String callingPackage) {
3173 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3174 return false;
3175 }
3176
Andrew Lee77527ac2014-10-21 16:57:39 -07003177 // Check the user preference and the system-level IMS setting. Even if the user has
3178 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3179 // In the long run, we may instead need to check if there exists a connection service
3180 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003181 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3182 return imsManager.isVtEnabledByPlatform()
3183 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3184 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003185 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003186
Andrew Leea1239f22015-03-02 17:44:07 -08003187 @Override
3188 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003189 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003190 }
3191
3192 @Override
3193 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003194 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003195 }
3196
Andrew Lee9431b832015-03-09 18:46:45 -07003197 @Override
3198 public boolean isTtyModeSupported() {
3199 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3200 TelephonyManager telephonyManager =
3201 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003202 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003203 }
3204
3205 @Override
3206 public boolean isHearingAidCompatibilitySupported() {
3207 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3208 }
3209
Sanket Padawe7310cc72015-01-14 09:53:20 -08003210 /**
3211 * Returns the unique device ID of phone, for example, the IMEI for
3212 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3213 *
3214 * <p>Requires Permission:
3215 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3216 */
3217 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003218 public String getDeviceId(String callingPackage) {
3219 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3220 return null;
3221 }
3222
Sanket Padawe7310cc72015-01-14 09:53:20 -08003223 final Phone phone = PhoneFactory.getPhone(0);
3224 if (phone != null) {
3225 return phone.getDeviceId();
3226 } else {
3227 return null;
3228 }
3229 }
3230
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003231 /*
3232 * {@hide}
3233 * Returns the IMS Registration Status
3234 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003235 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003236 public boolean isImsRegistered() {
3237 return mPhone.isImsRegistered();
3238 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003239
Ping Sunc67b7c22016-03-02 19:16:45 +08003240 /**
3241 * {@hide}
3242 * Returns the IMS Registration Status on a particular subid
3243 *
3244 * @param subId
3245 */
3246 public boolean isImsRegisteredForSubscriber(int subId) {
3247 Phone phone = getPhone(subId);
3248 if (phone != null) {
3249 return phone.isImsRegistered();
3250 } else {
3251 return false;
3252 }
3253 }
3254
Santos Cordon7a1885b2015-02-03 11:15:19 -08003255 @Override
3256 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3257 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3258 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003259
Nathan Haroldc55097a2015-03-11 18:14:50 -07003260 /*
3261 * {@hide}
3262 * Returns the IMS Registration Status
3263 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003264 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003265 return mPhone.isWifiCallingEnabled();
3266 }
3267
3268 /*
3269 * {@hide}
3270 * Returns the IMS Registration Status
3271 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003272 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003273 return mPhone.isVolteEnabled();
3274 }
Svet Ganovb320e182015-04-16 12:30:10 -07003275
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003276 /*
3277 * {@hide} Returns the IMS Registration Status
3278 */
3279 public boolean isVideoTelephonyAvailable() {
3280 return mPhone.isVideoEnabled();
3281 }
3282
Svet Ganovb320e182015-04-16 12:30:10 -07003283 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003284 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003285 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003286 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3287
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003288 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003289 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003290 } catch (SecurityException e) {
3291 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3292 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003293 }
Svet Ganovb320e182015-04-16 12:30:10 -07003294
3295 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3296 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3297 return false;
3298 }
3299
3300 return true;
3301 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003302
Makoto Onukifee69342015-06-29 14:44:50 -07003303 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003304 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003305 */
3306 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003307 // Default SMS app can always read it.
3308 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3309 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3310 return true;
3311 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003312
Makoto Onukie4072d12015-08-03 15:12:23 -07003313 try {
3314 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003315 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003316 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003317 // Can be read with READ_SMS too.
3318 try {
3319 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3320 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3321 if (opCode != AppOpsManager.OP_NONE) {
3322 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3323 == AppOpsManager.MODE_ALLOWED;
3324 } else {
3325 return true;
3326 }
3327 } catch (SecurityException readSmsSecurityException) {
3328 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003329 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003330 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003331 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003332 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003333 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003334 if (opCode != AppOpsManager.OP_NONE) {
3335 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3336 == AppOpsManager.MODE_ALLOWED;
3337 } else {
3338 return true;
3339 }
3340 } catch (SecurityException readPhoneNumberSecurityException) {
3341 }
3342
3343 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3344 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3345 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003346 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003347 }
3348
Stuart Scott8eef64f2015-04-08 15:13:54 -07003349 @Override
3350 public void factoryReset(int subId) {
3351 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003352 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3353 return;
3354 }
3355
Svet Ganovcc087f82015-05-12 20:35:54 -07003356 final long identity = Binder.clearCallingIdentity();
3357 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003358 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3359 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003360 // Enable data
Malcolm Chen964682d2017-11-28 16:20:07 -08003361 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003362 // Set network selection mode to automatic
3363 setNetworkSelectionModeAutomatic(subId);
3364 // Set preferred mobile network type to the best available
3365 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3366 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003367 mPhone.setDataRoamingEnabled(false);
pkanwar79ec0542017-07-31 14:10:01 -07003368 // Remove IMSI encryption keys from Carrier DB.
3369 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003370 }
3371 } finally {
3372 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003373 }
3374 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003375
3376 @Override
3377 public String getLocaleFromDefaultSim() {
3378 // We query all subscriptions instead of just the active ones, because
3379 // this might be called early on in the provisioning flow when the
3380 // subscriptions potentially aren't active yet.
3381 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3382 if (slist == null || slist.isEmpty()) {
3383 return null;
3384 }
3385
3386 // This function may be called very early, say, from the setup wizard, at
3387 // which point we won't have a default subscription set. If that's the case
3388 // we just choose the first, which will be valid in "most cases".
3389 final int defaultSubId = getDefaultSubscription();
3390 SubscriptionInfo info = null;
3391 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3392 info = slist.get(0);
3393 } else {
3394 for (SubscriptionInfo item : slist) {
3395 if (item.getSubscriptionId() == defaultSubId) {
3396 info = item;
3397 break;
3398 }
3399 }
3400
3401 if (info == null) {
3402 return null;
3403 }
3404 }
3405
3406 // Try and fetch the locale from the carrier properties or from the SIM language
3407 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003408 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003409 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003410 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003411 if (defaultPhone != null) {
3412 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3413 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003414 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003415 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3416 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003417 } else {
3418 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003419 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003420 }
3421 }
3422
Narayan Kamath011676f2015-07-29 12:04:08 +01003423 // The SIM language preferences only store a language (e.g. fr = French), not an
3424 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3425 // the SIM and carrier preferences does not include a country we add the country
3426 // determined from the SIM MCC to provide an exact locale.
3427 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003428 if (mccLocale != null) {
3429 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3430 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003431 }
3432
Tony Hill183b2de2015-06-24 14:53:58 +01003433 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003434 return null;
3435 }
3436
3437 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 return mSubscriptionController.getAllSubInfoList(
3441 mPhone.getContext().getOpPackageName());
3442 } finally {
3443 Binder.restoreCallingIdentity(identity);
3444 }
3445 }
3446
3447 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3448 final long identity = Binder.clearCallingIdentity();
3449 try {
3450 return mSubscriptionController.getActiveSubscriptionInfoList(
3451 mPhone.getContext().getOpPackageName());
3452 } finally {
3453 Binder.restoreCallingIdentity(identity);
3454 }
3455 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003456
3457 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003458 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3459 * representing the state of the modem.
3460 *
3461 * NOTE: This clears the modem state, so there should only every be one caller.
3462 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003463 */
3464 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003465 public void requestModemActivityInfo(ResultReceiver result) {
3466 enforceModifyPermission();
3467
3468 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3469 Bundle bundle = new Bundle();
3470 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3471 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003472 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003473
3474 /**
3475 * {@hide}
3476 * Returns the service state information on specified subscription.
3477 */
3478 @Override
3479 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3480
3481 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3482 return null;
3483 }
3484
3485 final Phone phone = getPhone(subId);
3486 if (phone == null) {
3487 return null;
3488 }
3489
3490 return phone.getServiceState();
3491 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003492
3493 /**
3494 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3495 *
3496 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3497 * voicemail ringtone.
3498 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3499 * PhoneAccount.
3500 */
3501 @Override
3502 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003503 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003504 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003505 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003506 }
3507
fionaxu7ed723d2017-05-30 18:58:54 -07003508 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003509 }
3510
3511 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003512 * Sets the per-account voicemail ringtone.
3513 *
3514 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3515 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3516 *
3517 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3518 * voicemail ringtone.
3519 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3520 * PhoneAccount.
3521 */
3522 @Override
3523 public void setVoicemailRingtoneUri(String callingPackage,
3524 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3525 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3526 if (!TextUtils.equals(callingPackage,
3527 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3528 enforceModifyPermissionOrCarrierPrivilege(
3529 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3530 }
3531 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3532 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003533 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003534 }
fionaxu7ed723d2017-05-30 18:58:54 -07003535 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003536 }
3537
3538 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003539 * Returns whether vibration is set for voicemail notification in Phone settings.
3540 *
3541 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3542 * voicemail vibration setting.
3543 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3544 */
3545 @Override
3546 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003547 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003548 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003549 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003550 }
3551
fionaxu7ed723d2017-05-30 18:58:54 -07003552 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003553 }
3554
Youhan Wange64578a2016-05-02 15:32:42 -07003555 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003556 * Sets the per-account voicemail vibration.
3557 *
3558 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3559 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3560 *
3561 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3562 * voicemail vibration setting.
3563 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3564 * specific PhoneAccount.
3565 */
3566 @Override
3567 public void setVoicemailVibrationEnabled(String callingPackage,
3568 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3569 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3570 if (!TextUtils.equals(callingPackage,
3571 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3572 enforceModifyPermissionOrCarrierPrivilege(
3573 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3574 }
3575
3576 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3577 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003578 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003579 }
fionaxu7ed723d2017-05-30 18:58:54 -07003580 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003581 }
3582
3583 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003584 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3585 *
3586 * @throws SecurityException if the caller does not have the required permission
3587 */
3588 private void enforceReadPrivilegedPermission() {
3589 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3590 null);
3591 }
3592
3593 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003594 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3595 * permission.
3596 *
3597 * @throws SecurityException if the caller does not have the required permission
3598 */
3599 private void enforceSendSmsPermission() {
3600 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3601 }
3602
3603 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003604 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003605 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003606 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003607 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003608 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003609 ComponentName componentName =
3610 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3611 if(componentName == null) {
3612 throw new SecurityException("Caller not current active visual voicemail package[null]");
3613 }
3614 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003615 if (!callingPackage.equals(vvmPackage)) {
3616 throw new SecurityException("Caller not current active visual voicemail package[" +
3617 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003618 }
3619 }
3620
3621 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003622 * Return the application ID for the app type.
3623 *
3624 * @param subId the subscription ID that this request applies to.
3625 * @param appType the uicc app type.
3626 * @return Application ID for specificied app type, or null if no uicc.
3627 */
3628 @Override
3629 public String getAidForAppType(int subId, int appType) {
3630 enforceReadPrivilegedPermission();
3631 Phone phone = getPhone(subId);
3632 if (phone == null) {
3633 return null;
3634 }
3635 String aid = null;
3636 try {
3637 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3638 .getApplicationByType(appType).getAid();
3639 } catch (Exception e) {
3640 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3641 }
3642 return aid;
3643 }
3644
Youhan Wang4001d252016-05-11 10:29:41 -07003645 /**
3646 * Return the Electronic Serial Number.
3647 *
3648 * @param subId the subscription ID that this request applies to.
3649 * @return ESN or null if error.
3650 */
3651 @Override
3652 public String getEsn(int subId) {
3653 enforceReadPrivilegedPermission();
3654 Phone phone = getPhone(subId);
3655 if (phone == null) {
3656 return null;
3657 }
3658 String esn = null;
3659 try {
3660 esn = phone.getEsn();
3661 } catch (Exception e) {
3662 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3663 }
3664 return esn;
3665 }
3666
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003667 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003668 * Return the Preferred Roaming List Version.
3669 *
3670 * @param subId the subscription ID that this request applies to.
3671 * @return PRLVersion or null if error.
3672 */
3673 @Override
3674 public String getCdmaPrlVersion(int subId) {
3675 enforceReadPrivilegedPermission();
3676 Phone phone = getPhone(subId);
3677 if (phone == null) {
3678 return null;
3679 }
3680 String cdmaPrlVersion = null;
3681 try {
3682 cdmaPrlVersion = phone.getCdmaPrlVersion();
3683 } catch (Exception e) {
3684 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3685 }
3686 return cdmaPrlVersion;
3687 }
3688
3689 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003690 * Get snapshot of Telephony histograms
3691 * @return List of Telephony histograms
3692 * @hide
3693 */
3694 @Override
3695 public List<TelephonyHistogram> getTelephonyHistograms() {
3696 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3697 return RIL.getTelephonyRILTimingHistograms();
3698 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003699
3700 /**
3701 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003702 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003703 * Require system privileges. In the future we may add this to carrier APIs.
3704 *
3705 * @return The number of carriers set successfully, should match length of carriers
3706 */
3707 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003708 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003709 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003710
Meng Wang9b7c4e92017-02-17 11:41:27 -08003711 if (carriers == null) {
3712 throw new NullPointerException("carriers cannot be null");
3713 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003714
3715 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003716 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3717 return retVal[0];
3718 }
3719
3720 /**
3721 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003722 * Get 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 List of {@link android.service.telephony.CarrierIdentifier}; empty list
3726 * means all carriers are allowed.
3727 */
3728 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003729 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003730 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003731 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003732 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3733 }
3734
fionaxu59545b42016-05-25 15:53:37 -07003735 /**
3736 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3737 * @param subId the subscription ID that this action applies to.
3738 * @param enabled control enable or disable metered apns.
3739 * {@hide}
3740 */
3741 @Override
3742 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3743 enforceModifyPermission();
3744 final Phone phone = getPhone(subId);
3745 if (phone == null) {
3746 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3747 return;
3748 }
3749 try {
3750 phone.carrierActionSetMeteredApnsEnabled(enabled);
3751 } catch (Exception e) {
3752 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3753 }
3754 }
3755
3756 /**
3757 * Action set from carrier signalling broadcast receivers to enable/disable radio
3758 * @param subId the subscription ID that this action applies to.
3759 * @param enabled control enable or disable radio.
3760 * {@hide}
3761 */
3762 @Override
3763 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3764 enforceModifyPermission();
3765 final Phone phone = getPhone(subId);
3766 if (phone == null) {
3767 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3768 return;
3769 }
3770 try {
3771 phone.carrierActionSetRadioEnabled(enabled);
3772 } catch (Exception e) {
3773 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3774 }
3775 }
3776
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003777 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003778 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3779 * network status based on which carrier apps could apply actions accordingly,
3780 * enable/disable default url handler for example.
3781 *
3782 * @param subId the subscription ID that this action applies to.
3783 * @param report control start/stop reporting the default network status.
3784 * {@hide}
3785 */
3786 @Override
3787 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3788 enforceModifyPermission();
3789 final Phone phone = getPhone(subId);
3790 if (phone == null) {
3791 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3792 return;
3793 }
3794 try {
3795 phone.carrierActionReportDefaultNetworkStatus(report);
3796 } catch (Exception e) {
3797 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3798 }
3799 }
3800
3801 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003802 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3803 * bug report is being generated.
3804 */
3805 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003806 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003807 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3808 != PackageManager.PERMISSION_GRANTED) {
3809 writer.println("Permission Denial: can't dump Phone from pid="
3810 + Binder.getCallingPid()
3811 + ", uid=" + Binder.getCallingUid()
3812 + "without permission "
3813 + android.Manifest.permission.DUMP);
3814 return;
3815 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003816 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003817 }
Jack Yueb89b242016-06-22 13:27:47 -07003818
3819 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003820 * Get aggregated video call data usage since boot.
3821 *
3822 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3823 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003824 * {@hide}
3825 */
3826 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003827 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003828 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3829 null);
3830
Jack Yu84291ec2017-05-26 16:07:50 -07003831 // NetworkStatsService keeps tracking the active network interface and identity. It
3832 // records the delta with the corresponding network identity. We just return the total video
3833 // call data usage snapshot since boot.
3834 Phone phone = getPhone(subId);
3835 if (phone != null) {
3836 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003837 }
Jack Yu84291ec2017-05-26 16:07:50 -07003838 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003839 }
Jack Yu75ab2952016-07-08 14:29:33 -07003840
3841 /**
3842 * Policy control of data connection. Usually used when data limit is passed.
3843 * @param enabled True if enabling the data, otherwise disabling.
3844 * @param subId Subscription index
3845 * {@hide}
3846 */
3847 @Override
3848 public void setPolicyDataEnabled(boolean enabled, int subId) {
3849 enforceModifyPermission();
3850 Phone phone = getPhone(subId);
3851 if (phone != null) {
3852 phone.setPolicyDataEnabled(enabled);
3853 }
3854 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003855
3856 /**
3857 * Get Client request stats
3858 * @return List of Client Request Stats
3859 * @hide
3860 */
3861 @Override
3862 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3863 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3864 return null;
3865 }
3866
3867 Phone phone = getPhone(subId);
3868 if (phone != null) {
3869 return phone.getClientRequestStats();
3870 }
3871
3872 return null;
3873 }
3874
3875 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3876 if (workSource != null) {
3877 return workSource;
3878 }
3879
3880 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3881 workSource = new WorkSource(uid, packageName);
3882 return workSource;
3883 }
Jack Yueb4124c2017-02-16 15:32:43 -08003884
3885 /**
Grace Chen70990072017-03-24 17:21:30 -07003886 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003887 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003888 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003889 * @param state State of SIM (power down, power up, pass through)
3890 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3891 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3892 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003893 *
3894 **/
3895 @Override
Grace Chen70990072017-03-24 17:21:30 -07003896 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003897 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003898 Phone phone = PhoneFactory.getPhone(slotIndex);
3899
Jack Yueb4124c2017-02-16 15:32:43 -08003900 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003901 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003902 }
3903 }
Shuo Qiandd210312017-04-12 22:11:33 +00003904
Tyler Gunn65d45c22017-06-05 11:22:26 -07003905 private boolean isUssdApiAllowed(int subId) {
3906 CarrierConfigManager configManager =
3907 (CarrierConfigManager) mPhone.getContext().getSystemService(
3908 Context.CARRIER_CONFIG_SERVICE);
3909 if (configManager == null) {
3910 return false;
3911 }
3912 PersistableBundle pb = configManager.getConfigForSubId(subId);
3913 if (pb == null) {
3914 return false;
3915 }
3916 return pb.getBoolean(
3917 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3918 }
3919
Shuo Qiandd210312017-04-12 22:11:33 +00003920 /**
3921 * Check if phone is in emergency callback mode
3922 * @return true if phone is in emergency callback mode
3923 * @param subId sub id
3924 */
goneil9c5f4872017-12-05 14:07:56 -08003925 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00003926 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08003927 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00003928 final Phone phone = getPhone(subId);
3929 if (phone != null) {
3930 return phone.isInEcm();
3931 } else {
3932 return false;
3933 }
3934 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003935
3936 /**
3937 * Get the current signal strength information for the given subscription.
3938 * Because this information is not updated when the device is in a low power state
3939 * it should not be relied-upon to be current.
3940 * @param subId Subscription index
3941 * @return the most recent cached signal strength info from the modem
3942 */
3943 @Override
3944 public SignalStrength getSignalStrength(int subId) {
3945 Phone p = getPhone(subId);
3946 if (p == null) {
3947 return null;
3948 }
3949
3950 return p.getSignalStrength();
3951 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003952}