blob: 4fb2c9be060f26bf2afce3406aa76c7d985e1f21 [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;
Pengquan Meng85728fb2018-03-12 16:31:21 -070045import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070047import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070048import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070049import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080050import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070051import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080052import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080053import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070054import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070055import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070058import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080059import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070060import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080061import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070062import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070063import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070064import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080066import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070067import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080068import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080069import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070070import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070071import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000072import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070074import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080075import android.telephony.ims.aidl.IImsConfig;
76import android.telephony.ims.aidl.IImsMmTelFeature;
77import android.telephony.ims.aidl.IImsRcsFeature;
78import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080079import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080081import android.util.ArraySet;
Tyler Gunn67073572018-02-14 14:19:42 -080082import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080084import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080085import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080086
Andrew Lee312e8172014-10-23 17:01:36 -070087import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080088import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070089import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070090import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070091import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070092import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070093import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080096import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010097import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070098import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070099import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -0800101import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700102import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700103import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700104import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700105import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700106import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800107import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800108import com.android.internal.telephony.TelephonyPermissions;
Jonathan Basseribf5362b2017-07-19 12:22:35 -0700109import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700110import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700111import com.android.internal.telephony.uicc.IccIoResult;
112import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800113import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700114import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800115import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800117import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000118import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700119import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800120import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700121import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800122import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700123import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700124import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800125
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700126import java.io.FileDescriptor;
127import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800128import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800130import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800131import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100132import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800133import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134
135/**
136 * Implementation of the ITelephony interface.
137 */
Santos Cordon117fee72014-05-16 17:56:12 -0700138public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139 private static final String LOG_TAG = "PhoneInterfaceManager";
140 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
141 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800142 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143
144 // Message codes used with mMainThreadHandler
145 private static final int CMD_HANDLE_PIN_MMI = 1;
146 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
147 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
148 private static final int CMD_ANSWER_RINGING_CALL = 4;
149 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700150 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
151 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700152 private static final int CMD_OPEN_CHANNEL = 9;
153 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
154 private static final int CMD_CLOSE_CHANNEL = 11;
155 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800156 private static final int CMD_NV_READ_ITEM = 13;
157 private static final int EVENT_NV_READ_ITEM_DONE = 14;
158 private static final int CMD_NV_WRITE_ITEM = 15;
159 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
160 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
161 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
162 private static final int CMD_NV_RESET_CONFIG = 19;
163 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800164 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
165 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
166 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
167 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800168 private static final int CMD_SEND_ENVELOPE = 25;
169 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700170 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
171 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
172 private static final int CMD_EXCHANGE_SIM_IO = 31;
173 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800174 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
175 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700176 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
177 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700178 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
179 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700180 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
181 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
182 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
183 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700184 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
185 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
186 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
187 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700188 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800189 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
190 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000191 private static final int CMD_SWITCH_SLOTS = 50;
192 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800194 // Parameters of select command.
195 private static final int SELECT_COMMAND = 0xA4;
196 private static final int SELECT_P1 = 0x04;
197 private static final int SELECT_P2 = 0;
198 private static final int SELECT_P3 = 0x10;
199
Pengquan Meng85728fb2018-03-12 16:31:21 -0700200 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
201 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
202 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
203
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204 /** The singleton instance. */
205 private static PhoneInterfaceManager sInstance;
206
Wink Saville3ab207e2014-11-20 13:07:20 -0800207 private PhoneGlobals mApp;
208 private Phone mPhone;
209 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700210 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800211 private AppOpsManager mAppOps;
212 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800213 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800214 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215
Derek Tan97ebb422014-09-05 16:55:38 -0700216 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
217 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800218 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700219
Derek Tan740e1672017-06-27 14:56:27 -0700220 // The AID of ISD-R.
221 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
222
yinxub1bed742017-04-17 11:45:04 -0700223 private NetworkScanRequestTracker mNetworkScanRequestTracker;
224
Derek Tan89e89d42014-07-08 17:00:10 -0700225 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700226 * A request object to use for transmitting data to an ICC.
227 */
228 private static final class IccAPDUArgument {
229 public int channel, cla, command, p1, p2, p3;
230 public String data;
231
232 public IccAPDUArgument(int channel, int cla, int command,
233 int p1, int p2, int p3, String data) {
234 this.channel = channel;
235 this.cla = cla;
236 this.command = command;
237 this.p1 = p1;
238 this.p2 = p2;
239 this.p3 = p3;
240 this.data = data;
241 }
242 }
243
244 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700245 * A request object to use for transmitting data to an ICC.
246 */
247 private static final class ManualNetworkSelectionArgument {
248 public OperatorInfo operatorInfo;
249 public boolean persistSelection;
250
251 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
252 this.operatorInfo = operatorInfo;
253 this.persistSelection = persistSelection;
254 }
255 }
256
257 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
259 * request after sending. The main thread will notify the request when it is complete.
260 */
261 private static final class MainThreadRequest {
262 /** The argument to use for the request */
263 public Object argument;
264 /** The result of the request that is run on the main thread */
265 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800266 // The subscriber id that this request applies to. Defaults to
267 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
268 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269
270 public MainThreadRequest(Object argument) {
271 this.argument = argument;
272 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800273
274 public MainThreadRequest(Object argument, Integer subId) {
275 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800276 if (subId != null) {
277 this.subId = subId;
278 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280 }
281
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800282 private static final class IncomingThirdPartyCallArgs {
283 public final ComponentName component;
284 public final String callId;
285 public final String callerDisplayName;
286
287 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
288 String callerDisplayName) {
289 this.component = component;
290 this.callId = callId;
291 this.callerDisplayName = callerDisplayName;
292 }
293 }
294
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 /**
296 * A handler that processes messages on the main thread in the phone process. Since many
297 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
298 * inbound binder threads to the main thread in the phone process. The Binder thread
299 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
300 * on, which will be notified when the operation completes and will contain the result of the
301 * request.
302 *
303 * <p>If a MainThreadRequest object is provided in the msg.obj field,
304 * note that request.result must be set to something non-null for the calling thread to
305 * unblock.
306 */
307 private final class MainThreadHandler extends Handler {
308 @Override
309 public void handleMessage(Message msg) {
310 MainThreadRequest request;
311 Message onCompleted;
312 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800313 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700314 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315
316 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700317 case CMD_HANDLE_USSD_REQUEST: {
318 request = (MainThreadRequest) msg.obj;
319 final Phone phone = getPhoneFromRequest(request);
320 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
321 String ussdRequest = ussdObject.first;
322 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700323
324 if (!isUssdApiAllowed(request.subId)) {
325 // Carrier does not support use of this API, return failure.
326 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
327 UssdResponse response = new UssdResponse(ussdRequest, null);
328 Bundle returnData = new Bundle();
329 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
330 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
331
332 request.result = true;
333 synchronized (request) {
334 request.notifyAll();
335 }
336 return;
337 }
338
Tyler Gunn52dcf772017-04-26 11:30:31 -0700339 try {
340 request.result = phone != null ?
341 phone.handleUssdRequest(ussdRequest, wrappedCallback)
342 : false;
343 } catch (CallStateException cse) {
344 request.result = false;
345 }
pkanwar32d516d2016-10-14 19:37:38 -0700346 // Wake up the requesting thread
347 synchronized (request) {
348 request.notifyAll();
349 }
350 break;
351 }
352
Yorke Lee716f67e2015-06-17 15:39:16 -0700353 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700355 final Phone phone = getPhoneFromRequest(request);
356 request.result = phone != null ?
357 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
358 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 // Wake up the requesting thread
360 synchronized (request) {
361 request.notifyAll();
362 }
363 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700364 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365
366 case CMD_HANDLE_NEIGHBORING_CELL:
367 request = (MainThreadRequest) msg.obj;
368 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
369 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700370 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 break;
372
373 case EVENT_NEIGHBORING_CELL_DONE:
374 ar = (AsyncResult) msg.obj;
375 request = (MainThreadRequest) ar.userObj;
376 if (ar.exception == null && ar.result != null) {
377 request.result = ar.result;
378 } else {
379 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800380 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 }
382 // Wake up the requesting thread
383 synchronized (request) {
384 request.notifyAll();
385 }
386 break;
387
388 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700389 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800390 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700391 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392 break;
393
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 case CMD_END_CALL:
395 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800396 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700397 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700398 Phone phone = getPhone(end_subId);
399 if (phone == null) {
400 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
401 break;
402 }
403 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
405 // CDMA: If the user presses the Power button we treat it as
406 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700407 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
409 // GSM: End the call as per the Phone state
410 hungUp = PhoneUtils.hangup(mCM);
411 } else {
412 throw new IllegalStateException("Unexpected phone type: " + phoneType);
413 }
414 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
415 request.result = hungUp;
416 // Wake up the requesting thread
417 synchronized (request) {
418 request.notifyAll();
419 }
420 break;
421
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700422 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700423 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700424 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800425 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700426 if (uiccCard == null) {
427 loge("iccTransmitApduLogicalChannel: No UICC");
428 request.result = new IccIoResult(0x6F, 0, (byte[])null);
429 synchronized (request) {
430 request.notifyAll();
431 }
432 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700433 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
434 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700435 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700436 iccArgument.channel, iccArgument.cla, iccArgument.command,
437 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700439 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700440 break;
441
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 ar = (AsyncResult) msg.obj;
444 request = (MainThreadRequest) ar.userObj;
445 if (ar.exception == null && ar.result != null) {
446 request.result = ar.result;
447 } else {
448 request.result = new IccIoResult(0x6F, 0, (byte[])null);
449 if (ar.result == null) {
450 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800451 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800453 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 } else {
455 loge("iccTransmitApduLogicalChannel: Unknown exception");
456 }
457 }
458 synchronized (request) {
459 request.notifyAll();
460 }
461 break;
462
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
464 request = (MainThreadRequest) msg.obj;
465 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800466 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 if (uiccCard == null) {
468 loge("iccTransmitApduBasicChannel: No UICC");
469 request.result = new IccIoResult(0x6F, 0, (byte[])null);
470 synchronized (request) {
471 request.notifyAll();
472 }
473 } else {
474 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
475 request);
476 uiccCard.iccTransmitApduBasicChannel(
477 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
478 iccArgument.p3, iccArgument.data, onCompleted);
479 }
480 break;
481
482 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
483 ar = (AsyncResult) msg.obj;
484 request = (MainThreadRequest) ar.userObj;
485 if (ar.exception == null && ar.result != null) {
486 request.result = ar.result;
487 } else {
488 request.result = new IccIoResult(0x6F, 0, (byte[])null);
489 if (ar.result == null) {
490 loge("iccTransmitApduBasicChannel: Empty response");
491 } else if (ar.exception instanceof CommandException) {
492 loge("iccTransmitApduBasicChannel: CommandException: " +
493 ar.exception);
494 } else {
495 loge("iccTransmitApduBasicChannel: Unknown exception");
496 }
497 }
498 synchronized (request) {
499 request.notifyAll();
500 }
501 break;
502
503 case CMD_EXCHANGE_SIM_IO:
504 request = (MainThreadRequest) msg.obj;
505 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800506 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 if (uiccCard == null) {
508 loge("iccExchangeSimIO: No UICC");
509 request.result = new IccIoResult(0x6F, 0, (byte[])null);
510 synchronized (request) {
511 request.notifyAll();
512 }
513 } else {
514 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
515 request);
516 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
517 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
518 iccArgument.data, onCompleted);
519 }
520 break;
521
522 case EVENT_EXCHANGE_SIM_IO_DONE:
523 ar = (AsyncResult) msg.obj;
524 request = (MainThreadRequest) ar.userObj;
525 if (ar.exception == null && ar.result != null) {
526 request.result = ar.result;
527 } else {
528 request.result = new IccIoResult(0x6f, 0, (byte[])null);
529 }
530 synchronized (request) {
531 request.notifyAll();
532 }
533 break;
534
Derek Tan4d5e5c12014-02-04 11:54:58 -0800535 case CMD_SEND_ENVELOPE:
536 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800537 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700538 if (uiccCard == null) {
539 loge("sendEnvelopeWithStatus: No UICC");
540 request.result = new IccIoResult(0x6F, 0, (byte[])null);
541 synchronized (request) {
542 request.notifyAll();
543 }
544 } else {
545 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
546 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
547 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800548 break;
549
550 case EVENT_SEND_ENVELOPE_DONE:
551 ar = (AsyncResult) msg.obj;
552 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700553 if (ar.exception == null && ar.result != null) {
554 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800555 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700556 request.result = new IccIoResult(0x6F, 0, (byte[])null);
557 if (ar.result == null) {
558 loge("sendEnvelopeWithStatus: Empty response");
559 } else if (ar.exception instanceof CommandException) {
560 loge("sendEnvelopeWithStatus: CommandException: " +
561 ar.exception);
562 } else {
563 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
564 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 }
566 synchronized (request) {
567 request.notifyAll();
568 }
569 break;
570
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 case CMD_OPEN_CHANNEL:
572 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800573 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800574 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700575 if (uiccCard == null) {
576 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800577 request.result = new IccOpenLogicalChannelResponse(-1,
578 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 synchronized (request) {
580 request.notifyAll();
581 }
582 } else {
583 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800584 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
585 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700586 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 break;
588
589 case EVENT_OPEN_CHANNEL_DONE:
590 ar = (AsyncResult) msg.obj;
591 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 int[] result = (int[]) ar.result;
595 int channelId = result[0];
596 byte[] selectResponse = null;
597 if (result.length > 1) {
598 selectResponse = new byte[result.length - 1];
599 for (int i = 1; i < result.length; ++i) {
600 selectResponse[i - 1] = (byte) result[i];
601 }
602 }
603 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700604 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 if (ar.result == null) {
607 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 if (ar.exception != null) {
610 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
611 }
612
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700614 if (ar.exception instanceof CommandException) {
615 CommandException.Error error =
616 ((CommandException) (ar.exception)).getCommandError();
617 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700618 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700619 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700620 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 }
622 }
623 openChannelResp = new IccOpenLogicalChannelResponse(
624 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700626 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 synchronized (request) {
628 request.notifyAll();
629 }
630 break;
631
632 case CMD_CLOSE_CHANNEL:
633 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800634 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 if (uiccCard == null) {
636 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900637 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 synchronized (request) {
639 request.notifyAll();
640 }
641 } else {
642 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
643 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
644 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 break;
646
647 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800648 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
649 break;
650
651 case CMD_NV_READ_ITEM:
652 request = (MainThreadRequest) msg.obj;
653 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
654 mPhone.nvReadItem((Integer) request.argument, onCompleted);
655 break;
656
657 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 ar = (AsyncResult) msg.obj;
659 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800660 if (ar.exception == null && ar.result != null) {
661 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800663 request.result = "";
664 if (ar.result == null) {
665 loge("nvReadItem: Empty response");
666 } else if (ar.exception instanceof CommandException) {
667 loge("nvReadItem: CommandException: " +
668 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800670 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 }
672 }
673 synchronized (request) {
674 request.notifyAll();
675 }
676 break;
677
Jake Hambye994d462014-02-03 13:10:13 -0800678 case CMD_NV_WRITE_ITEM:
679 request = (MainThreadRequest) msg.obj;
680 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
681 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
682 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
683 break;
684
685 case EVENT_NV_WRITE_ITEM_DONE:
686 handleNullReturnEvent(msg, "nvWriteItem");
687 break;
688
689 case CMD_NV_WRITE_CDMA_PRL:
690 request = (MainThreadRequest) msg.obj;
691 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
692 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
693 break;
694
695 case EVENT_NV_WRITE_CDMA_PRL_DONE:
696 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
697 break;
698
699 case CMD_NV_RESET_CONFIG:
700 request = (MainThreadRequest) msg.obj;
701 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
702 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
703 break;
704
705 case EVENT_NV_RESET_CONFIG_DONE:
706 handleNullReturnEvent(msg, "nvResetConfig");
707 break;
708
Jake Hamby7c27be32014-03-03 13:25:59 -0800709 case CMD_GET_PREFERRED_NETWORK_TYPE:
710 request = (MainThreadRequest) msg.obj;
711 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700712 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 break;
714
715 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
716 ar = (AsyncResult) msg.obj;
717 request = (MainThreadRequest) ar.userObj;
718 if (ar.exception == null && ar.result != null) {
719 request.result = ar.result; // Integer
720 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800721 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800722 if (ar.result == null) {
723 loge("getPreferredNetworkType: Empty response");
724 } else if (ar.exception instanceof CommandException) {
725 loge("getPreferredNetworkType: CommandException: " +
726 ar.exception);
727 } else {
728 loge("getPreferredNetworkType: Unknown exception");
729 }
730 }
731 synchronized (request) {
732 request.notifyAll();
733 }
734 break;
735
736 case CMD_SET_PREFERRED_NETWORK_TYPE:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
739 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700740 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800741 break;
742
743 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
744 handleNullReturnEvent(msg, "setPreferredNetworkType");
745 break;
746
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800747 case CMD_SET_VOICEMAIL_NUMBER:
748 request = (MainThreadRequest) msg.obj;
749 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
750 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800751 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
752 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800753 break;
754
755 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
756 handleNullReturnEvent(msg, "setVoicemailNumber");
757 break;
758
Stuart Scott54788802015-03-30 13:18:01 -0700759 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
762 request);
763 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
764 break;
765
766 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
767 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
768 break;
769
Shishir Agrawal302c8692015-06-19 13:49:39 -0700770 case CMD_PERFORM_NETWORK_SCAN:
771 request = (MainThreadRequest) msg.obj;
772 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
773 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
774 break;
775
776 case EVENT_PERFORM_NETWORK_SCAN_DONE:
777 ar = (AsyncResult) msg.obj;
778 request = (MainThreadRequest) ar.userObj;
779 CellNetworkScanResult cellScanResult;
780 if (ar.exception == null && ar.result != null) {
781 cellScanResult = new CellNetworkScanResult(
782 CellNetworkScanResult.STATUS_SUCCESS,
783 (List<OperatorInfo>) ar.result);
784 } else {
785 if (ar.result == null) {
786 loge("getCellNetworkScanResults: Empty response");
787 }
788 if (ar.exception != null) {
789 loge("getCellNetworkScanResults: Exception: " + ar.exception);
790 }
791 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
792 if (ar.exception instanceof CommandException) {
793 CommandException.Error error =
794 ((CommandException) (ar.exception)).getCommandError();
795 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
796 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
797 } else if (error == CommandException.Error.GENERIC_FAILURE) {
798 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
799 }
800 }
801 cellScanResult = new CellNetworkScanResult(errorCode, null);
802 }
803 request.result = cellScanResult;
804 synchronized (request) {
805 request.notifyAll();
806 }
807 break;
808
809 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
810 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700811 ManualNetworkSelectionArgument selArg =
812 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700813 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
814 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700815 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
816 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700817 break;
818
819 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
820 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
821 break;
822
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700823 case CMD_GET_MODEM_ACTIVITY_INFO:
824 request = (MainThreadRequest) msg.obj;
825 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700826 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700827 break;
828
829 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
830 ar = (AsyncResult) msg.obj;
831 request = (MainThreadRequest) ar.userObj;
832 if (ar.exception == null && ar.result != null) {
833 request.result = ar.result;
834 } else {
835 if (ar.result == null) {
836 loge("queryModemActivityInfo: Empty response");
837 } else if (ar.exception instanceof CommandException) {
838 loge("queryModemActivityInfo: CommandException: " +
839 ar.exception);
840 } else {
841 loge("queryModemActivityInfo: Unknown exception");
842 }
843 }
Amit Mahajand4766222016-01-28 15:28:28 -0800844 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
845 if (request.result == null) {
846 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
847 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700848 synchronized (request) {
849 request.notifyAll();
850 }
851 break;
852
Meng Wang1a7c35a2016-05-05 20:56:15 -0700853 case CMD_SET_ALLOWED_CARRIERS:
854 request = (MainThreadRequest) msg.obj;
855 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
856 mPhone.setAllowedCarriers(
857 (List<CarrierIdentifier>) request.argument,
858 onCompleted);
859 break;
860
861 case EVENT_SET_ALLOWED_CARRIERS_DONE:
862 ar = (AsyncResult) msg.obj;
863 request = (MainThreadRequest) ar.userObj;
864 if (ar.exception == null && ar.result != null) {
865 request.result = ar.result;
866 } else {
867 if (ar.result == null) {
868 loge("setAllowedCarriers: Empty response");
869 } else if (ar.exception instanceof CommandException) {
870 loge("setAllowedCarriers: CommandException: " +
871 ar.exception);
872 } else {
873 loge("setAllowedCarriers: Unknown exception");
874 }
875 }
876 // Result cannot be null. Return -1 on error.
877 if (request.result == null) {
878 request.result = new int[]{-1};
879 }
880 synchronized (request) {
881 request.notifyAll();
882 }
883 break;
884
885 case CMD_GET_ALLOWED_CARRIERS:
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
888 mPhone.getAllowedCarriers(onCompleted);
889 break;
890
891 case EVENT_GET_ALLOWED_CARRIERS_DONE:
892 ar = (AsyncResult) msg.obj;
893 request = (MainThreadRequest) ar.userObj;
894 if (ar.exception == null && ar.result != null) {
895 request.result = ar.result;
896 } else {
897 if (ar.result == null) {
898 loge("getAllowedCarriers: Empty response");
899 } else if (ar.exception instanceof CommandException) {
900 loge("getAllowedCarriers: CommandException: " +
901 ar.exception);
902 } else {
903 loge("getAllowedCarriers: Unknown exception");
904 }
905 }
906 // Result cannot be null. Return empty list of CarrierIdentifier.
907 if (request.result == null) {
908 request.result = new ArrayList<CarrierIdentifier>(0);
909 }
910 synchronized (request) {
911 request.notifyAll();
912 }
913 break;
914
Nathan Haroldb3014052017-01-25 15:57:32 -0800915 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 if (ar.exception == null && ar.result != null) {
919 request.result = ar.result;
920 } else {
921 request.result = new IllegalArgumentException(
922 "Failed to retrieve Forbidden Plmns");
923 if (ar.result == null) {
924 loge("getForbiddenPlmns: Empty response");
925 } else {
926 loge("getForbiddenPlmns: Unknown exception");
927 }
928 }
929 synchronized (request) {
930 request.notifyAll();
931 }
932 break;
933
934 case CMD_GET_FORBIDDEN_PLMNS:
935 request = (MainThreadRequest) msg.obj;
936 uiccCard = getUiccCardFromRequest(request);
937 if (uiccCard == null) {
938 loge("getForbiddenPlmns() UiccCard is null");
939 request.result = new IllegalArgumentException(
940 "getForbiddenPlmns() UiccCard is null");
941 synchronized (request) {
942 request.notifyAll();
943 }
944 break;
945 }
946 Integer appType = (Integer) request.argument;
947 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
948 if (uiccApp == null) {
949 loge("getForbiddenPlmns() no app with specified type -- "
950 + appType);
951 request.result = new IllegalArgumentException("Failed to get UICC App");
952 synchronized (request) {
953 request.notifyAll();
954 }
955 break;
956 } else {
957 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
958 + " specified type -- " + appType);
959 }
960 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
961 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
962 onCompleted);
963 break;
964
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000965 case CMD_SWITCH_SLOTS:
966 request = (MainThreadRequest) msg.obj;
967 int[] physicalSlots = (int[]) request.argument;
968 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
969 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
970 break;
971
972 case EVENT_SWITCH_SLOTS_DONE:
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 request.result = (ar.exception == null);
976 synchronized (request) {
977 request.notifyAll();
978 }
979 break;
980
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700981 default:
982 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
983 break;
984 }
985 }
Jake Hambye994d462014-02-03 13:10:13 -0800986
987 private void handleNullReturnEvent(Message msg, String command) {
988 AsyncResult ar = (AsyncResult) msg.obj;
989 MainThreadRequest request = (MainThreadRequest) ar.userObj;
990 if (ar.exception == null) {
991 request.result = true;
992 } else {
993 request.result = false;
994 if (ar.exception instanceof CommandException) {
995 loge(command + ": CommandException: " + ar.exception);
996 } else {
997 loge(command + ": Unknown exception");
998 }
999 }
1000 synchronized (request) {
1001 request.notifyAll();
1002 }
1003 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -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 */
1011 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001012 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001013 }
1014
1015 /**
1016 * Posts the specified command to be executed on the main thread,
1017 * waits for the request to complete, and returns the result.
1018 * @see #sendRequestAsync
1019 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001020 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001021 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1022 throw new RuntimeException("This method will deadlock if called from the main thread.");
1023 }
1024
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001025 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001026 Message msg = mMainThreadHandler.obtainMessage(command, request);
1027 msg.sendToTarget();
1028
1029 // Wait for the request to complete
1030 synchronized (request) {
1031 while (request.result == null) {
1032 try {
1033 request.wait();
1034 } catch (InterruptedException e) {
1035 // Do nothing, go back and wait until the request is complete
1036 }
1037 }
1038 }
1039 return request.result;
1040 }
1041
1042 /**
1043 * Asynchronous ("fire and forget") version of sendRequest():
1044 * Posts the specified command to be executed on the main thread, and
1045 * returns immediately.
1046 * @see #sendRequest
1047 */
1048 private void sendRequestAsync(int command) {
1049 mMainThreadHandler.sendEmptyMessage(command);
1050 }
1051
1052 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001053 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1054 * @see {@link #sendRequest(int,Object)}
1055 */
1056 private void sendRequestAsync(int command, Object argument) {
1057 MainThreadRequest request = new MainThreadRequest(argument);
1058 Message msg = mMainThreadHandler.obtainMessage(command, request);
1059 msg.sendToTarget();
1060 }
1061
1062 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001063 * Initialize the singleton PhoneInterfaceManager instance.
1064 * This is only done once, at startup, from PhoneApp.onCreate().
1065 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001066 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001067 synchronized (PhoneInterfaceManager.class) {
1068 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001069 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001070 } else {
1071 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1072 }
1073 return sInstance;
1074 }
1075 }
1076
1077 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001078 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001079 mApp = app;
1080 mPhone = phone;
1081 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001082 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1084 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001085 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001086 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001087 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001088 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001089
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001090 publish();
1091 }
1092
1093 private void publish() {
1094 if (DBG) log("publish: " + this);
1095
1096 ServiceManager.addService("phone", this);
1097 }
1098
Stuart Scott584921c2015-01-15 17:10:34 -08001099 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001100 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1101 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001102 }
1103
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001104 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1105 Phone phone = getPhoneFromRequest(request);
1106 return phone == null ? null :
1107 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1108 }
1109
Wink Saville36469e72014-06-11 15:17:00 -07001110 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001111 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001112 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001114 //
1115 // Implementation of the ITelephony interface.
1116 //
1117
1118 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001119 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001120 }
1121
Wink Savilleb564aae2014-10-23 10:18:09 -07001122 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001123 if (DBG) log("dial: " + number);
1124 // No permission check needed here: This is just a wrapper around the
1125 // ACTION_DIAL intent, which is available to any app since it puts up
1126 // the UI before it does anything.
1127
1128 String url = createTelUrl(number);
1129 if (url == null) {
1130 return;
1131 }
1132
1133 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001134 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001135 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1136 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1137 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1138 mApp.startActivity(intent);
1139 }
1140 }
1141
1142 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001143 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001144 }
1145
Wink Savilleb564aae2014-10-23 10:18:09 -07001146 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001147 if (DBG) log("call: " + number);
1148
1149 // This is just a wrapper around the ACTION_CALL intent, but we still
1150 // need to do a permission check since we're calling startActivity()
1151 // from the context of the phone app.
1152 enforceCallPermission();
1153
1154 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1155 != AppOpsManager.MODE_ALLOWED) {
1156 return;
1157 }
1158
1159 String url = createTelUrl(number);
1160 if (url == null) {
1161 return;
1162 }
1163
Wink Saville08874612014-08-31 19:19:58 -07001164 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001165 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001166 if (slist != null) {
1167 for (SubscriptionInfo subInfoRecord : slist) {
1168 if (subInfoRecord.getSubscriptionId() == subId) {
1169 isValid = true;
1170 break;
1171 }
Wink Saville08874612014-08-31 19:19:58 -07001172 }
1173 }
1174 if (isValid == false) {
1175 return;
1176 }
1177
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001178 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001179 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001180 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1181 mApp.startActivity(intent);
1182 }
1183
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001184 /**
1185 * End a call based on call state
1186 * @return true is a call was ended
1187 */
1188 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001189 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001190 }
1191
1192 /**
1193 * End a call based on the call state of the subId
1194 * @return true is a call was ended
1195 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001196 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001197 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1198 != PackageManager.PERMISSION_GRANTED) {
1199 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1200 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1201 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1202 }
Stuart Scott584921c2015-01-15 17:10:34 -08001203 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001204 }
1205
1206 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001207 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001208 }
1209
Wink Savilleb564aae2014-10-23 10:18:09 -07001210 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001211 if (DBG) log("answerRingingCall...");
1212 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1213 // but that can probably wait till the big TelephonyManager API overhaul.
1214 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1215 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001216 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001217 }
1218
1219 /**
1220 * Make the actual telephony calls to implement answerRingingCall().
1221 * This should only be called from the main thread of the Phone app.
1222 * @see #answerRingingCall
1223 *
1224 * TODO: it would be nice to return true if we answered the call, or
1225 * false if there wasn't actually a ringing incoming call, or some
1226 * other error occurred. (In other words, pass back the return value
1227 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1228 * But that would require calling this method via sendRequest() rather
1229 * than sendRequestAsync(), and right now we don't actually *need* that
1230 * return value, so let's just return void for now.
1231 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001232 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001233 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001235 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1236 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001237 if (hasActiveCall && hasHoldingCall) {
1238 // Both lines are in use!
1239 // TODO: provide a flag to let the caller specify what
1240 // policy to use if both lines are in use. (The current
1241 // behavior is hardwired to "answer incoming, end ongoing",
1242 // which is how the CALL button is specced to behave.)
1243 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1244 return;
1245 } else {
1246 // answerCall() will automatically hold the current active
1247 // call, if there is one.
1248 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1249 return;
1250 }
1251 } else {
1252 // No call was ringing.
1253 return;
1254 }
1255 }
1256
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001257 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001258 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001260 public void silenceRinger() {
1261 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 }
1263
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001264 @Override
1265 public boolean isOffhook(String callingPackage) {
1266 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001267 }
1268
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001269 @Override
1270 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001272 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001273 return false;
1274 }
1275
Sanket Padawe356d7632015-06-22 14:03:32 -07001276 final Phone phone = getPhone(subId);
1277 if (phone != null) {
1278 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1279 } else {
1280 return false;
1281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282 }
1283
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001284 @Override
1285 public boolean isRinging(String callingPackage) {
1286 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001287 }
1288
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001289 @Override
1290 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001291 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001292 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001293 return false;
1294 }
1295
Sanket Padawe356d7632015-06-22 14:03:32 -07001296 final Phone phone = getPhone(subId);
1297 if (phone != null) {
1298 return (phone.getState() == PhoneConstants.State.RINGING);
1299 } else {
1300 return false;
1301 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001302 }
1303
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001304 @Override
1305 public boolean isIdle(String callingPackage) {
1306 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001307 }
1308
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001309 @Override
1310 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001312 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001313 return false;
1314 }
1315
Sanket Padawe356d7632015-06-22 14:03:32 -07001316 final Phone phone = getPhone(subId);
1317 if (phone != null) {
1318 return (phone.getState() == PhoneConstants.State.IDLE);
1319 } else {
1320 return false;
1321 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001322 }
1323
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001325 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001326 }
1327
Wink Savilleb564aae2014-10-23 10:18:09 -07001328 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001329 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001330 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1331 }
1332
1333 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001334 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001335 }
1336
Wink Savilleb564aae2014-10-23 10:18:09 -07001337 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001338 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001339 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1340 }
1341
1342 /** {@hide} */
1343 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001344 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001345 }
1346
Wink Savilleb564aae2014-10-23 10:18:09 -07001347 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001348 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001349 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001350 checkSimPin.start();
1351 return checkSimPin.unlockSim(null, pin);
1352 }
1353
Wink Saville9de0f752013-10-22 19:04:03 -07001354 /** {@hide} */
1355 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001356 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001357 }
1358
Wink Savilleb564aae2014-10-23 10:18:09 -07001359 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001361 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001362 checkSimPuk.start();
1363 return checkSimPuk.unlockSim(puk, pin);
1364 }
1365
1366 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001367 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001368 * a synchronous one.
1369 */
1370 private static class UnlockSim extends Thread {
1371
1372 private final IccCard mSimCard;
1373
1374 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001375 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1376 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377
1378 // For replies from SimCard interface
1379 private Handler mHandler;
1380
1381 // For async handler to identify request type
1382 private static final int SUPPLY_PIN_COMPLETE = 100;
1383
1384 public UnlockSim(IccCard simCard) {
1385 mSimCard = simCard;
1386 }
1387
1388 @Override
1389 public void run() {
1390 Looper.prepare();
1391 synchronized (UnlockSim.this) {
1392 mHandler = new Handler() {
1393 @Override
1394 public void handleMessage(Message msg) {
1395 AsyncResult ar = (AsyncResult) msg.obj;
1396 switch (msg.what) {
1397 case SUPPLY_PIN_COMPLETE:
1398 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1399 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001400 mRetryCount = msg.arg1;
1401 if (ar.exception != null) {
1402 if (ar.exception instanceof CommandException &&
1403 ((CommandException)(ar.exception)).getCommandError()
1404 == CommandException.Error.PASSWORD_INCORRECT) {
1405 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1406 } else {
1407 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1408 }
1409 } else {
1410 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 mDone = true;
1413 UnlockSim.this.notifyAll();
1414 }
1415 break;
1416 }
1417 }
1418 };
1419 UnlockSim.this.notifyAll();
1420 }
1421 Looper.loop();
1422 }
1423
1424 /*
1425 * Use PIN or PUK to unlock SIM card
1426 *
1427 * If PUK is null, unlock SIM card with PIN
1428 *
1429 * If PUK is not null, unlock SIM card with PUK and set PIN code
1430 */
Wink Saville9de0f752013-10-22 19:04:03 -07001431 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001432
1433 while (mHandler == null) {
1434 try {
1435 wait();
1436 } catch (InterruptedException e) {
1437 Thread.currentThread().interrupt();
1438 }
1439 }
1440 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1441
1442 if (puk == null) {
1443 mSimCard.supplyPin(pin, callback);
1444 } else {
1445 mSimCard.supplyPuk(puk, pin, callback);
1446 }
1447
1448 while (!mDone) {
1449 try {
1450 Log.d(LOG_TAG, "wait for done");
1451 wait();
1452 } catch (InterruptedException e) {
1453 // Restore the interrupted status
1454 Thread.currentThread().interrupt();
1455 }
1456 }
1457 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001458 int[] resultArray = new int[2];
1459 resultArray[0] = mResult;
1460 resultArray[1] = mRetryCount;
1461 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 }
1463 }
1464
1465 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001466 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001467
1468 }
1469
Wink Savilleb564aae2014-10-23 10:18:09 -07001470 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471 // No permission check needed here: this call is harmless, and it's
1472 // needed for the ServiceState.requestStateUpdate() call (which is
1473 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001474 final Phone phone = getPhone(subId);
1475 if (phone != null) {
1476 phone.updateServiceLocation();
1477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478 }
1479
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001480 @Override
1481 public boolean isRadioOn(String callingPackage) {
1482 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001483 }
1484
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001485 @Override
1486 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001488 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001489 return false;
1490 }
1491 return isRadioOnForSubscriber(subId);
1492 }
1493
1494 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001495 final Phone phone = getPhone(subId);
1496 if (phone != null) {
1497 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1498 } else {
1499 return false;
1500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 }
1502
1503 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001504 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001505
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506 }
Wink Saville36469e72014-06-11 15:17:00 -07001507
Wink Savilleb564aae2014-10-23 10:18:09 -07001508 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001510 final Phone phone = getPhone(subId);
1511 if (phone != null) {
1512 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1513 }
Wink Saville36469e72014-06-11 15:17:00 -07001514 }
1515
1516 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001517 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001518 }
1519
Wink Savilleb564aae2014-10-23 10:18:09 -07001520 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001521 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001522 final Phone phone = getPhone(subId);
1523 if (phone == null) {
1524 return false;
1525 }
1526 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001527 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001528 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 }
1530 return true;
1531 }
Wink Saville36469e72014-06-11 15:17:00 -07001532
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001533 public boolean needMobileRadioShutdown() {
1534 /*
1535 * If any of the Radios are available, it will need to be
1536 * shutdown. So return true if any Radio is available.
1537 */
1538 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1539 Phone phone = PhoneFactory.getPhone(i);
1540 if (phone != null && phone.isRadioAvailable()) return true;
1541 }
1542 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1543 return false;
1544 }
1545
1546 public void shutdownMobileRadios() {
1547 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1548 logv("Shutting down Phone " + i);
1549 shutdownRadioUsingPhoneId(i);
1550 }
1551 }
1552
1553 private void shutdownRadioUsingPhoneId(int phoneId) {
1554 enforceModifyPermission();
1555 Phone phone = PhoneFactory.getPhone(phoneId);
1556 if (phone != null && phone.isRadioAvailable()) {
1557 phone.shutdownRadio();
1558 }
1559 }
1560
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001561 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001562 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001563 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1564 if (defaultPhone != null) {
1565 defaultPhone.setRadioPower(turnOn);
1566 return true;
1567 } else {
1568 loge("There's no default phone.");
1569 return false;
1570 }
Wink Saville36469e72014-06-11 15:17:00 -07001571 }
1572
Wink Savilleb564aae2014-10-23 10:18:09 -07001573 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001575 final Phone phone = getPhone(subId);
1576 if (phone != null) {
1577 phone.setRadioPower(turnOn);
1578 return true;
1579 } else {
1580 return false;
1581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 }
1583
Wink Saville36469e72014-06-11 15:17:00 -07001584 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001585 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 public boolean enableDataConnectivity() {
1587 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001588 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001589 final Phone phone = getPhone(subId);
1590 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001591 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001592 return true;
1593 } else {
1594 return false;
1595 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596 }
1597
Wink Saville36469e72014-06-11 15:17:00 -07001598 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001599 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 public boolean disableDataConnectivity() {
1601 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001602 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001603 final Phone phone = getPhone(subId);
1604 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001605 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001606 return true;
1607 } else {
1608 return false;
1609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 }
1611
Sanket Padawe356d7632015-06-22 14:03:32 -07001612 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001613 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001614 final Phone phone = getPhone(subId);
1615 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001616 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001617 } else {
1618 return false;
1619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 }
1621
1622 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001623 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001624 }
1625
pkanwarae03a6b2016-11-06 20:37:09 -08001626 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001627 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001628 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1629 return;
1630 }
1631 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1632 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1633 };
1634
Wink Savilleb564aae2014-10-23 10:18:09 -07001635 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001637 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1638 return false;
1639 }
Wink Saville36469e72014-06-11 15:17:00 -07001640 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 }
1642
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001644 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001645 }
1646
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001647 public int getCallStateForSlot(int slotIndex) {
1648 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001649 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001650 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 }
1652
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001655 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001656 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001657 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001658 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001659 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001660 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 }
1662
Sanket Padawe356d7632015-06-22 14:03:32 -07001663 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001665 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001666 if (phone != null) {
1667 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1668 } else {
1669 return TelephonyManager.DATA_ACTIVITY_NONE;
1670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 }
1672
1673 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001674 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001675 mPhone.getContext().getSystemService(AppOpsManager.class)
1676 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001677 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001678 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001679 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001680 }
1681
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001682 if (DBG_LOC) log("getCellLocation: is active user");
1683 Bundle data = new Bundle();
1684 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1685 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 return null;
1687 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001689 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001690 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1691 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001692 }
1693
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001695 public String getNetworkCountryIsoForPhone(int phoneId) {
1696 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1697 // registered cell info, so return a NULL country instead.
1698 final long identity = Binder.clearCallingIdentity();
1699 try {
1700 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1701 if (TelephonyManager.NETWORK_TYPE_IWLAN
1702 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1703 return "";
1704 }
1705 } finally {
1706 Binder.restoreCallingIdentity(identity);
1707 }
1708 return TelephonyManager.getTelephonyProperty(
1709 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1710 }
1711
1712 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001714 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001715 }
1716
Sanket Padawe356d7632015-06-22 14:03:32 -07001717 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001718 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 mApp.enforceCallingOrSelfPermission(
1720 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001721 final Phone phone = getPhone(subId);
1722 if (phone != null) {
1723 phone.enableLocationUpdates();
1724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
1727 @Override
1728 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001729 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001730 }
1731
Sanket Padawe356d7632015-06-22 14:03:32 -07001732 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001733 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 mApp.enforceCallingOrSelfPermission(
1735 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001736 final Phone phone = getPhone(subId);
1737 if (phone != null) {
1738 phone.disableLocationUpdates();
1739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 }
1741
1742 @Override
1743 @SuppressWarnings("unchecked")
1744 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001745 mPhone.getContext().getSystemService(AppOpsManager.class)
1746 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001747 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001748 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001749 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 }
1751
1752 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1753 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1754 return null;
1755 }
Svetoslav64fad262015-04-14 14:35:21 -07001756
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001757 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001759 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001761 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001762 try {
1763 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1764 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1765 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1766 } catch (RuntimeException e) {
1767 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001769 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
1771
1772
1773 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001774 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001775 mPhone.getContext().getSystemService(AppOpsManager.class)
1776 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001777 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001778 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001779 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001780 }
1781
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001782 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001783 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001784 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1785 for (Phone phone : PhoneFactory.getPhones()) {
1786 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1787 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001789 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 }
1791
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001792 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001794 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001795 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001796 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 }
1798
Shishir Agrawala9f32182016-04-12 12:00:16 -07001799 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001800 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001801 Phone phone = PhoneFactory.getPhone(slotIndex);
1802 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001803 return null;
1804 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001805 int subId = phone.getSubId();
1806 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1807 mApp, subId, callingPackage, "getImeiForSlot")) {
1808 return null;
1809 }
1810 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001811 }
1812
1813 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001814 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001815 Phone phone = PhoneFactory.getPhone(slotIndex);
1816 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001817 return null;
1818 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001819 int subId = phone.getSubId();
1820 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1821 mApp, subId, callingPackage, "getMeidForSlot")) {
1822 return null;
1823 }
1824 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001825 }
1826
1827 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001828 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001829 Phone phone = PhoneFactory.getPhone(slotIndex);
1830 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001831 return null;
1832 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001833 int subId = phone.getSubId();
1834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1835 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1836 return null;
1837 }
1838 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001839 }
1840
fionaxu43304da2017-11-27 22:51:16 -08001841 @Override
1842 public int getSubscriptionCarrierId(int subId) {
1843 final Phone phone = getPhone(subId);
1844 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1845 }
1846
1847 @Override
1848 public String getSubscriptionCarrierName(int subId) {
1849 final Phone phone = getPhone(subId);
1850 return phone == null ? null : phone.getCarrierName();
1851 }
1852
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 //
1854 // Internal helper methods.
1855 //
1856
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001857 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1859 *
1860 * @throws SecurityException if the caller does not have the required permission
1861 */
1862 private void enforceModifyPermission() {
1863 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1864 }
1865
1866 /**
1867 * Make sure the caller has the CALL_PHONE permission.
1868 *
1869 * @throws SecurityException if the caller does not have the required permission
1870 */
1871 private void enforceCallPermission() {
1872 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1873 }
1874
Stuart Scott8eef64f2015-04-08 15:13:54 -07001875 private void enforceConnectivityInternalPermission() {
1876 mApp.enforceCallingOrSelfPermission(
1877 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1878 "ConnectivityService");
1879 }
1880
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 private String createTelUrl(String number) {
1882 if (TextUtils.isEmpty(number)) {
1883 return null;
1884 }
1885
Jake Hambye994d462014-02-03 13:10:13 -08001886 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 }
1888
Ihab Awadf9e92732013-12-05 18:02:52 -08001889 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1891 }
1892
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001893 private static void logv(String msg) {
1894 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1895 }
1896
Ihab Awadf9e92732013-12-05 18:02:52 -08001897 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1899 }
1900
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001901 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001903 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001904 }
1905
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001907 public int getActivePhoneTypeForSlot(int slotIndex) {
1908 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001909 if (phone == null) {
1910 return PhoneConstants.PHONE_TYPE_NONE;
1911 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001912 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 }
1915
1916 /**
1917 * Returns the CDMA ERI icon index to display
1918 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001919 @Override
1920 public int getCdmaEriIconIndex(String callingPackage) {
1921 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001922 }
1923
Sanket Padawe356d7632015-06-22 14:03:32 -07001924 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001925 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001927 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001928 return -1;
1929 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001930 final Phone phone = getPhone(subId);
1931 if (phone != null) {
1932 return phone.getCdmaEriIconIndex();
1933 } else {
1934 return -1;
1935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
1938 /**
1939 * Returns the CDMA ERI icon mode,
1940 * 0 - ON
1941 * 1 - FLASHING
1942 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001943 @Override
1944 public int getCdmaEriIconMode(String callingPackage) {
1945 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001946 }
1947
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001949 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001950 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001951 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001952 return -1;
1953 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001954 final Phone phone = getPhone(subId);
1955 if (phone != null) {
1956 return phone.getCdmaEriIconMode();
1957 } else {
1958 return -1;
1959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001960 }
1961
1962 /**
1963 * Returns the CDMA ERI text,
1964 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001965 @Override
1966 public String getCdmaEriText(String callingPackage) {
1967 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001968 }
1969
Sanket Padawe356d7632015-06-22 14:03:32 -07001970 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001971 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001973 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001974 return null;
1975 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 final Phone phone = getPhone(subId);
1977 if (phone != null) {
1978 return phone.getCdmaEriText();
1979 } else {
1980 return null;
1981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 }
1983
1984 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001985 * Returns the CDMA MDN.
1986 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001987 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001988 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1990 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07001991 final Phone phone = getPhone(subId);
1992 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1993 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001994 } else {
1995 return null;
1996 }
1997 }
1998
1999 /**
2000 * Returns the CDMA MIN.
2001 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002002 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002003 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2005 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002006 final Phone phone = getPhone(subId);
2007 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2008 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002009 } else {
2010 return null;
2011 }
2012 }
2013
2014 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 * Returns true if CDMA provisioning needs to run.
2016 */
2017 public boolean needsOtaServiceProvisioning() {
2018 return mPhone.needsOtaServiceProvisioning();
2019 }
2020
2021 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002022 * Sets the voice mail number of a given subId.
2023 */
2024 @Override
2025 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002026 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002027 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2028 new Pair<String, String>(alphaTag, number), new Integer(subId));
2029 return success;
2030 }
2031
Ta-wei Yen87c49842016-05-13 21:19:52 -07002032 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002033 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2034 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2035 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2036 if (!TextUtils.equals(callingPackage, systemDialer)) {
2037 throw new SecurityException("caller must be system dialer");
2038 }
2039 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2040 if (phoneAccountHandle == null){
2041 return null;
2042 }
2043 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2044 }
2045
2046 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002047 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002048 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002050 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002051 return null;
2052 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002053 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2054 }
2055
2056 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002057 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2058 VisualVoicemailSmsFilterSettings settings) {
2059 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002060 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002061 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2062 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002063 }
2064
2065 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002066 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2067 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002068 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002069 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002070 }
2071
2072 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002073 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2074 String callingPackage, int subId) {
2075 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002076 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002077 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002078 }
2079
2080 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002081 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002082 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002083 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002084 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2085 }
2086
2087 @Override
2088 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2089 String number, int port, String text, PendingIntent sentIntent) {
2090 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002091 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002092 enforceSendSmsPermission();
2093 // Make the calls as the phone process.
2094 final long identity = Binder.clearCallingIdentity();
2095 try {
2096 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2097 if (port == 0) {
2098 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2099 sentIntent, null, false);
2100 } else {
2101 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2102 smsManager.sendDataMessageWithSelfPermissions(number, null,
2103 (short) port, data, sentIntent, null);
2104 }
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
2107 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002108 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002109 /**
fionaxu0152e512016-11-14 13:36:14 -08002110 * Sets the voice activation state of a given subId.
2111 */
2112 @Override
2113 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2115 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002116 final Phone phone = getPhone(subId);
2117 if (phone != null) {
2118 phone.setVoiceActivationState(activationState);
2119 } else {
2120 loge("setVoiceActivationState fails with invalid subId: " + subId);
2121 }
2122 }
2123
2124 /**
2125 * Sets the data activation state of a given subId.
2126 */
2127 @Override
2128 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2130 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002131 final Phone phone = getPhone(subId);
2132 if (phone != null) {
2133 phone.setDataActivationState(activationState);
2134 } else {
2135 loge("setVoiceActivationState fails with invalid subId: " + subId);
2136 }
2137 }
2138
2139 /**
2140 * Returns the voice activation state of a given subId.
2141 */
2142 @Override
2143 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002144 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002145 final Phone phone = getPhone(subId);
2146 if (phone != null) {
2147 return phone.getVoiceActivationState();
2148 } else {
2149 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2150 }
2151 }
2152
2153 /**
2154 * Returns the data activation state of a given subId.
2155 */
2156 @Override
2157 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002158 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002159 final Phone phone = getPhone(subId);
2160 if (phone != null) {
2161 return phone.getDataActivationState();
2162 } else {
2163 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2164 }
2165 }
2166
2167 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 * Returns the unread count of voicemails
2169 */
2170 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002171 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002172 }
2173
2174 /**
2175 * Returns the unread count of voicemails for a subId
2176 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002177 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002178 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002179 final Phone phone = getPhone(subId);
2180 if (phone != null) {
2181 return phone.getVoiceMessageCount();
2182 } else {
2183 return 0;
2184 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186
2187 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002188 * returns true, if the device is in a state where both voice and data
2189 * are supported simultaneously. This can change based on location or network condition.
2190 */
2191 @Override
2192 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2193 final Phone phone = getPhone(subId);
2194 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2195 }
2196
2197 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002198 * Send the dialer code if called from the current default dialer or the caller has
2199 * carrier privilege.
2200 * @param inputCode The dialer code to send
2201 */
2202 @Override
2203 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2204 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2205 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2206 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002207 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2208 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002209 }
2210 mPhone.sendDialerSpecialCode(inputCode);
2211 }
2212
2213 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002214 * Returns the data network type.
2215 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 *
2217 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2218 */
2219 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002220 public int getNetworkType() {
2221 final Phone phone = getPhone(getDefaultSubscription());
2222 if (phone != null) {
2223 return phone.getServiceState().getDataNetworkType();
2224 } else {
2225 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2226 }
Wink Saville36469e72014-06-11 15:17:00 -07002227 }
2228
2229 /**
2230 * Returns the network type for a subId
2231 */
2232 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002233 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002235 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002236 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2237 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002238
Sanket Padawe356d7632015-06-22 14:03:32 -07002239 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002240 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002241 return phone.getServiceState().getDataNetworkType();
2242 } else {
2243 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 }
2246
2247 /**
2248 * Returns the data network type
2249 */
2250 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002251 public int getDataNetworkType(String callingPackage) {
2252 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002253 }
2254
2255 /**
2256 * Returns the data network type for a subId
2257 */
2258 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002259 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002261 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002262 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2263 }
2264
Sanket Padawe356d7632015-06-22 14:03:32 -07002265 final Phone phone = getPhone(subId);
2266 if (phone != null) {
2267 return phone.getServiceState().getDataNetworkType();
2268 } else {
2269 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 }
2272
2273 /**
Wink Saville36469e72014-06-11 15:17:00 -07002274 * Returns the Voice network type for a subId
2275 */
2276 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002277 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002279 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002280 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2281 }
2282
Sanket Padawe356d7632015-06-22 14:03:32 -07002283 final Phone phone = getPhone(subId);
2284 if (phone != null) {
2285 return phone.getServiceState().getVoiceNetworkType();
2286 } else {
2287 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 }
2290
2291 /**
2292 * @return true if a ICC card is present
2293 */
2294 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002295 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002296 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2297 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002298 }
2299
2300 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002301 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002302 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002303 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002304 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2305 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002306 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002308 } else {
2309 return false;
2310 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 }
2312
2313 /**
2314 * Return if the current radio is LTE on CDMA. This
2315 * is a tri-state return value as for a period of time
2316 * the mode may be unknown.
2317 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002318 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002320 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002322 @Override
2323 public int getLteOnCdmaMode(String callingPackage) {
2324 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002325 }
2326
Sanket Padawe356d7632015-06-22 14:03:32 -07002327 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002328 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002330 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002331 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2332 }
2333
Sanket Padawe356d7632015-06-22 14:03:32 -07002334 final Phone phone = getPhone(subId);
2335 if (phone == null) {
2336 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2337 } else {
2338 return phone.getLteOnCdmaMode();
2339 }
Wink Saville36469e72014-06-11 15:17:00 -07002340 }
2341
2342 public void setPhone(Phone phone) {
2343 mPhone = phone;
2344 }
2345
2346 /**
2347 * {@hide}
2348 * Returns Default subId, 0 in the case of single standby.
2349 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002350 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002351 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002352 }
2353
Shishir Agrawala9f32182016-04-12 12:00:16 -07002354 private int getSlotForDefaultSubscription() {
2355 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2356 }
2357
Wink Savilleb564aae2014-10-23 10:18:09 -07002358 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002359 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002361
2362 /**
2363 * @see android.telephony.TelephonyManager.WifiCallingChoices
2364 */
2365 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002366 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2367 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002368 }
2369
2370 /**
2371 * @see android.telephony.TelephonyManager.WifiCallingChoices
2372 */
2373 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002374 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2375 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2376 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002377 }
2378
Sailesh Nepald1e68152013-12-12 19:08:02 -08002379 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002380 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002381 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002382 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002383
Shishir Agrawal566b7612013-10-28 14:41:00 -07002384 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002385 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2386 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2388 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002389
Derek Tan740e1672017-06-27 14:56:27 -07002390 if (TextUtils.equals(ISDR_AID, aid)) {
2391 // Only allows LPA to open logical channel to ISD-R.
2392 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2393 ComponentInfo bestComponent =
2394 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2395 if (bestComponent == null
2396 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2397 loge("The calling package is not allowed to access ISD-R.");
2398 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2399 }
2400 }
2401
2402 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002403 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002404 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002405 if (DBG) log("iccOpenLogicalChannel: " + response);
2406 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002407 }
2408
2409 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002410 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2412 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002413
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002414 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002415 if (channel < 0) {
2416 return false;
2417 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002418 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002419 if (DBG) log("iccCloseLogicalChannel: " + success);
2420 return success;
2421 }
2422
2423 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002424 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002425 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2427 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002428
2429 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002430 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2431 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002432 " data=" + data);
2433 }
2434
2435 if (channel < 0) {
2436 return "";
2437 }
2438
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002439 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002440 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002441 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2442
Shishir Agrawal566b7612013-10-28 14:41:00 -07002443 // Append the returned status code to the end of the response payload.
2444 String s = Integer.toHexString(
2445 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002446 if (response.payload != null) {
2447 s = IccUtils.bytesToHexString(response.payload) + s;
2448 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002449 return s;
2450 }
Jake Hambye994d462014-02-03 13:10:13 -08002451
Evan Charltonc66da362014-05-16 14:06:40 -07002452 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002453 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2454 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2456 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002457
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002458 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2459 && TextUtils.equals(ISDR_AID, data)) {
2460 // Only allows LPA to select ISD-R.
2461 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2462 ComponentInfo bestComponent =
2463 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2464 if (bestComponent == null
2465 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2466 loge("The calling package is not allowed to select ISD-R.");
2467 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2468 }
2469 }
2470
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002471 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002472 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2473 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002474 }
2475
2476 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002477 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002478 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2479
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002480 // Append the returned status code to the end of the response payload.
2481 String s = Integer.toHexString(
2482 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002483 if (response.payload != null) {
2484 s = IccUtils.bytesToHexString(response.payload) + s;
2485 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002486 return s;
2487 }
2488
2489 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002490 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002491 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2493 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002494
2495 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002496 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002497 p1 + " " + p2 + " " + p3 + ":" + filePath);
2498 }
2499
2500 IccIoResult response =
2501 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002502 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2503 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002504
2505 if (DBG) {
2506 log("Exchange SIM_IO [R]" + response);
2507 }
2508
2509 byte[] result = null;
2510 int length = 2;
2511 if (response.payload != null) {
2512 length = 2 + response.payload.length;
2513 result = new byte[length];
2514 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2515 } else {
2516 result = new byte[length];
2517 }
2518
2519 result[length - 1] = (byte) response.sw2;
2520 result[length - 2] = (byte) response.sw1;
2521 return result;
2522 }
2523
Nathan Haroldb3014052017-01-25 15:57:32 -08002524 /**
2525 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2526 * on a particular subscription
2527 */
2528 public String[] getForbiddenPlmns(int subId, int appType) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002529 // TODO(b/73884967): Migrate to TelephonyPermissions check.
Nathan Harold892104e2017-04-13 18:19:05 -07002530 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2531 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002532 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2533 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2534 return null;
2535 }
2536 Object response = sendRequest(
2537 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2538 if (response instanceof String[]) {
2539 return (String[]) response;
2540 }
2541 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2542 return null;
2543 }
2544
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002545 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002546 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2548 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002549
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002550 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002551 if (response.payload == null) {
2552 return "";
2553 }
2554
2555 // Append the returned status code to the end of the response payload.
2556 String s = Integer.toHexString(
2557 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2558 s = IccUtils.bytesToHexString(response.payload) + s;
2559 return s;
2560 }
2561
Jake Hambye994d462014-02-03 13:10:13 -08002562 /**
2563 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2564 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2565 *
2566 * @param itemID the ID of the item to read
2567 * @return the NV item as a String, or null on error.
2568 */
2569 @Override
2570 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2572 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002573 if (DBG) log("nvReadItem: item " + itemID);
2574 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2575 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2576 return value;
2577 }
2578
2579 /**
2580 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2581 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2582 *
2583 * @param itemID the ID of the item to read
2584 * @param itemValue the value to write, as a String
2585 * @return true on success; false on any failure
2586 */
2587 @Override
2588 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2590 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002591 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2592 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2593 new Pair<Integer, String>(itemID, itemValue));
2594 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2595 return success;
2596 }
2597
2598 /**
2599 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2600 * Used for device configuration by some CDMA operators.
2601 *
2602 * @param preferredRoamingList byte array containing the new PRL
2603 * @return true on success; false on any failure
2604 */
2605 @Override
2606 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2608 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002609 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2610 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2611 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2612 return success;
2613 }
2614
2615 /**
2616 * Perform the specified type of NV config reset.
2617 * Used for device configuration by some CDMA operators.
2618 *
2619 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2620 * @return true on success; false on any failure
2621 */
2622 @Override
2623 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2625 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002626 if (DBG) log("nvResetConfig: type " + resetType);
2627 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2628 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2629 return success;
2630 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002631
2632 /**
Wink Saville36469e72014-06-11 15:17:00 -07002633 * {@hide}
2634 * Returns Default sim, 0 in the case of single standby.
2635 */
2636 public int getDefaultSim() {
2637 //TODO Need to get it from Telephony Devcontroller
2638 return 0;
2639 }
2640
Svet Ganovb320e182015-04-16 12:30:10 -07002641 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002642 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002643 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002644 return new String[0];
2645 }
2646
2647
ram87fca6f2014-07-18 18:58:44 +05302648 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002649 }
2650
Brad Ebinger51f743a2017-01-23 13:50:20 -08002651 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002652 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2653 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002654 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002655 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002656 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002657 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002658 }
2659
2660 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002661 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2662 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002663 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002664 public void disableIms(int slotId) {
2665 enforceModifyPermission();
2666 PhoneFactory.getImsResolver().disableIms(slotId);
2667 }
2668
2669 /**
2670 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2671 * feature or {@link null} if the service is not available. If the feature is available, the
2672 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2673 */
2674 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002675 IImsServiceFeatureCallback callback) {
2676 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002677 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002678 }
2679
2680 /**
2681 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2682 * feature during emergency calling or {@link null} if the service is not available. If the
2683 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2684 * listener for feature updates.
2685 */
2686 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2687 enforceModifyPermission();
2688 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002689 }
2690
Brad Ebinger5f64b052017-12-14 14:26:15 -08002691 /**
2692 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2693 * specified.
2694 */
2695 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2696 enforceModifyPermission();
2697 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2698 }
2699
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002700 /**
2701 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2702 * specified.
2703 */
2704 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2705 enforceModifyPermission();
2706 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2707 }
2708
Brad Ebinger884c07b2018-02-15 16:17:40 -08002709 /**
2710 * @return true if emergency calling is available on IMS, false if it should fallback to CS.
2711 */
2712 public boolean isEmergencyMmTelAvailable(int slotId) {
2713 enforceModifyPermission();
2714 return PhoneFactory.getImsResolver().isEmergencyMmTelAvailable(slotId);
2715 }
2716
Brad Ebinger304415d2018-03-02 13:43:36 -08002717 /**
2718 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2719 * available, false if the IMS resolver is idle.
2720 */
2721 public boolean isResolvingImsBinding() {
2722 enforceModifyPermission();
2723 return PhoneFactory.getImsResolver().isResolvingBinding();
2724 }
2725
Wink Saville36469e72014-06-11 15:17:00 -07002726 public void setImsRegistrationState(boolean registered) {
2727 enforceModifyPermission();
2728 mPhone.setImsRegistrationState(registered);
2729 }
2730
2731 /**
Stuart Scott54788802015-03-30 13:18:01 -07002732 * Set the network selection mode to automatic.
2733 *
2734 */
2735 @Override
2736 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2738 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002739 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2740 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2741 }
2742
2743 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002744 * Set the network selection mode to manual with the selected carrier.
2745 */
2746 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002747 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002748 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2750 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002751 OperatorInfo operator = new OperatorInfo(
2752 /* operatorAlphaLong */ "",
2753 /* operatorAlphaShort */ "",
2754 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002755 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002756 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2757 persistSelection);
2758 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002759 }
2760
2761 /**
2762 * Scans for available networks.
2763 */
2764 @Override
2765 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2767 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002768 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2769 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2770 CMD_PERFORM_NETWORK_SCAN, null, subId);
2771 return result;
2772 }
2773
2774 /**
yinxub1bed742017-04-17 11:45:04 -07002775 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002776 *
yinxub1bed742017-04-17 11:45:04 -07002777 * @param subId id of the subscription
2778 * @param request contains the radio access networks with bands/channels to scan
2779 * @param messenger callback messenger for scan results or errors
2780 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002781 * @return the id of the requested scan which can be used to stop the scan.
2782 */
2783 @Override
2784 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2785 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2787 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002788 return mNetworkScanRequestTracker.startNetworkScan(
2789 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002790 }
2791
2792 /**
2793 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002794 *
2795 * @param subId id of the subscription
2796 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002797 */
2798 @Override
2799 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002800 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2801 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002802 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002803 }
2804
2805 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002806 * Get the calculated preferred network type.
2807 * Used for debugging incorrect network type.
2808 *
2809 * @return the preferred network type, defined in RILConstants.java.
2810 */
2811 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002812 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002813 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002814 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002815 return RILConstants.PREFERRED_NETWORK_MODE;
2816 }
2817
Amit Mahajan43330e02014-11-18 11:54:45 -08002818 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002819 }
2820
2821 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002822 * Get the preferred network type.
2823 * Used for device configuration by some CDMA operators.
2824 *
2825 * @return the preferred network type, defined in RILConstants.java.
2826 */
2827 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002828 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2830 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002831 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002832 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002833 int networkType = (result != null ? result[0] : -1);
2834 if (DBG) log("getPreferredNetworkType: " + networkType);
2835 return networkType;
2836 }
2837
2838 /**
2839 * Set the preferred network type.
2840 * Used for device configuration by some CDMA operators.
2841 *
2842 * @param networkType the preferred network type, defined in RILConstants.java.
2843 * @return true on success; false on any failure.
2844 */
2845 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002846 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2848 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002849 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2850 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002851 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002852 if (success) {
2853 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002854 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002855 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002856 return success;
2857 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002858
2859 /**
Junda Liu475951f2014-11-07 16:45:03 -08002860 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2861 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2862 * tethering.
2863 *
2864 * @return 0: Not required. 1: required. 2: Not set.
2865 * @hide
2866 */
2867 @Override
2868 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002869 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002870 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2871 Settings.Global.TETHER_DUN_REQUIRED, 2);
2872 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2873 // config_tether_apndata.
2874 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2875 dunRequired = 1;
2876 }
2877 return dunRequired;
2878 }
2879
2880 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002881 * Set mobile data enabled
2882 * Used by the user through settings etc to turn on/off mobile data
2883 *
2884 * @param enable {@code true} turn turn data on, else {@code false}
2885 */
2886 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002887 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2889 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002890 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002891 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002892 Phone phone = PhoneFactory.getPhone(phoneId);
2893 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002894 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2895 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002896 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002897 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002898 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002899 }
2900
2901 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002902 * Get the user enabled state of Mobile Data.
2903 *
2904 * TODO: remove and use isUserDataEnabled.
2905 * This can't be removed now because some vendor codes
2906 * calls through ITelephony directly while they should
2907 * use TelephonyManager.
2908 *
2909 * @return true on enabled
2910 */
2911 @Override
2912 public boolean getDataEnabled(int subId) {
2913 return isUserDataEnabled(subId);
2914 }
2915
2916 /**
2917 * Get whether mobile data is enabled per user setting.
2918 *
2919 * There are other factors deciding whether mobile data is actually enabled, but they are
2920 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002921 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002922 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002923 *
2924 * @return {@code true} if data is enabled else {@code false}
2925 */
2926 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002927 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002928 try {
2929 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2930 null);
2931 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2933 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002934 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002935 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002936 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002937 Phone phone = PhoneFactory.getPhone(phoneId);
2938 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002939 boolean retVal = phone.isUserDataEnabled();
2940 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002941 return retVal;
2942 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002943 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2944 return false;
2945 }
2946 }
2947
2948 /**
2949 * Get whether mobile data is enabled.
2950 *
2951 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2952 * whether mobile data is actually enabled.
2953 *
2954 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2955 *
2956 * @return {@code true} if data is enabled else {@code false}
2957 */
2958 @Override
2959 public boolean isDataEnabled(int subId) {
2960 try {
2961 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2962 null);
2963 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002964 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2965 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08002966 }
2967 int phoneId = mSubscriptionController.getPhoneId(subId);
2968 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2969 Phone phone = PhoneFactory.getPhone(phoneId);
2970 if (phone != null) {
2971 boolean retVal = phone.isDataEnabled();
2972 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2973 return retVal;
2974 } else {
2975 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002976 return false;
2977 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002978 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002979
2980 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002981 public int getCarrierPrivilegeStatus(int subId) {
2982 final Phone phone = getPhone(subId);
2983 if (phone == null) {
2984 loge("getCarrierPrivilegeStatus: Invalid subId");
2985 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2986 }
2987 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002988 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002989 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002990 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2991 }
2992 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002993 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002994 }
Junda Liu29340342014-07-10 15:23:27 -07002995
2996 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08002997 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
2998 final Phone phone = getPhone(subId);
2999 if (phone == null) {
3000 loge("getCarrierPrivilegeStatus: Invalid subId");
3001 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3002 }
3003 UiccProfile profile =
3004 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3005 if (profile == null) {
3006 loge("getCarrierPrivilegeStatus: No UICC");
3007 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3008 }
3009 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3010 }
3011
3012 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003013 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003014 if (TextUtils.isEmpty(pkgName))
3015 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003016 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003017 if (card == null) {
3018 loge("checkCarrierPrivilegesForPackage: No UICC");
3019 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3020 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003021 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3022 }
3023
3024 @Override
3025 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003026 if (TextUtils.isEmpty(pkgName))
3027 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003028 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3029 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3030 UiccCard card = UiccController.getInstance().getUiccCard(i);
3031 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003032 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003033 continue;
3034 }
3035
3036 result = card.getCarrierPrivilegeStatus(
3037 mPhone.getContext().getPackageManager(), pkgName);
3038 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3039 break;
3040 }
3041 }
3042
3043 return result;
Junda Liu29340342014-07-10 15:23:27 -07003044 }
Derek Tan89e89d42014-07-08 17:00:10 -07003045
3046 @Override
Junda Liue64de782015-04-16 17:19:16 -07003047 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3048 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3049 loge("phoneId " + phoneId + " is not valid.");
3050 return null;
3051 }
3052 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003053 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003054 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003055 return null ;
3056 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003057 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003058 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003059 }
3060
Amith Yamasani6e118872016-02-19 12:53:51 -08003061 @Override
3062 public List<String> getPackagesWithCarrierPrivileges() {
3063 PackageManager pm = mPhone.getContext().getPackageManager();
3064 List<String> privilegedPackages = new ArrayList<>();
3065 List<PackageInfo> packages = null;
3066 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3067 UiccCard card = UiccController.getInstance().getUiccCard(i);
3068 if (card == null) {
3069 // No UICC in that slot.
3070 continue;
3071 }
3072 if (card.hasCarrierPrivilegeRules()) {
3073 if (packages == null) {
3074 // Only check packages in user 0 for now
3075 packages = pm.getInstalledPackagesAsUser(
3076 PackageManager.MATCH_DISABLED_COMPONENTS
3077 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3078 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3079 }
3080 for (int p = packages.size() - 1; p >= 0; p--) {
3081 PackageInfo pkgInfo = packages.get(p);
3082 if (pkgInfo != null && pkgInfo.packageName != null
3083 && card.getCarrierPrivilegeStatus(pkgInfo)
3084 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3085 privilegedPackages.add(pkgInfo.packageName);
3086 }
3087 }
3088 }
3089 }
3090 return privilegedPackages;
3091 }
3092
Wink Savilleb564aae2014-10-23 10:18:09 -07003093 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003094 final Phone phone = getPhone(subId);
3095 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003096 if (card == null) {
3097 loge("getIccId: No UICC");
3098 return null;
3099 }
3100 String iccId = card.getIccId();
3101 if (TextUtils.isEmpty(iccId)) {
3102 loge("getIccId: ICC ID is null or empty.");
3103 return null;
3104 }
3105 return iccId;
3106 }
3107
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003108 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003109 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3110 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003111 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3112 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003113
Jeff Sharkey85190e62014-12-05 09:40:12 -08003114 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003115 final Phone phone = getPhone(subId);
3116 if (phone == null) {
3117 return false;
3118 }
3119 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003120
3121 if (DBG_MERGE) {
3122 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3123 + subscriberId + " to " + number);
3124 }
3125
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003126 if (TextUtils.isEmpty(iccId)) {
3127 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003128 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003129
Jeff Sharkey85190e62014-12-05 09:40:12 -08003130 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3131
3132 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003133 if (alphaTag == null) {
3134 editor.remove(alphaTagPrefKey);
3135 } else {
3136 editor.putString(alphaTagPrefKey, alphaTag);
3137 }
3138
Jeff Sharkey85190e62014-12-05 09:40:12 -08003139 // Record both the line number and IMSI for this ICCID, since we need to
3140 // track all merged IMSIs based on line number
3141 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3142 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003143 if (number == null) {
3144 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003145 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003146 } else {
3147 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003148 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003149 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003150
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003151 editor.commit();
3152 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003153 }
3154
3155 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003156 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003157 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003159 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003160 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003161 return null;
3162 }
Derek Tan97ebb422014-09-05 16:55:38 -07003163
3164 String iccId = getIccId(subId);
3165 if (iccId != null) {
3166 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003167 if (DBG_MERGE) {
3168 log("getLine1NumberForDisplay returning " +
3169 mTelephonySharedPreferences.getString(numberPrefKey, null));
3170 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003171 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003172 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003173 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003174 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003175 }
3176
3177 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003178 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003180 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003181 return null;
3182 }
Derek Tan97ebb422014-09-05 16:55:38 -07003183
3184 String iccId = getIccId(subId);
3185 if (iccId != null) {
3186 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003187 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003188 }
Derek Tan97ebb422014-09-05 16:55:38 -07003189 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003190 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003191
3192 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003193 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003194 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3195 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003197 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3198 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003199 return null;
3200 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003201 final Context context = mPhone.getContext();
3202 final TelephonyManager tele = TelephonyManager.from(context);
3203 final SubscriptionManager sub = SubscriptionManager.from(context);
3204
3205 // Figure out what subscribers are currently active
3206 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003207 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3208 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3209 final long identity = Binder.clearCallingIdentity();
3210 try {
3211 final int[] subIds = sub.getActiveSubscriptionIdList();
3212 for (int subId : subIds) {
3213 activeSubscriberIds.add(tele.getSubscriberId(subId));
3214 }
3215 } finally {
3216 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003217 }
3218
3219 // First pass, find a number override for an active subscriber
3220 String mergeNumber = null;
3221 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3222 for (String key : prefs.keySet()) {
3223 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3224 final String subscriberId = (String) prefs.get(key);
3225 if (activeSubscriberIds.contains(subscriberId)) {
3226 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3227 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3228 mergeNumber = (String) prefs.get(numberKey);
3229 if (DBG_MERGE) {
3230 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3231 + " for active subscriber " + subscriberId);
3232 }
3233 if (!TextUtils.isEmpty(mergeNumber)) {
3234 break;
3235 }
3236 }
3237 }
3238 }
3239
3240 // Shortcut when no active merged subscribers
3241 if (TextUtils.isEmpty(mergeNumber)) {
3242 return null;
3243 }
3244
3245 // Second pass, find all subscribers under that line override
3246 final ArraySet<String> result = new ArraySet<>();
3247 for (String key : prefs.keySet()) {
3248 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3249 final String number = (String) prefs.get(key);
3250 if (mergeNumber.equals(number)) {
3251 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3252 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3253 final String subscriberId = (String) prefs.get(subscriberKey);
3254 if (!TextUtils.isEmpty(subscriberId)) {
3255 result.add(subscriberId);
3256 }
3257 }
3258 }
3259 }
3260
3261 final String[] resultArray = result.toArray(new String[result.size()]);
3262 Arrays.sort(resultArray);
3263 if (DBG_MERGE) {
3264 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3265 }
3266 return resultArray;
3267 }
3268
3269 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003270 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003271 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3272 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003273 final Phone phone = getPhone(subId);
3274 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003275 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003276
3277 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003278 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003279 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3280 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003281 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003282 final Phone phone = getPhone(subId);
3283 if (phone == null) {
3284 return false;
3285 }
3286 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003287 cdmaNonRoamingList);
3288 }
3289
3290 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003291 public void setRadioCapability(RadioAccessFamily[] rafs) {
3292 try {
3293 ProxyController.getInstance().setRadioCapability(rafs);
3294 } catch (RuntimeException e) {
3295 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3296 }
3297 }
3298
3299 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003300 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003301 Phone phone = PhoneFactory.getPhone(phoneId);
3302 if (phone == null) {
3303 return RadioAccessFamily.RAF_UNKNOWN;
3304 }
3305 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003307 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003308 return RadioAccessFamily.RAF_UNKNOWN;
3309 }
3310
Wink Saville5d475dd2014-10-17 15:00:58 -07003311 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3312 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003313
3314 @Override
3315 public void enableVideoCalling(boolean enable) {
3316 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003317 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003318 }
3319
3320 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003321 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003323 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003324 return false;
3325 }
3326
Andrew Lee77527ac2014-10-21 16:57:39 -07003327 // Check the user preference and the system-level IMS setting. Even if the user has
3328 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3329 // In the long run, we may instead need to check if there exists a connection service
3330 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003331 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3332 return imsManager.isVtEnabledByPlatform()
3333 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3334 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003335 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003336
Andrew Leea1239f22015-03-02 17:44:07 -08003337 @Override
3338 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003339 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003340 }
3341
3342 @Override
3343 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003344 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003345 }
3346
Andrew Lee9431b832015-03-09 18:46:45 -07003347 @Override
3348 public boolean isTtyModeSupported() {
3349 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3350 TelephonyManager telephonyManager =
3351 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003352 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003353 }
3354
3355 @Override
3356 public boolean isHearingAidCompatibilitySupported() {
3357 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3358 }
3359
Hall Liu98187582018-01-22 19:15:32 -08003360 public boolean isRttSupported() {
3361 boolean isCarrierSupported =
3362 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3363 boolean isDeviceSupported =
3364 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3365 return isCarrierSupported && isDeviceSupported;
3366 }
3367
Sanket Padawe7310cc72015-01-14 09:53:20 -08003368 /**
3369 * Returns the unique device ID of phone, for example, the IMEI for
3370 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3371 *
3372 * <p>Requires Permission:
3373 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3374 */
3375 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003376 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003377 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08003378 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003379 return null;
3380 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003381 int subId = phone.getSubId();
3382 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3383 mApp, subId, callingPackage, "getDeviceId")) {
3384 return null;
3385 }
3386 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003387 }
3388
Ping Sunc67b7c22016-03-02 19:16:45 +08003389 /**
3390 * {@hide}
3391 * Returns the IMS Registration Status on a particular subid
3392 *
3393 * @param subId
3394 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003395 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003396 Phone phone = getPhone(subId);
3397 if (phone != null) {
3398 return phone.isImsRegistered();
3399 } else {
3400 return false;
3401 }
3402 }
3403
Santos Cordon7a1885b2015-02-03 11:15:19 -08003404 @Override
3405 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3406 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3407 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003408
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003409 /**
3410 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003411 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003412 public boolean isWifiCallingAvailable(int subId) {
3413 Phone phone = getPhone(subId);
3414 if (phone != null) {
3415 return phone.isWifiCallingEnabled();
3416 } else {
3417 return false;
3418 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003419 }
3420
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003421 /**
3422 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003423 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003424 public boolean isVolteAvailable(int subId) {
3425 Phone phone = getPhone(subId);
3426 if (phone != null) {
3427 return phone.isVolteEnabled();
3428 } else {
3429 return false;
3430 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003431 }
Svet Ganovb320e182015-04-16 12:30:10 -07003432
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003433 /**
3434 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003435 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003436 public boolean isVideoTelephonyAvailable(int subId) {
3437 Phone phone = getPhone(subId);
3438 if (phone != null) {
3439 return phone.isVideoEnabled();
3440 } else {
3441 return false;
3442 }
3443 }
3444
3445 /**
3446 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3447 * defined in {@link ImsRegistrationImplBase}.
3448 */
3449 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3450 Phone phone = getPhone(subId);
3451 if (phone != null) {
3452 return phone.getImsRegistrationTech();
3453 } else {
3454 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3455 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003456 }
3457
Stuart Scott8eef64f2015-04-08 15:13:54 -07003458 @Override
3459 public void factoryReset(int subId) {
3460 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003461 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3462 return;
3463 }
3464
Svet Ganovcc087f82015-05-12 20:35:54 -07003465 final long identity = Binder.clearCallingIdentity();
3466 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003467 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3468 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07003469 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07003470 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07003471 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
3472 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07003473 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003474 }
3475 } finally {
3476 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003477 }
3478 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003479
3480 @Override
3481 public String getLocaleFromDefaultSim() {
3482 // We query all subscriptions instead of just the active ones, because
3483 // this might be called early on in the provisioning flow when the
3484 // subscriptions potentially aren't active yet.
3485 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3486 if (slist == null || slist.isEmpty()) {
3487 return null;
3488 }
3489
3490 // This function may be called very early, say, from the setup wizard, at
3491 // which point we won't have a default subscription set. If that's the case
3492 // we just choose the first, which will be valid in "most cases".
3493 final int defaultSubId = getDefaultSubscription();
3494 SubscriptionInfo info = null;
3495 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3496 info = slist.get(0);
3497 } else {
3498 for (SubscriptionInfo item : slist) {
3499 if (item.getSubscriptionId() == defaultSubId) {
3500 info = item;
3501 break;
3502 }
3503 }
3504
3505 if (info == null) {
3506 return null;
3507 }
3508 }
3509
3510 // Try and fetch the locale from the carrier properties or from the SIM language
3511 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003512 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003513 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003514 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003515 if (defaultPhone != null) {
3516 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3517 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003518 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003519 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3520 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003521 } else {
3522 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003523 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003524 }
3525 }
3526
Narayan Kamath011676f2015-07-29 12:04:08 +01003527 // The SIM language preferences only store a language (e.g. fr = French), not an
3528 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3529 // the SIM and carrier preferences does not include a country we add the country
3530 // determined from the SIM MCC to provide an exact locale.
3531 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003532 if (mccLocale != null) {
3533 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3534 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003535 }
3536
Tony Hill183b2de2015-06-24 14:53:58 +01003537 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003538 return null;
3539 }
3540
3541 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3542 final long identity = Binder.clearCallingIdentity();
3543 try {
3544 return mSubscriptionController.getAllSubInfoList(
3545 mPhone.getContext().getOpPackageName());
3546 } finally {
3547 Binder.restoreCallingIdentity(identity);
3548 }
3549 }
3550
3551 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 return mSubscriptionController.getActiveSubscriptionInfoList(
3555 mPhone.getContext().getOpPackageName());
3556 } finally {
3557 Binder.restoreCallingIdentity(identity);
3558 }
3559 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003560
Chenjie Yu1ba97252018-01-11 18:16:20 -08003561 private final ModemActivityInfo mLastModemActivityInfo =
3562 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3563
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003564 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003565 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3566 * representing the state of the modem.
3567 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003568 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3569 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003570 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003571 */
3572 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003573 public void requestModemActivityInfo(ResultReceiver result) {
3574 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003575 ModemActivityInfo ret = null;
3576 synchronized (mLastModemActivityInfo) {
3577 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3578 null);
3579 if (info != null) {
3580 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3581 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3582 mergedTxTimeMs[i] =
3583 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3584 }
3585 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3586 mLastModemActivityInfo.setSleepTimeMillis(
3587 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3588 mLastModemActivityInfo.setIdleTimeMillis(
3589 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3590 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3591 mLastModemActivityInfo.setRxTimeMillis(
3592 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3593 mLastModemActivityInfo.setEnergyUsed(
3594 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3595 }
3596 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3597 mLastModemActivityInfo.getSleepTimeMillis(),
3598 mLastModemActivityInfo.getIdleTimeMillis(),
3599 mLastModemActivityInfo.getTxTimeMillis(),
3600 mLastModemActivityInfo.getRxTimeMillis(),
3601 mLastModemActivityInfo.getEnergyUsed());
3602 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003603 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003604 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003605 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003606 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003607
3608 /**
3609 * {@hide}
3610 * Returns the service state information on specified subscription.
3611 */
3612 @Override
3613 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3614
Jeff Davidson7e17e312018-02-13 18:17:36 -08003615 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003616 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003617 return null;
3618 }
3619
3620 final Phone phone = getPhone(subId);
3621 if (phone == null) {
3622 return null;
3623 }
3624
3625 return phone.getServiceState();
3626 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003627
3628 /**
3629 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3630 *
3631 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3632 * voicemail ringtone.
3633 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3634 * PhoneAccount.
3635 */
3636 @Override
3637 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003638 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003639 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003640 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003641 }
3642
fionaxu7ed723d2017-05-30 18:58:54 -07003643 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003644 }
3645
3646 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003647 * Sets the per-account voicemail ringtone.
3648 *
3649 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3650 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3651 *
3652 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3653 * voicemail ringtone.
3654 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3655 * PhoneAccount.
3656 */
3657 @Override
3658 public void setVoicemailRingtoneUri(String callingPackage,
3659 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3660 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3661 if (!TextUtils.equals(callingPackage,
3662 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3664 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3665 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003666 }
3667 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3668 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003669 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003670 }
fionaxu7ed723d2017-05-30 18:58:54 -07003671 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003672 }
3673
3674 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003675 * Returns whether vibration is set for voicemail notification in Phone settings.
3676 *
3677 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3678 * voicemail vibration setting.
3679 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3680 */
3681 @Override
3682 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003683 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003684 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003685 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003686 }
3687
fionaxu7ed723d2017-05-30 18:58:54 -07003688 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003689 }
3690
Youhan Wange64578a2016-05-02 15:32:42 -07003691 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003692 * Sets the per-account voicemail vibration.
3693 *
3694 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3695 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3696 *
3697 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3698 * voicemail vibration setting.
3699 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3700 * specific PhoneAccount.
3701 */
3702 @Override
3703 public void setVoicemailVibrationEnabled(String callingPackage,
3704 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3705 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3706 if (!TextUtils.equals(callingPackage,
3707 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3709 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3710 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003711 }
3712
3713 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3714 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003715 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003716 }
fionaxu7ed723d2017-05-30 18:58:54 -07003717 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003718 }
3719
3720 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003721 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3722 *
3723 * @throws SecurityException if the caller does not have the required permission
3724 */
3725 private void enforceReadPrivilegedPermission() {
3726 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3727 null);
3728 }
3729
3730 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003731 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3732 * permission.
3733 *
3734 * @throws SecurityException if the caller does not have the required permission
3735 */
3736 private void enforceSendSmsPermission() {
3737 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3738 }
3739
3740 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003741 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003742 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003743 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003744 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003745 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003746 ComponentName componentName =
3747 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3748 if(componentName == null) {
3749 throw new SecurityException("Caller not current active visual voicemail package[null]");
3750 }
3751 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003752 if (!callingPackage.equals(vvmPackage)) {
3753 throw new SecurityException("Caller not current active visual voicemail package[" +
3754 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003755 }
3756 }
3757
3758 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003759 * Return the application ID for the app type.
3760 *
3761 * @param subId the subscription ID that this request applies to.
3762 * @param appType the uicc app type.
3763 * @return Application ID for specificied app type, or null if no uicc.
3764 */
3765 @Override
3766 public String getAidForAppType(int subId, int appType) {
3767 enforceReadPrivilegedPermission();
3768 Phone phone = getPhone(subId);
3769 if (phone == null) {
3770 return null;
3771 }
3772 String aid = null;
3773 try {
3774 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3775 .getApplicationByType(appType).getAid();
3776 } catch (Exception e) {
3777 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3778 }
3779 return aid;
3780 }
3781
Youhan Wang4001d252016-05-11 10:29:41 -07003782 /**
3783 * Return the Electronic Serial Number.
3784 *
3785 * @param subId the subscription ID that this request applies to.
3786 * @return ESN or null if error.
3787 */
3788 @Override
3789 public String getEsn(int subId) {
3790 enforceReadPrivilegedPermission();
3791 Phone phone = getPhone(subId);
3792 if (phone == null) {
3793 return null;
3794 }
3795 String esn = null;
3796 try {
3797 esn = phone.getEsn();
3798 } catch (Exception e) {
3799 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3800 }
3801 return esn;
3802 }
3803
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003804 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003805 * Return the Preferred Roaming List Version.
3806 *
3807 * @param subId the subscription ID that this request applies to.
3808 * @return PRLVersion or null if error.
3809 */
3810 @Override
3811 public String getCdmaPrlVersion(int subId) {
3812 enforceReadPrivilegedPermission();
3813 Phone phone = getPhone(subId);
3814 if (phone == null) {
3815 return null;
3816 }
3817 String cdmaPrlVersion = null;
3818 try {
3819 cdmaPrlVersion = phone.getCdmaPrlVersion();
3820 } catch (Exception e) {
3821 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3822 }
3823 return cdmaPrlVersion;
3824 }
3825
3826 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003827 * Get snapshot of Telephony histograms
3828 * @return List of Telephony histograms
3829 * @hide
3830 */
3831 @Override
3832 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3834 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003835 return RIL.getTelephonyRILTimingHistograms();
3836 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003837
3838 /**
3839 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003840 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003841 * Require system privileges. In the future we may add this to carrier APIs.
3842 *
3843 * @return The number of carriers set successfully, should match length of carriers
3844 */
3845 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003846 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003847 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003848
Meng Wang9b7c4e92017-02-17 11:41:27 -08003849 if (carriers == null) {
3850 throw new NullPointerException("carriers cannot be null");
3851 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003852
3853 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003854 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3855 return retVal[0];
3856 }
3857
3858 /**
3859 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003860 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003861 * Require system privileges. In the future we may add this to carrier APIs.
3862 *
3863 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3864 * means all carriers are allowed.
3865 */
3866 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003867 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003868 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003869 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003870 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3871 }
3872
fionaxu59545b42016-05-25 15:53:37 -07003873 /**
3874 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3875 * @param subId the subscription ID that this action applies to.
3876 * @param enabled control enable or disable metered apns.
3877 * {@hide}
3878 */
3879 @Override
3880 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3881 enforceModifyPermission();
3882 final Phone phone = getPhone(subId);
3883 if (phone == null) {
3884 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3885 return;
3886 }
3887 try {
3888 phone.carrierActionSetMeteredApnsEnabled(enabled);
3889 } catch (Exception e) {
3890 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3891 }
3892 }
3893
3894 /**
3895 * Action set from carrier signalling broadcast receivers to enable/disable radio
3896 * @param subId the subscription ID that this action applies to.
3897 * @param enabled control enable or disable radio.
3898 * {@hide}
3899 */
3900 @Override
3901 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3902 enforceModifyPermission();
3903 final Phone phone = getPhone(subId);
3904 if (phone == null) {
3905 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3906 return;
3907 }
3908 try {
3909 phone.carrierActionSetRadioEnabled(enabled);
3910 } catch (Exception e) {
3911 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3912 }
3913 }
3914
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003915 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003916 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3917 * network status based on which carrier apps could apply actions accordingly,
3918 * enable/disable default url handler for example.
3919 *
3920 * @param subId the subscription ID that this action applies to.
3921 * @param report control start/stop reporting the default network status.
3922 * {@hide}
3923 */
3924 @Override
3925 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3926 enforceModifyPermission();
3927 final Phone phone = getPhone(subId);
3928 if (phone == null) {
3929 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3930 return;
3931 }
3932 try {
3933 phone.carrierActionReportDefaultNetworkStatus(report);
3934 } catch (Exception e) {
3935 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3936 }
3937 }
3938
3939 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003940 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3941 * bug report is being generated.
3942 */
3943 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003944 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003945 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3946 != PackageManager.PERMISSION_GRANTED) {
3947 writer.println("Permission Denial: can't dump Phone from pid="
3948 + Binder.getCallingPid()
3949 + ", uid=" + Binder.getCallingUid()
3950 + "without permission "
3951 + android.Manifest.permission.DUMP);
3952 return;
3953 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003954 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003955 }
Jack Yueb89b242016-06-22 13:27:47 -07003956
3957 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003958 * Get aggregated video call data usage since boot.
3959 *
3960 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3961 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003962 * {@hide}
3963 */
3964 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003965 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003966 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3967 null);
3968
Jack Yu84291ec2017-05-26 16:07:50 -07003969 // NetworkStatsService keeps tracking the active network interface and identity. It
3970 // records the delta with the corresponding network identity. We just return the total video
3971 // call data usage snapshot since boot.
3972 Phone phone = getPhone(subId);
3973 if (phone != null) {
3974 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003975 }
Jack Yu84291ec2017-05-26 16:07:50 -07003976 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003977 }
Jack Yu75ab2952016-07-08 14:29:33 -07003978
3979 /**
3980 * Policy control of data connection. Usually used when data limit is passed.
3981 * @param enabled True if enabling the data, otherwise disabling.
3982 * @param subId Subscription index
3983 * {@hide}
3984 */
3985 @Override
3986 public void setPolicyDataEnabled(boolean enabled, int subId) {
3987 enforceModifyPermission();
3988 Phone phone = getPhone(subId);
3989 if (phone != null) {
3990 phone.setPolicyDataEnabled(enabled);
3991 }
3992 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003993
3994 /**
3995 * Get Client request stats
3996 * @return List of Client Request Stats
3997 * @hide
3998 */
3999 @Override
4000 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004001 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004002 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004003 return null;
4004 }
4005
4006 Phone phone = getPhone(subId);
4007 if (phone != null) {
4008 return phone.getClientRequestStats();
4009 }
4010
4011 return null;
4012 }
4013
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004014 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004015 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004016 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004017 }
Jack Yueb4124c2017-02-16 15:32:43 -08004018
4019 /**
Grace Chen70990072017-03-24 17:21:30 -07004020 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004021 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004022 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004023 * @param state State of SIM (power down, power up, pass through)
4024 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4025 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4026 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004027 *
4028 **/
4029 @Override
Grace Chen70990072017-03-24 17:21:30 -07004030 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004031 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004032 Phone phone = PhoneFactory.getPhone(slotIndex);
4033
Jack Yueb4124c2017-02-16 15:32:43 -08004034 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004035 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004036 }
4037 }
Shuo Qiandd210312017-04-12 22:11:33 +00004038
Tyler Gunn65d45c22017-06-05 11:22:26 -07004039 private boolean isUssdApiAllowed(int subId) {
4040 CarrierConfigManager configManager =
4041 (CarrierConfigManager) mPhone.getContext().getSystemService(
4042 Context.CARRIER_CONFIG_SERVICE);
4043 if (configManager == null) {
4044 return false;
4045 }
4046 PersistableBundle pb = configManager.getConfigForSubId(subId);
4047 if (pb == null) {
4048 return false;
4049 }
4050 return pb.getBoolean(
4051 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4052 }
4053
Shuo Qiandd210312017-04-12 22:11:33 +00004054 /**
4055 * Check if phone is in emergency callback mode
4056 * @return true if phone is in emergency callback mode
4057 * @param subId sub id
4058 */
goneil9c5f4872017-12-05 14:07:56 -08004059 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004060 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004061 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004062 final Phone phone = getPhone(subId);
4063 if (phone != null) {
4064 return phone.isInEcm();
4065 } else {
4066 return false;
4067 }
4068 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004069
4070 /**
4071 * Get the current signal strength information for the given subscription.
4072 * Because this information is not updated when the device is in a low power state
4073 * it should not be relied-upon to be current.
4074 * @param subId Subscription index
4075 * @return the most recent cached signal strength info from the modem
4076 */
4077 @Override
4078 public SignalStrength getSignalStrength(int subId) {
4079 Phone p = getPhone(subId);
4080 if (p == null) {
4081 return null;
4082 }
4083
4084 return p.getSignalStrength();
4085 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004086
4087 @Override
4088 public UiccSlotInfo[] getUiccSlotsInfo() {
4089 enforceReadPrivilegedPermission();
4090
4091 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4092 if (slots == null) return null;
4093 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4094 for (int i = 0; i < slots.length; i++) {
4095 UiccSlot slot = slots[i];
4096
4097 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4098
4099 int cardState = 0;
4100 switch (slot.getCardState()) {
4101 case CARDSTATE_ABSENT:
4102 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4103 break;
4104 case CARDSTATE_PRESENT:
4105 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4106 break;
4107 case CARDSTATE_ERROR:
4108 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4109 break;
4110 case CARDSTATE_RESTRICTED:
4111 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4112 break;
4113 default:
4114 break;
4115
4116 }
4117
Qingxi Li795c5882018-01-31 13:43:27 -08004118 infos[i] = new UiccSlotInfo(
Qingxi Lie7245372018-03-07 10:52:26 -08004119 slot.isActive(),
4120 slot.isEuicc(),
4121 cardId,
4122 cardState,
4123 slot.getPhoneId(),
4124 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004125 }
4126 return infos;
4127 }
4128
4129 @Override
4130 public boolean switchSlots(int[] physicalSlots) {
4131 enforceModifyPermission();
4132 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4133 }
Jack Yu4c988042018-02-27 15:30:01 -08004134
4135 @Override
4136 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4137 enforceModifyPermission();
4138 final Phone phone = getPhone(subId);
4139 if (phone == null) {
4140 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4141 return;
4142 }
4143
4144 phone.setRadioIndicationUpdateMode(filters, mode);
4145 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07004146
4147 /**
4148 * Returns false if the mobile data is disabled by default, otherwise return true.
4149 */
4150 private boolean getDefaultDataEnabled() {
4151 return "true".equalsIgnoreCase(
4152 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
4153 }
4154
4155 /**
4156 * Returns true if the data roaming is enabled by default, i.e the system property
4157 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
4158 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
4159 */
4160 private boolean getDefaultDataRoamingEnabled(int subId) {
4161 final CarrierConfigManager configMgr = (CarrierConfigManager)
4162 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
4163 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
4164 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
4165 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
4166 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
4167 return isDataRoamingEnabled;
4168 }
4169
4170 /**
4171 * Returns the default network type for the given {@code subId}, if the default network type is
4172 * not set, return {@link Phone#PREFERRED_NT_MODE}.
4173 */
4174 private int getDefaultNetworkType(int subId) {
4175 return Integer.parseInt(
4176 TelephonyManager.getTelephonyProperty(
4177 mSubscriptionController.getPhoneId(subId),
4178 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
4179 String.valueOf(Phone.PREFERRED_NT_MODE)));
4180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004181}