blob: 02ca301a97859f168dc1999e7470a73f56b82455 [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.ActivityManager;
23import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070025import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.content.Context;
27import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070028import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070029import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080030import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070031import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070032import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.net.Uri;
34import android.os.AsyncResult;
35import android.os.Binder;
36import android.os.Bundle;
37import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070038import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Looper;
40import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070042import android.os.PersistableBundle;
Brad Ebinger34bef922017-11-09 10:27:08 -080043import android.os.Process;
Adam Lesinski903a54c2016-04-11 14:49:52 -070044import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.ServiceManager;
46import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070047import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070048import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070049import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080050import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070051import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080052import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080053import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070054import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070055import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070058import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070059import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080060import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070061import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070062import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070063import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080065import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070066import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080067import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080068import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070069import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070070import android.telephony.TelephonyManager;
Tyler Gunn65d45c22017-06-05 11:22:26 -070071import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070072import android.telephony.VisualVoicemailSmsFilterSettings;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080074import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080076import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080077import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080078
Andrew Lee312e8172014-10-23 17:01:36 -070079import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080080import com.android.ims.internal.IImsMMTelFeature;
81import com.android.ims.internal.IImsRcsFeature;
82import 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;
Shishir Agrawal302c8692015-06-19 13:49:39 -070085import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070086import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080089import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010090import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070091import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070092import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080094import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070095import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070096import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -070097import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070098import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -070099import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800100import com.android.internal.telephony.SubscriptionController;
Jonathan Basseri03923952017-07-19 12:22:35 -0700101import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700102import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700103import com.android.internal.telephony.uicc.IccIoResult;
104import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800105import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700106import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800107import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700108import com.android.internal.telephony.uicc.UiccController;
fionaxu7ed723d2017-05-30 18:58:54 -0700109import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800110import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700111import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800112import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700113import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700114import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800115
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700116import java.io.FileDescriptor;
117import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800118import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800120import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800121import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100122import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800123import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124
125/**
126 * Implementation of the ITelephony interface.
127 */
Santos Cordon117fee72014-05-16 17:56:12 -0700128public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129 private static final String LOG_TAG = "PhoneInterfaceManager";
130 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
131 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133
134 // Message codes used with mMainThreadHandler
135 private static final int CMD_HANDLE_PIN_MMI = 1;
136 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
137 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
138 private static final int CMD_ANSWER_RINGING_CALL = 4;
139 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700140 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
141 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142 private static final int CMD_OPEN_CHANNEL = 9;
143 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
144 private static final int CMD_CLOSE_CHANNEL = 11;
145 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800146 private static final int CMD_NV_READ_ITEM = 13;
147 private static final int EVENT_NV_READ_ITEM_DONE = 14;
148 private static final int CMD_NV_WRITE_ITEM = 15;
149 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
150 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
151 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
152 private static final int CMD_NV_RESET_CONFIG = 19;
153 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800154 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
155 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
156 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
157 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800158 private static final int CMD_SEND_ENVELOPE = 25;
159 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700160 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
161 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
162 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
163 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
164 private static final int CMD_EXCHANGE_SIM_IO = 31;
165 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800166 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
167 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700168 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
169 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700170 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
171 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700172 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
173 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
174 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
175 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700176 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
177 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
178 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
179 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700180 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800181 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
182 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700183
184 /** The singleton instance. */
185 private static PhoneInterfaceManager sInstance;
186
Wink Saville3ab207e2014-11-20 13:07:20 -0800187 private PhoneGlobals mApp;
188 private Phone mPhone;
189 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700190 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800191 private AppOpsManager mAppOps;
192 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800193 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800194 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195
Derek Tan97ebb422014-09-05 16:55:38 -0700196 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
197 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800198 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700199
Derek Tan740e1672017-06-27 14:56:27 -0700200 // The AID of ISD-R.
201 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
202
yinxub1bed742017-04-17 11:45:04 -0700203 private NetworkScanRequestTracker mNetworkScanRequestTracker;
204
Derek Tan89e89d42014-07-08 17:00:10 -0700205 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700206 * A request object to use for transmitting data to an ICC.
207 */
208 private static final class IccAPDUArgument {
209 public int channel, cla, command, p1, p2, p3;
210 public String data;
211
212 public IccAPDUArgument(int channel, int cla, int command,
213 int p1, int p2, int p3, String data) {
214 this.channel = channel;
215 this.cla = cla;
216 this.command = command;
217 this.p1 = p1;
218 this.p2 = p2;
219 this.p3 = p3;
220 this.data = data;
221 }
222 }
223
224 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700225 * A request object to use for transmitting data to an ICC.
226 */
227 private static final class ManualNetworkSelectionArgument {
228 public OperatorInfo operatorInfo;
229 public boolean persistSelection;
230
231 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
232 this.operatorInfo = operatorInfo;
233 this.persistSelection = persistSelection;
234 }
235 }
236
237 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700238 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
239 * request after sending. The main thread will notify the request when it is complete.
240 */
241 private static final class MainThreadRequest {
242 /** The argument to use for the request */
243 public Object argument;
244 /** The result of the request that is run on the main thread */
245 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800246 // The subscriber id that this request applies to. Defaults to
247 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
248 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249
250 public MainThreadRequest(Object argument) {
251 this.argument = argument;
252 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800253
254 public MainThreadRequest(Object argument, Integer subId) {
255 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800256 if (subId != null) {
257 this.subId = subId;
258 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800259 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700260 }
261
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800262 private static final class IncomingThirdPartyCallArgs {
263 public final ComponentName component;
264 public final String callId;
265 public final String callerDisplayName;
266
267 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
268 String callerDisplayName) {
269 this.component = component;
270 this.callId = callId;
271 this.callerDisplayName = callerDisplayName;
272 }
273 }
274
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 /**
276 * A handler that processes messages on the main thread in the phone process. Since many
277 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
278 * inbound binder threads to the main thread in the phone process. The Binder thread
279 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
280 * on, which will be notified when the operation completes and will contain the result of the
281 * request.
282 *
283 * <p>If a MainThreadRequest object is provided in the msg.obj field,
284 * note that request.result must be set to something non-null for the calling thread to
285 * unblock.
286 */
287 private final class MainThreadHandler extends Handler {
288 @Override
289 public void handleMessage(Message msg) {
290 MainThreadRequest request;
291 Message onCompleted;
292 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800293 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700294 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295
296 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700297 case CMD_HANDLE_USSD_REQUEST: {
298 request = (MainThreadRequest) msg.obj;
299 final Phone phone = getPhoneFromRequest(request);
300 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
301 String ussdRequest = ussdObject.first;
302 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700303
304 if (!isUssdApiAllowed(request.subId)) {
305 // Carrier does not support use of this API, return failure.
306 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
307 UssdResponse response = new UssdResponse(ussdRequest, null);
308 Bundle returnData = new Bundle();
309 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
310 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
311
312 request.result = true;
313 synchronized (request) {
314 request.notifyAll();
315 }
316 return;
317 }
318
Tyler Gunn52dcf772017-04-26 11:30:31 -0700319 try {
320 request.result = phone != null ?
321 phone.handleUssdRequest(ussdRequest, wrappedCallback)
322 : false;
323 } catch (CallStateException cse) {
324 request.result = false;
325 }
pkanwar32d516d2016-10-14 19:37:38 -0700326 // Wake up the requesting thread
327 synchronized (request) {
328 request.notifyAll();
329 }
330 break;
331 }
332
Yorke Lee716f67e2015-06-17 15:39:16 -0700333 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700335 final Phone phone = getPhoneFromRequest(request);
336 request.result = phone != null ?
337 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
338 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700339 // Wake up the requesting thread
340 synchronized (request) {
341 request.notifyAll();
342 }
343 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345
346 case CMD_HANDLE_NEIGHBORING_CELL:
347 request = (MainThreadRequest) msg.obj;
348 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
349 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700350 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 break;
352
353 case EVENT_NEIGHBORING_CELL_DONE:
354 ar = (AsyncResult) msg.obj;
355 request = (MainThreadRequest) ar.userObj;
356 if (ar.exception == null && ar.result != null) {
357 request.result = ar.result;
358 } else {
359 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800360 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 }
362 // Wake up the requesting thread
363 synchronized (request) {
364 request.notifyAll();
365 }
366 break;
367
368 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700369 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800370 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700371 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 break;
373
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 case CMD_END_CALL:
375 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800376 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700377 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700378 Phone phone = getPhone(end_subId);
379 if (phone == null) {
380 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
381 break;
382 }
383 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
385 // CDMA: If the user presses the Power button we treat it as
386 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700387 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
389 // GSM: End the call as per the Phone state
390 hungUp = PhoneUtils.hangup(mCM);
391 } else {
392 throw new IllegalStateException("Unexpected phone type: " + phoneType);
393 }
394 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
395 request.result = hungUp;
396 // Wake up the requesting thread
397 synchronized (request) {
398 request.notifyAll();
399 }
400 break;
401
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700402 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700403 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700404 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800405 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700406 if (uiccCard == null) {
407 loge("iccTransmitApduLogicalChannel: No UICC");
408 request.result = new IccIoResult(0x6F, 0, (byte[])null);
409 synchronized (request) {
410 request.notifyAll();
411 }
412 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
414 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700415 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 iccArgument.channel, iccArgument.cla, iccArgument.command,
417 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700418 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700419 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700420 break;
421
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700422 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700423 ar = (AsyncResult) msg.obj;
424 request = (MainThreadRequest) ar.userObj;
425 if (ar.exception == null && ar.result != null) {
426 request.result = ar.result;
427 } else {
428 request.result = new IccIoResult(0x6F, 0, (byte[])null);
429 if (ar.result == null) {
430 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800431 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800433 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700434 } else {
435 loge("iccTransmitApduLogicalChannel: Unknown exception");
436 }
437 }
438 synchronized (request) {
439 request.notifyAll();
440 }
441 break;
442
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
444 request = (MainThreadRequest) msg.obj;
445 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800446 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 if (uiccCard == null) {
448 loge("iccTransmitApduBasicChannel: No UICC");
449 request.result = new IccIoResult(0x6F, 0, (byte[])null);
450 synchronized (request) {
451 request.notifyAll();
452 }
453 } else {
454 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
455 request);
456 uiccCard.iccTransmitApduBasicChannel(
457 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
458 iccArgument.p3, iccArgument.data, onCompleted);
459 }
460 break;
461
462 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
463 ar = (AsyncResult) msg.obj;
464 request = (MainThreadRequest) ar.userObj;
465 if (ar.exception == null && ar.result != null) {
466 request.result = ar.result;
467 } else {
468 request.result = new IccIoResult(0x6F, 0, (byte[])null);
469 if (ar.result == null) {
470 loge("iccTransmitApduBasicChannel: Empty response");
471 } else if (ar.exception instanceof CommandException) {
472 loge("iccTransmitApduBasicChannel: CommandException: " +
473 ar.exception);
474 } else {
475 loge("iccTransmitApduBasicChannel: Unknown exception");
476 }
477 }
478 synchronized (request) {
479 request.notifyAll();
480 }
481 break;
482
483 case CMD_EXCHANGE_SIM_IO:
484 request = (MainThreadRequest) msg.obj;
485 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800486 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 if (uiccCard == null) {
488 loge("iccExchangeSimIO: No UICC");
489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
490 synchronized (request) {
491 request.notifyAll();
492 }
493 } else {
494 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
495 request);
496 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
497 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
498 iccArgument.data, onCompleted);
499 }
500 break;
501
502 case EVENT_EXCHANGE_SIM_IO_DONE:
503 ar = (AsyncResult) msg.obj;
504 request = (MainThreadRequest) ar.userObj;
505 if (ar.exception == null && ar.result != null) {
506 request.result = ar.result;
507 } else {
508 request.result = new IccIoResult(0x6f, 0, (byte[])null);
509 }
510 synchronized (request) {
511 request.notifyAll();
512 }
513 break;
514
Derek Tan4d5e5c12014-02-04 11:54:58 -0800515 case CMD_SEND_ENVELOPE:
516 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800517 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700518 if (uiccCard == null) {
519 loge("sendEnvelopeWithStatus: No UICC");
520 request.result = new IccIoResult(0x6F, 0, (byte[])null);
521 synchronized (request) {
522 request.notifyAll();
523 }
524 } else {
525 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
526 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
527 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800528 break;
529
530 case EVENT_SEND_ENVELOPE_DONE:
531 ar = (AsyncResult) msg.obj;
532 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700533 if (ar.exception == null && ar.result != null) {
534 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800535 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700536 request.result = new IccIoResult(0x6F, 0, (byte[])null);
537 if (ar.result == null) {
538 loge("sendEnvelopeWithStatus: Empty response");
539 } else if (ar.exception instanceof CommandException) {
540 loge("sendEnvelopeWithStatus: CommandException: " +
541 ar.exception);
542 } else {
543 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
544 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800545 }
546 synchronized (request) {
547 request.notifyAll();
548 }
549 break;
550
Shishir Agrawal566b7612013-10-28 14:41:00 -0700551 case CMD_OPEN_CHANNEL:
552 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800553 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800554 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 if (uiccCard == null) {
556 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800557 request.result = new IccOpenLogicalChannelResponse(-1,
558 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700559 synchronized (request) {
560 request.notifyAll();
561 }
562 } else {
563 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800564 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
565 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 break;
568
569 case EVENT_OPEN_CHANNEL_DONE:
570 ar = (AsyncResult) msg.obj;
571 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700572 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 int[] result = (int[]) ar.result;
575 int channelId = result[0];
576 byte[] selectResponse = null;
577 if (result.length > 1) {
578 selectResponse = new byte[result.length - 1];
579 for (int i = 1; i < result.length; ++i) {
580 selectResponse[i - 1] = (byte) result[i];
581 }
582 }
583 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700584 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 if (ar.result == null) {
587 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 if (ar.exception != null) {
590 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
591 }
592
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700593 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700594 if (ar.exception instanceof CommandException) {
595 CommandException.Error error =
596 ((CommandException) (ar.exception)).getCommandError();
597 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700598 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700599 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700600 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 }
602 }
603 openChannelResp = new IccOpenLogicalChannelResponse(
604 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700606 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 synchronized (request) {
608 request.notifyAll();
609 }
610 break;
611
612 case CMD_CLOSE_CHANNEL:
613 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800614 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700615 if (uiccCard == null) {
616 loge("iccCloseLogicalChannel: No UICC");
617 request.result = new IccIoResult(0x6F, 0, (byte[])null);
618 synchronized (request) {
619 request.notifyAll();
620 }
621 } else {
622 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
623 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
624 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 break;
626
627 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800628 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
629 break;
630
631 case CMD_NV_READ_ITEM:
632 request = (MainThreadRequest) msg.obj;
633 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
634 mPhone.nvReadItem((Integer) request.argument, onCompleted);
635 break;
636
637 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 ar = (AsyncResult) msg.obj;
639 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800640 if (ar.exception == null && ar.result != null) {
641 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800643 request.result = "";
644 if (ar.result == null) {
645 loge("nvReadItem: Empty response");
646 } else if (ar.exception instanceof CommandException) {
647 loge("nvReadItem: CommandException: " +
648 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800650 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 }
652 }
653 synchronized (request) {
654 request.notifyAll();
655 }
656 break;
657
Jake Hambye994d462014-02-03 13:10:13 -0800658 case CMD_NV_WRITE_ITEM:
659 request = (MainThreadRequest) msg.obj;
660 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
661 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
662 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
663 break;
664
665 case EVENT_NV_WRITE_ITEM_DONE:
666 handleNullReturnEvent(msg, "nvWriteItem");
667 break;
668
669 case CMD_NV_WRITE_CDMA_PRL:
670 request = (MainThreadRequest) msg.obj;
671 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
672 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
673 break;
674
675 case EVENT_NV_WRITE_CDMA_PRL_DONE:
676 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
677 break;
678
679 case CMD_NV_RESET_CONFIG:
680 request = (MainThreadRequest) msg.obj;
681 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
682 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
683 break;
684
685 case EVENT_NV_RESET_CONFIG_DONE:
686 handleNullReturnEvent(msg, "nvResetConfig");
687 break;
688
Jake Hamby7c27be32014-03-03 13:25:59 -0800689 case CMD_GET_PREFERRED_NETWORK_TYPE:
690 request = (MainThreadRequest) msg.obj;
691 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700692 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800693 break;
694
695 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
696 ar = (AsyncResult) msg.obj;
697 request = (MainThreadRequest) ar.userObj;
698 if (ar.exception == null && ar.result != null) {
699 request.result = ar.result; // Integer
700 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800701 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800702 if (ar.result == null) {
703 loge("getPreferredNetworkType: Empty response");
704 } else if (ar.exception instanceof CommandException) {
705 loge("getPreferredNetworkType: CommandException: " +
706 ar.exception);
707 } else {
708 loge("getPreferredNetworkType: Unknown exception");
709 }
710 }
711 synchronized (request) {
712 request.notifyAll();
713 }
714 break;
715
716 case CMD_SET_PREFERRED_NETWORK_TYPE:
717 request = (MainThreadRequest) msg.obj;
718 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
719 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700720 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800721 break;
722
723 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
724 handleNullReturnEvent(msg, "setPreferredNetworkType");
725 break;
726
Steven Liu4bf01bc2014-07-17 11:05:29 -0500727 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
728 request = (MainThreadRequest)msg.obj;
729 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
730 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
731 break;
732
733 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
734 ar = (AsyncResult)msg.obj;
735 request = (MainThreadRequest)ar.userObj;
736 request.result = ar;
737 synchronized (request) {
738 request.notifyAll();
739 }
740 break;
741
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800742 case CMD_SET_VOICEMAIL_NUMBER:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
745 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800746 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
747 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800748 break;
749
750 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
751 handleNullReturnEvent(msg, "setVoicemailNumber");
752 break;
753
Stuart Scott54788802015-03-30 13:18:01 -0700754 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
757 request);
758 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
759 break;
760
761 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
762 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
763 break;
764
Shishir Agrawal302c8692015-06-19 13:49:39 -0700765 case CMD_PERFORM_NETWORK_SCAN:
766 request = (MainThreadRequest) msg.obj;
767 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
768 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
769 break;
770
771 case EVENT_PERFORM_NETWORK_SCAN_DONE:
772 ar = (AsyncResult) msg.obj;
773 request = (MainThreadRequest) ar.userObj;
774 CellNetworkScanResult cellScanResult;
775 if (ar.exception == null && ar.result != null) {
776 cellScanResult = new CellNetworkScanResult(
777 CellNetworkScanResult.STATUS_SUCCESS,
778 (List<OperatorInfo>) ar.result);
779 } else {
780 if (ar.result == null) {
781 loge("getCellNetworkScanResults: Empty response");
782 }
783 if (ar.exception != null) {
784 loge("getCellNetworkScanResults: Exception: " + ar.exception);
785 }
786 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
787 if (ar.exception instanceof CommandException) {
788 CommandException.Error error =
789 ((CommandException) (ar.exception)).getCommandError();
790 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
791 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
792 } else if (error == CommandException.Error.GENERIC_FAILURE) {
793 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
794 }
795 }
796 cellScanResult = new CellNetworkScanResult(errorCode, null);
797 }
798 request.result = cellScanResult;
799 synchronized (request) {
800 request.notifyAll();
801 }
802 break;
803
804 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
805 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700806 ManualNetworkSelectionArgument selArg =
807 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700808 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
809 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700810 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
811 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700812 break;
813
814 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
815 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
816 break;
817
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700818 case CMD_GET_MODEM_ACTIVITY_INFO:
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700821 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700822 break;
823
824 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
825 ar = (AsyncResult) msg.obj;
826 request = (MainThreadRequest) ar.userObj;
827 if (ar.exception == null && ar.result != null) {
828 request.result = ar.result;
829 } else {
830 if (ar.result == null) {
831 loge("queryModemActivityInfo: Empty response");
832 } else if (ar.exception instanceof CommandException) {
833 loge("queryModemActivityInfo: CommandException: " +
834 ar.exception);
835 } else {
836 loge("queryModemActivityInfo: Unknown exception");
837 }
838 }
Amit Mahajand4766222016-01-28 15:28:28 -0800839 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
840 if (request.result == null) {
841 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
842 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700843 synchronized (request) {
844 request.notifyAll();
845 }
846 break;
847
Meng Wang1a7c35a2016-05-05 20:56:15 -0700848 case CMD_SET_ALLOWED_CARRIERS:
849 request = (MainThreadRequest) msg.obj;
850 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
851 mPhone.setAllowedCarriers(
852 (List<CarrierIdentifier>) request.argument,
853 onCompleted);
854 break;
855
856 case EVENT_SET_ALLOWED_CARRIERS_DONE:
857 ar = (AsyncResult) msg.obj;
858 request = (MainThreadRequest) ar.userObj;
859 if (ar.exception == null && ar.result != null) {
860 request.result = ar.result;
861 } else {
862 if (ar.result == null) {
863 loge("setAllowedCarriers: Empty response");
864 } else if (ar.exception instanceof CommandException) {
865 loge("setAllowedCarriers: CommandException: " +
866 ar.exception);
867 } else {
868 loge("setAllowedCarriers: Unknown exception");
869 }
870 }
871 // Result cannot be null. Return -1 on error.
872 if (request.result == null) {
873 request.result = new int[]{-1};
874 }
875 synchronized (request) {
876 request.notifyAll();
877 }
878 break;
879
880 case CMD_GET_ALLOWED_CARRIERS:
881 request = (MainThreadRequest) msg.obj;
882 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
883 mPhone.getAllowedCarriers(onCompleted);
884 break;
885
886 case EVENT_GET_ALLOWED_CARRIERS_DONE:
887 ar = (AsyncResult) msg.obj;
888 request = (MainThreadRequest) ar.userObj;
889 if (ar.exception == null && ar.result != null) {
890 request.result = ar.result;
891 } else {
892 if (ar.result == null) {
893 loge("getAllowedCarriers: Empty response");
894 } else if (ar.exception instanceof CommandException) {
895 loge("getAllowedCarriers: CommandException: " +
896 ar.exception);
897 } else {
898 loge("getAllowedCarriers: Unknown exception");
899 }
900 }
901 // Result cannot be null. Return empty list of CarrierIdentifier.
902 if (request.result == null) {
903 request.result = new ArrayList<CarrierIdentifier>(0);
904 }
905 synchronized (request) {
906 request.notifyAll();
907 }
908 break;
909
Nathan Haroldb3014052017-01-25 15:57:32 -0800910 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
913 if (ar.exception == null && ar.result != null) {
914 request.result = ar.result;
915 } else {
916 request.result = new IllegalArgumentException(
917 "Failed to retrieve Forbidden Plmns");
918 if (ar.result == null) {
919 loge("getForbiddenPlmns: Empty response");
920 } else {
921 loge("getForbiddenPlmns: Unknown exception");
922 }
923 }
924 synchronized (request) {
925 request.notifyAll();
926 }
927 break;
928
929 case CMD_GET_FORBIDDEN_PLMNS:
930 request = (MainThreadRequest) msg.obj;
931 uiccCard = getUiccCardFromRequest(request);
932 if (uiccCard == null) {
933 loge("getForbiddenPlmns() UiccCard is null");
934 request.result = new IllegalArgumentException(
935 "getForbiddenPlmns() UiccCard is null");
936 synchronized (request) {
937 request.notifyAll();
938 }
939 break;
940 }
941 Integer appType = (Integer) request.argument;
942 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
943 if (uiccApp == null) {
944 loge("getForbiddenPlmns() no app with specified type -- "
945 + appType);
946 request.result = new IllegalArgumentException("Failed to get UICC App");
947 synchronized (request) {
948 request.notifyAll();
949 }
950 break;
951 } else {
952 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
953 + " specified type -- " + appType);
954 }
955 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
956 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
957 onCompleted);
958 break;
959
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700960 default:
961 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
962 break;
963 }
964 }
Jake Hambye994d462014-02-03 13:10:13 -0800965
966 private void handleNullReturnEvent(Message msg, String command) {
967 AsyncResult ar = (AsyncResult) msg.obj;
968 MainThreadRequest request = (MainThreadRequest) ar.userObj;
969 if (ar.exception == null) {
970 request.result = true;
971 } else {
972 request.result = false;
973 if (ar.exception instanceof CommandException) {
974 loge(command + ": CommandException: " + ar.exception);
975 } else {
976 loge(command + ": Unknown exception");
977 }
978 }
979 synchronized (request) {
980 request.notifyAll();
981 }
982 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700983 }
984
985 /**
986 * Posts the specified command to be executed on the main thread,
987 * waits for the request to complete, and returns the result.
988 * @see #sendRequestAsync
989 */
990 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -0800991 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -0700992 }
993
994 /**
995 * Posts the specified command to be executed on the main thread,
996 * waits for the request to complete, and returns the result.
997 * @see #sendRequestAsync
998 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800999 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001000 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1001 throw new RuntimeException("This method will deadlock if called from the main thread.");
1002 }
1003
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001004 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001005 Message msg = mMainThreadHandler.obtainMessage(command, request);
1006 msg.sendToTarget();
1007
1008 // Wait for the request to complete
1009 synchronized (request) {
1010 while (request.result == null) {
1011 try {
1012 request.wait();
1013 } catch (InterruptedException e) {
1014 // Do nothing, go back and wait until the request is complete
1015 }
1016 }
1017 }
1018 return request.result;
1019 }
1020
1021 /**
1022 * Asynchronous ("fire and forget") version of sendRequest():
1023 * Posts the specified command to be executed on the main thread, and
1024 * returns immediately.
1025 * @see #sendRequest
1026 */
1027 private void sendRequestAsync(int command) {
1028 mMainThreadHandler.sendEmptyMessage(command);
1029 }
1030
1031 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001032 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1033 * @see {@link #sendRequest(int,Object)}
1034 */
1035 private void sendRequestAsync(int command, Object argument) {
1036 MainThreadRequest request = new MainThreadRequest(argument);
1037 Message msg = mMainThreadHandler.obtainMessage(command, request);
1038 msg.sendToTarget();
1039 }
1040
1041 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001042 * Initialize the singleton PhoneInterfaceManager instance.
1043 * This is only done once, at startup, from PhoneApp.onCreate().
1044 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001045 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001046 synchronized (PhoneInterfaceManager.class) {
1047 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001048 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001049 } else {
1050 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1051 }
1052 return sInstance;
1053 }
1054 }
1055
1056 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001057 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001058 mApp = app;
1059 mPhone = phone;
1060 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001061 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001062 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1063 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001064 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001065 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001066 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001067 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001068
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001069 publish();
1070 }
1071
1072 private void publish() {
1073 if (DBG) log("publish: " + this);
1074
1075 ServiceManager.addService("phone", this);
1076 }
1077
Stuart Scott584921c2015-01-15 17:10:34 -08001078 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001079 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1080 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001081 }
1082
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001083 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1084 Phone phone = getPhoneFromRequest(request);
1085 return phone == null ? null :
1086 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1087 }
1088
Wink Saville36469e72014-06-11 15:17:00 -07001089 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001090 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001091 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001093 //
1094 // Implementation of the ITelephony interface.
1095 //
1096
1097 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001098 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001099 }
1100
Wink Savilleb564aae2014-10-23 10:18:09 -07001101 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001102 if (DBG) log("dial: " + number);
1103 // No permission check needed here: This is just a wrapper around the
1104 // ACTION_DIAL intent, which is available to any app since it puts up
1105 // the UI before it does anything.
1106
1107 String url = createTelUrl(number);
1108 if (url == null) {
1109 return;
1110 }
1111
1112 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001113 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001114 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1115 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1116 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1117 mApp.startActivity(intent);
1118 }
1119 }
1120
1121 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001122 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001123 }
1124
Wink Savilleb564aae2014-10-23 10:18:09 -07001125 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001126 if (DBG) log("call: " + number);
1127
1128 // This is just a wrapper around the ACTION_CALL intent, but we still
1129 // need to do a permission check since we're calling startActivity()
1130 // from the context of the phone app.
1131 enforceCallPermission();
1132
1133 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1134 != AppOpsManager.MODE_ALLOWED) {
1135 return;
1136 }
1137
1138 String url = createTelUrl(number);
1139 if (url == null) {
1140 return;
1141 }
1142
Wink Saville08874612014-08-31 19:19:58 -07001143 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001144 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001145 if (slist != null) {
1146 for (SubscriptionInfo subInfoRecord : slist) {
1147 if (subInfoRecord.getSubscriptionId() == subId) {
1148 isValid = true;
1149 break;
1150 }
Wink Saville08874612014-08-31 19:19:58 -07001151 }
1152 }
1153 if (isValid == false) {
1154 return;
1155 }
1156
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001157 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001158 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001159 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1160 mApp.startActivity(intent);
1161 }
1162
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001163 /**
1164 * End a call based on call state
1165 * @return true is a call was ended
1166 */
1167 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001168 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001169 }
1170
1171 /**
1172 * End a call based on the call state of the subId
1173 * @return true is a call was ended
1174 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001175 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001176 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001177 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001178 }
1179
1180 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001181 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001182 }
1183
Wink Savilleb564aae2014-10-23 10:18:09 -07001184 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001185 if (DBG) log("answerRingingCall...");
1186 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1187 // but that can probably wait till the big TelephonyManager API overhaul.
1188 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1189 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001190 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001191 }
1192
1193 /**
1194 * Make the actual telephony calls to implement answerRingingCall().
1195 * This should only be called from the main thread of the Phone app.
1196 * @see #answerRingingCall
1197 *
1198 * TODO: it would be nice to return true if we answered the call, or
1199 * false if there wasn't actually a ringing incoming call, or some
1200 * other error occurred. (In other words, pass back the return value
1201 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1202 * But that would require calling this method via sendRequest() rather
1203 * than sendRequestAsync(), and right now we don't actually *need* that
1204 * return value, so let's just return void for now.
1205 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001206 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001207 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001208 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001209 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1210 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001211 if (hasActiveCall && hasHoldingCall) {
1212 // Both lines are in use!
1213 // TODO: provide a flag to let the caller specify what
1214 // policy to use if both lines are in use. (The current
1215 // behavior is hardwired to "answer incoming, end ongoing",
1216 // which is how the CALL button is specced to behave.)
1217 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1218 return;
1219 } else {
1220 // answerCall() will automatically hold the current active
1221 // call, if there is one.
1222 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1223 return;
1224 }
1225 } else {
1226 // No call was ringing.
1227 return;
1228 }
1229 }
1230
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001232 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001233 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001234 public void silenceRinger() {
1235 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001236 }
1237
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001238 @Override
1239 public boolean isOffhook(String callingPackage) {
1240 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001241 }
1242
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001243 @Override
1244 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1245 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1246 return false;
1247 }
1248
Sanket Padawe356d7632015-06-22 14:03:32 -07001249 final Phone phone = getPhone(subId);
1250 if (phone != null) {
1251 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1252 } else {
1253 return false;
1254 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001255 }
1256
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001257 @Override
1258 public boolean isRinging(String callingPackage) {
1259 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001260 }
1261
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001262 @Override
1263 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1264 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1265 return false;
1266 }
1267
Sanket Padawe356d7632015-06-22 14:03:32 -07001268 final Phone phone = getPhone(subId);
1269 if (phone != null) {
1270 return (phone.getState() == PhoneConstants.State.RINGING);
1271 } else {
1272 return false;
1273 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 }
1275
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001276 @Override
1277 public boolean isIdle(String callingPackage) {
1278 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001279 }
1280
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001281 @Override
1282 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1283 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1284 return false;
1285 }
1286
Sanket Padawe356d7632015-06-22 14:03:32 -07001287 final Phone phone = getPhone(subId);
1288 if (phone != null) {
1289 return (phone.getState() == PhoneConstants.State.IDLE);
1290 } else {
1291 return false;
1292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001293 }
1294
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001295 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001296 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001297 }
1298
Wink Savilleb564aae2014-10-23 10:18:09 -07001299 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001300 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001301 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1302 }
1303
1304 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001305 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001306 }
1307
Wink Savilleb564aae2014-10-23 10:18:09 -07001308 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001309 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001310 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1311 }
1312
1313 /** {@hide} */
1314 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001315 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001316 }
1317
Wink Savilleb564aae2014-10-23 10:18:09 -07001318 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001320 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001321 checkSimPin.start();
1322 return checkSimPin.unlockSim(null, pin);
1323 }
1324
Wink Saville9de0f752013-10-22 19:04:03 -07001325 /** {@hide} */
1326 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001327 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001328 }
1329
Wink Savilleb564aae2014-10-23 10:18:09 -07001330 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001332 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 checkSimPuk.start();
1334 return checkSimPuk.unlockSim(puk, pin);
1335 }
1336
1337 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001338 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 * a synchronous one.
1340 */
1341 private static class UnlockSim extends Thread {
1342
1343 private final IccCard mSimCard;
1344
1345 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001346 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1347 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001348
1349 // For replies from SimCard interface
1350 private Handler mHandler;
1351
1352 // For async handler to identify request type
1353 private static final int SUPPLY_PIN_COMPLETE = 100;
1354
1355 public UnlockSim(IccCard simCard) {
1356 mSimCard = simCard;
1357 }
1358
1359 @Override
1360 public void run() {
1361 Looper.prepare();
1362 synchronized (UnlockSim.this) {
1363 mHandler = new Handler() {
1364 @Override
1365 public void handleMessage(Message msg) {
1366 AsyncResult ar = (AsyncResult) msg.obj;
1367 switch (msg.what) {
1368 case SUPPLY_PIN_COMPLETE:
1369 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1370 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001371 mRetryCount = msg.arg1;
1372 if (ar.exception != null) {
1373 if (ar.exception instanceof CommandException &&
1374 ((CommandException)(ar.exception)).getCommandError()
1375 == CommandException.Error.PASSWORD_INCORRECT) {
1376 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1377 } else {
1378 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1379 }
1380 } else {
1381 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1382 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383 mDone = true;
1384 UnlockSim.this.notifyAll();
1385 }
1386 break;
1387 }
1388 }
1389 };
1390 UnlockSim.this.notifyAll();
1391 }
1392 Looper.loop();
1393 }
1394
1395 /*
1396 * Use PIN or PUK to unlock SIM card
1397 *
1398 * If PUK is null, unlock SIM card with PIN
1399 *
1400 * If PUK is not null, unlock SIM card with PUK and set PIN code
1401 */
Wink Saville9de0f752013-10-22 19:04:03 -07001402 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403
1404 while (mHandler == null) {
1405 try {
1406 wait();
1407 } catch (InterruptedException e) {
1408 Thread.currentThread().interrupt();
1409 }
1410 }
1411 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1412
1413 if (puk == null) {
1414 mSimCard.supplyPin(pin, callback);
1415 } else {
1416 mSimCard.supplyPuk(puk, pin, callback);
1417 }
1418
1419 while (!mDone) {
1420 try {
1421 Log.d(LOG_TAG, "wait for done");
1422 wait();
1423 } catch (InterruptedException e) {
1424 // Restore the interrupted status
1425 Thread.currentThread().interrupt();
1426 }
1427 }
1428 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001429 int[] resultArray = new int[2];
1430 resultArray[0] = mResult;
1431 resultArray[1] = mRetryCount;
1432 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001433 }
1434 }
1435
1436 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001437 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001438
1439 }
1440
Wink Savilleb564aae2014-10-23 10:18:09 -07001441 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442 // No permission check needed here: this call is harmless, and it's
1443 // needed for the ServiceState.requestStateUpdate() call (which is
1444 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001445 final Phone phone = getPhone(subId);
1446 if (phone != null) {
1447 phone.updateServiceLocation();
1448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449 }
1450
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001451 @Override
1452 public boolean isRadioOn(String callingPackage) {
1453 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001454 }
1455
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001456 @Override
1457 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1458 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1459 return false;
1460 }
1461 return isRadioOnForSubscriber(subId);
1462 }
1463
1464 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001465 final Phone phone = getPhone(subId);
1466 if (phone != null) {
1467 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1468 } else {
1469 return false;
1470 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471 }
1472
1473 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001474 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001475
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001476 }
Wink Saville36469e72014-06-11 15:17:00 -07001477
Wink Savilleb564aae2014-10-23 10:18:09 -07001478 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001480 final Phone phone = getPhone(subId);
1481 if (phone != null) {
1482 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1483 }
Wink Saville36469e72014-06-11 15:17:00 -07001484 }
1485
1486 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001487 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001488 }
1489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001491 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001492 final Phone phone = getPhone(subId);
1493 if (phone == null) {
1494 return false;
1495 }
1496 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001497 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001498 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001499 }
1500 return true;
1501 }
Wink Saville36469e72014-06-11 15:17:00 -07001502
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001503 public boolean needMobileRadioShutdown() {
1504 /*
1505 * If any of the Radios are available, it will need to be
1506 * shutdown. So return true if any Radio is available.
1507 */
1508 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1509 Phone phone = PhoneFactory.getPhone(i);
1510 if (phone != null && phone.isRadioAvailable()) return true;
1511 }
1512 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1513 return false;
1514 }
1515
1516 public void shutdownMobileRadios() {
1517 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1518 logv("Shutting down Phone " + i);
1519 shutdownRadioUsingPhoneId(i);
1520 }
1521 }
1522
1523 private void shutdownRadioUsingPhoneId(int phoneId) {
1524 enforceModifyPermission();
1525 Phone phone = PhoneFactory.getPhone(phoneId);
1526 if (phone != null && phone.isRadioAvailable()) {
1527 phone.shutdownRadio();
1528 }
1529 }
1530
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001532 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001533 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1534 if (defaultPhone != null) {
1535 defaultPhone.setRadioPower(turnOn);
1536 return true;
1537 } else {
1538 loge("There's no default phone.");
1539 return false;
1540 }
Wink Saville36469e72014-06-11 15:17:00 -07001541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001545 final Phone phone = getPhone(subId);
1546 if (phone != null) {
1547 phone.setRadioPower(turnOn);
1548 return true;
1549 } else {
1550 return false;
1551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001552 }
1553
Wink Saville36469e72014-06-11 15:17:00 -07001554 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001555 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 public boolean enableDataConnectivity() {
1557 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001558 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001559 final Phone phone = getPhone(subId);
1560 if (phone != null) {
1561 phone.setDataEnabled(true);
1562 return true;
1563 } else {
1564 return false;
1565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 }
1567
Wink Saville36469e72014-06-11 15:17:00 -07001568 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001569 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 public boolean disableDataConnectivity() {
1571 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001572 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001573 final Phone phone = getPhone(subId);
1574 if (phone != null) {
1575 phone.setDataEnabled(false);
1576 return true;
1577 } else {
1578 return false;
1579 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001580 }
1581
Sanket Padawe356d7632015-06-22 14:03:32 -07001582 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001583 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001584 final Phone phone = getPhone(subId);
1585 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001586 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001587 } else {
1588 return false;
1589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 }
1591
1592 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001593 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001594 }
1595
pkanwarae03a6b2016-11-06 20:37:09 -08001596 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001597 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001598 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1599 return;
1600 }
1601 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1602 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1603 };
1604
Wink Savilleb564aae2014-10-23 10:18:09 -07001605 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001607 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1608 return false;
1609 }
Wink Saville36469e72014-06-11 15:17:00 -07001610 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001611 }
1612
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001613 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001614 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001615 }
1616
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001617 public int getCallStateForSlot(int slotIndex) {
1618 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001619 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001620 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
1622
Sanket Padawe356d7632015-06-22 14:03:32 -07001623 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001625 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001626 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001627 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001628 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001629 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 }
1632
Sanket Padawe356d7632015-06-22 14:03:32 -07001633 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001635 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001636 if (phone != null) {
1637 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1638 } else {
1639 return TelephonyManager.DATA_ACTIVITY_NONE;
1640 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 }
1642
1643 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001644 public Bundle getCellLocation(String callingPackage) {
1645 enforceFineOrCoarseLocationPermission("getCellLocation");
1646
1647 // OP_COARSE_LOCATION controls both fine and coarse location.
1648 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1649 callingPackage) != AppOpsManager.MODE_ALLOWED) {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001650 log("getCellLocation: returning null; mode != allowed");
Svetoslav64fad262015-04-14 14:35:21 -07001651 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 }
1653
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001654 if (checkIfCallerIsSelfOrForegroundUser() ||
1655 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 if (DBG_LOC) log("getCellLocation: is active user");
1657 Bundle data = new Bundle();
Legler Wu2c01cdf2014-12-08 19:00:59 +08001658 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001659 if (phone == null) {
1660 return null;
1661 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001662
1663 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1664 phone.getCellLocation(workSource).fillInNotifierBundle(data);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 return data;
1666 } else {
Amit Mahajan9acc70d2015-06-02 13:17:33 -07001667 log("getCellLocation: suppress non-active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 return null;
1669 }
1670 }
1671
Svetoslav64fad262015-04-14 14:35:21 -07001672 private void enforceFineOrCoarseLocationPermission(String message) {
1673 try {
1674 mApp.enforceCallingOrSelfPermission(
1675 android.Manifest.permission.ACCESS_FINE_LOCATION, null);
1676 } catch (SecurityException e) {
1677 // If we have ACCESS_FINE_LOCATION permission, skip the check for ACCESS_COARSE_LOCATION
1678 // A failure should throw the SecurityException from ACCESS_COARSE_LOCATION since this
1679 // is the weaker precondition
1680 mApp.enforceCallingOrSelfPermission(
1681 android.Manifest.permission.ACCESS_COARSE_LOCATION, message);
1682 }
1683 }
1684
1685
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001687 public String getNetworkCountryIsoForPhone(int phoneId) {
1688 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1689 // registered cell info, so return a NULL country instead.
1690 final long identity = Binder.clearCallingIdentity();
1691 try {
1692 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1693 if (TelephonyManager.NETWORK_TYPE_IWLAN
1694 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1695 return "";
1696 }
1697 } finally {
1698 Binder.restoreCallingIdentity(identity);
1699 }
1700 return TelephonyManager.getTelephonyProperty(
1701 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1702 }
1703
1704 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001706 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001707 }
1708
Sanket Padawe356d7632015-06-22 14:03:32 -07001709 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001710 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 mApp.enforceCallingOrSelfPermission(
1712 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001713 final Phone phone = getPhone(subId);
1714 if (phone != null) {
1715 phone.enableLocationUpdates();
1716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717 }
1718
1719 @Override
1720 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001721 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001722 }
1723
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001725 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 mApp.enforceCallingOrSelfPermission(
1727 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001728 final Phone phone = getPhone(subId);
1729 if (phone != null) {
1730 phone.disableLocationUpdates();
1731 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 }
1733
1734 @Override
1735 @SuppressWarnings("unchecked")
1736 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav64fad262015-04-14 14:35:21 -07001737 enforceFineOrCoarseLocationPermission("getNeighboringCellInfo");
1738
1739 // OP_COARSE_LOCATION controls both fine and coarse location.
1740 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1741 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1742 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 }
1744
1745 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1746 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1747 return null;
1748 }
Svetoslav64fad262015-04-14 14:35:21 -07001749
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001750 if (checkIfCallerIsSelfOrForegroundUser() ||
1751 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
1753
1754 ArrayList<NeighboringCellInfo> cells = null;
1755
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001756 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 try {
1758 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001759 CMD_HANDLE_NEIGHBORING_CELL, workSource,
Sanket Padawe56e75a32016-02-08 12:18:19 -08001760 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 } catch (RuntimeException e) {
Wink Saville36469e72014-06-11 15:17:00 -07001762 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001763 }
1764 return cells;
1765 } else {
1766 if (DBG_LOC) log("getNeighboringCellInfo: suppress non-active user");
1767 return null;
1768 }
1769 }
1770
1771
1772 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001773 public List<CellInfo> getAllCellInfo(String callingPackage) {
1774 enforceFineOrCoarseLocationPermission("getAllCellInfo");
1775
1776 // OP_COARSE_LOCATION controls both fine and coarse location.
1777 if (mAppOps.noteOp(AppOpsManager.OP_COARSE_LOCATION, Binder.getCallingUid(),
1778 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1779 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001780 }
1781
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001782 if (checkIfCallerIsSelfOrForegroundUser() ||
1783 checkCallerInteractAcrossUsersFull()) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784 if (DBG_LOC) log("getAllCellInfo: is active user");
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001785 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
Legler Wu2c01cdf2014-12-08 19:00:59 +08001786 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1787 for (Phone phone : PhoneFactory.getPhones()) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001788 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1789 if (info != null) cellInfos.addAll(info);
Legler Wu2c01cdf2014-12-08 19:00:59 +08001790 }
1791 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 } else {
1793 if (DBG_LOC) log("getAllCellInfo: suppress non-active user");
1794 return null;
1795 }
1796 }
1797
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001798 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001799 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001800 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001801 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1802 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 }
1804
Shishir Agrawala9f32182016-04-12 12:00:16 -07001805 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001806 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001807 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1808 return null;
1809 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001810 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001811 return phone == null ? null : phone.getImei();
1812 }
1813
1814 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001815 public String getMeidForSlot(int slotIndex, String callingPackage) {
1816 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1817 return null;
1818 }
1819 Phone phone = PhoneFactory.getPhone(slotIndex);
1820 return phone == null ? null : phone.getMeid();
1821 }
1822
1823 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001824 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001825 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1826 return null;
1827 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001828 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001829 return phone == null ? null : phone.getDeviceSvn();
1830 }
1831
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 //
1833 // Internal helper methods.
1834 //
1835
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001836 /**
1837 * Returns true if the caller holds INTERACT_ACROSS_USERS_FULL.
1838 */
1839 private boolean checkCallerInteractAcrossUsersFull() {
1840 return mPhone.getContext().checkCallingOrSelfPermission(
1841 android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
1842 == PackageManager.PERMISSION_GRANTED;
1843 }
1844
Jake Hambye994d462014-02-03 13:10:13 -08001845 private static boolean checkIfCallerIsSelfOrForegroundUser() {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 boolean ok;
1847
1848 boolean self = Binder.getCallingUid() == Process.myUid();
1849 if (!self) {
1850 // Get the caller's user id then clear the calling identity
1851 // which will be restored in the finally clause.
1852 int callingUser = UserHandle.getCallingUserId();
1853 long ident = Binder.clearCallingIdentity();
1854
1855 try {
1856 // With calling identity cleared the current user is the foreground user.
1857 int foregroundUser = ActivityManager.getCurrentUser();
1858 ok = (foregroundUser == callingUser);
1859 if (DBG_LOC) {
1860 log("checkIfCallerIsSelfOrForegoundUser: foregroundUser=" + foregroundUser
1861 + " callingUser=" + callingUser + " ok=" + ok);
1862 }
1863 } catch (Exception ex) {
1864 if (DBG_LOC) loge("checkIfCallerIsSelfOrForegoundUser: Exception ex=" + ex);
1865 ok = false;
1866 } finally {
1867 Binder.restoreCallingIdentity(ident);
1868 }
1869 } else {
1870 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: is self");
1871 ok = true;
1872 }
1873 if (DBG_LOC) log("checkIfCallerIsSelfOrForegoundUser: ret=" + ok);
1874 return ok;
1875 }
1876
1877 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1879 *
1880 * @throws SecurityException if the caller does not have the required permission
1881 */
1882 private void enforceModifyPermission() {
1883 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1884 }
1885
1886 /**
Junda Liua2e36012014-07-09 18:30:01 -07001887 * Make sure either system app or the caller has carrier privilege.
1888 *
1889 * @throws SecurityException if the caller does not have the required permission/privilege
1890 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001891 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001892 int permission = mApp.checkCallingOrSelfPermission(
1893 android.Manifest.permission.MODIFY_PHONE_STATE);
1894 if (permission == PackageManager.PERMISSION_GRANTED) {
1895 return;
1896 }
1897
1898 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001899 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001900 }
1901
1902 /**
1903 * Make sure the caller has carrier privilege.
1904 *
1905 * @throws SecurityException if the caller does not have the required permission
1906 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001907 private void enforceCarrierPrivilege(int subId) {
1908 if (getCarrierPrivilegeStatus(subId) !=
1909 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001910 loge("No Carrier Privilege.");
1911 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001912 }
1913 }
1914
1915 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 * Make sure the caller has the CALL_PHONE permission.
1917 *
1918 * @throws SecurityException if the caller does not have the required permission
1919 */
1920 private void enforceCallPermission() {
1921 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1922 }
1923
Stuart Scott8eef64f2015-04-08 15:13:54 -07001924 private void enforceConnectivityInternalPermission() {
1925 mApp.enforceCallingOrSelfPermission(
1926 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1927 "ConnectivityService");
1928 }
1929
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930 private String createTelUrl(String number) {
1931 if (TextUtils.isEmpty(number)) {
1932 return null;
1933 }
1934
Jake Hambye994d462014-02-03 13:10:13 -08001935 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
Ihab Awadf9e92732013-12-05 18:02:52 -08001938 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1940 }
1941
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001942 private static void logv(String msg) {
1943 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1944 }
1945
Ihab Awadf9e92732013-12-05 18:02:52 -08001946 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1948 }
1949
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001950 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001952 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001953 }
1954
Sanket Padawe356d7632015-06-22 14:03:32 -07001955 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001956 public int getActivePhoneTypeForSlot(int slotIndex) {
1957 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001958 if (phone == null) {
1959 return PhoneConstants.PHONE_TYPE_NONE;
1960 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001961 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963 }
1964
1965 /**
1966 * Returns the CDMA ERI icon index to display
1967 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001968 @Override
1969 public int getCdmaEriIconIndex(String callingPackage) {
1970 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001971 }
1972
Sanket Padawe356d7632015-06-22 14:03:32 -07001973 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001974 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1975 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1976 return -1;
1977 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001978 final Phone phone = getPhone(subId);
1979 if (phone != null) {
1980 return phone.getCdmaEriIconIndex();
1981 } else {
1982 return -1;
1983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 }
1985
1986 /**
1987 * Returns the CDMA ERI icon mode,
1988 * 0 - ON
1989 * 1 - FLASHING
1990 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001991 @Override
1992 public int getCdmaEriIconMode(String callingPackage) {
1993 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001994 }
1995
Sanket Padawe356d7632015-06-22 14:03:32 -07001996 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001997 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1998 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1999 return -1;
2000 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002001 final Phone phone = getPhone(subId);
2002 if (phone != null) {
2003 return phone.getCdmaEriIconMode();
2004 } else {
2005 return -1;
2006 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007 }
2008
2009 /**
2010 * Returns the CDMA ERI text,
2011 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002012 @Override
2013 public String getCdmaEriText(String callingPackage) {
2014 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002015 }
2016
Sanket Padawe356d7632015-06-22 14:03:32 -07002017 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002018 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
2019 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
2020 return null;
2021 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002022 final Phone phone = getPhone(subId);
2023 if (phone != null) {
2024 return phone.getCdmaEriText();
2025 } else {
2026 return null;
2027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 }
2029
2030 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002031 * Returns the CDMA MDN.
2032 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002033 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002034 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002035 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002036 final Phone phone = getPhone(subId);
2037 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2038 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002039 } else {
2040 return null;
2041 }
2042 }
2043
2044 /**
2045 * Returns the CDMA MIN.
2046 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002047 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002048 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002049 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07002050 final Phone phone = getPhone(subId);
2051 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2052 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002053 } else {
2054 return null;
2055 }
2056 }
2057
2058 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002059 * Returns true if CDMA provisioning needs to run.
2060 */
2061 public boolean needsOtaServiceProvisioning() {
2062 return mPhone.needsOtaServiceProvisioning();
2063 }
2064
2065 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002066 * Sets the voice mail number of a given subId.
2067 */
2068 @Override
2069 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002070 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002071 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2072 new Pair<String, String>(alphaTag, number), new Integer(subId));
2073 return success;
2074 }
2075
Ta-wei Yen87c49842016-05-13 21:19:52 -07002076 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002077 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2078 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2079 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2080 if (!TextUtils.equals(callingPackage, systemDialer)) {
2081 throw new SecurityException("caller must be system dialer");
2082 }
2083 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2084 if (phoneAccountHandle == null){
2085 return null;
2086 }
2087 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2088 }
2089
2090 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002091 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002092 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2093 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2094 return null;
2095 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002096 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2097 }
2098
2099 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002100 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2101 VisualVoicemailSmsFilterSettings settings) {
2102 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002103 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002104 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2105 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002106 }
2107
2108 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002109 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2110 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002111 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002112 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002113 }
2114
2115 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002116 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2117 String callingPackage, int subId) {
2118 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002119 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002120 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002121 }
2122
2123 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002124 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002125 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002126 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002127 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2128 }
2129
2130 @Override
2131 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2132 String number, int port, String text, PendingIntent sentIntent) {
2133 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002134 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002135 enforceSendSmsPermission();
2136 // Make the calls as the phone process.
2137 final long identity = Binder.clearCallingIdentity();
2138 try {
2139 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2140 if (port == 0) {
2141 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2142 sentIntent, null, false);
2143 } else {
2144 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2145 smsManager.sendDataMessageWithSelfPermissions(number, null,
2146 (short) port, data, sentIntent, null);
2147 }
2148 } finally {
2149 Binder.restoreCallingIdentity(identity);
2150 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002151 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002152 /**
fionaxu0152e512016-11-14 13:36:14 -08002153 * Sets the voice activation state of a given subId.
2154 */
2155 @Override
2156 public void setVoiceActivationState(int subId, int activationState) {
2157 enforceModifyPermissionOrCarrierPrivilege(subId);
2158 final Phone phone = getPhone(subId);
2159 if (phone != null) {
2160 phone.setVoiceActivationState(activationState);
2161 } else {
2162 loge("setVoiceActivationState fails with invalid subId: " + subId);
2163 }
2164 }
2165
2166 /**
2167 * Sets the data activation state of a given subId.
2168 */
2169 @Override
2170 public void setDataActivationState(int subId, int activationState) {
2171 enforceModifyPermissionOrCarrierPrivilege(subId);
2172 final Phone phone = getPhone(subId);
2173 if (phone != null) {
2174 phone.setDataActivationState(activationState);
2175 } else {
2176 loge("setVoiceActivationState fails with invalid subId: " + subId);
2177 }
2178 }
2179
2180 /**
2181 * Returns the voice activation state of a given subId.
2182 */
2183 @Override
2184 public int getVoiceActivationState(int subId, String callingPackage) {
2185 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2186 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2187 }
2188 final Phone phone = getPhone(subId);
2189 if (phone != null) {
2190 return phone.getVoiceActivationState();
2191 } else {
2192 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2193 }
2194 }
2195
2196 /**
2197 * Returns the data activation state of a given subId.
2198 */
2199 @Override
2200 public int getDataActivationState(int subId, String callingPackage) {
2201 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2202 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2203 }
2204 final Phone phone = getPhone(subId);
2205 if (phone != null) {
2206 return phone.getDataActivationState();
2207 } else {
2208 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2209 }
2210 }
2211
2212 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213 * Returns the unread count of voicemails
2214 */
2215 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002216 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002217 }
2218
2219 /**
2220 * Returns the unread count of voicemails for a subId
2221 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002222 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002223 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002224 final Phone phone = getPhone(subId);
2225 if (phone != null) {
2226 return phone.getVoiceMessageCount();
2227 } else {
2228 return 0;
2229 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 }
2231
2232 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002233 * returns true, if the device is in a state where both voice and data
2234 * are supported simultaneously. This can change based on location or network condition.
2235 */
2236 @Override
2237 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2238 final Phone phone = getPhone(subId);
2239 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2240 }
2241
2242 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002243 * Send the dialer code if called from the current default dialer or the caller has
2244 * carrier privilege.
2245 * @param inputCode The dialer code to send
2246 */
2247 @Override
2248 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2249 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2250 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2251 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2252 enforceCarrierPrivilege(getDefaultSubscription());
2253 }
2254 mPhone.sendDialerSpecialCode(inputCode);
2255 }
2256
2257 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002258 * Returns the data network type.
2259 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 *
2261 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2262 */
2263 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002264 public int getNetworkType() {
2265 final Phone phone = getPhone(getDefaultSubscription());
2266 if (phone != null) {
2267 return phone.getServiceState().getDataNetworkType();
2268 } else {
2269 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2270 }
Wink Saville36469e72014-06-11 15:17:00 -07002271 }
2272
2273 /**
2274 * Returns the network type for a subId
2275 */
2276 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002277 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2278 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2279 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2280 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002281
Sanket Padawe356d7632015-06-22 14:03:32 -07002282 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002283 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002284 return phone.getServiceState().getDataNetworkType();
2285 } else {
2286 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2287 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 }
2289
2290 /**
2291 * Returns the data network type
2292 */
2293 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002294 public int getDataNetworkType(String callingPackage) {
2295 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002296 }
2297
2298 /**
2299 * Returns the data network type for a subId
2300 */
2301 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002302 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2303 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2304 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2305 }
2306
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 final Phone phone = getPhone(subId);
2308 if (phone != null) {
2309 return phone.getServiceState().getDataNetworkType();
2310 } else {
2311 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2312 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 }
2314
2315 /**
Wink Saville36469e72014-06-11 15:17:00 -07002316 * Returns the Voice network type for a subId
2317 */
2318 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002319 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2320 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2321 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2322 }
2323
Sanket Padawe356d7632015-06-22 14:03:32 -07002324 final Phone phone = getPhone(subId);
2325 if (phone != null) {
2326 return phone.getServiceState().getVoiceNetworkType();
2327 } else {
2328 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 }
2331
2332 /**
2333 * @return true if a ICC card is present
2334 */
2335 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002336 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002337 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2338 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002339 }
2340
2341 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002342 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002343 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002344 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002345 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2346 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002347 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002348 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002349 } else {
2350 return false;
2351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 }
2353
2354 /**
2355 * Return if the current radio is LTE on CDMA. This
2356 * is a tri-state return value as for a period of time
2357 * the mode may be unknown.
2358 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002359 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002361 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002363 @Override
2364 public int getLteOnCdmaMode(String callingPackage) {
2365 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002366 }
2367
Sanket Padawe356d7632015-06-22 14:03:32 -07002368 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002369 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2370 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2371 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2372 }
2373
Sanket Padawe356d7632015-06-22 14:03:32 -07002374 final Phone phone = getPhone(subId);
2375 if (phone == null) {
2376 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2377 } else {
2378 return phone.getLteOnCdmaMode();
2379 }
Wink Saville36469e72014-06-11 15:17:00 -07002380 }
2381
2382 public void setPhone(Phone phone) {
2383 mPhone = phone;
2384 }
2385
2386 /**
2387 * {@hide}
2388 * Returns Default subId, 0 in the case of single standby.
2389 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002390 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002391 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002392 }
2393
Shishir Agrawala9f32182016-04-12 12:00:16 -07002394 private int getSlotForDefaultSubscription() {
2395 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2396 }
2397
Wink Savilleb564aae2014-10-23 10:18:09 -07002398 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002399 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002401
2402 /**
2403 * @see android.telephony.TelephonyManager.WifiCallingChoices
2404 */
2405 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002406 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2407 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002408 }
2409
2410 /**
2411 * @see android.telephony.TelephonyManager.WifiCallingChoices
2412 */
2413 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002414 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2415 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2416 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002417 }
2418
Sailesh Nepald1e68152013-12-12 19:08:02 -08002419 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002420 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002421 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002422 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002423
Shishir Agrawal566b7612013-10-28 14:41:00 -07002424 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002425 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2426 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002427 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002428
Derek Tan740e1672017-06-27 14:56:27 -07002429 if (TextUtils.equals(ISDR_AID, aid)) {
2430 // Only allows LPA to open logical channel to ISD-R.
2431 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2432 ComponentInfo bestComponent =
2433 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2434 if (bestComponent == null
2435 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2436 loge("The calling package is not allowed to access ISD-R.");
2437 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2438 }
2439 }
2440
2441 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002442 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002443 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002444 if (DBG) log("iccOpenLogicalChannel: " + response);
2445 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002446 }
2447
2448 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002449 public boolean iccCloseLogicalChannel(int subId, int channel) {
2450 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002451
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002452 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002453 if (channel < 0) {
2454 return false;
2455 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002456 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002457 if (DBG) log("iccCloseLogicalChannel: " + success);
2458 return success;
2459 }
2460
2461 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002462 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002463 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002464 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002465
2466 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002467 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2468 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002469 " data=" + data);
2470 }
2471
2472 if (channel < 0) {
2473 return "";
2474 }
2475
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002476 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002477 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002478 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2479
Shishir Agrawal566b7612013-10-28 14:41:00 -07002480 // Append the returned status code to the end of the response payload.
2481 String s = Integer.toHexString(
2482 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002483 if (response.payload != null) {
2484 s = IccUtils.bytesToHexString(response.payload) + s;
2485 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002486 return s;
2487 }
Jake Hambye994d462014-02-03 13:10:13 -08002488
Evan Charltonc66da362014-05-16 14:06:40 -07002489 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002490 public String iccTransmitApduBasicChannel(int subId, int cla, int command, int p1, int p2,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002491 int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002492 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002493
2494 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002495 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2496 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002497 }
2498
2499 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002500 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002501 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2502
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002503 // Append the returned status code to the end of the response payload.
2504 String s = Integer.toHexString(
2505 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002506 if (response.payload != null) {
2507 s = IccUtils.bytesToHexString(response.payload) + s;
2508 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002509 return s;
2510 }
2511
2512 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002513 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002514 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002515 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002516
2517 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002518 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002519 p1 + " " + p2 + " " + p3 + ":" + filePath);
2520 }
2521
2522 IccIoResult response =
2523 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002524 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2525 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002526
2527 if (DBG) {
2528 log("Exchange SIM_IO [R]" + response);
2529 }
2530
2531 byte[] result = null;
2532 int length = 2;
2533 if (response.payload != null) {
2534 length = 2 + response.payload.length;
2535 result = new byte[length];
2536 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2537 } else {
2538 result = new byte[length];
2539 }
2540
2541 result[length - 1] = (byte) response.sw2;
2542 result[length - 2] = (byte) response.sw1;
2543 return result;
2544 }
2545
Nathan Haroldb3014052017-01-25 15:57:32 -08002546 /**
2547 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2548 * on a particular subscription
2549 */
2550 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002551 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2552 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002553 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2554 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2555 return null;
2556 }
2557 Object response = sendRequest(
2558 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2559 if (response instanceof String[]) {
2560 return (String[]) response;
2561 }
2562 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2563 return null;
2564 }
2565
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002566 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002567 public String sendEnvelopeWithStatus(int subId, String content) {
2568 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002569
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002570 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002571 if (response.payload == null) {
2572 return "";
2573 }
2574
2575 // Append the returned status code to the end of the response payload.
2576 String s = Integer.toHexString(
2577 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2578 s = IccUtils.bytesToHexString(response.payload) + s;
2579 return s;
2580 }
2581
Jake Hambye994d462014-02-03 13:10:13 -08002582 /**
2583 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2584 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2585 *
2586 * @param itemID the ID of the item to read
2587 * @return the NV item as a String, or null on error.
2588 */
2589 @Override
2590 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002591 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002592 if (DBG) log("nvReadItem: item " + itemID);
2593 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2594 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2595 return value;
2596 }
2597
2598 /**
2599 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2600 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2601 *
2602 * @param itemID the ID of the item to read
2603 * @param itemValue the value to write, as a String
2604 * @return true on success; false on any failure
2605 */
2606 @Override
2607 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002608 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002609 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2610 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2611 new Pair<Integer, String>(itemID, itemValue));
2612 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2613 return success;
2614 }
2615
2616 /**
2617 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2618 * Used for device configuration by some CDMA operators.
2619 *
2620 * @param preferredRoamingList byte array containing the new PRL
2621 * @return true on success; false on any failure
2622 */
2623 @Override
2624 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002625 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002626 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2627 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2628 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2629 return success;
2630 }
2631
2632 /**
2633 * Perform the specified type of NV config reset.
2634 * Used for device configuration by some CDMA operators.
2635 *
2636 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2637 * @return true on success; false on any failure
2638 */
2639 @Override
2640 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002641 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002642 if (DBG) log("nvResetConfig: type " + resetType);
2643 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2644 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2645 return success;
2646 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002647
2648 /**
Wink Saville36469e72014-06-11 15:17:00 -07002649 * {@hide}
2650 * Returns Default sim, 0 in the case of single standby.
2651 */
2652 public int getDefaultSim() {
2653 //TODO Need to get it from Telephony Devcontroller
2654 return 0;
2655 }
2656
Svet Ganovb320e182015-04-16 12:30:10 -07002657 public String[] getPcscfAddress(String apnType, String callingPackage) {
2658 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2659 return new String[0];
2660 }
2661
2662
ram87fca6f2014-07-18 18:58:44 +05302663 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002664 }
2665
Brad Ebinger51f743a2017-01-23 13:50:20 -08002666 /**
Brad Ebinger34bef922017-11-09 10:27:08 -08002667 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2668 * feature or {@link null} if the service is not available. If the feature is available, the
2669 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002670 */
Brad Ebinger34bef922017-11-09 10:27:08 -08002671 public IImsMMTelFeature getMMTelFeatureAndListen(int slotId,
2672 IImsServiceFeatureCallback callback) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002673 enforceModifyPermission();
Brad Ebinger34bef922017-11-09 10:27:08 -08002674 return PhoneFactory.getImsResolver().getMMTelFeatureAndListen(slotId, callback);
2675 }
2676
2677 /**
2678 * Returns the {@link IImsMMTelFeature} that corresponds to the given slot Id for the MMTel
2679 * feature during emergency calling or {@link null} if the service is not available. If the
2680 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2681 * listener for feature updates.
2682 */
2683 public IImsMMTelFeature getEmergencyMMTelFeatureAndListen(int slotId,
2684 IImsServiceFeatureCallback callback) {
2685 enforceModifyPermission();
2686 return PhoneFactory.getImsResolver().getEmergencyMMTelFeatureAndListen(slotId, callback);
2687 }
2688
2689 /**
2690 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2691 * feature during emergency calling or {@link null} if the service is not available. If the
2692 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2693 * listener for feature updates.
2694 */
2695 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2696 enforceModifyPermission();
2697 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002698 }
2699
Wink Saville36469e72014-06-11 15:17:00 -07002700 public void setImsRegistrationState(boolean registered) {
2701 enforceModifyPermission();
2702 mPhone.setImsRegistrationState(registered);
2703 }
2704
2705 /**
Stuart Scott54788802015-03-30 13:18:01 -07002706 * Set the network selection mode to automatic.
2707 *
2708 */
2709 @Override
2710 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002711 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002712 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2713 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2714 }
2715
2716 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002717 * Set the network selection mode to manual with the selected carrier.
2718 */
2719 @Override
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002720 public boolean setNetworkSelectionModeManual(int subId, OperatorInfo operator,
2721 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002722 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002723 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002724 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2725 persistSelection);
2726 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002727 }
2728
2729 /**
2730 * Scans for available networks.
2731 */
2732 @Override
2733 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002734 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002735 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2736 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2737 CMD_PERFORM_NETWORK_SCAN, null, subId);
2738 return result;
2739 }
2740
2741 /**
yinxub1bed742017-04-17 11:45:04 -07002742 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002743 *
yinxub1bed742017-04-17 11:45:04 -07002744 * @param subId id of the subscription
2745 * @param request contains the radio access networks with bands/channels to scan
2746 * @param messenger callback messenger for scan results or errors
2747 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002748 * @return the id of the requested scan which can be used to stop the scan.
2749 */
2750 @Override
2751 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2752 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002753 enforceModifyPermissionOrCarrierPrivilege(subId);
2754 return mNetworkScanRequestTracker.startNetworkScan(
2755 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002756 }
2757
2758 /**
2759 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002760 *
2761 * @param subId id of the subscription
2762 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002763 */
2764 @Override
2765 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002766 enforceModifyPermissionOrCarrierPrivilege(subId);
2767 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002768 }
2769
2770 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002771 * Get the calculated preferred network type.
2772 * Used for debugging incorrect network type.
2773 *
2774 * @return the preferred network type, defined in RILConstants.java.
2775 */
2776 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002777 public int getCalculatedPreferredNetworkType(String callingPackage) {
2778 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2779 return RILConstants.PREFERRED_NETWORK_MODE;
2780 }
2781
Amit Mahajan43330e02014-11-18 11:54:45 -08002782 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002783 }
2784
2785 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002786 * Get the preferred network type.
2787 * Used for device configuration by some CDMA operators.
2788 *
2789 * @return the preferred network type, defined in RILConstants.java.
2790 */
2791 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002792 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002793 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002794 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002795 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002796 int networkType = (result != null ? result[0] : -1);
2797 if (DBG) log("getPreferredNetworkType: " + networkType);
2798 return networkType;
2799 }
2800
2801 /**
2802 * Set the preferred network type.
2803 * Used for device configuration by some CDMA operators.
2804 *
2805 * @param networkType the preferred network type, defined in RILConstants.java.
2806 * @return true on success; false on any failure.
2807 */
2808 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002809 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002810 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002811 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2812 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002813 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002814 if (success) {
2815 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002816 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002817 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002818 return success;
2819 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002820
2821 /**
Junda Liu475951f2014-11-07 16:45:03 -08002822 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2823 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2824 * tethering.
2825 *
2826 * @return 0: Not required. 1: required. 2: Not set.
2827 * @hide
2828 */
2829 @Override
2830 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002831 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002832 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2833 Settings.Global.TETHER_DUN_REQUIRED, 2);
2834 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2835 // config_tether_apndata.
2836 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2837 dunRequired = 1;
2838 }
2839 return dunRequired;
2840 }
2841
2842 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002843 * Set mobile data enabled
2844 * Used by the user through settings etc to turn on/off mobile data
2845 *
2846 * @param enable {@code true} turn turn data on, else {@code false}
2847 */
2848 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002849 public void setDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002850 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002851 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002852 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002853 Phone phone = PhoneFactory.getPhone(phoneId);
2854 if (phone != null) {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002855 if (DBG) log("setDataEnabled: subId=" + subId + " enable=" + enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002856 phone.setDataEnabled(enable);
2857 } else {
2858 loge("setDataEnabled: no phone for subId=" + subId);
2859 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002860 }
2861
2862 /**
Robert Greenwalt646120a2014-05-23 11:54:03 -07002863 * Get whether mobile data is enabled.
2864 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002865 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002866 *
2867 * @return {@code true} if data is enabled else {@code false}
2868 */
2869 @Override
Wink Savillee7353bb2014-12-05 14:21:41 -08002870 public boolean getDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002871 try {
2872 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2873 null);
2874 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002875 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002876 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002877 int phoneId = mSubscriptionController.getPhoneId(subId);
Joe Onoratoa601dd22016-02-23 13:03:53 -08002878 if (DBG) log("getDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002879 Phone phone = PhoneFactory.getPhone(phoneId);
2880 if (phone != null) {
2881 boolean retVal = phone.getDataEnabled();
Joe Onoratoa601dd22016-02-23 13:03:53 -08002882 if (DBG) log("getDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002883 return retVal;
2884 } else {
Joe Onoratoa601dd22016-02-23 13:03:53 -08002885 if (DBG) loge("getDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002886 return false;
2887 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002888 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002889
2890 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002891 public int getCarrierPrivilegeStatus(int subId) {
2892 final Phone phone = getPhone(subId);
2893 if (phone == null) {
2894 loge("getCarrierPrivilegeStatus: Invalid subId");
2895 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2896 }
2897 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002898 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002899 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002900 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2901 }
2902 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002903 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002904 }
Junda Liu29340342014-07-10 15:23:27 -07002905
2906 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002907 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002908 if (TextUtils.isEmpty(pkgName))
2909 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002910 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002911 if (card == null) {
2912 loge("checkCarrierPrivilegesForPackage: No UICC");
2913 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2914 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002915 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2916 }
2917
2918 @Override
2919 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002920 if (TextUtils.isEmpty(pkgName))
2921 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002922 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2923 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2924 UiccCard card = UiccController.getInstance().getUiccCard(i);
2925 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002926 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002927 continue;
2928 }
2929
2930 result = card.getCarrierPrivilegeStatus(
2931 mPhone.getContext().getPackageManager(), pkgName);
2932 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2933 break;
2934 }
2935 }
2936
2937 return result;
Junda Liu29340342014-07-10 15:23:27 -07002938 }
Derek Tan89e89d42014-07-08 17:00:10 -07002939
2940 @Override
Junda Liue64de782015-04-16 17:19:16 -07002941 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2942 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2943 loge("phoneId " + phoneId + " is not valid.");
2944 return null;
2945 }
2946 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002947 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002948 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002949 return null ;
2950 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002951 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002952 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002953 }
2954
Amith Yamasani6e118872016-02-19 12:53:51 -08002955 @Override
2956 public List<String> getPackagesWithCarrierPrivileges() {
2957 PackageManager pm = mPhone.getContext().getPackageManager();
2958 List<String> privilegedPackages = new ArrayList<>();
2959 List<PackageInfo> packages = null;
2960 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2961 UiccCard card = UiccController.getInstance().getUiccCard(i);
2962 if (card == null) {
2963 // No UICC in that slot.
2964 continue;
2965 }
2966 if (card.hasCarrierPrivilegeRules()) {
2967 if (packages == null) {
2968 // Only check packages in user 0 for now
2969 packages = pm.getInstalledPackagesAsUser(
2970 PackageManager.MATCH_DISABLED_COMPONENTS
2971 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
2972 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
2973 }
2974 for (int p = packages.size() - 1; p >= 0; p--) {
2975 PackageInfo pkgInfo = packages.get(p);
2976 if (pkgInfo != null && pkgInfo.packageName != null
2977 && card.getCarrierPrivilegeStatus(pkgInfo)
2978 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2979 privilegedPackages.add(pkgInfo.packageName);
2980 }
2981 }
2982 }
2983 }
2984 return privilegedPackages;
2985 }
2986
Wink Savilleb564aae2014-10-23 10:18:09 -07002987 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002988 final Phone phone = getPhone(subId);
2989 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07002990 if (card == null) {
2991 loge("getIccId: No UICC");
2992 return null;
2993 }
2994 String iccId = card.getIccId();
2995 if (TextUtils.isEmpty(iccId)) {
2996 loge("getIccId: ICC ID is null or empty.");
2997 return null;
2998 }
2999 return iccId;
3000 }
3001
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003002 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003003 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3004 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003005 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07003006
Jeff Sharkey85190e62014-12-05 09:40:12 -08003007 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003008 final Phone phone = getPhone(subId);
3009 if (phone == null) {
3010 return false;
3011 }
3012 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003013
3014 if (DBG_MERGE) {
3015 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3016 + subscriberId + " to " + number);
3017 }
3018
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003019 if (TextUtils.isEmpty(iccId)) {
3020 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003021 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003022
Jeff Sharkey85190e62014-12-05 09:40:12 -08003023 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3024
3025 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003026 if (alphaTag == null) {
3027 editor.remove(alphaTagPrefKey);
3028 } else {
3029 editor.putString(alphaTagPrefKey, alphaTag);
3030 }
3031
Jeff Sharkey85190e62014-12-05 09:40:12 -08003032 // Record both the line number and IMSI for this ICCID, since we need to
3033 // track all merged IMSIs based on line number
3034 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3035 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003036 if (number == null) {
3037 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003038 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003039 } else {
3040 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003041 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003042 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003043
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003044 editor.commit();
3045 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003046 }
3047
3048 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003049 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003050 // This is open to apps with WRITE_SMS.
3051 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003052 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003053 return null;
3054 }
Derek Tan97ebb422014-09-05 16:55:38 -07003055
3056 String iccId = getIccId(subId);
3057 if (iccId != null) {
3058 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003059 if (DBG_MERGE) {
3060 log("getLine1NumberForDisplay returning " +
3061 mTelephonySharedPreferences.getString(numberPrefKey, null));
3062 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003063 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003064 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003065 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003066 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003067 }
3068
3069 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003070 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3071 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3072 return null;
3073 }
Derek Tan97ebb422014-09-05 16:55:38 -07003074
3075 String iccId = getIccId(subId);
3076 if (iccId != null) {
3077 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003078 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003079 }
Derek Tan97ebb422014-09-05 16:55:38 -07003080 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003081 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003082
3083 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003084 public String[] getMergedSubscriberIds(String callingPackage) {
3085 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3086 return null;
3087 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003088 final Context context = mPhone.getContext();
3089 final TelephonyManager tele = TelephonyManager.from(context);
3090 final SubscriptionManager sub = SubscriptionManager.from(context);
3091
3092 // Figure out what subscribers are currently active
3093 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003094 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3095 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3096 final long identity = Binder.clearCallingIdentity();
3097 try {
3098 final int[] subIds = sub.getActiveSubscriptionIdList();
3099 for (int subId : subIds) {
3100 activeSubscriberIds.add(tele.getSubscriberId(subId));
3101 }
3102 } finally {
3103 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003104 }
3105
3106 // First pass, find a number override for an active subscriber
3107 String mergeNumber = null;
3108 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3109 for (String key : prefs.keySet()) {
3110 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3111 final String subscriberId = (String) prefs.get(key);
3112 if (activeSubscriberIds.contains(subscriberId)) {
3113 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3114 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3115 mergeNumber = (String) prefs.get(numberKey);
3116 if (DBG_MERGE) {
3117 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3118 + " for active subscriber " + subscriberId);
3119 }
3120 if (!TextUtils.isEmpty(mergeNumber)) {
3121 break;
3122 }
3123 }
3124 }
3125 }
3126
3127 // Shortcut when no active merged subscribers
3128 if (TextUtils.isEmpty(mergeNumber)) {
3129 return null;
3130 }
3131
3132 // Second pass, find all subscribers under that line override
3133 final ArraySet<String> result = new ArraySet<>();
3134 for (String key : prefs.keySet()) {
3135 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3136 final String number = (String) prefs.get(key);
3137 if (mergeNumber.equals(number)) {
3138 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3139 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3140 final String subscriberId = (String) prefs.get(subscriberKey);
3141 if (!TextUtils.isEmpty(subscriberId)) {
3142 result.add(subscriberId);
3143 }
3144 }
3145 }
3146 }
3147
3148 final String[] resultArray = result.toArray(new String[result.size()]);
3149 Arrays.sort(resultArray);
3150 if (DBG_MERGE) {
3151 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3152 }
3153 return resultArray;
3154 }
3155
3156 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003157 public boolean setOperatorBrandOverride(int subId, String brand) {
3158 enforceCarrierPrivilege(subId);
3159 final Phone phone = getPhone(subId);
3160 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003161 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003162
3163 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003164 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003165 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3166 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003167 enforceCarrierPrivilege(subId);
3168 final Phone phone = getPhone(subId);
3169 if (phone == null) {
3170 return false;
3171 }
3172 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003173 cdmaNonRoamingList);
3174 }
3175
3176 @Override
Amit Mahajanf43fe462017-02-23 12:08:31 -08003177 @Deprecated
Steven Liu4bf01bc2014-07-17 11:05:29 -05003178 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3179 enforceModifyPermission();
3180
3181 int returnValue = 0;
3182 try {
3183 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3184 if(result.exception == null) {
3185 if (result.result != null) {
3186 byte[] responseData = (byte[])(result.result);
3187 if(responseData.length > oemResp.length) {
3188 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3189 responseData.length + "bytes. Buffer Size is " +
3190 oemResp.length + "bytes.");
3191 }
3192 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3193 returnValue = responseData.length;
3194 }
3195 } else {
3196 CommandException ex = (CommandException) result.exception;
3197 returnValue = ex.getCommandError().ordinal();
3198 if(returnValue > 0) returnValue *= -1;
3199 }
3200 } catch (RuntimeException e) {
3201 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3202 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3203 if(returnValue > 0) returnValue *= -1;
3204 }
3205
3206 return returnValue;
3207 }
Wink Saville5d475dd2014-10-17 15:00:58 -07003208
3209 @Override
3210 public void setRadioCapability(RadioAccessFamily[] rafs) {
3211 try {
3212 ProxyController.getInstance().setRadioCapability(rafs);
3213 } catch (RuntimeException e) {
3214 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3215 }
3216 }
3217
3218 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003219 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3220 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3221 return RadioAccessFamily.RAF_UNKNOWN;
3222 }
3223
Wink Saville5d475dd2014-10-17 15:00:58 -07003224 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3225 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003226
3227 @Override
3228 public void enableVideoCalling(boolean enable) {
3229 enforceModifyPermission();
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003230 ImsManager.setVtSetting(mPhone.getContext(), enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003231 }
3232
3233 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003234 public boolean isVideoCallingEnabled(String callingPackage) {
3235 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3236 return false;
3237 }
3238
Andrew Lee77527ac2014-10-21 16:57:39 -07003239 // Check the user preference and the system-level IMS setting. Even if the user has
3240 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3241 // In the long run, we may instead need to check if there exists a connection service
3242 // which can support video calling.
Andrew Lee312e8172014-10-23 17:01:36 -07003243 return ImsManager.isVtEnabledByPlatform(mPhone.getContext())
3244 && ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mPhone.getContext())
Tyler Gunnfdd69de2015-12-04 21:24:38 -08003245 && ImsManager.isVtEnabledByUser(mPhone.getContext());
Andrew Leedf14ead2014-10-17 14:22:52 -07003246 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003247
Andrew Leea1239f22015-03-02 17:44:07 -08003248 @Override
3249 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003250 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003251 }
3252
3253 @Override
3254 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003255 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003256 }
3257
Andrew Lee9431b832015-03-09 18:46:45 -07003258 @Override
3259 public boolean isTtyModeSupported() {
3260 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3261 TelephonyManager telephonyManager =
3262 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003263 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003264 }
3265
3266 @Override
3267 public boolean isHearingAidCompatibilitySupported() {
3268 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3269 }
3270
Sanket Padawe7310cc72015-01-14 09:53:20 -08003271 /**
3272 * Returns the unique device ID of phone, for example, the IMEI for
3273 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3274 *
3275 * <p>Requires Permission:
3276 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3277 */
3278 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003279 public String getDeviceId(String callingPackage) {
3280 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3281 return null;
3282 }
3283
Sanket Padawe7310cc72015-01-14 09:53:20 -08003284 final Phone phone = PhoneFactory.getPhone(0);
3285 if (phone != null) {
3286 return phone.getDeviceId();
3287 } else {
3288 return null;
3289 }
3290 }
3291
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003292 /*
3293 * {@hide}
3294 * Returns the IMS Registration Status
3295 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003296 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003297 public boolean isImsRegistered() {
3298 return mPhone.isImsRegistered();
3299 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003300
Ping Sun014fe8e2016-03-02 19:16:45 +08003301 /**
3302 * {@hide}
3303 * Returns the IMS Registration Status on a particular subid
3304 *
3305 * @param subId
3306 */
3307 public boolean isImsRegisteredForSubscriber(int subId) {
3308 Phone phone = getPhone(subId);
3309 if (phone != null) {
3310 return phone.isImsRegistered();
3311 } else {
3312 return false;
3313 }
3314 }
3315
Santos Cordon7a1885b2015-02-03 11:15:19 -08003316 @Override
3317 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3318 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3319 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003320
Nathan Haroldc55097a2015-03-11 18:14:50 -07003321 /*
3322 * {@hide}
3323 * Returns the IMS Registration Status
3324 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003325 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003326 return mPhone.isWifiCallingEnabled();
3327 }
3328
3329 /*
3330 * {@hide}
3331 * Returns the IMS Registration Status
3332 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003333 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003334 return mPhone.isVolteEnabled();
3335 }
Svet Ganovb320e182015-04-16 12:30:10 -07003336
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003337 /*
3338 * {@hide} Returns the IMS Registration Status
3339 */
3340 public boolean isVideoTelephonyAvailable() {
3341 return mPhone.isVideoEnabled();
3342 }
3343
Svet Ganovb320e182015-04-16 12:30:10 -07003344 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003345 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003346 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003347 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3348
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003349 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003350 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003351 } catch (SecurityException e) {
3352 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3353 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003354 }
Svet Ganovb320e182015-04-16 12:30:10 -07003355
3356 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3357 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3358 return false;
3359 }
3360
3361 return true;
3362 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003363
Makoto Onukifee69342015-06-29 14:44:50 -07003364 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003365 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003366 */
3367 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003368 // Default SMS app can always read it.
3369 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3370 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3371 return true;
3372 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003373
Makoto Onukie4072d12015-08-03 15:12:23 -07003374 try {
3375 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003376 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003377 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003378 // Can be read with READ_SMS too.
3379 try {
3380 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3381 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3382 if (opCode != AppOpsManager.OP_NONE) {
3383 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3384 == AppOpsManager.MODE_ALLOWED;
3385 } else {
3386 return true;
3387 }
3388 } catch (SecurityException readSmsSecurityException) {
3389 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003390 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003391 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003392 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003393 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003394 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003395 if (opCode != AppOpsManager.OP_NONE) {
3396 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3397 == AppOpsManager.MODE_ALLOWED;
3398 } else {
3399 return true;
3400 }
3401 } catch (SecurityException readPhoneNumberSecurityException) {
3402 }
3403
3404 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3405 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3406 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003407 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003408 }
3409
Stuart Scott8eef64f2015-04-08 15:13:54 -07003410 @Override
3411 public void factoryReset(int subId) {
3412 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003413 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3414 return;
3415 }
3416
Svet Ganovcc087f82015-05-12 20:35:54 -07003417 final long identity = Binder.clearCallingIdentity();
3418 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003419 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3420 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003421 // Enable data
3422 setDataEnabled(subId, true);
3423 // Set network selection mode to automatic
3424 setNetworkSelectionModeAutomatic(subId);
3425 // Set preferred mobile network type to the best available
3426 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3427 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003428 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003429 }
3430 } finally {
3431 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003432 }
3433 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003434
3435 @Override
3436 public String getLocaleFromDefaultSim() {
3437 // We query all subscriptions instead of just the active ones, because
3438 // this might be called early on in the provisioning flow when the
3439 // subscriptions potentially aren't active yet.
3440 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3441 if (slist == null || slist.isEmpty()) {
3442 return null;
3443 }
3444
3445 // This function may be called very early, say, from the setup wizard, at
3446 // which point we won't have a default subscription set. If that's the case
3447 // we just choose the first, which will be valid in "most cases".
3448 final int defaultSubId = getDefaultSubscription();
3449 SubscriptionInfo info = null;
3450 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3451 info = slist.get(0);
3452 } else {
3453 for (SubscriptionInfo item : slist) {
3454 if (item.getSubscriptionId() == defaultSubId) {
3455 info = item;
3456 break;
3457 }
3458 }
3459
3460 if (info == null) {
3461 return null;
3462 }
3463 }
3464
3465 // Try and fetch the locale from the carrier properties or from the SIM language
3466 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003467 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003468 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003469 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003470 if (defaultPhone != null) {
3471 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3472 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003473 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003474 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3475 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003476 } else {
3477 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003478 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003479 }
3480 }
3481
Narayan Kamath011676f2015-07-29 12:04:08 +01003482 // The SIM language preferences only store a language (e.g. fr = French), not an
3483 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3484 // the SIM and carrier preferences does not include a country we add the country
3485 // determined from the SIM MCC to provide an exact locale.
3486 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003487 if (mccLocale != null) {
3488 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3489 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003490 }
3491
Tony Hill183b2de2015-06-24 14:53:58 +01003492 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003493 return null;
3494 }
3495
3496 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3497 final long identity = Binder.clearCallingIdentity();
3498 try {
3499 return mSubscriptionController.getAllSubInfoList(
3500 mPhone.getContext().getOpPackageName());
3501 } finally {
3502 Binder.restoreCallingIdentity(identity);
3503 }
3504 }
3505
3506 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 return mSubscriptionController.getActiveSubscriptionInfoList(
3510 mPhone.getContext().getOpPackageName());
3511 } finally {
3512 Binder.restoreCallingIdentity(identity);
3513 }
3514 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003515
3516 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003517 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3518 * representing the state of the modem.
3519 *
3520 * NOTE: This clears the modem state, so there should only every be one caller.
3521 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003522 */
3523 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003524 public void requestModemActivityInfo(ResultReceiver result) {
3525 enforceModifyPermission();
3526
3527 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3528 Bundle bundle = new Bundle();
3529 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3530 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003531 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003532
3533 /**
3534 * {@hide}
3535 * Returns the service state information on specified subscription.
3536 */
3537 @Override
3538 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3539
3540 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3541 return null;
3542 }
3543
3544 final Phone phone = getPhone(subId);
3545 if (phone == null) {
3546 return null;
3547 }
3548
3549 return phone.getServiceState();
3550 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003551
3552 /**
3553 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3554 *
3555 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3556 * voicemail ringtone.
3557 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3558 * PhoneAccount.
3559 */
3560 @Override
3561 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003562 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003563 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003564 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003565 }
3566
fionaxu7ed723d2017-05-30 18:58:54 -07003567 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003568 }
3569
3570 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003571 * Sets the per-account voicemail ringtone.
3572 *
3573 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3574 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3575 *
3576 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3577 * voicemail ringtone.
3578 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3579 * PhoneAccount.
3580 */
3581 @Override
3582 public void setVoicemailRingtoneUri(String callingPackage,
3583 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3584 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3585 if (!TextUtils.equals(callingPackage,
3586 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3587 enforceModifyPermissionOrCarrierPrivilege(
3588 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3589 }
3590 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3591 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003592 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003593 }
fionaxu7ed723d2017-05-30 18:58:54 -07003594 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003595 }
3596
3597 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003598 * Returns whether vibration is set for voicemail notification in Phone settings.
3599 *
3600 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3601 * voicemail vibration setting.
3602 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3603 */
3604 @Override
3605 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003606 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003607 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003608 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003609 }
3610
fionaxu7ed723d2017-05-30 18:58:54 -07003611 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003612 }
3613
Youhan Wange64578a2016-05-02 15:32:42 -07003614 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003615 * Sets the per-account voicemail vibration.
3616 *
3617 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3618 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3619 *
3620 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3621 * voicemail vibration setting.
3622 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3623 * specific PhoneAccount.
3624 */
3625 @Override
3626 public void setVoicemailVibrationEnabled(String callingPackage,
3627 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3628 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3629 if (!TextUtils.equals(callingPackage,
3630 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3631 enforceModifyPermissionOrCarrierPrivilege(
3632 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3633 }
3634
3635 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3636 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003637 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003638 }
fionaxu7ed723d2017-05-30 18:58:54 -07003639 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003640 }
3641
3642 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003643 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3644 *
3645 * @throws SecurityException if the caller does not have the required permission
3646 */
3647 private void enforceReadPrivilegedPermission() {
3648 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3649 null);
3650 }
3651
3652 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003653 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3654 * permission.
3655 *
3656 * @throws SecurityException if the caller does not have the required permission
3657 */
3658 private void enforceSendSmsPermission() {
3659 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3660 }
3661
3662 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003663 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003664 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003665 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003666 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003667 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003668 ComponentName componentName =
3669 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3670 if(componentName == null) {
3671 throw new SecurityException("Caller not current active visual voicemail package[null]");
3672 }
3673 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003674 if (!callingPackage.equals(vvmPackage)) {
3675 throw new SecurityException("Caller not current active visual voicemail package[" +
3676 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003677 }
3678 }
3679
3680 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003681 * Return the application ID for the app type.
3682 *
3683 * @param subId the subscription ID that this request applies to.
3684 * @param appType the uicc app type.
3685 * @return Application ID for specificied app type, or null if no uicc.
3686 */
3687 @Override
3688 public String getAidForAppType(int subId, int appType) {
3689 enforceReadPrivilegedPermission();
3690 Phone phone = getPhone(subId);
3691 if (phone == null) {
3692 return null;
3693 }
3694 String aid = null;
3695 try {
3696 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3697 .getApplicationByType(appType).getAid();
3698 } catch (Exception e) {
3699 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3700 }
3701 return aid;
3702 }
3703
Youhan Wang4001d252016-05-11 10:29:41 -07003704 /**
3705 * Return the Electronic Serial Number.
3706 *
3707 * @param subId the subscription ID that this request applies to.
3708 * @return ESN or null if error.
3709 */
3710 @Override
3711 public String getEsn(int subId) {
3712 enforceReadPrivilegedPermission();
3713 Phone phone = getPhone(subId);
3714 if (phone == null) {
3715 return null;
3716 }
3717 String esn = null;
3718 try {
3719 esn = phone.getEsn();
3720 } catch (Exception e) {
3721 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3722 }
3723 return esn;
3724 }
3725
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003726 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003727 * Return the Preferred Roaming List Version.
3728 *
3729 * @param subId the subscription ID that this request applies to.
3730 * @return PRLVersion or null if error.
3731 */
3732 @Override
3733 public String getCdmaPrlVersion(int subId) {
3734 enforceReadPrivilegedPermission();
3735 Phone phone = getPhone(subId);
3736 if (phone == null) {
3737 return null;
3738 }
3739 String cdmaPrlVersion = null;
3740 try {
3741 cdmaPrlVersion = phone.getCdmaPrlVersion();
3742 } catch (Exception e) {
3743 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3744 }
3745 return cdmaPrlVersion;
3746 }
3747
3748 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003749 * Get snapshot of Telephony histograms
3750 * @return List of Telephony histograms
3751 * @hide
3752 */
3753 @Override
3754 public List<TelephonyHistogram> getTelephonyHistograms() {
3755 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3756 return RIL.getTelephonyRILTimingHistograms();
3757 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003758
3759 /**
3760 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003761 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003762 * Require system privileges. In the future we may add this to carrier APIs.
3763 *
3764 * @return The number of carriers set successfully, should match length of carriers
3765 */
3766 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003767 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003768 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003769
Meng Wang9b7c4e92017-02-17 11:41:27 -08003770 if (carriers == null) {
3771 throw new NullPointerException("carriers cannot be null");
3772 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003773
3774 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003775 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3776 return retVal[0];
3777 }
3778
3779 /**
3780 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003781 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003782 * Require system privileges. In the future we may add this to carrier APIs.
3783 *
3784 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3785 * means all carriers are allowed.
3786 */
3787 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003788 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003789 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003790 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003791 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3792 }
3793
fionaxu59545b42016-05-25 15:53:37 -07003794 /**
3795 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3796 * @param subId the subscription ID that this action applies to.
3797 * @param enabled control enable or disable metered apns.
3798 * {@hide}
3799 */
3800 @Override
3801 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3802 enforceModifyPermission();
3803 final Phone phone = getPhone(subId);
3804 if (phone == null) {
3805 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3806 return;
3807 }
3808 try {
3809 phone.carrierActionSetMeteredApnsEnabled(enabled);
3810 } catch (Exception e) {
3811 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3812 }
3813 }
3814
3815 /**
3816 * Action set from carrier signalling broadcast receivers to enable/disable radio
3817 * @param subId the subscription ID that this action applies to.
3818 * @param enabled control enable or disable radio.
3819 * {@hide}
3820 */
3821 @Override
3822 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3823 enforceModifyPermission();
3824 final Phone phone = getPhone(subId);
3825 if (phone == null) {
3826 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3827 return;
3828 }
3829 try {
3830 phone.carrierActionSetRadioEnabled(enabled);
3831 } catch (Exception e) {
3832 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3833 }
3834 }
3835
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003836 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003837 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3838 * network status based on which carrier apps could apply actions accordingly,
3839 * enable/disable default url handler for example.
3840 *
3841 * @param subId the subscription ID that this action applies to.
3842 * @param report control start/stop reporting the default network status.
3843 * {@hide}
3844 */
3845 @Override
3846 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3847 enforceModifyPermission();
3848 final Phone phone = getPhone(subId);
3849 if (phone == null) {
3850 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3851 return;
3852 }
3853 try {
3854 phone.carrierActionReportDefaultNetworkStatus(report);
3855 } catch (Exception e) {
3856 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3857 }
3858 }
3859
3860 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003861 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3862 * bug report is being generated.
3863 */
3864 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003865 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003866 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3867 != PackageManager.PERMISSION_GRANTED) {
3868 writer.println("Permission Denial: can't dump Phone from pid="
3869 + Binder.getCallingPid()
3870 + ", uid=" + Binder.getCallingUid()
3871 + "without permission "
3872 + android.Manifest.permission.DUMP);
3873 return;
3874 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003875 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003876 }
Jack Yueb89b242016-06-22 13:27:47 -07003877
3878 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003879 * Get aggregated video call data usage since boot.
3880 *
3881 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3882 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003883 * {@hide}
3884 */
3885 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003886 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003887 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3888 null);
3889
Jack Yu84291ec2017-05-26 16:07:50 -07003890 // NetworkStatsService keeps tracking the active network interface and identity. It
3891 // records the delta with the corresponding network identity. We just return the total video
3892 // call data usage snapshot since boot.
3893 Phone phone = getPhone(subId);
3894 if (phone != null) {
3895 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003896 }
Jack Yu84291ec2017-05-26 16:07:50 -07003897 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003898 }
Jack Yu75ab2952016-07-08 14:29:33 -07003899
3900 /**
3901 * Policy control of data connection. Usually used when data limit is passed.
3902 * @param enabled True if enabling the data, otherwise disabling.
3903 * @param subId Subscription index
3904 * {@hide}
3905 */
3906 @Override
3907 public void setPolicyDataEnabled(boolean enabled, int subId) {
3908 enforceModifyPermission();
3909 Phone phone = getPhone(subId);
3910 if (phone != null) {
3911 phone.setPolicyDataEnabled(enabled);
3912 }
3913 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003914
3915 /**
3916 * Get Client request stats
3917 * @return List of Client Request Stats
3918 * @hide
3919 */
3920 @Override
3921 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3922 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3923 return null;
3924 }
3925
3926 Phone phone = getPhone(subId);
3927 if (phone != null) {
3928 return phone.getClientRequestStats();
3929 }
3930
3931 return null;
3932 }
3933
3934 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3935 if (workSource != null) {
3936 return workSource;
3937 }
3938
3939 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3940 workSource = new WorkSource(uid, packageName);
3941 return workSource;
3942 }
Jack Yueb4124c2017-02-16 15:32:43 -08003943
3944 /**
Grace Chen70990072017-03-24 17:21:30 -07003945 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003946 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003947 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003948 * @param state State of SIM (power down, power up, pass through)
3949 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3950 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3951 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003952 *
3953 **/
3954 @Override
Grace Chen70990072017-03-24 17:21:30 -07003955 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003956 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003957 Phone phone = PhoneFactory.getPhone(slotIndex);
3958
Jack Yueb4124c2017-02-16 15:32:43 -08003959 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003960 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003961 }
3962 }
Shuo Qiandd210312017-04-12 22:11:33 +00003963
Tyler Gunn65d45c22017-06-05 11:22:26 -07003964 private boolean isUssdApiAllowed(int subId) {
3965 CarrierConfigManager configManager =
3966 (CarrierConfigManager) mPhone.getContext().getSystemService(
3967 Context.CARRIER_CONFIG_SERVICE);
3968 if (configManager == null) {
3969 return false;
3970 }
3971 PersistableBundle pb = configManager.getConfigForSubId(subId);
3972 if (pb == null) {
3973 return false;
3974 }
3975 return pb.getBoolean(
3976 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3977 }
3978
Shuo Qiandd210312017-04-12 22:11:33 +00003979 /**
3980 * Check if phone is in emergency callback mode
3981 * @return true if phone is in emergency callback mode
3982 * @param subId sub id
3983 */
3984 public boolean getEmergencyCallbackMode(int subId) {
3985 final Phone phone = getPhone(subId);
3986 if (phone != null) {
3987 return phone.isInEcm();
3988 } else {
3989 return false;
3990 }
3991 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08003992
3993 /**
3994 * Get the current signal strength information for the given subscription.
3995 * Because this information is not updated when the device is in a low power state
3996 * it should not be relied-upon to be current.
3997 * @param subId Subscription index
3998 * @return the most recent cached signal strength info from the modem
3999 */
4000 @Override
4001 public SignalStrength getSignalStrength(int subId) {
4002 Phone p = getPhone(subId);
4003 if (p == null) {
4004 return null;
4005 }
4006
4007 return p.getSignalStrength();
4008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004009}