blob: beae63abcd023e8e501d6131c89e988bcee0a599 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
Pengquan Meng85728fb2018-03-12 16:31:21 -070045import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070047import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070048import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070049import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080050import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070051import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080052import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080053import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070054import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070055import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070058import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080059import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070060import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080061import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070062import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070063import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070064import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080066import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070067import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080068import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080069import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070070import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070071import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000072import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070074import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080075import android.telephony.ims.aidl.IImsConfig;
76import android.telephony.ims.aidl.IImsMmTelFeature;
77import android.telephony.ims.aidl.IImsRcsFeature;
78import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080079import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080081import android.util.ArraySet;
Tyler Gunn67073572018-02-14 14:19:42 -080082import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080084import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080085import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080086
Andrew Lee312e8172014-10-23 17:01:36 -070087import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080088import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070089import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070090import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070091import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070092import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070093import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070095import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080096import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010097import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070098import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070099import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700100import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -0800101import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700102import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700103import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700104import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700105import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700106import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800107import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800108import com.android.internal.telephony.TelephonyPermissions;
Jonathan Basseribf5362b2017-07-19 12:22:35 -0700109import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700110import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700111import com.android.internal.telephony.uicc.IccIoResult;
112import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800113import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700114import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800115import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800117import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000118import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700119import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800120import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700121import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800122import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700123import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700124import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800125
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700126import java.io.FileDescriptor;
127import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800128import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800130import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800131import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100132import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800133import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134
135/**
136 * Implementation of the ITelephony interface.
137 */
Santos Cordon117fee72014-05-16 17:56:12 -0700138public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139 private static final String LOG_TAG = "PhoneInterfaceManager";
140 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
141 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800142 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143
144 // Message codes used with mMainThreadHandler
145 private static final int CMD_HANDLE_PIN_MMI = 1;
146 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
147 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
148 private static final int CMD_ANSWER_RINGING_CALL = 4;
149 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700150 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
151 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700152 private static final int CMD_OPEN_CHANNEL = 9;
153 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
154 private static final int CMD_CLOSE_CHANNEL = 11;
155 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800156 private static final int CMD_NV_READ_ITEM = 13;
157 private static final int EVENT_NV_READ_ITEM_DONE = 14;
158 private static final int CMD_NV_WRITE_ITEM = 15;
159 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
160 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
161 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
162 private static final int CMD_NV_RESET_CONFIG = 19;
163 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800164 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
165 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
166 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
167 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800168 private static final int CMD_SEND_ENVELOPE = 25;
169 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700170 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
171 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
172 private static final int CMD_EXCHANGE_SIM_IO = 31;
173 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800174 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
175 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700176 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
177 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700178 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
179 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700180 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
181 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
182 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
183 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700184 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
185 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
186 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
187 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700188 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800189 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
190 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000191 private static final int CMD_SWITCH_SLOTS = 50;
192 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800194 // Parameters of select command.
195 private static final int SELECT_COMMAND = 0xA4;
196 private static final int SELECT_P1 = 0x04;
197 private static final int SELECT_P2 = 0;
198 private static final int SELECT_P3 = 0x10;
199
Pengquan Meng85728fb2018-03-12 16:31:21 -0700200 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
201 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
202 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
203
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204 /** The singleton instance. */
205 private static PhoneInterfaceManager sInstance;
206
Wink Saville3ab207e2014-11-20 13:07:20 -0800207 private PhoneGlobals mApp;
208 private Phone mPhone;
209 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700210 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800211 private AppOpsManager mAppOps;
212 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800213 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800214 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700215
Derek Tan97ebb422014-09-05 16:55:38 -0700216 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
217 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800218 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700219
Derek Tan740e1672017-06-27 14:56:27 -0700220 // The AID of ISD-R.
221 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
222
yinxub1bed742017-04-17 11:45:04 -0700223 private NetworkScanRequestTracker mNetworkScanRequestTracker;
224
Derek Tan89e89d42014-07-08 17:00:10 -0700225 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700226 * A request object to use for transmitting data to an ICC.
227 */
228 private static final class IccAPDUArgument {
229 public int channel, cla, command, p1, p2, p3;
230 public String data;
231
232 public IccAPDUArgument(int channel, int cla, int command,
233 int p1, int p2, int p3, String data) {
234 this.channel = channel;
235 this.cla = cla;
236 this.command = command;
237 this.p1 = p1;
238 this.p2 = p2;
239 this.p3 = p3;
240 this.data = data;
241 }
242 }
243
244 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700245 * A request object to use for transmitting data to an ICC.
246 */
247 private static final class ManualNetworkSelectionArgument {
248 public OperatorInfo operatorInfo;
249 public boolean persistSelection;
250
251 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
252 this.operatorInfo = operatorInfo;
253 this.persistSelection = persistSelection;
254 }
255 }
256
257 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
259 * request after sending. The main thread will notify the request when it is complete.
260 */
261 private static final class MainThreadRequest {
262 /** The argument to use for the request */
263 public Object argument;
264 /** The result of the request that is run on the main thread */
265 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800266 // The subscriber id that this request applies to. Defaults to
267 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
268 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269
270 public MainThreadRequest(Object argument) {
271 this.argument = argument;
272 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800273
274 public MainThreadRequest(Object argument, Integer subId) {
275 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800276 if (subId != null) {
277 this.subId = subId;
278 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280 }
281
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800282 private static final class IncomingThirdPartyCallArgs {
283 public final ComponentName component;
284 public final String callId;
285 public final String callerDisplayName;
286
287 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
288 String callerDisplayName) {
289 this.component = component;
290 this.callId = callId;
291 this.callerDisplayName = callerDisplayName;
292 }
293 }
294
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 /**
296 * A handler that processes messages on the main thread in the phone process. Since many
297 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
298 * inbound binder threads to the main thread in the phone process. The Binder thread
299 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
300 * on, which will be notified when the operation completes and will contain the result of the
301 * request.
302 *
303 * <p>If a MainThreadRequest object is provided in the msg.obj field,
304 * note that request.result must be set to something non-null for the calling thread to
305 * unblock.
306 */
307 private final class MainThreadHandler extends Handler {
308 @Override
309 public void handleMessage(Message msg) {
310 MainThreadRequest request;
311 Message onCompleted;
312 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800313 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700314 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315
316 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700317 case CMD_HANDLE_USSD_REQUEST: {
318 request = (MainThreadRequest) msg.obj;
319 final Phone phone = getPhoneFromRequest(request);
320 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
321 String ussdRequest = ussdObject.first;
322 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700323
324 if (!isUssdApiAllowed(request.subId)) {
325 // Carrier does not support use of this API, return failure.
326 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
327 UssdResponse response = new UssdResponse(ussdRequest, null);
328 Bundle returnData = new Bundle();
329 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
330 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
331
332 request.result = true;
333 synchronized (request) {
334 request.notifyAll();
335 }
336 return;
337 }
338
Tyler Gunn52dcf772017-04-26 11:30:31 -0700339 try {
340 request.result = phone != null ?
341 phone.handleUssdRequest(ussdRequest, wrappedCallback)
342 : false;
343 } catch (CallStateException cse) {
344 request.result = false;
345 }
pkanwar32d516d2016-10-14 19:37:38 -0700346 // Wake up the requesting thread
347 synchronized (request) {
348 request.notifyAll();
349 }
350 break;
351 }
352
Yorke Lee716f67e2015-06-17 15:39:16 -0700353 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700355 final Phone phone = getPhoneFromRequest(request);
356 request.result = phone != null ?
357 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
358 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 // Wake up the requesting thread
360 synchronized (request) {
361 request.notifyAll();
362 }
363 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700364 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365
366 case CMD_HANDLE_NEIGHBORING_CELL:
367 request = (MainThreadRequest) msg.obj;
368 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
369 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700370 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 break;
372
373 case EVENT_NEIGHBORING_CELL_DONE:
374 ar = (AsyncResult) msg.obj;
375 request = (MainThreadRequest) ar.userObj;
376 if (ar.exception == null && ar.result != null) {
377 request.result = ar.result;
378 } else {
379 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800380 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 }
382 // Wake up the requesting thread
383 synchronized (request) {
384 request.notifyAll();
385 }
386 break;
387
388 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700389 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800390 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700391 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700392 break;
393
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 case CMD_END_CALL:
395 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800396 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700397 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700398 Phone phone = getPhone(end_subId);
399 if (phone == null) {
400 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
401 break;
402 }
403 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
405 // CDMA: If the user presses the Power button we treat it as
406 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700407 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700408 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
409 // GSM: End the call as per the Phone state
410 hungUp = PhoneUtils.hangup(mCM);
411 } else {
412 throw new IllegalStateException("Unexpected phone type: " + phoneType);
413 }
414 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
415 request.result = hungUp;
416 // Wake up the requesting thread
417 synchronized (request) {
418 request.notifyAll();
419 }
420 break;
421
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700422 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700423 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700424 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800425 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700426 if (uiccCard == null) {
427 loge("iccTransmitApduLogicalChannel: No UICC");
428 request.result = new IccIoResult(0x6F, 0, (byte[])null);
429 synchronized (request) {
430 request.notifyAll();
431 }
432 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700433 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
434 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700435 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700436 iccArgument.channel, iccArgument.cla, iccArgument.command,
437 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700439 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700440 break;
441
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 ar = (AsyncResult) msg.obj;
444 request = (MainThreadRequest) ar.userObj;
445 if (ar.exception == null && ar.result != null) {
446 request.result = ar.result;
447 } else {
448 request.result = new IccIoResult(0x6F, 0, (byte[])null);
449 if (ar.result == null) {
450 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800451 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800453 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 } else {
455 loge("iccTransmitApduLogicalChannel: Unknown exception");
456 }
457 }
458 synchronized (request) {
459 request.notifyAll();
460 }
461 break;
462
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
464 request = (MainThreadRequest) msg.obj;
465 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800466 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 if (uiccCard == null) {
468 loge("iccTransmitApduBasicChannel: No UICC");
469 request.result = new IccIoResult(0x6F, 0, (byte[])null);
470 synchronized (request) {
471 request.notifyAll();
472 }
473 } else {
474 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
475 request);
476 uiccCard.iccTransmitApduBasicChannel(
477 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
478 iccArgument.p3, iccArgument.data, onCompleted);
479 }
480 break;
481
482 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
483 ar = (AsyncResult) msg.obj;
484 request = (MainThreadRequest) ar.userObj;
485 if (ar.exception == null && ar.result != null) {
486 request.result = ar.result;
487 } else {
488 request.result = new IccIoResult(0x6F, 0, (byte[])null);
489 if (ar.result == null) {
490 loge("iccTransmitApduBasicChannel: Empty response");
491 } else if (ar.exception instanceof CommandException) {
492 loge("iccTransmitApduBasicChannel: CommandException: " +
493 ar.exception);
494 } else {
495 loge("iccTransmitApduBasicChannel: Unknown exception");
496 }
497 }
498 synchronized (request) {
499 request.notifyAll();
500 }
501 break;
502
503 case CMD_EXCHANGE_SIM_IO:
504 request = (MainThreadRequest) msg.obj;
505 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800506 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 if (uiccCard == null) {
508 loge("iccExchangeSimIO: No UICC");
509 request.result = new IccIoResult(0x6F, 0, (byte[])null);
510 synchronized (request) {
511 request.notifyAll();
512 }
513 } else {
514 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
515 request);
516 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
517 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
518 iccArgument.data, onCompleted);
519 }
520 break;
521
522 case EVENT_EXCHANGE_SIM_IO_DONE:
523 ar = (AsyncResult) msg.obj;
524 request = (MainThreadRequest) ar.userObj;
525 if (ar.exception == null && ar.result != null) {
526 request.result = ar.result;
527 } else {
528 request.result = new IccIoResult(0x6f, 0, (byte[])null);
529 }
530 synchronized (request) {
531 request.notifyAll();
532 }
533 break;
534
Derek Tan4d5e5c12014-02-04 11:54:58 -0800535 case CMD_SEND_ENVELOPE:
536 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800537 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700538 if (uiccCard == null) {
539 loge("sendEnvelopeWithStatus: No UICC");
540 request.result = new IccIoResult(0x6F, 0, (byte[])null);
541 synchronized (request) {
542 request.notifyAll();
543 }
544 } else {
545 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
546 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
547 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800548 break;
549
550 case EVENT_SEND_ENVELOPE_DONE:
551 ar = (AsyncResult) msg.obj;
552 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700553 if (ar.exception == null && ar.result != null) {
554 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800555 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700556 request.result = new IccIoResult(0x6F, 0, (byte[])null);
557 if (ar.result == null) {
558 loge("sendEnvelopeWithStatus: Empty response");
559 } else if (ar.exception instanceof CommandException) {
560 loge("sendEnvelopeWithStatus: CommandException: " +
561 ar.exception);
562 } else {
563 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
564 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 }
566 synchronized (request) {
567 request.notifyAll();
568 }
569 break;
570
Shishir Agrawal566b7612013-10-28 14:41:00 -0700571 case CMD_OPEN_CHANNEL:
572 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800573 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800574 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700575 if (uiccCard == null) {
576 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800577 request.result = new IccOpenLogicalChannelResponse(-1,
578 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 synchronized (request) {
580 request.notifyAll();
581 }
582 } else {
583 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800584 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
585 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700586 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 break;
588
589 case EVENT_OPEN_CHANNEL_DONE:
590 ar = (AsyncResult) msg.obj;
591 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 int[] result = (int[]) ar.result;
595 int channelId = result[0];
596 byte[] selectResponse = null;
597 if (result.length > 1) {
598 selectResponse = new byte[result.length - 1];
599 for (int i = 1; i < result.length; ++i) {
600 selectResponse[i - 1] = (byte) result[i];
601 }
602 }
603 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700604 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 if (ar.result == null) {
607 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700609 if (ar.exception != null) {
610 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
611 }
612
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700614 if (ar.exception instanceof CommandException) {
615 CommandException.Error error =
616 ((CommandException) (ar.exception)).getCommandError();
617 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700618 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700619 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700620 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700621 }
622 }
623 openChannelResp = new IccOpenLogicalChannelResponse(
624 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700626 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 synchronized (request) {
628 request.notifyAll();
629 }
630 break;
631
632 case CMD_CLOSE_CHANNEL:
633 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800634 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 if (uiccCard == null) {
636 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900637 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700638 synchronized (request) {
639 request.notifyAll();
640 }
641 } else {
642 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
643 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
644 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700645 break;
646
647 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800648 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
649 break;
650
651 case CMD_NV_READ_ITEM:
652 request = (MainThreadRequest) msg.obj;
653 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
654 mPhone.nvReadItem((Integer) request.argument, onCompleted);
655 break;
656
657 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 ar = (AsyncResult) msg.obj;
659 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800660 if (ar.exception == null && ar.result != null) {
661 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800663 request.result = "";
664 if (ar.result == null) {
665 loge("nvReadItem: Empty response");
666 } else if (ar.exception instanceof CommandException) {
667 loge("nvReadItem: CommandException: " +
668 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800670 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 }
672 }
673 synchronized (request) {
674 request.notifyAll();
675 }
676 break;
677
Jake Hambye994d462014-02-03 13:10:13 -0800678 case CMD_NV_WRITE_ITEM:
679 request = (MainThreadRequest) msg.obj;
680 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
681 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
682 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
683 break;
684
685 case EVENT_NV_WRITE_ITEM_DONE:
686 handleNullReturnEvent(msg, "nvWriteItem");
687 break;
688
689 case CMD_NV_WRITE_CDMA_PRL:
690 request = (MainThreadRequest) msg.obj;
691 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
692 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
693 break;
694
695 case EVENT_NV_WRITE_CDMA_PRL_DONE:
696 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
697 break;
698
699 case CMD_NV_RESET_CONFIG:
700 request = (MainThreadRequest) msg.obj;
701 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
702 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
703 break;
704
705 case EVENT_NV_RESET_CONFIG_DONE:
706 handleNullReturnEvent(msg, "nvResetConfig");
707 break;
708
Jake Hamby7c27be32014-03-03 13:25:59 -0800709 case CMD_GET_PREFERRED_NETWORK_TYPE:
710 request = (MainThreadRequest) msg.obj;
711 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700712 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 break;
714
715 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
716 ar = (AsyncResult) msg.obj;
717 request = (MainThreadRequest) ar.userObj;
718 if (ar.exception == null && ar.result != null) {
719 request.result = ar.result; // Integer
720 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800721 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800722 if (ar.result == null) {
723 loge("getPreferredNetworkType: Empty response");
724 } else if (ar.exception instanceof CommandException) {
725 loge("getPreferredNetworkType: CommandException: " +
726 ar.exception);
727 } else {
728 loge("getPreferredNetworkType: Unknown exception");
729 }
730 }
731 synchronized (request) {
732 request.notifyAll();
733 }
734 break;
735
736 case CMD_SET_PREFERRED_NETWORK_TYPE:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
739 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700740 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800741 break;
742
743 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
744 handleNullReturnEvent(msg, "setPreferredNetworkType");
745 break;
746
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800747 case CMD_SET_VOICEMAIL_NUMBER:
748 request = (MainThreadRequest) msg.obj;
749 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
750 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800751 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
752 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800753 break;
754
755 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
756 handleNullReturnEvent(msg, "setVoicemailNumber");
757 break;
758
Stuart Scott54788802015-03-30 13:18:01 -0700759 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
762 request);
763 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
764 break;
765
766 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
767 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
768 break;
769
Shishir Agrawal302c8692015-06-19 13:49:39 -0700770 case CMD_PERFORM_NETWORK_SCAN:
771 request = (MainThreadRequest) msg.obj;
772 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
773 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
774 break;
775
776 case EVENT_PERFORM_NETWORK_SCAN_DONE:
777 ar = (AsyncResult) msg.obj;
778 request = (MainThreadRequest) ar.userObj;
779 CellNetworkScanResult cellScanResult;
780 if (ar.exception == null && ar.result != null) {
781 cellScanResult = new CellNetworkScanResult(
782 CellNetworkScanResult.STATUS_SUCCESS,
783 (List<OperatorInfo>) ar.result);
784 } else {
785 if (ar.result == null) {
786 loge("getCellNetworkScanResults: Empty response");
787 }
788 if (ar.exception != null) {
789 loge("getCellNetworkScanResults: Exception: " + ar.exception);
790 }
791 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
792 if (ar.exception instanceof CommandException) {
793 CommandException.Error error =
794 ((CommandException) (ar.exception)).getCommandError();
795 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
796 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
797 } else if (error == CommandException.Error.GENERIC_FAILURE) {
798 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
799 }
800 }
801 cellScanResult = new CellNetworkScanResult(errorCode, null);
802 }
803 request.result = cellScanResult;
804 synchronized (request) {
805 request.notifyAll();
806 }
807 break;
808
809 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
810 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700811 ManualNetworkSelectionArgument selArg =
812 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700813 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
814 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700815 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
816 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700817 break;
818
819 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
820 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
821 break;
822
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700823 case CMD_GET_MODEM_ACTIVITY_INFO:
824 request = (MainThreadRequest) msg.obj;
825 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700826 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700827 break;
828
829 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
830 ar = (AsyncResult) msg.obj;
831 request = (MainThreadRequest) ar.userObj;
832 if (ar.exception == null && ar.result != null) {
833 request.result = ar.result;
834 } else {
835 if (ar.result == null) {
836 loge("queryModemActivityInfo: Empty response");
837 } else if (ar.exception instanceof CommandException) {
838 loge("queryModemActivityInfo: CommandException: " +
839 ar.exception);
840 } else {
841 loge("queryModemActivityInfo: Unknown exception");
842 }
843 }
Amit Mahajand4766222016-01-28 15:28:28 -0800844 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
845 if (request.result == null) {
846 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
847 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700848 synchronized (request) {
849 request.notifyAll();
850 }
851 break;
852
Meng Wang1a7c35a2016-05-05 20:56:15 -0700853 case CMD_SET_ALLOWED_CARRIERS:
854 request = (MainThreadRequest) msg.obj;
855 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
856 mPhone.setAllowedCarriers(
857 (List<CarrierIdentifier>) request.argument,
858 onCompleted);
859 break;
860
861 case EVENT_SET_ALLOWED_CARRIERS_DONE:
862 ar = (AsyncResult) msg.obj;
863 request = (MainThreadRequest) ar.userObj;
864 if (ar.exception == null && ar.result != null) {
865 request.result = ar.result;
866 } else {
867 if (ar.result == null) {
868 loge("setAllowedCarriers: Empty response");
869 } else if (ar.exception instanceof CommandException) {
870 loge("setAllowedCarriers: CommandException: " +
871 ar.exception);
872 } else {
873 loge("setAllowedCarriers: Unknown exception");
874 }
875 }
876 // Result cannot be null. Return -1 on error.
877 if (request.result == null) {
878 request.result = new int[]{-1};
879 }
880 synchronized (request) {
881 request.notifyAll();
882 }
883 break;
884
885 case CMD_GET_ALLOWED_CARRIERS:
886 request = (MainThreadRequest) msg.obj;
887 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
888 mPhone.getAllowedCarriers(onCompleted);
889 break;
890
891 case EVENT_GET_ALLOWED_CARRIERS_DONE:
892 ar = (AsyncResult) msg.obj;
893 request = (MainThreadRequest) ar.userObj;
894 if (ar.exception == null && ar.result != null) {
895 request.result = ar.result;
896 } else {
897 if (ar.result == null) {
898 loge("getAllowedCarriers: Empty response");
899 } else if (ar.exception instanceof CommandException) {
900 loge("getAllowedCarriers: CommandException: " +
901 ar.exception);
902 } else {
903 loge("getAllowedCarriers: Unknown exception");
904 }
905 }
906 // Result cannot be null. Return empty list of CarrierIdentifier.
907 if (request.result == null) {
908 request.result = new ArrayList<CarrierIdentifier>(0);
909 }
910 synchronized (request) {
911 request.notifyAll();
912 }
913 break;
914
Nathan Haroldb3014052017-01-25 15:57:32 -0800915 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 if (ar.exception == null && ar.result != null) {
919 request.result = ar.result;
920 } else {
921 request.result = new IllegalArgumentException(
922 "Failed to retrieve Forbidden Plmns");
923 if (ar.result == null) {
924 loge("getForbiddenPlmns: Empty response");
925 } else {
926 loge("getForbiddenPlmns: Unknown exception");
927 }
928 }
929 synchronized (request) {
930 request.notifyAll();
931 }
932 break;
933
934 case CMD_GET_FORBIDDEN_PLMNS:
935 request = (MainThreadRequest) msg.obj;
936 uiccCard = getUiccCardFromRequest(request);
937 if (uiccCard == null) {
938 loge("getForbiddenPlmns() UiccCard is null");
939 request.result = new IllegalArgumentException(
940 "getForbiddenPlmns() UiccCard is null");
941 synchronized (request) {
942 request.notifyAll();
943 }
944 break;
945 }
946 Integer appType = (Integer) request.argument;
947 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
948 if (uiccApp == null) {
949 loge("getForbiddenPlmns() no app with specified type -- "
950 + appType);
951 request.result = new IllegalArgumentException("Failed to get UICC App");
952 synchronized (request) {
953 request.notifyAll();
954 }
955 break;
956 } else {
957 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
958 + " specified type -- " + appType);
959 }
960 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
961 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
962 onCompleted);
963 break;
964
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000965 case CMD_SWITCH_SLOTS:
966 request = (MainThreadRequest) msg.obj;
967 int[] physicalSlots = (int[]) request.argument;
968 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
969 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
970 break;
971
972 case EVENT_SWITCH_SLOTS_DONE:
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 request.result = (ar.exception == null);
976 synchronized (request) {
977 request.notifyAll();
978 }
979 break;
980
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700981 default:
982 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
983 break;
984 }
985 }
Jake Hambye994d462014-02-03 13:10:13 -0800986
987 private void handleNullReturnEvent(Message msg, String command) {
988 AsyncResult ar = (AsyncResult) msg.obj;
989 MainThreadRequest request = (MainThreadRequest) ar.userObj;
990 if (ar.exception == null) {
991 request.result = true;
992 } else {
993 request.result = false;
994 if (ar.exception instanceof CommandException) {
995 loge(command + ": CommandException: " + ar.exception);
996 } else {
997 loge(command + ": Unknown exception");
998 }
999 }
1000 synchronized (request) {
1001 request.notifyAll();
1002 }
1003 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001004 }
1005
1006 /**
1007 * Posts the specified command to be executed on the main thread,
1008 * waits for the request to complete, and returns the result.
1009 * @see #sendRequestAsync
1010 */
1011 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001012 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001013 }
1014
1015 /**
1016 * Posts the specified command to be executed on the main thread,
1017 * waits for the request to complete, and returns the result.
1018 * @see #sendRequestAsync
1019 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001020 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001021 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1022 throw new RuntimeException("This method will deadlock if called from the main thread.");
1023 }
1024
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001025 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001026 Message msg = mMainThreadHandler.obtainMessage(command, request);
1027 msg.sendToTarget();
1028
1029 // Wait for the request to complete
1030 synchronized (request) {
1031 while (request.result == null) {
1032 try {
1033 request.wait();
1034 } catch (InterruptedException e) {
1035 // Do nothing, go back and wait until the request is complete
1036 }
1037 }
1038 }
1039 return request.result;
1040 }
1041
1042 /**
1043 * Asynchronous ("fire and forget") version of sendRequest():
1044 * Posts the specified command to be executed on the main thread, and
1045 * returns immediately.
1046 * @see #sendRequest
1047 */
1048 private void sendRequestAsync(int command) {
1049 mMainThreadHandler.sendEmptyMessage(command);
1050 }
1051
1052 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001053 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1054 * @see {@link #sendRequest(int,Object)}
1055 */
1056 private void sendRequestAsync(int command, Object argument) {
1057 MainThreadRequest request = new MainThreadRequest(argument);
1058 Message msg = mMainThreadHandler.obtainMessage(command, request);
1059 msg.sendToTarget();
1060 }
1061
1062 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001063 * Initialize the singleton PhoneInterfaceManager instance.
1064 * This is only done once, at startup, from PhoneApp.onCreate().
1065 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001066 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001067 synchronized (PhoneInterfaceManager.class) {
1068 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001069 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001070 } else {
1071 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1072 }
1073 return sInstance;
1074 }
1075 }
1076
1077 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001078 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001079 mApp = app;
1080 mPhone = phone;
1081 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001082 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1084 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001085 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001086 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001087 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001088 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001089
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001090 publish();
1091 }
1092
1093 private void publish() {
1094 if (DBG) log("publish: " + this);
1095
1096 ServiceManager.addService("phone", this);
1097 }
1098
Stuart Scott584921c2015-01-15 17:10:34 -08001099 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001100 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1101 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001102 }
1103
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001104 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1105 Phone phone = getPhoneFromRequest(request);
1106 return phone == null ? null :
1107 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1108 }
1109
Wink Saville36469e72014-06-11 15:17:00 -07001110 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001111 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001112 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001113 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001114 //
1115 // Implementation of the ITelephony interface.
1116 //
1117
1118 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001119 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001120 }
1121
Wink Savilleb564aae2014-10-23 10:18:09 -07001122 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001123 if (DBG) log("dial: " + number);
1124 // No permission check needed here: This is just a wrapper around the
1125 // ACTION_DIAL intent, which is available to any app since it puts up
1126 // the UI before it does anything.
1127
1128 String url = createTelUrl(number);
1129 if (url == null) {
1130 return;
1131 }
1132
1133 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001134 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001135 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1136 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1137 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1138 mApp.startActivity(intent);
1139 }
1140 }
1141
1142 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001143 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001144 }
1145
Wink Savilleb564aae2014-10-23 10:18:09 -07001146 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001147 if (DBG) log("call: " + number);
1148
1149 // This is just a wrapper around the ACTION_CALL intent, but we still
1150 // need to do a permission check since we're calling startActivity()
1151 // from the context of the phone app.
1152 enforceCallPermission();
1153
1154 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1155 != AppOpsManager.MODE_ALLOWED) {
1156 return;
1157 }
1158
1159 String url = createTelUrl(number);
1160 if (url == null) {
1161 return;
1162 }
1163
Wink Saville08874612014-08-31 19:19:58 -07001164 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001165 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001166 if (slist != null) {
1167 for (SubscriptionInfo subInfoRecord : slist) {
1168 if (subInfoRecord.getSubscriptionId() == subId) {
1169 isValid = true;
1170 break;
1171 }
Wink Saville08874612014-08-31 19:19:58 -07001172 }
1173 }
1174 if (isValid == false) {
1175 return;
1176 }
1177
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001178 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001179 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001180 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1181 mApp.startActivity(intent);
1182 }
1183
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001184 /**
1185 * End a call based on call state
1186 * @return true is a call was ended
1187 */
1188 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001189 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001190 }
1191
1192 /**
1193 * End a call based on the call state of the subId
1194 * @return true is a call was ended
1195 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001196 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001197 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1198 != PackageManager.PERMISSION_GRANTED) {
1199 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1200 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1201 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1202 }
Stuart Scott584921c2015-01-15 17:10:34 -08001203 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001204 }
1205
1206 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001207 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001208 }
1209
Wink Savilleb564aae2014-10-23 10:18:09 -07001210 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001211 if (DBG) log("answerRingingCall...");
1212 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1213 // but that can probably wait till the big TelephonyManager API overhaul.
1214 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1215 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001216 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001217 }
1218
1219 /**
1220 * Make the actual telephony calls to implement answerRingingCall().
1221 * This should only be called from the main thread of the Phone app.
1222 * @see #answerRingingCall
1223 *
1224 * TODO: it would be nice to return true if we answered the call, or
1225 * false if there wasn't actually a ringing incoming call, or some
1226 * other error occurred. (In other words, pass back the return value
1227 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1228 * But that would require calling this method via sendRequest() rather
1229 * than sendRequestAsync(), and right now we don't actually *need* that
1230 * return value, so let's just return void for now.
1231 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001232 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001233 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001235 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1236 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001237 if (hasActiveCall && hasHoldingCall) {
1238 // Both lines are in use!
1239 // TODO: provide a flag to let the caller specify what
1240 // policy to use if both lines are in use. (The current
1241 // behavior is hardwired to "answer incoming, end ongoing",
1242 // which is how the CALL button is specced to behave.)
1243 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1244 return;
1245 } else {
1246 // answerCall() will automatically hold the current active
1247 // call, if there is one.
1248 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1249 return;
1250 }
1251 } else {
1252 // No call was ringing.
1253 return;
1254 }
1255 }
1256
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001257 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001258 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001260 public void silenceRinger() {
1261 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 }
1263
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001264 @Override
1265 public boolean isOffhook(String callingPackage) {
1266 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001267 }
1268
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001269 @Override
1270 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001272 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001273 return false;
1274 }
1275
Sanket Padawe356d7632015-06-22 14:03:32 -07001276 final Phone phone = getPhone(subId);
1277 if (phone != null) {
1278 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1279 } else {
1280 return false;
1281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282 }
1283
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001284 @Override
1285 public boolean isRinging(String callingPackage) {
1286 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001287 }
1288
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001289 @Override
1290 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001291 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001292 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001293 return false;
1294 }
1295
Sanket Padawe356d7632015-06-22 14:03:32 -07001296 final Phone phone = getPhone(subId);
1297 if (phone != null) {
1298 return (phone.getState() == PhoneConstants.State.RINGING);
1299 } else {
1300 return false;
1301 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001302 }
1303
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001304 @Override
1305 public boolean isIdle(String callingPackage) {
1306 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001307 }
1308
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001309 @Override
1310 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001312 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001313 return false;
1314 }
1315
Sanket Padawe356d7632015-06-22 14:03:32 -07001316 final Phone phone = getPhone(subId);
1317 if (phone != null) {
1318 return (phone.getState() == PhoneConstants.State.IDLE);
1319 } else {
1320 return false;
1321 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001322 }
1323
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001325 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001326 }
1327
Wink Savilleb564aae2014-10-23 10:18:09 -07001328 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001329 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001330 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1331 }
1332
1333 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001334 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001335 }
1336
Wink Savilleb564aae2014-10-23 10:18:09 -07001337 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001338 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001339 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1340 }
1341
1342 /** {@hide} */
1343 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001344 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001345 }
1346
Wink Savilleb564aae2014-10-23 10:18:09 -07001347 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001348 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001349 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001350 checkSimPin.start();
1351 return checkSimPin.unlockSim(null, pin);
1352 }
1353
Wink Saville9de0f752013-10-22 19:04:03 -07001354 /** {@hide} */
1355 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001356 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001357 }
1358
Wink Savilleb564aae2014-10-23 10:18:09 -07001359 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001361 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001362 checkSimPuk.start();
1363 return checkSimPuk.unlockSim(puk, pin);
1364 }
1365
1366 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001367 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001368 * a synchronous one.
1369 */
1370 private static class UnlockSim extends Thread {
1371
1372 private final IccCard mSimCard;
1373
1374 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001375 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1376 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377
1378 // For replies from SimCard interface
1379 private Handler mHandler;
1380
1381 // For async handler to identify request type
1382 private static final int SUPPLY_PIN_COMPLETE = 100;
1383
1384 public UnlockSim(IccCard simCard) {
1385 mSimCard = simCard;
1386 }
1387
1388 @Override
1389 public void run() {
1390 Looper.prepare();
1391 synchronized (UnlockSim.this) {
1392 mHandler = new Handler() {
1393 @Override
1394 public void handleMessage(Message msg) {
1395 AsyncResult ar = (AsyncResult) msg.obj;
1396 switch (msg.what) {
1397 case SUPPLY_PIN_COMPLETE:
1398 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1399 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001400 mRetryCount = msg.arg1;
1401 if (ar.exception != null) {
1402 if (ar.exception instanceof CommandException &&
1403 ((CommandException)(ar.exception)).getCommandError()
1404 == CommandException.Error.PASSWORD_INCORRECT) {
1405 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1406 } else {
1407 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1408 }
1409 } else {
1410 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1411 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001412 mDone = true;
1413 UnlockSim.this.notifyAll();
1414 }
1415 break;
1416 }
1417 }
1418 };
1419 UnlockSim.this.notifyAll();
1420 }
1421 Looper.loop();
1422 }
1423
1424 /*
1425 * Use PIN or PUK to unlock SIM card
1426 *
1427 * If PUK is null, unlock SIM card with PIN
1428 *
1429 * If PUK is not null, unlock SIM card with PUK and set PIN code
1430 */
Wink Saville9de0f752013-10-22 19:04:03 -07001431 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001432
1433 while (mHandler == null) {
1434 try {
1435 wait();
1436 } catch (InterruptedException e) {
1437 Thread.currentThread().interrupt();
1438 }
1439 }
1440 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1441
1442 if (puk == null) {
1443 mSimCard.supplyPin(pin, callback);
1444 } else {
1445 mSimCard.supplyPuk(puk, pin, callback);
1446 }
1447
1448 while (!mDone) {
1449 try {
1450 Log.d(LOG_TAG, "wait for done");
1451 wait();
1452 } catch (InterruptedException e) {
1453 // Restore the interrupted status
1454 Thread.currentThread().interrupt();
1455 }
1456 }
1457 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001458 int[] resultArray = new int[2];
1459 resultArray[0] = mResult;
1460 resultArray[1] = mRetryCount;
1461 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 }
1463 }
1464
1465 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001466 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001467
1468 }
1469
Wink Savilleb564aae2014-10-23 10:18:09 -07001470 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471 // No permission check needed here: this call is harmless, and it's
1472 // needed for the ServiceState.requestStateUpdate() call (which is
1473 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001474 final Phone phone = getPhone(subId);
1475 if (phone != null) {
1476 phone.updateServiceLocation();
1477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478 }
1479
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001480 @Override
1481 public boolean isRadioOn(String callingPackage) {
1482 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001483 }
1484
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001485 @Override
1486 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001488 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001489 return false;
1490 }
1491 return isRadioOnForSubscriber(subId);
1492 }
1493
1494 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001495 final Phone phone = getPhone(subId);
1496 if (phone != null) {
1497 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1498 } else {
1499 return false;
1500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 }
1502
1503 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001504 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001505
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506 }
Wink Saville36469e72014-06-11 15:17:00 -07001507
Wink Savilleb564aae2014-10-23 10:18:09 -07001508 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001510 final Phone phone = getPhone(subId);
1511 if (phone != null) {
1512 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1513 }
Wink Saville36469e72014-06-11 15:17:00 -07001514 }
1515
1516 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001517 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001518 }
1519
Wink Savilleb564aae2014-10-23 10:18:09 -07001520 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001521 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001522 final Phone phone = getPhone(subId);
1523 if (phone == null) {
1524 return false;
1525 }
1526 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001527 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001528 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 }
1530 return true;
1531 }
Wink Saville36469e72014-06-11 15:17:00 -07001532
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001533 public boolean needMobileRadioShutdown() {
1534 /*
1535 * If any of the Radios are available, it will need to be
1536 * shutdown. So return true if any Radio is available.
1537 */
1538 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1539 Phone phone = PhoneFactory.getPhone(i);
1540 if (phone != null && phone.isRadioAvailable()) return true;
1541 }
1542 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1543 return false;
1544 }
1545
1546 public void shutdownMobileRadios() {
1547 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1548 logv("Shutting down Phone " + i);
1549 shutdownRadioUsingPhoneId(i);
1550 }
1551 }
1552
1553 private void shutdownRadioUsingPhoneId(int phoneId) {
1554 enforceModifyPermission();
1555 Phone phone = PhoneFactory.getPhone(phoneId);
1556 if (phone != null && phone.isRadioAvailable()) {
1557 phone.shutdownRadio();
1558 }
1559 }
1560
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001561 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001562 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001563 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1564 if (defaultPhone != null) {
1565 defaultPhone.setRadioPower(turnOn);
1566 return true;
1567 } else {
1568 loge("There's no default phone.");
1569 return false;
1570 }
Wink Saville36469e72014-06-11 15:17:00 -07001571 }
1572
Wink Savilleb564aae2014-10-23 10:18:09 -07001573 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001575 final Phone phone = getPhone(subId);
1576 if (phone != null) {
1577 phone.setRadioPower(turnOn);
1578 return true;
1579 } else {
1580 return false;
1581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 }
1583
Wink Saville36469e72014-06-11 15:17:00 -07001584 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001585 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 public boolean enableDataConnectivity() {
1587 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001588 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001589 final Phone phone = getPhone(subId);
1590 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001591 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001592 return true;
1593 } else {
1594 return false;
1595 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596 }
1597
Wink Saville36469e72014-06-11 15:17:00 -07001598 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001599 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 public boolean disableDataConnectivity() {
1601 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001602 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001603 final Phone phone = getPhone(subId);
1604 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001605 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001606 return true;
1607 } else {
1608 return false;
1609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 }
1611
Sanket Padawe356d7632015-06-22 14:03:32 -07001612 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001613 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001614 final Phone phone = getPhone(subId);
1615 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001616 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001617 } else {
1618 return false;
1619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 }
1621
1622 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001623 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001624 }
1625
pkanwarae03a6b2016-11-06 20:37:09 -08001626 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001627 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001628 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1629 return;
1630 }
1631 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1632 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1633 };
1634
Wink Savilleb564aae2014-10-23 10:18:09 -07001635 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001637 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1638 return false;
1639 }
Wink Saville36469e72014-06-11 15:17:00 -07001640 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 }
1642
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001643 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001644 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001645 }
1646
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001647 public int getCallStateForSlot(int slotIndex) {
1648 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001649 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001650 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 }
1652
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001655 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001656 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001657 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001658 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001659 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001660 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 }
1662
Sanket Padawe356d7632015-06-22 14:03:32 -07001663 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001665 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001666 if (phone != null) {
1667 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1668 } else {
1669 return TelephonyManager.DATA_ACTIVITY_NONE;
1670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 }
1672
1673 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001674 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001675 mPhone.getContext().getSystemService(AppOpsManager.class)
1676 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001677 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001678 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001679 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001680 }
1681
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001682 if (DBG_LOC) log("getCellLocation: is active user");
1683 Bundle data = new Bundle();
1684 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1685 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 return null;
1687 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001689 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001690 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1691 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001692 }
1693
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001695 public String getNetworkCountryIsoForPhone(int phoneId) {
1696 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1697 // registered cell info, so return a NULL country instead.
1698 final long identity = Binder.clearCallingIdentity();
1699 try {
1700 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1701 if (TelephonyManager.NETWORK_TYPE_IWLAN
1702 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1703 return "";
1704 }
1705 } finally {
1706 Binder.restoreCallingIdentity(identity);
1707 }
1708 return TelephonyManager.getTelephonyProperty(
1709 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1710 }
1711
1712 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001714 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001715 }
1716
Sanket Padawe356d7632015-06-22 14:03:32 -07001717 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001718 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 mApp.enforceCallingOrSelfPermission(
1720 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001721 final Phone phone = getPhone(subId);
1722 if (phone != null) {
1723 phone.enableLocationUpdates();
1724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
1727 @Override
1728 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001729 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001730 }
1731
Sanket Padawe356d7632015-06-22 14:03:32 -07001732 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001733 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 mApp.enforceCallingOrSelfPermission(
1735 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001736 final Phone phone = getPhone(subId);
1737 if (phone != null) {
1738 phone.disableLocationUpdates();
1739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 }
1741
1742 @Override
1743 @SuppressWarnings("unchecked")
1744 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001745 mPhone.getContext().getSystemService(AppOpsManager.class)
1746 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001747 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001748 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001749 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 }
1751
1752 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1753 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1754 return null;
1755 }
Svetoslav64fad262015-04-14 14:35:21 -07001756
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001757 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001759 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001761 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001762 try {
1763 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1764 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1765 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1766 } catch (RuntimeException e) {
1767 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001769 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
1771
1772
1773 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001774 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001775 mPhone.getContext().getSystemService(AppOpsManager.class)
1776 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001777 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001778 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001779 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001780 }
1781
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001782 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001783 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001784 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1785 for (Phone phone : PhoneFactory.getPhones()) {
1786 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1787 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001789 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 }
1791
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001792 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001794 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001795 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001796 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 }
1798
Shishir Agrawala9f32182016-04-12 12:00:16 -07001799 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001800 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001801 Phone phone = PhoneFactory.getPhone(slotIndex);
1802 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001803 return null;
1804 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001805 int subId = phone.getSubId();
1806 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1807 mApp, subId, callingPackage, "getImeiForSlot")) {
1808 return null;
1809 }
1810 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001811 }
1812
1813 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001814 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001815 Phone phone = PhoneFactory.getPhone(slotIndex);
1816 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001817 return null;
1818 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001819 int subId = phone.getSubId();
1820 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1821 mApp, subId, callingPackage, "getMeidForSlot")) {
1822 return null;
1823 }
1824 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001825 }
1826
1827 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001828 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001829 Phone phone = PhoneFactory.getPhone(slotIndex);
1830 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001831 return null;
1832 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001833 int subId = phone.getSubId();
1834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1835 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1836 return null;
1837 }
1838 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001839 }
1840
fionaxu43304da2017-11-27 22:51:16 -08001841 @Override
1842 public int getSubscriptionCarrierId(int subId) {
1843 final Phone phone = getPhone(subId);
1844 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1845 }
1846
1847 @Override
1848 public String getSubscriptionCarrierName(int subId) {
1849 final Phone phone = getPhone(subId);
1850 return phone == null ? null : phone.getCarrierName();
1851 }
1852
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 //
1854 // Internal helper methods.
1855 //
1856
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001857 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1859 *
1860 * @throws SecurityException if the caller does not have the required permission
1861 */
1862 private void enforceModifyPermission() {
1863 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1864 }
1865
1866 /**
1867 * Make sure the caller has the CALL_PHONE permission.
1868 *
1869 * @throws SecurityException if the caller does not have the required permission
1870 */
1871 private void enforceCallPermission() {
1872 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1873 }
1874
Stuart Scott8eef64f2015-04-08 15:13:54 -07001875 private void enforceConnectivityInternalPermission() {
1876 mApp.enforceCallingOrSelfPermission(
1877 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1878 "ConnectivityService");
1879 }
1880
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 private String createTelUrl(String number) {
1882 if (TextUtils.isEmpty(number)) {
1883 return null;
1884 }
1885
Jake Hambye994d462014-02-03 13:10:13 -08001886 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 }
1888
Ihab Awadf9e92732013-12-05 18:02:52 -08001889 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1891 }
1892
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001893 private static void logv(String msg) {
1894 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1895 }
1896
Ihab Awadf9e92732013-12-05 18:02:52 -08001897 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1899 }
1900
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001901 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001903 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001904 }
1905
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001907 public int getActivePhoneTypeForSlot(int slotIndex) {
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 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002053 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2054 }
2055
2056 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002057 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2058 VisualVoicemailSmsFilterSettings settings) {
2059 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002060 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002061 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2062 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002063 }
2064
2065 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002066 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2067 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002068 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002069 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002070 }
2071
2072 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002073 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2074 String callingPackage, int subId) {
2075 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002076 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002077 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002078 }
2079
2080 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002081 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002082 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002083 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002084 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2085 }
2086
2087 @Override
2088 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2089 String number, int port, String text, PendingIntent sentIntent) {
2090 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002091 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002092 enforceSendSmsPermission();
2093 // Make the calls as the phone process.
2094 final long identity = Binder.clearCallingIdentity();
2095 try {
2096 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2097 if (port == 0) {
2098 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2099 sentIntent, null, false);
2100 } else {
2101 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2102 smsManager.sendDataMessageWithSelfPermissions(number, null,
2103 (short) port, data, sentIntent, null);
2104 }
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
2107 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002108 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002109 /**
fionaxu0152e512016-11-14 13:36:14 -08002110 * Sets the voice activation state of a given subId.
2111 */
2112 @Override
2113 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2115 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002116 final Phone phone = getPhone(subId);
2117 if (phone != null) {
2118 phone.setVoiceActivationState(activationState);
2119 } else {
2120 loge("setVoiceActivationState fails with invalid subId: " + subId);
2121 }
2122 }
2123
2124 /**
2125 * Sets the data activation state of a given subId.
2126 */
2127 @Override
2128 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2130 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002131 final Phone phone = getPhone(subId);
2132 if (phone != null) {
2133 phone.setDataActivationState(activationState);
2134 } else {
2135 loge("setVoiceActivationState fails with invalid subId: " + subId);
2136 }
2137 }
2138
2139 /**
2140 * Returns the voice activation state of a given subId.
2141 */
2142 @Override
2143 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002144 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002145 final Phone phone = getPhone(subId);
2146 if (phone != null) {
2147 return phone.getVoiceActivationState();
2148 } else {
2149 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2150 }
2151 }
2152
2153 /**
2154 * Returns the data activation state of a given subId.
2155 */
2156 @Override
2157 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002158 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002159 final Phone phone = getPhone(subId);
2160 if (phone != null) {
2161 return phone.getDataActivationState();
2162 } else {
2163 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2164 }
2165 }
2166
2167 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 * Returns the unread count of voicemails
2169 */
2170 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002171 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002172 }
2173
2174 /**
2175 * Returns the unread count of voicemails for a subId
2176 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002177 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002178 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002179 final Phone phone = getPhone(subId);
2180 if (phone != null) {
2181 return phone.getVoiceMessageCount();
2182 } else {
2183 return 0;
2184 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186
2187 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002188 * returns true, if the device is in a state where both voice and data
2189 * are supported simultaneously. This can change based on location or network condition.
2190 */
2191 @Override
2192 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2193 final Phone phone = getPhone(subId);
2194 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2195 }
2196
2197 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002198 * Send the dialer code if called from the current default dialer or the caller has
2199 * carrier privilege.
2200 * @param inputCode The dialer code to send
2201 */
2202 @Override
2203 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2204 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2205 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2206 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002207 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2208 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002209 }
2210 mPhone.sendDialerSpecialCode(inputCode);
2211 }
2212
2213 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002214 * Returns the data network type.
2215 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 *
2217 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2218 */
2219 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002220 public int getNetworkType() {
2221 final Phone phone = getPhone(getDefaultSubscription());
2222 if (phone != null) {
2223 return phone.getServiceState().getDataNetworkType();
2224 } else {
2225 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2226 }
Wink Saville36469e72014-06-11 15:17:00 -07002227 }
2228
2229 /**
2230 * Returns the network type for a subId
2231 */
2232 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002233 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002235 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002236 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2237 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002238
Sanket Padawe356d7632015-06-22 14:03:32 -07002239 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002240 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002241 return phone.getServiceState().getDataNetworkType();
2242 } else {
2243 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 }
2246
2247 /**
2248 * Returns the data network type
2249 */
2250 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002251 public int getDataNetworkType(String callingPackage) {
2252 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002253 }
2254
2255 /**
2256 * Returns the data network type for a subId
2257 */
2258 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002259 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002261 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002262 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2263 }
2264
Sanket Padawe356d7632015-06-22 14:03:32 -07002265 final Phone phone = getPhone(subId);
2266 if (phone != null) {
2267 return phone.getServiceState().getDataNetworkType();
2268 } else {
2269 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 }
2272
2273 /**
Wink Saville36469e72014-06-11 15:17:00 -07002274 * Returns the Voice network type for a subId
2275 */
2276 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002277 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002279 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002280 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2281 }
2282
Sanket Padawe356d7632015-06-22 14:03:32 -07002283 final Phone phone = getPhone(subId);
2284 if (phone != null) {
2285 return phone.getServiceState().getVoiceNetworkType();
2286 } else {
2287 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 }
2290
2291 /**
2292 * @return true if a ICC card is present
2293 */
2294 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002295 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002296 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2297 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002298 }
2299
2300 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002301 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002302 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002303 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002304 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2305 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002306 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002308 } else {
2309 return false;
2310 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 }
2312
2313 /**
2314 * Return if the current radio is LTE on CDMA. This
2315 * is a tri-state return value as for a period of time
2316 * the mode may be unknown.
2317 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002318 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002320 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002322 @Override
2323 public int getLteOnCdmaMode(String callingPackage) {
2324 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002325 }
2326
Sanket Padawe356d7632015-06-22 14:03:32 -07002327 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002328 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002330 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002331 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2332 }
2333
Sanket Padawe356d7632015-06-22 14:03:32 -07002334 final Phone phone = getPhone(subId);
2335 if (phone == null) {
2336 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2337 } else {
2338 return phone.getLteOnCdmaMode();
2339 }
Wink Saville36469e72014-06-11 15:17:00 -07002340 }
2341
2342 public void setPhone(Phone phone) {
2343 mPhone = phone;
2344 }
2345
2346 /**
2347 * {@hide}
2348 * Returns Default subId, 0 in the case of single standby.
2349 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002350 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002351 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002352 }
2353
Shishir Agrawala9f32182016-04-12 12:00:16 -07002354 private int getSlotForDefaultSubscription() {
2355 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2356 }
2357
Wink Savilleb564aae2014-10-23 10:18:09 -07002358 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002359 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002361
2362 /**
2363 * @see android.telephony.TelephonyManager.WifiCallingChoices
2364 */
2365 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002366 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2367 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002368 }
2369
2370 /**
2371 * @see android.telephony.TelephonyManager.WifiCallingChoices
2372 */
2373 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002374 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2375 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2376 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002377 }
2378
Sailesh Nepald1e68152013-12-12 19:08:02 -08002379 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002380 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002381 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002382 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002383
Shishir Agrawal566b7612013-10-28 14:41:00 -07002384 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002385 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2386 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2388 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002389
Derek Tan740e1672017-06-27 14:56:27 -07002390 if (TextUtils.equals(ISDR_AID, aid)) {
2391 // Only allows LPA to open logical channel to ISD-R.
2392 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2393 ComponentInfo bestComponent =
2394 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2395 if (bestComponent == null
2396 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2397 loge("The calling package is not allowed to access ISD-R.");
2398 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2399 }
2400 }
2401
2402 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002403 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002404 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002405 if (DBG) log("iccOpenLogicalChannel: " + response);
2406 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002407 }
2408
2409 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002410 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002411 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2412 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002413
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002414 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002415 if (channel < 0) {
2416 return false;
2417 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002418 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002419 if (DBG) log("iccCloseLogicalChannel: " + success);
2420 return success;
2421 }
2422
2423 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002424 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002425 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2427 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002428
2429 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002430 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2431 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002432 " data=" + data);
2433 }
2434
2435 if (channel < 0) {
2436 return "";
2437 }
2438
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002439 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002440 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002441 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2442
Shishir Agrawal566b7612013-10-28 14:41:00 -07002443 // Append the returned status code to the end of the response payload.
2444 String s = Integer.toHexString(
2445 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002446 if (response.payload != null) {
2447 s = IccUtils.bytesToHexString(response.payload) + s;
2448 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002449 return s;
2450 }
Jake Hambye994d462014-02-03 13:10:13 -08002451
Evan Charltonc66da362014-05-16 14:06:40 -07002452 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002453 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2454 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2456 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002457
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002458 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2459 && TextUtils.equals(ISDR_AID, data)) {
2460 // Only allows LPA to select ISD-R.
2461 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2462 ComponentInfo bestComponent =
2463 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2464 if (bestComponent == null
2465 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2466 loge("The calling package is not allowed to select ISD-R.");
2467 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2468 }
2469 }
2470
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002471 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002472 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2473 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002474 }
2475
2476 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002477 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002478 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2479
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002480 // Append the returned status code to the end of the response payload.
2481 String s = Integer.toHexString(
2482 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002483 if (response.payload != null) {
2484 s = IccUtils.bytesToHexString(response.payload) + s;
2485 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002486 return s;
2487 }
2488
2489 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002490 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002491 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2493 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002494
2495 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002496 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002497 p1 + " " + p2 + " " + p3 + ":" + filePath);
2498 }
2499
2500 IccIoResult response =
2501 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002502 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2503 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002504
2505 if (DBG) {
2506 log("Exchange SIM_IO [R]" + response);
2507 }
2508
2509 byte[] result = null;
2510 int length = 2;
2511 if (response.payload != null) {
2512 length = 2 + response.payload.length;
2513 result = new byte[length];
2514 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2515 } else {
2516 result = new byte[length];
2517 }
2518
2519 result[length - 1] = (byte) response.sw2;
2520 result[length - 2] = (byte) response.sw1;
2521 return result;
2522 }
2523
Nathan Haroldb3014052017-01-25 15:57:32 -08002524 /**
2525 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2526 * on a particular subscription
2527 */
sqianb6e41952018-03-12 14:54:01 -07002528 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2530 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2531 return null;
2532 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002533 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2534 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2535 return null;
2536 }
2537 Object response = sendRequest(
2538 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2539 if (response instanceof String[]) {
2540 return (String[]) response;
2541 }
2542 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2543 return null;
2544 }
2545
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002546 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002547 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2549 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002550
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002551 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002552 if (response.payload == null) {
2553 return "";
2554 }
2555
2556 // Append the returned status code to the end of the response payload.
2557 String s = Integer.toHexString(
2558 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2559 s = IccUtils.bytesToHexString(response.payload) + s;
2560 return s;
2561 }
2562
Jake Hambye994d462014-02-03 13:10:13 -08002563 /**
2564 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2565 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2566 *
2567 * @param itemID the ID of the item to read
2568 * @return the NV item as a String, or null on error.
2569 */
2570 @Override
2571 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2573 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002574 if (DBG) log("nvReadItem: item " + itemID);
2575 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2576 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2577 return value;
2578 }
2579
2580 /**
2581 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2582 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2583 *
2584 * @param itemID the ID of the item to read
2585 * @param itemValue the value to write, as a String
2586 * @return true on success; false on any failure
2587 */
2588 @Override
2589 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2591 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002592 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2593 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2594 new Pair<Integer, String>(itemID, itemValue));
2595 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2596 return success;
2597 }
2598
2599 /**
2600 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2601 * Used for device configuration by some CDMA operators.
2602 *
2603 * @param preferredRoamingList byte array containing the new PRL
2604 * @return true on success; false on any failure
2605 */
2606 @Override
2607 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002608 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2609 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002610 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2611 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2612 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2613 return success;
2614 }
2615
2616 /**
2617 * Perform the specified type of NV config reset.
2618 * Used for device configuration by some CDMA operators.
2619 *
2620 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2621 * @return true on success; false on any failure
2622 */
2623 @Override
2624 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2626 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002627 if (DBG) log("nvResetConfig: type " + resetType);
2628 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2629 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2630 return success;
2631 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002632
2633 /**
Wink Saville36469e72014-06-11 15:17:00 -07002634 * {@hide}
2635 * Returns Default sim, 0 in the case of single standby.
2636 */
2637 public int getDefaultSim() {
2638 //TODO Need to get it from Telephony Devcontroller
2639 return 0;
2640 }
2641
Svet Ganovb320e182015-04-16 12:30:10 -07002642 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002643 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002644 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002645 return new String[0];
2646 }
2647
2648
ram87fca6f2014-07-18 18:58:44 +05302649 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002650 }
2651
Brad Ebinger51f743a2017-01-23 13:50:20 -08002652 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002653 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2654 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002655 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002656 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002657 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002658 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002659 }
2660
2661 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002662 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2663 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002664 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002665 public void disableIms(int slotId) {
2666 enforceModifyPermission();
2667 PhoneFactory.getImsResolver().disableIms(slotId);
2668 }
2669
2670 /**
2671 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2672 * feature or {@link null} if the service is not available. If the feature is available, the
2673 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2674 */
2675 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002676 IImsServiceFeatureCallback callback) {
2677 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002678 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002679 }
2680
2681 /**
2682 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2683 * feature during emergency calling or {@link null} if the service is not available. If the
2684 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2685 * listener for feature updates.
2686 */
2687 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2688 enforceModifyPermission();
2689 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002690 }
2691
Brad Ebinger5f64b052017-12-14 14:26:15 -08002692 /**
2693 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2694 * specified.
2695 */
2696 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2697 enforceModifyPermission();
2698 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2699 }
2700
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002701 /**
2702 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2703 * specified.
2704 */
2705 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2706 enforceModifyPermission();
2707 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2708 }
2709
Brad Ebinger884c07b2018-02-15 16:17:40 -08002710 /**
2711 * @return true if emergency calling is available on IMS, false if it should fallback to CS.
2712 */
2713 public boolean isEmergencyMmTelAvailable(int slotId) {
2714 enforceModifyPermission();
2715 return PhoneFactory.getImsResolver().isEmergencyMmTelAvailable(slotId);
2716 }
2717
Brad Ebinger304415d2018-03-02 13:43:36 -08002718 /**
2719 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2720 * available, false if the IMS resolver is idle.
2721 */
2722 public boolean isResolvingImsBinding() {
2723 enforceModifyPermission();
2724 return PhoneFactory.getImsResolver().isResolvingBinding();
2725 }
2726
Wink Saville36469e72014-06-11 15:17:00 -07002727 public void setImsRegistrationState(boolean registered) {
2728 enforceModifyPermission();
2729 mPhone.setImsRegistrationState(registered);
2730 }
2731
2732 /**
Stuart Scott54788802015-03-30 13:18:01 -07002733 * Set the network selection mode to automatic.
2734 *
2735 */
2736 @Override
2737 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2739 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002740 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2741 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2742 }
2743
2744 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002745 * Set the network selection mode to manual with the selected carrier.
2746 */
2747 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002748 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002749 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2751 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002752 OperatorInfo operator = new OperatorInfo(
2753 /* operatorAlphaLong */ "",
2754 /* operatorAlphaShort */ "",
2755 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002756 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002757 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2758 persistSelection);
2759 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002760 }
2761
2762 /**
2763 * Scans for available networks.
2764 */
2765 @Override
2766 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2768 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002769 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2770 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2771 CMD_PERFORM_NETWORK_SCAN, null, subId);
2772 return result;
2773 }
2774
2775 /**
yinxub1bed742017-04-17 11:45:04 -07002776 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002777 *
yinxub1bed742017-04-17 11:45:04 -07002778 * @param subId id of the subscription
2779 * @param request contains the radio access networks with bands/channels to scan
2780 * @param messenger callback messenger for scan results or errors
2781 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002782 * @return the id of the requested scan which can be used to stop the scan.
2783 */
2784 @Override
2785 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2786 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2788 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002789 return mNetworkScanRequestTracker.startNetworkScan(
2790 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002791 }
2792
2793 /**
2794 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002795 *
2796 * @param subId id of the subscription
2797 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002798 */
2799 @Override
2800 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2802 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002803 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002804 }
2805
2806 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002807 * Get the calculated preferred network type.
2808 * Used for debugging incorrect network type.
2809 *
2810 * @return the preferred network type, defined in RILConstants.java.
2811 */
2812 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002813 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002814 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002815 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002816 return RILConstants.PREFERRED_NETWORK_MODE;
2817 }
2818
Amit Mahajan43330e02014-11-18 11:54:45 -08002819 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002820 }
2821
2822 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002823 * Get the preferred network type.
2824 * Used for device configuration by some CDMA operators.
2825 *
2826 * @return the preferred network type, defined in RILConstants.java.
2827 */
2828 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002829 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2831 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002832 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002833 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002834 int networkType = (result != null ? result[0] : -1);
2835 if (DBG) log("getPreferredNetworkType: " + networkType);
2836 return networkType;
2837 }
2838
2839 /**
2840 * Set the preferred network type.
2841 * Used for device configuration by some CDMA operators.
2842 *
2843 * @param networkType the preferred network type, defined in RILConstants.java.
2844 * @return true on success; false on any failure.
2845 */
2846 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002847 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2849 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002850 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2851 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002852 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002853 if (success) {
2854 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002855 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002856 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002857 return success;
2858 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002859
2860 /**
Junda Liu475951f2014-11-07 16:45:03 -08002861 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2862 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2863 * tethering.
2864 *
2865 * @return 0: Not required. 1: required. 2: Not set.
2866 * @hide
2867 */
2868 @Override
2869 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002870 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002871 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2872 Settings.Global.TETHER_DUN_REQUIRED, 2);
2873 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2874 // config_tether_apndata.
2875 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2876 dunRequired = 1;
2877 }
2878 return dunRequired;
2879 }
2880
2881 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002882 * Set mobile data enabled
2883 * Used by the user through settings etc to turn on/off mobile data
2884 *
2885 * @param enable {@code true} turn turn data on, else {@code false}
2886 */
2887 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002888 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002889 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2890 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002891 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002892 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002893 Phone phone = PhoneFactory.getPhone(phoneId);
2894 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002895 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2896 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002897 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002898 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002899 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002900 }
2901
2902 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002903 * Get the user enabled state of Mobile Data.
2904 *
2905 * TODO: remove and use isUserDataEnabled.
2906 * This can't be removed now because some vendor codes
2907 * calls through ITelephony directly while they should
2908 * use TelephonyManager.
2909 *
2910 * @return true on enabled
2911 */
2912 @Override
2913 public boolean getDataEnabled(int subId) {
2914 return isUserDataEnabled(subId);
2915 }
2916
2917 /**
2918 * Get whether mobile data is enabled per user setting.
2919 *
2920 * There are other factors deciding whether mobile data is actually enabled, but they are
2921 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002922 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002923 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002924 *
2925 * @return {@code true} if data is enabled else {@code false}
2926 */
2927 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002928 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002929 try {
2930 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2931 null);
2932 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2934 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002935 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002936 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002937 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002938 Phone phone = PhoneFactory.getPhone(phoneId);
2939 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002940 boolean retVal = phone.isUserDataEnabled();
2941 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002942 return retVal;
2943 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002944 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2945 return false;
2946 }
2947 }
2948
2949 /**
2950 * Get whether mobile data is enabled.
2951 *
2952 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2953 * whether mobile data is actually enabled.
2954 *
2955 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2956 *
2957 * @return {@code true} if data is enabled else {@code false}
2958 */
2959 @Override
2960 public boolean isDataEnabled(int subId) {
2961 try {
2962 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2963 null);
2964 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2966 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08002967 }
2968 int phoneId = mSubscriptionController.getPhoneId(subId);
2969 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2970 Phone phone = PhoneFactory.getPhone(phoneId);
2971 if (phone != null) {
2972 boolean retVal = phone.isDataEnabled();
2973 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2974 return retVal;
2975 } else {
2976 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002977 return false;
2978 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002979 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002980
2981 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002982 public int getCarrierPrivilegeStatus(int subId) {
2983 final Phone phone = getPhone(subId);
2984 if (phone == null) {
2985 loge("getCarrierPrivilegeStatus: Invalid subId");
2986 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2987 }
2988 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002989 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002990 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002991 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2992 }
2993 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002994 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002995 }
Junda Liu29340342014-07-10 15:23:27 -07002996
2997 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08002998 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
2999 final Phone phone = getPhone(subId);
3000 if (phone == null) {
3001 loge("getCarrierPrivilegeStatus: Invalid subId");
3002 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3003 }
3004 UiccProfile profile =
3005 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3006 if (profile == null) {
3007 loge("getCarrierPrivilegeStatus: No UICC");
3008 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3009 }
3010 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3011 }
3012
3013 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003014 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003015 if (TextUtils.isEmpty(pkgName))
3016 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003017 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003018 if (card == null) {
3019 loge("checkCarrierPrivilegesForPackage: No UICC");
3020 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3021 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003022 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3023 }
3024
3025 @Override
3026 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003027 if (TextUtils.isEmpty(pkgName))
3028 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003029 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3030 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3031 UiccCard card = UiccController.getInstance().getUiccCard(i);
3032 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003033 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003034 continue;
3035 }
3036
3037 result = card.getCarrierPrivilegeStatus(
3038 mPhone.getContext().getPackageManager(), pkgName);
3039 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3040 break;
3041 }
3042 }
3043
3044 return result;
Junda Liu29340342014-07-10 15:23:27 -07003045 }
Derek Tan89e89d42014-07-08 17:00:10 -07003046
3047 @Override
Junda Liue64de782015-04-16 17:19:16 -07003048 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3049 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3050 loge("phoneId " + phoneId + " is not valid.");
3051 return null;
3052 }
3053 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003054 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003055 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003056 return null ;
3057 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003058 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003059 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003060 }
3061
Amith Yamasani6e118872016-02-19 12:53:51 -08003062 @Override
3063 public List<String> getPackagesWithCarrierPrivileges() {
3064 PackageManager pm = mPhone.getContext().getPackageManager();
3065 List<String> privilegedPackages = new ArrayList<>();
3066 List<PackageInfo> packages = null;
3067 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3068 UiccCard card = UiccController.getInstance().getUiccCard(i);
3069 if (card == null) {
3070 // No UICC in that slot.
3071 continue;
3072 }
3073 if (card.hasCarrierPrivilegeRules()) {
3074 if (packages == null) {
3075 // Only check packages in user 0 for now
3076 packages = pm.getInstalledPackagesAsUser(
3077 PackageManager.MATCH_DISABLED_COMPONENTS
3078 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3079 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3080 }
3081 for (int p = packages.size() - 1; p >= 0; p--) {
3082 PackageInfo pkgInfo = packages.get(p);
3083 if (pkgInfo != null && pkgInfo.packageName != null
3084 && card.getCarrierPrivilegeStatus(pkgInfo)
3085 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3086 privilegedPackages.add(pkgInfo.packageName);
3087 }
3088 }
3089 }
3090 }
3091 return privilegedPackages;
3092 }
3093
Wink Savilleb564aae2014-10-23 10:18:09 -07003094 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003095 final Phone phone = getPhone(subId);
3096 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003097 if (card == null) {
3098 loge("getIccId: No UICC");
3099 return null;
3100 }
3101 String iccId = card.getIccId();
3102 if (TextUtils.isEmpty(iccId)) {
3103 loge("getIccId: ICC ID is null or empty.");
3104 return null;
3105 }
3106 return iccId;
3107 }
3108
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003109 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003110 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3111 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003112 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3113 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003114
Jeff Sharkey85190e62014-12-05 09:40:12 -08003115 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003116 final Phone phone = getPhone(subId);
3117 if (phone == null) {
3118 return false;
3119 }
3120 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003121
3122 if (DBG_MERGE) {
3123 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3124 + subscriberId + " to " + number);
3125 }
3126
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003127 if (TextUtils.isEmpty(iccId)) {
3128 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003129 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003130
Jeff Sharkey85190e62014-12-05 09:40:12 -08003131 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3132
3133 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003134 if (alphaTag == null) {
3135 editor.remove(alphaTagPrefKey);
3136 } else {
3137 editor.putString(alphaTagPrefKey, alphaTag);
3138 }
3139
Jeff Sharkey85190e62014-12-05 09:40:12 -08003140 // Record both the line number and IMSI for this ICCID, since we need to
3141 // track all merged IMSIs based on line number
3142 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3143 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003144 if (number == null) {
3145 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003146 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003147 } else {
3148 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003149 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003150 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003151
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003152 editor.commit();
3153 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003154 }
3155
3156 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003157 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003158 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003159 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003160 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003161 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003162 return null;
3163 }
Derek Tan97ebb422014-09-05 16:55:38 -07003164
3165 String iccId = getIccId(subId);
3166 if (iccId != null) {
3167 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003168 if (DBG_MERGE) {
3169 log("getLine1NumberForDisplay returning " +
3170 mTelephonySharedPreferences.getString(numberPrefKey, null));
3171 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003172 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003173 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003174 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003175 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003176 }
3177
3178 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003179 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003181 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003182 return null;
3183 }
Derek Tan97ebb422014-09-05 16:55:38 -07003184
3185 String iccId = getIccId(subId);
3186 if (iccId != null) {
3187 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003188 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003189 }
Derek Tan97ebb422014-09-05 16:55:38 -07003190 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003191 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003192
3193 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003194 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003195 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3196 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003198 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3199 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003200 return null;
3201 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003202 final Context context = mPhone.getContext();
3203 final TelephonyManager tele = TelephonyManager.from(context);
3204 final SubscriptionManager sub = SubscriptionManager.from(context);
3205
3206 // Figure out what subscribers are currently active
3207 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003208 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3209 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 final int[] subIds = sub.getActiveSubscriptionIdList();
3213 for (int subId : subIds) {
3214 activeSubscriberIds.add(tele.getSubscriberId(subId));
3215 }
3216 } finally {
3217 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003218 }
3219
3220 // First pass, find a number override for an active subscriber
3221 String mergeNumber = null;
3222 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3223 for (String key : prefs.keySet()) {
3224 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3225 final String subscriberId = (String) prefs.get(key);
3226 if (activeSubscriberIds.contains(subscriberId)) {
3227 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3228 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3229 mergeNumber = (String) prefs.get(numberKey);
3230 if (DBG_MERGE) {
3231 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3232 + " for active subscriber " + subscriberId);
3233 }
3234 if (!TextUtils.isEmpty(mergeNumber)) {
3235 break;
3236 }
3237 }
3238 }
3239 }
3240
3241 // Shortcut when no active merged subscribers
3242 if (TextUtils.isEmpty(mergeNumber)) {
3243 return null;
3244 }
3245
3246 // Second pass, find all subscribers under that line override
3247 final ArraySet<String> result = new ArraySet<>();
3248 for (String key : prefs.keySet()) {
3249 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3250 final String number = (String) prefs.get(key);
3251 if (mergeNumber.equals(number)) {
3252 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3253 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3254 final String subscriberId = (String) prefs.get(subscriberKey);
3255 if (!TextUtils.isEmpty(subscriberId)) {
3256 result.add(subscriberId);
3257 }
3258 }
3259 }
3260 }
3261
3262 final String[] resultArray = result.toArray(new String[result.size()]);
3263 Arrays.sort(resultArray);
3264 if (DBG_MERGE) {
3265 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3266 }
3267 return resultArray;
3268 }
3269
3270 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003271 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003272 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3273 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003274 final Phone phone = getPhone(subId);
3275 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003276 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003277
3278 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003279 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003280 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3281 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003282 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003283 final Phone phone = getPhone(subId);
3284 if (phone == null) {
3285 return false;
3286 }
3287 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003288 cdmaNonRoamingList);
3289 }
3290
3291 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003292 public void setRadioCapability(RadioAccessFamily[] rafs) {
3293 try {
3294 ProxyController.getInstance().setRadioCapability(rafs);
3295 } catch (RuntimeException e) {
3296 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3297 }
3298 }
3299
3300 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003301 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003302 Phone phone = PhoneFactory.getPhone(phoneId);
3303 if (phone == null) {
3304 return RadioAccessFamily.RAF_UNKNOWN;
3305 }
3306 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003308 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003309 return RadioAccessFamily.RAF_UNKNOWN;
3310 }
3311
Wink Saville5d475dd2014-10-17 15:00:58 -07003312 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3313 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003314
3315 @Override
3316 public void enableVideoCalling(boolean enable) {
3317 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003318 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003319 }
3320
3321 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003322 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3324 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3325 return false;
3326 }
Svet Ganovb320e182015-04-16 12:30:10 -07003327
Andrew Lee77527ac2014-10-21 16:57:39 -07003328 // Check the user preference and the system-level IMS setting. Even if the user has
3329 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3330 // In the long run, we may instead need to check if there exists a connection service
3331 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003332 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3333 return imsManager.isVtEnabledByPlatform()
3334 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3335 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003336 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003337
Andrew Leea1239f22015-03-02 17:44:07 -08003338 @Override
3339 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003340 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003341 }
3342
3343 @Override
3344 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003345 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003346 }
3347
Andrew Lee9431b832015-03-09 18:46:45 -07003348 @Override
3349 public boolean isTtyModeSupported() {
3350 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3351 TelephonyManager telephonyManager =
3352 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003353 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003354 }
3355
3356 @Override
3357 public boolean isHearingAidCompatibilitySupported() {
3358 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3359 }
3360
Hall Liu98187582018-01-22 19:15:32 -08003361 public boolean isRttSupported() {
3362 boolean isCarrierSupported =
3363 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3364 boolean isDeviceSupported =
3365 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3366 return isCarrierSupported && isDeviceSupported;
3367 }
3368
Sanket Padawe7310cc72015-01-14 09:53:20 -08003369 /**
3370 * Returns the unique device ID of phone, for example, the IMEI for
3371 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3372 *
3373 * <p>Requires Permission:
3374 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3375 */
3376 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003377 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003378 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08003379 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003380 return null;
3381 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003382 int subId = phone.getSubId();
3383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3384 mApp, subId, callingPackage, "getDeviceId")) {
3385 return null;
3386 }
3387 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003388 }
3389
Ping Sunc67b7c22016-03-02 19:16:45 +08003390 /**
3391 * {@hide}
3392 * Returns the IMS Registration Status on a particular subid
3393 *
3394 * @param subId
3395 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003396 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003397 Phone phone = getPhone(subId);
3398 if (phone != null) {
3399 return phone.isImsRegistered();
3400 } else {
3401 return false;
3402 }
3403 }
3404
Santos Cordon7a1885b2015-02-03 11:15:19 -08003405 @Override
3406 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3407 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3408 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003409
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003410 /**
3411 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003412 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003413 public boolean isWifiCallingAvailable(int subId) {
3414 Phone phone = getPhone(subId);
3415 if (phone != null) {
3416 return phone.isWifiCallingEnabled();
3417 } else {
3418 return false;
3419 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003420 }
3421
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003422 /**
3423 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003424 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003425 public boolean isVolteAvailable(int subId) {
3426 Phone phone = getPhone(subId);
3427 if (phone != null) {
3428 return phone.isVolteEnabled();
3429 } else {
3430 return false;
3431 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003432 }
Svet Ganovb320e182015-04-16 12:30:10 -07003433
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003434 /**
3435 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003436 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003437 public boolean isVideoTelephonyAvailable(int subId) {
3438 Phone phone = getPhone(subId);
3439 if (phone != null) {
3440 return phone.isVideoEnabled();
3441 } else {
3442 return false;
3443 }
3444 }
3445
3446 /**
3447 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3448 * defined in {@link ImsRegistrationImplBase}.
3449 */
3450 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3451 Phone phone = getPhone(subId);
3452 if (phone != null) {
3453 return phone.getImsRegistrationTech();
3454 } else {
3455 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3456 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003457 }
3458
Stuart Scott8eef64f2015-04-08 15:13:54 -07003459 @Override
3460 public void factoryReset(int subId) {
3461 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003462 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3463 return;
3464 }
3465
Svet Ganovcc087f82015-05-12 20:35:54 -07003466 final long identity = Binder.clearCallingIdentity();
3467 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003468 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3469 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07003470 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07003471 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07003472 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
3473 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07003474 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003475 }
3476 } finally {
3477 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003478 }
3479 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003480
3481 @Override
3482 public String getLocaleFromDefaultSim() {
3483 // We query all subscriptions instead of just the active ones, because
3484 // this might be called early on in the provisioning flow when the
3485 // subscriptions potentially aren't active yet.
3486 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3487 if (slist == null || slist.isEmpty()) {
3488 return null;
3489 }
3490
3491 // This function may be called very early, say, from the setup wizard, at
3492 // which point we won't have a default subscription set. If that's the case
3493 // we just choose the first, which will be valid in "most cases".
3494 final int defaultSubId = getDefaultSubscription();
3495 SubscriptionInfo info = null;
3496 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3497 info = slist.get(0);
3498 } else {
3499 for (SubscriptionInfo item : slist) {
3500 if (item.getSubscriptionId() == defaultSubId) {
3501 info = item;
3502 break;
3503 }
3504 }
3505
3506 if (info == null) {
3507 return null;
3508 }
3509 }
3510
3511 // Try and fetch the locale from the carrier properties or from the SIM language
3512 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003513 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003514 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003515 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003516 if (defaultPhone != null) {
3517 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3518 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003519 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003520 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3521 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003522 } else {
3523 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003524 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003525 }
3526 }
3527
Narayan Kamath011676f2015-07-29 12:04:08 +01003528 // The SIM language preferences only store a language (e.g. fr = French), not an
3529 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3530 // the SIM and carrier preferences does not include a country we add the country
3531 // determined from the SIM MCC to provide an exact locale.
3532 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003533 if (mccLocale != null) {
3534 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3535 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003536 }
3537
Tony Hill183b2de2015-06-24 14:53:58 +01003538 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003539 return null;
3540 }
3541
3542 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 return mSubscriptionController.getAllSubInfoList(
3546 mPhone.getContext().getOpPackageName());
3547 } finally {
3548 Binder.restoreCallingIdentity(identity);
3549 }
3550 }
3551
3552 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3553 final long identity = Binder.clearCallingIdentity();
3554 try {
3555 return mSubscriptionController.getActiveSubscriptionInfoList(
3556 mPhone.getContext().getOpPackageName());
3557 } finally {
3558 Binder.restoreCallingIdentity(identity);
3559 }
3560 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003561
Chenjie Yu1ba97252018-01-11 18:16:20 -08003562 private final ModemActivityInfo mLastModemActivityInfo =
3563 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3564
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003565 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003566 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3567 * representing the state of the modem.
3568 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003569 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3570 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003571 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003572 */
3573 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003574 public void requestModemActivityInfo(ResultReceiver result) {
3575 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003576 ModemActivityInfo ret = null;
3577 synchronized (mLastModemActivityInfo) {
3578 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3579 null);
3580 if (info != null) {
3581 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3582 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3583 mergedTxTimeMs[i] =
3584 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3585 }
3586 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3587 mLastModemActivityInfo.setSleepTimeMillis(
3588 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3589 mLastModemActivityInfo.setIdleTimeMillis(
3590 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3591 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3592 mLastModemActivityInfo.setRxTimeMillis(
3593 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3594 mLastModemActivityInfo.setEnergyUsed(
3595 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3596 }
3597 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3598 mLastModemActivityInfo.getSleepTimeMillis(),
3599 mLastModemActivityInfo.getIdleTimeMillis(),
3600 mLastModemActivityInfo.getTxTimeMillis(),
3601 mLastModemActivityInfo.getRxTimeMillis(),
3602 mLastModemActivityInfo.getEnergyUsed());
3603 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003604 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003605 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003606 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003607 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003608
3609 /**
3610 * {@hide}
3611 * Returns the service state information on specified subscription.
3612 */
3613 @Override
3614 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3615
Jeff Davidson7e17e312018-02-13 18:17:36 -08003616 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003617 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003618 return null;
3619 }
3620
3621 final Phone phone = getPhone(subId);
3622 if (phone == null) {
3623 return null;
3624 }
3625
3626 return phone.getServiceState();
3627 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003628
3629 /**
3630 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3631 *
3632 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3633 * voicemail ringtone.
3634 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3635 * PhoneAccount.
3636 */
3637 @Override
3638 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003639 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003640 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003641 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003642 }
3643
fionaxu7ed723d2017-05-30 18:58:54 -07003644 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003645 }
3646
3647 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003648 * Sets the per-account voicemail ringtone.
3649 *
3650 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3651 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3652 *
3653 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3654 * voicemail ringtone.
3655 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3656 * PhoneAccount.
3657 */
3658 @Override
3659 public void setVoicemailRingtoneUri(String callingPackage,
3660 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3661 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3662 if (!TextUtils.equals(callingPackage,
3663 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3665 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3666 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003667 }
3668 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3669 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003670 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003671 }
fionaxu7ed723d2017-05-30 18:58:54 -07003672 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003673 }
3674
3675 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003676 * Returns whether vibration is set for voicemail notification in Phone settings.
3677 *
3678 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3679 * voicemail vibration setting.
3680 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3681 */
3682 @Override
3683 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003684 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003685 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003686 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003687 }
3688
fionaxu7ed723d2017-05-30 18:58:54 -07003689 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003690 }
3691
Youhan Wange64578a2016-05-02 15:32:42 -07003692 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003693 * Sets the per-account voicemail vibration.
3694 *
3695 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3696 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3697 *
3698 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3699 * voicemail vibration setting.
3700 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3701 * specific PhoneAccount.
3702 */
3703 @Override
3704 public void setVoicemailVibrationEnabled(String callingPackage,
3705 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3706 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3707 if (!TextUtils.equals(callingPackage,
3708 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3710 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3711 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003712 }
3713
3714 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3715 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003716 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003717 }
fionaxu7ed723d2017-05-30 18:58:54 -07003718 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003719 }
3720
3721 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003722 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3723 *
3724 * @throws SecurityException if the caller does not have the required permission
3725 */
3726 private void enforceReadPrivilegedPermission() {
3727 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3728 null);
3729 }
3730
3731 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003732 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3733 * permission.
3734 *
3735 * @throws SecurityException if the caller does not have the required permission
3736 */
3737 private void enforceSendSmsPermission() {
3738 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3739 }
3740
3741 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003742 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003743 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003744 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003745 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003746 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003747 ComponentName componentName =
3748 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3749 if(componentName == null) {
3750 throw new SecurityException("Caller not current active visual voicemail package[null]");
3751 }
3752 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003753 if (!callingPackage.equals(vvmPackage)) {
3754 throw new SecurityException("Caller not current active visual voicemail package[" +
3755 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003756 }
3757 }
3758
3759 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003760 * Return the application ID for the app type.
3761 *
3762 * @param subId the subscription ID that this request applies to.
3763 * @param appType the uicc app type.
3764 * @return Application ID for specificied app type, or null if no uicc.
3765 */
3766 @Override
3767 public String getAidForAppType(int subId, int appType) {
3768 enforceReadPrivilegedPermission();
3769 Phone phone = getPhone(subId);
3770 if (phone == null) {
3771 return null;
3772 }
3773 String aid = null;
3774 try {
3775 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3776 .getApplicationByType(appType).getAid();
3777 } catch (Exception e) {
3778 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3779 }
3780 return aid;
3781 }
3782
Youhan Wang4001d252016-05-11 10:29:41 -07003783 /**
3784 * Return the Electronic Serial Number.
3785 *
3786 * @param subId the subscription ID that this request applies to.
3787 * @return ESN or null if error.
3788 */
3789 @Override
3790 public String getEsn(int subId) {
3791 enforceReadPrivilegedPermission();
3792 Phone phone = getPhone(subId);
3793 if (phone == null) {
3794 return null;
3795 }
3796 String esn = null;
3797 try {
3798 esn = phone.getEsn();
3799 } catch (Exception e) {
3800 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3801 }
3802 return esn;
3803 }
3804
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003805 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003806 * Return the Preferred Roaming List Version.
3807 *
3808 * @param subId the subscription ID that this request applies to.
3809 * @return PRLVersion or null if error.
3810 */
3811 @Override
3812 public String getCdmaPrlVersion(int subId) {
3813 enforceReadPrivilegedPermission();
3814 Phone phone = getPhone(subId);
3815 if (phone == null) {
3816 return null;
3817 }
3818 String cdmaPrlVersion = null;
3819 try {
3820 cdmaPrlVersion = phone.getCdmaPrlVersion();
3821 } catch (Exception e) {
3822 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3823 }
3824 return cdmaPrlVersion;
3825 }
3826
3827 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003828 * Get snapshot of Telephony histograms
3829 * @return List of Telephony histograms
3830 * @hide
3831 */
3832 @Override
3833 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3835 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003836 return RIL.getTelephonyRILTimingHistograms();
3837 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003838
3839 /**
3840 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003841 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003842 * Require system privileges. In the future we may add this to carrier APIs.
3843 *
3844 * @return The number of carriers set successfully, should match length of carriers
3845 */
3846 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003847 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003848 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003849
Meng Wang9b7c4e92017-02-17 11:41:27 -08003850 if (carriers == null) {
3851 throw new NullPointerException("carriers cannot be null");
3852 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003853
3854 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003855 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3856 return retVal[0];
3857 }
3858
3859 /**
3860 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003861 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003862 * Require system privileges. In the future we may add this to carrier APIs.
3863 *
3864 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3865 * means all carriers are allowed.
3866 */
3867 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003868 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003869 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003870 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003871 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3872 }
3873
fionaxu59545b42016-05-25 15:53:37 -07003874 /**
3875 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3876 * @param subId the subscription ID that this action applies to.
3877 * @param enabled control enable or disable metered apns.
3878 * {@hide}
3879 */
3880 @Override
3881 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3882 enforceModifyPermission();
3883 final Phone phone = getPhone(subId);
3884 if (phone == null) {
3885 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3886 return;
3887 }
3888 try {
3889 phone.carrierActionSetMeteredApnsEnabled(enabled);
3890 } catch (Exception e) {
3891 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3892 }
3893 }
3894
3895 /**
3896 * Action set from carrier signalling broadcast receivers to enable/disable radio
3897 * @param subId the subscription ID that this action applies to.
3898 * @param enabled control enable or disable radio.
3899 * {@hide}
3900 */
3901 @Override
3902 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3903 enforceModifyPermission();
3904 final Phone phone = getPhone(subId);
3905 if (phone == null) {
3906 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3907 return;
3908 }
3909 try {
3910 phone.carrierActionSetRadioEnabled(enabled);
3911 } catch (Exception e) {
3912 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3913 }
3914 }
3915
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003916 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003917 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3918 * network status based on which carrier apps could apply actions accordingly,
3919 * enable/disable default url handler for example.
3920 *
3921 * @param subId the subscription ID that this action applies to.
3922 * @param report control start/stop reporting the default network status.
3923 * {@hide}
3924 */
3925 @Override
3926 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3927 enforceModifyPermission();
3928 final Phone phone = getPhone(subId);
3929 if (phone == null) {
3930 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3931 return;
3932 }
3933 try {
3934 phone.carrierActionReportDefaultNetworkStatus(report);
3935 } catch (Exception e) {
3936 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3937 }
3938 }
3939
3940 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003941 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3942 * bug report is being generated.
3943 */
3944 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003945 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003946 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3947 != PackageManager.PERMISSION_GRANTED) {
3948 writer.println("Permission Denial: can't dump Phone from pid="
3949 + Binder.getCallingPid()
3950 + ", uid=" + Binder.getCallingUid()
3951 + "without permission "
3952 + android.Manifest.permission.DUMP);
3953 return;
3954 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003955 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003956 }
Jack Yueb89b242016-06-22 13:27:47 -07003957
3958 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003959 * Get aggregated video call data usage since boot.
3960 *
3961 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3962 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003963 * {@hide}
3964 */
3965 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003966 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003967 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3968 null);
3969
Jack Yu84291ec2017-05-26 16:07:50 -07003970 // NetworkStatsService keeps tracking the active network interface and identity. It
3971 // records the delta with the corresponding network identity. We just return the total video
3972 // call data usage snapshot since boot.
3973 Phone phone = getPhone(subId);
3974 if (phone != null) {
3975 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003976 }
Jack Yu84291ec2017-05-26 16:07:50 -07003977 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003978 }
Jack Yu75ab2952016-07-08 14:29:33 -07003979
3980 /**
3981 * Policy control of data connection. Usually used when data limit is passed.
3982 * @param enabled True if enabling the data, otherwise disabling.
3983 * @param subId Subscription index
3984 * {@hide}
3985 */
3986 @Override
3987 public void setPolicyDataEnabled(boolean enabled, int subId) {
3988 enforceModifyPermission();
3989 Phone phone = getPhone(subId);
3990 if (phone != null) {
3991 phone.setPolicyDataEnabled(enabled);
3992 }
3993 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003994
3995 /**
3996 * Get Client request stats
3997 * @return List of Client Request Stats
3998 * @hide
3999 */
4000 @Override
4001 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004003 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004004 return null;
4005 }
4006
4007 Phone phone = getPhone(subId);
4008 if (phone != null) {
4009 return phone.getClientRequestStats();
4010 }
4011
4012 return null;
4013 }
4014
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004015 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004016 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004017 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004018 }
Jack Yueb4124c2017-02-16 15:32:43 -08004019
4020 /**
Grace Chen70990072017-03-24 17:21:30 -07004021 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004022 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004023 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004024 * @param state State of SIM (power down, power up, pass through)
4025 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4026 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4027 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004028 *
4029 **/
4030 @Override
Grace Chen70990072017-03-24 17:21:30 -07004031 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004032 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004033 Phone phone = PhoneFactory.getPhone(slotIndex);
4034
Jack Yueb4124c2017-02-16 15:32:43 -08004035 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004036 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004037 }
4038 }
Shuo Qiandd210312017-04-12 22:11:33 +00004039
Tyler Gunn65d45c22017-06-05 11:22:26 -07004040 private boolean isUssdApiAllowed(int subId) {
4041 CarrierConfigManager configManager =
4042 (CarrierConfigManager) mPhone.getContext().getSystemService(
4043 Context.CARRIER_CONFIG_SERVICE);
4044 if (configManager == null) {
4045 return false;
4046 }
4047 PersistableBundle pb = configManager.getConfigForSubId(subId);
4048 if (pb == null) {
4049 return false;
4050 }
4051 return pb.getBoolean(
4052 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4053 }
4054
Shuo Qiandd210312017-04-12 22:11:33 +00004055 /**
4056 * Check if phone is in emergency callback mode
4057 * @return true if phone is in emergency callback mode
4058 * @param subId sub id
4059 */
goneil9c5f4872017-12-05 14:07:56 -08004060 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004061 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004062 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004063 final Phone phone = getPhone(subId);
4064 if (phone != null) {
4065 return phone.isInEcm();
4066 } else {
4067 return false;
4068 }
4069 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004070
4071 /**
4072 * Get the current signal strength information for the given subscription.
4073 * Because this information is not updated when the device is in a low power state
4074 * it should not be relied-upon to be current.
4075 * @param subId Subscription index
4076 * @return the most recent cached signal strength info from the modem
4077 */
4078 @Override
4079 public SignalStrength getSignalStrength(int subId) {
4080 Phone p = getPhone(subId);
4081 if (p == null) {
4082 return null;
4083 }
4084
4085 return p.getSignalStrength();
4086 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004087
4088 @Override
4089 public UiccSlotInfo[] getUiccSlotsInfo() {
4090 enforceReadPrivilegedPermission();
4091
4092 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4093 if (slots == null) return null;
4094 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4095 for (int i = 0; i < slots.length; i++) {
4096 UiccSlot slot = slots[i];
4097
4098 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4099
4100 int cardState = 0;
4101 switch (slot.getCardState()) {
4102 case CARDSTATE_ABSENT:
4103 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4104 break;
4105 case CARDSTATE_PRESENT:
4106 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4107 break;
4108 case CARDSTATE_ERROR:
4109 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4110 break;
4111 case CARDSTATE_RESTRICTED:
4112 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4113 break;
4114 default:
4115 break;
4116
4117 }
4118
Qingxi Li795c5882018-01-31 13:43:27 -08004119 infos[i] = new UiccSlotInfo(
Qingxi Lie7245372018-03-07 10:52:26 -08004120 slot.isActive(),
4121 slot.isEuicc(),
4122 cardId,
4123 cardState,
4124 slot.getPhoneId(),
4125 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004126 }
4127 return infos;
4128 }
4129
4130 @Override
4131 public boolean switchSlots(int[] physicalSlots) {
4132 enforceModifyPermission();
4133 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4134 }
Jack Yu4c988042018-02-27 15:30:01 -08004135
4136 @Override
4137 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4138 enforceModifyPermission();
4139 final Phone phone = getPhone(subId);
4140 if (phone == null) {
4141 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4142 return;
4143 }
4144
4145 phone.setRadioIndicationUpdateMode(filters, mode);
4146 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07004147
4148 /**
4149 * Returns false if the mobile data is disabled by default, otherwise return true.
4150 */
4151 private boolean getDefaultDataEnabled() {
4152 return "true".equalsIgnoreCase(
4153 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
4154 }
4155
4156 /**
4157 * Returns true if the data roaming is enabled by default, i.e the system property
4158 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
4159 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
4160 */
4161 private boolean getDefaultDataRoamingEnabled(int subId) {
4162 final CarrierConfigManager configMgr = (CarrierConfigManager)
4163 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
4164 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
4165 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
4166 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
4167 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
4168 return isDataRoamingEnabled;
4169 }
4170
4171 /**
4172 * Returns the default network type for the given {@code subId}, if the default network type is
4173 * not set, return {@link Phone#PREFERRED_NT_MODE}.
4174 */
4175 private int getDefaultNetworkType(int subId) {
4176 return Integer.parseInt(
4177 TelephonyManager.getTelephonyProperty(
4178 mSubscriptionController.getPhoneId(subId),
4179 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
4180 String.valueOf(Phone.PREFERRED_NT_MODE)));
4181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004182}