blob: 64cfff73474e128fb9d350ffa59575612bf8b0f1 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
45import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070046import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070047import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070048import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080049import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070050import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080051import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080052import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070053import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070054import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070057import android.telephony.IccOpenLogicalChannelResponse;
Hall Liubefa7332017-11-22 17:40:08 -080058import android.telephony.LocationAccessPolicy;
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;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000071import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070072import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070073import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080074import android.telephony.ims.aidl.IImsConfig;
75import android.telephony.ims.aidl.IImsMmTelFeature;
76import android.telephony.ims.aidl.IImsRcsFeature;
77import android.telephony.ims.aidl.IImsRegistration;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070078import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080079import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080082import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080083
Andrew Lee312e8172014-10-23 17:01:36 -070084import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080085import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070086import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070087import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070088import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070089import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070090import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080093import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010094import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070095import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070096import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080098import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070099import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700100import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700101import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700103import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800104import com.android.internal.telephony.SubscriptionController;
Jonathan Basseribf5362b2017-07-19 12:22:35 -0700105import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700106import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700107import com.android.internal.telephony.uicc.IccIoResult;
108import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800109import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700110import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800111import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700112import com.android.internal.telephony.uicc.UiccController;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000113import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700114import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800115import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700116import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800117import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700118import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700119import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700121import java.io.FileDescriptor;
122import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800123import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800125import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800126import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100127import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800128import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129
130/**
131 * Implementation of the ITelephony interface.
132 */
Santos Cordon117fee72014-05-16 17:56:12 -0700133public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134 private static final String LOG_TAG = "PhoneInterfaceManager";
135 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
136 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800137 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138
139 // Message codes used with mMainThreadHandler
140 private static final int CMD_HANDLE_PIN_MMI = 1;
141 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
142 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
143 private static final int CMD_ANSWER_RINGING_CALL = 4;
144 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700145 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
146 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147 private static final int CMD_OPEN_CHANNEL = 9;
148 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
149 private static final int CMD_CLOSE_CHANNEL = 11;
150 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800151 private static final int CMD_NV_READ_ITEM = 13;
152 private static final int EVENT_NV_READ_ITEM_DONE = 14;
153 private static final int CMD_NV_WRITE_ITEM = 15;
154 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
155 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
156 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
157 private static final int CMD_NV_RESET_CONFIG = 19;
158 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800159 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
160 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
161 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
162 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800163 private static final int CMD_SEND_ENVELOPE = 25;
164 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700165 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
166 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
167 private static final int CMD_EXCHANGE_SIM_IO = 31;
168 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800169 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
170 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700171 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
172 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700173 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
174 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700175 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
176 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
177 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
178 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700179 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
180 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
181 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
182 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700183 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800184 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
185 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000186 private static final int CMD_SWITCH_SLOTS = 50;
187 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800189 // Parameters of select command.
190 private static final int SELECT_COMMAND = 0xA4;
191 private static final int SELECT_P1 = 0x04;
192 private static final int SELECT_P2 = 0;
193 private static final int SELECT_P3 = 0x10;
194
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195 /** The singleton instance. */
196 private static PhoneInterfaceManager sInstance;
197
Wink Saville3ab207e2014-11-20 13:07:20 -0800198 private PhoneGlobals mApp;
199 private Phone mPhone;
200 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700201 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800202 private AppOpsManager mAppOps;
203 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800204 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800205 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206
Derek Tan97ebb422014-09-05 16:55:38 -0700207 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
208 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800209 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700210
Derek Tan740e1672017-06-27 14:56:27 -0700211 // The AID of ISD-R.
212 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
213
yinxub1bed742017-04-17 11:45:04 -0700214 private NetworkScanRequestTracker mNetworkScanRequestTracker;
215
Derek Tan89e89d42014-07-08 17:00:10 -0700216 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700217 * A request object to use for transmitting data to an ICC.
218 */
219 private static final class IccAPDUArgument {
220 public int channel, cla, command, p1, p2, p3;
221 public String data;
222
223 public IccAPDUArgument(int channel, int cla, int command,
224 int p1, int p2, int p3, String data) {
225 this.channel = channel;
226 this.cla = cla;
227 this.command = command;
228 this.p1 = p1;
229 this.p2 = p2;
230 this.p3 = p3;
231 this.data = data;
232 }
233 }
234
235 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700236 * A request object to use for transmitting data to an ICC.
237 */
238 private static final class ManualNetworkSelectionArgument {
239 public OperatorInfo operatorInfo;
240 public boolean persistSelection;
241
242 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
243 this.operatorInfo = operatorInfo;
244 this.persistSelection = persistSelection;
245 }
246 }
247
248 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
250 * request after sending. The main thread will notify the request when it is complete.
251 */
252 private static final class MainThreadRequest {
253 /** The argument to use for the request */
254 public Object argument;
255 /** The result of the request that is run on the main thread */
256 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800257 // The subscriber id that this request applies to. Defaults to
258 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
259 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700260
261 public MainThreadRequest(Object argument) {
262 this.argument = argument;
263 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800264
265 public MainThreadRequest(Object argument, Integer subId) {
266 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800267 if (subId != null) {
268 this.subId = subId;
269 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271 }
272
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800273 private static final class IncomingThirdPartyCallArgs {
274 public final ComponentName component;
275 public final String callId;
276 public final String callerDisplayName;
277
278 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
279 String callerDisplayName) {
280 this.component = component;
281 this.callId = callId;
282 this.callerDisplayName = callerDisplayName;
283 }
284 }
285
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286 /**
287 * A handler that processes messages on the main thread in the phone process. Since many
288 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
289 * inbound binder threads to the main thread in the phone process. The Binder thread
290 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
291 * on, which will be notified when the operation completes and will contain the result of the
292 * request.
293 *
294 * <p>If a MainThreadRequest object is provided in the msg.obj field,
295 * note that request.result must be set to something non-null for the calling thread to
296 * unblock.
297 */
298 private final class MainThreadHandler extends Handler {
299 @Override
300 public void handleMessage(Message msg) {
301 MainThreadRequest request;
302 Message onCompleted;
303 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800304 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700305 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700306
307 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700308 case CMD_HANDLE_USSD_REQUEST: {
309 request = (MainThreadRequest) msg.obj;
310 final Phone phone = getPhoneFromRequest(request);
311 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
312 String ussdRequest = ussdObject.first;
313 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700314
315 if (!isUssdApiAllowed(request.subId)) {
316 // Carrier does not support use of this API, return failure.
317 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
318 UssdResponse response = new UssdResponse(ussdRequest, null);
319 Bundle returnData = new Bundle();
320 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
321 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
322
323 request.result = true;
324 synchronized (request) {
325 request.notifyAll();
326 }
327 return;
328 }
329
Tyler Gunn52dcf772017-04-26 11:30:31 -0700330 try {
331 request.result = phone != null ?
332 phone.handleUssdRequest(ussdRequest, wrappedCallback)
333 : false;
334 } catch (CallStateException cse) {
335 request.result = false;
336 }
pkanwar32d516d2016-10-14 19:37:38 -0700337 // Wake up the requesting thread
338 synchronized (request) {
339 request.notifyAll();
340 }
341 break;
342 }
343
Yorke Lee716f67e2015-06-17 15:39:16 -0700344 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700345 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700346 final Phone phone = getPhoneFromRequest(request);
347 request.result = phone != null ?
348 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
349 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 // Wake up the requesting thread
351 synchronized (request) {
352 request.notifyAll();
353 }
354 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356
357 case CMD_HANDLE_NEIGHBORING_CELL:
358 request = (MainThreadRequest) msg.obj;
359 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
360 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700361 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362 break;
363
364 case EVENT_NEIGHBORING_CELL_DONE:
365 ar = (AsyncResult) msg.obj;
366 request = (MainThreadRequest) ar.userObj;
367 if (ar.exception == null && ar.result != null) {
368 request.result = ar.result;
369 } else {
370 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800371 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 }
373 // Wake up the requesting thread
374 synchronized (request) {
375 request.notifyAll();
376 }
377 break;
378
379 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700380 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800381 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700382 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 break;
384
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 case CMD_END_CALL:
386 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800387 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700388 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700389 Phone phone = getPhone(end_subId);
390 if (phone == null) {
391 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
392 break;
393 }
394 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
396 // CDMA: If the user presses the Power button we treat it as
397 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700398 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
400 // GSM: End the call as per the Phone state
401 hungUp = PhoneUtils.hangup(mCM);
402 } else {
403 throw new IllegalStateException("Unexpected phone type: " + phoneType);
404 }
405 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
406 request.result = hungUp;
407 // Wake up the requesting thread
408 synchronized (request) {
409 request.notifyAll();
410 }
411 break;
412
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700414 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800416 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700417 if (uiccCard == null) {
418 loge("iccTransmitApduLogicalChannel: No UICC");
419 request.result = new IccIoResult(0x6F, 0, (byte[])null);
420 synchronized (request) {
421 request.notifyAll();
422 }
423 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700424 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
425 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700426 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 iccArgument.channel, iccArgument.cla, iccArgument.command,
428 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700429 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700430 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 break;
432
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700433 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700434 ar = (AsyncResult) msg.obj;
435 request = (MainThreadRequest) ar.userObj;
436 if (ar.exception == null && ar.result != null) {
437 request.result = ar.result;
438 } else {
439 request.result = new IccIoResult(0x6F, 0, (byte[])null);
440 if (ar.result == null) {
441 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800442 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800444 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 } else {
446 loge("iccTransmitApduLogicalChannel: Unknown exception");
447 }
448 }
449 synchronized (request) {
450 request.notifyAll();
451 }
452 break;
453
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700454 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
455 request = (MainThreadRequest) msg.obj;
456 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800457 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 if (uiccCard == null) {
459 loge("iccTransmitApduBasicChannel: No UICC");
460 request.result = new IccIoResult(0x6F, 0, (byte[])null);
461 synchronized (request) {
462 request.notifyAll();
463 }
464 } else {
465 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
466 request);
467 uiccCard.iccTransmitApduBasicChannel(
468 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
469 iccArgument.p3, iccArgument.data, onCompleted);
470 }
471 break;
472
473 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
474 ar = (AsyncResult) msg.obj;
475 request = (MainThreadRequest) ar.userObj;
476 if (ar.exception == null && ar.result != null) {
477 request.result = ar.result;
478 } else {
479 request.result = new IccIoResult(0x6F, 0, (byte[])null);
480 if (ar.result == null) {
481 loge("iccTransmitApduBasicChannel: Empty response");
482 } else if (ar.exception instanceof CommandException) {
483 loge("iccTransmitApduBasicChannel: CommandException: " +
484 ar.exception);
485 } else {
486 loge("iccTransmitApduBasicChannel: Unknown exception");
487 }
488 }
489 synchronized (request) {
490 request.notifyAll();
491 }
492 break;
493
494 case CMD_EXCHANGE_SIM_IO:
495 request = (MainThreadRequest) msg.obj;
496 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800497 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 if (uiccCard == null) {
499 loge("iccExchangeSimIO: No UICC");
500 request.result = new IccIoResult(0x6F, 0, (byte[])null);
501 synchronized (request) {
502 request.notifyAll();
503 }
504 } else {
505 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
506 request);
507 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
508 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
509 iccArgument.data, onCompleted);
510 }
511 break;
512
513 case EVENT_EXCHANGE_SIM_IO_DONE:
514 ar = (AsyncResult) msg.obj;
515 request = (MainThreadRequest) ar.userObj;
516 if (ar.exception == null && ar.result != null) {
517 request.result = ar.result;
518 } else {
519 request.result = new IccIoResult(0x6f, 0, (byte[])null);
520 }
521 synchronized (request) {
522 request.notifyAll();
523 }
524 break;
525
Derek Tan4d5e5c12014-02-04 11:54:58 -0800526 case CMD_SEND_ENVELOPE:
527 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800528 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700529 if (uiccCard == null) {
530 loge("sendEnvelopeWithStatus: No UICC");
531 request.result = new IccIoResult(0x6F, 0, (byte[])null);
532 synchronized (request) {
533 request.notifyAll();
534 }
535 } else {
536 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
537 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
538 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800539 break;
540
541 case EVENT_SEND_ENVELOPE_DONE:
542 ar = (AsyncResult) msg.obj;
543 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700544 if (ar.exception == null && ar.result != null) {
545 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800546 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700547 request.result = new IccIoResult(0x6F, 0, (byte[])null);
548 if (ar.result == null) {
549 loge("sendEnvelopeWithStatus: Empty response");
550 } else if (ar.exception instanceof CommandException) {
551 loge("sendEnvelopeWithStatus: CommandException: " +
552 ar.exception);
553 } else {
554 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
555 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800556 }
557 synchronized (request) {
558 request.notifyAll();
559 }
560 break;
561
Shishir Agrawal566b7612013-10-28 14:41:00 -0700562 case CMD_OPEN_CHANNEL:
563 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800564 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800565 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 if (uiccCard == null) {
567 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800568 request.result = new IccOpenLogicalChannelResponse(-1,
569 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 synchronized (request) {
571 request.notifyAll();
572 }
573 } else {
574 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800575 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
576 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700577 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700578 break;
579
580 case EVENT_OPEN_CHANNEL_DONE:
581 ar = (AsyncResult) msg.obj;
582 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700583 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 int[] result = (int[]) ar.result;
586 int channelId = result[0];
587 byte[] selectResponse = null;
588 if (result.length > 1) {
589 selectResponse = new byte[result.length - 1];
590 for (int i = 1; i < result.length; ++i) {
591 selectResponse[i - 1] = (byte) result[i];
592 }
593 }
594 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700595 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 if (ar.result == null) {
598 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 if (ar.exception != null) {
601 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
602 }
603
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700604 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700605 if (ar.exception instanceof CommandException) {
606 CommandException.Error error =
607 ((CommandException) (ar.exception)).getCommandError();
608 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700609 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700610 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700611 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 }
613 }
614 openChannelResp = new IccOpenLogicalChannelResponse(
615 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700617 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 synchronized (request) {
619 request.notifyAll();
620 }
621 break;
622
623 case CMD_CLOSE_CHANNEL:
624 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800625 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 if (uiccCard == null) {
627 loge("iccCloseLogicalChannel: No UICC");
628 request.result = new IccIoResult(0x6F, 0, (byte[])null);
629 synchronized (request) {
630 request.notifyAll();
631 }
632 } else {
633 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
634 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
635 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 break;
637
638 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800639 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
640 break;
641
642 case CMD_NV_READ_ITEM:
643 request = (MainThreadRequest) msg.obj;
644 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
645 mPhone.nvReadItem((Integer) request.argument, onCompleted);
646 break;
647
648 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 ar = (AsyncResult) msg.obj;
650 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800651 if (ar.exception == null && ar.result != null) {
652 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800654 request.result = "";
655 if (ar.result == null) {
656 loge("nvReadItem: Empty response");
657 } else if (ar.exception instanceof CommandException) {
658 loge("nvReadItem: CommandException: " +
659 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800661 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 }
663 }
664 synchronized (request) {
665 request.notifyAll();
666 }
667 break;
668
Jake Hambye994d462014-02-03 13:10:13 -0800669 case CMD_NV_WRITE_ITEM:
670 request = (MainThreadRequest) msg.obj;
671 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
672 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
673 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
674 break;
675
676 case EVENT_NV_WRITE_ITEM_DONE:
677 handleNullReturnEvent(msg, "nvWriteItem");
678 break;
679
680 case CMD_NV_WRITE_CDMA_PRL:
681 request = (MainThreadRequest) msg.obj;
682 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
683 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
684 break;
685
686 case EVENT_NV_WRITE_CDMA_PRL_DONE:
687 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
688 break;
689
690 case CMD_NV_RESET_CONFIG:
691 request = (MainThreadRequest) msg.obj;
692 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
693 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
694 break;
695
696 case EVENT_NV_RESET_CONFIG_DONE:
697 handleNullReturnEvent(msg, "nvResetConfig");
698 break;
699
Jake Hamby7c27be32014-03-03 13:25:59 -0800700 case CMD_GET_PREFERRED_NETWORK_TYPE:
701 request = (MainThreadRequest) msg.obj;
702 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700703 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 break;
705
706 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
707 ar = (AsyncResult) msg.obj;
708 request = (MainThreadRequest) ar.userObj;
709 if (ar.exception == null && ar.result != null) {
710 request.result = ar.result; // Integer
711 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800712 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 if (ar.result == null) {
714 loge("getPreferredNetworkType: Empty response");
715 } else if (ar.exception instanceof CommandException) {
716 loge("getPreferredNetworkType: CommandException: " +
717 ar.exception);
718 } else {
719 loge("getPreferredNetworkType: Unknown exception");
720 }
721 }
722 synchronized (request) {
723 request.notifyAll();
724 }
725 break;
726
727 case CMD_SET_PREFERRED_NETWORK_TYPE:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
730 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700731 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800732 break;
733
734 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
735 handleNullReturnEvent(msg, "setPreferredNetworkType");
736 break;
737
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800738 case CMD_SET_VOICEMAIL_NUMBER:
739 request = (MainThreadRequest) msg.obj;
740 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
741 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800742 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
743 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800744 break;
745
746 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
747 handleNullReturnEvent(msg, "setVoicemailNumber");
748 break;
749
Stuart Scott54788802015-03-30 13:18:01 -0700750 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
751 request = (MainThreadRequest) msg.obj;
752 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
753 request);
754 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
755 break;
756
757 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
758 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
759 break;
760
Shishir Agrawal302c8692015-06-19 13:49:39 -0700761 case CMD_PERFORM_NETWORK_SCAN:
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
764 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
765 break;
766
767 case EVENT_PERFORM_NETWORK_SCAN_DONE:
768 ar = (AsyncResult) msg.obj;
769 request = (MainThreadRequest) ar.userObj;
770 CellNetworkScanResult cellScanResult;
771 if (ar.exception == null && ar.result != null) {
772 cellScanResult = new CellNetworkScanResult(
773 CellNetworkScanResult.STATUS_SUCCESS,
774 (List<OperatorInfo>) ar.result);
775 } else {
776 if (ar.result == null) {
777 loge("getCellNetworkScanResults: Empty response");
778 }
779 if (ar.exception != null) {
780 loge("getCellNetworkScanResults: Exception: " + ar.exception);
781 }
782 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
783 if (ar.exception instanceof CommandException) {
784 CommandException.Error error =
785 ((CommandException) (ar.exception)).getCommandError();
786 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
787 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
788 } else if (error == CommandException.Error.GENERIC_FAILURE) {
789 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
790 }
791 }
792 cellScanResult = new CellNetworkScanResult(errorCode, null);
793 }
794 request.result = cellScanResult;
795 synchronized (request) {
796 request.notifyAll();
797 }
798 break;
799
800 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
801 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700802 ManualNetworkSelectionArgument selArg =
803 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700804 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
805 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700806 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
807 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700808 break;
809
810 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
811 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
812 break;
813
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700814 case CMD_GET_MODEM_ACTIVITY_INFO:
815 request = (MainThreadRequest) msg.obj;
816 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700817 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700818 break;
819
820 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
821 ar = (AsyncResult) msg.obj;
822 request = (MainThreadRequest) ar.userObj;
823 if (ar.exception == null && ar.result != null) {
824 request.result = ar.result;
825 } else {
826 if (ar.result == null) {
827 loge("queryModemActivityInfo: Empty response");
828 } else if (ar.exception instanceof CommandException) {
829 loge("queryModemActivityInfo: CommandException: " +
830 ar.exception);
831 } else {
832 loge("queryModemActivityInfo: Unknown exception");
833 }
834 }
Amit Mahajand4766222016-01-28 15:28:28 -0800835 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
836 if (request.result == null) {
837 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
838 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700839 synchronized (request) {
840 request.notifyAll();
841 }
842 break;
843
Meng Wang1a7c35a2016-05-05 20:56:15 -0700844 case CMD_SET_ALLOWED_CARRIERS:
845 request = (MainThreadRequest) msg.obj;
846 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
847 mPhone.setAllowedCarriers(
848 (List<CarrierIdentifier>) request.argument,
849 onCompleted);
850 break;
851
852 case EVENT_SET_ALLOWED_CARRIERS_DONE:
853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null && ar.result != null) {
856 request.result = ar.result;
857 } else {
858 if (ar.result == null) {
859 loge("setAllowedCarriers: Empty response");
860 } else if (ar.exception instanceof CommandException) {
861 loge("setAllowedCarriers: CommandException: " +
862 ar.exception);
863 } else {
864 loge("setAllowedCarriers: Unknown exception");
865 }
866 }
867 // Result cannot be null. Return -1 on error.
868 if (request.result == null) {
869 request.result = new int[]{-1};
870 }
871 synchronized (request) {
872 request.notifyAll();
873 }
874 break;
875
876 case CMD_GET_ALLOWED_CARRIERS:
877 request = (MainThreadRequest) msg.obj;
878 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
879 mPhone.getAllowedCarriers(onCompleted);
880 break;
881
882 case EVENT_GET_ALLOWED_CARRIERS_DONE:
883 ar = (AsyncResult) msg.obj;
884 request = (MainThreadRequest) ar.userObj;
885 if (ar.exception == null && ar.result != null) {
886 request.result = ar.result;
887 } else {
888 if (ar.result == null) {
889 loge("getAllowedCarriers: Empty response");
890 } else if (ar.exception instanceof CommandException) {
891 loge("getAllowedCarriers: CommandException: " +
892 ar.exception);
893 } else {
894 loge("getAllowedCarriers: Unknown exception");
895 }
896 }
897 // Result cannot be null. Return empty list of CarrierIdentifier.
898 if (request.result == null) {
899 request.result = new ArrayList<CarrierIdentifier>(0);
900 }
901 synchronized (request) {
902 request.notifyAll();
903 }
904 break;
905
Nathan Haroldb3014052017-01-25 15:57:32 -0800906 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
907 ar = (AsyncResult) msg.obj;
908 request = (MainThreadRequest) ar.userObj;
909 if (ar.exception == null && ar.result != null) {
910 request.result = ar.result;
911 } else {
912 request.result = new IllegalArgumentException(
913 "Failed to retrieve Forbidden Plmns");
914 if (ar.result == null) {
915 loge("getForbiddenPlmns: Empty response");
916 } else {
917 loge("getForbiddenPlmns: Unknown exception");
918 }
919 }
920 synchronized (request) {
921 request.notifyAll();
922 }
923 break;
924
925 case CMD_GET_FORBIDDEN_PLMNS:
926 request = (MainThreadRequest) msg.obj;
927 uiccCard = getUiccCardFromRequest(request);
928 if (uiccCard == null) {
929 loge("getForbiddenPlmns() UiccCard is null");
930 request.result = new IllegalArgumentException(
931 "getForbiddenPlmns() UiccCard is null");
932 synchronized (request) {
933 request.notifyAll();
934 }
935 break;
936 }
937 Integer appType = (Integer) request.argument;
938 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
939 if (uiccApp == null) {
940 loge("getForbiddenPlmns() no app with specified type -- "
941 + appType);
942 request.result = new IllegalArgumentException("Failed to get UICC App");
943 synchronized (request) {
944 request.notifyAll();
945 }
946 break;
947 } else {
948 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
949 + " specified type -- " + appType);
950 }
951 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
952 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
953 onCompleted);
954 break;
955
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000956 case CMD_SWITCH_SLOTS:
957 request = (MainThreadRequest) msg.obj;
958 int[] physicalSlots = (int[]) request.argument;
959 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
960 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
961 break;
962
963 case EVENT_SWITCH_SLOTS_DONE:
964 ar = (AsyncResult) msg.obj;
965 request = (MainThreadRequest) ar.userObj;
966 request.result = (ar.exception == null);
967 synchronized (request) {
968 request.notifyAll();
969 }
970 break;
971
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700972 default:
973 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
974 break;
975 }
976 }
Jake Hambye994d462014-02-03 13:10:13 -0800977
978 private void handleNullReturnEvent(Message msg, String command) {
979 AsyncResult ar = (AsyncResult) msg.obj;
980 MainThreadRequest request = (MainThreadRequest) ar.userObj;
981 if (ar.exception == null) {
982 request.result = true;
983 } else {
984 request.result = false;
985 if (ar.exception instanceof CommandException) {
986 loge(command + ": CommandException: " + ar.exception);
987 } else {
988 loge(command + ": Unknown exception");
989 }
990 }
991 synchronized (request) {
992 request.notifyAll();
993 }
994 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700995 }
996
997 /**
998 * Posts the specified command to be executed on the main thread,
999 * waits for the request to complete, and returns the result.
1000 * @see #sendRequestAsync
1001 */
1002 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001003 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001004 }
1005
1006 /**
1007 * Posts the specified command to be executed on the main thread,
1008 * waits for the request to complete, and returns the result.
1009 * @see #sendRequestAsync
1010 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001011 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001012 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1013 throw new RuntimeException("This method will deadlock if called from the main thread.");
1014 }
1015
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001016 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001017 Message msg = mMainThreadHandler.obtainMessage(command, request);
1018 msg.sendToTarget();
1019
1020 // Wait for the request to complete
1021 synchronized (request) {
1022 while (request.result == null) {
1023 try {
1024 request.wait();
1025 } catch (InterruptedException e) {
1026 // Do nothing, go back and wait until the request is complete
1027 }
1028 }
1029 }
1030 return request.result;
1031 }
1032
1033 /**
1034 * Asynchronous ("fire and forget") version of sendRequest():
1035 * Posts the specified command to be executed on the main thread, and
1036 * returns immediately.
1037 * @see #sendRequest
1038 */
1039 private void sendRequestAsync(int command) {
1040 mMainThreadHandler.sendEmptyMessage(command);
1041 }
1042
1043 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001044 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1045 * @see {@link #sendRequest(int,Object)}
1046 */
1047 private void sendRequestAsync(int command, Object argument) {
1048 MainThreadRequest request = new MainThreadRequest(argument);
1049 Message msg = mMainThreadHandler.obtainMessage(command, request);
1050 msg.sendToTarget();
1051 }
1052
1053 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001054 * Initialize the singleton PhoneInterfaceManager instance.
1055 * This is only done once, at startup, from PhoneApp.onCreate().
1056 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001057 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001058 synchronized (PhoneInterfaceManager.class) {
1059 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001060 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001061 } else {
1062 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1063 }
1064 return sInstance;
1065 }
1066 }
1067
1068 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001069 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001070 mApp = app;
1071 mPhone = phone;
1072 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001073 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001074 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1075 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001076 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001077 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001078 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001079 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001080
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001081 publish();
1082 }
1083
1084 private void publish() {
1085 if (DBG) log("publish: " + this);
1086
1087 ServiceManager.addService("phone", this);
1088 }
1089
Stuart Scott584921c2015-01-15 17:10:34 -08001090 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001091 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1092 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001093 }
1094
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001095 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1096 Phone phone = getPhoneFromRequest(request);
1097 return phone == null ? null :
1098 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1099 }
1100
Wink Saville36469e72014-06-11 15:17:00 -07001101 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001102 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001103 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001105 //
1106 // Implementation of the ITelephony interface.
1107 //
1108
1109 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001110 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001111 }
1112
Wink Savilleb564aae2014-10-23 10:18:09 -07001113 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001114 if (DBG) log("dial: " + number);
1115 // No permission check needed here: This is just a wrapper around the
1116 // ACTION_DIAL intent, which is available to any app since it puts up
1117 // the UI before it does anything.
1118
1119 String url = createTelUrl(number);
1120 if (url == null) {
1121 return;
1122 }
1123
1124 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001125 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001126 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1127 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1128 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1129 mApp.startActivity(intent);
1130 }
1131 }
1132
1133 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001134 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001135 }
1136
Wink Savilleb564aae2014-10-23 10:18:09 -07001137 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001138 if (DBG) log("call: " + number);
1139
1140 // This is just a wrapper around the ACTION_CALL intent, but we still
1141 // need to do a permission check since we're calling startActivity()
1142 // from the context of the phone app.
1143 enforceCallPermission();
1144
1145 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1146 != AppOpsManager.MODE_ALLOWED) {
1147 return;
1148 }
1149
1150 String url = createTelUrl(number);
1151 if (url == null) {
1152 return;
1153 }
1154
Wink Saville08874612014-08-31 19:19:58 -07001155 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001156 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001157 if (slist != null) {
1158 for (SubscriptionInfo subInfoRecord : slist) {
1159 if (subInfoRecord.getSubscriptionId() == subId) {
1160 isValid = true;
1161 break;
1162 }
Wink Saville08874612014-08-31 19:19:58 -07001163 }
1164 }
1165 if (isValid == false) {
1166 return;
1167 }
1168
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001169 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001170 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1172 mApp.startActivity(intent);
1173 }
1174
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001175 /**
1176 * End a call based on call state
1177 * @return true is a call was ended
1178 */
1179 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001180 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001181 }
1182
1183 /**
1184 * End a call based on the call state of the subId
1185 * @return true is a call was ended
1186 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001187 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001188 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001189 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 }
1191
1192 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001193 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001194 }
1195
Wink Savilleb564aae2014-10-23 10:18:09 -07001196 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001197 if (DBG) log("answerRingingCall...");
1198 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1199 // but that can probably wait till the big TelephonyManager API overhaul.
1200 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1201 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001202 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001203 }
1204
1205 /**
1206 * Make the actual telephony calls to implement answerRingingCall().
1207 * This should only be called from the main thread of the Phone app.
1208 * @see #answerRingingCall
1209 *
1210 * TODO: it would be nice to return true if we answered the call, or
1211 * false if there wasn't actually a ringing incoming call, or some
1212 * other error occurred. (In other words, pass back the return value
1213 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1214 * But that would require calling this method via sendRequest() rather
1215 * than sendRequestAsync(), and right now we don't actually *need* that
1216 * return value, so let's just return void for now.
1217 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001218 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001219 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001220 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001221 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1222 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001223 if (hasActiveCall && hasHoldingCall) {
1224 // Both lines are in use!
1225 // TODO: provide a flag to let the caller specify what
1226 // policy to use if both lines are in use. (The current
1227 // behavior is hardwired to "answer incoming, end ongoing",
1228 // which is how the CALL button is specced to behave.)
1229 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1230 return;
1231 } else {
1232 // answerCall() will automatically hold the current active
1233 // call, if there is one.
1234 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1235 return;
1236 }
1237 } else {
1238 // No call was ringing.
1239 return;
1240 }
1241 }
1242
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001243 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001244 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001246 public void silenceRinger() {
1247 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001248 }
1249
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001250 @Override
1251 public boolean isOffhook(String callingPackage) {
1252 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001253 }
1254
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001255 @Override
1256 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1257 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1258 return false;
1259 }
1260
Sanket Padawe356d7632015-06-22 14:03:32 -07001261 final Phone phone = getPhone(subId);
1262 if (phone != null) {
1263 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1264 } else {
1265 return false;
1266 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001267 }
1268
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001269 @Override
1270 public boolean isRinging(String callingPackage) {
1271 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001272 }
1273
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001274 @Override
1275 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1276 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1277 return false;
1278 }
1279
Sanket Padawe356d7632015-06-22 14:03:32 -07001280 final Phone phone = getPhone(subId);
1281 if (phone != null) {
1282 return (phone.getState() == PhoneConstants.State.RINGING);
1283 } else {
1284 return false;
1285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001286 }
1287
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001288 @Override
1289 public boolean isIdle(String callingPackage) {
1290 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001291 }
1292
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001293 @Override
1294 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1295 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1296 return false;
1297 }
1298
Sanket Padawe356d7632015-06-22 14:03:32 -07001299 final Phone phone = getPhone(subId);
1300 if (phone != null) {
1301 return (phone.getState() == PhoneConstants.State.IDLE);
1302 } else {
1303 return false;
1304 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001305 }
1306
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001308 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001309 }
1310
Wink Savilleb564aae2014-10-23 10:18:09 -07001311 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001312 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001313 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1314 }
1315
1316 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001317 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001318 }
1319
Wink Savilleb564aae2014-10-23 10:18:09 -07001320 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001321 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001322 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1323 }
1324
1325 /** {@hide} */
1326 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001327 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001328 }
1329
Wink Savilleb564aae2014-10-23 10:18:09 -07001330 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001332 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 checkSimPin.start();
1334 return checkSimPin.unlockSim(null, pin);
1335 }
1336
Wink Saville9de0f752013-10-22 19:04:03 -07001337 /** {@hide} */
1338 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001339 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001340 }
1341
Wink Savilleb564aae2014-10-23 10:18:09 -07001342 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001344 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001345 checkSimPuk.start();
1346 return checkSimPuk.unlockSim(puk, pin);
1347 }
1348
1349 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001350 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001351 * a synchronous one.
1352 */
1353 private static class UnlockSim extends Thread {
1354
1355 private final IccCard mSimCard;
1356
1357 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001358 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1359 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360
1361 // For replies from SimCard interface
1362 private Handler mHandler;
1363
1364 // For async handler to identify request type
1365 private static final int SUPPLY_PIN_COMPLETE = 100;
1366
1367 public UnlockSim(IccCard simCard) {
1368 mSimCard = simCard;
1369 }
1370
1371 @Override
1372 public void run() {
1373 Looper.prepare();
1374 synchronized (UnlockSim.this) {
1375 mHandler = new Handler() {
1376 @Override
1377 public void handleMessage(Message msg) {
1378 AsyncResult ar = (AsyncResult) msg.obj;
1379 switch (msg.what) {
1380 case SUPPLY_PIN_COMPLETE:
1381 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1382 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001383 mRetryCount = msg.arg1;
1384 if (ar.exception != null) {
1385 if (ar.exception instanceof CommandException &&
1386 ((CommandException)(ar.exception)).getCommandError()
1387 == CommandException.Error.PASSWORD_INCORRECT) {
1388 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1389 } else {
1390 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1391 }
1392 } else {
1393 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1394 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 mDone = true;
1396 UnlockSim.this.notifyAll();
1397 }
1398 break;
1399 }
1400 }
1401 };
1402 UnlockSim.this.notifyAll();
1403 }
1404 Looper.loop();
1405 }
1406
1407 /*
1408 * Use PIN or PUK to unlock SIM card
1409 *
1410 * If PUK is null, unlock SIM card with PIN
1411 *
1412 * If PUK is not null, unlock SIM card with PUK and set PIN code
1413 */
Wink Saville9de0f752013-10-22 19:04:03 -07001414 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415
1416 while (mHandler == null) {
1417 try {
1418 wait();
1419 } catch (InterruptedException e) {
1420 Thread.currentThread().interrupt();
1421 }
1422 }
1423 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1424
1425 if (puk == null) {
1426 mSimCard.supplyPin(pin, callback);
1427 } else {
1428 mSimCard.supplyPuk(puk, pin, callback);
1429 }
1430
1431 while (!mDone) {
1432 try {
1433 Log.d(LOG_TAG, "wait for done");
1434 wait();
1435 } catch (InterruptedException e) {
1436 // Restore the interrupted status
1437 Thread.currentThread().interrupt();
1438 }
1439 }
1440 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001441 int[] resultArray = new int[2];
1442 resultArray[0] = mResult;
1443 resultArray[1] = mRetryCount;
1444 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001445 }
1446 }
1447
1448 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001449 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001450
1451 }
1452
Wink Savilleb564aae2014-10-23 10:18:09 -07001453 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454 // No permission check needed here: this call is harmless, and it's
1455 // needed for the ServiceState.requestStateUpdate() call (which is
1456 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001457 final Phone phone = getPhone(subId);
1458 if (phone != null) {
1459 phone.updateServiceLocation();
1460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 }
1462
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001463 @Override
1464 public boolean isRadioOn(String callingPackage) {
1465 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001466 }
1467
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001468 @Override
1469 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1470 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1471 return false;
1472 }
1473 return isRadioOnForSubscriber(subId);
1474 }
1475
1476 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001477 final Phone phone = getPhone(subId);
1478 if (phone != null) {
1479 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1480 } else {
1481 return false;
1482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484
1485 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001486 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001487
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 }
Wink Saville36469e72014-06-11 15:17:00 -07001489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001492 final Phone phone = getPhone(subId);
1493 if (phone != null) {
1494 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1495 }
Wink Saville36469e72014-06-11 15:17:00 -07001496 }
1497
1498 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001499 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001500 }
1501
Wink Savilleb564aae2014-10-23 10:18:09 -07001502 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001503 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001504 final Phone phone = getPhone(subId);
1505 if (phone == null) {
1506 return false;
1507 }
1508 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001509 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001510 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511 }
1512 return true;
1513 }
Wink Saville36469e72014-06-11 15:17:00 -07001514
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001515 public boolean needMobileRadioShutdown() {
1516 /*
1517 * If any of the Radios are available, it will need to be
1518 * shutdown. So return true if any Radio is available.
1519 */
1520 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1521 Phone phone = PhoneFactory.getPhone(i);
1522 if (phone != null && phone.isRadioAvailable()) return true;
1523 }
1524 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1525 return false;
1526 }
1527
1528 public void shutdownMobileRadios() {
1529 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1530 logv("Shutting down Phone " + i);
1531 shutdownRadioUsingPhoneId(i);
1532 }
1533 }
1534
1535 private void shutdownRadioUsingPhoneId(int phoneId) {
1536 enforceModifyPermission();
1537 Phone phone = PhoneFactory.getPhone(phoneId);
1538 if (phone != null && phone.isRadioAvailable()) {
1539 phone.shutdownRadio();
1540 }
1541 }
1542
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001544 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001545 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1546 if (defaultPhone != null) {
1547 defaultPhone.setRadioPower(turnOn);
1548 return true;
1549 } else {
1550 loge("There's no default phone.");
1551 return false;
1552 }
Wink Saville36469e72014-06-11 15:17:00 -07001553 }
1554
Wink Savilleb564aae2014-10-23 10:18:09 -07001555 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001557 final Phone phone = getPhone(subId);
1558 if (phone != null) {
1559 phone.setRadioPower(turnOn);
1560 return true;
1561 } else {
1562 return false;
1563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
1565
Wink Saville36469e72014-06-11 15:17:00 -07001566 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001567 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568 public boolean enableDataConnectivity() {
1569 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001570 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001571 final Phone phone = getPhone(subId);
1572 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001573 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001574 return true;
1575 } else {
1576 return false;
1577 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001578 }
1579
Wink Saville36469e72014-06-11 15:17:00 -07001580 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001581 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 public boolean disableDataConnectivity() {
1583 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001584 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001585 final Phone phone = getPhone(subId);
1586 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001587 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001588 return true;
1589 } else {
1590 return false;
1591 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001592 }
1593
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001595 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001596 final Phone phone = getPhone(subId);
1597 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001598 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001599 } else {
1600 return false;
1601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001602 }
1603
1604 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001605 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001606 }
1607
pkanwarae03a6b2016-11-06 20:37:09 -08001608 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001609 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001610 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1611 return;
1612 }
1613 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1614 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1615 };
1616
Wink Savilleb564aae2014-10-23 10:18:09 -07001617 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1620 return false;
1621 }
Wink Saville36469e72014-06-11 15:17:00 -07001622 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 }
1624
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001626 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001627 }
1628
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001629 public int getCallStateForSlot(int slotIndex) {
1630 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001631 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001632 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001633 }
1634
Sanket Padawe356d7632015-06-22 14:03:32 -07001635 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001637 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001638 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001639 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001640 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001641 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 }
1644
Sanket Padawe356d7632015-06-22 14:03:32 -07001645 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001647 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001648 if (phone != null) {
1649 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1650 } else {
1651 return TelephonyManager.DATA_ACTIVITY_NONE;
1652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653 }
1654
1655 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001656 public Bundle getCellLocation(String callingPackage) {
Hall Liubefa7332017-11-22 17:40:08 -08001657 mPhone.getContext().getSystemService(AppOpsManager.class)
1658 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001659 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liubefa7332017-11-22 17:40:08 -08001660 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001661 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 }
1663
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001664 if (DBG_LOC) log("getCellLocation: is active user");
1665 Bundle data = new Bundle();
1666 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1667 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 return null;
1669 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001671 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001672 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1673 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001674 }
1675
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001677 public String getNetworkCountryIsoForPhone(int phoneId) {
1678 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1679 // registered cell info, so return a NULL country instead.
1680 final long identity = Binder.clearCallingIdentity();
1681 try {
1682 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1683 if (TelephonyManager.NETWORK_TYPE_IWLAN
1684 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1685 return "";
1686 }
1687 } finally {
1688 Binder.restoreCallingIdentity(identity);
1689 }
1690 return TelephonyManager.getTelephonyProperty(
1691 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1692 }
1693
1694 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001696 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001697 }
1698
Sanket Padawe356d7632015-06-22 14:03:32 -07001699 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001700 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 mApp.enforceCallingOrSelfPermission(
1702 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001703 final Phone phone = getPhone(subId);
1704 if (phone != null) {
1705 phone.enableLocationUpdates();
1706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 }
1708
1709 @Override
1710 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001711 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001712 }
1713
Sanket Padawe356d7632015-06-22 14:03:32 -07001714 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001715 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001716 mApp.enforceCallingOrSelfPermission(
1717 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001718 final Phone phone = getPhone(subId);
1719 if (phone != null) {
1720 phone.disableLocationUpdates();
1721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001722 }
1723
1724 @Override
1725 @SuppressWarnings("unchecked")
1726 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liubefa7332017-11-22 17:40:08 -08001727 mPhone.getContext().getSystemService(AppOpsManager.class)
1728 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001729 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liubefa7332017-11-22 17:40:08 -08001730 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001731 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 }
1733
1734 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1735 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1736 return null;
1737 }
Svetoslav64fad262015-04-14 14:35:21 -07001738
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001739 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001741 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001743 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001744 try {
1745 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1746 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1747 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1748 } catch (RuntimeException e) {
1749 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001751 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 }
1753
1754
1755 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001756 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liubefa7332017-11-22 17:40:08 -08001757 mPhone.getContext().getSystemService(AppOpsManager.class)
1758 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001759 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liubefa7332017-11-22 17:40:08 -08001760 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001761 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 }
1763
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001764 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001765 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001766 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1767 for (Phone phone : PhoneFactory.getPhones()) {
1768 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1769 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001771 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 }
1773
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001774 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001776 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001777 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001778 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 }
1780
Shishir Agrawala9f32182016-04-12 12:00:16 -07001781 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001782 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001783 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1784 return null;
1785 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001786 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001787 return phone == null ? null : phone.getImei();
1788 }
1789
1790 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001791 public String getMeidForSlot(int slotIndex, String callingPackage) {
1792 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1793 return null;
1794 }
1795 Phone phone = PhoneFactory.getPhone(slotIndex);
1796 return phone == null ? null : phone.getMeid();
1797 }
1798
1799 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001800 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001801 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1802 return null;
1803 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001804 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001805 return phone == null ? null : phone.getDeviceSvn();
1806 }
1807
fionaxu43304da2017-11-27 22:51:16 -08001808 @Override
1809 public int getSubscriptionCarrierId(int subId) {
1810 final Phone phone = getPhone(subId);
1811 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1812 }
1813
1814 @Override
1815 public String getSubscriptionCarrierName(int subId) {
1816 final Phone phone = getPhone(subId);
1817 return phone == null ? null : phone.getCarrierName();
1818 }
1819
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 //
1821 // Internal helper methods.
1822 //
1823
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001824 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1826 *
1827 * @throws SecurityException if the caller does not have the required permission
1828 */
1829 private void enforceModifyPermission() {
1830 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1831 }
1832
1833 /**
Junda Liua2e36012014-07-09 18:30:01 -07001834 * Make sure either system app or the caller has carrier privilege.
1835 *
1836 * @throws SecurityException if the caller does not have the required permission/privilege
1837 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001838 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001839 int permission = mApp.checkCallingOrSelfPermission(
1840 android.Manifest.permission.MODIFY_PHONE_STATE);
1841 if (permission == PackageManager.PERMISSION_GRANTED) {
1842 return;
1843 }
1844
1845 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001846 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001847 }
1848
1849 /**
1850 * Make sure the caller has carrier privilege.
1851 *
1852 * @throws SecurityException if the caller does not have the required permission
1853 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001854 private void enforceCarrierPrivilege(int subId) {
1855 if (getCarrierPrivilegeStatus(subId) !=
1856 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001857 loge("No Carrier Privilege.");
1858 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001859 }
1860 }
1861
1862 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 * Make sure the caller has the CALL_PHONE permission.
1864 *
1865 * @throws SecurityException if the caller does not have the required permission
1866 */
1867 private void enforceCallPermission() {
1868 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1869 }
1870
Stuart Scott8eef64f2015-04-08 15:13:54 -07001871 private void enforceConnectivityInternalPermission() {
1872 mApp.enforceCallingOrSelfPermission(
1873 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1874 "ConnectivityService");
1875 }
1876
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 private String createTelUrl(String number) {
1878 if (TextUtils.isEmpty(number)) {
1879 return null;
1880 }
1881
Jake Hambye994d462014-02-03 13:10:13 -08001882 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001883 }
1884
Ihab Awadf9e92732013-12-05 18:02:52 -08001885 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1887 }
1888
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001889 private static void logv(String msg) {
1890 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1891 }
1892
Ihab Awadf9e92732013-12-05 18:02:52 -08001893 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1895 }
1896
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001897 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001899 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001900 }
1901
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001903 public int getActivePhoneTypeForSlot(int slotIndex) {
1904 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001905 if (phone == null) {
1906 return PhoneConstants.PHONE_TYPE_NONE;
1907 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001908 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 }
1911
1912 /**
1913 * Returns the CDMA ERI icon index to display
1914 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001915 @Override
1916 public int getCdmaEriIconIndex(String callingPackage) {
1917 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001918 }
1919
Sanket Padawe356d7632015-06-22 14:03:32 -07001920 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001921 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1922 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1923 return -1;
1924 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001925 final Phone phone = getPhone(subId);
1926 if (phone != null) {
1927 return phone.getCdmaEriIconIndex();
1928 } else {
1929 return -1;
1930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 }
1932
1933 /**
1934 * Returns the CDMA ERI icon mode,
1935 * 0 - ON
1936 * 1 - FLASHING
1937 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001938 @Override
1939 public int getCdmaEriIconMode(String callingPackage) {
1940 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001941 }
1942
Sanket Padawe356d7632015-06-22 14:03:32 -07001943 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001944 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1945 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1946 return -1;
1947 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 final Phone phone = getPhone(subId);
1949 if (phone != null) {
1950 return phone.getCdmaEriIconMode();
1951 } else {
1952 return -1;
1953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 }
1955
1956 /**
1957 * Returns the CDMA ERI text,
1958 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001959 @Override
1960 public String getCdmaEriText(String callingPackage) {
1961 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001962 }
1963
Sanket Padawe356d7632015-06-22 14:03:32 -07001964 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001965 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1966 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1967 return null;
1968 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001969 final Phone phone = getPhone(subId);
1970 if (phone != null) {
1971 return phone.getCdmaEriText();
1972 } else {
1973 return null;
1974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 }
1976
1977 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001978 * Returns the CDMA MDN.
1979 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001980 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001981 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001982 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001983 final Phone phone = getPhone(subId);
1984 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1985 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001986 } else {
1987 return null;
1988 }
1989 }
1990
1991 /**
1992 * Returns the CDMA MIN.
1993 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001994 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001995 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001996 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 final Phone phone = getPhone(subId);
1998 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1999 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002000 } else {
2001 return null;
2002 }
2003 }
2004
2005 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002006 * Returns true if CDMA provisioning needs to run.
2007 */
2008 public boolean needsOtaServiceProvisioning() {
2009 return mPhone.needsOtaServiceProvisioning();
2010 }
2011
2012 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002013 * Sets the voice mail number of a given subId.
2014 */
2015 @Override
2016 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002017 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002018 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2019 new Pair<String, String>(alphaTag, number), new Integer(subId));
2020 return success;
2021 }
2022
Ta-wei Yen87c49842016-05-13 21:19:52 -07002023 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002024 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2025 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2026 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2027 if (!TextUtils.equals(callingPackage, systemDialer)) {
2028 throw new SecurityException("caller must be system dialer");
2029 }
2030 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2031 if (phoneAccountHandle == null){
2032 return null;
2033 }
2034 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2035 }
2036
2037 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002038 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002039 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2040 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2041 return null;
2042 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002043 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2044 }
2045
2046 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002047 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2048 VisualVoicemailSmsFilterSettings settings) {
2049 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002050 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002051 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2052 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002053 }
2054
2055 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002056 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2057 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002058 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002059 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002060 }
2061
2062 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002063 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2064 String callingPackage, int subId) {
2065 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002066 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002067 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002068 }
2069
2070 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002071 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002072 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002073 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002074 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2075 }
2076
2077 @Override
2078 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2079 String number, int port, String text, PendingIntent sentIntent) {
2080 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002081 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002082 enforceSendSmsPermission();
2083 // Make the calls as the phone process.
2084 final long identity = Binder.clearCallingIdentity();
2085 try {
2086 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2087 if (port == 0) {
2088 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2089 sentIntent, null, false);
2090 } else {
2091 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2092 smsManager.sendDataMessageWithSelfPermissions(number, null,
2093 (short) port, data, sentIntent, null);
2094 }
2095 } finally {
2096 Binder.restoreCallingIdentity(identity);
2097 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002098 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002099 /**
fionaxu0152e512016-11-14 13:36:14 -08002100 * Sets the voice activation state of a given subId.
2101 */
2102 @Override
2103 public void setVoiceActivationState(int subId, int activationState) {
2104 enforceModifyPermissionOrCarrierPrivilege(subId);
2105 final Phone phone = getPhone(subId);
2106 if (phone != null) {
2107 phone.setVoiceActivationState(activationState);
2108 } else {
2109 loge("setVoiceActivationState fails with invalid subId: " + subId);
2110 }
2111 }
2112
2113 /**
2114 * Sets the data activation state of a given subId.
2115 */
2116 @Override
2117 public void setDataActivationState(int subId, int activationState) {
2118 enforceModifyPermissionOrCarrierPrivilege(subId);
2119 final Phone phone = getPhone(subId);
2120 if (phone != null) {
2121 phone.setDataActivationState(activationState);
2122 } else {
2123 loge("setVoiceActivationState fails with invalid subId: " + subId);
2124 }
2125 }
2126
2127 /**
2128 * Returns the voice activation state of a given subId.
2129 */
2130 @Override
2131 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002132 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002133 final Phone phone = getPhone(subId);
2134 if (phone != null) {
2135 return phone.getVoiceActivationState();
2136 } else {
2137 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2138 }
2139 }
2140
2141 /**
2142 * Returns the data activation state of a given subId.
2143 */
2144 @Override
2145 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002146 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002147 final Phone phone = getPhone(subId);
2148 if (phone != null) {
2149 return phone.getDataActivationState();
2150 } else {
2151 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2152 }
2153 }
2154
2155 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 * Returns the unread count of voicemails
2157 */
2158 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002159 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002160 }
2161
2162 /**
2163 * Returns the unread count of voicemails for a subId
2164 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002165 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002166 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002167 final Phone phone = getPhone(subId);
2168 if (phone != null) {
2169 return phone.getVoiceMessageCount();
2170 } else {
2171 return 0;
2172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 }
2174
2175 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002176 * returns true, if the device is in a state where both voice and data
2177 * are supported simultaneously. This can change based on location or network condition.
2178 */
2179 @Override
2180 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2181 final Phone phone = getPhone(subId);
2182 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2183 }
2184
2185 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002186 * Send the dialer code if called from the current default dialer or the caller has
2187 * carrier privilege.
2188 * @param inputCode The dialer code to send
2189 */
2190 @Override
2191 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2192 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2193 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2194 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2195 enforceCarrierPrivilege(getDefaultSubscription());
2196 }
2197 mPhone.sendDialerSpecialCode(inputCode);
2198 }
2199
2200 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002201 * Returns the data network type.
2202 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 *
2204 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2205 */
2206 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002207 public int getNetworkType() {
2208 final Phone phone = getPhone(getDefaultSubscription());
2209 if (phone != null) {
2210 return phone.getServiceState().getDataNetworkType();
2211 } else {
2212 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2213 }
Wink Saville36469e72014-06-11 15:17:00 -07002214 }
2215
2216 /**
2217 * Returns the network type for a subId
2218 */
2219 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002220 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2221 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2222 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2223 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002224
Sanket Padawe356d7632015-06-22 14:03:32 -07002225 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002226 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002227 return phone.getServiceState().getDataNetworkType();
2228 } else {
2229 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 }
2232
2233 /**
2234 * Returns the data network type
2235 */
2236 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002237 public int getDataNetworkType(String callingPackage) {
2238 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002239 }
2240
2241 /**
2242 * Returns the data network type for a subId
2243 */
2244 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002245 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2246 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2247 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2248 }
2249
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 final Phone phone = getPhone(subId);
2251 if (phone != null) {
2252 return phone.getServiceState().getDataNetworkType();
2253 } else {
2254 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 }
2257
2258 /**
Wink Saville36469e72014-06-11 15:17:00 -07002259 * Returns the Voice network type for a subId
2260 */
2261 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002262 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2263 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2264 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2265 }
2266
Sanket Padawe356d7632015-06-22 14:03:32 -07002267 final Phone phone = getPhone(subId);
2268 if (phone != null) {
2269 return phone.getServiceState().getVoiceNetworkType();
2270 } else {
2271 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 }
2274
2275 /**
2276 * @return true if a ICC card is present
2277 */
2278 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002279 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002280 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2281 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002282 }
2283
2284 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002285 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002286 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002287 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002288 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2289 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002290 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002291 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002292 } else {
2293 return false;
2294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 }
2296
2297 /**
2298 * Return if the current radio is LTE on CDMA. This
2299 * is a tri-state return value as for a period of time
2300 * the mode may be unknown.
2301 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002302 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002304 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002305 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002306 @Override
2307 public int getLteOnCdmaMode(String callingPackage) {
2308 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002309 }
2310
Sanket Padawe356d7632015-06-22 14:03:32 -07002311 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002312 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2313 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2314 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2315 }
2316
Sanket Padawe356d7632015-06-22 14:03:32 -07002317 final Phone phone = getPhone(subId);
2318 if (phone == null) {
2319 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2320 } else {
2321 return phone.getLteOnCdmaMode();
2322 }
Wink Saville36469e72014-06-11 15:17:00 -07002323 }
2324
2325 public void setPhone(Phone phone) {
2326 mPhone = phone;
2327 }
2328
2329 /**
2330 * {@hide}
2331 * Returns Default subId, 0 in the case of single standby.
2332 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002333 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002334 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002335 }
2336
Shishir Agrawala9f32182016-04-12 12:00:16 -07002337 private int getSlotForDefaultSubscription() {
2338 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2339 }
2340
Wink Savilleb564aae2014-10-23 10:18:09 -07002341 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002342 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002344
2345 /**
2346 * @see android.telephony.TelephonyManager.WifiCallingChoices
2347 */
2348 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002349 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2350 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002351 }
2352
2353 /**
2354 * @see android.telephony.TelephonyManager.WifiCallingChoices
2355 */
2356 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002357 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2358 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2359 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002360 }
2361
Sailesh Nepald1e68152013-12-12 19:08:02 -08002362 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002363 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002364 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002365 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002366
Shishir Agrawal566b7612013-10-28 14:41:00 -07002367 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002368 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2369 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002370 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002371
Derek Tan740e1672017-06-27 14:56:27 -07002372 if (TextUtils.equals(ISDR_AID, aid)) {
2373 // Only allows LPA to open logical channel to ISD-R.
2374 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2375 ComponentInfo bestComponent =
2376 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2377 if (bestComponent == null
2378 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2379 loge("The calling package is not allowed to access ISD-R.");
2380 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2381 }
2382 }
2383
2384 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002385 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002386 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002387 if (DBG) log("iccOpenLogicalChannel: " + response);
2388 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002389 }
2390
2391 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002392 public boolean iccCloseLogicalChannel(int subId, int channel) {
2393 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002394
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002395 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002396 if (channel < 0) {
2397 return false;
2398 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002399 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002400 if (DBG) log("iccCloseLogicalChannel: " + success);
2401 return success;
2402 }
2403
2404 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002405 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002406 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002407 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002408
2409 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002410 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2411 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002412 " data=" + data);
2413 }
2414
2415 if (channel < 0) {
2416 return "";
2417 }
2418
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002419 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002420 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002421 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2422
Shishir Agrawal566b7612013-10-28 14:41:00 -07002423 // Append the returned status code to the end of the response payload.
2424 String s = Integer.toHexString(
2425 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002426 if (response.payload != null) {
2427 s = IccUtils.bytesToHexString(response.payload) + s;
2428 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002429 return s;
2430 }
Jake Hambye994d462014-02-03 13:10:13 -08002431
Evan Charltonc66da362014-05-16 14:06:40 -07002432 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002433 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2434 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002435 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002436
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002437 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2438 && TextUtils.equals(ISDR_AID, data)) {
2439 // Only allows LPA to select ISD-R.
2440 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2441 ComponentInfo bestComponent =
2442 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2443 if (bestComponent == null
2444 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2445 loge("The calling package is not allowed to select ISD-R.");
2446 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2447 }
2448 }
2449
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002450 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002451 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2452 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002453 }
2454
2455 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002456 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002457 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2458
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002459 // Append the returned status code to the end of the response payload.
2460 String s = Integer.toHexString(
2461 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002462 if (response.payload != null) {
2463 s = IccUtils.bytesToHexString(response.payload) + s;
2464 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002465 return s;
2466 }
2467
2468 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002469 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002470 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002471 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002472
2473 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002474 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002475 p1 + " " + p2 + " " + p3 + ":" + filePath);
2476 }
2477
2478 IccIoResult response =
2479 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002480 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2481 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002482
2483 if (DBG) {
2484 log("Exchange SIM_IO [R]" + response);
2485 }
2486
2487 byte[] result = null;
2488 int length = 2;
2489 if (response.payload != null) {
2490 length = 2 + response.payload.length;
2491 result = new byte[length];
2492 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2493 } else {
2494 result = new byte[length];
2495 }
2496
2497 result[length - 1] = (byte) response.sw2;
2498 result[length - 2] = (byte) response.sw1;
2499 return result;
2500 }
2501
Nathan Haroldb3014052017-01-25 15:57:32 -08002502 /**
2503 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2504 * on a particular subscription
2505 */
2506 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002507 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2508 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002509 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2510 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2511 return null;
2512 }
2513 Object response = sendRequest(
2514 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2515 if (response instanceof String[]) {
2516 return (String[]) response;
2517 }
2518 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2519 return null;
2520 }
2521
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002522 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002523 public String sendEnvelopeWithStatus(int subId, String content) {
2524 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002525
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002526 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002527 if (response.payload == null) {
2528 return "";
2529 }
2530
2531 // Append the returned status code to the end of the response payload.
2532 String s = Integer.toHexString(
2533 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2534 s = IccUtils.bytesToHexString(response.payload) + s;
2535 return s;
2536 }
2537
Jake Hambye994d462014-02-03 13:10:13 -08002538 /**
2539 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2540 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2541 *
2542 * @param itemID the ID of the item to read
2543 * @return the NV item as a String, or null on error.
2544 */
2545 @Override
2546 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002547 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002548 if (DBG) log("nvReadItem: item " + itemID);
2549 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2550 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2551 return value;
2552 }
2553
2554 /**
2555 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2556 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2557 *
2558 * @param itemID the ID of the item to read
2559 * @param itemValue the value to write, as a String
2560 * @return true on success; false on any failure
2561 */
2562 @Override
2563 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002564 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002565 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2566 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2567 new Pair<Integer, String>(itemID, itemValue));
2568 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2569 return success;
2570 }
2571
2572 /**
2573 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2574 * Used for device configuration by some CDMA operators.
2575 *
2576 * @param preferredRoamingList byte array containing the new PRL
2577 * @return true on success; false on any failure
2578 */
2579 @Override
2580 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002581 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002582 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2583 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2584 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2585 return success;
2586 }
2587
2588 /**
2589 * Perform the specified type of NV config reset.
2590 * Used for device configuration by some CDMA operators.
2591 *
2592 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2593 * @return true on success; false on any failure
2594 */
2595 @Override
2596 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002597 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002598 if (DBG) log("nvResetConfig: type " + resetType);
2599 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2600 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2601 return success;
2602 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002603
2604 /**
Wink Saville36469e72014-06-11 15:17:00 -07002605 * {@hide}
2606 * Returns Default sim, 0 in the case of single standby.
2607 */
2608 public int getDefaultSim() {
2609 //TODO Need to get it from Telephony Devcontroller
2610 return 0;
2611 }
2612
Svet Ganovb320e182015-04-16 12:30:10 -07002613 public String[] getPcscfAddress(String apnType, String callingPackage) {
2614 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2615 return new String[0];
2616 }
2617
2618
ram87fca6f2014-07-18 18:58:44 +05302619 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002620 }
2621
Brad Ebinger51f743a2017-01-23 13:50:20 -08002622 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002623 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2624 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002625 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002626 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002627 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002628 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002629 }
2630
2631 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002632 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2633 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002634 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002635 public void disableIms(int slotId) {
2636 enforceModifyPermission();
2637 PhoneFactory.getImsResolver().disableIms(slotId);
2638 }
2639
2640 /**
2641 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2642 * feature or {@link null} if the service is not available. If the feature is available, the
2643 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2644 */
2645 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002646 IImsServiceFeatureCallback callback) {
2647 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002648 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002649 }
2650
2651 /**
2652 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2653 * feature during emergency calling or {@link null} if the service is not available. If the
2654 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2655 * listener for feature updates.
2656 */
2657 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2658 enforceModifyPermission();
2659 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002660 }
2661
Brad Ebinger5f64b052017-12-14 14:26:15 -08002662 /**
2663 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2664 * specified.
2665 */
2666 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2667 enforceModifyPermission();
2668 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2669 }
2670
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002671 /**
2672 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2673 * specified.
2674 */
2675 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2676 enforceModifyPermission();
2677 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2678 }
2679
Wink Saville36469e72014-06-11 15:17:00 -07002680 public void setImsRegistrationState(boolean registered) {
2681 enforceModifyPermission();
2682 mPhone.setImsRegistrationState(registered);
2683 }
2684
2685 /**
Stuart Scott54788802015-03-30 13:18:01 -07002686 * Set the network selection mode to automatic.
2687 *
2688 */
2689 @Override
2690 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002691 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002692 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2693 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2694 }
2695
2696 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002697 * Set the network selection mode to manual with the selected carrier.
2698 */
2699 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002700 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002701 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002702 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002703 OperatorInfo operator = new OperatorInfo(
2704 /* operatorAlphaLong */ "",
2705 /* operatorAlphaShort */ "",
2706 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002707 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002708 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2709 persistSelection);
2710 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002711 }
2712
2713 /**
2714 * Scans for available networks.
2715 */
2716 @Override
2717 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002718 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002719 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2720 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2721 CMD_PERFORM_NETWORK_SCAN, null, subId);
2722 return result;
2723 }
2724
2725 /**
yinxub1bed742017-04-17 11:45:04 -07002726 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002727 *
yinxub1bed742017-04-17 11:45:04 -07002728 * @param subId id of the subscription
2729 * @param request contains the radio access networks with bands/channels to scan
2730 * @param messenger callback messenger for scan results or errors
2731 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002732 * @return the id of the requested scan which can be used to stop the scan.
2733 */
2734 @Override
2735 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2736 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002737 enforceModifyPermissionOrCarrierPrivilege(subId);
2738 return mNetworkScanRequestTracker.startNetworkScan(
2739 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002740 }
2741
2742 /**
2743 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002744 *
2745 * @param subId id of the subscription
2746 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002747 */
2748 @Override
2749 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002750 enforceModifyPermissionOrCarrierPrivilege(subId);
2751 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002752 }
2753
2754 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002755 * Get the calculated preferred network type.
2756 * Used for debugging incorrect network type.
2757 *
2758 * @return the preferred network type, defined in RILConstants.java.
2759 */
2760 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002761 public int getCalculatedPreferredNetworkType(String callingPackage) {
2762 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2763 return RILConstants.PREFERRED_NETWORK_MODE;
2764 }
2765
Amit Mahajan43330e02014-11-18 11:54:45 -08002766 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002767 }
2768
2769 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002770 * Get the preferred network type.
2771 * Used for device configuration by some CDMA operators.
2772 *
2773 * @return the preferred network type, defined in RILConstants.java.
2774 */
2775 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002776 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002777 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002778 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002779 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002780 int networkType = (result != null ? result[0] : -1);
2781 if (DBG) log("getPreferredNetworkType: " + networkType);
2782 return networkType;
2783 }
2784
2785 /**
2786 * Set the preferred network type.
2787 * Used for device configuration by some CDMA operators.
2788 *
2789 * @param networkType the preferred network type, defined in RILConstants.java.
2790 * @return true on success; false on any failure.
2791 */
2792 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002793 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002794 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002795 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2796 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002797 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002798 if (success) {
2799 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002800 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002801 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002802 return success;
2803 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002804
2805 /**
Junda Liu475951f2014-11-07 16:45:03 -08002806 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2807 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2808 * tethering.
2809 *
2810 * @return 0: Not required. 1: required. 2: Not set.
2811 * @hide
2812 */
2813 @Override
2814 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002815 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002816 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2817 Settings.Global.TETHER_DUN_REQUIRED, 2);
2818 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2819 // config_tether_apndata.
2820 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2821 dunRequired = 1;
2822 }
2823 return dunRequired;
2824 }
2825
2826 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002827 * Set mobile data enabled
2828 * Used by the user through settings etc to turn on/off mobile data
2829 *
2830 * @param enable {@code true} turn turn data on, else {@code false}
2831 */
2832 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002833 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002834 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002835 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002836 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002837 Phone phone = PhoneFactory.getPhone(phoneId);
2838 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002839 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2840 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002841 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002842 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002843 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002844 }
2845
2846 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002847 * Get the user enabled state of Mobile Data.
2848 *
2849 * TODO: remove and use isUserDataEnabled.
2850 * This can't be removed now because some vendor codes
2851 * calls through ITelephony directly while they should
2852 * use TelephonyManager.
2853 *
2854 * @return true on enabled
2855 */
2856 @Override
2857 public boolean getDataEnabled(int subId) {
2858 return isUserDataEnabled(subId);
2859 }
2860
2861 /**
2862 * Get whether mobile data is enabled per user setting.
2863 *
2864 * There are other factors deciding whether mobile data is actually enabled, but they are
2865 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002866 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002867 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002868 *
2869 * @return {@code true} if data is enabled else {@code false}
2870 */
2871 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002872 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002873 try {
2874 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2875 null);
2876 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002877 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002878 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002879 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002880 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002881 Phone phone = PhoneFactory.getPhone(phoneId);
2882 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002883 boolean retVal = phone.isUserDataEnabled();
2884 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002885 return retVal;
2886 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002887 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2888 return false;
2889 }
2890 }
2891
2892 /**
2893 * Get whether mobile data is enabled.
2894 *
2895 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2896 * whether mobile data is actually enabled.
2897 *
2898 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2899 *
2900 * @return {@code true} if data is enabled else {@code false}
2901 */
2902 @Override
2903 public boolean isDataEnabled(int subId) {
2904 try {
2905 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2906 null);
2907 } catch (Exception e) {
2908 enforceModifyPermissionOrCarrierPrivilege(subId);
2909 }
2910 int phoneId = mSubscriptionController.getPhoneId(subId);
2911 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2912 Phone phone = PhoneFactory.getPhone(phoneId);
2913 if (phone != null) {
2914 boolean retVal = phone.isDataEnabled();
2915 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2916 return retVal;
2917 } else {
2918 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002919 return false;
2920 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002921 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002922
2923 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002924 public int getCarrierPrivilegeStatus(int subId) {
2925 final Phone phone = getPhone(subId);
2926 if (phone == null) {
2927 loge("getCarrierPrivilegeStatus: Invalid subId");
2928 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2929 }
2930 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002931 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002932 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002933 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2934 }
2935 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002936 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002937 }
Junda Liu29340342014-07-10 15:23:27 -07002938
2939 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002940 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002941 if (TextUtils.isEmpty(pkgName))
2942 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002943 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002944 if (card == null) {
2945 loge("checkCarrierPrivilegesForPackage: No UICC");
2946 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2947 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002948 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2949 }
2950
2951 @Override
2952 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002953 if (TextUtils.isEmpty(pkgName))
2954 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002955 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2956 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2957 UiccCard card = UiccController.getInstance().getUiccCard(i);
2958 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002959 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002960 continue;
2961 }
2962
2963 result = card.getCarrierPrivilegeStatus(
2964 mPhone.getContext().getPackageManager(), pkgName);
2965 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2966 break;
2967 }
2968 }
2969
2970 return result;
Junda Liu29340342014-07-10 15:23:27 -07002971 }
Derek Tan89e89d42014-07-08 17:00:10 -07002972
2973 @Override
Junda Liue64de782015-04-16 17:19:16 -07002974 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2975 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2976 loge("phoneId " + phoneId + " is not valid.");
2977 return null;
2978 }
2979 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002980 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002981 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002982 return null ;
2983 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002984 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002985 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002986 }
2987
Amith Yamasani6e118872016-02-19 12:53:51 -08002988 @Override
2989 public List<String> getPackagesWithCarrierPrivileges() {
2990 PackageManager pm = mPhone.getContext().getPackageManager();
2991 List<String> privilegedPackages = new ArrayList<>();
2992 List<PackageInfo> packages = null;
2993 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2994 UiccCard card = UiccController.getInstance().getUiccCard(i);
2995 if (card == null) {
2996 // No UICC in that slot.
2997 continue;
2998 }
2999 if (card.hasCarrierPrivilegeRules()) {
3000 if (packages == null) {
3001 // Only check packages in user 0 for now
3002 packages = pm.getInstalledPackagesAsUser(
3003 PackageManager.MATCH_DISABLED_COMPONENTS
3004 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3005 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3006 }
3007 for (int p = packages.size() - 1; p >= 0; p--) {
3008 PackageInfo pkgInfo = packages.get(p);
3009 if (pkgInfo != null && pkgInfo.packageName != null
3010 && card.getCarrierPrivilegeStatus(pkgInfo)
3011 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3012 privilegedPackages.add(pkgInfo.packageName);
3013 }
3014 }
3015 }
3016 }
3017 return privilegedPackages;
3018 }
3019
Wink Savilleb564aae2014-10-23 10:18:09 -07003020 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003021 final Phone phone = getPhone(subId);
3022 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003023 if (card == null) {
3024 loge("getIccId: No UICC");
3025 return null;
3026 }
3027 String iccId = card.getIccId();
3028 if (TextUtils.isEmpty(iccId)) {
3029 loge("getIccId: ICC ID is null or empty.");
3030 return null;
3031 }
3032 return iccId;
3033 }
3034
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003035 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003036 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3037 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003038 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07003039
Jeff Sharkey85190e62014-12-05 09:40:12 -08003040 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003041 final Phone phone = getPhone(subId);
3042 if (phone == null) {
3043 return false;
3044 }
3045 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003046
3047 if (DBG_MERGE) {
3048 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3049 + subscriberId + " to " + number);
3050 }
3051
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003052 if (TextUtils.isEmpty(iccId)) {
3053 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003054 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003055
Jeff Sharkey85190e62014-12-05 09:40:12 -08003056 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3057
3058 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003059 if (alphaTag == null) {
3060 editor.remove(alphaTagPrefKey);
3061 } else {
3062 editor.putString(alphaTagPrefKey, alphaTag);
3063 }
3064
Jeff Sharkey85190e62014-12-05 09:40:12 -08003065 // Record both the line number and IMSI for this ICCID, since we need to
3066 // track all merged IMSIs based on line number
3067 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3068 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003069 if (number == null) {
3070 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003071 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003072 } else {
3073 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003074 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003075 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003076
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003077 editor.commit();
3078 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003079 }
3080
3081 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003082 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003083 // This is open to apps with WRITE_SMS.
3084 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003085 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003086 return null;
3087 }
Derek Tan97ebb422014-09-05 16:55:38 -07003088
3089 String iccId = getIccId(subId);
3090 if (iccId != null) {
3091 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003092 if (DBG_MERGE) {
3093 log("getLine1NumberForDisplay returning " +
3094 mTelephonySharedPreferences.getString(numberPrefKey, null));
3095 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003096 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003097 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003098 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003099 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003100 }
3101
3102 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003103 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3104 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3105 return null;
3106 }
Derek Tan97ebb422014-09-05 16:55:38 -07003107
3108 String iccId = getIccId(subId);
3109 if (iccId != null) {
3110 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003111 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003112 }
Derek Tan97ebb422014-09-05 16:55:38 -07003113 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003114 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003115
3116 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003117 public String[] getMergedSubscriberIds(String callingPackage) {
3118 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3119 return null;
3120 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003121 final Context context = mPhone.getContext();
3122 final TelephonyManager tele = TelephonyManager.from(context);
3123 final SubscriptionManager sub = SubscriptionManager.from(context);
3124
3125 // Figure out what subscribers are currently active
3126 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003127 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3128 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3129 final long identity = Binder.clearCallingIdentity();
3130 try {
3131 final int[] subIds = sub.getActiveSubscriptionIdList();
3132 for (int subId : subIds) {
3133 activeSubscriberIds.add(tele.getSubscriberId(subId));
3134 }
3135 } finally {
3136 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003137 }
3138
3139 // First pass, find a number override for an active subscriber
3140 String mergeNumber = null;
3141 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3142 for (String key : prefs.keySet()) {
3143 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3144 final String subscriberId = (String) prefs.get(key);
3145 if (activeSubscriberIds.contains(subscriberId)) {
3146 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3147 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3148 mergeNumber = (String) prefs.get(numberKey);
3149 if (DBG_MERGE) {
3150 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3151 + " for active subscriber " + subscriberId);
3152 }
3153 if (!TextUtils.isEmpty(mergeNumber)) {
3154 break;
3155 }
3156 }
3157 }
3158 }
3159
3160 // Shortcut when no active merged subscribers
3161 if (TextUtils.isEmpty(mergeNumber)) {
3162 return null;
3163 }
3164
3165 // Second pass, find all subscribers under that line override
3166 final ArraySet<String> result = new ArraySet<>();
3167 for (String key : prefs.keySet()) {
3168 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3169 final String number = (String) prefs.get(key);
3170 if (mergeNumber.equals(number)) {
3171 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3172 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3173 final String subscriberId = (String) prefs.get(subscriberKey);
3174 if (!TextUtils.isEmpty(subscriberId)) {
3175 result.add(subscriberId);
3176 }
3177 }
3178 }
3179 }
3180
3181 final String[] resultArray = result.toArray(new String[result.size()]);
3182 Arrays.sort(resultArray);
3183 if (DBG_MERGE) {
3184 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3185 }
3186 return resultArray;
3187 }
3188
3189 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003190 public boolean setOperatorBrandOverride(int subId, String brand) {
3191 enforceCarrierPrivilege(subId);
3192 final Phone phone = getPhone(subId);
3193 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003194 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003195
3196 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003197 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003198 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3199 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003200 enforceCarrierPrivilege(subId);
3201 final Phone phone = getPhone(subId);
3202 if (phone == null) {
3203 return false;
3204 }
3205 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003206 cdmaNonRoamingList);
3207 }
3208
3209 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003210 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();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003230 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(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.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003243 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3244 return imsManager.isVtEnabledByPlatform()
3245 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3246 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003247 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003248
Andrew Leea1239f22015-03-02 17:44:07 -08003249 @Override
3250 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003251 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003252 }
3253
3254 @Override
3255 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003256 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003257 }
3258
Andrew Lee9431b832015-03-09 18:46:45 -07003259 @Override
3260 public boolean isTtyModeSupported() {
3261 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3262 TelephonyManager telephonyManager =
3263 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003264 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003265 }
3266
3267 @Override
3268 public boolean isHearingAidCompatibilitySupported() {
3269 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3270 }
3271
Hall Liu98187582018-01-22 19:15:32 -08003272 public boolean isRttSupported() {
3273 boolean isCarrierSupported =
3274 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3275 boolean isDeviceSupported =
3276 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3277 return isCarrierSupported && isDeviceSupported;
3278 }
3279
Sanket Padawe7310cc72015-01-14 09:53:20 -08003280 /**
3281 * Returns the unique device ID of phone, for example, the IMEI for
3282 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3283 *
3284 * <p>Requires Permission:
3285 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3286 */
3287 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003288 public String getDeviceId(String callingPackage) {
3289 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3290 return null;
3291 }
3292
Sanket Padawe7310cc72015-01-14 09:53:20 -08003293 final Phone phone = PhoneFactory.getPhone(0);
3294 if (phone != null) {
3295 return phone.getDeviceId();
3296 } else {
3297 return null;
3298 }
3299 }
3300
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003301 /*
3302 * {@hide}
3303 * Returns the IMS Registration Status
3304 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003305 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003306 public boolean isImsRegistered() {
3307 return mPhone.isImsRegistered();
3308 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003309
Ping Sunc67b7c22016-03-02 19:16:45 +08003310 /**
3311 * {@hide}
3312 * Returns the IMS Registration Status on a particular subid
3313 *
3314 * @param subId
3315 */
3316 public boolean isImsRegisteredForSubscriber(int subId) {
3317 Phone phone = getPhone(subId);
3318 if (phone != null) {
3319 return phone.isImsRegistered();
3320 } else {
3321 return false;
3322 }
3323 }
3324
Santos Cordon7a1885b2015-02-03 11:15:19 -08003325 @Override
3326 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3327 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3328 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003329
Nathan Haroldc55097a2015-03-11 18:14:50 -07003330 /*
3331 * {@hide}
3332 * Returns the IMS Registration Status
3333 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003334 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003335 return mPhone.isWifiCallingEnabled();
3336 }
3337
3338 /*
3339 * {@hide}
3340 * Returns the IMS Registration Status
3341 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003342 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003343 return mPhone.isVolteEnabled();
3344 }
Svet Ganovb320e182015-04-16 12:30:10 -07003345
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003346 /*
3347 * {@hide} Returns the IMS Registration Status
3348 */
3349 public boolean isVideoTelephonyAvailable() {
3350 return mPhone.isVideoEnabled();
3351 }
3352
Svet Ganovb320e182015-04-16 12:30:10 -07003353 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003354 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003355 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003356 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3357
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003358 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003359 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003360 } catch (SecurityException e) {
3361 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3362 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003363 }
Svet Ganovb320e182015-04-16 12:30:10 -07003364
3365 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3366 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3367 return false;
3368 }
3369
3370 return true;
3371 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003372
Makoto Onukifee69342015-06-29 14:44:50 -07003373 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003374 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003375 */
3376 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003377 // Default SMS app can always read it.
3378 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3379 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3380 return true;
3381 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003382
Makoto Onukie4072d12015-08-03 15:12:23 -07003383 try {
3384 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003385 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003386 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003387 // Can be read with READ_SMS too.
3388 try {
3389 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3390 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3391 if (opCode != AppOpsManager.OP_NONE) {
3392 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3393 == AppOpsManager.MODE_ALLOWED;
3394 } else {
3395 return true;
3396 }
3397 } catch (SecurityException readSmsSecurityException) {
3398 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003399 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003400 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003401 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003402 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003403 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003404 if (opCode != AppOpsManager.OP_NONE) {
3405 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3406 == AppOpsManager.MODE_ALLOWED;
3407 } else {
3408 return true;
3409 }
3410 } catch (SecurityException readPhoneNumberSecurityException) {
3411 }
3412
3413 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3414 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3415 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003416 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003417 }
3418
Stuart Scott8eef64f2015-04-08 15:13:54 -07003419 @Override
3420 public void factoryReset(int subId) {
3421 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003422 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3423 return;
3424 }
3425
Svet Ganovcc087f82015-05-12 20:35:54 -07003426 final long identity = Binder.clearCallingIdentity();
3427 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003428 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3429 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003430 // Enable data
Malcolm Chen964682d2017-11-28 16:20:07 -08003431 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003432 // Set network selection mode to automatic
3433 setNetworkSelectionModeAutomatic(subId);
3434 // Set preferred mobile network type to the best available
3435 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3436 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003437 mPhone.setDataRoamingEnabled(false);
pkanwar79ec0542017-07-31 14:10:01 -07003438 // Remove IMSI encryption keys from Carrier DB.
3439 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003440 }
3441 } finally {
3442 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003443 }
3444 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003445
3446 @Override
3447 public String getLocaleFromDefaultSim() {
3448 // We query all subscriptions instead of just the active ones, because
3449 // this might be called early on in the provisioning flow when the
3450 // subscriptions potentially aren't active yet.
3451 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3452 if (slist == null || slist.isEmpty()) {
3453 return null;
3454 }
3455
3456 // This function may be called very early, say, from the setup wizard, at
3457 // which point we won't have a default subscription set. If that's the case
3458 // we just choose the first, which will be valid in "most cases".
3459 final int defaultSubId = getDefaultSubscription();
3460 SubscriptionInfo info = null;
3461 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3462 info = slist.get(0);
3463 } else {
3464 for (SubscriptionInfo item : slist) {
3465 if (item.getSubscriptionId() == defaultSubId) {
3466 info = item;
3467 break;
3468 }
3469 }
3470
3471 if (info == null) {
3472 return null;
3473 }
3474 }
3475
3476 // Try and fetch the locale from the carrier properties or from the SIM language
3477 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003478 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003479 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003480 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003481 if (defaultPhone != null) {
3482 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3483 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003484 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003485 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3486 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003487 } else {
3488 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003489 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003490 }
3491 }
3492
Narayan Kamath011676f2015-07-29 12:04:08 +01003493 // The SIM language preferences only store a language (e.g. fr = French), not an
3494 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3495 // the SIM and carrier preferences does not include a country we add the country
3496 // determined from the SIM MCC to provide an exact locale.
3497 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003498 if (mccLocale != null) {
3499 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3500 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003501 }
3502
Tony Hill183b2de2015-06-24 14:53:58 +01003503 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003504 return null;
3505 }
3506
3507 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3508 final long identity = Binder.clearCallingIdentity();
3509 try {
3510 return mSubscriptionController.getAllSubInfoList(
3511 mPhone.getContext().getOpPackageName());
3512 } finally {
3513 Binder.restoreCallingIdentity(identity);
3514 }
3515 }
3516
3517 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3518 final long identity = Binder.clearCallingIdentity();
3519 try {
3520 return mSubscriptionController.getActiveSubscriptionInfoList(
3521 mPhone.getContext().getOpPackageName());
3522 } finally {
3523 Binder.restoreCallingIdentity(identity);
3524 }
3525 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003526
Chenjie Yu1ba97252018-01-11 18:16:20 -08003527 private final ModemActivityInfo mLastModemActivityInfo =
3528 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3529
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003530 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003531 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3532 * representing the state of the modem.
3533 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003534 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3535 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003536 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003537 */
3538 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003539 public void requestModemActivityInfo(ResultReceiver result) {
3540 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003541 ModemActivityInfo ret = null;
3542 synchronized (mLastModemActivityInfo) {
3543 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3544 null);
3545 if (info != null) {
3546 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3547 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3548 mergedTxTimeMs[i] =
3549 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3550 }
3551 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3552 mLastModemActivityInfo.setSleepTimeMillis(
3553 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3554 mLastModemActivityInfo.setIdleTimeMillis(
3555 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3556 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3557 mLastModemActivityInfo.setRxTimeMillis(
3558 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3559 mLastModemActivityInfo.setEnergyUsed(
3560 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3561 }
3562 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3563 mLastModemActivityInfo.getSleepTimeMillis(),
3564 mLastModemActivityInfo.getIdleTimeMillis(),
3565 mLastModemActivityInfo.getTxTimeMillis(),
3566 mLastModemActivityInfo.getRxTimeMillis(),
3567 mLastModemActivityInfo.getEnergyUsed());
3568 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003569 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003570 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003571 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003572 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003573
3574 /**
3575 * {@hide}
3576 * Returns the service state information on specified subscription.
3577 */
3578 @Override
3579 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3580
3581 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3582 return null;
3583 }
3584
3585 final Phone phone = getPhone(subId);
3586 if (phone == null) {
3587 return null;
3588 }
3589
3590 return phone.getServiceState();
3591 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003592
3593 /**
3594 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3595 *
3596 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3597 * voicemail ringtone.
3598 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3599 * PhoneAccount.
3600 */
3601 @Override
3602 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003603 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003604 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003605 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003606 }
3607
fionaxu7ed723d2017-05-30 18:58:54 -07003608 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003609 }
3610
3611 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003612 * Sets the per-account voicemail ringtone.
3613 *
3614 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3615 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3616 *
3617 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3618 * voicemail ringtone.
3619 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3620 * PhoneAccount.
3621 */
3622 @Override
3623 public void setVoicemailRingtoneUri(String callingPackage,
3624 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3625 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3626 if (!TextUtils.equals(callingPackage,
3627 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3628 enforceModifyPermissionOrCarrierPrivilege(
3629 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3630 }
3631 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3632 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003633 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003634 }
fionaxu7ed723d2017-05-30 18:58:54 -07003635 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003636 }
3637
3638 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003639 * Returns whether vibration is set for voicemail notification in Phone settings.
3640 *
3641 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3642 * voicemail vibration setting.
3643 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3644 */
3645 @Override
3646 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003647 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003648 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003649 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003650 }
3651
fionaxu7ed723d2017-05-30 18:58:54 -07003652 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003653 }
3654
Youhan Wange64578a2016-05-02 15:32:42 -07003655 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003656 * Sets the per-account voicemail vibration.
3657 *
3658 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3659 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3660 *
3661 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3662 * voicemail vibration setting.
3663 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3664 * specific PhoneAccount.
3665 */
3666 @Override
3667 public void setVoicemailVibrationEnabled(String callingPackage,
3668 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3669 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3670 if (!TextUtils.equals(callingPackage,
3671 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3672 enforceModifyPermissionOrCarrierPrivilege(
3673 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3674 }
3675
3676 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3677 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003678 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003679 }
fionaxu7ed723d2017-05-30 18:58:54 -07003680 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003681 }
3682
3683 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003684 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3685 *
3686 * @throws SecurityException if the caller does not have the required permission
3687 */
3688 private void enforceReadPrivilegedPermission() {
3689 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3690 null);
3691 }
3692
3693 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003694 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3695 * permission.
3696 *
3697 * @throws SecurityException if the caller does not have the required permission
3698 */
3699 private void enforceSendSmsPermission() {
3700 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3701 }
3702
3703 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003704 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003705 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003706 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003707 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003708 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003709 ComponentName componentName =
3710 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3711 if(componentName == null) {
3712 throw new SecurityException("Caller not current active visual voicemail package[null]");
3713 }
3714 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003715 if (!callingPackage.equals(vvmPackage)) {
3716 throw new SecurityException("Caller not current active visual voicemail package[" +
3717 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003718 }
3719 }
3720
3721 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003722 * Return the application ID for the app type.
3723 *
3724 * @param subId the subscription ID that this request applies to.
3725 * @param appType the uicc app type.
3726 * @return Application ID for specificied app type, or null if no uicc.
3727 */
3728 @Override
3729 public String getAidForAppType(int subId, int appType) {
3730 enforceReadPrivilegedPermission();
3731 Phone phone = getPhone(subId);
3732 if (phone == null) {
3733 return null;
3734 }
3735 String aid = null;
3736 try {
3737 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3738 .getApplicationByType(appType).getAid();
3739 } catch (Exception e) {
3740 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3741 }
3742 return aid;
3743 }
3744
Youhan Wang4001d252016-05-11 10:29:41 -07003745 /**
3746 * Return the Electronic Serial Number.
3747 *
3748 * @param subId the subscription ID that this request applies to.
3749 * @return ESN or null if error.
3750 */
3751 @Override
3752 public String getEsn(int subId) {
3753 enforceReadPrivilegedPermission();
3754 Phone phone = getPhone(subId);
3755 if (phone == null) {
3756 return null;
3757 }
3758 String esn = null;
3759 try {
3760 esn = phone.getEsn();
3761 } catch (Exception e) {
3762 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3763 }
3764 return esn;
3765 }
3766
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003767 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003768 * Return the Preferred Roaming List Version.
3769 *
3770 * @param subId the subscription ID that this request applies to.
3771 * @return PRLVersion or null if error.
3772 */
3773 @Override
3774 public String getCdmaPrlVersion(int subId) {
3775 enforceReadPrivilegedPermission();
3776 Phone phone = getPhone(subId);
3777 if (phone == null) {
3778 return null;
3779 }
3780 String cdmaPrlVersion = null;
3781 try {
3782 cdmaPrlVersion = phone.getCdmaPrlVersion();
3783 } catch (Exception e) {
3784 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3785 }
3786 return cdmaPrlVersion;
3787 }
3788
3789 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003790 * Get snapshot of Telephony histograms
3791 * @return List of Telephony histograms
3792 * @hide
3793 */
3794 @Override
3795 public List<TelephonyHistogram> getTelephonyHistograms() {
3796 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3797 return RIL.getTelephonyRILTimingHistograms();
3798 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003799
3800 /**
3801 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003802 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003803 * Require system privileges. In the future we may add this to carrier APIs.
3804 *
3805 * @return The number of carriers set successfully, should match length of carriers
3806 */
3807 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003808 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003809 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003810
Meng Wang9b7c4e92017-02-17 11:41:27 -08003811 if (carriers == null) {
3812 throw new NullPointerException("carriers cannot be null");
3813 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003814
3815 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003816 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3817 return retVal[0];
3818 }
3819
3820 /**
3821 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003822 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003823 * Require system privileges. In the future we may add this to carrier APIs.
3824 *
3825 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3826 * means all carriers are allowed.
3827 */
3828 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003829 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003830 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003831 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003832 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3833 }
3834
fionaxu59545b42016-05-25 15:53:37 -07003835 /**
3836 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3837 * @param subId the subscription ID that this action applies to.
3838 * @param enabled control enable or disable metered apns.
3839 * {@hide}
3840 */
3841 @Override
3842 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3843 enforceModifyPermission();
3844 final Phone phone = getPhone(subId);
3845 if (phone == null) {
3846 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3847 return;
3848 }
3849 try {
3850 phone.carrierActionSetMeteredApnsEnabled(enabled);
3851 } catch (Exception e) {
3852 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3853 }
3854 }
3855
3856 /**
3857 * Action set from carrier signalling broadcast receivers to enable/disable radio
3858 * @param subId the subscription ID that this action applies to.
3859 * @param enabled control enable or disable radio.
3860 * {@hide}
3861 */
3862 @Override
3863 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3864 enforceModifyPermission();
3865 final Phone phone = getPhone(subId);
3866 if (phone == null) {
3867 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3868 return;
3869 }
3870 try {
3871 phone.carrierActionSetRadioEnabled(enabled);
3872 } catch (Exception e) {
3873 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3874 }
3875 }
3876
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003877 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003878 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3879 * network status based on which carrier apps could apply actions accordingly,
3880 * enable/disable default url handler for example.
3881 *
3882 * @param subId the subscription ID that this action applies to.
3883 * @param report control start/stop reporting the default network status.
3884 * {@hide}
3885 */
3886 @Override
3887 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3888 enforceModifyPermission();
3889 final Phone phone = getPhone(subId);
3890 if (phone == null) {
3891 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3892 return;
3893 }
3894 try {
3895 phone.carrierActionReportDefaultNetworkStatus(report);
3896 } catch (Exception e) {
3897 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3898 }
3899 }
3900
3901 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003902 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3903 * bug report is being generated.
3904 */
3905 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003906 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003907 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3908 != PackageManager.PERMISSION_GRANTED) {
3909 writer.println("Permission Denial: can't dump Phone from pid="
3910 + Binder.getCallingPid()
3911 + ", uid=" + Binder.getCallingUid()
3912 + "without permission "
3913 + android.Manifest.permission.DUMP);
3914 return;
3915 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003916 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003917 }
Jack Yueb89b242016-06-22 13:27:47 -07003918
3919 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003920 * Get aggregated video call data usage since boot.
3921 *
3922 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3923 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003924 * {@hide}
3925 */
3926 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003927 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003928 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3929 null);
3930
Jack Yu84291ec2017-05-26 16:07:50 -07003931 // NetworkStatsService keeps tracking the active network interface and identity. It
3932 // records the delta with the corresponding network identity. We just return the total video
3933 // call data usage snapshot since boot.
3934 Phone phone = getPhone(subId);
3935 if (phone != null) {
3936 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003937 }
Jack Yu84291ec2017-05-26 16:07:50 -07003938 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003939 }
Jack Yu75ab2952016-07-08 14:29:33 -07003940
3941 /**
3942 * Policy control of data connection. Usually used when data limit is passed.
3943 * @param enabled True if enabling the data, otherwise disabling.
3944 * @param subId Subscription index
3945 * {@hide}
3946 */
3947 @Override
3948 public void setPolicyDataEnabled(boolean enabled, int subId) {
3949 enforceModifyPermission();
3950 Phone phone = getPhone(subId);
3951 if (phone != null) {
3952 phone.setPolicyDataEnabled(enabled);
3953 }
3954 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003955
3956 /**
3957 * Get Client request stats
3958 * @return List of Client Request Stats
3959 * @hide
3960 */
3961 @Override
3962 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3963 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3964 return null;
3965 }
3966
3967 Phone phone = getPhone(subId);
3968 if (phone != null) {
3969 return phone.getClientRequestStats();
3970 }
3971
3972 return null;
3973 }
3974
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003975 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003976 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003977 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003978 }
Jack Yueb4124c2017-02-16 15:32:43 -08003979
3980 /**
Grace Chen70990072017-03-24 17:21:30 -07003981 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003982 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003983 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003984 * @param state State of SIM (power down, power up, pass through)
3985 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3986 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3987 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003988 *
3989 **/
3990 @Override
Grace Chen70990072017-03-24 17:21:30 -07003991 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003992 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003993 Phone phone = PhoneFactory.getPhone(slotIndex);
3994
Jack Yueb4124c2017-02-16 15:32:43 -08003995 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003996 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003997 }
3998 }
Shuo Qiandd210312017-04-12 22:11:33 +00003999
Tyler Gunn65d45c22017-06-05 11:22:26 -07004000 private boolean isUssdApiAllowed(int subId) {
4001 CarrierConfigManager configManager =
4002 (CarrierConfigManager) mPhone.getContext().getSystemService(
4003 Context.CARRIER_CONFIG_SERVICE);
4004 if (configManager == null) {
4005 return false;
4006 }
4007 PersistableBundle pb = configManager.getConfigForSubId(subId);
4008 if (pb == null) {
4009 return false;
4010 }
4011 return pb.getBoolean(
4012 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4013 }
4014
Shuo Qiandd210312017-04-12 22:11:33 +00004015 /**
4016 * Check if phone is in emergency callback mode
4017 * @return true if phone is in emergency callback mode
4018 * @param subId sub id
4019 */
goneil9c5f4872017-12-05 14:07:56 -08004020 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004021 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004022 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004023 final Phone phone = getPhone(subId);
4024 if (phone != null) {
4025 return phone.isInEcm();
4026 } else {
4027 return false;
4028 }
4029 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004030
4031 /**
4032 * Get the current signal strength information for the given subscription.
4033 * Because this information is not updated when the device is in a low power state
4034 * it should not be relied-upon to be current.
4035 * @param subId Subscription index
4036 * @return the most recent cached signal strength info from the modem
4037 */
4038 @Override
4039 public SignalStrength getSignalStrength(int subId) {
4040 Phone p = getPhone(subId);
4041 if (p == null) {
4042 return null;
4043 }
4044
4045 return p.getSignalStrength();
4046 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004047
4048 @Override
4049 public UiccSlotInfo[] getUiccSlotsInfo() {
4050 enforceReadPrivilegedPermission();
4051
4052 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4053 if (slots == null) return null;
4054 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4055 for (int i = 0; i < slots.length; i++) {
4056 UiccSlot slot = slots[i];
4057
4058 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4059
4060 int cardState = 0;
4061 switch (slot.getCardState()) {
4062 case CARDSTATE_ABSENT:
4063 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4064 break;
4065 case CARDSTATE_PRESENT:
4066 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4067 break;
4068 case CARDSTATE_ERROR:
4069 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4070 break;
4071 case CARDSTATE_RESTRICTED:
4072 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4073 break;
4074 default:
4075 break;
4076
4077 }
4078
4079 infos[i] = new UiccSlotInfo(slot.isActive(), slot.isEuicc(), cardId, cardState);
4080 }
4081 return infos;
4082 }
4083
4084 @Override
4085 public boolean switchSlots(int[] physicalSlots) {
4086 enforceModifyPermission();
4087 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004089}