blob: 8cf7ed60f3ed5937e88301001d6284d552695795 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
Pengquan Meng85728fb2018-03-12 16:31:21 -070045import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070047import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070048import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070049import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080050import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070051import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080052import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080053import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070054import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070055import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070058import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080059import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070060import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080061import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070062import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070063import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070064import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080066import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070067import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080068import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080069import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070070import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070071import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000072import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070074import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080075import android.telephony.ims.aidl.IImsConfig;
76import android.telephony.ims.aidl.IImsMmTelFeature;
77import android.telephony.ims.aidl.IImsRcsFeature;
78import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080079import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080081import android.util.ArraySet;
Tyler Gunn67073572018-02-14 14:19:42 -080082import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080084import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080085import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080086
Andrew Lee312e8172014-10-23 17:01:36 -070087import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080088import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070089import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070090import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070091import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070092import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070093import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080096import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010097import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070098import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070099import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -0800101import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700102import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700103import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700104import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700105import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700106import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800107import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800108import com.android.internal.telephony.TelephonyPermissions;
Jonathan Basseribf5362b2017-07-19 12:22:35 -0700109import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700110import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700111import com.android.internal.telephony.uicc.IccIoResult;
112import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800113import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700114import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800115import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800117import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000118import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700119import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800120import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700121import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800122import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700123import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700124import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800125
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700126import java.io.FileDescriptor;
127import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800128import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800130import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800131import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100132import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800133import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134
135/**
136 * Implementation of the ITelephony interface.
137 */
Santos Cordon117fee72014-05-16 17:56:12 -0700138public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139 private static final String LOG_TAG = "PhoneInterfaceManager";
140 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
141 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800142 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143
144 // Message codes used with mMainThreadHandler
145 private static final int CMD_HANDLE_PIN_MMI = 1;
146 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
147 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
148 private static final int CMD_ANSWER_RINGING_CALL = 4;
149 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700150 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
151 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700152 private static final int CMD_OPEN_CHANNEL = 9;
153 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
154 private static final int CMD_CLOSE_CHANNEL = 11;
155 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800156 private static final int CMD_NV_READ_ITEM = 13;
157 private static final int EVENT_NV_READ_ITEM_DONE = 14;
158 private static final int CMD_NV_WRITE_ITEM = 15;
159 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
160 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
161 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
162 private static final int CMD_NV_RESET_CONFIG = 19;
163 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800164 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
165 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
166 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
167 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800168 private static final int CMD_SEND_ENVELOPE = 25;
169 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700170 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
171 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
172 private static final int CMD_EXCHANGE_SIM_IO = 31;
173 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800174 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
175 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700176 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
177 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700178 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
179 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700180 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
181 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
182 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
183 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700184 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
185 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
186 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
187 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700188 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800189 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
190 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000191 private static final int CMD_SWITCH_SLOTS = 50;
192 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800194 // Parameters of select command.
195 private static final int SELECT_COMMAND = 0xA4;
196 private static final int SELECT_P1 = 0x04;
197 private static final int SELECT_P2 = 0;
198 private static final int SELECT_P3 = 0x10;
199
Pengquan Meng85728fb2018-03-12 16:31:21 -0700200 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
201 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
202 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
203
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204 /** The singleton instance. */
205 private static PhoneInterfaceManager sInstance;
206
Wink Saville3ab207e2014-11-20 13:07:20 -0800207 private PhoneGlobals mApp;
208 private Phone mPhone;
209 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700210 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800211 private AppOpsManager mAppOps;
212 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800213 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800214 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215
Derek Tan97ebb422014-09-05 16:55:38 -0700216 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
217 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800218 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700219
Derek Tan740e1672017-06-27 14:56:27 -0700220 // The AID of ISD-R.
221 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
222
yinxub1bed742017-04-17 11:45:04 -0700223 private NetworkScanRequestTracker mNetworkScanRequestTracker;
224
Derek Tan89e89d42014-07-08 17:00:10 -0700225 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700226 * A request object to use for transmitting data to an ICC.
227 */
228 private static final class IccAPDUArgument {
229 public int channel, cla, command, p1, p2, p3;
230 public String data;
231
232 public IccAPDUArgument(int channel, int cla, int command,
233 int p1, int p2, int p3, String data) {
234 this.channel = channel;
235 this.cla = cla;
236 this.command = command;
237 this.p1 = p1;
238 this.p2 = p2;
239 this.p3 = p3;
240 this.data = data;
241 }
242 }
243
244 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700245 * A request object to use for transmitting data to an ICC.
246 */
247 private static final class ManualNetworkSelectionArgument {
248 public OperatorInfo operatorInfo;
249 public boolean persistSelection;
250
251 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
252 this.operatorInfo = operatorInfo;
253 this.persistSelection = persistSelection;
254 }
255 }
256
257 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
259 * request after sending. The main thread will notify the request when it is complete.
260 */
261 private static final class MainThreadRequest {
262 /** The argument to use for the request */
263 public Object argument;
264 /** The result of the request that is run on the main thread */
265 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800266 // The subscriber id that this request applies to. Defaults to
267 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
268 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269
270 public MainThreadRequest(Object argument) {
271 this.argument = argument;
272 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800273
274 public MainThreadRequest(Object argument, Integer subId) {
275 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800276 if (subId != null) {
277 this.subId = subId;
278 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280 }
281
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800282 private static final class IncomingThirdPartyCallArgs {
283 public final ComponentName component;
284 public final String callId;
285 public final String callerDisplayName;
286
287 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
288 String callerDisplayName) {
289 this.component = component;
290 this.callId = callId;
291 this.callerDisplayName = callerDisplayName;
292 }
293 }
294
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 /**
296 * A handler that processes messages on the main thread in the phone process. Since many
297 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
298 * inbound binder threads to the main thread in the phone process. The Binder thread
299 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
300 * on, which will be notified when the operation completes and will contain the result of the
301 * request.
302 *
303 * <p>If a MainThreadRequest object is provided in the msg.obj field,
304 * note that request.result must be set to something non-null for the calling thread to
305 * unblock.
306 */
307 private final class MainThreadHandler extends Handler {
308 @Override
309 public void handleMessage(Message msg) {
310 MainThreadRequest request;
311 Message onCompleted;
312 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800313 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700314 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315
316 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700317 case CMD_HANDLE_USSD_REQUEST: {
318 request = (MainThreadRequest) msg.obj;
319 final Phone phone = getPhoneFromRequest(request);
320 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
321 String ussdRequest = ussdObject.first;
322 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700323
324 if (!isUssdApiAllowed(request.subId)) {
325 // Carrier does not support use of this API, return failure.
326 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
327 UssdResponse response = new UssdResponse(ussdRequest, null);
328 Bundle returnData = new Bundle();
329 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
330 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
331
332 request.result = true;
333 synchronized (request) {
334 request.notifyAll();
335 }
336 return;
337 }
338
Tyler Gunn52dcf772017-04-26 11:30:31 -0700339 try {
340 request.result = phone != null ?
341 phone.handleUssdRequest(ussdRequest, wrappedCallback)
342 : false;
343 } catch (CallStateException cse) {
344 request.result = false;
345 }
pkanwar32d516d2016-10-14 19:37:38 -0700346 // Wake up the requesting thread
347 synchronized (request) {
348 request.notifyAll();
349 }
350 break;
351 }
352
Yorke Lee716f67e2015-06-17 15:39:16 -0700353 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700355 final Phone phone = getPhoneFromRequest(request);
356 request.result = phone != null ?
357 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
358 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 // Wake up the requesting thread
360 synchronized (request) {
361 request.notifyAll();
362 }
363 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700364 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365
366 case CMD_HANDLE_NEIGHBORING_CELL:
367 request = (MainThreadRequest) msg.obj;
368 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
369 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700370 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 break;
372
373 case EVENT_NEIGHBORING_CELL_DONE:
374 ar = (AsyncResult) msg.obj;
375 request = (MainThreadRequest) ar.userObj;
376 if (ar.exception == null && ar.result != null) {
377 request.result = ar.result;
378 } else {
379 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800380 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 }
382 // Wake up the requesting thread
383 synchronized (request) {
384 request.notifyAll();
385 }
386 break;
387
388 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700389 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800390 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700391 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392 break;
393
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 case CMD_END_CALL:
395 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800396 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700397 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700398 Phone phone = getPhone(end_subId);
399 if (phone == null) {
400 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
401 break;
402 }
403 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
405 // CDMA: If the user presses the Power button we treat it as
406 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700407 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
409 // GSM: End the call as per the Phone state
410 hungUp = PhoneUtils.hangup(mCM);
411 } else {
412 throw new IllegalStateException("Unexpected phone type: " + phoneType);
413 }
414 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
415 request.result = hungUp;
416 // Wake up the requesting thread
417 synchronized (request) {
418 request.notifyAll();
419 }
420 break;
421
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700422 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700423 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700424 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800425 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700426 if (uiccCard == null) {
427 loge("iccTransmitApduLogicalChannel: No UICC");
428 request.result = new IccIoResult(0x6F, 0, (byte[])null);
429 synchronized (request) {
430 request.notifyAll();
431 }
432 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700433 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
434 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700435 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700436 iccArgument.channel, iccArgument.cla, iccArgument.command,
437 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700439 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700440 break;
441
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 ar = (AsyncResult) msg.obj;
444 request = (MainThreadRequest) ar.userObj;
445 if (ar.exception == null && ar.result != null) {
446 request.result = ar.result;
447 } else {
448 request.result = new IccIoResult(0x6F, 0, (byte[])null);
449 if (ar.result == null) {
450 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800451 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800453 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 } else {
455 loge("iccTransmitApduLogicalChannel: Unknown exception");
456 }
457 }
458 synchronized (request) {
459 request.notifyAll();
460 }
461 break;
462
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
464 request = (MainThreadRequest) msg.obj;
465 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800466 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 if (uiccCard == null) {
468 loge("iccTransmitApduBasicChannel: No UICC");
469 request.result = new IccIoResult(0x6F, 0, (byte[])null);
470 synchronized (request) {
471 request.notifyAll();
472 }
473 } else {
474 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
475 request);
476 uiccCard.iccTransmitApduBasicChannel(
477 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
478 iccArgument.p3, iccArgument.data, onCompleted);
479 }
480 break;
481
482 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
483 ar = (AsyncResult) msg.obj;
484 request = (MainThreadRequest) ar.userObj;
485 if (ar.exception == null && ar.result != null) {
486 request.result = ar.result;
487 } else {
488 request.result = new IccIoResult(0x6F, 0, (byte[])null);
489 if (ar.result == null) {
490 loge("iccTransmitApduBasicChannel: Empty response");
491 } else if (ar.exception instanceof CommandException) {
492 loge("iccTransmitApduBasicChannel: CommandException: " +
493 ar.exception);
494 } else {
495 loge("iccTransmitApduBasicChannel: Unknown exception");
496 }
497 }
498 synchronized (request) {
499 request.notifyAll();
500 }
501 break;
502
503 case CMD_EXCHANGE_SIM_IO:
504 request = (MainThreadRequest) msg.obj;
505 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800506 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 if (uiccCard == null) {
508 loge("iccExchangeSimIO: No UICC");
509 request.result = new IccIoResult(0x6F, 0, (byte[])null);
510 synchronized (request) {
511 request.notifyAll();
512 }
513 } else {
514 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
515 request);
516 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
517 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
518 iccArgument.data, onCompleted);
519 }
520 break;
521
522 case EVENT_EXCHANGE_SIM_IO_DONE:
523 ar = (AsyncResult) msg.obj;
524 request = (MainThreadRequest) ar.userObj;
525 if (ar.exception == null && ar.result != null) {
526 request.result = ar.result;
527 } else {
528 request.result = new IccIoResult(0x6f, 0, (byte[])null);
529 }
530 synchronized (request) {
531 request.notifyAll();
532 }
533 break;
534
Derek Tan4d5e5c12014-02-04 11:54:58 -0800535 case CMD_SEND_ENVELOPE:
536 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800537 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700538 if (uiccCard == null) {
539 loge("sendEnvelopeWithStatus: No UICC");
540 request.result = new IccIoResult(0x6F, 0, (byte[])null);
541 synchronized (request) {
542 request.notifyAll();
543 }
544 } else {
545 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
546 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
547 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800548 break;
549
550 case EVENT_SEND_ENVELOPE_DONE:
551 ar = (AsyncResult) msg.obj;
552 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700553 if (ar.exception == null && ar.result != null) {
554 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800555 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700556 request.result = new IccIoResult(0x6F, 0, (byte[])null);
557 if (ar.result == null) {
558 loge("sendEnvelopeWithStatus: Empty response");
559 } else if (ar.exception instanceof CommandException) {
560 loge("sendEnvelopeWithStatus: CommandException: " +
561 ar.exception);
562 } else {
563 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
564 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 }
566 synchronized (request) {
567 request.notifyAll();
568 }
569 break;
570
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 case CMD_OPEN_CHANNEL:
572 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800573 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800574 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700575 if (uiccCard == null) {
576 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800577 request.result = new IccOpenLogicalChannelResponse(-1,
578 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 synchronized (request) {
580 request.notifyAll();
581 }
582 } else {
583 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800584 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
585 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700586 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 break;
588
589 case EVENT_OPEN_CHANNEL_DONE:
590 ar = (AsyncResult) msg.obj;
591 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 int[] result = (int[]) ar.result;
595 int channelId = result[0];
596 byte[] selectResponse = null;
597 if (result.length > 1) {
598 selectResponse = new byte[result.length - 1];
599 for (int i = 1; i < result.length; ++i) {
600 selectResponse[i - 1] = (byte) result[i];
601 }
602 }
603 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700604 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 if (ar.result == null) {
607 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 if (ar.exception != null) {
610 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
611 }
612
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700614 if (ar.exception instanceof CommandException) {
615 CommandException.Error error =
616 ((CommandException) (ar.exception)).getCommandError();
617 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700618 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700619 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700620 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 }
622 }
623 openChannelResp = new IccOpenLogicalChannelResponse(
624 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700626 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 synchronized (request) {
628 request.notifyAll();
629 }
630 break;
631
632 case CMD_CLOSE_CHANNEL:
633 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800634 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 if (uiccCard == null) {
636 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900637 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 synchronized (request) {
639 request.notifyAll();
640 }
641 } else {
642 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
643 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
644 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 break;
646
647 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800648 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
649 break;
650
651 case CMD_NV_READ_ITEM:
652 request = (MainThreadRequest) msg.obj;
653 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
654 mPhone.nvReadItem((Integer) request.argument, onCompleted);
655 break;
656
657 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 ar = (AsyncResult) msg.obj;
659 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800660 if (ar.exception == null && ar.result != null) {
661 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800663 request.result = "";
664 if (ar.result == null) {
665 loge("nvReadItem: Empty response");
666 } else if (ar.exception instanceof CommandException) {
667 loge("nvReadItem: CommandException: " +
668 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800670 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 }
672 }
673 synchronized (request) {
674 request.notifyAll();
675 }
676 break;
677
Jake Hambye994d462014-02-03 13:10:13 -0800678 case CMD_NV_WRITE_ITEM:
679 request = (MainThreadRequest) msg.obj;
680 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
681 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
682 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
683 break;
684
685 case EVENT_NV_WRITE_ITEM_DONE:
686 handleNullReturnEvent(msg, "nvWriteItem");
687 break;
688
689 case CMD_NV_WRITE_CDMA_PRL:
690 request = (MainThreadRequest) msg.obj;
691 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
692 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
693 break;
694
695 case EVENT_NV_WRITE_CDMA_PRL_DONE:
696 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
697 break;
698
699 case CMD_NV_RESET_CONFIG:
700 request = (MainThreadRequest) msg.obj;
701 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
702 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
703 break;
704
705 case EVENT_NV_RESET_CONFIG_DONE:
706 handleNullReturnEvent(msg, "nvResetConfig");
707 break;
708
Jake Hamby7c27be32014-03-03 13:25:59 -0800709 case CMD_GET_PREFERRED_NETWORK_TYPE:
710 request = (MainThreadRequest) msg.obj;
711 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700712 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 break;
714
715 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
716 ar = (AsyncResult) msg.obj;
717 request = (MainThreadRequest) ar.userObj;
718 if (ar.exception == null && ar.result != null) {
719 request.result = ar.result; // Integer
720 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800721 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800722 if (ar.result == null) {
723 loge("getPreferredNetworkType: Empty response");
724 } else if (ar.exception instanceof CommandException) {
725 loge("getPreferredNetworkType: CommandException: " +
726 ar.exception);
727 } else {
728 loge("getPreferredNetworkType: Unknown exception");
729 }
730 }
731 synchronized (request) {
732 request.notifyAll();
733 }
734 break;
735
736 case CMD_SET_PREFERRED_NETWORK_TYPE:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
739 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700740 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800741 break;
742
743 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
744 handleNullReturnEvent(msg, "setPreferredNetworkType");
745 break;
746
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800747 case CMD_SET_VOICEMAIL_NUMBER:
748 request = (MainThreadRequest) msg.obj;
749 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
750 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800751 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
752 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800753 break;
754
755 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
756 handleNullReturnEvent(msg, "setVoicemailNumber");
757 break;
758
Stuart Scott54788802015-03-30 13:18:01 -0700759 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
762 request);
763 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
764 break;
765
766 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
767 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
768 break;
769
Shishir Agrawal302c8692015-06-19 13:49:39 -0700770 case CMD_PERFORM_NETWORK_SCAN:
771 request = (MainThreadRequest) msg.obj;
772 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
773 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
774 break;
775
776 case EVENT_PERFORM_NETWORK_SCAN_DONE:
777 ar = (AsyncResult) msg.obj;
778 request = (MainThreadRequest) ar.userObj;
779 CellNetworkScanResult cellScanResult;
780 if (ar.exception == null && ar.result != null) {
781 cellScanResult = new CellNetworkScanResult(
782 CellNetworkScanResult.STATUS_SUCCESS,
783 (List<OperatorInfo>) ar.result);
784 } else {
785 if (ar.result == null) {
786 loge("getCellNetworkScanResults: Empty response");
787 }
788 if (ar.exception != null) {
789 loge("getCellNetworkScanResults: Exception: " + ar.exception);
790 }
791 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
792 if (ar.exception instanceof CommandException) {
793 CommandException.Error error =
794 ((CommandException) (ar.exception)).getCommandError();
795 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
796 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
797 } else if (error == CommandException.Error.GENERIC_FAILURE) {
798 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
799 }
800 }
801 cellScanResult = new CellNetworkScanResult(errorCode, null);
802 }
803 request.result = cellScanResult;
804 synchronized (request) {
805 request.notifyAll();
806 }
807 break;
808
809 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
810 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700811 ManualNetworkSelectionArgument selArg =
812 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700813 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
814 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700815 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
816 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700817 break;
818
819 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
820 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
821 break;
822
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700823 case CMD_GET_MODEM_ACTIVITY_INFO:
824 request = (MainThreadRequest) msg.obj;
825 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700826 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700827 break;
828
829 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
830 ar = (AsyncResult) msg.obj;
831 request = (MainThreadRequest) ar.userObj;
832 if (ar.exception == null && ar.result != null) {
833 request.result = ar.result;
834 } else {
835 if (ar.result == null) {
836 loge("queryModemActivityInfo: Empty response");
837 } else if (ar.exception instanceof CommandException) {
838 loge("queryModemActivityInfo: CommandException: " +
839 ar.exception);
840 } else {
841 loge("queryModemActivityInfo: Unknown exception");
842 }
843 }
Amit Mahajand4766222016-01-28 15:28:28 -0800844 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
845 if (request.result == null) {
846 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
847 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700848 synchronized (request) {
849 request.notifyAll();
850 }
851 break;
852
Meng Wang1a7c35a2016-05-05 20:56:15 -0700853 case CMD_SET_ALLOWED_CARRIERS:
854 request = (MainThreadRequest) msg.obj;
855 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
856 mPhone.setAllowedCarriers(
857 (List<CarrierIdentifier>) request.argument,
858 onCompleted);
859 break;
860
861 case EVENT_SET_ALLOWED_CARRIERS_DONE:
862 ar = (AsyncResult) msg.obj;
863 request = (MainThreadRequest) ar.userObj;
864 if (ar.exception == null && ar.result != null) {
865 request.result = ar.result;
866 } else {
867 if (ar.result == null) {
868 loge("setAllowedCarriers: Empty response");
869 } else if (ar.exception instanceof CommandException) {
870 loge("setAllowedCarriers: CommandException: " +
871 ar.exception);
872 } else {
873 loge("setAllowedCarriers: Unknown exception");
874 }
875 }
876 // Result cannot be null. Return -1 on error.
877 if (request.result == null) {
878 request.result = new int[]{-1};
879 }
880 synchronized (request) {
881 request.notifyAll();
882 }
883 break;
884
885 case CMD_GET_ALLOWED_CARRIERS:
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
888 mPhone.getAllowedCarriers(onCompleted);
889 break;
890
891 case EVENT_GET_ALLOWED_CARRIERS_DONE:
892 ar = (AsyncResult) msg.obj;
893 request = (MainThreadRequest) ar.userObj;
894 if (ar.exception == null && ar.result != null) {
895 request.result = ar.result;
896 } else {
897 if (ar.result == null) {
898 loge("getAllowedCarriers: Empty response");
899 } else if (ar.exception instanceof CommandException) {
900 loge("getAllowedCarriers: CommandException: " +
901 ar.exception);
902 } else {
903 loge("getAllowedCarriers: Unknown exception");
904 }
905 }
906 // Result cannot be null. Return empty list of CarrierIdentifier.
907 if (request.result == null) {
908 request.result = new ArrayList<CarrierIdentifier>(0);
909 }
910 synchronized (request) {
911 request.notifyAll();
912 }
913 break;
914
Nathan Haroldb3014052017-01-25 15:57:32 -0800915 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 if (ar.exception == null && ar.result != null) {
919 request.result = ar.result;
920 } else {
921 request.result = new IllegalArgumentException(
922 "Failed to retrieve Forbidden Plmns");
923 if (ar.result == null) {
924 loge("getForbiddenPlmns: Empty response");
925 } else {
926 loge("getForbiddenPlmns: Unknown exception");
927 }
928 }
929 synchronized (request) {
930 request.notifyAll();
931 }
932 break;
933
934 case CMD_GET_FORBIDDEN_PLMNS:
935 request = (MainThreadRequest) msg.obj;
936 uiccCard = getUiccCardFromRequest(request);
937 if (uiccCard == null) {
938 loge("getForbiddenPlmns() UiccCard is null");
939 request.result = new IllegalArgumentException(
940 "getForbiddenPlmns() UiccCard is null");
941 synchronized (request) {
942 request.notifyAll();
943 }
944 break;
945 }
946 Integer appType = (Integer) request.argument;
947 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
948 if (uiccApp == null) {
949 loge("getForbiddenPlmns() no app with specified type -- "
950 + appType);
951 request.result = new IllegalArgumentException("Failed to get UICC App");
952 synchronized (request) {
953 request.notifyAll();
954 }
955 break;
956 } else {
957 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
958 + " specified type -- " + appType);
959 }
960 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
961 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
962 onCompleted);
963 break;
964
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000965 case CMD_SWITCH_SLOTS:
966 request = (MainThreadRequest) msg.obj;
967 int[] physicalSlots = (int[]) request.argument;
968 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
969 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
970 break;
971
972 case EVENT_SWITCH_SLOTS_DONE:
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 request.result = (ar.exception == null);
976 synchronized (request) {
977 request.notifyAll();
978 }
979 break;
980
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700981 default:
982 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
983 break;
984 }
985 }
Jake Hambye994d462014-02-03 13:10:13 -0800986
987 private void handleNullReturnEvent(Message msg, String command) {
988 AsyncResult ar = (AsyncResult) msg.obj;
989 MainThreadRequest request = (MainThreadRequest) ar.userObj;
990 if (ar.exception == null) {
991 request.result = true;
992 } else {
993 request.result = false;
994 if (ar.exception instanceof CommandException) {
995 loge(command + ": CommandException: " + ar.exception);
996 } else {
997 loge(command + ": Unknown exception");
998 }
999 }
1000 synchronized (request) {
1001 request.notifyAll();
1002 }
1003 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001004 }
1005
1006 /**
1007 * Posts the specified command to be executed on the main thread,
1008 * waits for the request to complete, and returns the result.
1009 * @see #sendRequestAsync
1010 */
1011 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001012 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001013 }
1014
1015 /**
1016 * Posts the specified command to be executed on the main thread,
1017 * waits for the request to complete, and returns the result.
1018 * @see #sendRequestAsync
1019 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001020 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001021 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1022 throw new RuntimeException("This method will deadlock if called from the main thread.");
1023 }
1024
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001025 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001026 Message msg = mMainThreadHandler.obtainMessage(command, request);
1027 msg.sendToTarget();
1028
1029 // Wait for the request to complete
1030 synchronized (request) {
1031 while (request.result == null) {
1032 try {
1033 request.wait();
1034 } catch (InterruptedException e) {
1035 // Do nothing, go back and wait until the request is complete
1036 }
1037 }
1038 }
1039 return request.result;
1040 }
1041
1042 /**
1043 * Asynchronous ("fire and forget") version of sendRequest():
1044 * Posts the specified command to be executed on the main thread, and
1045 * returns immediately.
1046 * @see #sendRequest
1047 */
1048 private void sendRequestAsync(int command) {
1049 mMainThreadHandler.sendEmptyMessage(command);
1050 }
1051
1052 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001053 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1054 * @see {@link #sendRequest(int,Object)}
1055 */
1056 private void sendRequestAsync(int command, Object argument) {
1057 MainThreadRequest request = new MainThreadRequest(argument);
1058 Message msg = mMainThreadHandler.obtainMessage(command, request);
1059 msg.sendToTarget();
1060 }
1061
1062 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001063 * Initialize the singleton PhoneInterfaceManager instance.
1064 * This is only done once, at startup, from PhoneApp.onCreate().
1065 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001066 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001067 synchronized (PhoneInterfaceManager.class) {
1068 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001069 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001070 } else {
1071 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1072 }
1073 return sInstance;
1074 }
1075 }
1076
1077 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001078 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001079 mApp = app;
1080 mPhone = phone;
1081 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001082 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1084 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001085 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001086 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001087 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001088 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001089
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001090 publish();
1091 }
1092
1093 private void publish() {
1094 if (DBG) log("publish: " + this);
1095
1096 ServiceManager.addService("phone", this);
1097 }
1098
Stuart Scott584921c2015-01-15 17:10:34 -08001099 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001100 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1101 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001102 }
1103
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001104 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1105 Phone phone = getPhoneFromRequest(request);
1106 return phone == null ? null :
1107 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1108 }
1109
Wink Saville36469e72014-06-11 15:17:00 -07001110 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001111 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001112 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001114 //
1115 // Implementation of the ITelephony interface.
1116 //
1117
1118 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001119 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001120 }
1121
Wink Savilleb564aae2014-10-23 10:18:09 -07001122 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001123 if (DBG) log("dial: " + number);
1124 // No permission check needed here: This is just a wrapper around the
1125 // ACTION_DIAL intent, which is available to any app since it puts up
1126 // the UI before it does anything.
1127
1128 String url = createTelUrl(number);
1129 if (url == null) {
1130 return;
1131 }
1132
1133 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001134 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001135 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1136 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1137 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1138 mApp.startActivity(intent);
1139 }
1140 }
1141
1142 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001143 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001144 }
1145
Wink Savilleb564aae2014-10-23 10:18:09 -07001146 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001147 if (DBG) log("call: " + number);
1148
1149 // This is just a wrapper around the ACTION_CALL intent, but we still
1150 // need to do a permission check since we're calling startActivity()
1151 // from the context of the phone app.
1152 enforceCallPermission();
1153
1154 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1155 != AppOpsManager.MODE_ALLOWED) {
1156 return;
1157 }
1158
1159 String url = createTelUrl(number);
1160 if (url == null) {
1161 return;
1162 }
1163
Wink Saville08874612014-08-31 19:19:58 -07001164 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001165 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001166 if (slist != null) {
1167 for (SubscriptionInfo subInfoRecord : slist) {
1168 if (subInfoRecord.getSubscriptionId() == subId) {
1169 isValid = true;
1170 break;
1171 }
Wink Saville08874612014-08-31 19:19:58 -07001172 }
1173 }
1174 if (isValid == false) {
1175 return;
1176 }
1177
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001178 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001179 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001180 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1181 mApp.startActivity(intent);
1182 }
1183
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001184 /**
1185 * End a call based on call state
1186 * @return true is a call was ended
1187 */
1188 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001189 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001190 }
1191
1192 /**
1193 * End a call based on the call state of the subId
1194 * @return true is a call was ended
1195 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001196 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001197 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1198 != PackageManager.PERMISSION_GRANTED) {
1199 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1200 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1201 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1202 }
Stuart Scott584921c2015-01-15 17:10:34 -08001203 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001204 }
1205
1206 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001207 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001208 }
1209
Wink Savilleb564aae2014-10-23 10:18:09 -07001210 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001211 if (DBG) log("answerRingingCall...");
1212 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1213 // but that can probably wait till the big TelephonyManager API overhaul.
1214 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1215 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001216 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001217 }
1218
1219 /**
1220 * Make the actual telephony calls to implement answerRingingCall().
1221 * This should only be called from the main thread of the Phone app.
1222 * @see #answerRingingCall
1223 *
1224 * TODO: it would be nice to return true if we answered the call, or
1225 * false if there wasn't actually a ringing incoming call, or some
1226 * other error occurred. (In other words, pass back the return value
1227 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1228 * But that would require calling this method via sendRequest() rather
1229 * than sendRequestAsync(), and right now we don't actually *need* that
1230 * return value, so let's just return void for now.
1231 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001232 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001233 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001235 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1236 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001237 if (hasActiveCall && hasHoldingCall) {
1238 // Both lines are in use!
1239 // TODO: provide a flag to let the caller specify what
1240 // policy to use if both lines are in use. (The current
1241 // behavior is hardwired to "answer incoming, end ongoing",
1242 // which is how the CALL button is specced to behave.)
1243 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1244 return;
1245 } else {
1246 // answerCall() will automatically hold the current active
1247 // call, if there is one.
1248 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1249 return;
1250 }
1251 } else {
1252 // No call was ringing.
1253 return;
1254 }
1255 }
1256
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001257 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001258 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001260 public void silenceRinger() {
1261 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 }
1263
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001264 @Override
1265 public boolean isOffhook(String callingPackage) {
1266 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001267 }
1268
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001269 @Override
1270 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001272 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001273 return false;
1274 }
1275
Sanket Padawe356d7632015-06-22 14:03:32 -07001276 final Phone phone = getPhone(subId);
1277 if (phone != null) {
1278 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1279 } else {
1280 return false;
1281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282 }
1283
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001284 @Override
1285 public boolean isRinging(String callingPackage) {
1286 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001287 }
1288
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001289 @Override
1290 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001291 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001292 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001293 return false;
1294 }
1295
Sanket Padawe356d7632015-06-22 14:03:32 -07001296 final Phone phone = getPhone(subId);
1297 if (phone != null) {
1298 return (phone.getState() == PhoneConstants.State.RINGING);
1299 } else {
1300 return false;
1301 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001302 }
1303
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001304 @Override
1305 public boolean isIdle(String callingPackage) {
1306 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001307 }
1308
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001309 @Override
1310 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001312 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001313 return false;
1314 }
1315
Sanket Padawe356d7632015-06-22 14:03:32 -07001316 final Phone phone = getPhone(subId);
1317 if (phone != null) {
1318 return (phone.getState() == PhoneConstants.State.IDLE);
1319 } else {
1320 return false;
1321 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001322 }
1323
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001325 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001326 }
1327
Wink Savilleb564aae2014-10-23 10:18:09 -07001328 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001329 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001330 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1331 }
1332
1333 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001334 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001335 }
1336
Wink Savilleb564aae2014-10-23 10:18:09 -07001337 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001338 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001339 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1340 }
1341
1342 /** {@hide} */
1343 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001344 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001345 }
1346
Wink Savilleb564aae2014-10-23 10:18:09 -07001347 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001348 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001349 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001350 checkSimPin.start();
1351 return checkSimPin.unlockSim(null, pin);
1352 }
1353
Wink Saville9de0f752013-10-22 19:04:03 -07001354 /** {@hide} */
1355 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001356 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001357 }
1358
Wink Savilleb564aae2014-10-23 10:18:09 -07001359 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001361 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001362 checkSimPuk.start();
1363 return checkSimPuk.unlockSim(puk, pin);
1364 }
1365
1366 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001367 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001368 * a synchronous one.
1369 */
1370 private static class UnlockSim extends Thread {
1371
1372 private final IccCard mSimCard;
1373
1374 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001375 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1376 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377
1378 // For replies from SimCard interface
1379 private Handler mHandler;
1380
1381 // For async handler to identify request type
1382 private static final int SUPPLY_PIN_COMPLETE = 100;
1383
1384 public UnlockSim(IccCard simCard) {
1385 mSimCard = simCard;
1386 }
1387
1388 @Override
1389 public void run() {
1390 Looper.prepare();
1391 synchronized (UnlockSim.this) {
1392 mHandler = new Handler() {
1393 @Override
1394 public void handleMessage(Message msg) {
1395 AsyncResult ar = (AsyncResult) msg.obj;
1396 switch (msg.what) {
1397 case SUPPLY_PIN_COMPLETE:
1398 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1399 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001400 mRetryCount = msg.arg1;
1401 if (ar.exception != null) {
1402 if (ar.exception instanceof CommandException &&
1403 ((CommandException)(ar.exception)).getCommandError()
1404 == CommandException.Error.PASSWORD_INCORRECT) {
1405 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1406 } else {
1407 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1408 }
1409 } else {
1410 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 mDone = true;
1413 UnlockSim.this.notifyAll();
1414 }
1415 break;
1416 }
1417 }
1418 };
1419 UnlockSim.this.notifyAll();
1420 }
1421 Looper.loop();
1422 }
1423
1424 /*
1425 * Use PIN or PUK to unlock SIM card
1426 *
1427 * If PUK is null, unlock SIM card with PIN
1428 *
1429 * If PUK is not null, unlock SIM card with PUK and set PIN code
1430 */
Wink Saville9de0f752013-10-22 19:04:03 -07001431 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001432
1433 while (mHandler == null) {
1434 try {
1435 wait();
1436 } catch (InterruptedException e) {
1437 Thread.currentThread().interrupt();
1438 }
1439 }
1440 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1441
1442 if (puk == null) {
1443 mSimCard.supplyPin(pin, callback);
1444 } else {
1445 mSimCard.supplyPuk(puk, pin, callback);
1446 }
1447
1448 while (!mDone) {
1449 try {
1450 Log.d(LOG_TAG, "wait for done");
1451 wait();
1452 } catch (InterruptedException e) {
1453 // Restore the interrupted status
1454 Thread.currentThread().interrupt();
1455 }
1456 }
1457 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001458 int[] resultArray = new int[2];
1459 resultArray[0] = mResult;
1460 resultArray[1] = mRetryCount;
1461 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 }
1463 }
1464
1465 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001466 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001467
1468 }
1469
Wink Savilleb564aae2014-10-23 10:18:09 -07001470 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471 // No permission check needed here: this call is harmless, and it's
1472 // needed for the ServiceState.requestStateUpdate() call (which is
1473 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001474 final Phone phone = getPhone(subId);
1475 if (phone != null) {
1476 phone.updateServiceLocation();
1477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478 }
1479
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001480 @Override
1481 public boolean isRadioOn(String callingPackage) {
1482 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001483 }
1484
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001485 @Override
1486 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001488 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001489 return false;
1490 }
1491 return isRadioOnForSubscriber(subId);
1492 }
1493
1494 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001495 final Phone phone = getPhone(subId);
1496 if (phone != null) {
1497 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1498 } else {
1499 return false;
1500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 }
1502
1503 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001504 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001505
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506 }
Wink Saville36469e72014-06-11 15:17:00 -07001507
Wink Savilleb564aae2014-10-23 10:18:09 -07001508 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001510 final Phone phone = getPhone(subId);
1511 if (phone != null) {
1512 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1513 }
Wink Saville36469e72014-06-11 15:17:00 -07001514 }
1515
1516 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001517 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001518 }
1519
Wink Savilleb564aae2014-10-23 10:18:09 -07001520 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001521 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001522 final Phone phone = getPhone(subId);
1523 if (phone == null) {
1524 return false;
1525 }
1526 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001527 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001528 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 }
1530 return true;
1531 }
Wink Saville36469e72014-06-11 15:17:00 -07001532
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001533 public boolean needMobileRadioShutdown() {
1534 /*
1535 * If any of the Radios are available, it will need to be
1536 * shutdown. So return true if any Radio is available.
1537 */
1538 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1539 Phone phone = PhoneFactory.getPhone(i);
1540 if (phone != null && phone.isRadioAvailable()) return true;
1541 }
1542 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1543 return false;
1544 }
1545
1546 public void shutdownMobileRadios() {
1547 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1548 logv("Shutting down Phone " + i);
1549 shutdownRadioUsingPhoneId(i);
1550 }
1551 }
1552
1553 private void shutdownRadioUsingPhoneId(int phoneId) {
1554 enforceModifyPermission();
1555 Phone phone = PhoneFactory.getPhone(phoneId);
1556 if (phone != null && phone.isRadioAvailable()) {
1557 phone.shutdownRadio();
1558 }
1559 }
1560
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001561 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001562 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001563 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1564 if (defaultPhone != null) {
1565 defaultPhone.setRadioPower(turnOn);
1566 return true;
1567 } else {
1568 loge("There's no default phone.");
1569 return false;
1570 }
Wink Saville36469e72014-06-11 15:17:00 -07001571 }
1572
Wink Savilleb564aae2014-10-23 10:18:09 -07001573 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001575 final Phone phone = getPhone(subId);
1576 if (phone != null) {
1577 phone.setRadioPower(turnOn);
1578 return true;
1579 } else {
1580 return false;
1581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 }
1583
Wink Saville36469e72014-06-11 15:17:00 -07001584 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001585 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 public boolean enableDataConnectivity() {
1587 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001588 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001589 final Phone phone = getPhone(subId);
1590 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001591 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001592 return true;
1593 } else {
1594 return false;
1595 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596 }
1597
Wink Saville36469e72014-06-11 15:17:00 -07001598 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001599 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 public boolean disableDataConnectivity() {
1601 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001602 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001603 final Phone phone = getPhone(subId);
1604 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001605 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001606 return true;
1607 } else {
1608 return false;
1609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 }
1611
Sanket Padawe356d7632015-06-22 14:03:32 -07001612 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001613 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001614 final Phone phone = getPhone(subId);
1615 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001616 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001617 } else {
1618 return false;
1619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 }
1621
1622 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001623 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001624 }
1625
pkanwarae03a6b2016-11-06 20:37:09 -08001626 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001627 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001628 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1629 return;
1630 }
1631 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1632 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1633 };
1634
Wink Savilleb564aae2014-10-23 10:18:09 -07001635 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001637 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1638 return false;
1639 }
Wink Saville36469e72014-06-11 15:17:00 -07001640 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 }
1642
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001644 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001645 }
1646
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001647 public int getCallStateForSlot(int slotIndex) {
1648 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001649 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001650 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 }
1652
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001655 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001656 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001657 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001658 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001659 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001660 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 }
1662
Sanket Padawe356d7632015-06-22 14:03:32 -07001663 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001665 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001666 if (phone != null) {
1667 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1668 } else {
1669 return TelephonyManager.DATA_ACTIVITY_NONE;
1670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 }
1672
1673 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001674 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001675 mPhone.getContext().getSystemService(AppOpsManager.class)
1676 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001677 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001678 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001679 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001680 }
1681
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001682 if (DBG_LOC) log("getCellLocation: is active user");
1683 Bundle data = new Bundle();
1684 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1685 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 return null;
1687 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001689 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001690 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1691 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001692 }
1693
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001695 public String getNetworkCountryIsoForPhone(int phoneId) {
1696 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1697 // registered cell info, so return a NULL country instead.
1698 final long identity = Binder.clearCallingIdentity();
1699 try {
1700 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1701 if (TelephonyManager.NETWORK_TYPE_IWLAN
1702 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1703 return "";
1704 }
1705 } finally {
1706 Binder.restoreCallingIdentity(identity);
1707 }
1708 return TelephonyManager.getTelephonyProperty(
1709 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1710 }
1711
1712 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001714 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001715 }
1716
Sanket Padawe356d7632015-06-22 14:03:32 -07001717 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001718 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 mApp.enforceCallingOrSelfPermission(
1720 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001721 final Phone phone = getPhone(subId);
1722 if (phone != null) {
1723 phone.enableLocationUpdates();
1724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
1727 @Override
1728 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001729 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001730 }
1731
Sanket Padawe356d7632015-06-22 14:03:32 -07001732 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001733 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 mApp.enforceCallingOrSelfPermission(
1735 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001736 final Phone phone = getPhone(subId);
1737 if (phone != null) {
1738 phone.disableLocationUpdates();
1739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 }
1741
1742 @Override
1743 @SuppressWarnings("unchecked")
1744 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001745 mPhone.getContext().getSystemService(AppOpsManager.class)
1746 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001747 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001748 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001749 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 }
1751
1752 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1753 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1754 return null;
1755 }
Svetoslav64fad262015-04-14 14:35:21 -07001756
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001757 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001759 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001761 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001762 try {
1763 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1764 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1765 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1766 } catch (RuntimeException e) {
1767 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001769 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
1771
1772
1773 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001774 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001775 mPhone.getContext().getSystemService(AppOpsManager.class)
1776 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001777 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001778 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001779 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001780 }
1781
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001782 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001783 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001784 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1785 for (Phone phone : PhoneFactory.getPhones()) {
1786 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1787 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001789 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 }
1791
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001792 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001794 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001795 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001796 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 }
1798
Shishir Agrawala9f32182016-04-12 12:00:16 -07001799 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001800 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001801 Phone phone = PhoneFactory.getPhone(slotIndex);
1802 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001803 return null;
1804 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001805 int subId = phone.getSubId();
1806 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1807 mApp, subId, callingPackage, "getImeiForSlot")) {
1808 return null;
1809 }
1810 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001811 }
1812
1813 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001814 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001815 Phone phone = PhoneFactory.getPhone(slotIndex);
1816 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001817 return null;
1818 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001819 int subId = phone.getSubId();
1820 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1821 mApp, subId, callingPackage, "getMeidForSlot")) {
1822 return null;
1823 }
1824 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001825 }
1826
1827 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001828 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001829 Phone phone = PhoneFactory.getPhone(slotIndex);
1830 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001831 return null;
1832 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001833 int subId = phone.getSubId();
1834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1835 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1836 return null;
1837 }
1838 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001839 }
1840
fionaxu43304da2017-11-27 22:51:16 -08001841 @Override
1842 public int getSubscriptionCarrierId(int subId) {
1843 final Phone phone = getPhone(subId);
1844 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1845 }
1846
1847 @Override
1848 public String getSubscriptionCarrierName(int subId) {
1849 final Phone phone = getPhone(subId);
1850 return phone == null ? null : phone.getCarrierName();
1851 }
1852
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 //
1854 // Internal helper methods.
1855 //
1856
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001857 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1859 *
1860 * @throws SecurityException if the caller does not have the required permission
1861 */
1862 private void enforceModifyPermission() {
1863 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1864 }
1865
1866 /**
1867 * Make sure the caller has the CALL_PHONE permission.
1868 *
1869 * @throws SecurityException if the caller does not have the required permission
1870 */
1871 private void enforceCallPermission() {
1872 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1873 }
1874
Stuart Scott8eef64f2015-04-08 15:13:54 -07001875 private void enforceConnectivityInternalPermission() {
1876 mApp.enforceCallingOrSelfPermission(
1877 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1878 "ConnectivityService");
1879 }
1880
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 private String createTelUrl(String number) {
1882 if (TextUtils.isEmpty(number)) {
1883 return null;
1884 }
1885
Jake Hambye994d462014-02-03 13:10:13 -08001886 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 }
1888
Ihab Awadf9e92732013-12-05 18:02:52 -08001889 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1891 }
1892
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001893 private static void logv(String msg) {
1894 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1895 }
1896
Ihab Awadf9e92732013-12-05 18:02:52 -08001897 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1899 }
1900
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001901 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001903 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001904 }
1905
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001907 public int getActivePhoneTypeForSlot(int slotIndex) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00001908 final Phone phone = PhoneFactory.getPhone(slotIndex);
1909 if (phone == null) {
1910 return PhoneConstants.PHONE_TYPE_NONE;
1911 } else {
1912 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 }
1915
1916 /**
1917 * Returns the CDMA ERI icon index to display
1918 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001919 @Override
1920 public int getCdmaEriIconIndex(String callingPackage) {
1921 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001922 }
1923
Sanket Padawe356d7632015-06-22 14:03:32 -07001924 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001925 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001927 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001928 return -1;
1929 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001930 final Phone phone = getPhone(subId);
1931 if (phone != null) {
1932 return phone.getCdmaEriIconIndex();
1933 } else {
1934 return -1;
1935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
1938 /**
1939 * Returns the CDMA ERI icon mode,
1940 * 0 - ON
1941 * 1 - FLASHING
1942 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001943 @Override
1944 public int getCdmaEriIconMode(String callingPackage) {
1945 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001946 }
1947
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001949 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001950 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001951 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001952 return -1;
1953 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001954 final Phone phone = getPhone(subId);
1955 if (phone != null) {
1956 return phone.getCdmaEriIconMode();
1957 } else {
1958 return -1;
1959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001960 }
1961
1962 /**
1963 * Returns the CDMA ERI text,
1964 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001965 @Override
1966 public String getCdmaEriText(String callingPackage) {
1967 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001968 }
1969
Sanket Padawe356d7632015-06-22 14:03:32 -07001970 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001971 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001973 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001974 return null;
1975 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 final Phone phone = getPhone(subId);
1977 if (phone != null) {
1978 return phone.getCdmaEriText();
1979 } else {
1980 return null;
1981 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 }
1983
1984 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001985 * Returns the CDMA MDN.
1986 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001987 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001988 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1990 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07001991 final Phone phone = getPhone(subId);
1992 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1993 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001994 } else {
1995 return null;
1996 }
1997 }
1998
1999 /**
2000 * Returns the CDMA MIN.
2001 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002002 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002003 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2005 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002006 final Phone phone = getPhone(subId);
2007 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2008 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002009 } else {
2010 return null;
2011 }
2012 }
2013
2014 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 * Returns true if CDMA provisioning needs to run.
2016 */
2017 public boolean needsOtaServiceProvisioning() {
2018 return mPhone.needsOtaServiceProvisioning();
2019 }
2020
2021 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002022 * Sets the voice mail number of a given subId.
2023 */
2024 @Override
2025 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002026 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002027 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2028 new Pair<String, String>(alphaTag, number), new Integer(subId));
2029 return success;
2030 }
2031
Ta-wei Yen87c49842016-05-13 21:19:52 -07002032 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002033 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2034 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2035 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2036 if (!TextUtils.equals(callingPackage, systemDialer)) {
2037 throw new SecurityException("caller must be system dialer");
2038 }
2039 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2040 if (phoneAccountHandle == null){
2041 return null;
2042 }
2043 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2044 }
2045
2046 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002047 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002048 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002050 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002051 return null;
2052 }
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002053 final long identity = Binder.clearCallingIdentity();
2054 try {
2055 return RemoteVvmTaskManager
2056 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2057 } finally {
2058 Binder.restoreCallingIdentity(identity);
2059 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002060 }
2061
2062 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002063 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2064 VisualVoicemailSmsFilterSettings settings) {
2065 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002066 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002067 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2068 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002069 }
2070
2071 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002072 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2073 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002074 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002075 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002076 }
2077
2078 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002079 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2080 String callingPackage, int subId) {
2081 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002082 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002083 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002084 }
2085
2086 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002087 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002088 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002089 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002090 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2091 }
2092
2093 @Override
2094 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2095 String number, int port, String text, PendingIntent sentIntent) {
2096 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002097 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002098 enforceSendSmsPermission();
2099 // Make the calls as the phone process.
2100 final long identity = Binder.clearCallingIdentity();
2101 try {
2102 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2103 if (port == 0) {
2104 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2105 sentIntent, null, false);
2106 } else {
2107 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2108 smsManager.sendDataMessageWithSelfPermissions(number, null,
2109 (short) port, data, sentIntent, null);
2110 }
2111 } finally {
2112 Binder.restoreCallingIdentity(identity);
2113 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002114 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002115 /**
fionaxu0152e512016-11-14 13:36:14 -08002116 * Sets the voice activation state of a given subId.
2117 */
2118 @Override
2119 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2121 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002122 final Phone phone = getPhone(subId);
2123 if (phone != null) {
2124 phone.setVoiceActivationState(activationState);
2125 } else {
2126 loge("setVoiceActivationState fails with invalid subId: " + subId);
2127 }
2128 }
2129
2130 /**
2131 * Sets the data activation state of a given subId.
2132 */
2133 @Override
2134 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002135 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2136 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002137 final Phone phone = getPhone(subId);
2138 if (phone != null) {
2139 phone.setDataActivationState(activationState);
2140 } else {
2141 loge("setVoiceActivationState fails with invalid subId: " + subId);
2142 }
2143 }
2144
2145 /**
2146 * Returns the voice activation state of a given subId.
2147 */
2148 @Override
2149 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002150 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002151 final Phone phone = getPhone(subId);
2152 if (phone != null) {
2153 return phone.getVoiceActivationState();
2154 } else {
2155 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2156 }
2157 }
2158
2159 /**
2160 * Returns the data activation state of a given subId.
2161 */
2162 @Override
2163 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002164 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002165 final Phone phone = getPhone(subId);
2166 if (phone != null) {
2167 return phone.getDataActivationState();
2168 } else {
2169 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2170 }
2171 }
2172
2173 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174 * Returns the unread count of voicemails
2175 */
2176 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002177 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002178 }
2179
2180 /**
2181 * Returns the unread count of voicemails for a subId
2182 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002183 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002184 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002185 final Phone phone = getPhone(subId);
2186 if (phone != null) {
2187 return phone.getVoiceMessageCount();
2188 } else {
2189 return 0;
2190 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 }
2192
2193 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002194 * returns true, if the device is in a state where both voice and data
2195 * are supported simultaneously. This can change based on location or network condition.
2196 */
2197 @Override
2198 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2199 final Phone phone = getPhone(subId);
2200 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2201 }
2202
2203 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002204 * Send the dialer code if called from the current default dialer or the caller has
2205 * carrier privilege.
2206 * @param inputCode The dialer code to send
2207 */
2208 @Override
2209 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2210 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2211 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2212 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002213 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2214 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002215 }
2216 mPhone.sendDialerSpecialCode(inputCode);
2217 }
2218
2219 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002220 * Returns the data network type.
2221 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002222 *
2223 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2224 */
2225 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002226 public int getNetworkType() {
2227 final Phone phone = getPhone(getDefaultSubscription());
2228 if (phone != null) {
2229 return phone.getServiceState().getDataNetworkType();
2230 } else {
2231 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2232 }
Wink Saville36469e72014-06-11 15:17:00 -07002233 }
2234
2235 /**
2236 * Returns the network type for a subId
2237 */
2238 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002239 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002241 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002242 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2243 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002244
Sanket Padawe356d7632015-06-22 14:03:32 -07002245 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002246 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002247 return phone.getServiceState().getDataNetworkType();
2248 } else {
2249 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 }
2252
2253 /**
2254 * Returns the data network type
2255 */
2256 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002257 public int getDataNetworkType(String callingPackage) {
2258 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002259 }
2260
2261 /**
2262 * Returns the data network type for a subId
2263 */
2264 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002265 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002266 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002267 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002268 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2269 }
2270
Sanket Padawe356d7632015-06-22 14:03:32 -07002271 final Phone phone = getPhone(subId);
2272 if (phone != null) {
2273 return phone.getServiceState().getDataNetworkType();
2274 } else {
2275 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 }
2278
2279 /**
Wink Saville36469e72014-06-11 15:17:00 -07002280 * Returns the Voice network type for a subId
2281 */
2282 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002283 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002284 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002285 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002286 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2287 }
2288
Sanket Padawe356d7632015-06-22 14:03:32 -07002289 final Phone phone = getPhone(subId);
2290 if (phone != null) {
2291 return phone.getServiceState().getVoiceNetworkType();
2292 } else {
2293 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 }
2296
2297 /**
2298 * @return true if a ICC card is present
2299 */
2300 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002301 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002302 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2303 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002304 }
2305
2306 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002307 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002308 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002309 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002310 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2311 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002312 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002313 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002314 } else {
2315 return false;
2316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002317 }
2318
2319 /**
2320 * Return if the current radio is LTE on CDMA. This
2321 * is a tri-state return value as for a period of time
2322 * the mode may be unknown.
2323 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002324 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002325 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002326 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002328 @Override
2329 public int getLteOnCdmaMode(String callingPackage) {
2330 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002331 }
2332
Sanket Padawe356d7632015-06-22 14:03:32 -07002333 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002334 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002335 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002336 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002337 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2338 }
2339
Sanket Padawe356d7632015-06-22 14:03:32 -07002340 final Phone phone = getPhone(subId);
2341 if (phone == null) {
2342 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2343 } else {
2344 return phone.getLteOnCdmaMode();
2345 }
Wink Saville36469e72014-06-11 15:17:00 -07002346 }
2347
2348 public void setPhone(Phone phone) {
2349 mPhone = phone;
2350 }
2351
2352 /**
2353 * {@hide}
2354 * Returns Default subId, 0 in the case of single standby.
2355 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002356 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002357 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002358 }
2359
Shishir Agrawala9f32182016-04-12 12:00:16 -07002360 private int getSlotForDefaultSubscription() {
2361 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2362 }
2363
Wink Savilleb564aae2014-10-23 10:18:09 -07002364 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002365 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002367
2368 /**
2369 * @see android.telephony.TelephonyManager.WifiCallingChoices
2370 */
2371 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002372 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2373 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002374 }
2375
2376 /**
2377 * @see android.telephony.TelephonyManager.WifiCallingChoices
2378 */
2379 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002380 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2381 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2382 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002383 }
2384
Sailesh Nepald1e68152013-12-12 19:08:02 -08002385 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002386 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002387 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002388 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002389
Shishir Agrawal566b7612013-10-28 14:41:00 -07002390 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002391 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2392 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2394 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002395
Derek Tan740e1672017-06-27 14:56:27 -07002396 if (TextUtils.equals(ISDR_AID, aid)) {
2397 // Only allows LPA to open logical channel to ISD-R.
2398 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2399 ComponentInfo bestComponent =
2400 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2401 if (bestComponent == null
2402 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2403 loge("The calling package is not allowed to access ISD-R.");
2404 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2405 }
2406 }
2407
2408 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002409 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002410 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002411 if (DBG) log("iccOpenLogicalChannel: " + response);
2412 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002413 }
2414
2415 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002416 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2418 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002419
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002420 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002421 if (channel < 0) {
2422 return false;
2423 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002424 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002425 if (DBG) log("iccCloseLogicalChannel: " + success);
2426 return success;
2427 }
2428
2429 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002430 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002431 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2433 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002434
2435 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002436 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2437 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002438 " data=" + data);
2439 }
2440
2441 if (channel < 0) {
2442 return "";
2443 }
2444
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002445 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002446 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002447 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2448
Shishir Agrawal566b7612013-10-28 14:41:00 -07002449 // Append the returned status code to the end of the response payload.
2450 String s = Integer.toHexString(
2451 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002452 if (response.payload != null) {
2453 s = IccUtils.bytesToHexString(response.payload) + s;
2454 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002455 return s;
2456 }
Jake Hambye994d462014-02-03 13:10:13 -08002457
Evan Charltonc66da362014-05-16 14:06:40 -07002458 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002459 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2460 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2462 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002463
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002464 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2465 && TextUtils.equals(ISDR_AID, data)) {
2466 // Only allows LPA to select ISD-R.
2467 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2468 ComponentInfo bestComponent =
2469 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2470 if (bestComponent == null
2471 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2472 loge("The calling package is not allowed to select ISD-R.");
2473 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2474 }
2475 }
2476
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002477 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002478 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2479 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002480 }
2481
2482 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002483 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002484 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2485
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002486 // Append the returned status code to the end of the response payload.
2487 String s = Integer.toHexString(
2488 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002489 if (response.payload != null) {
2490 s = IccUtils.bytesToHexString(response.payload) + s;
2491 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002492 return s;
2493 }
2494
2495 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002496 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002497 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2499 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002500
2501 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002502 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002503 p1 + " " + p2 + " " + p3 + ":" + filePath);
2504 }
2505
2506 IccIoResult response =
2507 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002508 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2509 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002510
2511 if (DBG) {
2512 log("Exchange SIM_IO [R]" + response);
2513 }
2514
2515 byte[] result = null;
2516 int length = 2;
2517 if (response.payload != null) {
2518 length = 2 + response.payload.length;
2519 result = new byte[length];
2520 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2521 } else {
2522 result = new byte[length];
2523 }
2524
2525 result[length - 1] = (byte) response.sw2;
2526 result[length - 2] = (byte) response.sw1;
2527 return result;
2528 }
2529
Nathan Haroldb3014052017-01-25 15:57:32 -08002530 /**
2531 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2532 * on a particular subscription
2533 */
sqianb6e41952018-03-12 14:54:01 -07002534 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2535 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2536 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2537 return null;
2538 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002539 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2540 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2541 return null;
2542 }
2543 Object response = sendRequest(
2544 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2545 if (response instanceof String[]) {
2546 return (String[]) response;
2547 }
2548 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2549 return null;
2550 }
2551
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002552 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002553 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2555 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002556
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002557 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002558 if (response.payload == null) {
2559 return "";
2560 }
2561
2562 // Append the returned status code to the end of the response payload.
2563 String s = Integer.toHexString(
2564 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2565 s = IccUtils.bytesToHexString(response.payload) + s;
2566 return s;
2567 }
2568
Jake Hambye994d462014-02-03 13:10:13 -08002569 /**
2570 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2571 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2572 *
2573 * @param itemID the ID of the item to read
2574 * @return the NV item as a String, or null on error.
2575 */
2576 @Override
2577 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2579 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002580 if (DBG) log("nvReadItem: item " + itemID);
2581 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2582 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2583 return value;
2584 }
2585
2586 /**
2587 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2588 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2589 *
2590 * @param itemID the ID of the item to read
2591 * @param itemValue the value to write, as a String
2592 * @return true on success; false on any failure
2593 */
2594 @Override
2595 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2597 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002598 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2599 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2600 new Pair<Integer, String>(itemID, itemValue));
2601 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2602 return success;
2603 }
2604
2605 /**
2606 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2607 * Used for device configuration by some CDMA operators.
2608 *
2609 * @param preferredRoamingList byte array containing the new PRL
2610 * @return true on success; false on any failure
2611 */
2612 @Override
2613 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2615 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002616 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2617 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2618 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2619 return success;
2620 }
2621
2622 /**
2623 * Perform the specified type of NV config reset.
2624 * Used for device configuration by some CDMA operators.
2625 *
2626 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2627 * @return true on success; false on any failure
2628 */
2629 @Override
2630 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2632 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002633 if (DBG) log("nvResetConfig: type " + resetType);
2634 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2635 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2636 return success;
2637 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002638
2639 /**
Wink Saville36469e72014-06-11 15:17:00 -07002640 * {@hide}
2641 * Returns Default sim, 0 in the case of single standby.
2642 */
2643 public int getDefaultSim() {
2644 //TODO Need to get it from Telephony Devcontroller
2645 return 0;
2646 }
2647
Svet Ganovb320e182015-04-16 12:30:10 -07002648 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002649 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002650 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002651 return new String[0];
2652 }
2653
2654
ram87fca6f2014-07-18 18:58:44 +05302655 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002656 }
2657
Brad Ebinger51f743a2017-01-23 13:50:20 -08002658 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002659 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2660 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002661 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002662 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002663 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002664 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002665 }
2666
2667 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002668 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2669 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002670 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002671 public void disableIms(int slotId) {
2672 enforceModifyPermission();
2673 PhoneFactory.getImsResolver().disableIms(slotId);
2674 }
2675
2676 /**
2677 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2678 * feature or {@link null} if the service is not available. If the feature is available, the
2679 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2680 */
2681 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002682 IImsServiceFeatureCallback callback) {
2683 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002684 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002685 }
2686
2687 /**
2688 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2689 * feature during emergency calling or {@link null} if the service is not available. If the
2690 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2691 * listener for feature updates.
2692 */
2693 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2694 enforceModifyPermission();
2695 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002696 }
2697
Brad Ebinger5f64b052017-12-14 14:26:15 -08002698 /**
2699 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2700 * specified.
2701 */
2702 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2703 enforceModifyPermission();
2704 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2705 }
2706
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002707 /**
2708 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2709 * specified.
2710 */
2711 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2712 enforceModifyPermission();
2713 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2714 }
2715
Brad Ebinger884c07b2018-02-15 16:17:40 -08002716 /**
Brad Ebinger304415d2018-03-02 13:43:36 -08002717 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2718 * available, false if the IMS resolver is idle.
2719 */
2720 public boolean isResolvingImsBinding() {
2721 enforceModifyPermission();
2722 return PhoneFactory.getImsResolver().isResolvingBinding();
2723 }
2724
Wink Saville36469e72014-06-11 15:17:00 -07002725 public void setImsRegistrationState(boolean registered) {
2726 enforceModifyPermission();
2727 mPhone.setImsRegistrationState(registered);
2728 }
2729
2730 /**
Stuart Scott54788802015-03-30 13:18:01 -07002731 * Set the network selection mode to automatic.
2732 *
2733 */
2734 @Override
2735 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2737 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002738 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2739 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2740 }
2741
2742 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002743 * Set the network selection mode to manual with the selected carrier.
2744 */
2745 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002746 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002747 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2749 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002750 OperatorInfo operator = new OperatorInfo(
2751 /* operatorAlphaLong */ "",
2752 /* operatorAlphaShort */ "",
2753 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002754 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002755 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2756 persistSelection);
2757 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002758 }
2759
2760 /**
2761 * Scans for available networks.
2762 */
2763 @Override
2764 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2766 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002767 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2768 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2769 CMD_PERFORM_NETWORK_SCAN, null, subId);
2770 return result;
2771 }
2772
2773 /**
yinxub1bed742017-04-17 11:45:04 -07002774 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002775 *
yinxub1bed742017-04-17 11:45:04 -07002776 * @param subId id of the subscription
2777 * @param request contains the radio access networks with bands/channels to scan
2778 * @param messenger callback messenger for scan results or errors
2779 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002780 * @return the id of the requested scan which can be used to stop the scan.
2781 */
2782 @Override
2783 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2784 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2786 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002787 return mNetworkScanRequestTracker.startNetworkScan(
2788 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002789 }
2790
2791 /**
2792 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002793 *
2794 * @param subId id of the subscription
2795 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002796 */
2797 @Override
2798 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2800 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002801 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002802 }
2803
2804 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002805 * Get the calculated preferred network type.
2806 * Used for debugging incorrect network type.
2807 *
2808 * @return the preferred network type, defined in RILConstants.java.
2809 */
2810 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002811 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002812 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002813 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002814 return RILConstants.PREFERRED_NETWORK_MODE;
2815 }
2816
Amit Mahajan43330e02014-11-18 11:54:45 -08002817 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002818 }
2819
2820 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002821 * Get the preferred network type.
2822 * Used for device configuration by some CDMA operators.
2823 *
2824 * @return the preferred network type, defined in RILConstants.java.
2825 */
2826 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002827 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2829 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002830 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002831 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002832 int networkType = (result != null ? result[0] : -1);
2833 if (DBG) log("getPreferredNetworkType: " + networkType);
2834 return networkType;
2835 }
2836
2837 /**
2838 * Set the preferred network type.
2839 * Used for device configuration by some CDMA operators.
2840 *
2841 * @param networkType the preferred network type, defined in RILConstants.java.
2842 * @return true on success; false on any failure.
2843 */
2844 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002845 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2847 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002848 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2849 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002850 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002851 if (success) {
2852 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002853 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002854 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002855 return success;
2856 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002857
2858 /**
Junda Liu475951f2014-11-07 16:45:03 -08002859 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2860 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2861 * tethering.
2862 *
2863 * @return 0: Not required. 1: required. 2: Not set.
2864 * @hide
2865 */
2866 @Override
2867 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002868 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002869 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2870 Settings.Global.TETHER_DUN_REQUIRED, 2);
2871 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2872 // config_tether_apndata.
2873 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2874 dunRequired = 1;
2875 }
2876 return dunRequired;
2877 }
2878
2879 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002880 * Set mobile data enabled
2881 * Used by the user through settings etc to turn on/off mobile data
2882 *
2883 * @param enable {@code true} turn turn data on, else {@code false}
2884 */
2885 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002886 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2888 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002889 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002890 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002891 Phone phone = PhoneFactory.getPhone(phoneId);
2892 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002893 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2894 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002895 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002896 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002897 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002898 }
2899
2900 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002901 * Get the user enabled state of Mobile Data.
2902 *
2903 * TODO: remove and use isUserDataEnabled.
2904 * This can't be removed now because some vendor codes
2905 * calls through ITelephony directly while they should
2906 * use TelephonyManager.
2907 *
2908 * @return true on enabled
2909 */
2910 @Override
2911 public boolean getDataEnabled(int subId) {
2912 return isUserDataEnabled(subId);
2913 }
2914
2915 /**
2916 * Get whether mobile data is enabled per user setting.
2917 *
2918 * There are other factors deciding whether mobile data is actually enabled, but they are
2919 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002920 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002921 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002922 *
2923 * @return {@code true} if data is enabled else {@code false}
2924 */
2925 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002926 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002927 try {
2928 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2929 null);
2930 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2932 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002933 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002934 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002935 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002936 Phone phone = PhoneFactory.getPhone(phoneId);
2937 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002938 boolean retVal = phone.isUserDataEnabled();
2939 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002940 return retVal;
2941 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002942 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2943 return false;
2944 }
2945 }
2946
2947 /**
2948 * Get whether mobile data is enabled.
2949 *
2950 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2951 * whether mobile data is actually enabled.
2952 *
2953 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2954 *
2955 * @return {@code true} if data is enabled else {@code false}
2956 */
2957 @Override
2958 public boolean isDataEnabled(int subId) {
2959 try {
2960 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2961 null);
2962 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2964 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08002965 }
2966 int phoneId = mSubscriptionController.getPhoneId(subId);
2967 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2968 Phone phone = PhoneFactory.getPhone(phoneId);
2969 if (phone != null) {
2970 boolean retVal = phone.isDataEnabled();
2971 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2972 return retVal;
2973 } else {
2974 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002975 return false;
2976 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002977 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002978
2979 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002980 public int getCarrierPrivilegeStatus(int subId) {
2981 final Phone phone = getPhone(subId);
2982 if (phone == null) {
2983 loge("getCarrierPrivilegeStatus: Invalid subId");
2984 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2985 }
2986 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002987 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002988 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002989 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2990 }
2991 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002992 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002993 }
Junda Liu29340342014-07-10 15:23:27 -07002994
2995 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08002996 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
2997 final Phone phone = getPhone(subId);
2998 if (phone == null) {
2999 loge("getCarrierPrivilegeStatus: Invalid subId");
3000 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3001 }
3002 UiccProfile profile =
3003 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3004 if (profile == null) {
3005 loge("getCarrierPrivilegeStatus: No UICC");
3006 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3007 }
3008 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3009 }
3010
3011 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003012 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003013 if (TextUtils.isEmpty(pkgName))
3014 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003015 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003016 if (card == null) {
3017 loge("checkCarrierPrivilegesForPackage: No UICC");
3018 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3019 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003020 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3021 }
3022
3023 @Override
3024 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003025 if (TextUtils.isEmpty(pkgName))
3026 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003027 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3028 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3029 UiccCard card = UiccController.getInstance().getUiccCard(i);
3030 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003031 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003032 continue;
3033 }
3034
3035 result = card.getCarrierPrivilegeStatus(
3036 mPhone.getContext().getPackageManager(), pkgName);
3037 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3038 break;
3039 }
3040 }
3041
3042 return result;
Junda Liu29340342014-07-10 15:23:27 -07003043 }
Derek Tan89e89d42014-07-08 17:00:10 -07003044
3045 @Override
Junda Liue64de782015-04-16 17:19:16 -07003046 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3047 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3048 loge("phoneId " + phoneId + " is not valid.");
3049 return null;
3050 }
3051 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003052 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003053 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003054 return null ;
3055 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003056 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003057 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003058 }
3059
Amith Yamasani6e118872016-02-19 12:53:51 -08003060 @Override
3061 public List<String> getPackagesWithCarrierPrivileges() {
3062 PackageManager pm = mPhone.getContext().getPackageManager();
3063 List<String> privilegedPackages = new ArrayList<>();
3064 List<PackageInfo> packages = null;
3065 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3066 UiccCard card = UiccController.getInstance().getUiccCard(i);
3067 if (card == null) {
3068 // No UICC in that slot.
3069 continue;
3070 }
3071 if (card.hasCarrierPrivilegeRules()) {
3072 if (packages == null) {
3073 // Only check packages in user 0 for now
3074 packages = pm.getInstalledPackagesAsUser(
3075 PackageManager.MATCH_DISABLED_COMPONENTS
3076 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3077 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3078 }
3079 for (int p = packages.size() - 1; p >= 0; p--) {
3080 PackageInfo pkgInfo = packages.get(p);
3081 if (pkgInfo != null && pkgInfo.packageName != null
3082 && card.getCarrierPrivilegeStatus(pkgInfo)
3083 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3084 privilegedPackages.add(pkgInfo.packageName);
3085 }
3086 }
3087 }
3088 }
3089 return privilegedPackages;
3090 }
3091
Wink Savilleb564aae2014-10-23 10:18:09 -07003092 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003093 final Phone phone = getPhone(subId);
3094 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003095 if (card == null) {
3096 loge("getIccId: No UICC");
3097 return null;
3098 }
3099 String iccId = card.getIccId();
3100 if (TextUtils.isEmpty(iccId)) {
3101 loge("getIccId: ICC ID is null or empty.");
3102 return null;
3103 }
3104 return iccId;
3105 }
3106
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003107 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003108 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3109 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003110 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3111 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003112
Jeff Sharkey85190e62014-12-05 09:40:12 -08003113 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003114 final Phone phone = getPhone(subId);
3115 if (phone == null) {
3116 return false;
3117 }
3118 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003119
3120 if (DBG_MERGE) {
3121 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3122 + subscriberId + " to " + number);
3123 }
3124
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003125 if (TextUtils.isEmpty(iccId)) {
3126 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003127 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003128
Jeff Sharkey85190e62014-12-05 09:40:12 -08003129 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3130
3131 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003132 if (alphaTag == null) {
3133 editor.remove(alphaTagPrefKey);
3134 } else {
3135 editor.putString(alphaTagPrefKey, alphaTag);
3136 }
3137
Jeff Sharkey85190e62014-12-05 09:40:12 -08003138 // Record both the line number and IMSI for this ICCID, since we need to
3139 // track all merged IMSIs based on line number
3140 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3141 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003142 if (number == null) {
3143 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003144 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003145 } else {
3146 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003147 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003148 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003149
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003150 editor.commit();
3151 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003152 }
3153
3154 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003155 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003156 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003157 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003158 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003159 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003160 return null;
3161 }
Derek Tan97ebb422014-09-05 16:55:38 -07003162
3163 String iccId = getIccId(subId);
3164 if (iccId != null) {
3165 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003166 if (DBG_MERGE) {
3167 log("getLine1NumberForDisplay returning " +
3168 mTelephonySharedPreferences.getString(numberPrefKey, null));
3169 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003170 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003171 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003172 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003173 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003174 }
3175
3176 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003177 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003178 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003179 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003180 return null;
3181 }
Derek Tan97ebb422014-09-05 16:55:38 -07003182
3183 String iccId = getIccId(subId);
3184 if (iccId != null) {
3185 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003186 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003187 }
Derek Tan97ebb422014-09-05 16:55:38 -07003188 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003189 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003190
3191 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003192 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003193 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3194 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003195 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003196 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3197 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003198 return null;
3199 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003200 final Context context = mPhone.getContext();
3201 final TelephonyManager tele = TelephonyManager.from(context);
3202 final SubscriptionManager sub = SubscriptionManager.from(context);
3203
3204 // Figure out what subscribers are currently active
3205 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003206 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3207 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 final int[] subIds = sub.getActiveSubscriptionIdList();
3211 for (int subId : subIds) {
3212 activeSubscriberIds.add(tele.getSubscriberId(subId));
3213 }
3214 } finally {
3215 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003216 }
3217
3218 // First pass, find a number override for an active subscriber
3219 String mergeNumber = null;
3220 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3221 for (String key : prefs.keySet()) {
3222 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3223 final String subscriberId = (String) prefs.get(key);
3224 if (activeSubscriberIds.contains(subscriberId)) {
3225 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3226 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3227 mergeNumber = (String) prefs.get(numberKey);
3228 if (DBG_MERGE) {
3229 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3230 + " for active subscriber " + subscriberId);
3231 }
3232 if (!TextUtils.isEmpty(mergeNumber)) {
3233 break;
3234 }
3235 }
3236 }
3237 }
3238
3239 // Shortcut when no active merged subscribers
3240 if (TextUtils.isEmpty(mergeNumber)) {
3241 return null;
3242 }
3243
3244 // Second pass, find all subscribers under that line override
3245 final ArraySet<String> result = new ArraySet<>();
3246 for (String key : prefs.keySet()) {
3247 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3248 final String number = (String) prefs.get(key);
3249 if (mergeNumber.equals(number)) {
3250 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3251 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3252 final String subscriberId = (String) prefs.get(subscriberKey);
3253 if (!TextUtils.isEmpty(subscriberId)) {
3254 result.add(subscriberId);
3255 }
3256 }
3257 }
3258 }
3259
3260 final String[] resultArray = result.toArray(new String[result.size()]);
3261 Arrays.sort(resultArray);
3262 if (DBG_MERGE) {
3263 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3264 }
3265 return resultArray;
3266 }
3267
3268 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003269 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003270 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3271 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003272 final Phone phone = getPhone(subId);
3273 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003274 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003275
3276 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003277 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003278 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3279 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003280 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003281 final Phone phone = getPhone(subId);
3282 if (phone == null) {
3283 return false;
3284 }
3285 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003286 cdmaNonRoamingList);
3287 }
3288
3289 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003290 public void setRadioCapability(RadioAccessFamily[] rafs) {
3291 try {
3292 ProxyController.getInstance().setRadioCapability(rafs);
3293 } catch (RuntimeException e) {
3294 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3295 }
3296 }
3297
3298 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003299 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003300 Phone phone = PhoneFactory.getPhone(phoneId);
3301 if (phone == null) {
3302 return RadioAccessFamily.RAF_UNKNOWN;
3303 }
3304 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003306 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003307 return RadioAccessFamily.RAF_UNKNOWN;
3308 }
3309
Wink Saville5d475dd2014-10-17 15:00:58 -07003310 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3311 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003312
3313 @Override
3314 public void enableVideoCalling(boolean enable) {
3315 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003316 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003317 }
3318
3319 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003320 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3322 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3323 return false;
3324 }
Svet Ganovb320e182015-04-16 12:30:10 -07003325
Andrew Lee77527ac2014-10-21 16:57:39 -07003326 // Check the user preference and the system-level IMS setting. Even if the user has
3327 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3328 // In the long run, we may instead need to check if there exists a connection service
3329 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003330 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3331 return imsManager.isVtEnabledByPlatform()
3332 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3333 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003334 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003335
Andrew Leea1239f22015-03-02 17:44:07 -08003336 @Override
3337 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003338 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003339 }
3340
3341 @Override
3342 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003343 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003344 }
3345
Andrew Lee9431b832015-03-09 18:46:45 -07003346 @Override
3347 public boolean isTtyModeSupported() {
3348 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3349 TelephonyManager telephonyManager =
3350 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003351 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003352 }
3353
3354 @Override
3355 public boolean isHearingAidCompatibilitySupported() {
3356 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3357 }
3358
Hall Liu98187582018-01-22 19:15:32 -08003359 public boolean isRttSupported() {
3360 boolean isCarrierSupported =
3361 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3362 boolean isDeviceSupported =
3363 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3364 return isCarrierSupported && isDeviceSupported;
3365 }
3366
Sanket Padawe7310cc72015-01-14 09:53:20 -08003367 /**
3368 * Returns the unique device ID of phone, for example, the IMEI for
3369 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3370 *
3371 * <p>Requires Permission:
3372 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3373 */
3374 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003375 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003376 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08003377 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003378 return null;
3379 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003380 int subId = phone.getSubId();
3381 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3382 mApp, subId, callingPackage, "getDeviceId")) {
3383 return null;
3384 }
3385 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003386 }
3387
Ping Sunc67b7c22016-03-02 19:16:45 +08003388 /**
3389 * {@hide}
3390 * Returns the IMS Registration Status on a particular subid
3391 *
3392 * @param subId
3393 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003394 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003395 Phone phone = getPhone(subId);
3396 if (phone != null) {
3397 return phone.isImsRegistered();
3398 } else {
3399 return false;
3400 }
3401 }
3402
Santos Cordon7a1885b2015-02-03 11:15:19 -08003403 @Override
3404 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3405 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3406 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003407
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003408 /**
3409 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003410 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003411 public boolean isWifiCallingAvailable(int subId) {
3412 Phone phone = getPhone(subId);
3413 if (phone != null) {
3414 return phone.isWifiCallingEnabled();
3415 } else {
3416 return false;
3417 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003418 }
3419
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003420 /**
3421 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003422 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003423 public boolean isVolteAvailable(int subId) {
3424 Phone phone = getPhone(subId);
3425 if (phone != null) {
3426 return phone.isVolteEnabled();
3427 } else {
3428 return false;
3429 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003430 }
Svet Ganovb320e182015-04-16 12:30:10 -07003431
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003432 /**
3433 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003434 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003435 public boolean isVideoTelephonyAvailable(int subId) {
3436 Phone phone = getPhone(subId);
3437 if (phone != null) {
3438 return phone.isVideoEnabled();
3439 } else {
3440 return false;
3441 }
3442 }
3443
3444 /**
3445 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3446 * defined in {@link ImsRegistrationImplBase}.
3447 */
3448 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3449 Phone phone = getPhone(subId);
3450 if (phone != null) {
3451 return phone.getImsRegistrationTech();
3452 } else {
3453 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3454 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003455 }
3456
Stuart Scott8eef64f2015-04-08 15:13:54 -07003457 @Override
3458 public void factoryReset(int subId) {
3459 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003460 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3461 return;
3462 }
3463
Svet Ganovcc087f82015-05-12 20:35:54 -07003464 final long identity = Binder.clearCallingIdentity();
3465 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003466 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3467 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07003468 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07003469 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07003470 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
3471 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07003472 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003473 }
3474 } finally {
3475 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003476 }
3477 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003478
3479 @Override
3480 public String getLocaleFromDefaultSim() {
3481 // We query all subscriptions instead of just the active ones, because
3482 // this might be called early on in the provisioning flow when the
3483 // subscriptions potentially aren't active yet.
3484 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3485 if (slist == null || slist.isEmpty()) {
3486 return null;
3487 }
3488
3489 // This function may be called very early, say, from the setup wizard, at
3490 // which point we won't have a default subscription set. If that's the case
3491 // we just choose the first, which will be valid in "most cases".
3492 final int defaultSubId = getDefaultSubscription();
3493 SubscriptionInfo info = null;
3494 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3495 info = slist.get(0);
3496 } else {
3497 for (SubscriptionInfo item : slist) {
3498 if (item.getSubscriptionId() == defaultSubId) {
3499 info = item;
3500 break;
3501 }
3502 }
3503
3504 if (info == null) {
3505 return null;
3506 }
3507 }
3508
3509 // Try and fetch the locale from the carrier properties or from the SIM language
3510 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003511 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003512 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003513 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003514 if (defaultPhone != null) {
3515 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3516 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003517 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003518 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3519 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003520 } else {
3521 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003522 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003523 }
3524 }
3525
Narayan Kamath011676f2015-07-29 12:04:08 +01003526 // The SIM language preferences only store a language (e.g. fr = French), not an
3527 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3528 // the SIM and carrier preferences does not include a country we add the country
3529 // determined from the SIM MCC to provide an exact locale.
3530 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003531 if (mccLocale != null) {
3532 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3533 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003534 }
3535
Tony Hill183b2de2015-06-24 14:53:58 +01003536 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003537 return null;
3538 }
3539
3540 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3541 final long identity = Binder.clearCallingIdentity();
3542 try {
3543 return mSubscriptionController.getAllSubInfoList(
3544 mPhone.getContext().getOpPackageName());
3545 } finally {
3546 Binder.restoreCallingIdentity(identity);
3547 }
3548 }
3549
3550 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 return mSubscriptionController.getActiveSubscriptionInfoList(
3554 mPhone.getContext().getOpPackageName());
3555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
3558 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003559
Chenjie Yu1ba97252018-01-11 18:16:20 -08003560 private final ModemActivityInfo mLastModemActivityInfo =
3561 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3562
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003563 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003564 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3565 * representing the state of the modem.
3566 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003567 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3568 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003569 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003570 */
3571 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003572 public void requestModemActivityInfo(ResultReceiver result) {
3573 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003574 ModemActivityInfo ret = null;
3575 synchronized (mLastModemActivityInfo) {
3576 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3577 null);
3578 if (info != null) {
3579 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3580 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3581 mergedTxTimeMs[i] =
3582 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3583 }
3584 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3585 mLastModemActivityInfo.setSleepTimeMillis(
3586 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3587 mLastModemActivityInfo.setIdleTimeMillis(
3588 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3589 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3590 mLastModemActivityInfo.setRxTimeMillis(
3591 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3592 mLastModemActivityInfo.setEnergyUsed(
3593 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3594 }
3595 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3596 mLastModemActivityInfo.getSleepTimeMillis(),
3597 mLastModemActivityInfo.getIdleTimeMillis(),
3598 mLastModemActivityInfo.getTxTimeMillis(),
3599 mLastModemActivityInfo.getRxTimeMillis(),
3600 mLastModemActivityInfo.getEnergyUsed());
3601 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003602 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003603 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003604 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003605 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003606
3607 /**
3608 * {@hide}
3609 * Returns the service state information on specified subscription.
3610 */
3611 @Override
3612 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3613
Jeff Davidson7e17e312018-02-13 18:17:36 -08003614 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003615 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003616 return null;
3617 }
3618
3619 final Phone phone = getPhone(subId);
3620 if (phone == null) {
3621 return null;
3622 }
3623
3624 return phone.getServiceState();
3625 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003626
3627 /**
3628 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3629 *
3630 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3631 * voicemail ringtone.
3632 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3633 * PhoneAccount.
3634 */
3635 @Override
3636 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003637 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003638 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003639 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003640 }
3641
fionaxu7ed723d2017-05-30 18:58:54 -07003642 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003643 }
3644
3645 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003646 * Sets the per-account voicemail ringtone.
3647 *
3648 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3649 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3650 *
3651 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3652 * voicemail ringtone.
3653 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3654 * PhoneAccount.
3655 */
3656 @Override
3657 public void setVoicemailRingtoneUri(String callingPackage,
3658 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3659 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3660 if (!TextUtils.equals(callingPackage,
3661 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3663 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3664 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003665 }
3666 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3667 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003668 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003669 }
fionaxu7ed723d2017-05-30 18:58:54 -07003670 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003671 }
3672
3673 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003674 * Returns whether vibration is set for voicemail notification in Phone settings.
3675 *
3676 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3677 * voicemail vibration setting.
3678 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3679 */
3680 @Override
3681 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003682 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003683 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003684 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003685 }
3686
fionaxu7ed723d2017-05-30 18:58:54 -07003687 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003688 }
3689
Youhan Wange64578a2016-05-02 15:32:42 -07003690 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003691 * Sets the per-account voicemail vibration.
3692 *
3693 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3694 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3695 *
3696 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3697 * voicemail vibration setting.
3698 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3699 * specific PhoneAccount.
3700 */
3701 @Override
3702 public void setVoicemailVibrationEnabled(String callingPackage,
3703 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3704 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3705 if (!TextUtils.equals(callingPackage,
3706 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3708 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3709 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003710 }
3711
3712 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3713 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003714 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003715 }
fionaxu7ed723d2017-05-30 18:58:54 -07003716 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003717 }
3718
3719 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003720 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3721 *
3722 * @throws SecurityException if the caller does not have the required permission
3723 */
3724 private void enforceReadPrivilegedPermission() {
3725 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3726 null);
3727 }
3728
3729 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003730 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3731 * permission.
3732 *
3733 * @throws SecurityException if the caller does not have the required permission
3734 */
3735 private void enforceSendSmsPermission() {
3736 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3737 }
3738
3739 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003740 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003741 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003742 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003743 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003744 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003745 ComponentName componentName =
3746 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3747 if(componentName == null) {
3748 throw new SecurityException("Caller not current active visual voicemail package[null]");
3749 }
3750 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003751 if (!callingPackage.equals(vvmPackage)) {
3752 throw new SecurityException("Caller not current active visual voicemail package[" +
3753 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003754 }
3755 }
3756
3757 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003758 * Return the application ID for the app type.
3759 *
3760 * @param subId the subscription ID that this request applies to.
3761 * @param appType the uicc app type.
3762 * @return Application ID for specificied app type, or null if no uicc.
3763 */
3764 @Override
3765 public String getAidForAppType(int subId, int appType) {
3766 enforceReadPrivilegedPermission();
3767 Phone phone = getPhone(subId);
3768 if (phone == null) {
3769 return null;
3770 }
3771 String aid = null;
3772 try {
3773 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3774 .getApplicationByType(appType).getAid();
3775 } catch (Exception e) {
3776 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3777 }
3778 return aid;
3779 }
3780
Youhan Wang4001d252016-05-11 10:29:41 -07003781 /**
3782 * Return the Electronic Serial Number.
3783 *
3784 * @param subId the subscription ID that this request applies to.
3785 * @return ESN or null if error.
3786 */
3787 @Override
3788 public String getEsn(int subId) {
3789 enforceReadPrivilegedPermission();
3790 Phone phone = getPhone(subId);
3791 if (phone == null) {
3792 return null;
3793 }
3794 String esn = null;
3795 try {
3796 esn = phone.getEsn();
3797 } catch (Exception e) {
3798 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3799 }
3800 return esn;
3801 }
3802
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003803 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003804 * Return the Preferred Roaming List Version.
3805 *
3806 * @param subId the subscription ID that this request applies to.
3807 * @return PRLVersion or null if error.
3808 */
3809 @Override
3810 public String getCdmaPrlVersion(int subId) {
3811 enforceReadPrivilegedPermission();
3812 Phone phone = getPhone(subId);
3813 if (phone == null) {
3814 return null;
3815 }
3816 String cdmaPrlVersion = null;
3817 try {
3818 cdmaPrlVersion = phone.getCdmaPrlVersion();
3819 } catch (Exception e) {
3820 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3821 }
3822 return cdmaPrlVersion;
3823 }
3824
3825 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003826 * Get snapshot of Telephony histograms
3827 * @return List of Telephony histograms
3828 * @hide
3829 */
3830 @Override
3831 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3833 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003834 return RIL.getTelephonyRILTimingHistograms();
3835 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003836
3837 /**
3838 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003839 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003840 * Require system privileges. In the future we may add this to carrier APIs.
3841 *
3842 * @return The number of carriers set successfully, should match length of carriers
3843 */
3844 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003845 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003846 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003847
Meng Wang9b7c4e92017-02-17 11:41:27 -08003848 if (carriers == null) {
3849 throw new NullPointerException("carriers cannot be null");
3850 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003851
3852 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003853 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3854 return retVal[0];
3855 }
3856
3857 /**
3858 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003859 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003860 * Require system privileges. In the future we may add this to carrier APIs.
3861 *
3862 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3863 * means all carriers are allowed.
3864 */
3865 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003866 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003867 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003868 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003869 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3870 }
3871
fionaxu59545b42016-05-25 15:53:37 -07003872 /**
3873 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3874 * @param subId the subscription ID that this action applies to.
3875 * @param enabled control enable or disable metered apns.
3876 * {@hide}
3877 */
3878 @Override
3879 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3880 enforceModifyPermission();
3881 final Phone phone = getPhone(subId);
3882 if (phone == null) {
3883 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3884 return;
3885 }
3886 try {
3887 phone.carrierActionSetMeteredApnsEnabled(enabled);
3888 } catch (Exception e) {
3889 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3890 }
3891 }
3892
3893 /**
3894 * Action set from carrier signalling broadcast receivers to enable/disable radio
3895 * @param subId the subscription ID that this action applies to.
3896 * @param enabled control enable or disable radio.
3897 * {@hide}
3898 */
3899 @Override
3900 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3901 enforceModifyPermission();
3902 final Phone phone = getPhone(subId);
3903 if (phone == null) {
3904 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3905 return;
3906 }
3907 try {
3908 phone.carrierActionSetRadioEnabled(enabled);
3909 } catch (Exception e) {
3910 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3911 }
3912 }
3913
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003914 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003915 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3916 * network status based on which carrier apps could apply actions accordingly,
3917 * enable/disable default url handler for example.
3918 *
3919 * @param subId the subscription ID that this action applies to.
3920 * @param report control start/stop reporting the default network status.
3921 * {@hide}
3922 */
3923 @Override
3924 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3925 enforceModifyPermission();
3926 final Phone phone = getPhone(subId);
3927 if (phone == null) {
3928 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3929 return;
3930 }
3931 try {
3932 phone.carrierActionReportDefaultNetworkStatus(report);
3933 } catch (Exception e) {
3934 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3935 }
3936 }
3937
3938 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003939 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3940 * bug report is being generated.
3941 */
3942 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003943 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003944 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3945 != PackageManager.PERMISSION_GRANTED) {
3946 writer.println("Permission Denial: can't dump Phone from pid="
3947 + Binder.getCallingPid()
3948 + ", uid=" + Binder.getCallingUid()
3949 + "without permission "
3950 + android.Manifest.permission.DUMP);
3951 return;
3952 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003953 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003954 }
Jack Yueb89b242016-06-22 13:27:47 -07003955
3956 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003957 * Get aggregated video call data usage since boot.
3958 *
3959 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3960 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003961 * {@hide}
3962 */
3963 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003964 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003965 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3966 null);
3967
Jack Yu84291ec2017-05-26 16:07:50 -07003968 // NetworkStatsService keeps tracking the active network interface and identity. It
3969 // records the delta with the corresponding network identity. We just return the total video
3970 // call data usage snapshot since boot.
3971 Phone phone = getPhone(subId);
3972 if (phone != null) {
3973 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003974 }
Jack Yu84291ec2017-05-26 16:07:50 -07003975 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003976 }
Jack Yu75ab2952016-07-08 14:29:33 -07003977
3978 /**
3979 * Policy control of data connection. Usually used when data limit is passed.
3980 * @param enabled True if enabling the data, otherwise disabling.
3981 * @param subId Subscription index
3982 * {@hide}
3983 */
3984 @Override
3985 public void setPolicyDataEnabled(boolean enabled, int subId) {
3986 enforceModifyPermission();
3987 Phone phone = getPhone(subId);
3988 if (phone != null) {
3989 phone.setPolicyDataEnabled(enabled);
3990 }
3991 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003992
3993 /**
3994 * Get Client request stats
3995 * @return List of Client Request Stats
3996 * @hide
3997 */
3998 @Override
3999 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004000 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004001 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004002 return null;
4003 }
4004
4005 Phone phone = getPhone(subId);
4006 if (phone != null) {
4007 return phone.getClientRequestStats();
4008 }
4009
4010 return null;
4011 }
4012
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004013 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004014 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004015 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004016 }
Jack Yueb4124c2017-02-16 15:32:43 -08004017
4018 /**
Grace Chen70990072017-03-24 17:21:30 -07004019 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004020 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004021 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004022 * @param state State of SIM (power down, power up, pass through)
4023 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4024 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4025 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004026 *
4027 **/
4028 @Override
Grace Chen70990072017-03-24 17:21:30 -07004029 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004030 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004031 Phone phone = PhoneFactory.getPhone(slotIndex);
4032
Jack Yueb4124c2017-02-16 15:32:43 -08004033 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004034 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004035 }
4036 }
Shuo Qiandd210312017-04-12 22:11:33 +00004037
Tyler Gunn65d45c22017-06-05 11:22:26 -07004038 private boolean isUssdApiAllowed(int subId) {
4039 CarrierConfigManager configManager =
4040 (CarrierConfigManager) mPhone.getContext().getSystemService(
4041 Context.CARRIER_CONFIG_SERVICE);
4042 if (configManager == null) {
4043 return false;
4044 }
4045 PersistableBundle pb = configManager.getConfigForSubId(subId);
4046 if (pb == null) {
4047 return false;
4048 }
4049 return pb.getBoolean(
4050 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4051 }
4052
Shuo Qiandd210312017-04-12 22:11:33 +00004053 /**
4054 * Check if phone is in emergency callback mode
4055 * @return true if phone is in emergency callback mode
4056 * @param subId sub id
4057 */
goneil9c5f4872017-12-05 14:07:56 -08004058 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004059 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004060 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004061 final Phone phone = getPhone(subId);
4062 if (phone != null) {
4063 return phone.isInEcm();
4064 } else {
4065 return false;
4066 }
4067 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004068
4069 /**
4070 * Get the current signal strength information for the given subscription.
4071 * Because this information is not updated when the device is in a low power state
4072 * it should not be relied-upon to be current.
4073 * @param subId Subscription index
4074 * @return the most recent cached signal strength info from the modem
4075 */
4076 @Override
4077 public SignalStrength getSignalStrength(int subId) {
4078 Phone p = getPhone(subId);
4079 if (p == null) {
4080 return null;
4081 }
4082
4083 return p.getSignalStrength();
4084 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004085
4086 @Override
4087 public UiccSlotInfo[] getUiccSlotsInfo() {
4088 enforceReadPrivilegedPermission();
4089
4090 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004091 if (slots == null) {
4092 Rlog.i(LOG_TAG, "slots is null.");
4093 return null;
4094 }
4095
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004096 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4097 for (int i = 0; i < slots.length; i++) {
4098 UiccSlot slot = slots[i];
4099
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07004100 String cardId = null;
4101 UiccCard card = slot.getUiccCard();
4102 if (card != null) {
4103 cardId = card.getCardId();
4104 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004105
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 }
fionaxua13278b2018-03-21 00:08:13 -07004188
4189 @Override
4190 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
4191 gid1, String gid2, String plmn, String spn) {
4192 enforceModifyPermission();
4193 final Phone phone = getPhone(subId);
4194 if (phone == null) {
4195 loge("setCarrierTestOverride fails with invalid subId: " + subId);
4196 return;
4197 }
4198 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
4199 }
4200
4201 @Override
4202 public int getCarrierIdListVersion(int subId) {
4203 enforceReadPrivilegedPermission();
4204 final Phone phone = getPhone(subId);
4205 if (phone == null) {
4206 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
4207 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
4208 }
4209 return phone.getCarrierIdListVersion();
4210 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004211}