blob: 8d1df85e7e1f10e18fe7e200113b62bff66e13a9 [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;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000170 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
171 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700172 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
173 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
174 private static final int CMD_EXCHANGE_SIM_IO = 31;
175 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800176 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
177 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700178 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
179 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700180 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
181 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700182 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
183 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
184 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
185 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700186 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
187 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
188 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
189 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700190 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800191 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
192 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000193 private static final int CMD_SWITCH_SLOTS = 50;
194 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800196 // Parameters of select command.
197 private static final int SELECT_COMMAND = 0xA4;
198 private static final int SELECT_P1 = 0x04;
199 private static final int SELECT_P2 = 0;
200 private static final int SELECT_P3 = 0x10;
201
Pengquan Meng85728fb2018-03-12 16:31:21 -0700202 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
203 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
204 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
205
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700206 /** The singleton instance. */
207 private static PhoneInterfaceManager sInstance;
208
Wink Saville3ab207e2014-11-20 13:07:20 -0800209 private PhoneGlobals mApp;
210 private Phone mPhone;
211 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700212 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800213 private AppOpsManager mAppOps;
214 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800215 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800216 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217
Derek Tan97ebb422014-09-05 16:55:38 -0700218 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
219 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800220 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700221
Derek Tan740e1672017-06-27 14:56:27 -0700222 // The AID of ISD-R.
223 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
224
yinxub1bed742017-04-17 11:45:04 -0700225 private NetworkScanRequestTracker mNetworkScanRequestTracker;
226
Derek Tan89e89d42014-07-08 17:00:10 -0700227 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700228 * A request object to use for transmitting data to an ICC.
229 */
230 private static final class IccAPDUArgument {
231 public int channel, cla, command, p1, p2, p3;
232 public String data;
233
234 public IccAPDUArgument(int channel, int cla, int command,
235 int p1, int p2, int p3, String data) {
236 this.channel = channel;
237 this.cla = cla;
238 this.command = command;
239 this.p1 = p1;
240 this.p2 = p2;
241 this.p3 = p3;
242 this.data = data;
243 }
244 }
245
246 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700247 * A request object to use for transmitting data to an ICC.
248 */
249 private static final class ManualNetworkSelectionArgument {
250 public OperatorInfo operatorInfo;
251 public boolean persistSelection;
252
253 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
254 this.operatorInfo = operatorInfo;
255 this.persistSelection = persistSelection;
256 }
257 }
258
259 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700260 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
261 * request after sending. The main thread will notify the request when it is complete.
262 */
263 private static final class MainThreadRequest {
264 /** The argument to use for the request */
265 public Object argument;
266 /** The result of the request that is run on the main thread */
267 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800268 // The subscriber id that this request applies to. Defaults to
269 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
270 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271
272 public MainThreadRequest(Object argument) {
273 this.argument = argument;
274 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800275
276 public MainThreadRequest(Object argument, Integer subId) {
277 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800278 if (subId != null) {
279 this.subId = subId;
280 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700282 }
283
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800284 private static final class IncomingThirdPartyCallArgs {
285 public final ComponentName component;
286 public final String callId;
287 public final String callerDisplayName;
288
289 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
290 String callerDisplayName) {
291 this.component = component;
292 this.callId = callId;
293 this.callerDisplayName = callerDisplayName;
294 }
295 }
296
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297 /**
298 * A handler that processes messages on the main thread in the phone process. Since many
299 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
300 * inbound binder threads to the main thread in the phone process. The Binder thread
301 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
302 * on, which will be notified when the operation completes and will contain the result of the
303 * request.
304 *
305 * <p>If a MainThreadRequest object is provided in the msg.obj field,
306 * note that request.result must be set to something non-null for the calling thread to
307 * unblock.
308 */
309 private final class MainThreadHandler extends Handler {
310 @Override
311 public void handleMessage(Message msg) {
312 MainThreadRequest request;
313 Message onCompleted;
314 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800315 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700316 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700317
318 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700319 case CMD_HANDLE_USSD_REQUEST: {
320 request = (MainThreadRequest) msg.obj;
321 final Phone phone = getPhoneFromRequest(request);
322 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
323 String ussdRequest = ussdObject.first;
324 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700325
326 if (!isUssdApiAllowed(request.subId)) {
327 // Carrier does not support use of this API, return failure.
328 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
329 UssdResponse response = new UssdResponse(ussdRequest, null);
330 Bundle returnData = new Bundle();
331 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
332 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
333
334 request.result = true;
335 synchronized (request) {
336 request.notifyAll();
337 }
338 return;
339 }
340
Tyler Gunn52dcf772017-04-26 11:30:31 -0700341 try {
342 request.result = phone != null ?
343 phone.handleUssdRequest(ussdRequest, wrappedCallback)
344 : false;
345 } catch (CallStateException cse) {
346 request.result = false;
347 }
pkanwar32d516d2016-10-14 19:37:38 -0700348 // Wake up the requesting thread
349 synchronized (request) {
350 request.notifyAll();
351 }
352 break;
353 }
354
Yorke Lee716f67e2015-06-17 15:39:16 -0700355 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700357 final Phone phone = getPhoneFromRequest(request);
358 request.result = phone != null ?
359 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
360 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 // Wake up the requesting thread
362 synchronized (request) {
363 request.notifyAll();
364 }
365 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367
368 case CMD_HANDLE_NEIGHBORING_CELL:
369 request = (MainThreadRequest) msg.obj;
370 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
371 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700372 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 break;
374
375 case EVENT_NEIGHBORING_CELL_DONE:
376 ar = (AsyncResult) msg.obj;
377 request = (MainThreadRequest) ar.userObj;
378 if (ar.exception == null && ar.result != null) {
379 request.result = ar.result;
380 } else {
381 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800382 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 }
384 // Wake up the requesting thread
385 synchronized (request) {
386 request.notifyAll();
387 }
388 break;
389
390 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700391 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800392 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700393 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 break;
395
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 case CMD_END_CALL:
397 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800398 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700399 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700400 Phone phone = getPhone(end_subId);
401 if (phone == null) {
402 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
403 break;
404 }
405 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
407 // CDMA: If the user presses the Power button we treat it as
408 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700409 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
411 // GSM: End the call as per the Phone state
412 hungUp = PhoneUtils.hangup(mCM);
413 } else {
414 throw new IllegalStateException("Unexpected phone type: " + phoneType);
415 }
416 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
417 request.result = hungUp;
418 // Wake up the requesting thread
419 synchronized (request) {
420 request.notifyAll();
421 }
422 break;
423
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700424 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700425 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700426 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800427 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700428 if (uiccCard == null) {
429 loge("iccTransmitApduLogicalChannel: No UICC");
430 request.result = new IccIoResult(0x6F, 0, (byte[])null);
431 synchronized (request) {
432 request.notifyAll();
433 }
434 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700435 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
436 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700437 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700438 iccArgument.channel, iccArgument.cla, iccArgument.command,
439 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700440 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700441 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 break;
443
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700444 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 ar = (AsyncResult) msg.obj;
446 request = (MainThreadRequest) ar.userObj;
447 if (ar.exception == null && ar.result != null) {
448 request.result = ar.result;
449 } else {
450 request.result = new IccIoResult(0x6F, 0, (byte[])null);
451 if (ar.result == null) {
452 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800453 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800455 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 } else {
457 loge("iccTransmitApduLogicalChannel: Unknown exception");
458 }
459 }
460 synchronized (request) {
461 request.notifyAll();
462 }
463 break;
464
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
466 request = (MainThreadRequest) msg.obj;
467 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800468 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700469 if (uiccCard == null) {
470 loge("iccTransmitApduBasicChannel: No UICC");
471 request.result = new IccIoResult(0x6F, 0, (byte[])null);
472 synchronized (request) {
473 request.notifyAll();
474 }
475 } else {
476 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
477 request);
478 uiccCard.iccTransmitApduBasicChannel(
479 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
480 iccArgument.p3, iccArgument.data, onCompleted);
481 }
482 break;
483
484 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
485 ar = (AsyncResult) msg.obj;
486 request = (MainThreadRequest) ar.userObj;
487 if (ar.exception == null && ar.result != null) {
488 request.result = ar.result;
489 } else {
490 request.result = new IccIoResult(0x6F, 0, (byte[])null);
491 if (ar.result == null) {
492 loge("iccTransmitApduBasicChannel: Empty response");
493 } else if (ar.exception instanceof CommandException) {
494 loge("iccTransmitApduBasicChannel: CommandException: " +
495 ar.exception);
496 } else {
497 loge("iccTransmitApduBasicChannel: Unknown exception");
498 }
499 }
500 synchronized (request) {
501 request.notifyAll();
502 }
503 break;
504
505 case CMD_EXCHANGE_SIM_IO:
506 request = (MainThreadRequest) msg.obj;
507 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800508 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 if (uiccCard == null) {
510 loge("iccExchangeSimIO: No UICC");
511 request.result = new IccIoResult(0x6F, 0, (byte[])null);
512 synchronized (request) {
513 request.notifyAll();
514 }
515 } else {
516 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
517 request);
518 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
519 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
520 iccArgument.data, onCompleted);
521 }
522 break;
523
524 case EVENT_EXCHANGE_SIM_IO_DONE:
525 ar = (AsyncResult) msg.obj;
526 request = (MainThreadRequest) ar.userObj;
527 if (ar.exception == null && ar.result != null) {
528 request.result = ar.result;
529 } else {
530 request.result = new IccIoResult(0x6f, 0, (byte[])null);
531 }
532 synchronized (request) {
533 request.notifyAll();
534 }
535 break;
536
Derek Tan4d5e5c12014-02-04 11:54:58 -0800537 case CMD_SEND_ENVELOPE:
538 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800539 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700540 if (uiccCard == null) {
541 loge("sendEnvelopeWithStatus: No UICC");
542 request.result = new IccIoResult(0x6F, 0, (byte[])null);
543 synchronized (request) {
544 request.notifyAll();
545 }
546 } else {
547 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
548 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
549 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800550 break;
551
552 case EVENT_SEND_ENVELOPE_DONE:
553 ar = (AsyncResult) msg.obj;
554 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700555 if (ar.exception == null && ar.result != null) {
556 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800557 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700558 request.result = new IccIoResult(0x6F, 0, (byte[])null);
559 if (ar.result == null) {
560 loge("sendEnvelopeWithStatus: Empty response");
561 } else if (ar.exception instanceof CommandException) {
562 loge("sendEnvelopeWithStatus: CommandException: " +
563 ar.exception);
564 } else {
565 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
566 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800567 }
568 synchronized (request) {
569 request.notifyAll();
570 }
571 break;
572
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 case CMD_OPEN_CHANNEL:
574 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800575 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800576 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700577 if (uiccCard == null) {
578 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800579 request.result = new IccOpenLogicalChannelResponse(-1,
580 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 synchronized (request) {
582 request.notifyAll();
583 }
584 } else {
585 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800586 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
587 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 break;
590
591 case EVENT_OPEN_CHANNEL_DONE:
592 ar = (AsyncResult) msg.obj;
593 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 int[] result = (int[]) ar.result;
597 int channelId = result[0];
598 byte[] selectResponse = null;
599 if (result.length > 1) {
600 selectResponse = new byte[result.length - 1];
601 for (int i = 1; i < result.length; ++i) {
602 selectResponse[i - 1] = (byte) result[i];
603 }
604 }
605 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700606 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 if (ar.result == null) {
609 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 if (ar.exception != null) {
612 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
613 }
614
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700615 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700616 if (ar.exception instanceof CommandException) {
617 CommandException.Error error =
618 ((CommandException) (ar.exception)).getCommandError();
619 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700620 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700621 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 }
624 }
625 openChannelResp = new IccOpenLogicalChannelResponse(
626 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700628 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 synchronized (request) {
630 request.notifyAll();
631 }
632 break;
633
634 case CMD_CLOSE_CHANNEL:
635 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800636 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700637 if (uiccCard == null) {
638 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900639 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 synchronized (request) {
641 request.notifyAll();
642 }
643 } else {
644 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
645 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
646 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
649 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800650 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
651 break;
652
653 case CMD_NV_READ_ITEM:
654 request = (MainThreadRequest) msg.obj;
655 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
656 mPhone.nvReadItem((Integer) request.argument, onCompleted);
657 break;
658
659 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 ar = (AsyncResult) msg.obj;
661 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800662 if (ar.exception == null && ar.result != null) {
663 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800665 request.result = "";
666 if (ar.result == null) {
667 loge("nvReadItem: Empty response");
668 } else if (ar.exception instanceof CommandException) {
669 loge("nvReadItem: CommandException: " +
670 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800672 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 }
674 }
675 synchronized (request) {
676 request.notifyAll();
677 }
678 break;
679
Jake Hambye994d462014-02-03 13:10:13 -0800680 case CMD_NV_WRITE_ITEM:
681 request = (MainThreadRequest) msg.obj;
682 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
683 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
684 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
685 break;
686
687 case EVENT_NV_WRITE_ITEM_DONE:
688 handleNullReturnEvent(msg, "nvWriteItem");
689 break;
690
691 case CMD_NV_WRITE_CDMA_PRL:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
694 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
695 break;
696
697 case EVENT_NV_WRITE_CDMA_PRL_DONE:
698 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
699 break;
700
701 case CMD_NV_RESET_CONFIG:
702 request = (MainThreadRequest) msg.obj;
703 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
704 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
705 break;
706
707 case EVENT_NV_RESET_CONFIG_DONE:
708 handleNullReturnEvent(msg, "nvResetConfig");
709 break;
710
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 case CMD_GET_PREFERRED_NETWORK_TYPE:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700714 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800715 break;
716
717 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
718 ar = (AsyncResult) msg.obj;
719 request = (MainThreadRequest) ar.userObj;
720 if (ar.exception == null && ar.result != null) {
721 request.result = ar.result; // Integer
722 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800723 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 if (ar.result == null) {
725 loge("getPreferredNetworkType: Empty response");
726 } else if (ar.exception instanceof CommandException) {
727 loge("getPreferredNetworkType: CommandException: " +
728 ar.exception);
729 } else {
730 loge("getPreferredNetworkType: Unknown exception");
731 }
732 }
733 synchronized (request) {
734 request.notifyAll();
735 }
736 break;
737
738 case CMD_SET_PREFERRED_NETWORK_TYPE:
739 request = (MainThreadRequest) msg.obj;
740 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
741 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700742 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800743 break;
744
745 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
746 handleNullReturnEvent(msg, "setPreferredNetworkType");
747 break;
748
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000749 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
750 request = (MainThreadRequest)msg.obj;
751 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
752 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
753 break;
754
755 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
756 ar = (AsyncResult)msg.obj;
757 request = (MainThreadRequest)ar.userObj;
758 request.result = ar;
759 synchronized (request) {
760 request.notifyAll();
761 }
762 break;
763
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800764 case CMD_SET_VOICEMAIL_NUMBER:
765 request = (MainThreadRequest) msg.obj;
766 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
767 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800768 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
769 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800770 break;
771
772 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
773 handleNullReturnEvent(msg, "setVoicemailNumber");
774 break;
775
Stuart Scott54788802015-03-30 13:18:01 -0700776 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
779 request);
780 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
781 break;
782
783 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
784 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
785 break;
786
Shishir Agrawal302c8692015-06-19 13:49:39 -0700787 case CMD_PERFORM_NETWORK_SCAN:
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
790 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
791 break;
792
793 case EVENT_PERFORM_NETWORK_SCAN_DONE:
794 ar = (AsyncResult) msg.obj;
795 request = (MainThreadRequest) ar.userObj;
796 CellNetworkScanResult cellScanResult;
797 if (ar.exception == null && ar.result != null) {
798 cellScanResult = new CellNetworkScanResult(
799 CellNetworkScanResult.STATUS_SUCCESS,
800 (List<OperatorInfo>) ar.result);
801 } else {
802 if (ar.result == null) {
803 loge("getCellNetworkScanResults: Empty response");
804 }
805 if (ar.exception != null) {
806 loge("getCellNetworkScanResults: Exception: " + ar.exception);
807 }
808 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
809 if (ar.exception instanceof CommandException) {
810 CommandException.Error error =
811 ((CommandException) (ar.exception)).getCommandError();
812 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
813 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
814 } else if (error == CommandException.Error.GENERIC_FAILURE) {
815 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
816 }
817 }
818 cellScanResult = new CellNetworkScanResult(errorCode, null);
819 }
820 request.result = cellScanResult;
821 synchronized (request) {
822 request.notifyAll();
823 }
824 break;
825
826 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
827 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700828 ManualNetworkSelectionArgument selArg =
829 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
831 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700832 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
833 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700834 break;
835
836 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
837 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
838 break;
839
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700840 case CMD_GET_MODEM_ACTIVITY_INFO:
841 request = (MainThreadRequest) msg.obj;
842 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700843 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700844 break;
845
846 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
849 if (ar.exception == null && ar.result != null) {
850 request.result = ar.result;
851 } else {
852 if (ar.result == null) {
853 loge("queryModemActivityInfo: Empty response");
854 } else if (ar.exception instanceof CommandException) {
855 loge("queryModemActivityInfo: CommandException: " +
856 ar.exception);
857 } else {
858 loge("queryModemActivityInfo: Unknown exception");
859 }
860 }
Amit Mahajand4766222016-01-28 15:28:28 -0800861 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
862 if (request.result == null) {
863 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
864 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700865 synchronized (request) {
866 request.notifyAll();
867 }
868 break;
869
Meng Wang1a7c35a2016-05-05 20:56:15 -0700870 case CMD_SET_ALLOWED_CARRIERS:
871 request = (MainThreadRequest) msg.obj;
872 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
873 mPhone.setAllowedCarriers(
874 (List<CarrierIdentifier>) request.argument,
875 onCompleted);
876 break;
877
878 case EVENT_SET_ALLOWED_CARRIERS_DONE:
879 ar = (AsyncResult) msg.obj;
880 request = (MainThreadRequest) ar.userObj;
881 if (ar.exception == null && ar.result != null) {
882 request.result = ar.result;
883 } else {
884 if (ar.result == null) {
885 loge("setAllowedCarriers: Empty response");
886 } else if (ar.exception instanceof CommandException) {
887 loge("setAllowedCarriers: CommandException: " +
888 ar.exception);
889 } else {
890 loge("setAllowedCarriers: Unknown exception");
891 }
892 }
893 // Result cannot be null. Return -1 on error.
894 if (request.result == null) {
895 request.result = new int[]{-1};
896 }
897 synchronized (request) {
898 request.notifyAll();
899 }
900 break;
901
902 case CMD_GET_ALLOWED_CARRIERS:
903 request = (MainThreadRequest) msg.obj;
904 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
905 mPhone.getAllowedCarriers(onCompleted);
906 break;
907
908 case EVENT_GET_ALLOWED_CARRIERS_DONE:
909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
911 if (ar.exception == null && ar.result != null) {
912 request.result = ar.result;
913 } else {
914 if (ar.result == null) {
915 loge("getAllowedCarriers: Empty response");
916 } else if (ar.exception instanceof CommandException) {
917 loge("getAllowedCarriers: CommandException: " +
918 ar.exception);
919 } else {
920 loge("getAllowedCarriers: Unknown exception");
921 }
922 }
923 // Result cannot be null. Return empty list of CarrierIdentifier.
924 if (request.result == null) {
925 request.result = new ArrayList<CarrierIdentifier>(0);
926 }
927 synchronized (request) {
928 request.notifyAll();
929 }
930 break;
931
Nathan Haroldb3014052017-01-25 15:57:32 -0800932 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
933 ar = (AsyncResult) msg.obj;
934 request = (MainThreadRequest) ar.userObj;
935 if (ar.exception == null && ar.result != null) {
936 request.result = ar.result;
937 } else {
938 request.result = new IllegalArgumentException(
939 "Failed to retrieve Forbidden Plmns");
940 if (ar.result == null) {
941 loge("getForbiddenPlmns: Empty response");
942 } else {
943 loge("getForbiddenPlmns: Unknown exception");
944 }
945 }
946 synchronized (request) {
947 request.notifyAll();
948 }
949 break;
950
951 case CMD_GET_FORBIDDEN_PLMNS:
952 request = (MainThreadRequest) msg.obj;
953 uiccCard = getUiccCardFromRequest(request);
954 if (uiccCard == null) {
955 loge("getForbiddenPlmns() UiccCard is null");
956 request.result = new IllegalArgumentException(
957 "getForbiddenPlmns() UiccCard is null");
958 synchronized (request) {
959 request.notifyAll();
960 }
961 break;
962 }
963 Integer appType = (Integer) request.argument;
964 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
965 if (uiccApp == null) {
966 loge("getForbiddenPlmns() no app with specified type -- "
967 + appType);
968 request.result = new IllegalArgumentException("Failed to get UICC App");
969 synchronized (request) {
970 request.notifyAll();
971 }
972 break;
973 } else {
974 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
975 + " specified type -- " + appType);
976 }
977 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
978 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
979 onCompleted);
980 break;
981
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000982 case CMD_SWITCH_SLOTS:
983 request = (MainThreadRequest) msg.obj;
984 int[] physicalSlots = (int[]) request.argument;
985 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
986 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
987 break;
988
989 case EVENT_SWITCH_SLOTS_DONE:
990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
992 request.result = (ar.exception == null);
993 synchronized (request) {
994 request.notifyAll();
995 }
996 break;
997
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700998 default:
999 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1000 break;
1001 }
1002 }
Jake Hambye994d462014-02-03 13:10:13 -08001003
1004 private void handleNullReturnEvent(Message msg, String command) {
1005 AsyncResult ar = (AsyncResult) msg.obj;
1006 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1007 if (ar.exception == null) {
1008 request.result = true;
1009 } else {
1010 request.result = false;
1011 if (ar.exception instanceof CommandException) {
1012 loge(command + ": CommandException: " + ar.exception);
1013 } else {
1014 loge(command + ": Unknown exception");
1015 }
1016 }
1017 synchronized (request) {
1018 request.notifyAll();
1019 }
1020 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001021 }
1022
1023 /**
1024 * Posts the specified command to be executed on the main thread,
1025 * waits for the request to complete, and returns the result.
1026 * @see #sendRequestAsync
1027 */
1028 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001029 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001030 }
1031
1032 /**
1033 * Posts the specified command to be executed on the main thread,
1034 * waits for the request to complete, and returns the result.
1035 * @see #sendRequestAsync
1036 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001037 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001038 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1039 throw new RuntimeException("This method will deadlock if called from the main thread.");
1040 }
1041
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001042 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001043 Message msg = mMainThreadHandler.obtainMessage(command, request);
1044 msg.sendToTarget();
1045
1046 // Wait for the request to complete
1047 synchronized (request) {
1048 while (request.result == null) {
1049 try {
1050 request.wait();
1051 } catch (InterruptedException e) {
1052 // Do nothing, go back and wait until the request is complete
1053 }
1054 }
1055 }
1056 return request.result;
1057 }
1058
1059 /**
1060 * Asynchronous ("fire and forget") version of sendRequest():
1061 * Posts the specified command to be executed on the main thread, and
1062 * returns immediately.
1063 * @see #sendRequest
1064 */
1065 private void sendRequestAsync(int command) {
1066 mMainThreadHandler.sendEmptyMessage(command);
1067 }
1068
1069 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001070 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1071 * @see {@link #sendRequest(int,Object)}
1072 */
1073 private void sendRequestAsync(int command, Object argument) {
1074 MainThreadRequest request = new MainThreadRequest(argument);
1075 Message msg = mMainThreadHandler.obtainMessage(command, request);
1076 msg.sendToTarget();
1077 }
1078
1079 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001080 * Initialize the singleton PhoneInterfaceManager instance.
1081 * This is only done once, at startup, from PhoneApp.onCreate().
1082 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001083 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001084 synchronized (PhoneInterfaceManager.class) {
1085 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001086 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001087 } else {
1088 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1089 }
1090 return sInstance;
1091 }
1092 }
1093
1094 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001095 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001096 mApp = app;
1097 mPhone = phone;
1098 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001099 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001100 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1101 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001102 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001103 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001104 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001105 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001106
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001107 publish();
1108 }
1109
1110 private void publish() {
1111 if (DBG) log("publish: " + this);
1112
1113 ServiceManager.addService("phone", this);
1114 }
1115
Stuart Scott584921c2015-01-15 17:10:34 -08001116 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001117 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1118 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001119 }
1120
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001121 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1122 Phone phone = getPhoneFromRequest(request);
1123 return phone == null ? null :
1124 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1125 }
1126
Wink Saville36469e72014-06-11 15:17:00 -07001127 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001128 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001129 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001130 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001131 //
1132 // Implementation of the ITelephony interface.
1133 //
1134
1135 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001136 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001137 }
1138
Wink Savilleb564aae2014-10-23 10:18:09 -07001139 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001140 if (DBG) log("dial: " + number);
1141 // No permission check needed here: This is just a wrapper around the
1142 // ACTION_DIAL intent, which is available to any app since it puts up
1143 // the UI before it does anything.
1144
1145 String url = createTelUrl(number);
1146 if (url == null) {
1147 return;
1148 }
1149
1150 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001151 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001152 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1153 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1154 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1155 mApp.startActivity(intent);
1156 }
1157 }
1158
1159 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001160 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001161 }
1162
Wink Savilleb564aae2014-10-23 10:18:09 -07001163 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001164 if (DBG) log("call: " + number);
1165
1166 // This is just a wrapper around the ACTION_CALL intent, but we still
1167 // need to do a permission check since we're calling startActivity()
1168 // from the context of the phone app.
1169 enforceCallPermission();
1170
1171 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1172 != AppOpsManager.MODE_ALLOWED) {
1173 return;
1174 }
1175
1176 String url = createTelUrl(number);
1177 if (url == null) {
1178 return;
1179 }
1180
Wink Saville08874612014-08-31 19:19:58 -07001181 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001182 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001183 if (slist != null) {
1184 for (SubscriptionInfo subInfoRecord : slist) {
1185 if (subInfoRecord.getSubscriptionId() == subId) {
1186 isValid = true;
1187 break;
1188 }
Wink Saville08874612014-08-31 19:19:58 -07001189 }
1190 }
1191 if (isValid == false) {
1192 return;
1193 }
1194
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001196 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001197 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1198 mApp.startActivity(intent);
1199 }
1200
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001201 /**
1202 * End a call based on call state
1203 * @return true is a call was ended
1204 */
1205 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001206 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001207 }
1208
1209 /**
1210 * End a call based on the call state of the subId
1211 * @return true is a call was ended
1212 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001213 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001214 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1215 != PackageManager.PERMISSION_GRANTED) {
1216 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1217 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1218 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1219 }
Stuart Scott584921c2015-01-15 17:10:34 -08001220 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001221 }
1222
1223 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001224 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001225 }
1226
Wink Savilleb564aae2014-10-23 10:18:09 -07001227 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001228 if (DBG) log("answerRingingCall...");
1229 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1230 // but that can probably wait till the big TelephonyManager API overhaul.
1231 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1232 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001233 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001234 }
1235
1236 /**
1237 * Make the actual telephony calls to implement answerRingingCall().
1238 * This should only be called from the main thread of the Phone app.
1239 * @see #answerRingingCall
1240 *
1241 * TODO: it would be nice to return true if we answered the call, or
1242 * false if there wasn't actually a ringing incoming call, or some
1243 * other error occurred. (In other words, pass back the return value
1244 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1245 * But that would require calling this method via sendRequest() rather
1246 * than sendRequestAsync(), and right now we don't actually *need* that
1247 * return value, so let's just return void for now.
1248 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001249 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001250 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001251 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001252 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1253 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001254 if (hasActiveCall && hasHoldingCall) {
1255 // Both lines are in use!
1256 // TODO: provide a flag to let the caller specify what
1257 // policy to use if both lines are in use. (The current
1258 // behavior is hardwired to "answer incoming, end ongoing",
1259 // which is how the CALL button is specced to behave.)
1260 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1261 return;
1262 } else {
1263 // answerCall() will automatically hold the current active
1264 // call, if there is one.
1265 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1266 return;
1267 }
1268 } else {
1269 // No call was ringing.
1270 return;
1271 }
1272 }
1273
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001275 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001277 public void silenceRinger() {
1278 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001279 }
1280
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001281 @Override
1282 public boolean isOffhook(String callingPackage) {
1283 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001284 }
1285
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001286 @Override
1287 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001288 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001289 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001290 return false;
1291 }
1292
Sanket Padawe356d7632015-06-22 14:03:32 -07001293 final Phone phone = getPhone(subId);
1294 if (phone != null) {
1295 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1296 } else {
1297 return false;
1298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001299 }
1300
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001301 @Override
1302 public boolean isRinging(String callingPackage) {
1303 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001304 }
1305
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001306 @Override
1307 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001309 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001310 return false;
1311 }
1312
Sanket Padawe356d7632015-06-22 14:03:32 -07001313 final Phone phone = getPhone(subId);
1314 if (phone != null) {
1315 return (phone.getState() == PhoneConstants.State.RINGING);
1316 } else {
1317 return false;
1318 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 }
1320
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001321 @Override
1322 public boolean isIdle(String callingPackage) {
1323 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001324 }
1325
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001326 @Override
1327 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001328 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001329 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001330 return false;
1331 }
1332
Sanket Padawe356d7632015-06-22 14:03:32 -07001333 final Phone phone = getPhone(subId);
1334 if (phone != null) {
1335 return (phone.getState() == PhoneConstants.State.IDLE);
1336 } else {
1337 return false;
1338 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 }
1340
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001341 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001342 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001343 }
1344
Wink Savilleb564aae2014-10-23 10:18:09 -07001345 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001346 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001347 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1348 }
1349
1350 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001351 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001352 }
1353
Wink Savilleb564aae2014-10-23 10:18:09 -07001354 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001355 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001356 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1357 }
1358
1359 /** {@hide} */
1360 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001361 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001362 }
1363
Wink Savilleb564aae2014-10-23 10:18:09 -07001364 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001366 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001367 checkSimPin.start();
1368 return checkSimPin.unlockSim(null, pin);
1369 }
1370
Wink Saville9de0f752013-10-22 19:04:03 -07001371 /** {@hide} */
1372 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001373 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001374 }
1375
Wink Savilleb564aae2014-10-23 10:18:09 -07001376 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001378 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 checkSimPuk.start();
1380 return checkSimPuk.unlockSim(puk, pin);
1381 }
1382
1383 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001384 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001385 * a synchronous one.
1386 */
1387 private static class UnlockSim extends Thread {
1388
1389 private final IccCard mSimCard;
1390
1391 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001392 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1393 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394
1395 // For replies from SimCard interface
1396 private Handler mHandler;
1397
1398 // For async handler to identify request type
1399 private static final int SUPPLY_PIN_COMPLETE = 100;
1400
1401 public UnlockSim(IccCard simCard) {
1402 mSimCard = simCard;
1403 }
1404
1405 @Override
1406 public void run() {
1407 Looper.prepare();
1408 synchronized (UnlockSim.this) {
1409 mHandler = new Handler() {
1410 @Override
1411 public void handleMessage(Message msg) {
1412 AsyncResult ar = (AsyncResult) msg.obj;
1413 switch (msg.what) {
1414 case SUPPLY_PIN_COMPLETE:
1415 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1416 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001417 mRetryCount = msg.arg1;
1418 if (ar.exception != null) {
1419 if (ar.exception instanceof CommandException &&
1420 ((CommandException)(ar.exception)).getCommandError()
1421 == CommandException.Error.PASSWORD_INCORRECT) {
1422 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1423 } else {
1424 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1425 }
1426 } else {
1427 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001429 mDone = true;
1430 UnlockSim.this.notifyAll();
1431 }
1432 break;
1433 }
1434 }
1435 };
1436 UnlockSim.this.notifyAll();
1437 }
1438 Looper.loop();
1439 }
1440
1441 /*
1442 * Use PIN or PUK to unlock SIM card
1443 *
1444 * If PUK is null, unlock SIM card with PIN
1445 *
1446 * If PUK is not null, unlock SIM card with PUK and set PIN code
1447 */
Wink Saville9de0f752013-10-22 19:04:03 -07001448 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449
1450 while (mHandler == null) {
1451 try {
1452 wait();
1453 } catch (InterruptedException e) {
1454 Thread.currentThread().interrupt();
1455 }
1456 }
1457 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1458
1459 if (puk == null) {
1460 mSimCard.supplyPin(pin, callback);
1461 } else {
1462 mSimCard.supplyPuk(puk, pin, callback);
1463 }
1464
1465 while (!mDone) {
1466 try {
1467 Log.d(LOG_TAG, "wait for done");
1468 wait();
1469 } catch (InterruptedException e) {
1470 // Restore the interrupted status
1471 Thread.currentThread().interrupt();
1472 }
1473 }
1474 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001475 int[] resultArray = new int[2];
1476 resultArray[0] = mResult;
1477 resultArray[1] = mRetryCount;
1478 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001479 }
1480 }
1481
1482 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001483 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001484
1485 }
1486
Wink Savilleb564aae2014-10-23 10:18:09 -07001487 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 // No permission check needed here: this call is harmless, and it's
1489 // needed for the ServiceState.requestStateUpdate() call (which is
1490 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001491 final Phone phone = getPhone(subId);
1492 if (phone != null) {
1493 phone.updateServiceLocation();
1494 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001495 }
1496
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001497 @Override
1498 public boolean isRadioOn(String callingPackage) {
1499 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001500 }
1501
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001502 @Override
1503 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001504 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001505 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001506 return false;
1507 }
1508 return isRadioOnForSubscriber(subId);
1509 }
1510
1511 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001512 final Phone phone = getPhone(subId);
1513 if (phone != null) {
1514 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1515 } else {
1516 return false;
1517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001518 }
1519
1520 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001521 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001522
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001523 }
Wink Saville36469e72014-06-11 15:17:00 -07001524
Wink Savilleb564aae2014-10-23 10:18:09 -07001525 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001527 final Phone phone = getPhone(subId);
1528 if (phone != null) {
1529 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1530 }
Wink Saville36469e72014-06-11 15:17:00 -07001531 }
1532
1533 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001534 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001535 }
1536
Wink Savilleb564aae2014-10-23 10:18:09 -07001537 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001538 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001539 final Phone phone = getPhone(subId);
1540 if (phone == null) {
1541 return false;
1542 }
1543 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001544 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001545 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001546 }
1547 return true;
1548 }
Wink Saville36469e72014-06-11 15:17:00 -07001549
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001550 public boolean needMobileRadioShutdown() {
1551 /*
1552 * If any of the Radios are available, it will need to be
1553 * shutdown. So return true if any Radio is available.
1554 */
1555 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1556 Phone phone = PhoneFactory.getPhone(i);
1557 if (phone != null && phone.isRadioAvailable()) return true;
1558 }
1559 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1560 return false;
1561 }
1562
1563 public void shutdownMobileRadios() {
1564 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1565 logv("Shutting down Phone " + i);
1566 shutdownRadioUsingPhoneId(i);
1567 }
1568 }
1569
1570 private void shutdownRadioUsingPhoneId(int phoneId) {
1571 enforceModifyPermission();
1572 Phone phone = PhoneFactory.getPhone(phoneId);
1573 if (phone != null && phone.isRadioAvailable()) {
1574 phone.shutdownRadio();
1575 }
1576 }
1577
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001578 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001579 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001580 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1581 if (defaultPhone != null) {
1582 defaultPhone.setRadioPower(turnOn);
1583 return true;
1584 } else {
1585 loge("There's no default phone.");
1586 return false;
1587 }
Wink Saville36469e72014-06-11 15:17:00 -07001588 }
1589
Wink Savilleb564aae2014-10-23 10:18:09 -07001590 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001592 final Phone phone = getPhone(subId);
1593 if (phone != null) {
1594 phone.setRadioPower(turnOn);
1595 return true;
1596 } else {
1597 return false;
1598 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 }
1600
Wink Saville36469e72014-06-11 15:17:00 -07001601 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001602 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001603 public boolean enableDataConnectivity() {
1604 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001605 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001606 final Phone phone = getPhone(subId);
1607 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001608 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001609 return true;
1610 } else {
1611 return false;
1612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001613 }
1614
Wink Saville36469e72014-06-11 15:17:00 -07001615 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001616 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001617 public boolean disableDataConnectivity() {
1618 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001619 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001620 final Phone phone = getPhone(subId);
1621 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001622 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001623 return true;
1624 } else {
1625 return false;
1626 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001627 }
1628
Sanket Padawe356d7632015-06-22 14:03:32 -07001629 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001630 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001631 final Phone phone = getPhone(subId);
1632 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001633 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001634 } else {
1635 return false;
1636 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001637 }
1638
1639 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001640 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001641 }
1642
pkanwarae03a6b2016-11-06 20:37:09 -08001643 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001644 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001645 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1646 return;
1647 }
1648 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1649 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1650 };
1651
Wink Savilleb564aae2014-10-23 10:18:09 -07001652 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001654 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1655 return false;
1656 }
Wink Saville36469e72014-06-11 15:17:00 -07001657 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
1659
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001661 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001662 }
1663
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001664 public int getCallStateForSlot(int slotIndex) {
1665 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001666 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001667 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 }
1669
Sanket Padawe356d7632015-06-22 14:03:32 -07001670 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001672 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001673 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001674 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001675 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001676 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 }
1679
Sanket Padawe356d7632015-06-22 14:03:32 -07001680 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001682 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001683 if (phone != null) {
1684 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1685 } else {
1686 return TelephonyManager.DATA_ACTIVITY_NONE;
1687 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001688 }
1689
1690 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001691 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001692 mPhone.getContext().getSystemService(AppOpsManager.class)
1693 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001694 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001695 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001696 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 }
1698
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001699 if (DBG_LOC) log("getCellLocation: is active user");
1700 Bundle data = new Bundle();
1701 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1702 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 return null;
1704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001706 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001707 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1708 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001709 }
1710
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001712 public String getNetworkCountryIsoForPhone(int phoneId) {
1713 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1714 // registered cell info, so return a NULL country instead.
1715 final long identity = Binder.clearCallingIdentity();
1716 try {
1717 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1718 if (TelephonyManager.NETWORK_TYPE_IWLAN
1719 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1720 return "";
1721 }
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
1724 }
1725 return TelephonyManager.getTelephonyProperty(
1726 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1727 }
1728
1729 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001731 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001732 }
1733
Sanket Padawe356d7632015-06-22 14:03:32 -07001734 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001735 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 mApp.enforceCallingOrSelfPermission(
1737 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001738 final Phone phone = getPhone(subId);
1739 if (phone != null) {
1740 phone.enableLocationUpdates();
1741 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742 }
1743
1744 @Override
1745 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001746 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001747 }
1748
Sanket Padawe356d7632015-06-22 14:03:32 -07001749 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001750 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 mApp.enforceCallingOrSelfPermission(
1752 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001753 final Phone phone = getPhone(subId);
1754 if (phone != null) {
1755 phone.disableLocationUpdates();
1756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 }
1758
1759 @Override
1760 @SuppressWarnings("unchecked")
1761 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001762 mPhone.getContext().getSystemService(AppOpsManager.class)
1763 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001764 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001765 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001766 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001767 }
1768
1769 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1770 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1771 return null;
1772 }
Svetoslav64fad262015-04-14 14:35:21 -07001773
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001774 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001776 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001778 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001779 try {
1780 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1781 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1782 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1783 } catch (RuntimeException e) {
1784 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001786 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787 }
1788
1789
1790 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001791 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001792 mPhone.getContext().getSystemService(AppOpsManager.class)
1793 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001794 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Svet Ganov4af66282018-03-07 19:57:05 -08001795 callingPackage, Binder.getCallingUid(), Binder.getCallingPid(), true)) {
Svetoslav64fad262015-04-14 14:35:21 -07001796 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 }
1798
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001799 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001800 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001801 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1802 for (Phone phone : PhoneFactory.getPhones()) {
1803 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1804 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001806 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 }
1808
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001809 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001811 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001812 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001813 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 }
1815
Shishir Agrawala9f32182016-04-12 12:00:16 -07001816 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001817 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001818 Phone phone = PhoneFactory.getPhone(slotIndex);
1819 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001820 return null;
1821 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001822 int subId = phone.getSubId();
1823 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1824 mApp, subId, callingPackage, "getImeiForSlot")) {
1825 return null;
1826 }
1827 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001828 }
1829
1830 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001831 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001832 Phone phone = PhoneFactory.getPhone(slotIndex);
1833 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001834 return null;
1835 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001836 int subId = phone.getSubId();
1837 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1838 mApp, subId, callingPackage, "getMeidForSlot")) {
1839 return null;
1840 }
1841 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001842 }
1843
1844 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001845 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001846 Phone phone = PhoneFactory.getPhone(slotIndex);
1847 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001848 return null;
1849 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001850 int subId = phone.getSubId();
1851 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1852 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1853 return null;
1854 }
1855 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001856 }
1857
fionaxu43304da2017-11-27 22:51:16 -08001858 @Override
1859 public int getSubscriptionCarrierId(int subId) {
1860 final Phone phone = getPhone(subId);
1861 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1862 }
1863
1864 @Override
1865 public String getSubscriptionCarrierName(int subId) {
1866 final Phone phone = getPhone(subId);
1867 return phone == null ? null : phone.getCarrierName();
1868 }
1869
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 //
1871 // Internal helper methods.
1872 //
1873
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001874 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1876 *
1877 * @throws SecurityException if the caller does not have the required permission
1878 */
1879 private void enforceModifyPermission() {
1880 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1881 }
1882
1883 /**
1884 * Make sure the caller has the CALL_PHONE permission.
1885 *
1886 * @throws SecurityException if the caller does not have the required permission
1887 */
1888 private void enforceCallPermission() {
1889 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1890 }
1891
Stuart Scott8eef64f2015-04-08 15:13:54 -07001892 private void enforceConnectivityInternalPermission() {
1893 mApp.enforceCallingOrSelfPermission(
1894 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1895 "ConnectivityService");
1896 }
1897
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 private String createTelUrl(String number) {
1899 if (TextUtils.isEmpty(number)) {
1900 return null;
1901 }
1902
Jake Hambye994d462014-02-03 13:10:13 -08001903 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001904 }
1905
Ihab Awadf9e92732013-12-05 18:02:52 -08001906 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1908 }
1909
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001910 private static void logv(String msg) {
1911 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1912 }
1913
Ihab Awadf9e92732013-12-05 18:02:52 -08001914 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1916 }
1917
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001918 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001920 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001921 }
1922
Sanket Padawe356d7632015-06-22 14:03:32 -07001923 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001924 public int getActivePhoneTypeForSlot(int slotIndex) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00001925 final Phone phone = PhoneFactory.getPhone(slotIndex);
1926 if (phone == null) {
1927 return PhoneConstants.PHONE_TYPE_NONE;
1928 } else {
1929 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 }
1932
1933 /**
1934 * Returns the CDMA ERI icon index to display
1935 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001936 @Override
1937 public int getCdmaEriIconIndex(String callingPackage) {
1938 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001939 }
1940
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001942 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001943 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001944 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001945 return -1;
1946 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001947 final Phone phone = getPhone(subId);
1948 if (phone != null) {
1949 return phone.getCdmaEriIconIndex();
1950 } else {
1951 return -1;
1952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
1955 /**
1956 * Returns the CDMA ERI icon mode,
1957 * 0 - ON
1958 * 1 - FLASHING
1959 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001960 @Override
1961 public int getCdmaEriIconMode(String callingPackage) {
1962 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001963 }
1964
Sanket Padawe356d7632015-06-22 14:03:32 -07001965 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001966 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001968 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001969 return -1;
1970 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001971 final Phone phone = getPhone(subId);
1972 if (phone != null) {
1973 return phone.getCdmaEriIconMode();
1974 } else {
1975 return -1;
1976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 }
1978
1979 /**
1980 * Returns the CDMA ERI text,
1981 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001982 @Override
1983 public String getCdmaEriText(String callingPackage) {
1984 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001985 }
1986
Sanket Padawe356d7632015-06-22 14:03:32 -07001987 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001988 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001990 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001991 return null;
1992 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001993 final Phone phone = getPhone(subId);
1994 if (phone != null) {
1995 return phone.getCdmaEriText();
1996 } else {
1997 return null;
1998 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 }
2000
2001 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002002 * Returns the CDMA MDN.
2003 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002004 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002005 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2007 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 final Phone phone = getPhone(subId);
2009 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2010 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002011 } else {
2012 return null;
2013 }
2014 }
2015
2016 /**
2017 * Returns the CDMA MIN.
2018 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002019 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002020 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2022 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002023 final Phone phone = getPhone(subId);
2024 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2025 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002026 } else {
2027 return null;
2028 }
2029 }
2030
2031 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 * Returns true if CDMA provisioning needs to run.
2033 */
2034 public boolean needsOtaServiceProvisioning() {
2035 return mPhone.needsOtaServiceProvisioning();
2036 }
2037
2038 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002039 * Sets the voice mail number of a given subId.
2040 */
2041 @Override
2042 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002043 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002044 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2045 new Pair<String, String>(alphaTag, number), new Integer(subId));
2046 return success;
2047 }
2048
Ta-wei Yen87c49842016-05-13 21:19:52 -07002049 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002050 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2051 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2052 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2053 if (!TextUtils.equals(callingPackage, systemDialer)) {
2054 throw new SecurityException("caller must be system dialer");
2055 }
2056 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2057 if (phoneAccountHandle == null){
2058 return null;
2059 }
2060 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2061 }
2062
2063 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002064 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002065 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002067 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002068 return null;
2069 }
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002070 final long identity = Binder.clearCallingIdentity();
2071 try {
2072 return RemoteVvmTaskManager
2073 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2074 } finally {
2075 Binder.restoreCallingIdentity(identity);
2076 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002077 }
2078
2079 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002080 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2081 VisualVoicemailSmsFilterSettings settings) {
2082 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002083 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002084 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2085 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002086 }
2087
2088 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002089 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2090 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002091 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002092 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002093 }
2094
2095 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002096 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2097 String callingPackage, int subId) {
2098 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002099 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002100 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002101 }
2102
2103 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002104 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002105 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002106 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002107 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2108 }
2109
2110 @Override
2111 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2112 String number, int port, String text, PendingIntent sentIntent) {
2113 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002114 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002115 enforceSendSmsPermission();
2116 // Make the calls as the phone process.
2117 final long identity = Binder.clearCallingIdentity();
2118 try {
2119 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2120 if (port == 0) {
2121 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2122 sentIntent, null, false);
2123 } else {
2124 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2125 smsManager.sendDataMessageWithSelfPermissions(number, null,
2126 (short) port, data, sentIntent, null);
2127 }
2128 } finally {
2129 Binder.restoreCallingIdentity(identity);
2130 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002131 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002132 /**
fionaxu0152e512016-11-14 13:36:14 -08002133 * Sets the voice activation state of a given subId.
2134 */
2135 @Override
2136 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2138 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002139 final Phone phone = getPhone(subId);
2140 if (phone != null) {
2141 phone.setVoiceActivationState(activationState);
2142 } else {
2143 loge("setVoiceActivationState fails with invalid subId: " + subId);
2144 }
2145 }
2146
2147 /**
2148 * Sets the data activation state of a given subId.
2149 */
2150 @Override
2151 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2153 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002154 final Phone phone = getPhone(subId);
2155 if (phone != null) {
2156 phone.setDataActivationState(activationState);
2157 } else {
2158 loge("setVoiceActivationState fails with invalid subId: " + subId);
2159 }
2160 }
2161
2162 /**
2163 * Returns the voice activation state of a given subId.
2164 */
2165 @Override
2166 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002167 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002168 final Phone phone = getPhone(subId);
2169 if (phone != null) {
2170 return phone.getVoiceActivationState();
2171 } else {
2172 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2173 }
2174 }
2175
2176 /**
2177 * Returns the data activation state of a given subId.
2178 */
2179 @Override
2180 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002181 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002182 final Phone phone = getPhone(subId);
2183 if (phone != null) {
2184 return phone.getDataActivationState();
2185 } else {
2186 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2187 }
2188 }
2189
2190 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 * Returns the unread count of voicemails
2192 */
2193 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002194 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002195 }
2196
2197 /**
2198 * Returns the unread count of voicemails for a subId
2199 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002200 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002201 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002202 final Phone phone = getPhone(subId);
2203 if (phone != null) {
2204 return phone.getVoiceMessageCount();
2205 } else {
2206 return 0;
2207 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002208 }
2209
2210 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002211 * returns true, if the device is in a state where both voice and data
2212 * are supported simultaneously. This can change based on location or network condition.
2213 */
2214 @Override
2215 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2216 final Phone phone = getPhone(subId);
2217 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2218 }
2219
2220 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002221 * Send the dialer code if called from the current default dialer or the caller has
2222 * carrier privilege.
2223 * @param inputCode The dialer code to send
2224 */
2225 @Override
2226 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2227 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2228 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2229 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002230 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2231 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002232 }
2233 mPhone.sendDialerSpecialCode(inputCode);
2234 }
2235
2236 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002237 * Returns the data network type.
2238 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 *
2240 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2241 */
2242 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002243 public int getNetworkType() {
2244 final Phone phone = getPhone(getDefaultSubscription());
2245 if (phone != null) {
2246 return phone.getServiceState().getDataNetworkType();
2247 } else {
2248 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2249 }
Wink Saville36469e72014-06-11 15:17:00 -07002250 }
2251
2252 /**
2253 * Returns the network type for a subId
2254 */
2255 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002256 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002257 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002258 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002259 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2260 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002261
Sanket Padawe356d7632015-06-22 14:03:32 -07002262 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002263 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002264 return phone.getServiceState().getDataNetworkType();
2265 } else {
2266 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 }
2269
2270 /**
2271 * Returns the data network type
2272 */
2273 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002274 public int getDataNetworkType(String callingPackage) {
2275 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002276 }
2277
2278 /**
2279 * Returns the data network type for a subId
2280 */
2281 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002282 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002284 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002285 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2286 }
2287
Sanket Padawe356d7632015-06-22 14:03:32 -07002288 final Phone phone = getPhone(subId);
2289 if (phone != null) {
2290 return phone.getServiceState().getDataNetworkType();
2291 } else {
2292 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 }
2295
2296 /**
Wink Saville36469e72014-06-11 15:17:00 -07002297 * Returns the Voice network type for a subId
2298 */
2299 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002300 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002302 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002303 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2304 }
2305
Sanket Padawe356d7632015-06-22 14:03:32 -07002306 final Phone phone = getPhone(subId);
2307 if (phone != null) {
2308 return phone.getServiceState().getVoiceNetworkType();
2309 } else {
2310 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313
2314 /**
2315 * @return true if a ICC card is present
2316 */
2317 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002318 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002319 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2320 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002321 }
2322
2323 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002324 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002325 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002326 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002327 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2328 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002329 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002330 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002331 } else {
2332 return false;
2333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002334 }
2335
2336 /**
2337 * Return if the current radio is LTE on CDMA. This
2338 * is a tri-state return value as for a period of time
2339 * the mode may be unknown.
2340 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002341 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002343 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002345 @Override
2346 public int getLteOnCdmaMode(String callingPackage) {
2347 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002348 }
2349
Sanket Padawe356d7632015-06-22 14:03:32 -07002350 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002351 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002353 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002354 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2355 }
2356
Sanket Padawe356d7632015-06-22 14:03:32 -07002357 final Phone phone = getPhone(subId);
2358 if (phone == null) {
2359 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2360 } else {
2361 return phone.getLteOnCdmaMode();
2362 }
Wink Saville36469e72014-06-11 15:17:00 -07002363 }
2364
2365 public void setPhone(Phone phone) {
2366 mPhone = phone;
2367 }
2368
2369 /**
2370 * {@hide}
2371 * Returns Default subId, 0 in the case of single standby.
2372 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002373 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002374 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002375 }
2376
Shishir Agrawala9f32182016-04-12 12:00:16 -07002377 private int getSlotForDefaultSubscription() {
2378 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2379 }
2380
Wink Savilleb564aae2014-10-23 10:18:09 -07002381 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002382 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002384
2385 /**
2386 * @see android.telephony.TelephonyManager.WifiCallingChoices
2387 */
2388 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002389 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2390 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002391 }
2392
2393 /**
2394 * @see android.telephony.TelephonyManager.WifiCallingChoices
2395 */
2396 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002397 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2398 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2399 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002400 }
2401
Sailesh Nepald1e68152013-12-12 19:08:02 -08002402 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002403 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002404 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002405 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002406
Shishir Agrawal566b7612013-10-28 14:41:00 -07002407 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002408 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2409 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2411 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002412
Derek Tan740e1672017-06-27 14:56:27 -07002413 if (TextUtils.equals(ISDR_AID, aid)) {
2414 // Only allows LPA to open logical channel to ISD-R.
2415 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2416 ComponentInfo bestComponent =
2417 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2418 if (bestComponent == null
2419 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2420 loge("The calling package is not allowed to access ISD-R.");
2421 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2422 }
2423 }
2424
2425 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002426 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002427 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002428 if (DBG) log("iccOpenLogicalChannel: " + response);
2429 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002430 }
2431
2432 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002433 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2435 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002436
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002437 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002438 if (channel < 0) {
2439 return false;
2440 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002441 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002442 if (DBG) log("iccCloseLogicalChannel: " + success);
2443 return success;
2444 }
2445
2446 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002447 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002448 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2450 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002451
2452 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002453 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2454 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002455 " data=" + data);
2456 }
2457
2458 if (channel < 0) {
2459 return "";
2460 }
2461
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002462 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002463 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002464 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2465
Shishir Agrawal566b7612013-10-28 14:41:00 -07002466 // Append the returned status code to the end of the response payload.
2467 String s = Integer.toHexString(
2468 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002469 if (response.payload != null) {
2470 s = IccUtils.bytesToHexString(response.payload) + s;
2471 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002472 return s;
2473 }
Jake Hambye994d462014-02-03 13:10:13 -08002474
Evan Charltonc66da362014-05-16 14:06:40 -07002475 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002476 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2477 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2479 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002480
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002481 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2482 && TextUtils.equals(ISDR_AID, data)) {
2483 // Only allows LPA to select ISD-R.
2484 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2485 ComponentInfo bestComponent =
2486 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2487 if (bestComponent == null
2488 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2489 loge("The calling package is not allowed to select ISD-R.");
2490 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2491 }
2492 }
2493
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002494 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002495 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2496 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002497 }
2498
2499 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002500 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002501 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2502
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002503 // Append the returned status code to the end of the response payload.
2504 String s = Integer.toHexString(
2505 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002506 if (response.payload != null) {
2507 s = IccUtils.bytesToHexString(response.payload) + s;
2508 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002509 return s;
2510 }
2511
2512 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002513 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002514 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2516 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002517
2518 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002519 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002520 p1 + " " + p2 + " " + p3 + ":" + filePath);
2521 }
2522
2523 IccIoResult response =
2524 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002525 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2526 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002527
2528 if (DBG) {
2529 log("Exchange SIM_IO [R]" + response);
2530 }
2531
2532 byte[] result = null;
2533 int length = 2;
2534 if (response.payload != null) {
2535 length = 2 + response.payload.length;
2536 result = new byte[length];
2537 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2538 } else {
2539 result = new byte[length];
2540 }
2541
2542 result[length - 1] = (byte) response.sw2;
2543 result[length - 2] = (byte) response.sw1;
2544 return result;
2545 }
2546
Nathan Haroldb3014052017-01-25 15:57:32 -08002547 /**
2548 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2549 * on a particular subscription
2550 */
sqianb6e41952018-03-12 14:54:01 -07002551 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
2552 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2553 mApp, subId, callingPackage, "getForbiddenPlmns")) {
2554 return null;
2555 }
Nathan Haroldb3014052017-01-25 15:57:32 -08002556 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2557 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2558 return null;
2559 }
2560 Object response = sendRequest(
2561 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2562 if (response instanceof String[]) {
2563 return (String[]) response;
2564 }
2565 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2566 return null;
2567 }
2568
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002569 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002570 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2572 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002573
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002574 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002575 if (response.payload == null) {
2576 return "";
2577 }
2578
2579 // Append the returned status code to the end of the response payload.
2580 String s = Integer.toHexString(
2581 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2582 s = IccUtils.bytesToHexString(response.payload) + s;
2583 return s;
2584 }
2585
Jake Hambye994d462014-02-03 13:10:13 -08002586 /**
2587 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2588 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2589 *
2590 * @param itemID the ID of the item to read
2591 * @return the NV item as a String, or null on error.
2592 */
2593 @Override
2594 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2596 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002597 if (DBG) log("nvReadItem: item " + itemID);
2598 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2599 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2600 return value;
2601 }
2602
2603 /**
2604 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2605 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2606 *
2607 * @param itemID the ID of the item to read
2608 * @param itemValue the value to write, as a String
2609 * @return true on success; false on any failure
2610 */
2611 @Override
2612 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2614 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002615 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2616 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2617 new Pair<Integer, String>(itemID, itemValue));
2618 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2619 return success;
2620 }
2621
2622 /**
2623 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2624 * Used for device configuration by some CDMA operators.
2625 *
2626 * @param preferredRoamingList byte array containing the new PRL
2627 * @return true on success; false on any failure
2628 */
2629 @Override
2630 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2632 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002633 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2634 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2635 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2636 return success;
2637 }
2638
2639 /**
2640 * Perform the specified type of NV config reset.
2641 * Used for device configuration by some CDMA operators.
2642 *
2643 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2644 * @return true on success; false on any failure
2645 */
2646 @Override
2647 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2649 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002650 if (DBG) log("nvResetConfig: type " + resetType);
2651 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2652 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2653 return success;
2654 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002655
2656 /**
Wink Saville36469e72014-06-11 15:17:00 -07002657 * {@hide}
2658 * Returns Default sim, 0 in the case of single standby.
2659 */
2660 public int getDefaultSim() {
2661 //TODO Need to get it from Telephony Devcontroller
2662 return 0;
2663 }
2664
Svet Ganovb320e182015-04-16 12:30:10 -07002665 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002666 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002667 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002668 return new String[0];
2669 }
2670
2671
ram87fca6f2014-07-18 18:58:44 +05302672 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002673 }
2674
Brad Ebinger51f743a2017-01-23 13:50:20 -08002675 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002676 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2677 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002678 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002679 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002680 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002681 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002682 }
2683
2684 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002685 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2686 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002687 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002688 public void disableIms(int slotId) {
2689 enforceModifyPermission();
2690 PhoneFactory.getImsResolver().disableIms(slotId);
2691 }
2692
2693 /**
2694 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2695 * feature or {@link null} if the service is not available. If the feature is available, the
2696 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2697 */
2698 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002699 IImsServiceFeatureCallback callback) {
2700 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002701 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002702 }
2703
2704 /**
2705 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2706 * feature during emergency calling or {@link null} if the service is not available. If the
2707 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2708 * listener for feature updates.
2709 */
2710 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2711 enforceModifyPermission();
2712 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002713 }
2714
Brad Ebinger5f64b052017-12-14 14:26:15 -08002715 /**
2716 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2717 * specified.
2718 */
2719 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2720 enforceModifyPermission();
2721 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2722 }
2723
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002724 /**
2725 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2726 * specified.
2727 */
2728 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2729 enforceModifyPermission();
2730 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2731 }
2732
Brad Ebinger884c07b2018-02-15 16:17:40 -08002733 /**
Brad Ebinger304415d2018-03-02 13:43:36 -08002734 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2735 * available, false if the IMS resolver is idle.
2736 */
2737 public boolean isResolvingImsBinding() {
2738 enforceModifyPermission();
2739 return PhoneFactory.getImsResolver().isResolvingBinding();
2740 }
2741
Wink Saville36469e72014-06-11 15:17:00 -07002742 public void setImsRegistrationState(boolean registered) {
2743 enforceModifyPermission();
2744 mPhone.setImsRegistrationState(registered);
2745 }
2746
2747 /**
Stuart Scott54788802015-03-30 13:18:01 -07002748 * Set the network selection mode to automatic.
2749 *
2750 */
2751 @Override
2752 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002753 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2754 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002755 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2756 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2757 }
2758
2759 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002760 * Set the network selection mode to manual with the selected carrier.
2761 */
2762 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002763 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002764 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2766 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002767 OperatorInfo operator = new OperatorInfo(
2768 /* operatorAlphaLong */ "",
2769 /* operatorAlphaShort */ "",
2770 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002771 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002772 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2773 persistSelection);
2774 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002775 }
2776
2777 /**
2778 * Scans for available networks.
2779 */
2780 @Override
2781 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2783 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002784 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2785 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2786 CMD_PERFORM_NETWORK_SCAN, null, subId);
2787 return result;
2788 }
2789
2790 /**
yinxub1bed742017-04-17 11:45:04 -07002791 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002792 *
yinxub1bed742017-04-17 11:45:04 -07002793 * @param subId id of the subscription
2794 * @param request contains the radio access networks with bands/channels to scan
2795 * @param messenger callback messenger for scan results or errors
2796 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002797 * @return the id of the requested scan which can be used to stop the scan.
2798 */
2799 @Override
2800 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2801 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2803 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002804 return mNetworkScanRequestTracker.startNetworkScan(
2805 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002806 }
2807
2808 /**
2809 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002810 *
2811 * @param subId id of the subscription
2812 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002813 */
2814 @Override
2815 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2817 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002818 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002819 }
2820
2821 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002822 * Get the calculated preferred network type.
2823 * Used for debugging incorrect network type.
2824 *
2825 * @return the preferred network type, defined in RILConstants.java.
2826 */
2827 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002828 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002830 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002831 return RILConstants.PREFERRED_NETWORK_MODE;
2832 }
2833
Amit Mahajan43330e02014-11-18 11:54:45 -08002834 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002835 }
2836
2837 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002838 * Get the preferred network type.
2839 * Used for device configuration by some CDMA operators.
2840 *
2841 * @return the preferred network type, defined in RILConstants.java.
2842 */
2843 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002844 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002845 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2846 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002847 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002848 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002849 int networkType = (result != null ? result[0] : -1);
2850 if (DBG) log("getPreferredNetworkType: " + networkType);
2851 return networkType;
2852 }
2853
2854 /**
2855 * Set the preferred network type.
2856 * Used for device configuration by some CDMA operators.
2857 *
2858 * @param networkType the preferred network type, defined in RILConstants.java.
2859 * @return true on success; false on any failure.
2860 */
2861 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002862 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2864 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002865 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2866 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002867 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002868 if (success) {
2869 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002870 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002871 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002872 return success;
2873 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002874
2875 /**
Junda Liu475951f2014-11-07 16:45:03 -08002876 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2877 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2878 * tethering.
2879 *
2880 * @return 0: Not required. 1: required. 2: Not set.
2881 * @hide
2882 */
2883 @Override
2884 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002885 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002886 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2887 Settings.Global.TETHER_DUN_REQUIRED, 2);
2888 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2889 // config_tether_apndata.
2890 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2891 dunRequired = 1;
2892 }
2893 return dunRequired;
2894 }
2895
2896 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002897 * Set mobile data enabled
2898 * Used by the user through settings etc to turn on/off mobile data
2899 *
2900 * @param enable {@code true} turn turn data on, else {@code false}
2901 */
2902 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002903 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2905 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002906 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002907 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002908 Phone phone = PhoneFactory.getPhone(phoneId);
2909 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002910 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2911 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002912 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002913 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002914 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002915 }
2916
2917 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002918 * Get the user enabled state of Mobile Data.
2919 *
2920 * TODO: remove and use isUserDataEnabled.
2921 * This can't be removed now because some vendor codes
2922 * calls through ITelephony directly while they should
2923 * use TelephonyManager.
2924 *
2925 * @return true on enabled
2926 */
2927 @Override
2928 public boolean getDataEnabled(int subId) {
2929 return isUserDataEnabled(subId);
2930 }
2931
2932 /**
2933 * Get whether mobile data is enabled per user setting.
2934 *
2935 * There are other factors deciding whether mobile data is actually enabled, but they are
2936 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002937 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002938 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002939 *
2940 * @return {@code true} if data is enabled else {@code false}
2941 */
2942 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002943 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002944 try {
2945 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2946 null);
2947 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2949 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002950 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002951 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002952 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002953 Phone phone = PhoneFactory.getPhone(phoneId);
2954 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002955 boolean retVal = phone.isUserDataEnabled();
2956 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002957 return retVal;
2958 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002959 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2960 return false;
2961 }
2962 }
2963
2964 /**
2965 * Get whether mobile data is enabled.
2966 *
2967 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2968 * whether mobile data is actually enabled.
2969 *
2970 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2971 *
2972 * @return {@code true} if data is enabled else {@code false}
2973 */
2974 @Override
2975 public boolean isDataEnabled(int subId) {
2976 try {
2977 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2978 null);
2979 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2981 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08002982 }
2983 int phoneId = mSubscriptionController.getPhoneId(subId);
2984 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2985 Phone phone = PhoneFactory.getPhone(phoneId);
2986 if (phone != null) {
2987 boolean retVal = phone.isDataEnabled();
2988 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2989 return retVal;
2990 } else {
2991 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002992 return false;
2993 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002994 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002995
2996 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002997 public int getCarrierPrivilegeStatus(int subId) {
2998 final Phone phone = getPhone(subId);
2999 if (phone == null) {
3000 loge("getCarrierPrivilegeStatus: Invalid subId");
3001 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3002 }
3003 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003004 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003005 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003006 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3007 }
3008 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003009 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003010 }
Junda Liu29340342014-07-10 15:23:27 -07003011
3012 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08003013 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3014 final Phone phone = getPhone(subId);
3015 if (phone == null) {
3016 loge("getCarrierPrivilegeStatus: Invalid subId");
3017 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3018 }
3019 UiccProfile profile =
3020 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3021 if (profile == null) {
3022 loge("getCarrierPrivilegeStatus: No UICC");
3023 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3024 }
3025 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3026 }
3027
3028 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003029 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003030 if (TextUtils.isEmpty(pkgName))
3031 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003032 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003033 if (card == null) {
3034 loge("checkCarrierPrivilegesForPackage: No UICC");
3035 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3036 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003037 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3038 }
3039
3040 @Override
3041 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003042 if (TextUtils.isEmpty(pkgName))
3043 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003044 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3045 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3046 UiccCard card = UiccController.getInstance().getUiccCard(i);
3047 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003048 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003049 continue;
3050 }
3051
3052 result = card.getCarrierPrivilegeStatus(
3053 mPhone.getContext().getPackageManager(), pkgName);
3054 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3055 break;
3056 }
3057 }
3058
3059 return result;
Junda Liu29340342014-07-10 15:23:27 -07003060 }
Derek Tan89e89d42014-07-08 17:00:10 -07003061
3062 @Override
Junda Liue64de782015-04-16 17:19:16 -07003063 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3064 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3065 loge("phoneId " + phoneId + " is not valid.");
3066 return null;
3067 }
3068 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003069 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003070 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003071 return null ;
3072 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003073 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003074 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003075 }
3076
Amith Yamasani6e118872016-02-19 12:53:51 -08003077 @Override
3078 public List<String> getPackagesWithCarrierPrivileges() {
3079 PackageManager pm = mPhone.getContext().getPackageManager();
3080 List<String> privilegedPackages = new ArrayList<>();
3081 List<PackageInfo> packages = null;
3082 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3083 UiccCard card = UiccController.getInstance().getUiccCard(i);
3084 if (card == null) {
3085 // No UICC in that slot.
3086 continue;
3087 }
3088 if (card.hasCarrierPrivilegeRules()) {
3089 if (packages == null) {
3090 // Only check packages in user 0 for now
3091 packages = pm.getInstalledPackagesAsUser(
3092 PackageManager.MATCH_DISABLED_COMPONENTS
3093 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3094 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3095 }
3096 for (int p = packages.size() - 1; p >= 0; p--) {
3097 PackageInfo pkgInfo = packages.get(p);
3098 if (pkgInfo != null && pkgInfo.packageName != null
3099 && card.getCarrierPrivilegeStatus(pkgInfo)
3100 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3101 privilegedPackages.add(pkgInfo.packageName);
3102 }
3103 }
3104 }
3105 }
3106 return privilegedPackages;
3107 }
3108
Wink Savilleb564aae2014-10-23 10:18:09 -07003109 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003110 final Phone phone = getPhone(subId);
3111 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003112 if (card == null) {
3113 loge("getIccId: No UICC");
3114 return null;
3115 }
3116 String iccId = card.getIccId();
3117 if (TextUtils.isEmpty(iccId)) {
3118 loge("getIccId: ICC ID is null or empty.");
3119 return null;
3120 }
3121 return iccId;
3122 }
3123
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003124 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003125 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3126 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003127 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3128 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003129
Jeff Sharkey85190e62014-12-05 09:40:12 -08003130 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003131 final Phone phone = getPhone(subId);
3132 if (phone == null) {
3133 return false;
3134 }
3135 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003136
3137 if (DBG_MERGE) {
3138 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3139 + subscriberId + " to " + number);
3140 }
3141
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003142 if (TextUtils.isEmpty(iccId)) {
3143 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003144 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003145
Jeff Sharkey85190e62014-12-05 09:40:12 -08003146 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3147
3148 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003149 if (alphaTag == null) {
3150 editor.remove(alphaTagPrefKey);
3151 } else {
3152 editor.putString(alphaTagPrefKey, alphaTag);
3153 }
3154
Jeff Sharkey85190e62014-12-05 09:40:12 -08003155 // Record both the line number and IMSI for this ICCID, since we need to
3156 // track all merged IMSIs based on line number
3157 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3158 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003159 if (number == null) {
3160 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003161 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003162 } else {
3163 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003164 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003165 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003166
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003167 editor.commit();
3168 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003169 }
3170
3171 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003172 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003173 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003175 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003176 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003177 return null;
3178 }
Derek Tan97ebb422014-09-05 16:55:38 -07003179
3180 String iccId = getIccId(subId);
3181 if (iccId != null) {
3182 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003183 if (DBG_MERGE) {
3184 log("getLine1NumberForDisplay returning " +
3185 mTelephonySharedPreferences.getString(numberPrefKey, null));
3186 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003187 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003188 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003189 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003190 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003191 }
3192
3193 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003194 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003195 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003196 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003197 return null;
3198 }
Derek Tan97ebb422014-09-05 16:55:38 -07003199
3200 String iccId = getIccId(subId);
3201 if (iccId != null) {
3202 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003203 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003204 }
Derek Tan97ebb422014-09-05 16:55:38 -07003205 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003206 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003207
3208 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003209 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003210 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3211 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003212 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003213 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3214 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003215 return null;
3216 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003217 final Context context = mPhone.getContext();
3218 final TelephonyManager tele = TelephonyManager.from(context);
3219 final SubscriptionManager sub = SubscriptionManager.from(context);
3220
3221 // Figure out what subscribers are currently active
3222 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003223 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3224 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3225 final long identity = Binder.clearCallingIdentity();
3226 try {
3227 final int[] subIds = sub.getActiveSubscriptionIdList();
3228 for (int subId : subIds) {
3229 activeSubscriberIds.add(tele.getSubscriberId(subId));
3230 }
3231 } finally {
3232 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003233 }
3234
3235 // First pass, find a number override for an active subscriber
3236 String mergeNumber = null;
3237 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3238 for (String key : prefs.keySet()) {
3239 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3240 final String subscriberId = (String) prefs.get(key);
3241 if (activeSubscriberIds.contains(subscriberId)) {
3242 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3243 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3244 mergeNumber = (String) prefs.get(numberKey);
3245 if (DBG_MERGE) {
3246 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3247 + " for active subscriber " + subscriberId);
3248 }
3249 if (!TextUtils.isEmpty(mergeNumber)) {
3250 break;
3251 }
3252 }
3253 }
3254 }
3255
3256 // Shortcut when no active merged subscribers
3257 if (TextUtils.isEmpty(mergeNumber)) {
3258 return null;
3259 }
3260
3261 // Second pass, find all subscribers under that line override
3262 final ArraySet<String> result = new ArraySet<>();
3263 for (String key : prefs.keySet()) {
3264 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3265 final String number = (String) prefs.get(key);
3266 if (mergeNumber.equals(number)) {
3267 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3268 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3269 final String subscriberId = (String) prefs.get(subscriberKey);
3270 if (!TextUtils.isEmpty(subscriberId)) {
3271 result.add(subscriberId);
3272 }
3273 }
3274 }
3275 }
3276
3277 final String[] resultArray = result.toArray(new String[result.size()]);
3278 Arrays.sort(resultArray);
3279 if (DBG_MERGE) {
3280 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3281 }
3282 return resultArray;
3283 }
3284
3285 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003286 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003287 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3288 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003289 final Phone phone = getPhone(subId);
3290 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003291 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003292
3293 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003294 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003295 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3296 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003297 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003298 final Phone phone = getPhone(subId);
3299 if (phone == null) {
3300 return false;
3301 }
3302 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003303 cdmaNonRoamingList);
3304 }
3305
3306 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00003307 @Deprecated
3308 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3309 enforceModifyPermission();
3310
3311 int returnValue = 0;
3312 try {
3313 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3314 if(result.exception == null) {
3315 if (result.result != null) {
3316 byte[] responseData = (byte[])(result.result);
3317 if(responseData.length > oemResp.length) {
3318 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3319 responseData.length + "bytes. Buffer Size is " +
3320 oemResp.length + "bytes.");
3321 }
3322 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3323 returnValue = responseData.length;
3324 }
3325 } else {
3326 CommandException ex = (CommandException) result.exception;
3327 returnValue = ex.getCommandError().ordinal();
3328 if(returnValue > 0) returnValue *= -1;
3329 }
3330 } catch (RuntimeException e) {
3331 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3332 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3333 if(returnValue > 0) returnValue *= -1;
3334 }
3335
3336 return returnValue;
3337 }
3338
3339 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003340 public void setRadioCapability(RadioAccessFamily[] rafs) {
3341 try {
3342 ProxyController.getInstance().setRadioCapability(rafs);
3343 } catch (RuntimeException e) {
3344 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3345 }
3346 }
3347
3348 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003349 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003350 Phone phone = PhoneFactory.getPhone(phoneId);
3351 if (phone == null) {
3352 return RadioAccessFamily.RAF_UNKNOWN;
3353 }
3354 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003355 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003356 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003357 return RadioAccessFamily.RAF_UNKNOWN;
3358 }
3359
Wink Saville5d475dd2014-10-17 15:00:58 -07003360 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3361 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003362
3363 @Override
3364 public void enableVideoCalling(boolean enable) {
3365 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003366 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003367 }
3368
3369 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003370 public boolean isVideoCallingEnabled(String callingPackage) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00003371 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3372 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
3373 return false;
3374 }
Svet Ganovb320e182015-04-16 12:30:10 -07003375
Andrew Lee77527ac2014-10-21 16:57:39 -07003376 // Check the user preference and the system-level IMS setting. Even if the user has
3377 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3378 // In the long run, we may instead need to check if there exists a connection service
3379 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003380 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3381 return imsManager.isVtEnabledByPlatform()
3382 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3383 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003384 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003385
Andrew Leea1239f22015-03-02 17:44:07 -08003386 @Override
3387 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003388 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003389 }
3390
3391 @Override
3392 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003393 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003394 }
3395
Andrew Lee9431b832015-03-09 18:46:45 -07003396 @Override
3397 public boolean isTtyModeSupported() {
3398 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3399 TelephonyManager telephonyManager =
3400 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003401 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003402 }
3403
3404 @Override
3405 public boolean isHearingAidCompatibilitySupported() {
3406 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3407 }
3408
Hall Liu98187582018-01-22 19:15:32 -08003409 public boolean isRttSupported() {
3410 boolean isCarrierSupported =
3411 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3412 boolean isDeviceSupported =
3413 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3414 return isCarrierSupported && isDeviceSupported;
3415 }
3416
Sanket Padawe7310cc72015-01-14 09:53:20 -08003417 /**
3418 * Returns the unique device ID of phone, for example, the IMEI for
3419 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3420 *
3421 * <p>Requires Permission:
3422 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3423 */
3424 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003425 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003426 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08003427 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003428 return null;
3429 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003430 int subId = phone.getSubId();
3431 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3432 mApp, subId, callingPackage, "getDeviceId")) {
3433 return null;
3434 }
3435 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003436 }
3437
Ping Sunc67b7c22016-03-02 19:16:45 +08003438 /**
3439 * {@hide}
3440 * Returns the IMS Registration Status on a particular subid
3441 *
3442 * @param subId
3443 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003444 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003445 Phone phone = getPhone(subId);
3446 if (phone != null) {
3447 return phone.isImsRegistered();
3448 } else {
3449 return false;
3450 }
3451 }
3452
Santos Cordon7a1885b2015-02-03 11:15:19 -08003453 @Override
3454 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3455 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3456 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003457
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003458 /**
3459 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003460 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003461 public boolean isWifiCallingAvailable(int subId) {
3462 Phone phone = getPhone(subId);
3463 if (phone != null) {
3464 return phone.isWifiCallingEnabled();
3465 } else {
3466 return false;
3467 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003468 }
3469
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003470 /**
3471 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003472 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003473 public boolean isVolteAvailable(int subId) {
3474 Phone phone = getPhone(subId);
3475 if (phone != null) {
3476 return phone.isVolteEnabled();
3477 } else {
3478 return false;
3479 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003480 }
Svet Ganovb320e182015-04-16 12:30:10 -07003481
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003482 /**
3483 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003484 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003485 public boolean isVideoTelephonyAvailable(int subId) {
3486 Phone phone = getPhone(subId);
3487 if (phone != null) {
3488 return phone.isVideoEnabled();
3489 } else {
3490 return false;
3491 }
3492 }
3493
3494 /**
3495 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3496 * defined in {@link ImsRegistrationImplBase}.
3497 */
3498 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3499 Phone phone = getPhone(subId);
3500 if (phone != null) {
3501 return phone.getImsRegistrationTech();
3502 } else {
3503 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3504 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003505 }
3506
Stuart Scott8eef64f2015-04-08 15:13:54 -07003507 @Override
3508 public void factoryReset(int subId) {
3509 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003510 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3511 return;
3512 }
3513
Svet Ganovcc087f82015-05-12 20:35:54 -07003514 final long identity = Binder.clearCallingIdentity();
3515 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003516 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3517 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07003518 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07003519 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07003520 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
3521 mPhone.setDataRoamingEnabled(getDefaultDataRoamingEnabled(subId));
pkanwar79ec0542017-07-31 14:10:01 -07003522 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003523 }
3524 } finally {
3525 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003526 }
3527 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003528
3529 @Override
3530 public String getLocaleFromDefaultSim() {
3531 // We query all subscriptions instead of just the active ones, because
3532 // this might be called early on in the provisioning flow when the
3533 // subscriptions potentially aren't active yet.
3534 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3535 if (slist == null || slist.isEmpty()) {
3536 return null;
3537 }
3538
3539 // This function may be called very early, say, from the setup wizard, at
3540 // which point we won't have a default subscription set. If that's the case
3541 // we just choose the first, which will be valid in "most cases".
3542 final int defaultSubId = getDefaultSubscription();
3543 SubscriptionInfo info = null;
3544 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3545 info = slist.get(0);
3546 } else {
3547 for (SubscriptionInfo item : slist) {
3548 if (item.getSubscriptionId() == defaultSubId) {
3549 info = item;
3550 break;
3551 }
3552 }
3553
3554 if (info == null) {
3555 return null;
3556 }
3557 }
3558
3559 // Try and fetch the locale from the carrier properties or from the SIM language
3560 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003561 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003562 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003563 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003564 if (defaultPhone != null) {
3565 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3566 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003567 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003568 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3569 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003570 } else {
3571 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003572 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003573 }
3574 }
3575
Narayan Kamath011676f2015-07-29 12:04:08 +01003576 // The SIM language preferences only store a language (e.g. fr = French), not an
3577 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3578 // the SIM and carrier preferences does not include a country we add the country
3579 // determined from the SIM MCC to provide an exact locale.
3580 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003581 if (mccLocale != null) {
3582 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3583 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003584 }
3585
Tony Hill183b2de2015-06-24 14:53:58 +01003586 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003587 return null;
3588 }
3589
3590 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3591 final long identity = Binder.clearCallingIdentity();
3592 try {
3593 return mSubscriptionController.getAllSubInfoList(
3594 mPhone.getContext().getOpPackageName());
3595 } finally {
3596 Binder.restoreCallingIdentity(identity);
3597 }
3598 }
3599
3600 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3601 final long identity = Binder.clearCallingIdentity();
3602 try {
3603 return mSubscriptionController.getActiveSubscriptionInfoList(
3604 mPhone.getContext().getOpPackageName());
3605 } finally {
3606 Binder.restoreCallingIdentity(identity);
3607 }
3608 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003609
Chenjie Yu1ba97252018-01-11 18:16:20 -08003610 private final ModemActivityInfo mLastModemActivityInfo =
3611 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3612
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003613 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003614 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3615 * representing the state of the modem.
3616 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003617 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3618 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003619 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003620 */
3621 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003622 public void requestModemActivityInfo(ResultReceiver result) {
3623 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003624 ModemActivityInfo ret = null;
3625 synchronized (mLastModemActivityInfo) {
3626 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3627 null);
3628 if (info != null) {
3629 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3630 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3631 mergedTxTimeMs[i] =
3632 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3633 }
3634 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3635 mLastModemActivityInfo.setSleepTimeMillis(
3636 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3637 mLastModemActivityInfo.setIdleTimeMillis(
3638 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3639 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3640 mLastModemActivityInfo.setRxTimeMillis(
3641 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3642 mLastModemActivityInfo.setEnergyUsed(
3643 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3644 }
3645 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3646 mLastModemActivityInfo.getSleepTimeMillis(),
3647 mLastModemActivityInfo.getIdleTimeMillis(),
3648 mLastModemActivityInfo.getTxTimeMillis(),
3649 mLastModemActivityInfo.getRxTimeMillis(),
3650 mLastModemActivityInfo.getEnergyUsed());
3651 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003652 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003653 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003654 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003655 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003656
3657 /**
3658 * {@hide}
3659 * Returns the service state information on specified subscription.
3660 */
3661 @Override
3662 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3663
Jeff Davidson7e17e312018-02-13 18:17:36 -08003664 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003665 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003666 return null;
3667 }
3668
3669 final Phone phone = getPhone(subId);
3670 if (phone == null) {
3671 return null;
3672 }
3673
3674 return phone.getServiceState();
3675 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003676
3677 /**
3678 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3679 *
3680 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3681 * voicemail ringtone.
3682 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3683 * PhoneAccount.
3684 */
3685 @Override
3686 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003687 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003688 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003689 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003690 }
3691
fionaxu7ed723d2017-05-30 18:58:54 -07003692 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003693 }
3694
3695 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003696 * Sets the per-account voicemail ringtone.
3697 *
3698 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3699 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3700 *
3701 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3702 * voicemail ringtone.
3703 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3704 * PhoneAccount.
3705 */
3706 @Override
3707 public void setVoicemailRingtoneUri(String callingPackage,
3708 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3709 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3710 if (!TextUtils.equals(callingPackage,
3711 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3713 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3714 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003715 }
3716 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3717 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003718 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003719 }
fionaxu7ed723d2017-05-30 18:58:54 -07003720 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003721 }
3722
3723 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003724 * Returns whether vibration is set for voicemail notification in Phone settings.
3725 *
3726 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3727 * voicemail vibration setting.
3728 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3729 */
3730 @Override
3731 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003732 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003733 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003734 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003735 }
3736
fionaxu7ed723d2017-05-30 18:58:54 -07003737 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003738 }
3739
Youhan Wange64578a2016-05-02 15:32:42 -07003740 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003741 * Sets the per-account voicemail vibration.
3742 *
3743 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3744 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3745 *
3746 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3747 * voicemail vibration setting.
3748 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3749 * specific PhoneAccount.
3750 */
3751 @Override
3752 public void setVoicemailVibrationEnabled(String callingPackage,
3753 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3754 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3755 if (!TextUtils.equals(callingPackage,
3756 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3758 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3759 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003760 }
3761
3762 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3763 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003764 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003765 }
fionaxu7ed723d2017-05-30 18:58:54 -07003766 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003767 }
3768
3769 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003770 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3771 *
3772 * @throws SecurityException if the caller does not have the required permission
3773 */
3774 private void enforceReadPrivilegedPermission() {
3775 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3776 null);
3777 }
3778
3779 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003780 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3781 * permission.
3782 *
3783 * @throws SecurityException if the caller does not have the required permission
3784 */
3785 private void enforceSendSmsPermission() {
3786 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3787 }
3788
3789 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003790 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003791 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003792 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003793 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003794 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003795 ComponentName componentName =
3796 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3797 if(componentName == null) {
3798 throw new SecurityException("Caller not current active visual voicemail package[null]");
3799 }
3800 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003801 if (!callingPackage.equals(vvmPackage)) {
3802 throw new SecurityException("Caller not current active visual voicemail package[" +
3803 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003804 }
3805 }
3806
3807 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003808 * Return the application ID for the app type.
3809 *
3810 * @param subId the subscription ID that this request applies to.
3811 * @param appType the uicc app type.
3812 * @return Application ID for specificied app type, or null if no uicc.
3813 */
3814 @Override
3815 public String getAidForAppType(int subId, int appType) {
3816 enforceReadPrivilegedPermission();
3817 Phone phone = getPhone(subId);
3818 if (phone == null) {
3819 return null;
3820 }
3821 String aid = null;
3822 try {
3823 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3824 .getApplicationByType(appType).getAid();
3825 } catch (Exception e) {
3826 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3827 }
3828 return aid;
3829 }
3830
Youhan Wang4001d252016-05-11 10:29:41 -07003831 /**
3832 * Return the Electronic Serial Number.
3833 *
3834 * @param subId the subscription ID that this request applies to.
3835 * @return ESN or null if error.
3836 */
3837 @Override
3838 public String getEsn(int subId) {
3839 enforceReadPrivilegedPermission();
3840 Phone phone = getPhone(subId);
3841 if (phone == null) {
3842 return null;
3843 }
3844 String esn = null;
3845 try {
3846 esn = phone.getEsn();
3847 } catch (Exception e) {
3848 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3849 }
3850 return esn;
3851 }
3852
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003853 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003854 * Return the Preferred Roaming List Version.
3855 *
3856 * @param subId the subscription ID that this request applies to.
3857 * @return PRLVersion or null if error.
3858 */
3859 @Override
3860 public String getCdmaPrlVersion(int subId) {
3861 enforceReadPrivilegedPermission();
3862 Phone phone = getPhone(subId);
3863 if (phone == null) {
3864 return null;
3865 }
3866 String cdmaPrlVersion = null;
3867 try {
3868 cdmaPrlVersion = phone.getCdmaPrlVersion();
3869 } catch (Exception e) {
3870 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3871 }
3872 return cdmaPrlVersion;
3873 }
3874
3875 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003876 * Get snapshot of Telephony histograms
3877 * @return List of Telephony histograms
3878 * @hide
3879 */
3880 @Override
3881 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003882 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3883 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003884 return RIL.getTelephonyRILTimingHistograms();
3885 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003886
3887 /**
3888 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003889 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003890 * Require system privileges. In the future we may add this to carrier APIs.
3891 *
3892 * @return The number of carriers set successfully, should match length of carriers
3893 */
3894 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003895 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003896 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003897
Meng Wang9b7c4e92017-02-17 11:41:27 -08003898 if (carriers == null) {
3899 throw new NullPointerException("carriers cannot be null");
3900 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003901
3902 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003903 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3904 return retVal[0];
3905 }
3906
3907 /**
3908 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003909 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003910 * Require system privileges. In the future we may add this to carrier APIs.
3911 *
3912 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3913 * means all carriers are allowed.
3914 */
3915 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003916 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003917 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003918 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003919 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3920 }
3921
fionaxu59545b42016-05-25 15:53:37 -07003922 /**
3923 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3924 * @param subId the subscription ID that this action applies to.
3925 * @param enabled control enable or disable metered apns.
3926 * {@hide}
3927 */
3928 @Override
3929 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3930 enforceModifyPermission();
3931 final Phone phone = getPhone(subId);
3932 if (phone == null) {
3933 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3934 return;
3935 }
3936 try {
3937 phone.carrierActionSetMeteredApnsEnabled(enabled);
3938 } catch (Exception e) {
3939 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3940 }
3941 }
3942
3943 /**
3944 * Action set from carrier signalling broadcast receivers to enable/disable radio
3945 * @param subId the subscription ID that this action applies to.
3946 * @param enabled control enable or disable radio.
3947 * {@hide}
3948 */
3949 @Override
3950 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3951 enforceModifyPermission();
3952 final Phone phone = getPhone(subId);
3953 if (phone == null) {
3954 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3955 return;
3956 }
3957 try {
3958 phone.carrierActionSetRadioEnabled(enabled);
3959 } catch (Exception e) {
3960 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3961 }
3962 }
3963
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003964 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003965 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3966 * network status based on which carrier apps could apply actions accordingly,
3967 * enable/disable default url handler for example.
3968 *
3969 * @param subId the subscription ID that this action applies to.
3970 * @param report control start/stop reporting the default network status.
3971 * {@hide}
3972 */
3973 @Override
3974 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3975 enforceModifyPermission();
3976 final Phone phone = getPhone(subId);
3977 if (phone == null) {
3978 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3979 return;
3980 }
3981 try {
3982 phone.carrierActionReportDefaultNetworkStatus(report);
3983 } catch (Exception e) {
3984 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3985 }
3986 }
3987
3988 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003989 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3990 * bug report is being generated.
3991 */
3992 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003993 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003994 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3995 != PackageManager.PERMISSION_GRANTED) {
3996 writer.println("Permission Denial: can't dump Phone from pid="
3997 + Binder.getCallingPid()
3998 + ", uid=" + Binder.getCallingUid()
3999 + "without permission "
4000 + android.Manifest.permission.DUMP);
4001 return;
4002 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004003 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004004 }
Jack Yueb89b242016-06-22 13:27:47 -07004005
4006 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004007 * Get aggregated video call data usage since boot.
4008 *
4009 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4010 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004011 * {@hide}
4012 */
4013 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004014 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004015 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4016 null);
4017
Jack Yu84291ec2017-05-26 16:07:50 -07004018 // NetworkStatsService keeps tracking the active network interface and identity. It
4019 // records the delta with the corresponding network identity. We just return the total video
4020 // call data usage snapshot since boot.
4021 Phone phone = getPhone(subId);
4022 if (phone != null) {
4023 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07004024 }
Jack Yu84291ec2017-05-26 16:07:50 -07004025 return null;
Jack Yueb89b242016-06-22 13:27:47 -07004026 }
Jack Yu75ab2952016-07-08 14:29:33 -07004027
4028 /**
4029 * Policy control of data connection. Usually used when data limit is passed.
4030 * @param enabled True if enabling the data, otherwise disabling.
4031 * @param subId Subscription index
4032 * {@hide}
4033 */
4034 @Override
4035 public void setPolicyDataEnabled(boolean enabled, int subId) {
4036 enforceModifyPermission();
4037 Phone phone = getPhone(subId);
4038 if (phone != null) {
4039 phone.setPolicyDataEnabled(enabled);
4040 }
4041 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004042
4043 /**
4044 * Get Client request stats
4045 * @return List of Client Request Stats
4046 * @hide
4047 */
4048 @Override
4049 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004051 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004052 return null;
4053 }
4054
4055 Phone phone = getPhone(subId);
4056 if (phone != null) {
4057 return phone.getClientRequestStats();
4058 }
4059
4060 return null;
4061 }
4062
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004063 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004064 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004065 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004066 }
Jack Yueb4124c2017-02-16 15:32:43 -08004067
4068 /**
Grace Chen70990072017-03-24 17:21:30 -07004069 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004070 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004071 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004072 * @param state State of SIM (power down, power up, pass through)
4073 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4074 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4075 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004076 *
4077 **/
4078 @Override
Grace Chen70990072017-03-24 17:21:30 -07004079 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004080 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004081 Phone phone = PhoneFactory.getPhone(slotIndex);
4082
Jack Yueb4124c2017-02-16 15:32:43 -08004083 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004084 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004085 }
4086 }
Shuo Qiandd210312017-04-12 22:11:33 +00004087
Tyler Gunn65d45c22017-06-05 11:22:26 -07004088 private boolean isUssdApiAllowed(int subId) {
4089 CarrierConfigManager configManager =
4090 (CarrierConfigManager) mPhone.getContext().getSystemService(
4091 Context.CARRIER_CONFIG_SERVICE);
4092 if (configManager == null) {
4093 return false;
4094 }
4095 PersistableBundle pb = configManager.getConfigForSubId(subId);
4096 if (pb == null) {
4097 return false;
4098 }
4099 return pb.getBoolean(
4100 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4101 }
4102
Shuo Qiandd210312017-04-12 22:11:33 +00004103 /**
4104 * Check if phone is in emergency callback mode
4105 * @return true if phone is in emergency callback mode
4106 * @param subId sub id
4107 */
goneil9c5f4872017-12-05 14:07:56 -08004108 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004109 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004110 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004111 final Phone phone = getPhone(subId);
4112 if (phone != null) {
4113 return phone.isInEcm();
4114 } else {
4115 return false;
4116 }
4117 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004118
4119 /**
4120 * Get the current signal strength information for the given subscription.
4121 * Because this information is not updated when the device is in a low power state
4122 * it should not be relied-upon to be current.
4123 * @param subId Subscription index
4124 * @return the most recent cached signal strength info from the modem
4125 */
4126 @Override
4127 public SignalStrength getSignalStrength(int subId) {
4128 Phone p = getPhone(subId);
4129 if (p == null) {
4130 return null;
4131 }
4132
4133 return p.getSignalStrength();
4134 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004135
4136 @Override
4137 public UiccSlotInfo[] getUiccSlotsInfo() {
4138 enforceReadPrivilegedPermission();
4139
4140 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4141 if (slots == null) return null;
4142 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4143 for (int i = 0; i < slots.length; i++) {
4144 UiccSlot slot = slots[i];
4145
4146 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4147
4148 int cardState = 0;
4149 switch (slot.getCardState()) {
4150 case CARDSTATE_ABSENT:
4151 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4152 break;
4153 case CARDSTATE_PRESENT:
4154 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4155 break;
4156 case CARDSTATE_ERROR:
4157 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4158 break;
4159 case CARDSTATE_RESTRICTED:
4160 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4161 break;
4162 default:
4163 break;
4164
4165 }
4166
Qingxi Li795c5882018-01-31 13:43:27 -08004167 infos[i] = new UiccSlotInfo(
Qingxi Lie7245372018-03-07 10:52:26 -08004168 slot.isActive(),
4169 slot.isEuicc(),
4170 cardId,
4171 cardState,
4172 slot.getPhoneId(),
4173 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004174 }
4175 return infos;
4176 }
4177
4178 @Override
4179 public boolean switchSlots(int[] physicalSlots) {
4180 enforceModifyPermission();
4181 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4182 }
Jack Yu4c988042018-02-27 15:30:01 -08004183
4184 @Override
4185 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4186 enforceModifyPermission();
4187 final Phone phone = getPhone(subId);
4188 if (phone == null) {
4189 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4190 return;
4191 }
4192
4193 phone.setRadioIndicationUpdateMode(filters, mode);
4194 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07004195
4196 /**
4197 * Returns false if the mobile data is disabled by default, otherwise return true.
4198 */
4199 private boolean getDefaultDataEnabled() {
4200 return "true".equalsIgnoreCase(
4201 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
4202 }
4203
4204 /**
4205 * Returns true if the data roaming is enabled by default, i.e the system property
4206 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
4207 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
4208 */
4209 private boolean getDefaultDataRoamingEnabled(int subId) {
4210 final CarrierConfigManager configMgr = (CarrierConfigManager)
4211 mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
4212 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
4213 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
4214 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
4215 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
4216 return isDataRoamingEnabled;
4217 }
4218
4219 /**
4220 * Returns the default network type for the given {@code subId}, if the default network type is
4221 * not set, return {@link Phone#PREFERRED_NT_MODE}.
4222 */
4223 private int getDefaultNetworkType(int subId) {
4224 return Integer.parseInt(
4225 TelephonyManager.getTelephonyProperty(
4226 mSubscriptionController.getPhoneId(subId),
4227 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
4228 String.valueOf(Phone.PREFERRED_NT_MODE)));
4229 }
fionaxua13278b2018-03-21 00:08:13 -07004230
4231 @Override
4232 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
4233 gid1, String gid2, String plmn, String spn) {
4234 enforceModifyPermission();
4235 final Phone phone = getPhone(subId);
4236 if (phone == null) {
4237 loge("setCarrierTestOverride fails with invalid subId: " + subId);
4238 return;
4239 }
4240 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
4241 }
4242
4243 @Override
4244 public int getCarrierIdListVersion(int subId) {
4245 enforceReadPrivilegedPermission();
4246 final Phone phone = getPhone(subId);
4247 if (phone == null) {
4248 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
4249 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
4250 }
4251 return phone.getCarrierIdListVersion();
4252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004253}