blob: 62faa45bb6fc21514bc2843c5049ca9f731b8532 [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) {
sqian9bb0ea12018-03-08 17:09:27 -08001614 enforceReadPrivilegedPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001615 final Phone phone = getPhone(subId);
1616 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001617 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001618 } else {
1619 return false;
1620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
1622
1623 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001624 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001625 }
1626
pkanwarae03a6b2016-11-06 20:37:09 -08001627 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001628 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001629 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1630 return;
1631 }
1632 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1633 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1634 };
1635
Wink Savilleb564aae2014-10-23 10:18:09 -07001636 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001637 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001638 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1639 return false;
1640 }
Wink Saville36469e72014-06-11 15:17:00 -07001641 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 }
1643
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001645 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001646 }
1647
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001648 public int getCallStateForSlot(int slotIndex) {
1649 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001650 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001651 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 }
1653
Sanket Padawe356d7632015-06-22 14:03:32 -07001654 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001656 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001657 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001658 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001659 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001660 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001661 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 }
1663
Sanket Padawe356d7632015-06-22 14:03:32 -07001664 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001666 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001667 if (phone != null) {
1668 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1669 } else {
1670 return TelephonyManager.DATA_ACTIVITY_NONE;
1671 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 }
1673
1674 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001675 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001676 mPhone.getContext().getSystemService(AppOpsManager.class)
1677 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001678 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001679 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001680 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 }
1682
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001683 if (DBG_LOC) log("getCellLocation: is active user");
1684 Bundle data = new Bundle();
1685 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1686 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001687 return null;
1688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001690 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001691 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1692 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001693 }
1694
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001696 public String getNetworkCountryIsoForPhone(int phoneId) {
1697 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1698 // registered cell info, so return a NULL country instead.
1699 final long identity = Binder.clearCallingIdentity();
1700 try {
1701 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1702 if (TelephonyManager.NETWORK_TYPE_IWLAN
1703 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1704 return "";
1705 }
1706 } finally {
1707 Binder.restoreCallingIdentity(identity);
1708 }
1709 return TelephonyManager.getTelephonyProperty(
1710 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1711 }
1712
1713 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001715 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001716 }
1717
Sanket Padawe356d7632015-06-22 14:03:32 -07001718 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001719 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 mApp.enforceCallingOrSelfPermission(
1721 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001722 final Phone phone = getPhone(subId);
1723 if (phone != null) {
1724 phone.enableLocationUpdates();
1725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
1728 @Override
1729 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001730 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001731 }
1732
Sanket Padawe356d7632015-06-22 14:03:32 -07001733 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001734 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 mApp.enforceCallingOrSelfPermission(
1736 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001737 final Phone phone = getPhone(subId);
1738 if (phone != null) {
1739 phone.disableLocationUpdates();
1740 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741 }
1742
1743 @Override
1744 @SuppressWarnings("unchecked")
1745 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001746 mPhone.getContext().getSystemService(AppOpsManager.class)
1747 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001748 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001749 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001750 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 }
1752
1753 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1754 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1755 return null;
1756 }
Svetoslav64fad262015-04-14 14:35:21 -07001757
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001758 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001760 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001762 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001763 try {
1764 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1765 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1766 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1767 } catch (RuntimeException e) {
1768 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001770 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 }
1772
1773
1774 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001775 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001776 mPhone.getContext().getSystemService(AppOpsManager.class)
1777 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001778 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001779 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001780 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 }
1782
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001783 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001784 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001785 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1786 for (Phone phone : PhoneFactory.getPhones()) {
1787 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1788 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001790 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 }
1792
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001793 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001795 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001796 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001797 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001798 }
1799
Shishir Agrawala9f32182016-04-12 12:00:16 -07001800 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001801 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001802 Phone phone = PhoneFactory.getPhone(slotIndex);
1803 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001804 return null;
1805 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001806 int subId = phone.getSubId();
1807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1808 mApp, subId, callingPackage, "getImeiForSlot")) {
1809 return null;
1810 }
1811 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001812 }
1813
1814 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001815 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001816 Phone phone = PhoneFactory.getPhone(slotIndex);
1817 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001818 return null;
1819 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001820 int subId = phone.getSubId();
1821 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1822 mApp, subId, callingPackage, "getMeidForSlot")) {
1823 return null;
1824 }
1825 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001826 }
1827
1828 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001829 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001830 Phone phone = PhoneFactory.getPhone(slotIndex);
1831 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001832 return null;
1833 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001834 int subId = phone.getSubId();
1835 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1836 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1837 return null;
1838 }
1839 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001840 }
1841
fionaxu43304da2017-11-27 22:51:16 -08001842 @Override
1843 public int getSubscriptionCarrierId(int subId) {
1844 final Phone phone = getPhone(subId);
1845 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1846 }
1847
1848 @Override
1849 public String getSubscriptionCarrierName(int subId) {
1850 final Phone phone = getPhone(subId);
1851 return phone == null ? null : phone.getCarrierName();
1852 }
1853
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001854 //
1855 // Internal helper methods.
1856 //
1857
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001858 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1860 *
1861 * @throws SecurityException if the caller does not have the required permission
1862 */
1863 private void enforceModifyPermission() {
1864 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1865 }
1866
1867 /**
1868 * Make sure the caller has the CALL_PHONE permission.
1869 *
1870 * @throws SecurityException if the caller does not have the required permission
1871 */
1872 private void enforceCallPermission() {
1873 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1874 }
1875
Stuart Scott8eef64f2015-04-08 15:13:54 -07001876 private void enforceConnectivityInternalPermission() {
1877 mApp.enforceCallingOrSelfPermission(
1878 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1879 "ConnectivityService");
1880 }
1881
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 private String createTelUrl(String number) {
1883 if (TextUtils.isEmpty(number)) {
1884 return null;
1885 }
1886
Jake Hambye994d462014-02-03 13:10:13 -08001887 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 }
1889
Ihab Awadf9e92732013-12-05 18:02:52 -08001890 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1892 }
1893
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001894 private static void logv(String msg) {
1895 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1896 }
1897
Ihab Awadf9e92732013-12-05 18:02:52 -08001898 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1900 }
1901
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001902 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001904 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001905 }
1906
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001908 public int getActivePhoneTypeForSlot(int slotIndex) {
sqian9bb0ea12018-03-08 17:09:27 -08001909 enforceReadPrivilegedPermission();
1910 return getPhoneTypeForSlot(slotIndex);
1911 }
1912
1913 @Override
1914 public int getVoiceCapableActivePhoneTypeForSlot(int slotIndex) {
1915 // Check if the device is voice-capable
1916 if (!mApp.getResources()
1917 .getBoolean(com.android.internal.R.bool.config_voice_capable)) {
1918 return TelephonyManager.PHONE_TYPE_NONE;
Sanket Padawe356d7632015-06-22 14:03:32 -07001919 }
sqian9bb0ea12018-03-08 17:09:27 -08001920 return getPhoneTypeForSlot(slotIndex);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 }
1922
1923 /**
1924 * Returns the CDMA ERI icon index to display
1925 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001926 @Override
1927 public int getCdmaEriIconIndex(String callingPackage) {
1928 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001929 }
1930
Sanket Padawe356d7632015-06-22 14:03:32 -07001931 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001932 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001933 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001934 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001935 return -1;
1936 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 final Phone phone = getPhone(subId);
1938 if (phone != null) {
1939 return phone.getCdmaEriIconIndex();
1940 } else {
1941 return -1;
1942 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944
1945 /**
1946 * Returns the CDMA ERI icon mode,
1947 * 0 - ON
1948 * 1 - FLASHING
1949 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001950 @Override
1951 public int getCdmaEriIconMode(String callingPackage) {
1952 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001953 }
1954
Sanket Padawe356d7632015-06-22 14:03:32 -07001955 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001956 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001958 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001959 return -1;
1960 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 final Phone phone = getPhone(subId);
1962 if (phone != null) {
1963 return phone.getCdmaEriIconMode();
1964 } else {
1965 return -1;
1966 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 }
1968
1969 /**
1970 * Returns the CDMA ERI text,
1971 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001972 @Override
1973 public String getCdmaEriText(String callingPackage) {
1974 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001975 }
1976
Sanket Padawe356d7632015-06-22 14:03:32 -07001977 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001978 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001979 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001980 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001981 return null;
1982 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001983 final Phone phone = getPhone(subId);
1984 if (phone != null) {
1985 return phone.getCdmaEriText();
1986 } else {
1987 return null;
1988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990
1991 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001992 * Returns the CDMA MDN.
1993 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001994 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001995 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1997 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07001998 final Phone phone = getPhone(subId);
1999 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2000 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002001 } else {
2002 return null;
2003 }
2004 }
2005
2006 /**
2007 * Returns the CDMA MIN.
2008 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002009 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002010 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2012 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002013 final Phone phone = getPhone(subId);
2014 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2015 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002016 } else {
2017 return null;
2018 }
2019 }
2020
2021 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002022 * Returns true if CDMA provisioning needs to run.
2023 */
2024 public boolean needsOtaServiceProvisioning() {
sqian9bb0ea12018-03-08 17:09:27 -08002025 enforceReadPrivilegedPermission();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026 return mPhone.needsOtaServiceProvisioning();
2027 }
2028
2029 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002030 * Sets the voice mail number of a given subId.
2031 */
2032 @Override
2033 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002034 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002035 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2036 new Pair<String, String>(alphaTag, number), new Integer(subId));
2037 return success;
2038 }
2039
Ta-wei Yen87c49842016-05-13 21:19:52 -07002040 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002041 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2043 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2044 if (!TextUtils.equals(callingPackage, systemDialer)) {
2045 throw new SecurityException("caller must be system dialer");
2046 }
2047 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2048 if (phoneAccountHandle == null){
2049 return null;
2050 }
2051 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2052 }
2053
2054 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002055 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002056 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002057 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002058 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002059 return null;
2060 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002061 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2062 }
2063
2064 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002065 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2066 VisualVoicemailSmsFilterSettings settings) {
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 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2070 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002071 }
2072
2073 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002074 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2075 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002076 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002077 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002078 }
2079
2080 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002081 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2082 String callingPackage, int subId) {
2083 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002084 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002085 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002086 }
2087
2088 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002089 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002090 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002091 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002092 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2093 }
2094
2095 @Override
2096 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2097 String number, int port, String text, PendingIntent sentIntent) {
2098 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002099 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002100 enforceSendSmsPermission();
2101 // Make the calls as the phone process.
2102 final long identity = Binder.clearCallingIdentity();
2103 try {
2104 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2105 if (port == 0) {
2106 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2107 sentIntent, null, false);
2108 } else {
2109 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2110 smsManager.sendDataMessageWithSelfPermissions(number, null,
2111 (short) port, data, sentIntent, null);
2112 }
2113 } finally {
2114 Binder.restoreCallingIdentity(identity);
2115 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002116 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002117 /**
fionaxu0152e512016-11-14 13:36:14 -08002118 * Sets the voice activation state of a given subId.
2119 */
2120 @Override
2121 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2123 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002124 final Phone phone = getPhone(subId);
2125 if (phone != null) {
2126 phone.setVoiceActivationState(activationState);
2127 } else {
2128 loge("setVoiceActivationState fails with invalid subId: " + subId);
2129 }
2130 }
2131
2132 /**
2133 * Sets the data activation state of a given subId.
2134 */
2135 @Override
2136 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2138 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002139 final Phone phone = getPhone(subId);
2140 if (phone != null) {
2141 phone.setDataActivationState(activationState);
2142 } else {
2143 loge("setVoiceActivationState fails with invalid subId: " + subId);
2144 }
2145 }
2146
2147 /**
2148 * Returns the voice activation state of a given subId.
2149 */
2150 @Override
2151 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002152 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002153 final Phone phone = getPhone(subId);
2154 if (phone != null) {
2155 return phone.getVoiceActivationState();
2156 } else {
2157 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2158 }
2159 }
2160
2161 /**
2162 * Returns the data activation state of a given subId.
2163 */
2164 @Override
2165 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002166 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002167 final Phone phone = getPhone(subId);
2168 if (phone != null) {
2169 return phone.getDataActivationState();
2170 } else {
2171 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2172 }
2173 }
2174
2175 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176 * Returns the unread count of voicemails
2177 */
2178 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002179 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002180 }
2181
2182 /**
2183 * Returns the unread count of voicemails for a subId
2184 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002185 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002186 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002187 final Phone phone = getPhone(subId);
2188 if (phone != null) {
2189 return phone.getVoiceMessageCount();
2190 } else {
2191 return 0;
2192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193 }
2194
2195 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002196 * returns true, if the device is in a state where both voice and data
2197 * are supported simultaneously. This can change based on location or network condition.
2198 */
2199 @Override
2200 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2201 final Phone phone = getPhone(subId);
2202 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2203 }
2204
2205 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002206 * Send the dialer code if called from the current default dialer or the caller has
2207 * carrier privilege.
2208 * @param inputCode The dialer code to send
2209 */
2210 @Override
2211 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2212 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2213 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2214 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002215 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2216 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002217 }
2218 mPhone.sendDialerSpecialCode(inputCode);
2219 }
2220
2221 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002222 * Returns the data network type.
2223 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002224 *
2225 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2226 */
2227 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002228 public int getNetworkType() {
2229 final Phone phone = getPhone(getDefaultSubscription());
2230 if (phone != null) {
2231 return phone.getServiceState().getDataNetworkType();
2232 } else {
2233 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2234 }
Wink Saville36469e72014-06-11 15:17:00 -07002235 }
2236
2237 /**
2238 * Returns the network type for a subId
2239 */
2240 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002241 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002243 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002244 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2245 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002246
Sanket Padawe356d7632015-06-22 14:03:32 -07002247 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002248 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002249 return phone.getServiceState().getDataNetworkType();
2250 } else {
2251 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 }
2254
2255 /**
2256 * Returns the data network type
2257 */
2258 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002259 public int getDataNetworkType(String callingPackage) {
2260 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002261 }
2262
2263 /**
2264 * Returns the data network type for a subId
2265 */
2266 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002267 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002268 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002269 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002270 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2271 }
2272
Sanket Padawe356d7632015-06-22 14:03:32 -07002273 final Phone phone = getPhone(subId);
2274 if (phone != null) {
2275 return phone.getServiceState().getDataNetworkType();
2276 } else {
2277 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2278 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 }
2280
2281 /**
Wink Saville36469e72014-06-11 15:17:00 -07002282 * Returns the Voice network type for a subId
2283 */
2284 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002285 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002287 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002288 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2289 }
2290
Sanket Padawe356d7632015-06-22 14:03:32 -07002291 final Phone phone = getPhone(subId);
2292 if (phone != null) {
2293 return phone.getServiceState().getVoiceNetworkType();
2294 } else {
2295 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 }
2298
2299 /**
2300 * @return true if a ICC card is present
2301 */
2302 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002303 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002304 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2305 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002306 }
2307
2308 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002309 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002310 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002311 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002312 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2313 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002314 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002315 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002316 } else {
2317 return false;
2318 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 }
2320
2321 /**
2322 * Return if the current radio is LTE on CDMA. This
2323 * is a tri-state return value as for a period of time
2324 * the mode may be unknown.
2325 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002326 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002328 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002330 @Override
2331 public int getLteOnCdmaMode(String callingPackage) {
2332 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002333 }
2334
Sanket Padawe356d7632015-06-22 14:03:32 -07002335 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002336 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002337 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002338 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002339 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2340 }
2341
Sanket Padawe356d7632015-06-22 14:03:32 -07002342 final Phone phone = getPhone(subId);
2343 if (phone == null) {
2344 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2345 } else {
2346 return phone.getLteOnCdmaMode();
2347 }
Wink Saville36469e72014-06-11 15:17:00 -07002348 }
2349
2350 public void setPhone(Phone phone) {
2351 mPhone = phone;
2352 }
2353
2354 /**
2355 * {@hide}
2356 * Returns Default subId, 0 in the case of single standby.
2357 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002358 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002359 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002360 }
2361
Shishir Agrawala9f32182016-04-12 12:00:16 -07002362 private int getSlotForDefaultSubscription() {
2363 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2364 }
2365
Wink Savilleb564aae2014-10-23 10:18:09 -07002366 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002367 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002369
2370 /**
2371 * @see android.telephony.TelephonyManager.WifiCallingChoices
2372 */
2373 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002374 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2375 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002376 }
2377
2378 /**
2379 * @see android.telephony.TelephonyManager.WifiCallingChoices
2380 */
2381 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002382 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2383 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2384 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002385 }
2386
Sailesh Nepald1e68152013-12-12 19:08:02 -08002387 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002388 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002389 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002390 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002391
Shishir Agrawal566b7612013-10-28 14:41:00 -07002392 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002393 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2394 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2396 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002397
Derek Tan740e1672017-06-27 14:56:27 -07002398 if (TextUtils.equals(ISDR_AID, aid)) {
2399 // Only allows LPA to open logical channel to ISD-R.
2400 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2401 ComponentInfo bestComponent =
2402 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2403 if (bestComponent == null
2404 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2405 loge("The calling package is not allowed to access ISD-R.");
2406 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2407 }
2408 }
2409
2410 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002411 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002412 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002413 if (DBG) log("iccOpenLogicalChannel: " + response);
2414 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002415 }
2416
2417 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002418 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2420 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002421
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002422 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002423 if (channel < 0) {
2424 return false;
2425 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002426 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002427 if (DBG) log("iccCloseLogicalChannel: " + success);
2428 return success;
2429 }
2430
2431 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002432 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002433 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2435 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002436
2437 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002438 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2439 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002440 " data=" + data);
2441 }
2442
2443 if (channel < 0) {
2444 return "";
2445 }
2446
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002447 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002448 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002449 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2450
Shishir Agrawal566b7612013-10-28 14:41:00 -07002451 // Append the returned status code to the end of the response payload.
2452 String s = Integer.toHexString(
2453 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002454 if (response.payload != null) {
2455 s = IccUtils.bytesToHexString(response.payload) + s;
2456 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002457 return s;
2458 }
Jake Hambye994d462014-02-03 13:10:13 -08002459
Evan Charltonc66da362014-05-16 14:06:40 -07002460 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002461 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2462 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2464 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002465
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002466 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2467 && TextUtils.equals(ISDR_AID, data)) {
2468 // Only allows LPA to select ISD-R.
2469 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2470 ComponentInfo bestComponent =
2471 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2472 if (bestComponent == null
2473 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2474 loge("The calling package is not allowed to select ISD-R.");
2475 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2476 }
2477 }
2478
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002479 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002480 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2481 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002482 }
2483
2484 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002485 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002486 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2487
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002488 // Append the returned status code to the end of the response payload.
2489 String s = Integer.toHexString(
2490 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002491 if (response.payload != null) {
2492 s = IccUtils.bytesToHexString(response.payload) + s;
2493 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002494 return s;
2495 }
2496
2497 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002498 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002499 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2501 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002502
2503 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002504 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002505 p1 + " " + p2 + " " + p3 + ":" + filePath);
2506 }
2507
2508 IccIoResult response =
2509 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002510 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2511 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002512
2513 if (DBG) {
2514 log("Exchange SIM_IO [R]" + response);
2515 }
2516
2517 byte[] result = null;
2518 int length = 2;
2519 if (response.payload != null) {
2520 length = 2 + response.payload.length;
2521 result = new byte[length];
2522 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2523 } else {
2524 result = new byte[length];
2525 }
2526
2527 result[length - 1] = (byte) response.sw2;
2528 result[length - 2] = (byte) response.sw1;
2529 return result;
2530 }
2531
Nathan Haroldb3014052017-01-25 15:57:32 -08002532 /**
2533 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2534 * on a particular subscription
2535 */
sqianb6e41952018-03-12 14:54:01 -07002536 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2538 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2539 return null;
2540 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002541 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2542 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2543 return null;
2544 }
2545 Object response = sendRequest(
2546 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2547 if (response instanceof String[]) {
2548 return (String[]) response;
2549 }
2550 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2551 return null;
2552 }
2553
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002554 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002555 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2557 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002558
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002559 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002560 if (response.payload == null) {
2561 return "";
2562 }
2563
2564 // Append the returned status code to the end of the response payload.
2565 String s = Integer.toHexString(
2566 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2567 s = IccUtils.bytesToHexString(response.payload) + s;
2568 return s;
2569 }
2570
Jake Hambye994d462014-02-03 13:10:13 -08002571 /**
2572 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2573 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2574 *
2575 * @param itemID the ID of the item to read
2576 * @return the NV item as a String, or null on error.
2577 */
2578 @Override
2579 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2581 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002582 if (DBG) log("nvReadItem: item " + itemID);
2583 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2584 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2585 return value;
2586 }
2587
2588 /**
2589 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2590 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2591 *
2592 * @param itemID the ID of the item to read
2593 * @param itemValue the value to write, as a String
2594 * @return true on success; false on any failure
2595 */
2596 @Override
2597 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002598 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2599 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002600 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2601 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2602 new Pair<Integer, String>(itemID, itemValue));
2603 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2604 return success;
2605 }
2606
2607 /**
2608 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2609 * Used for device configuration by some CDMA operators.
2610 *
2611 * @param preferredRoamingList byte array containing the new PRL
2612 * @return true on success; false on any failure
2613 */
2614 @Override
2615 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2617 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002618 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2619 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2620 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2621 return success;
2622 }
2623
2624 /**
2625 * Perform the specified type of NV config reset.
2626 * Used for device configuration by some CDMA operators.
2627 *
2628 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2629 * @return true on success; false on any failure
2630 */
2631 @Override
2632 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2634 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002635 if (DBG) log("nvResetConfig: type " + resetType);
2636 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2637 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2638 return success;
2639 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002640
2641 /**
Wink Saville36469e72014-06-11 15:17:00 -07002642 * {@hide}
2643 * Returns Default sim, 0 in the case of single standby.
2644 */
2645 public int getDefaultSim() {
2646 //TODO Need to get it from Telephony Devcontroller
2647 return 0;
2648 }
2649
Svet Ganovb320e182015-04-16 12:30:10 -07002650 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002652 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002653 return new String[0];
2654 }
2655
2656
ram87fca6f2014-07-18 18:58:44 +05302657 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002658 }
2659
Brad Ebinger51f743a2017-01-23 13:50:20 -08002660 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002661 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2662 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002663 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002664 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002665 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002666 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002667 }
2668
2669 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002670 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2671 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002672 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002673 public void disableIms(int slotId) {
2674 enforceModifyPermission();
2675 PhoneFactory.getImsResolver().disableIms(slotId);
2676 }
2677
2678 /**
2679 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2680 * feature or {@link null} if the service is not available. If the feature is available, the
2681 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2682 */
2683 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002684 IImsServiceFeatureCallback callback) {
2685 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002686 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002687 }
2688
2689 /**
2690 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2691 * feature during emergency calling or {@link null} if the service is not available. If the
2692 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2693 * listener for feature updates.
2694 */
2695 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2696 enforceModifyPermission();
2697 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002698 }
2699
Brad Ebinger5f64b052017-12-14 14:26:15 -08002700 /**
2701 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2702 * specified.
2703 */
2704 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2705 enforceModifyPermission();
2706 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2707 }
2708
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002709 /**
2710 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2711 * specified.
2712 */
2713 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2714 enforceModifyPermission();
2715 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2716 }
2717
Brad Ebinger884c07b2018-02-15 16:17:40 -08002718 /**
2719 * @return true if emergency calling is available on IMS, false if it should fallback to CS.
2720 */
2721 public boolean isEmergencyMmTelAvailable(int slotId) {
2722 enforceModifyPermission();
2723 return PhoneFactory.getImsResolver().isEmergencyMmTelAvailable(slotId);
2724 }
2725
Brad Ebinger304415d2018-03-02 13:43:36 -08002726 /**
2727 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2728 * available, false if the IMS resolver is idle.
2729 */
2730 public boolean isResolvingImsBinding() {
2731 enforceModifyPermission();
2732 return PhoneFactory.getImsResolver().isResolvingBinding();
2733 }
2734
Wink Saville36469e72014-06-11 15:17:00 -07002735 public void setImsRegistrationState(boolean registered) {
2736 enforceModifyPermission();
2737 mPhone.setImsRegistrationState(registered);
2738 }
2739
2740 /**
Stuart Scott54788802015-03-30 13:18:01 -07002741 * Set the network selection mode to automatic.
2742 *
2743 */
2744 @Override
2745 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2747 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002748 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2749 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2750 }
2751
2752 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002753 * Set the network selection mode to manual with the selected carrier.
2754 */
2755 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002756 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002757 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2759 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002760 OperatorInfo operator = new OperatorInfo(
2761 /* operatorAlphaLong */ "",
2762 /* operatorAlphaShort */ "",
2763 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002764 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002765 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2766 persistSelection);
2767 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002768 }
2769
2770 /**
2771 * Scans for available networks.
2772 */
2773 @Override
2774 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2776 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002777 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2778 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2779 CMD_PERFORM_NETWORK_SCAN, null, subId);
2780 return result;
2781 }
2782
2783 /**
yinxub1bed742017-04-17 11:45:04 -07002784 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002785 *
yinxub1bed742017-04-17 11:45:04 -07002786 * @param subId id of the subscription
2787 * @param request contains the radio access networks with bands/channels to scan
2788 * @param messenger callback messenger for scan results or errors
2789 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002790 * @return the id of the requested scan which can be used to stop the scan.
2791 */
2792 @Override
2793 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2794 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2796 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002797 return mNetworkScanRequestTracker.startNetworkScan(
2798 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002799 }
2800
2801 /**
2802 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002803 *
2804 * @param subId id of the subscription
2805 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002806 */
2807 @Override
2808 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2810 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002811 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002812 }
2813
2814 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002815 * Get the calculated preferred network type.
2816 * Used for debugging incorrect network type.
2817 *
2818 * @return the preferred network type, defined in RILConstants.java.
2819 */
2820 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002821 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002822 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002823 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002824 return RILConstants.PREFERRED_NETWORK_MODE;
2825 }
2826
Amit Mahajan43330e02014-11-18 11:54:45 -08002827 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002828 }
2829
2830 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002831 * Get the preferred network type.
2832 * Used for device configuration by some CDMA operators.
2833 *
2834 * @return the preferred network type, defined in RILConstants.java.
2835 */
2836 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002837 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2839 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002840 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002841 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002842 int networkType = (result != null ? result[0] : -1);
2843 if (DBG) log("getPreferredNetworkType: " + networkType);
2844 return networkType;
2845 }
2846
2847 /**
2848 * Set the preferred network type.
2849 * Used for device configuration by some CDMA operators.
2850 *
2851 * @param networkType the preferred network type, defined in RILConstants.java.
2852 * @return true on success; false on any failure.
2853 */
2854 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002855 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2857 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002858 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2859 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002860 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002861 if (success) {
2862 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002863 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002864 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002865 return success;
2866 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002867
2868 /**
Junda Liu475951f2014-11-07 16:45:03 -08002869 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2870 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2871 * tethering.
2872 *
2873 * @return 0: Not required. 1: required. 2: Not set.
2874 * @hide
2875 */
2876 @Override
2877 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002878 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002879 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2880 Settings.Global.TETHER_DUN_REQUIRED, 2);
2881 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2882 // config_tether_apndata.
2883 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2884 dunRequired = 1;
2885 }
2886 return dunRequired;
2887 }
2888
2889 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002890 * Set mobile data enabled
2891 * Used by the user through settings etc to turn on/off mobile data
2892 *
2893 * @param enable {@code true} turn turn data on, else {@code false}
2894 */
2895 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002896 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2898 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002899 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002900 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002901 Phone phone = PhoneFactory.getPhone(phoneId);
2902 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002903 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2904 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002905 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002906 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002907 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002908 }
2909
2910 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002911 * Get the user enabled state of Mobile Data.
2912 *
2913 * TODO: remove and use isUserDataEnabled.
2914 * This can't be removed now because some vendor codes
2915 * calls through ITelephony directly while they should
2916 * use TelephonyManager.
2917 *
2918 * @return true on enabled
2919 */
2920 @Override
2921 public boolean getDataEnabled(int subId) {
2922 return isUserDataEnabled(subId);
2923 }
2924
2925 /**
2926 * Get whether mobile data is enabled per user setting.
2927 *
2928 * There are other factors deciding whether mobile data is actually enabled, but they are
2929 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002930 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002931 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002932 *
2933 * @return {@code true} if data is enabled else {@code false}
2934 */
2935 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002936 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002937 try {
2938 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2939 null);
2940 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2942 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002943 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002944 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002945 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002946 Phone phone = PhoneFactory.getPhone(phoneId);
2947 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002948 boolean retVal = phone.isUserDataEnabled();
2949 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002950 return retVal;
2951 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002952 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2953 return false;
2954 }
2955 }
2956
2957 /**
2958 * Get whether mobile data is enabled.
2959 *
2960 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2961 * whether mobile data is actually enabled.
2962 *
2963 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2964 *
2965 * @return {@code true} if data is enabled else {@code false}
2966 */
2967 @Override
2968 public boolean isDataEnabled(int subId) {
2969 try {
2970 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2971 null);
2972 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2974 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08002975 }
2976 int phoneId = mSubscriptionController.getPhoneId(subId);
2977 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2978 Phone phone = PhoneFactory.getPhone(phoneId);
2979 if (phone != null) {
2980 boolean retVal = phone.isDataEnabled();
2981 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2982 return retVal;
2983 } else {
2984 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002985 return false;
2986 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002987 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002988
2989 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002990 public int getCarrierPrivilegeStatus(int subId) {
2991 final Phone phone = getPhone(subId);
2992 if (phone == null) {
2993 loge("getCarrierPrivilegeStatus: Invalid subId");
2994 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2995 }
2996 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002997 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002998 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002999 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3000 }
3001 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003002 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003003 }
Junda Liu29340342014-07-10 15:23:27 -07003004
3005 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003006 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3007 final Phone phone = getPhone(subId);
3008 if (phone == null) {
3009 loge("getCarrierPrivilegeStatus: Invalid subId");
3010 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3011 }
3012 UiccProfile profile =
3013 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3014 if (profile == null) {
3015 loge("getCarrierPrivilegeStatus: No UICC");
3016 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3017 }
3018 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3019 }
3020
3021 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003022 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003023 if (TextUtils.isEmpty(pkgName))
3024 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003025 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003026 if (card == null) {
3027 loge("checkCarrierPrivilegesForPackage: No UICC");
3028 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3029 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003030 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3031 }
3032
3033 @Override
3034 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003035 if (TextUtils.isEmpty(pkgName))
3036 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003037 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3038 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3039 UiccCard card = UiccController.getInstance().getUiccCard(i);
3040 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003041 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003042 continue;
3043 }
3044
3045 result = card.getCarrierPrivilegeStatus(
3046 mPhone.getContext().getPackageManager(), pkgName);
3047 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3048 break;
3049 }
3050 }
3051
3052 return result;
Junda Liu29340342014-07-10 15:23:27 -07003053 }
Derek Tan89e89d42014-07-08 17:00:10 -07003054
3055 @Override
Junda Liue64de782015-04-16 17:19:16 -07003056 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
sqian9bb0ea12018-03-08 17:09:27 -08003057 enforceReadPrivilegedPermission();
Junda Liue64de782015-04-16 17:19:16 -07003058 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3059 loge("phoneId " + phoneId + " is not valid.");
3060 return null;
3061 }
3062 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003063 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003064 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003065 return null ;
3066 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003067 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003068 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003069 }
3070
Amith Yamasani6e118872016-02-19 12:53:51 -08003071 @Override
3072 public List<String> getPackagesWithCarrierPrivileges() {
3073 PackageManager pm = mPhone.getContext().getPackageManager();
3074 List<String> privilegedPackages = new ArrayList<>();
3075 List<PackageInfo> packages = null;
3076 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3077 UiccCard card = UiccController.getInstance().getUiccCard(i);
3078 if (card == null) {
3079 // No UICC in that slot.
3080 continue;
3081 }
3082 if (card.hasCarrierPrivilegeRules()) {
3083 if (packages == null) {
3084 // Only check packages in user 0 for now
3085 packages = pm.getInstalledPackagesAsUser(
3086 PackageManager.MATCH_DISABLED_COMPONENTS
3087 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3088 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3089 }
3090 for (int p = packages.size() - 1; p >= 0; p--) {
3091 PackageInfo pkgInfo = packages.get(p);
3092 if (pkgInfo != null && pkgInfo.packageName != null
3093 && card.getCarrierPrivilegeStatus(pkgInfo)
3094 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3095 privilegedPackages.add(pkgInfo.packageName);
3096 }
3097 }
3098 }
3099 }
3100 return privilegedPackages;
3101 }
3102
Wink Savilleb564aae2014-10-23 10:18:09 -07003103 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003104 final Phone phone = getPhone(subId);
3105 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003106 if (card == null) {
3107 loge("getIccId: No UICC");
3108 return null;
3109 }
3110 String iccId = card.getIccId();
3111 if (TextUtils.isEmpty(iccId)) {
3112 loge("getIccId: ICC ID is null or empty.");
3113 return null;
3114 }
3115 return iccId;
3116 }
3117
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003118 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003119 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3120 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003121 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3122 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003123
Jeff Sharkey85190e62014-12-05 09:40:12 -08003124 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003125 final Phone phone = getPhone(subId);
3126 if (phone == null) {
3127 return false;
3128 }
3129 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003130
3131 if (DBG_MERGE) {
3132 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3133 + subscriberId + " to " + number);
3134 }
3135
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003136 if (TextUtils.isEmpty(iccId)) {
3137 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003138 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003139
Jeff Sharkey85190e62014-12-05 09:40:12 -08003140 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3141
3142 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003143 if (alphaTag == null) {
3144 editor.remove(alphaTagPrefKey);
3145 } else {
3146 editor.putString(alphaTagPrefKey, alphaTag);
3147 }
3148
Jeff Sharkey85190e62014-12-05 09:40:12 -08003149 // Record both the line number and IMSI for this ICCID, since we need to
3150 // track all merged IMSIs based on line number
3151 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3152 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003153 if (number == null) {
3154 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003155 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003156 } else {
3157 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003158 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003159 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003160
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003161 editor.commit();
3162 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003163 }
3164
3165 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003166 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003167 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003168 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003169 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003170 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003171 return null;
3172 }
Derek Tan97ebb422014-09-05 16:55:38 -07003173
3174 String iccId = getIccId(subId);
3175 if (iccId != null) {
3176 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003177 if (DBG_MERGE) {
3178 log("getLine1NumberForDisplay returning " +
3179 mTelephonySharedPreferences.getString(numberPrefKey, null));
3180 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003181 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003182 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003183 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003184 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003185 }
3186
3187 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003188 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003189 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003190 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003191 return null;
3192 }
Derek Tan97ebb422014-09-05 16:55:38 -07003193
3194 String iccId = getIccId(subId);
3195 if (iccId != null) {
3196 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003197 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003198 }
Derek Tan97ebb422014-09-05 16:55:38 -07003199 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003200 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003201
3202 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003203 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003204 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3205 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003206 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003207 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3208 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003209 return null;
3210 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003211 final Context context = mPhone.getContext();
3212 final TelephonyManager tele = TelephonyManager.from(context);
3213 final SubscriptionManager sub = SubscriptionManager.from(context);
3214
3215 // Figure out what subscribers are currently active
3216 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003217 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3218 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3219 final long identity = Binder.clearCallingIdentity();
3220 try {
3221 final int[] subIds = sub.getActiveSubscriptionIdList();
3222 for (int subId : subIds) {
3223 activeSubscriberIds.add(tele.getSubscriberId(subId));
3224 }
3225 } finally {
3226 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003227 }
3228
3229 // First pass, find a number override for an active subscriber
3230 String mergeNumber = null;
3231 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3232 for (String key : prefs.keySet()) {
3233 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3234 final String subscriberId = (String) prefs.get(key);
3235 if (activeSubscriberIds.contains(subscriberId)) {
3236 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3237 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3238 mergeNumber = (String) prefs.get(numberKey);
3239 if (DBG_MERGE) {
3240 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3241 + " for active subscriber " + subscriberId);
3242 }
3243 if (!TextUtils.isEmpty(mergeNumber)) {
3244 break;
3245 }
3246 }
3247 }
3248 }
3249
3250 // Shortcut when no active merged subscribers
3251 if (TextUtils.isEmpty(mergeNumber)) {
3252 return null;
3253 }
3254
3255 // Second pass, find all subscribers under that line override
3256 final ArraySet<String> result = new ArraySet<>();
3257 for (String key : prefs.keySet()) {
3258 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3259 final String number = (String) prefs.get(key);
3260 if (mergeNumber.equals(number)) {
3261 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3262 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3263 final String subscriberId = (String) prefs.get(subscriberKey);
3264 if (!TextUtils.isEmpty(subscriberId)) {
3265 result.add(subscriberId);
3266 }
3267 }
3268 }
3269 }
3270
3271 final String[] resultArray = result.toArray(new String[result.size()]);
3272 Arrays.sort(resultArray);
3273 if (DBG_MERGE) {
3274 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3275 }
3276 return resultArray;
3277 }
3278
3279 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003280 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003281 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3282 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003283 final Phone phone = getPhone(subId);
3284 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003285 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003286
3287 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003288 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003289 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3290 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003291 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003292 final Phone phone = getPhone(subId);
3293 if (phone == null) {
3294 return false;
3295 }
3296 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003297 cdmaNonRoamingList);
3298 }
3299
3300 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003301 public void setRadioCapability(RadioAccessFamily[] rafs) {
3302 try {
3303 ProxyController.getInstance().setRadioCapability(rafs);
3304 } catch (RuntimeException e) {
3305 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3306 }
3307 }
3308
3309 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003310 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003311 Phone phone = PhoneFactory.getPhone(phoneId);
3312 if (phone == null) {
3313 return RadioAccessFamily.RAF_UNKNOWN;
3314 }
3315 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003316 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003317 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003318 return RadioAccessFamily.RAF_UNKNOWN;
3319 }
3320
Wink Saville5d475dd2014-10-17 15:00:58 -07003321 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3322 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003323
3324 @Override
3325 public void enableVideoCalling(boolean enable) {
3326 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003327 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003328 }
3329
3330 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003331 public boolean isVideoCallingEnabled(String callingPackage) {
sqian9bb0ea12018-03-08 17:09:27 -08003332 enforceReadPrivilegedPermission();
Svet Ganovb320e182015-04-16 12:30:10 -07003333
Andrew Lee77527ac2014-10-21 16:57:39 -07003334 // Check the user preference and the system-level IMS setting. Even if the user has
3335 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3336 // In the long run, we may instead need to check if there exists a connection service
3337 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003338 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3339 return imsManager.isVtEnabledByPlatform()
3340 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3341 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003342 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003343
Andrew Leea1239f22015-03-02 17:44:07 -08003344 @Override
3345 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003346 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003347 }
3348
3349 @Override
3350 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003351 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003352 }
3353
Andrew Lee9431b832015-03-09 18:46:45 -07003354 @Override
3355 public boolean isTtyModeSupported() {
3356 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3357 TelephonyManager telephonyManager =
3358 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003359 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003360 }
3361
3362 @Override
3363 public boolean isHearingAidCompatibilitySupported() {
3364 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3365 }
3366
Hall Liu98187582018-01-22 19:15:32 -08003367 public boolean isRttSupported() {
3368 boolean isCarrierSupported =
3369 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3370 boolean isDeviceSupported =
3371 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3372 return isCarrierSupported && isDeviceSupported;
3373 }
3374
Sanket Padawe7310cc72015-01-14 09:53:20 -08003375 /**
3376 * Returns the unique device ID of phone, for example, the IMEI for
3377 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3378 *
3379 * <p>Requires Permission:
3380 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3381 */
3382 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003383 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003384 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08003385 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003386 return null;
3387 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003388 int subId = phone.getSubId();
3389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3390 mApp, subId, callingPackage, "getDeviceId")) {
3391 return null;
3392 }
3393 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003394 }
3395
Ping Sunc67b7c22016-03-02 19:16:45 +08003396 /**
3397 * {@hide}
3398 * Returns the IMS Registration Status on a particular subid
3399 *
3400 * @param subId
3401 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003402 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003403 Phone phone = getPhone(subId);
3404 if (phone != null) {
3405 return phone.isImsRegistered();
3406 } else {
3407 return false;
3408 }
3409 }
3410
Santos Cordon7a1885b2015-02-03 11:15:19 -08003411 @Override
3412 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3413 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3414 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003415
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003416 /**
3417 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003418 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003419 public boolean isWifiCallingAvailable(int subId) {
3420 Phone phone = getPhone(subId);
3421 if (phone != null) {
3422 return phone.isWifiCallingEnabled();
3423 } else {
3424 return false;
3425 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003426 }
3427
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003428 /**
3429 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003430 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003431 public boolean isVolteAvailable(int subId) {
3432 Phone phone = getPhone(subId);
3433 if (phone != null) {
3434 return phone.isVolteEnabled();
3435 } else {
3436 return false;
3437 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003438 }
Svet Ganovb320e182015-04-16 12:30:10 -07003439
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003440 /**
3441 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003442 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003443 public boolean isVideoTelephonyAvailable(int subId) {
3444 Phone phone = getPhone(subId);
3445 if (phone != null) {
3446 return phone.isVideoEnabled();
3447 } else {
3448 return false;
3449 }
3450 }
3451
3452 /**
3453 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3454 * defined in {@link ImsRegistrationImplBase}.
3455 */
3456 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3457 Phone phone = getPhone(subId);
3458 if (phone != null) {
3459 return phone.getImsRegistrationTech();
3460 } else {
3461 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3462 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003463 }
3464
Stuart Scott8eef64f2015-04-08 15:13:54 -07003465 @Override
3466 public void factoryReset(int subId) {
3467 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003468 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3469 return;
3470 }
3471
Svet Ganovcc087f82015-05-12 20:35:54 -07003472 final long identity = Binder.clearCallingIdentity();
3473 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003474 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3475 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07003476 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07003477 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07003478 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
3479 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07003480 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003481 }
3482 } finally {
3483 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003484 }
3485 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003486
3487 @Override
3488 public String getLocaleFromDefaultSim() {
3489 // We query all subscriptions instead of just the active ones, because
3490 // this might be called early on in the provisioning flow when the
3491 // subscriptions potentially aren't active yet.
3492 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3493 if (slist == null || slist.isEmpty()) {
3494 return null;
3495 }
3496
3497 // This function may be called very early, say, from the setup wizard, at
3498 // which point we won't have a default subscription set. If that's the case
3499 // we just choose the first, which will be valid in "most cases".
3500 final int defaultSubId = getDefaultSubscription();
3501 SubscriptionInfo info = null;
3502 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3503 info = slist.get(0);
3504 } else {
3505 for (SubscriptionInfo item : slist) {
3506 if (item.getSubscriptionId() == defaultSubId) {
3507 info = item;
3508 break;
3509 }
3510 }
3511
3512 if (info == null) {
3513 return null;
3514 }
3515 }
3516
3517 // Try and fetch the locale from the carrier properties or from the SIM language
3518 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003519 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003520 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003521 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003522 if (defaultPhone != null) {
3523 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3524 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003525 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003526 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3527 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003528 } else {
3529 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003530 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003531 }
3532 }
3533
Narayan Kamath011676f2015-07-29 12:04:08 +01003534 // The SIM language preferences only store a language (e.g. fr = French), not an
3535 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3536 // the SIM and carrier preferences does not include a country we add the country
3537 // determined from the SIM MCC to provide an exact locale.
3538 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003539 if (mccLocale != null) {
3540 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3541 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003542 }
3543
Tony Hill183b2de2015-06-24 14:53:58 +01003544 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003545 return null;
3546 }
3547
3548 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 return mSubscriptionController.getAllSubInfoList(
3552 mPhone.getContext().getOpPackageName());
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
3556 }
3557
3558 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3559 final long identity = Binder.clearCallingIdentity();
3560 try {
3561 return mSubscriptionController.getActiveSubscriptionInfoList(
3562 mPhone.getContext().getOpPackageName());
3563 } finally {
3564 Binder.restoreCallingIdentity(identity);
3565 }
3566 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003567
Chenjie Yu1ba97252018-01-11 18:16:20 -08003568 private final ModemActivityInfo mLastModemActivityInfo =
3569 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3570
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003571 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003572 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3573 * representing the state of the modem.
3574 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003575 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3576 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003577 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003578 */
3579 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003580 public void requestModemActivityInfo(ResultReceiver result) {
3581 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003582 ModemActivityInfo ret = null;
3583 synchronized (mLastModemActivityInfo) {
3584 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3585 null);
3586 if (info != null) {
3587 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3588 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3589 mergedTxTimeMs[i] =
3590 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3591 }
3592 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3593 mLastModemActivityInfo.setSleepTimeMillis(
3594 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3595 mLastModemActivityInfo.setIdleTimeMillis(
3596 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3597 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3598 mLastModemActivityInfo.setRxTimeMillis(
3599 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3600 mLastModemActivityInfo.setEnergyUsed(
3601 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3602 }
3603 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3604 mLastModemActivityInfo.getSleepTimeMillis(),
3605 mLastModemActivityInfo.getIdleTimeMillis(),
3606 mLastModemActivityInfo.getTxTimeMillis(),
3607 mLastModemActivityInfo.getRxTimeMillis(),
3608 mLastModemActivityInfo.getEnergyUsed());
3609 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003610 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003611 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003612 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003613 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003614
3615 /**
3616 * {@hide}
3617 * Returns the service state information on specified subscription.
3618 */
3619 @Override
3620 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3621
Jeff Davidson7e17e312018-02-13 18:17:36 -08003622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003623 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003624 return null;
3625 }
3626
3627 final Phone phone = getPhone(subId);
3628 if (phone == null) {
3629 return null;
3630 }
3631
3632 return phone.getServiceState();
3633 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003634
3635 /**
3636 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3637 *
3638 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3639 * voicemail ringtone.
3640 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3641 * PhoneAccount.
3642 */
3643 @Override
3644 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003645 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003646 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003647 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003648 }
3649
fionaxu7ed723d2017-05-30 18:58:54 -07003650 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003651 }
3652
3653 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003654 * Sets the per-account voicemail ringtone.
3655 *
3656 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3657 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3658 *
3659 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3660 * voicemail ringtone.
3661 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3662 * PhoneAccount.
3663 */
3664 @Override
3665 public void setVoicemailRingtoneUri(String callingPackage,
3666 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3667 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3668 if (!TextUtils.equals(callingPackage,
3669 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003670 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3671 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3672 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003673 }
3674 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3675 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003676 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003677 }
fionaxu7ed723d2017-05-30 18:58:54 -07003678 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003679 }
3680
3681 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003682 * Returns whether vibration is set for voicemail notification in Phone settings.
3683 *
3684 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3685 * voicemail vibration setting.
3686 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3687 */
3688 @Override
3689 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003690 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003691 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003692 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003693 }
3694
fionaxu7ed723d2017-05-30 18:58:54 -07003695 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003696 }
3697
Youhan Wange64578a2016-05-02 15:32:42 -07003698 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003699 * Sets the per-account voicemail vibration.
3700 *
3701 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3702 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3703 *
3704 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3705 * voicemail vibration setting.
3706 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3707 * specific PhoneAccount.
3708 */
3709 @Override
3710 public void setVoicemailVibrationEnabled(String callingPackage,
3711 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3713 if (!TextUtils.equals(callingPackage,
3714 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3716 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3717 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003718 }
3719
3720 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3721 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003722 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003723 }
fionaxu7ed723d2017-05-30 18:58:54 -07003724 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003725 }
3726
3727 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003728 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3729 *
3730 * @throws SecurityException if the caller does not have the required permission
3731 */
3732 private void enforceReadPrivilegedPermission() {
3733 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3734 null);
3735 }
3736
3737 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003738 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3739 * permission.
3740 *
3741 * @throws SecurityException if the caller does not have the required permission
3742 */
3743 private void enforceSendSmsPermission() {
3744 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3745 }
3746
3747 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003748 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003749 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003750 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003751 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003752 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003753 ComponentName componentName =
3754 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3755 if(componentName == null) {
3756 throw new SecurityException("Caller not current active visual voicemail package[null]");
3757 }
3758 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003759 if (!callingPackage.equals(vvmPackage)) {
3760 throw new SecurityException("Caller not current active visual voicemail package[" +
3761 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003762 }
3763 }
3764
3765 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003766 * Return the application ID for the app type.
3767 *
3768 * @param subId the subscription ID that this request applies to.
3769 * @param appType the uicc app type.
3770 * @return Application ID for specificied app type, or null if no uicc.
3771 */
3772 @Override
3773 public String getAidForAppType(int subId, int appType) {
3774 enforceReadPrivilegedPermission();
3775 Phone phone = getPhone(subId);
3776 if (phone == null) {
3777 return null;
3778 }
3779 String aid = null;
3780 try {
3781 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3782 .getApplicationByType(appType).getAid();
3783 } catch (Exception e) {
3784 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3785 }
3786 return aid;
3787 }
3788
Youhan Wang4001d252016-05-11 10:29:41 -07003789 /**
3790 * Return the Electronic Serial Number.
3791 *
3792 * @param subId the subscription ID that this request applies to.
3793 * @return ESN or null if error.
3794 */
3795 @Override
3796 public String getEsn(int subId) {
3797 enforceReadPrivilegedPermission();
3798 Phone phone = getPhone(subId);
3799 if (phone == null) {
3800 return null;
3801 }
3802 String esn = null;
3803 try {
3804 esn = phone.getEsn();
3805 } catch (Exception e) {
3806 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3807 }
3808 return esn;
3809 }
3810
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003811 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003812 * Return the Preferred Roaming List Version.
3813 *
3814 * @param subId the subscription ID that this request applies to.
3815 * @return PRLVersion or null if error.
3816 */
3817 @Override
3818 public String getCdmaPrlVersion(int subId) {
3819 enforceReadPrivilegedPermission();
3820 Phone phone = getPhone(subId);
3821 if (phone == null) {
3822 return null;
3823 }
3824 String cdmaPrlVersion = null;
3825 try {
3826 cdmaPrlVersion = phone.getCdmaPrlVersion();
3827 } catch (Exception e) {
3828 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3829 }
3830 return cdmaPrlVersion;
3831 }
3832
3833 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003834 * Get snapshot of Telephony histograms
3835 * @return List of Telephony histograms
3836 * @hide
3837 */
3838 @Override
3839 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3841 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003842 return RIL.getTelephonyRILTimingHistograms();
3843 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003844
3845 /**
3846 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003847 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003848 * Require system privileges. In the future we may add this to carrier APIs.
3849 *
3850 * @return The number of carriers set successfully, should match length of carriers
3851 */
3852 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003853 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003854 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003855
Meng Wang9b7c4e92017-02-17 11:41:27 -08003856 if (carriers == null) {
3857 throw new NullPointerException("carriers cannot be null");
3858 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003859
3860 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003861 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3862 return retVal[0];
3863 }
3864
3865 /**
3866 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003867 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003868 * Require system privileges. In the future we may add this to carrier APIs.
3869 *
3870 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3871 * means all carriers are allowed.
3872 */
3873 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003874 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003875 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003876 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003877 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3878 }
3879
fionaxu59545b42016-05-25 15:53:37 -07003880 /**
3881 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3882 * @param subId the subscription ID that this action applies to.
3883 * @param enabled control enable or disable metered apns.
3884 * {@hide}
3885 */
3886 @Override
3887 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3888 enforceModifyPermission();
3889 final Phone phone = getPhone(subId);
3890 if (phone == null) {
3891 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3892 return;
3893 }
3894 try {
3895 phone.carrierActionSetMeteredApnsEnabled(enabled);
3896 } catch (Exception e) {
3897 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3898 }
3899 }
3900
3901 /**
3902 * Action set from carrier signalling broadcast receivers to enable/disable radio
3903 * @param subId the subscription ID that this action applies to.
3904 * @param enabled control enable or disable radio.
3905 * {@hide}
3906 */
3907 @Override
3908 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3909 enforceModifyPermission();
3910 final Phone phone = getPhone(subId);
3911 if (phone == null) {
3912 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3913 return;
3914 }
3915 try {
3916 phone.carrierActionSetRadioEnabled(enabled);
3917 } catch (Exception e) {
3918 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3919 }
3920 }
3921
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003922 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003923 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3924 * network status based on which carrier apps could apply actions accordingly,
3925 * enable/disable default url handler for example.
3926 *
3927 * @param subId the subscription ID that this action applies to.
3928 * @param report control start/stop reporting the default network status.
3929 * {@hide}
3930 */
3931 @Override
3932 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3933 enforceModifyPermission();
3934 final Phone phone = getPhone(subId);
3935 if (phone == null) {
3936 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3937 return;
3938 }
3939 try {
3940 phone.carrierActionReportDefaultNetworkStatus(report);
3941 } catch (Exception e) {
3942 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3943 }
3944 }
3945
3946 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003947 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3948 * bug report is being generated.
3949 */
3950 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003951 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003952 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3953 != PackageManager.PERMISSION_GRANTED) {
3954 writer.println("Permission Denial: can't dump Phone from pid="
3955 + Binder.getCallingPid()
3956 + ", uid=" + Binder.getCallingUid()
3957 + "without permission "
3958 + android.Manifest.permission.DUMP);
3959 return;
3960 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003961 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003962 }
Jack Yueb89b242016-06-22 13:27:47 -07003963
3964 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003965 * Get aggregated video call data usage since boot.
3966 *
3967 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3968 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003969 * {@hide}
3970 */
3971 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003972 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003973 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3974 null);
3975
Jack Yu84291ec2017-05-26 16:07:50 -07003976 // NetworkStatsService keeps tracking the active network interface and identity. It
3977 // records the delta with the corresponding network identity. We just return the total video
3978 // call data usage snapshot since boot.
3979 Phone phone = getPhone(subId);
3980 if (phone != null) {
3981 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003982 }
Jack Yu84291ec2017-05-26 16:07:50 -07003983 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003984 }
Jack Yu75ab2952016-07-08 14:29:33 -07003985
3986 /**
3987 * Policy control of data connection. Usually used when data limit is passed.
3988 * @param enabled True if enabling the data, otherwise disabling.
3989 * @param subId Subscription index
3990 * {@hide}
3991 */
3992 @Override
3993 public void setPolicyDataEnabled(boolean enabled, int subId) {
3994 enforceModifyPermission();
3995 Phone phone = getPhone(subId);
3996 if (phone != null) {
3997 phone.setPolicyDataEnabled(enabled);
3998 }
3999 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004000
4001 /**
4002 * Get Client request stats
4003 * @return List of Client Request Stats
4004 * @hide
4005 */
4006 @Override
4007 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004009 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004010 return null;
4011 }
4012
4013 Phone phone = getPhone(subId);
4014 if (phone != null) {
4015 return phone.getClientRequestStats();
4016 }
4017
4018 return null;
4019 }
4020
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004021 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004022 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004023 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004024 }
Jack Yueb4124c2017-02-16 15:32:43 -08004025
4026 /**
Grace Chen70990072017-03-24 17:21:30 -07004027 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004028 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004029 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004030 * @param state State of SIM (power down, power up, pass through)
4031 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4032 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4033 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004034 *
4035 **/
4036 @Override
Grace Chen70990072017-03-24 17:21:30 -07004037 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004038 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004039 Phone phone = PhoneFactory.getPhone(slotIndex);
4040
Jack Yueb4124c2017-02-16 15:32:43 -08004041 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004042 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004043 }
4044 }
Shuo Qiandd210312017-04-12 22:11:33 +00004045
Tyler Gunn65d45c22017-06-05 11:22:26 -07004046 private boolean isUssdApiAllowed(int subId) {
4047 CarrierConfigManager configManager =
4048 (CarrierConfigManager) mPhone.getContext().getSystemService(
4049 Context.CARRIER_CONFIG_SERVICE);
4050 if (configManager == null) {
4051 return false;
4052 }
4053 PersistableBundle pb = configManager.getConfigForSubId(subId);
4054 if (pb == null) {
4055 return false;
4056 }
4057 return pb.getBoolean(
4058 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4059 }
4060
Shuo Qiandd210312017-04-12 22:11:33 +00004061 /**
4062 * Check if phone is in emergency callback mode
4063 * @return true if phone is in emergency callback mode
4064 * @param subId sub id
4065 */
goneil9c5f4872017-12-05 14:07:56 -08004066 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004067 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004068 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004069 final Phone phone = getPhone(subId);
4070 if (phone != null) {
4071 return phone.isInEcm();
4072 } else {
4073 return false;
4074 }
4075 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004076
4077 /**
4078 * Get the current signal strength information for the given subscription.
4079 * Because this information is not updated when the device is in a low power state
4080 * it should not be relied-upon to be current.
4081 * @param subId Subscription index
4082 * @return the most recent cached signal strength info from the modem
4083 */
4084 @Override
4085 public SignalStrength getSignalStrength(int subId) {
4086 Phone p = getPhone(subId);
4087 if (p == null) {
4088 return null;
4089 }
4090
4091 return p.getSignalStrength();
4092 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004093
4094 @Override
4095 public UiccSlotInfo[] getUiccSlotsInfo() {
4096 enforceReadPrivilegedPermission();
4097
4098 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4099 if (slots == null) return null;
4100 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4101 for (int i = 0; i < slots.length; i++) {
4102 UiccSlot slot = slots[i];
4103
4104 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4105
4106 int cardState = 0;
4107 switch (slot.getCardState()) {
4108 case CARDSTATE_ABSENT:
4109 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4110 break;
4111 case CARDSTATE_PRESENT:
4112 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4113 break;
4114 case CARDSTATE_ERROR:
4115 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4116 break;
4117 case CARDSTATE_RESTRICTED:
4118 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4119 break;
4120 default:
4121 break;
4122
4123 }
4124
Qingxi Li795c5882018-01-31 13:43:27 -08004125 infos[i] = new UiccSlotInfo(
Qingxi Lie7245372018-03-07 10:52:26 -08004126 slot.isActive(),
4127 slot.isEuicc(),
4128 cardId,
4129 cardState,
4130 slot.getPhoneId(),
4131 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004132 }
4133 return infos;
4134 }
4135
4136 @Override
4137 public boolean switchSlots(int[] physicalSlots) {
4138 enforceModifyPermission();
4139 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4140 }
Jack Yu4c988042018-02-27 15:30:01 -08004141
4142 @Override
4143 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4144 enforceModifyPermission();
4145 final Phone phone = getPhone(subId);
4146 if (phone == null) {
4147 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4148 return;
4149 }
4150
4151 phone.setRadioIndicationUpdateMode(filters, mode);
4152 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07004153
4154 /**
4155 * Returns false if the mobile data is disabled by default, otherwise return true.
4156 */
4157 private boolean getDefaultDataEnabled() {
4158 return "true".equalsIgnoreCase(
4159 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
4160 }
4161
4162 /**
4163 * Returns true if the data roaming is enabled by default, i.e the system property
4164 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
4165 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
4166 */
4167 private boolean getDefaultDataRoamingEnabled(int subId) {
4168 final CarrierConfigManager configMgr = (CarrierConfigManager)
4169 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
4170 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
4171 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
4172 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
4173 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
4174 return isDataRoamingEnabled;
4175 }
4176
4177 /**
4178 * Returns the default network type for the given {@code subId}, if the default network type is
4179 * not set, return {@link Phone#PREFERRED_NT_MODE}.
4180 */
4181 private int getDefaultNetworkType(int subId) {
4182 return Integer.parseInt(
4183 TelephonyManager.getTelephonyProperty(
4184 mSubscriptionController.getPhoneId(subId),
4185 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
4186 String.valueOf(Phone.PREFERRED_NT_MODE)));
4187 }
sqian9bb0ea12018-03-08 17:09:27 -08004188
4189 /**
4190 * Util function that returns the phone type.
4191 * @param slotIndex - slot to query.
4192 */
4193 private int getPhoneTypeForSlot(int slotIndex) {
4194 final Phone phone = PhoneFactory.getPhone(slotIndex);
4195 if (phone == null) {
4196 return PhoneConstants.PHONE_TYPE_NONE;
4197 } else {
4198 return phone.getPhoneType();
4199 }
4200 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004201}