blob: 678ab991de51d2750ee88b85b490f77c8c93bb23 [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 Ebinger7e934f52017-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;
45import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070046import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070047import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070048import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080049import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070050import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080051import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080052import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070053import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070054import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070057import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080058import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070059import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080060import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070061import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070062import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070063import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080065import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070066import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080067import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080068import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070069import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070070import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000071import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070072import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070073import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebingera12246d2018-01-16 09:39:35 -080074import android.telephony.ims.aidl.IImsConfig;
75import android.telephony.ims.aidl.IImsMmTelFeature;
76import android.telephony.ims.aidl.IImsRcsFeature;
77import android.telephony.ims.aidl.IImsRegistration;
Brad Ebingere21f25f2018-02-08 16:11:32 -080078import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080080import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080082import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080083import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080084
Andrew Lee312e8172014-10-23 17:01:36 -070085import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080086import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070087import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070088import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070089import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070090import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080093import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010094import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070095import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070096import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080098import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070099import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700100import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700101import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700103import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800104import com.android.internal.telephony.SubscriptionController;
Jeff Davidsond9a1bb52018-02-13 18:17:36 -0800105import com.android.internal.telephony.TelephonyPermissions;
Jonathan Basseri03923952017-07-19 12:22:35 -0700106import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700107import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700108import com.android.internal.telephony.uicc.IccIoResult;
109import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800110import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700111import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800112import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700113import com.android.internal.telephony.uicc.UiccController;
Jeff Davidsond9a1bb52018-02-13 18:17:36 -0800114import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000115import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700116import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800117import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700118import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800119import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700120import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700121import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800122
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700123import java.io.FileDescriptor;
124import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800125import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800127import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800128import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100129import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800130import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131
132/**
133 * Implementation of the ITelephony interface.
134 */
Santos Cordon117fee72014-05-16 17:56:12 -0700135public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136 private static final String LOG_TAG = "PhoneInterfaceManager";
137 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
138 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140
141 // Message codes used with mMainThreadHandler
142 private static final int CMD_HANDLE_PIN_MMI = 1;
143 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
144 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
145 private static final int CMD_ANSWER_RINGING_CALL = 4;
146 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700147 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
148 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149 private static final int CMD_OPEN_CHANNEL = 9;
150 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
151 private static final int CMD_CLOSE_CHANNEL = 11;
152 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800153 private static final int CMD_NV_READ_ITEM = 13;
154 private static final int EVENT_NV_READ_ITEM_DONE = 14;
155 private static final int CMD_NV_WRITE_ITEM = 15;
156 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
157 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
158 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
159 private static final int CMD_NV_RESET_CONFIG = 19;
160 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800161 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
162 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
163 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
164 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800165 private static final int CMD_SEND_ENVELOPE = 25;
166 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qianbf4c5392018-04-17 18:39:35 +0000167 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
168 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700169 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
170 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
171 private static final int CMD_EXCHANGE_SIM_IO = 31;
172 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800173 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
174 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700175 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
176 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700177 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
178 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700179 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
180 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
181 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
182 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700183 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
184 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
185 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
186 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700187 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800188 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
189 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000190 private static final int CMD_SWITCH_SLOTS = 50;
191 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800193 // Parameters of select command.
194 private static final int SELECT_COMMAND = 0xA4;
195 private static final int SELECT_P1 = 0x04;
196 private static final int SELECT_P2 = 0;
197 private static final int SELECT_P3 = 0x10;
198
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199 /** The singleton instance. */
200 private static PhoneInterfaceManager sInstance;
201
Wink Saville3ab207e2014-11-20 13:07:20 -0800202 private PhoneGlobals mApp;
203 private Phone mPhone;
204 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700205 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800206 private AppOpsManager mAppOps;
207 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800208 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800209 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700210
Derek Tan97ebb422014-09-05 16:55:38 -0700211 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
212 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800213 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700214
Derek Tan740e1672017-06-27 14:56:27 -0700215 // The AID of ISD-R.
216 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
217
yinxub1bed742017-04-17 11:45:04 -0700218 private NetworkScanRequestTracker mNetworkScanRequestTracker;
219
Derek Tan89e89d42014-07-08 17:00:10 -0700220 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700221 * A request object to use for transmitting data to an ICC.
222 */
223 private static final class IccAPDUArgument {
224 public int channel, cla, command, p1, p2, p3;
225 public String data;
226
227 public IccAPDUArgument(int channel, int cla, int command,
228 int p1, int p2, int p3, String data) {
229 this.channel = channel;
230 this.cla = cla;
231 this.command = command;
232 this.p1 = p1;
233 this.p2 = p2;
234 this.p3 = p3;
235 this.data = data;
236 }
237 }
238
239 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700240 * A request object to use for transmitting data to an ICC.
241 */
242 private static final class ManualNetworkSelectionArgument {
243 public OperatorInfo operatorInfo;
244 public boolean persistSelection;
245
246 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
247 this.operatorInfo = operatorInfo;
248 this.persistSelection = persistSelection;
249 }
250 }
251
252 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700253 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
254 * request after sending. The main thread will notify the request when it is complete.
255 */
256 private static final class MainThreadRequest {
257 /** The argument to use for the request */
258 public Object argument;
259 /** The result of the request that is run on the main thread */
260 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800261 // The subscriber id that this request applies to. Defaults to
262 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
263 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700264
265 public MainThreadRequest(Object argument) {
266 this.argument = argument;
267 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800268
269 public MainThreadRequest(Object argument, Integer subId) {
270 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800271 if (subId != null) {
272 this.subId = subId;
273 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 }
276
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800277 private static final class IncomingThirdPartyCallArgs {
278 public final ComponentName component;
279 public final String callId;
280 public final String callerDisplayName;
281
282 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
283 String callerDisplayName) {
284 this.component = component;
285 this.callId = callId;
286 this.callerDisplayName = callerDisplayName;
287 }
288 }
289
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290 /**
291 * A handler that processes messages on the main thread in the phone process. Since many
292 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
293 * inbound binder threads to the main thread in the phone process. The Binder thread
294 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
295 * on, which will be notified when the operation completes and will contain the result of the
296 * request.
297 *
298 * <p>If a MainThreadRequest object is provided in the msg.obj field,
299 * note that request.result must be set to something non-null for the calling thread to
300 * unblock.
301 */
302 private final class MainThreadHandler extends Handler {
303 @Override
304 public void handleMessage(Message msg) {
305 MainThreadRequest request;
306 Message onCompleted;
307 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800308 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700309 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310
311 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700312 case CMD_HANDLE_USSD_REQUEST: {
313 request = (MainThreadRequest) msg.obj;
314 final Phone phone = getPhoneFromRequest(request);
315 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
316 String ussdRequest = ussdObject.first;
317 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700318
319 if (!isUssdApiAllowed(request.subId)) {
320 // Carrier does not support use of this API, return failure.
321 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
322 UssdResponse response = new UssdResponse(ussdRequest, null);
323 Bundle returnData = new Bundle();
324 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
325 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
326
327 request.result = true;
328 synchronized (request) {
329 request.notifyAll();
330 }
331 return;
332 }
333
Tyler Gunn52dcf772017-04-26 11:30:31 -0700334 try {
335 request.result = phone != null ?
336 phone.handleUssdRequest(ussdRequest, wrappedCallback)
337 : false;
338 } catch (CallStateException cse) {
339 request.result = false;
340 }
pkanwar32d516d2016-10-14 19:37:38 -0700341 // Wake up the requesting thread
342 synchronized (request) {
343 request.notifyAll();
344 }
345 break;
346 }
347
Yorke Lee716f67e2015-06-17 15:39:16 -0700348 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700350 final Phone phone = getPhoneFromRequest(request);
351 request.result = phone != null ?
352 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
353 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 // Wake up the requesting thread
355 synchronized (request) {
356 request.notifyAll();
357 }
358 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
361 case CMD_HANDLE_NEIGHBORING_CELL:
362 request = (MainThreadRequest) msg.obj;
363 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
364 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700365 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 break;
367
368 case EVENT_NEIGHBORING_CELL_DONE:
369 ar = (AsyncResult) msg.obj;
370 request = (MainThreadRequest) ar.userObj;
371 if (ar.exception == null && ar.result != null) {
372 request.result = ar.result;
373 } else {
374 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800375 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 }
377 // Wake up the requesting thread
378 synchronized (request) {
379 request.notifyAll();
380 }
381 break;
382
383 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700384 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800385 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700386 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 break;
388
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389 case CMD_END_CALL:
390 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800391 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700392 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700393 Phone phone = getPhone(end_subId);
394 if (phone == null) {
395 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
396 break;
397 }
398 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
400 // CDMA: If the user presses the Power button we treat it as
401 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700402 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
404 // GSM: End the call as per the Phone state
405 hungUp = PhoneUtils.hangup(mCM);
406 } else {
407 throw new IllegalStateException("Unexpected phone type: " + phoneType);
408 }
409 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
410 request.result = hungUp;
411 // Wake up the requesting thread
412 synchronized (request) {
413 request.notifyAll();
414 }
415 break;
416
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700417 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700418 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700419 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800420 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700421 if (uiccCard == null) {
422 loge("iccTransmitApduLogicalChannel: No UICC");
423 request.result = new IccIoResult(0x6F, 0, (byte[])null);
424 synchronized (request) {
425 request.notifyAll();
426 }
427 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
429 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700430 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700431 iccArgument.channel, iccArgument.cla, iccArgument.command,
432 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700434 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 break;
436
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 ar = (AsyncResult) msg.obj;
439 request = (MainThreadRequest) ar.userObj;
440 if (ar.exception == null && ar.result != null) {
441 request.result = ar.result;
442 } else {
443 request.result = new IccIoResult(0x6F, 0, (byte[])null);
444 if (ar.result == null) {
445 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800446 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800448 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 } else {
450 loge("iccTransmitApduLogicalChannel: Unknown exception");
451 }
452 }
453 synchronized (request) {
454 request.notifyAll();
455 }
456 break;
457
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
459 request = (MainThreadRequest) msg.obj;
460 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800461 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 if (uiccCard == null) {
463 loge("iccTransmitApduBasicChannel: No UICC");
464 request.result = new IccIoResult(0x6F, 0, (byte[])null);
465 synchronized (request) {
466 request.notifyAll();
467 }
468 } else {
469 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
470 request);
471 uiccCard.iccTransmitApduBasicChannel(
472 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
473 iccArgument.p3, iccArgument.data, onCompleted);
474 }
475 break;
476
477 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
478 ar = (AsyncResult) msg.obj;
479 request = (MainThreadRequest) ar.userObj;
480 if (ar.exception == null && ar.result != null) {
481 request.result = ar.result;
482 } else {
483 request.result = new IccIoResult(0x6F, 0, (byte[])null);
484 if (ar.result == null) {
485 loge("iccTransmitApduBasicChannel: Empty response");
486 } else if (ar.exception instanceof CommandException) {
487 loge("iccTransmitApduBasicChannel: CommandException: " +
488 ar.exception);
489 } else {
490 loge("iccTransmitApduBasicChannel: Unknown exception");
491 }
492 }
493 synchronized (request) {
494 request.notifyAll();
495 }
496 break;
497
498 case CMD_EXCHANGE_SIM_IO:
499 request = (MainThreadRequest) msg.obj;
500 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800501 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 if (uiccCard == null) {
503 loge("iccExchangeSimIO: No UICC");
504 request.result = new IccIoResult(0x6F, 0, (byte[])null);
505 synchronized (request) {
506 request.notifyAll();
507 }
508 } else {
509 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
510 request);
511 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
512 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
513 iccArgument.data, onCompleted);
514 }
515 break;
516
517 case EVENT_EXCHANGE_SIM_IO_DONE:
518 ar = (AsyncResult) msg.obj;
519 request = (MainThreadRequest) ar.userObj;
520 if (ar.exception == null && ar.result != null) {
521 request.result = ar.result;
522 } else {
523 request.result = new IccIoResult(0x6f, 0, (byte[])null);
524 }
525 synchronized (request) {
526 request.notifyAll();
527 }
528 break;
529
Derek Tan4d5e5c12014-02-04 11:54:58 -0800530 case CMD_SEND_ENVELOPE:
531 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800532 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700533 if (uiccCard == null) {
534 loge("sendEnvelopeWithStatus: No UICC");
535 request.result = new IccIoResult(0x6F, 0, (byte[])null);
536 synchronized (request) {
537 request.notifyAll();
538 }
539 } else {
540 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
541 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
542 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800543 break;
544
545 case EVENT_SEND_ENVELOPE_DONE:
546 ar = (AsyncResult) msg.obj;
547 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700548 if (ar.exception == null && ar.result != null) {
549 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800550 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700551 request.result = new IccIoResult(0x6F, 0, (byte[])null);
552 if (ar.result == null) {
553 loge("sendEnvelopeWithStatus: Empty response");
554 } else if (ar.exception instanceof CommandException) {
555 loge("sendEnvelopeWithStatus: CommandException: " +
556 ar.exception);
557 } else {
558 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
559 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800560 }
561 synchronized (request) {
562 request.notifyAll();
563 }
564 break;
565
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 case CMD_OPEN_CHANNEL:
567 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800568 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800569 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 if (uiccCard == null) {
571 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800572 request.result = new IccOpenLogicalChannelResponse(-1,
573 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700574 synchronized (request) {
575 request.notifyAll();
576 }
577 } else {
578 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800579 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
580 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 break;
583
584 case EVENT_OPEN_CHANNEL_DONE:
585 ar = (AsyncResult) msg.obj;
586 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 int[] result = (int[]) ar.result;
590 int channelId = result[0];
591 byte[] selectResponse = null;
592 if (result.length > 1) {
593 selectResponse = new byte[result.length - 1];
594 for (int i = 1; i < result.length; ++i) {
595 selectResponse[i - 1] = (byte) result[i];
596 }
597 }
598 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700599 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 if (ar.result == null) {
602 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 if (ar.exception != null) {
605 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
606 }
607
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700608 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700609 if (ar.exception instanceof CommandException) {
610 CommandException.Error error =
611 ((CommandException) (ar.exception)).getCommandError();
612 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700614 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700615 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 }
617 }
618 openChannelResp = new IccOpenLogicalChannelResponse(
619 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700621 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 synchronized (request) {
623 request.notifyAll();
624 }
625 break;
626
627 case CMD_CLOSE_CHANNEL:
628 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800629 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 if (uiccCard == null) {
631 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900632 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 synchronized (request) {
634 request.notifyAll();
635 }
636 } else {
637 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
638 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
639 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 break;
641
642 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800643 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
644 break;
645
646 case CMD_NV_READ_ITEM:
647 request = (MainThreadRequest) msg.obj;
648 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
649 mPhone.nvReadItem((Integer) request.argument, onCompleted);
650 break;
651
652 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 ar = (AsyncResult) msg.obj;
654 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800655 if (ar.exception == null && ar.result != null) {
656 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800658 request.result = "";
659 if (ar.result == null) {
660 loge("nvReadItem: Empty response");
661 } else if (ar.exception instanceof CommandException) {
662 loge("nvReadItem: CommandException: " +
663 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800665 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 }
667 }
668 synchronized (request) {
669 request.notifyAll();
670 }
671 break;
672
Jake Hambye994d462014-02-03 13:10:13 -0800673 case CMD_NV_WRITE_ITEM:
674 request = (MainThreadRequest) msg.obj;
675 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
676 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
677 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
678 break;
679
680 case EVENT_NV_WRITE_ITEM_DONE:
681 handleNullReturnEvent(msg, "nvWriteItem");
682 break;
683
684 case CMD_NV_WRITE_CDMA_PRL:
685 request = (MainThreadRequest) msg.obj;
686 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
687 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
688 break;
689
690 case EVENT_NV_WRITE_CDMA_PRL_DONE:
691 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
692 break;
693
694 case CMD_NV_RESET_CONFIG:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
697 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
698 break;
699
700 case EVENT_NV_RESET_CONFIG_DONE:
701 handleNullReturnEvent(msg, "nvResetConfig");
702 break;
703
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 case CMD_GET_PREFERRED_NETWORK_TYPE:
705 request = (MainThreadRequest) msg.obj;
706 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700707 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800708 break;
709
710 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
711 ar = (AsyncResult) msg.obj;
712 request = (MainThreadRequest) ar.userObj;
713 if (ar.exception == null && ar.result != null) {
714 request.result = ar.result; // Integer
715 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800716 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800717 if (ar.result == null) {
718 loge("getPreferredNetworkType: Empty response");
719 } else if (ar.exception instanceof CommandException) {
720 loge("getPreferredNetworkType: CommandException: " +
721 ar.exception);
722 } else {
723 loge("getPreferredNetworkType: Unknown exception");
724 }
725 }
726 synchronized (request) {
727 request.notifyAll();
728 }
729 break;
730
731 case CMD_SET_PREFERRED_NETWORK_TYPE:
732 request = (MainThreadRequest) msg.obj;
733 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
734 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700735 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800736 break;
737
738 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
739 handleNullReturnEvent(msg, "setPreferredNetworkType");
740 break;
741
Shuo Qianbf4c5392018-04-17 18:39:35 +0000742 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
743 request = (MainThreadRequest)msg.obj;
744 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
745 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
746 break;
747
748 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
749 ar = (AsyncResult)msg.obj;
750 request = (MainThreadRequest)ar.userObj;
751 request.result = ar;
752 synchronized (request) {
753 request.notifyAll();
754 }
755 break;
756
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800757 case CMD_SET_VOICEMAIL_NUMBER:
758 request = (MainThreadRequest) msg.obj;
759 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
760 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800761 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
762 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800763 break;
764
765 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
766 handleNullReturnEvent(msg, "setVoicemailNumber");
767 break;
768
Stuart Scott54788802015-03-30 13:18:01 -0700769 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
770 request = (MainThreadRequest) msg.obj;
771 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
772 request);
773 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
774 break;
775
776 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
777 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
778 break;
779
Shishir Agrawal302c8692015-06-19 13:49:39 -0700780 case CMD_PERFORM_NETWORK_SCAN:
781 request = (MainThreadRequest) msg.obj;
782 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
783 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
784 break;
785
786 case EVENT_PERFORM_NETWORK_SCAN_DONE:
787 ar = (AsyncResult) msg.obj;
788 request = (MainThreadRequest) ar.userObj;
789 CellNetworkScanResult cellScanResult;
790 if (ar.exception == null && ar.result != null) {
791 cellScanResult = new CellNetworkScanResult(
792 CellNetworkScanResult.STATUS_SUCCESS,
793 (List<OperatorInfo>) ar.result);
794 } else {
795 if (ar.result == null) {
796 loge("getCellNetworkScanResults: Empty response");
797 }
798 if (ar.exception != null) {
799 loge("getCellNetworkScanResults: Exception: " + ar.exception);
800 }
801 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
802 if (ar.exception instanceof CommandException) {
803 CommandException.Error error =
804 ((CommandException) (ar.exception)).getCommandError();
805 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
806 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
807 } else if (error == CommandException.Error.GENERIC_FAILURE) {
808 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
809 }
810 }
811 cellScanResult = new CellNetworkScanResult(errorCode, null);
812 }
813 request.result = cellScanResult;
814 synchronized (request) {
815 request.notifyAll();
816 }
817 break;
818
819 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
820 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700821 ManualNetworkSelectionArgument selArg =
822 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700823 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
824 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700825 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
826 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700827 break;
828
829 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
830 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
831 break;
832
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700833 case CMD_GET_MODEM_ACTIVITY_INFO:
834 request = (MainThreadRequest) msg.obj;
835 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700836 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700837 break;
838
839 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
840 ar = (AsyncResult) msg.obj;
841 request = (MainThreadRequest) ar.userObj;
842 if (ar.exception == null && ar.result != null) {
843 request.result = ar.result;
844 } else {
845 if (ar.result == null) {
846 loge("queryModemActivityInfo: Empty response");
847 } else if (ar.exception instanceof CommandException) {
848 loge("queryModemActivityInfo: CommandException: " +
849 ar.exception);
850 } else {
851 loge("queryModemActivityInfo: Unknown exception");
852 }
853 }
Amit Mahajand4766222016-01-28 15:28:28 -0800854 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
855 if (request.result == null) {
856 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
857 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700858 synchronized (request) {
859 request.notifyAll();
860 }
861 break;
862
Meng Wang1a7c35a2016-05-05 20:56:15 -0700863 case CMD_SET_ALLOWED_CARRIERS:
864 request = (MainThreadRequest) msg.obj;
865 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
866 mPhone.setAllowedCarriers(
867 (List<CarrierIdentifier>) request.argument,
868 onCompleted);
869 break;
870
871 case EVENT_SET_ALLOWED_CARRIERS_DONE:
872 ar = (AsyncResult) msg.obj;
873 request = (MainThreadRequest) ar.userObj;
874 if (ar.exception == null && ar.result != null) {
875 request.result = ar.result;
876 } else {
877 if (ar.result == null) {
878 loge("setAllowedCarriers: Empty response");
879 } else if (ar.exception instanceof CommandException) {
880 loge("setAllowedCarriers: CommandException: " +
881 ar.exception);
882 } else {
883 loge("setAllowedCarriers: Unknown exception");
884 }
885 }
886 // Result cannot be null. Return -1 on error.
887 if (request.result == null) {
888 request.result = new int[]{-1};
889 }
890 synchronized (request) {
891 request.notifyAll();
892 }
893 break;
894
895 case CMD_GET_ALLOWED_CARRIERS:
896 request = (MainThreadRequest) msg.obj;
897 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
898 mPhone.getAllowedCarriers(onCompleted);
899 break;
900
901 case EVENT_GET_ALLOWED_CARRIERS_DONE:
902 ar = (AsyncResult) msg.obj;
903 request = (MainThreadRequest) ar.userObj;
904 if (ar.exception == null && ar.result != null) {
905 request.result = ar.result;
906 } else {
907 if (ar.result == null) {
908 loge("getAllowedCarriers: Empty response");
909 } else if (ar.exception instanceof CommandException) {
910 loge("getAllowedCarriers: CommandException: " +
911 ar.exception);
912 } else {
913 loge("getAllowedCarriers: Unknown exception");
914 }
915 }
916 // Result cannot be null. Return empty list of CarrierIdentifier.
917 if (request.result == null) {
918 request.result = new ArrayList<CarrierIdentifier>(0);
919 }
920 synchronized (request) {
921 request.notifyAll();
922 }
923 break;
924
Nathan Haroldb3014052017-01-25 15:57:32 -0800925 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
926 ar = (AsyncResult) msg.obj;
927 request = (MainThreadRequest) ar.userObj;
928 if (ar.exception == null && ar.result != null) {
929 request.result = ar.result;
930 } else {
931 request.result = new IllegalArgumentException(
932 "Failed to retrieve Forbidden Plmns");
933 if (ar.result == null) {
934 loge("getForbiddenPlmns: Empty response");
935 } else {
936 loge("getForbiddenPlmns: Unknown exception");
937 }
938 }
939 synchronized (request) {
940 request.notifyAll();
941 }
942 break;
943
944 case CMD_GET_FORBIDDEN_PLMNS:
945 request = (MainThreadRequest) msg.obj;
946 uiccCard = getUiccCardFromRequest(request);
947 if (uiccCard == null) {
948 loge("getForbiddenPlmns() UiccCard is null");
949 request.result = new IllegalArgumentException(
950 "getForbiddenPlmns() UiccCard is null");
951 synchronized (request) {
952 request.notifyAll();
953 }
954 break;
955 }
956 Integer appType = (Integer) request.argument;
957 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
958 if (uiccApp == null) {
959 loge("getForbiddenPlmns() no app with specified type -- "
960 + appType);
961 request.result = new IllegalArgumentException("Failed to get UICC App");
962 synchronized (request) {
963 request.notifyAll();
964 }
965 break;
966 } else {
967 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
968 + " specified type -- " + appType);
969 }
970 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
971 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
972 onCompleted);
973 break;
974
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000975 case CMD_SWITCH_SLOTS:
976 request = (MainThreadRequest) msg.obj;
977 int[] physicalSlots = (int[]) request.argument;
978 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
979 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
980 break;
981
982 case EVENT_SWITCH_SLOTS_DONE:
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 request.result = (ar.exception == null);
986 synchronized (request) {
987 request.notifyAll();
988 }
989 break;
990
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700991 default:
992 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
993 break;
994 }
995 }
Jake Hambye994d462014-02-03 13:10:13 -0800996
997 private void handleNullReturnEvent(Message msg, String command) {
998 AsyncResult ar = (AsyncResult) msg.obj;
999 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1000 if (ar.exception == null) {
1001 request.result = true;
1002 } else {
1003 request.result = false;
1004 if (ar.exception instanceof CommandException) {
1005 loge(command + ": CommandException: " + ar.exception);
1006 } else {
1007 loge(command + ": Unknown exception");
1008 }
1009 }
1010 synchronized (request) {
1011 request.notifyAll();
1012 }
1013 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001014 }
1015
1016 /**
1017 * Posts the specified command to be executed on the main thread,
1018 * waits for the request to complete, and returns the result.
1019 * @see #sendRequestAsync
1020 */
1021 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001022 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001023 }
1024
1025 /**
1026 * Posts the specified command to be executed on the main thread,
1027 * waits for the request to complete, and returns the result.
1028 * @see #sendRequestAsync
1029 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001030 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001031 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1032 throw new RuntimeException("This method will deadlock if called from the main thread.");
1033 }
1034
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001035 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001036 Message msg = mMainThreadHandler.obtainMessage(command, request);
1037 msg.sendToTarget();
1038
1039 // Wait for the request to complete
1040 synchronized (request) {
1041 while (request.result == null) {
1042 try {
1043 request.wait();
1044 } catch (InterruptedException e) {
1045 // Do nothing, go back and wait until the request is complete
1046 }
1047 }
1048 }
1049 return request.result;
1050 }
1051
1052 /**
1053 * Asynchronous ("fire and forget") version of sendRequest():
1054 * Posts the specified command to be executed on the main thread, and
1055 * returns immediately.
1056 * @see #sendRequest
1057 */
1058 private void sendRequestAsync(int command) {
1059 mMainThreadHandler.sendEmptyMessage(command);
1060 }
1061
1062 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001063 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1064 * @see {@link #sendRequest(int,Object)}
1065 */
1066 private void sendRequestAsync(int command, Object argument) {
1067 MainThreadRequest request = new MainThreadRequest(argument);
1068 Message msg = mMainThreadHandler.obtainMessage(command, request);
1069 msg.sendToTarget();
1070 }
1071
1072 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001073 * Initialize the singleton PhoneInterfaceManager instance.
1074 * This is only done once, at startup, from PhoneApp.onCreate().
1075 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001076 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001077 synchronized (PhoneInterfaceManager.class) {
1078 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001079 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001080 } else {
1081 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1082 }
1083 return sInstance;
1084 }
1085 }
1086
1087 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001088 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001089 mApp = app;
1090 mPhone = phone;
1091 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001092 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001093 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1094 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001095 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001096 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001097 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001098 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001099
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001100 publish();
1101 }
1102
1103 private void publish() {
1104 if (DBG) log("publish: " + this);
1105
1106 ServiceManager.addService("phone", this);
1107 }
1108
Stuart Scott584921c2015-01-15 17:10:34 -08001109 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001110 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1111 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001112 }
1113
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001114 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1115 Phone phone = getPhoneFromRequest(request);
1116 return phone == null ? null :
1117 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1118 }
1119
Wink Saville36469e72014-06-11 15:17:00 -07001120 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001121 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001122 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001123 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001124 //
1125 // Implementation of the ITelephony interface.
1126 //
1127
1128 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001129 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001130 }
1131
Wink Savilleb564aae2014-10-23 10:18:09 -07001132 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001133 if (DBG) log("dial: " + number);
1134 // No permission check needed here: This is just a wrapper around the
1135 // ACTION_DIAL intent, which is available to any app since it puts up
1136 // the UI before it does anything.
1137
1138 String url = createTelUrl(number);
1139 if (url == null) {
1140 return;
1141 }
1142
1143 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001144 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001145 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1146 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1147 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1148 mApp.startActivity(intent);
1149 }
1150 }
1151
1152 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001153 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001154 }
1155
Wink Savilleb564aae2014-10-23 10:18:09 -07001156 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001157 if (DBG) log("call: " + number);
1158
1159 // This is just a wrapper around the ACTION_CALL intent, but we still
1160 // need to do a permission check since we're calling startActivity()
1161 // from the context of the phone app.
1162 enforceCallPermission();
1163
1164 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1165 != AppOpsManager.MODE_ALLOWED) {
1166 return;
1167 }
1168
1169 String url = createTelUrl(number);
1170 if (url == null) {
1171 return;
1172 }
1173
Wink Saville08874612014-08-31 19:19:58 -07001174 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001175 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001176 if (slist != null) {
1177 for (SubscriptionInfo subInfoRecord : slist) {
1178 if (subInfoRecord.getSubscriptionId() == subId) {
1179 isValid = true;
1180 break;
1181 }
Wink Saville08874612014-08-31 19:19:58 -07001182 }
1183 }
1184 if (isValid == false) {
1185 return;
1186 }
1187
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001188 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001189 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1191 mApp.startActivity(intent);
1192 }
1193
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001194 /**
1195 * End a call based on call state
1196 * @return true is a call was ended
1197 */
1198 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001199 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001200 }
1201
1202 /**
1203 * End a call based on the call state of the subId
1204 * @return true is a call was ended
1205 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001206 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001207 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001208 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001209 }
1210
1211 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001212 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001213 }
1214
Wink Savilleb564aae2014-10-23 10:18:09 -07001215 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001216 if (DBG) log("answerRingingCall...");
1217 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1218 // but that can probably wait till the big TelephonyManager API overhaul.
1219 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1220 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001221 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001222 }
1223
1224 /**
1225 * Make the actual telephony calls to implement answerRingingCall().
1226 * This should only be called from the main thread of the Phone app.
1227 * @see #answerRingingCall
1228 *
1229 * TODO: it would be nice to return true if we answered the call, or
1230 * false if there wasn't actually a ringing incoming call, or some
1231 * other error occurred. (In other words, pass back the return value
1232 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1233 * But that would require calling this method via sendRequest() rather
1234 * than sendRequestAsync(), and right now we don't actually *need* that
1235 * return value, so let's just return void for now.
1236 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001237 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001238 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001239 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001240 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1241 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001242 if (hasActiveCall && hasHoldingCall) {
1243 // Both lines are in use!
1244 // TODO: provide a flag to let the caller specify what
1245 // policy to use if both lines are in use. (The current
1246 // behavior is hardwired to "answer incoming, end ongoing",
1247 // which is how the CALL button is specced to behave.)
1248 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1249 return;
1250 } else {
1251 // answerCall() will automatically hold the current active
1252 // call, if there is one.
1253 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1254 return;
1255 }
1256 } else {
1257 // No call was ringing.
1258 return;
1259 }
1260 }
1261
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001263 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001265 public void silenceRinger() {
1266 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001267 }
1268
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001269 @Override
1270 public boolean isOffhook(String callingPackage) {
1271 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001272 }
1273
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001274 @Override
1275 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001276 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001277 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001278 return false;
1279 }
1280
Sanket Padawe356d7632015-06-22 14:03:32 -07001281 final Phone phone = getPhone(subId);
1282 if (phone != null) {
1283 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1284 } else {
1285 return false;
1286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001287 }
1288
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001289 @Override
1290 public boolean isRinging(String callingPackage) {
1291 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001292 }
1293
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001294 @Override
1295 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001297 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001298 return false;
1299 }
1300
Sanket Padawe356d7632015-06-22 14:03:32 -07001301 final Phone phone = getPhone(subId);
1302 if (phone != null) {
1303 return (phone.getState() == PhoneConstants.State.RINGING);
1304 } else {
1305 return false;
1306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001307 }
1308
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001309 @Override
1310 public boolean isIdle(String callingPackage) {
1311 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001312 }
1313
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001314 @Override
1315 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001316 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001317 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001318 return false;
1319 }
1320
Sanket Padawe356d7632015-06-22 14:03:32 -07001321 final Phone phone = getPhone(subId);
1322 if (phone != null) {
1323 return (phone.getState() == PhoneConstants.State.IDLE);
1324 } else {
1325 return false;
1326 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327 }
1328
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001330 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001331 }
1332
Wink Savilleb564aae2014-10-23 10:18:09 -07001333 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001334 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001335 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1336 }
1337
1338 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001339 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001340 }
1341
Wink Savilleb564aae2014-10-23 10:18:09 -07001342 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001343 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001344 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1345 }
1346
1347 /** {@hide} */
1348 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001349 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001350 }
1351
Wink Savilleb564aae2014-10-23 10:18:09 -07001352 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001353 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001354 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001355 checkSimPin.start();
1356 return checkSimPin.unlockSim(null, pin);
1357 }
1358
Wink Saville9de0f752013-10-22 19:04:03 -07001359 /** {@hide} */
1360 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001361 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001362 }
1363
Wink Savilleb564aae2014-10-23 10:18:09 -07001364 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001366 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001367 checkSimPuk.start();
1368 return checkSimPuk.unlockSim(puk, pin);
1369 }
1370
1371 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001372 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001373 * a synchronous one.
1374 */
1375 private static class UnlockSim extends Thread {
1376
1377 private final IccCard mSimCard;
1378
1379 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001380 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1381 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382
1383 // For replies from SimCard interface
1384 private Handler mHandler;
1385
1386 // For async handler to identify request type
1387 private static final int SUPPLY_PIN_COMPLETE = 100;
1388
1389 public UnlockSim(IccCard simCard) {
1390 mSimCard = simCard;
1391 }
1392
1393 @Override
1394 public void run() {
1395 Looper.prepare();
1396 synchronized (UnlockSim.this) {
1397 mHandler = new Handler() {
1398 @Override
1399 public void handleMessage(Message msg) {
1400 AsyncResult ar = (AsyncResult) msg.obj;
1401 switch (msg.what) {
1402 case SUPPLY_PIN_COMPLETE:
1403 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1404 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001405 mRetryCount = msg.arg1;
1406 if (ar.exception != null) {
1407 if (ar.exception instanceof CommandException &&
1408 ((CommandException)(ar.exception)).getCommandError()
1409 == CommandException.Error.PASSWORD_INCORRECT) {
1410 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1411 } else {
1412 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1413 }
1414 } else {
1415 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1416 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001417 mDone = true;
1418 UnlockSim.this.notifyAll();
1419 }
1420 break;
1421 }
1422 }
1423 };
1424 UnlockSim.this.notifyAll();
1425 }
1426 Looper.loop();
1427 }
1428
1429 /*
1430 * Use PIN or PUK to unlock SIM card
1431 *
1432 * If PUK is null, unlock SIM card with PIN
1433 *
1434 * If PUK is not null, unlock SIM card with PUK and set PIN code
1435 */
Wink Saville9de0f752013-10-22 19:04:03 -07001436 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001437
1438 while (mHandler == null) {
1439 try {
1440 wait();
1441 } catch (InterruptedException e) {
1442 Thread.currentThread().interrupt();
1443 }
1444 }
1445 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1446
1447 if (puk == null) {
1448 mSimCard.supplyPin(pin, callback);
1449 } else {
1450 mSimCard.supplyPuk(puk, pin, callback);
1451 }
1452
1453 while (!mDone) {
1454 try {
1455 Log.d(LOG_TAG, "wait for done");
1456 wait();
1457 } catch (InterruptedException e) {
1458 // Restore the interrupted status
1459 Thread.currentThread().interrupt();
1460 }
1461 }
1462 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001463 int[] resultArray = new int[2];
1464 resultArray[0] = mResult;
1465 resultArray[1] = mRetryCount;
1466 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001467 }
1468 }
1469
1470 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001471 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001472
1473 }
1474
Wink Savilleb564aae2014-10-23 10:18:09 -07001475 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001476 // No permission check needed here: this call is harmless, and it's
1477 // needed for the ServiceState.requestStateUpdate() call (which is
1478 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001479 final Phone phone = getPhone(subId);
1480 if (phone != null) {
1481 phone.updateServiceLocation();
1482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001485 @Override
1486 public boolean isRadioOn(String callingPackage) {
1487 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001488 }
1489
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001490 @Override
1491 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001492 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001493 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001494 return false;
1495 }
1496 return isRadioOnForSubscriber(subId);
1497 }
1498
1499 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001500 final Phone phone = getPhone(subId);
1501 if (phone != null) {
1502 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1503 } else {
1504 return false;
1505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506 }
1507
1508 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001509 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001510
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511 }
Wink Saville36469e72014-06-11 15:17:00 -07001512
Wink Savilleb564aae2014-10-23 10:18:09 -07001513 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001514 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001515 final Phone phone = getPhone(subId);
1516 if (phone != null) {
1517 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1518 }
Wink Saville36469e72014-06-11 15:17:00 -07001519 }
1520
1521 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001522 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001523 }
1524
Wink Savilleb564aae2014-10-23 10:18:09 -07001525 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001526 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001527 final Phone phone = getPhone(subId);
1528 if (phone == null) {
1529 return false;
1530 }
1531 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001532 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001533 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001534 }
1535 return true;
1536 }
Wink Saville36469e72014-06-11 15:17:00 -07001537
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001538 public boolean needMobileRadioShutdown() {
1539 /*
1540 * If any of the Radios are available, it will need to be
1541 * shutdown. So return true if any Radio is available.
1542 */
1543 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1544 Phone phone = PhoneFactory.getPhone(i);
1545 if (phone != null && phone.isRadioAvailable()) return true;
1546 }
1547 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1548 return false;
1549 }
1550
1551 public void shutdownMobileRadios() {
1552 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1553 logv("Shutting down Phone " + i);
1554 shutdownRadioUsingPhoneId(i);
1555 }
1556 }
1557
1558 private void shutdownRadioUsingPhoneId(int phoneId) {
1559 enforceModifyPermission();
1560 Phone phone = PhoneFactory.getPhone(phoneId);
1561 if (phone != null && phone.isRadioAvailable()) {
1562 phone.shutdownRadio();
1563 }
1564 }
1565
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001566 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001567 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001568 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1569 if (defaultPhone != null) {
1570 defaultPhone.setRadioPower(turnOn);
1571 return true;
1572 } else {
1573 loge("There's no default phone.");
1574 return false;
1575 }
Wink Saville36469e72014-06-11 15:17:00 -07001576 }
1577
Wink Savilleb564aae2014-10-23 10:18:09 -07001578 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 final Phone phone = getPhone(subId);
1581 if (phone != null) {
1582 phone.setRadioPower(turnOn);
1583 return true;
1584 } else {
1585 return false;
1586 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 }
1588
Wink Saville36469e72014-06-11 15:17:00 -07001589 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001590 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 public boolean enableDataConnectivity() {
1592 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001593 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 final Phone phone = getPhone(subId);
1595 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001596 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001597 return true;
1598 } else {
1599 return false;
1600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 }
1602
Wink Saville36469e72014-06-11 15:17:00 -07001603 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001604 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 public boolean disableDataConnectivity() {
1606 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001607 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001608 final Phone phone = getPhone(subId);
1609 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001610 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001611 return true;
1612 } else {
1613 return false;
1614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 }
1616
Sanket Padawe356d7632015-06-22 14:03:32 -07001617 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001618 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 final Phone phone = getPhone(subId);
1620 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001621 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001622 } else {
1623 return false;
1624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 }
1626
1627 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001628 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001629 }
1630
pkanwarae03a6b2016-11-06 20:37:09 -08001631 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001632 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001633 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1634 return;
1635 }
1636 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1637 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1638 };
1639
Wink Savilleb564aae2014-10-23 10:18:09 -07001640 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001642 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1643 return false;
1644 }
Wink Saville36469e72014-06-11 15:17:00 -07001645 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 }
1647
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001649 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001650 }
1651
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001652 public int getCallStateForSlot(int slotIndex) {
1653 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001654 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001655 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 }
1657
Sanket Padawe356d7632015-06-22 14:03:32 -07001658 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001660 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001661 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001662 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001663 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001664 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 }
1667
Sanket Padawe356d7632015-06-22 14:03:32 -07001668 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001670 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001671 if (phone != null) {
1672 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1673 } else {
1674 return TelephonyManager.DATA_ACTIVITY_NONE;
1675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 }
1677
1678 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001679 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001680 mPhone.getContext().getSystemService(AppOpsManager.class)
1681 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001682 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001683 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001684 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 }
1686
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001687 if (DBG_LOC) log("getCellLocation: is active user");
1688 Bundle data = new Bundle();
1689 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1690 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 return null;
1692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001694 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1695 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1696 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001697 }
1698
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001700 public String getNetworkCountryIsoForPhone(int phoneId) {
1701 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1702 // registered cell info, so return a NULL country instead.
1703 final long identity = Binder.clearCallingIdentity();
1704 try {
1705 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1706 if (TelephonyManager.NETWORK_TYPE_IWLAN
1707 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1708 return "";
1709 }
1710 } finally {
1711 Binder.restoreCallingIdentity(identity);
1712 }
1713 return TelephonyManager.getTelephonyProperty(
1714 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1715 }
1716
1717 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001719 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001720 }
1721
Sanket Padawe356d7632015-06-22 14:03:32 -07001722 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001723 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 mApp.enforceCallingOrSelfPermission(
1725 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001726 final Phone phone = getPhone(subId);
1727 if (phone != null) {
1728 phone.enableLocationUpdates();
1729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 }
1731
1732 @Override
1733 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001734 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001735 }
1736
Sanket Padawe356d7632015-06-22 14:03:32 -07001737 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001738 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739 mApp.enforceCallingOrSelfPermission(
1740 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001741 final Phone phone = getPhone(subId);
1742 if (phone != null) {
1743 phone.disableLocationUpdates();
1744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
1746
1747 @Override
1748 @SuppressWarnings("unchecked")
1749 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001750 mPhone.getContext().getSystemService(AppOpsManager.class)
1751 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001752 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001753 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001754 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 }
1756
1757 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1758 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1759 return null;
1760 }
Svetoslav64fad262015-04-14 14:35:21 -07001761
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001762 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001763
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001764 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001766 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1767 try {
1768 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1769 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1770 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1771 } catch (RuntimeException e) {
1772 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001774 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 }
1776
1777
1778 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001779 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001780 mPhone.getContext().getSystemService(AppOpsManager.class)
1781 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001782 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001783 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001784 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
1786
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001787 if (DBG_LOC) log("getAllCellInfo: is active user");
1788 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1789 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1790 for (Phone phone : PhoneFactory.getPhones()) {
1791 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1792 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001794 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001795 }
1796
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001797 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001798 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001799 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001800 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1801 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001802 }
1803
Shishir Agrawala9f32182016-04-12 12:00:16 -07001804 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001805 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001806 Phone phone = PhoneFactory.getPhone(slotIndex);
1807 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001808 return null;
1809 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001810 int subId = phone.getSubId();
1811 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1812 mApp, subId, callingPackage, "getImeiForSlot")) {
1813 return null;
1814 }
1815 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001816 }
1817
1818 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001819 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001820 Phone phone = PhoneFactory.getPhone(slotIndex);
1821 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001822 return null;
1823 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001824 int subId = phone.getSubId();
1825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1826 mApp, subId, callingPackage, "getMeidForSlot")) {
1827 return null;
1828 }
1829 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001830 }
1831
1832 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001833 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001834 Phone phone = PhoneFactory.getPhone(slotIndex);
1835 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001836 return null;
1837 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001838 int subId = phone.getSubId();
1839 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1840 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1841 return null;
1842 }
1843 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001844 }
1845
fionaxuf32acdf2017-11-27 22:51:16 -08001846 @Override
1847 public int getSubscriptionCarrierId(int subId) {
1848 final Phone phone = getPhone(subId);
1849 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1850 }
1851
1852 @Override
1853 public String getSubscriptionCarrierName(int subId) {
1854 final Phone phone = getPhone(subId);
1855 return phone == null ? null : phone.getCarrierName();
1856 }
1857
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 //
1859 // Internal helper methods.
1860 //
1861
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001862 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1864 *
1865 * @throws SecurityException if the caller does not have the required permission
1866 */
1867 private void enforceModifyPermission() {
1868 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1869 }
1870
1871 /**
1872 * Make sure the caller has the CALL_PHONE permission.
1873 *
1874 * @throws SecurityException if the caller does not have the required permission
1875 */
1876 private void enforceCallPermission() {
1877 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1878 }
1879
Stuart Scott8eef64f2015-04-08 15:13:54 -07001880 private void enforceConnectivityInternalPermission() {
1881 mApp.enforceCallingOrSelfPermission(
1882 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1883 "ConnectivityService");
1884 }
1885
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 private String createTelUrl(String number) {
1887 if (TextUtils.isEmpty(number)) {
1888 return null;
1889 }
1890
Jake Hambye994d462014-02-03 13:10:13 -08001891 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 }
1893
Ihab Awadf9e92732013-12-05 18:02:52 -08001894 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1896 }
1897
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001898 private static void logv(String msg) {
1899 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1900 }
1901
Ihab Awadf9e92732013-12-05 18:02:52 -08001902 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1904 }
1905
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001906 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001908 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001909 }
1910
Sanket Padawe356d7632015-06-22 14:03:32 -07001911 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001912 public int getActivePhoneTypeForSlot(int slotIndex) {
1913 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 if (phone == null) {
1915 return PhoneConstants.PHONE_TYPE_NONE;
1916 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001917 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 }
1920
1921 /**
1922 * Returns the CDMA ERI icon index to display
1923 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001924 @Override
1925 public int getCdmaEriIconIndex(String callingPackage) {
1926 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001927 }
1928
Sanket Padawe356d7632015-06-22 14:03:32 -07001929 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001930 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001931 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001932 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001933 return -1;
1934 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001935 final Phone phone = getPhone(subId);
1936 if (phone != null) {
1937 return phone.getCdmaEriIconIndex();
1938 } else {
1939 return -1;
1940 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
1942
1943 /**
1944 * Returns the CDMA ERI icon mode,
1945 * 0 - ON
1946 * 1 - FLASHING
1947 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001948 @Override
1949 public int getCdmaEriIconMode(String callingPackage) {
1950 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001951 }
1952
Sanket Padawe356d7632015-06-22 14:03:32 -07001953 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001954 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001955 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001956 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001957 return -1;
1958 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001959 final Phone phone = getPhone(subId);
1960 if (phone != null) {
1961 return phone.getCdmaEriIconMode();
1962 } else {
1963 return -1;
1964 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001965 }
1966
1967 /**
1968 * Returns the CDMA ERI text,
1969 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001970 @Override
1971 public String getCdmaEriText(String callingPackage) {
1972 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001973 }
1974
Sanket Padawe356d7632015-06-22 14:03:32 -07001975 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001976 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001977 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001978 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001979 return null;
1980 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001981 final Phone phone = getPhone(subId);
1982 if (phone != null) {
1983 return phone.getCdmaEriText();
1984 } else {
1985 return null;
1986 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 }
1988
1989 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001990 * Returns the CDMA MDN.
1991 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001992 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001993 public String getCdmaMdn(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1995 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07001996 final Phone phone = getPhone(subId);
1997 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1998 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001999 } else {
2000 return null;
2001 }
2002 }
2003
2004 /**
2005 * Returns the CDMA MIN.
2006 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002007 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002008 public String getCdmaMin(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2010 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002011 final Phone phone = getPhone(subId);
2012 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2013 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002014 } else {
2015 return null;
2016 }
2017 }
2018
2019 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002020 * Returns true if CDMA provisioning needs to run.
2021 */
2022 public boolean needsOtaServiceProvisioning() {
2023 return mPhone.needsOtaServiceProvisioning();
2024 }
2025
2026 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002027 * Sets the voice mail number of a given subId.
2028 */
2029 @Override
2030 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002031 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002032 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2033 new Pair<String, String>(alphaTag, number), new Integer(subId));
2034 return success;
2035 }
2036
Ta-wei Yen87c49842016-05-13 21:19:52 -07002037 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002038 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2039 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2040 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2041 if (!TextUtils.equals(callingPackage, systemDialer)) {
2042 throw new SecurityException("caller must be system dialer");
2043 }
2044 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2045 if (phoneAccountHandle == null){
2046 return null;
2047 }
2048 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2049 }
2050
2051 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002052 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002053 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002054 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002055 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002056 return null;
2057 }
Jeff Davidson87b3c102018-03-15 17:16:18 -07002058 final long identity = Binder.clearCallingIdentity();
2059 try {
2060 return RemoteVvmTaskManager
2061 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2062 } finally {
2063 Binder.restoreCallingIdentity(identity);
2064 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002065 }
2066
2067 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002068 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2069 VisualVoicemailSmsFilterSettings settings) {
2070 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002071 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002072 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2073 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002074 }
2075
2076 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002077 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2078 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002079 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002080 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002081 }
2082
2083 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002084 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2085 String callingPackage, int subId) {
2086 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002087 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002088 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002089 }
2090
2091 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002092 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002093 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002094 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002095 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2096 }
2097
2098 @Override
2099 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2100 String number, int port, String text, PendingIntent sentIntent) {
2101 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002102 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002103 enforceSendSmsPermission();
2104 // Make the calls as the phone process.
2105 final long identity = Binder.clearCallingIdentity();
2106 try {
2107 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2108 if (port == 0) {
2109 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2110 sentIntent, null, false);
2111 } else {
2112 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2113 smsManager.sendDataMessageWithSelfPermissions(number, null,
2114 (short) port, data, sentIntent, null);
2115 }
2116 } finally {
2117 Binder.restoreCallingIdentity(identity);
2118 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002119 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002120 /**
fionaxu0152e512016-11-14 13:36:14 -08002121 * Sets the voice activation state of a given subId.
2122 */
2123 @Override
2124 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2126 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002127 final Phone phone = getPhone(subId);
2128 if (phone != null) {
2129 phone.setVoiceActivationState(activationState);
2130 } else {
2131 loge("setVoiceActivationState fails with invalid subId: " + subId);
2132 }
2133 }
2134
2135 /**
2136 * Sets the data activation state of a given subId.
2137 */
2138 @Override
2139 public void setDataActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2141 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002142 final Phone phone = getPhone(subId);
2143 if (phone != null) {
2144 phone.setDataActivationState(activationState);
2145 } else {
2146 loge("setVoiceActivationState fails with invalid subId: " + subId);
2147 }
2148 }
2149
2150 /**
2151 * Returns the voice activation state of a given subId.
2152 */
2153 @Override
2154 public int getVoiceActivationState(int subId, String callingPackage) {
goneil9e8ba382017-12-13 12:57:23 -08002155 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002156 final Phone phone = getPhone(subId);
2157 if (phone != null) {
2158 return phone.getVoiceActivationState();
2159 } else {
2160 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2161 }
2162 }
2163
2164 /**
2165 * Returns the data activation state of a given subId.
2166 */
2167 @Override
2168 public int getDataActivationState(int subId, String callingPackage) {
goneil9e8ba382017-12-13 12:57:23 -08002169 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002170 final Phone phone = getPhone(subId);
2171 if (phone != null) {
2172 return phone.getDataActivationState();
2173 } else {
2174 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2175 }
2176 }
2177
2178 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 * Returns the unread count of voicemails
2180 */
2181 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002182 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002183 }
2184
2185 /**
2186 * Returns the unread count of voicemails for a subId
2187 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002188 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002189 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002190 final Phone phone = getPhone(subId);
2191 if (phone != null) {
2192 return phone.getVoiceMessageCount();
2193 } else {
2194 return 0;
2195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 }
2197
2198 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002199 * returns true, if the device is in a state where both voice and data
2200 * are supported simultaneously. This can change based on location or network condition.
2201 */
2202 @Override
2203 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2204 final Phone phone = getPhone(subId);
2205 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2206 }
2207
2208 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002209 * Send the dialer code if called from the current default dialer or the caller has
2210 * carrier privilege.
2211 * @param inputCode The dialer code to send
2212 */
2213 @Override
2214 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2215 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2216 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2217 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002218 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2219 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002220 }
2221 mPhone.sendDialerSpecialCode(inputCode);
2222 }
2223
2224 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002225 * Returns the data network type.
2226 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 *
2228 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2229 */
2230 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002231 public int getNetworkType() {
2232 final Phone phone = getPhone(getDefaultSubscription());
2233 if (phone != null) {
2234 return phone.getServiceState().getDataNetworkType();
2235 } else {
2236 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2237 }
Wink Saville36469e72014-06-11 15:17:00 -07002238 }
2239
2240 /**
2241 * Returns the network type for a subId
2242 */
2243 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002244 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002245 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002246 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002247 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2248 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002249
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002251 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002252 return phone.getServiceState().getDataNetworkType();
2253 } else {
2254 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 }
2257
2258 /**
2259 * Returns the data network type
2260 */
2261 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002262 public int getDataNetworkType(String callingPackage) {
2263 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002264 }
2265
2266 /**
2267 * Returns the data network type for a subId
2268 */
2269 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002270 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002272 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002273 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2274 }
2275
Sanket Padawe356d7632015-06-22 14:03:32 -07002276 final Phone phone = getPhone(subId);
2277 if (phone != null) {
2278 return phone.getServiceState().getDataNetworkType();
2279 } else {
2280 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 }
2283
2284 /**
Wink Saville36469e72014-06-11 15:17:00 -07002285 * Returns the Voice network type for a subId
2286 */
2287 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002288 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002290 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002291 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2292 }
2293
Sanket Padawe356d7632015-06-22 14:03:32 -07002294 final Phone phone = getPhone(subId);
2295 if (phone != null) {
2296 return phone.getServiceState().getVoiceNetworkType();
2297 } else {
2298 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 }
2301
2302 /**
2303 * @return true if a ICC card is present
2304 */
2305 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002306 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002307 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2308 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002309 }
2310
2311 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002312 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002313 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002314 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002315 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2316 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002317 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002318 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002319 } else {
2320 return false;
2321 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002322 }
2323
2324 /**
2325 * Return if the current radio is LTE on CDMA. This
2326 * is a tri-state return value as for a period of time
2327 * the mode may be unknown.
2328 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002329 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002331 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002333 @Override
2334 public int getLteOnCdmaMode(String callingPackage) {
2335 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002336 }
2337
Sanket Padawe356d7632015-06-22 14:03:32 -07002338 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002339 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002341 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002342 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2343 }
2344
Sanket Padawe356d7632015-06-22 14:03:32 -07002345 final Phone phone = getPhone(subId);
2346 if (phone == null) {
2347 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2348 } else {
2349 return phone.getLteOnCdmaMode();
2350 }
Wink Saville36469e72014-06-11 15:17:00 -07002351 }
2352
2353 public void setPhone(Phone phone) {
2354 mPhone = phone;
2355 }
2356
2357 /**
2358 * {@hide}
2359 * Returns Default subId, 0 in the case of single standby.
2360 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002361 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002362 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002363 }
2364
Shishir Agrawala9f32182016-04-12 12:00:16 -07002365 private int getSlotForDefaultSubscription() {
2366 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2367 }
2368
Wink Savilleb564aae2014-10-23 10:18:09 -07002369 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002370 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002372
2373 /**
2374 * @see android.telephony.TelephonyManager.WifiCallingChoices
2375 */
2376 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002377 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2378 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002379 }
2380
2381 /**
2382 * @see android.telephony.TelephonyManager.WifiCallingChoices
2383 */
2384 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002385 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2386 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2387 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002388 }
2389
Sailesh Nepald1e68152013-12-12 19:08:02 -08002390 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002391 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002392 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002393 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002394
Shishir Agrawal566b7612013-10-28 14:41:00 -07002395 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002396 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2397 int subId, String callingPackage, String aid, int p2) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2399 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002400
Derek Tan740e1672017-06-27 14:56:27 -07002401 if (TextUtils.equals(ISDR_AID, aid)) {
2402 // Only allows LPA to open logical channel to ISD-R.
2403 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2404 ComponentInfo bestComponent =
2405 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2406 if (bestComponent == null
2407 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2408 loge("The calling package is not allowed to access ISD-R.");
2409 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2410 }
2411 }
2412
2413 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002414 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002415 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002416 if (DBG) log("iccOpenLogicalChannel: " + response);
2417 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002418 }
2419
2420 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002421 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2423 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002424
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002425 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002426 if (channel < 0) {
2427 return false;
2428 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002429 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002430 if (DBG) log("iccCloseLogicalChannel: " + success);
2431 return success;
2432 }
2433
2434 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002435 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002436 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2438 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002439
2440 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002441 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2442 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002443 " data=" + data);
2444 }
2445
2446 if (channel < 0) {
2447 return "";
2448 }
2449
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002450 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002451 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002452 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2453
Shishir Agrawal566b7612013-10-28 14:41:00 -07002454 // Append the returned status code to the end of the response payload.
2455 String s = Integer.toHexString(
2456 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002457 if (response.payload != null) {
2458 s = IccUtils.bytesToHexString(response.payload) + s;
2459 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002460 return s;
2461 }
Jake Hambye994d462014-02-03 13:10:13 -08002462
Evan Charltonc66da362014-05-16 14:06:40 -07002463 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002464 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2465 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2467 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002468
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002469 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2470 && TextUtils.equals(ISDR_AID, data)) {
2471 // Only allows LPA to select ISD-R.
2472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2473 ComponentInfo bestComponent =
2474 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2475 if (bestComponent == null
2476 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2477 loge("The calling package is not allowed to select ISD-R.");
2478 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2479 }
2480 }
2481
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002482 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002483 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2484 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002485 }
2486
2487 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002488 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002489 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2490
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002491 // Append the returned status code to the end of the response payload.
2492 String s = Integer.toHexString(
2493 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002494 if (response.payload != null) {
2495 s = IccUtils.bytesToHexString(response.payload) + s;
2496 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002497 return s;
2498 }
2499
2500 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002501 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002502 String filePath) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2504 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002505
2506 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002507 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002508 p1 + " " + p2 + " " + p3 + ":" + filePath);
2509 }
2510
2511 IccIoResult response =
2512 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002513 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2514 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002515
2516 if (DBG) {
2517 log("Exchange SIM_IO [R]" + response);
2518 }
2519
2520 byte[] result = null;
2521 int length = 2;
2522 if (response.payload != null) {
2523 length = 2 + response.payload.length;
2524 result = new byte[length];
2525 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2526 } else {
2527 result = new byte[length];
2528 }
2529
2530 result[length - 1] = (byte) response.sw2;
2531 result[length - 2] = (byte) response.sw1;
2532 return result;
2533 }
2534
Nathan Haroldb3014052017-01-25 15:57:32 -08002535 /**
2536 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2537 * on a particular subscription
2538 */
2539 public String[] getForbiddenPlmns(int subId, int appType) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002540 // TODO(b/73884967): Migrate to TelephonyPermissions check.
Nathan Harold892104e2017-04-13 18:19:05 -07002541 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2542 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002543 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2544 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2545 return null;
2546 }
2547 Object response = sendRequest(
2548 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2549 if (response instanceof String[]) {
2550 return (String[]) response;
2551 }
2552 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2553 return null;
2554 }
2555
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002556 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002557 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2559 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002560
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002561 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002562 if (response.payload == null) {
2563 return "";
2564 }
2565
2566 // Append the returned status code to the end of the response payload.
2567 String s = Integer.toHexString(
2568 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2569 s = IccUtils.bytesToHexString(response.payload) + s;
2570 return s;
2571 }
2572
Jake Hambye994d462014-02-03 13:10:13 -08002573 /**
2574 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2575 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2576 *
2577 * @param itemID the ID of the item to read
2578 * @return the NV item as a String, or null on error.
2579 */
2580 @Override
2581 public String nvReadItem(int itemID) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002582 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2583 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002584 if (DBG) log("nvReadItem: item " + itemID);
2585 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2586 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2587 return value;
2588 }
2589
2590 /**
2591 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2592 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2593 *
2594 * @param itemID the ID of the item to read
2595 * @param itemValue the value to write, as a String
2596 * @return true on success; false on any failure
2597 */
2598 @Override
2599 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2601 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002602 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2603 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2604 new Pair<Integer, String>(itemID, itemValue));
2605 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2606 return success;
2607 }
2608
2609 /**
2610 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2611 * Used for device configuration by some CDMA operators.
2612 *
2613 * @param preferredRoamingList byte array containing the new PRL
2614 * @return true on success; false on any failure
2615 */
2616 @Override
2617 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2619 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002620 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2621 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2622 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2623 return success;
2624 }
2625
2626 /**
2627 * Perform the specified type of NV config reset.
2628 * Used for device configuration by some CDMA operators.
2629 *
2630 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2631 * @return true on success; false on any failure
2632 */
2633 @Override
2634 public boolean nvResetConfig(int resetType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2636 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002637 if (DBG) log("nvResetConfig: type " + resetType);
2638 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2639 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2640 return success;
2641 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002642
Svet Ganovb320e182015-04-16 12:30:10 -07002643 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002644 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002645 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002646 return new String[0];
2647 }
2648
2649
ram87fca6f2014-07-18 18:58:44 +05302650 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002651 }
2652
Brad Ebinger51f743a2017-01-23 13:50:20 -08002653 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002654 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2655 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002656 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002657 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002658 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002659 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002660 }
2661
2662 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002663 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2664 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002665 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002666 public void disableIms(int slotId) {
2667 enforceModifyPermission();
2668 PhoneFactory.getImsResolver().disableIms(slotId);
2669 }
2670
2671 /**
2672 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2673 * feature or {@link null} if the service is not available. If the feature is available, the
2674 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2675 */
2676 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002677 IImsServiceFeatureCallback callback) {
2678 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002679 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002680 }
2681
2682 /**
2683 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2684 * feature during emergency calling or {@link null} if the service is not available. If the
2685 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2686 * listener for feature updates.
2687 */
2688 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2689 enforceModifyPermission();
2690 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002691 }
2692
Brad Ebinger7e934f52017-12-14 14:26:15 -08002693 /**
2694 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2695 * specified.
2696 */
2697 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2698 enforceModifyPermission();
2699 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2700 }
2701
Brad Ebingera12246d2018-01-16 09:39:35 -08002702 /**
2703 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2704 * specified.
2705 */
2706 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2707 enforceModifyPermission();
2708 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2709 }
2710
Brad Ebinger884c07b2018-02-15 16:17:40 -08002711 /**
Brad Ebinger67801702018-03-02 13:43:36 -08002712 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2713 * available, false if the IMS resolver is idle.
2714 */
2715 public boolean isResolvingImsBinding() {
2716 enforceModifyPermission();
2717 return PhoneFactory.getImsResolver().isResolvingBinding();
2718 }
2719
Wink Saville36469e72014-06-11 15:17:00 -07002720 public void setImsRegistrationState(boolean registered) {
2721 enforceModifyPermission();
2722 mPhone.setImsRegistrationState(registered);
2723 }
2724
2725 /**
Stuart Scott54788802015-03-30 13:18:01 -07002726 * Set the network selection mode to automatic.
2727 *
2728 */
2729 @Override
2730 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2732 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002733 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2734 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2735 }
2736
2737 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002738 * Set the network selection mode to manual with the selected carrier.
2739 */
2740 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002741 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002742 boolean persistSelection) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2744 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002745 OperatorInfo operator = new OperatorInfo(
2746 /* operatorAlphaLong */ "",
2747 /* operatorAlphaShort */ "",
2748 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002749 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002750 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2751 persistSelection);
2752 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002753 }
2754
2755 /**
2756 * Scans for available networks.
2757 */
2758 @Override
2759 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002760 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2761 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002762 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2763 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2764 CMD_PERFORM_NETWORK_SCAN, null, subId);
2765 return result;
2766 }
2767
2768 /**
yinxub1bed742017-04-17 11:45:04 -07002769 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002770 *
yinxub1bed742017-04-17 11:45:04 -07002771 * @param subId id of the subscription
2772 * @param request contains the radio access networks with bands/channels to scan
2773 * @param messenger callback messenger for scan results or errors
2774 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002775 * @return the id of the requested scan which can be used to stop the scan.
2776 */
2777 @Override
2778 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2779 IBinder binder) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2781 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002782 return mNetworkScanRequestTracker.startNetworkScan(
2783 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002784 }
2785
2786 /**
2787 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002788 *
2789 * @param subId id of the subscription
2790 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002791 */
2792 @Override
2793 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002794 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2795 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002796 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002797 }
2798
2799 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002800 * Get the calculated preferred network type.
2801 * Used for debugging incorrect network type.
2802 *
2803 * @return the preferred network type, defined in RILConstants.java.
2804 */
2805 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002806 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002807 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002808 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002809 return RILConstants.PREFERRED_NETWORK_MODE;
2810 }
2811
Amit Mahajan43330e02014-11-18 11:54:45 -08002812 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002813 }
2814
2815 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002816 * Get the preferred network type.
2817 * Used for device configuration by some CDMA operators.
2818 *
2819 * @return the preferred network type, defined in RILConstants.java.
2820 */
2821 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002822 public int getPreferredNetworkType(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2824 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002825 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002826 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002827 int networkType = (result != null ? result[0] : -1);
2828 if (DBG) log("getPreferredNetworkType: " + networkType);
2829 return networkType;
2830 }
2831
2832 /**
2833 * Set the preferred network type.
2834 * Used for device configuration by some CDMA operators.
2835 *
2836 * @param networkType the preferred network type, defined in RILConstants.java.
2837 * @return true on success; false on any failure.
2838 */
2839 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002840 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2842 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002843 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2844 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002845 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002846 if (success) {
2847 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002848 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002849 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002850 return success;
2851 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002852
2853 /**
Junda Liu475951f2014-11-07 16:45:03 -08002854 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2855 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2856 * tethering.
2857 *
2858 * @return 0: Not required. 1: required. 2: Not set.
2859 * @hide
2860 */
2861 @Override
2862 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002863 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002864 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2865 Settings.Global.TETHER_DUN_REQUIRED, 2);
2866 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2867 // config_tether_apndata.
2868 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2869 dunRequired = 1;
2870 }
2871 return dunRequired;
2872 }
2873
2874 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002875 * Set mobile data enabled
2876 * Used by the user through settings etc to turn on/off mobile data
2877 *
2878 * @param enable {@code true} turn turn data on, else {@code false}
2879 */
2880 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002881 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002882 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2883 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002884 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002885 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002886 Phone phone = PhoneFactory.getPhone(phoneId);
2887 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002888 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2889 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002890 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002891 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002892 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002893 }
2894
2895 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002896 * Get the user enabled state of Mobile Data.
2897 *
2898 * TODO: remove and use isUserDataEnabled.
2899 * This can't be removed now because some vendor codes
2900 * calls through ITelephony directly while they should
2901 * use TelephonyManager.
2902 *
2903 * @return true on enabled
2904 */
2905 @Override
2906 public boolean getDataEnabled(int subId) {
2907 return isUserDataEnabled(subId);
2908 }
2909
2910 /**
2911 * Get whether mobile data is enabled per user setting.
2912 *
2913 * There are other factors deciding whether mobile data is actually enabled, but they are
2914 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002915 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002916 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002917 *
2918 * @return {@code true} if data is enabled else {@code false}
2919 */
2920 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002921 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002922 try {
2923 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2924 null);
2925 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2927 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002928 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002929 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002930 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002931 Phone phone = PhoneFactory.getPhone(phoneId);
2932 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002933 boolean retVal = phone.isUserDataEnabled();
2934 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002935 return retVal;
2936 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002937 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2938 return false;
2939 }
2940 }
2941
2942 /**
2943 * Get whether mobile data is enabled.
2944 *
2945 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2946 * whether mobile data is actually enabled.
2947 *
2948 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2949 *
2950 * @return {@code true} if data is enabled else {@code false}
2951 */
2952 @Override
2953 public boolean isDataEnabled(int subId) {
2954 try {
2955 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2956 null);
2957 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2959 mApp, subId, "isDataEnabled");
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002960 }
2961 int phoneId = mSubscriptionController.getPhoneId(subId);
2962 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2963 Phone phone = PhoneFactory.getPhone(phoneId);
2964 if (phone != null) {
2965 boolean retVal = phone.isDataEnabled();
2966 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2967 return retVal;
2968 } else {
2969 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002970 return false;
2971 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002972 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002973
2974 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002975 public int getCarrierPrivilegeStatus(int subId) {
2976 final Phone phone = getPhone(subId);
2977 if (phone == null) {
2978 loge("getCarrierPrivilegeStatus: Invalid subId");
2979 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2980 }
2981 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002982 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002983 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002984 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2985 }
2986 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002987 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002988 }
Junda Liu29340342014-07-10 15:23:27 -07002989
2990 @Override
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002991 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
2992 final Phone phone = getPhone(subId);
2993 if (phone == null) {
2994 loge("getCarrierPrivilegeStatus: Invalid subId");
2995 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2996 }
2997 UiccProfile profile =
2998 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
2999 if (profile == null) {
3000 loge("getCarrierPrivilegeStatus: No UICC");
3001 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3002 }
3003 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3004 }
3005
3006 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003007 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003008 if (TextUtils.isEmpty(pkgName))
3009 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003010 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003011 if (card == null) {
3012 loge("checkCarrierPrivilegesForPackage: No UICC");
3013 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3014 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003015 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3016 }
3017
3018 @Override
3019 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003020 if (TextUtils.isEmpty(pkgName))
3021 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003022 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3023 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3024 UiccCard card = UiccController.getInstance().getUiccCard(i);
3025 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003026 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003027 continue;
3028 }
3029
3030 result = card.getCarrierPrivilegeStatus(
3031 mPhone.getContext().getPackageManager(), pkgName);
3032 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3033 break;
3034 }
3035 }
3036
3037 return result;
Junda Liu29340342014-07-10 15:23:27 -07003038 }
Derek Tan89e89d42014-07-08 17:00:10 -07003039
3040 @Override
Junda Liue64de782015-04-16 17:19:16 -07003041 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3042 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3043 loge("phoneId " + phoneId + " is not valid.");
3044 return null;
3045 }
3046 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003047 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003048 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003049 return null ;
3050 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003051 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003052 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003053 }
3054
Amith Yamasani6e118872016-02-19 12:53:51 -08003055 @Override
3056 public List<String> getPackagesWithCarrierPrivileges() {
3057 PackageManager pm = mPhone.getContext().getPackageManager();
3058 List<String> privilegedPackages = new ArrayList<>();
3059 List<PackageInfo> packages = null;
3060 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3061 UiccCard card = UiccController.getInstance().getUiccCard(i);
3062 if (card == null) {
3063 // No UICC in that slot.
3064 continue;
3065 }
3066 if (card.hasCarrierPrivilegeRules()) {
3067 if (packages == null) {
3068 // Only check packages in user 0 for now
3069 packages = pm.getInstalledPackagesAsUser(
3070 PackageManager.MATCH_DISABLED_COMPONENTS
3071 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3072 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3073 }
3074 for (int p = packages.size() - 1; p >= 0; p--) {
3075 PackageInfo pkgInfo = packages.get(p);
3076 if (pkgInfo != null && pkgInfo.packageName != null
3077 && card.getCarrierPrivilegeStatus(pkgInfo)
3078 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3079 privilegedPackages.add(pkgInfo.packageName);
3080 }
3081 }
3082 }
3083 }
3084 return privilegedPackages;
3085 }
3086
Wink Savilleb564aae2014-10-23 10:18:09 -07003087 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003088 final Phone phone = getPhone(subId);
3089 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003090 if (card == null) {
3091 loge("getIccId: No UICC");
3092 return null;
3093 }
3094 String iccId = card.getIccId();
3095 if (TextUtils.isEmpty(iccId)) {
3096 loge("getIccId: ICC ID is null or empty.");
3097 return null;
3098 }
3099 return iccId;
3100 }
3101
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003102 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003103 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3104 String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003105 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3106 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003107
Jeff Sharkey85190e62014-12-05 09:40:12 -08003108 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003109 final Phone phone = getPhone(subId);
3110 if (phone == null) {
3111 return false;
3112 }
3113 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003114
3115 if (DBG_MERGE) {
3116 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3117 + subscriberId + " to " + number);
3118 }
3119
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003120 if (TextUtils.isEmpty(iccId)) {
3121 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003122 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003123
Jeff Sharkey85190e62014-12-05 09:40:12 -08003124 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3125
3126 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003127 if (alphaTag == null) {
3128 editor.remove(alphaTagPrefKey);
3129 } else {
3130 editor.putString(alphaTagPrefKey, alphaTag);
3131 }
3132
Jeff Sharkey85190e62014-12-05 09:40:12 -08003133 // Record both the line number and IMSI for this ICCID, since we need to
3134 // track all merged IMSIs based on line number
3135 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3136 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003137 if (number == null) {
3138 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003139 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003140 } else {
3141 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003142 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003143 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003144
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003145 editor.commit();
3146 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003147 }
3148
3149 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003150 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003151 // This is open to apps with WRITE_SMS.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003153 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003154 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003155 return null;
3156 }
Derek Tan97ebb422014-09-05 16:55:38 -07003157
3158 String iccId = getIccId(subId);
3159 if (iccId != null) {
3160 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003161 if (DBG_MERGE) {
3162 log("getLine1NumberForDisplay returning " +
3163 mTelephonySharedPreferences.getString(numberPrefKey, null));
3164 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003165 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003166 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003167 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003168 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003169 }
3170
3171 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003172 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003174 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003175 return null;
3176 }
Derek Tan97ebb422014-09-05 16:55:38 -07003177
3178 String iccId = getIccId(subId);
3179 if (iccId != null) {
3180 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003181 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003182 }
Derek Tan97ebb422014-09-05 16:55:38 -07003183 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003184 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003185
3186 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003187 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003188 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3189 // about carrier-privileged callers not having access.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003191 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3192 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003193 return null;
3194 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003195 final Context context = mPhone.getContext();
3196 final TelephonyManager tele = TelephonyManager.from(context);
3197 final SubscriptionManager sub = SubscriptionManager.from(context);
3198
3199 // Figure out what subscribers are currently active
3200 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003201 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3202 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 final int[] subIds = sub.getActiveSubscriptionIdList();
3206 for (int subId : subIds) {
3207 activeSubscriberIds.add(tele.getSubscriberId(subId));
3208 }
3209 } finally {
3210 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003211 }
3212
3213 // First pass, find a number override for an active subscriber
3214 String mergeNumber = null;
3215 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3216 for (String key : prefs.keySet()) {
3217 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3218 final String subscriberId = (String) prefs.get(key);
3219 if (activeSubscriberIds.contains(subscriberId)) {
3220 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3221 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3222 mergeNumber = (String) prefs.get(numberKey);
3223 if (DBG_MERGE) {
3224 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3225 + " for active subscriber " + subscriberId);
3226 }
3227 if (!TextUtils.isEmpty(mergeNumber)) {
3228 break;
3229 }
3230 }
3231 }
3232 }
3233
3234 // Shortcut when no active merged subscribers
3235 if (TextUtils.isEmpty(mergeNumber)) {
3236 return null;
3237 }
3238
3239 // Second pass, find all subscribers under that line override
3240 final ArraySet<String> result = new ArraySet<>();
3241 for (String key : prefs.keySet()) {
3242 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3243 final String number = (String) prefs.get(key);
3244 if (mergeNumber.equals(number)) {
3245 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3246 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3247 final String subscriberId = (String) prefs.get(subscriberKey);
3248 if (!TextUtils.isEmpty(subscriberId)) {
3249 result.add(subscriberId);
3250 }
3251 }
3252 }
3253 }
3254
3255 final String[] resultArray = result.toArray(new String[result.size()]);
3256 Arrays.sort(resultArray);
3257 if (DBG_MERGE) {
3258 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3259 }
3260 return resultArray;
3261 }
3262
3263 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003264 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003265 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3266 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003267 final Phone phone = getPhone(subId);
3268 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003269 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003270
3271 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003272 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003273 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3274 List<String> cdmaNonRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003275 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003276 final Phone phone = getPhone(subId);
3277 if (phone == null) {
3278 return false;
3279 }
3280 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003281 cdmaNonRoamingList);
3282 }
3283
3284 @Override
Shuo Qianbf4c5392018-04-17 18:39:35 +00003285 @Deprecated
3286 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3287 enforceModifyPermission();
3288
3289 int returnValue = 0;
3290 try {
3291 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3292 if(result.exception == null) {
3293 if (result.result != null) {
3294 byte[] responseData = (byte[])(result.result);
3295 if(responseData.length > oemResp.length) {
3296 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3297 responseData.length + "bytes. Buffer Size is " +
3298 oemResp.length + "bytes.");
3299 }
3300 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3301 returnValue = responseData.length;
3302 }
3303 } else {
3304 CommandException ex = (CommandException) result.exception;
3305 returnValue = ex.getCommandError().ordinal();
3306 if(returnValue > 0) returnValue *= -1;
3307 }
3308 } catch (RuntimeException e) {
3309 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3310 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3311 if(returnValue > 0) returnValue *= -1;
3312 }
3313
3314 return returnValue;
3315 }
3316
3317 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003318 public void setRadioCapability(RadioAccessFamily[] rafs) {
3319 try {
3320 ProxyController.getInstance().setRadioCapability(rafs);
3321 } catch (RuntimeException e) {
3322 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3323 }
3324 }
3325
3326 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003327 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003328 Phone phone = PhoneFactory.getPhone(phoneId);
3329 if (phone == null) {
3330 return RadioAccessFamily.RAF_UNKNOWN;
3331 }
3332 int subId = phone.getSubId();
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003333 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003334 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003335 return RadioAccessFamily.RAF_UNKNOWN;
3336 }
3337
Wink Saville5d475dd2014-10-17 15:00:58 -07003338 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3339 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003340
3341 @Override
3342 public void enableVideoCalling(boolean enable) {
3343 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003344 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003345 }
3346
3347 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003348 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003349 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003350 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003351 return false;
3352 }
3353
Andrew Lee77527ac2014-10-21 16:57:39 -07003354 // Check the user preference and the system-level IMS setting. Even if the user has
3355 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3356 // In the long run, we may instead need to check if there exists a connection service
3357 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003358 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3359 return imsManager.isVtEnabledByPlatform()
3360 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3361 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003362 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003363
Andrew Leea1239f22015-03-02 17:44:07 -08003364 @Override
3365 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003366 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003367 }
3368
3369 @Override
3370 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003371 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003372 }
3373
Andrew Lee9431b832015-03-09 18:46:45 -07003374 @Override
3375 public boolean isTtyModeSupported() {
3376 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3377 TelephonyManager telephonyManager =
3378 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003379 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003380 }
3381
3382 @Override
3383 public boolean isHearingAidCompatibilitySupported() {
3384 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3385 }
3386
Hall Liu73714012018-01-22 19:15:32 -08003387 public boolean isRttSupported() {
3388 boolean isCarrierSupported =
3389 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3390 boolean isDeviceSupported =
3391 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3392 return isCarrierSupported && isDeviceSupported;
3393 }
3394
Hall Liub1585172018-04-06 16:23:39 -07003395 public boolean isRttEnabled() {
3396 return isRttSupported() && Settings.Secure.getInt(mPhone.getContext().getContentResolver(),
3397 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
3398 }
3399
Sanket Padawe7310cc72015-01-14 09:53:20 -08003400 /**
3401 * Returns the unique device ID of phone, for example, the IMEI for
3402 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3403 *
3404 * <p>Requires Permission:
3405 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3406 */
3407 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003408 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003409 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003410 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003411 return null;
3412 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003413 int subId = phone.getSubId();
3414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3415 mApp, subId, callingPackage, "getDeviceId")) {
3416 return null;
3417 }
3418 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003419 }
3420
Ping Sun014fe8e2016-03-02 19:16:45 +08003421 /**
3422 * {@hide}
3423 * Returns the IMS Registration Status on a particular subid
3424 *
3425 * @param subId
3426 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003427 public boolean isImsRegistered(int subId) {
Ping Sun014fe8e2016-03-02 19:16:45 +08003428 Phone phone = getPhone(subId);
3429 if (phone != null) {
3430 return phone.isImsRegistered();
3431 } else {
3432 return false;
3433 }
3434 }
3435
Santos Cordon7a1885b2015-02-03 11:15:19 -08003436 @Override
3437 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3438 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3439 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003440
Brad Ebingere21f25f2018-02-08 16:11:32 -08003441 /**
3442 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003443 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003444 public boolean isWifiCallingAvailable(int subId) {
3445 Phone phone = getPhone(subId);
3446 if (phone != null) {
3447 return phone.isWifiCallingEnabled();
3448 } else {
3449 return false;
3450 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003451 }
3452
Brad Ebingere21f25f2018-02-08 16:11:32 -08003453 /**
3454 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003455 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003456 public boolean isVolteAvailable(int subId) {
3457 Phone phone = getPhone(subId);
3458 if (phone != null) {
3459 return phone.isVolteEnabled();
3460 } else {
3461 return false;
3462 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003463 }
Svet Ganovb320e182015-04-16 12:30:10 -07003464
Brad Ebingere21f25f2018-02-08 16:11:32 -08003465 /**
3466 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003467 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003468 public boolean isVideoTelephonyAvailable(int subId) {
3469 Phone phone = getPhone(subId);
3470 if (phone != null) {
3471 return phone.isVideoEnabled();
3472 } else {
3473 return false;
3474 }
3475 }
3476
3477 /**
3478 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3479 * defined in {@link ImsRegistrationImplBase}.
3480 */
3481 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3482 Phone phone = getPhone(subId);
3483 if (phone != null) {
3484 return phone.getImsRegistrationTech();
3485 } else {
3486 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3487 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003488 }
3489
Stuart Scott8eef64f2015-04-08 15:13:54 -07003490 @Override
3491 public void factoryReset(int subId) {
3492 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003493 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3494 return;
3495 }
3496
Svet Ganovcc087f82015-05-12 20:35:54 -07003497 final long identity = Binder.clearCallingIdentity();
3498 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003499 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3500 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003501 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003502 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003503 // Set network selection mode to automatic
3504 setNetworkSelectionModeAutomatic(subId);
3505 // Set preferred mobile network type to the best available
Kitta Koutarouab8a69b2018-03-05 14:16:45 +09003506 String defaultNetwork = TelephonyManager.getTelephonyProperty(
3507 mSubscriptionController.getPhoneId(subId),
3508 "ro.telephony.default_network",
3509 null);
3510 int networkType = !TextUtils.isEmpty(defaultNetwork)
3511 ? Integer.parseInt(defaultNetwork) : Phone.PREFERRED_NT_MODE;
3512 setPreferredNetworkType(subId, networkType);
Svet Ganovcc087f82015-05-12 20:35:54 -07003513 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003514 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003515 }
3516 } finally {
3517 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003518 }
3519 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003520
3521 @Override
3522 public String getLocaleFromDefaultSim() {
3523 // We query all subscriptions instead of just the active ones, because
3524 // this might be called early on in the provisioning flow when the
3525 // subscriptions potentially aren't active yet.
3526 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3527 if (slist == null || slist.isEmpty()) {
3528 return null;
3529 }
3530
3531 // This function may be called very early, say, from the setup wizard, at
3532 // which point we won't have a default subscription set. If that's the case
3533 // we just choose the first, which will be valid in "most cases".
3534 final int defaultSubId = getDefaultSubscription();
3535 SubscriptionInfo info = null;
3536 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3537 info = slist.get(0);
3538 } else {
3539 for (SubscriptionInfo item : slist) {
3540 if (item.getSubscriptionId() == defaultSubId) {
3541 info = item;
3542 break;
3543 }
3544 }
3545
3546 if (info == null) {
3547 return null;
3548 }
3549 }
3550
3551 // Try and fetch the locale from the carrier properties or from the SIM language
3552 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003553 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003554 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003555 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003556 if (defaultPhone != null) {
3557 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3558 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003559 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003560 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3561 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003562 } else {
3563 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003564 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003565 }
3566 }
3567
Narayan Kamath011676f2015-07-29 12:04:08 +01003568 // The SIM language preferences only store a language (e.g. fr = French), not an
3569 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3570 // the SIM and carrier preferences does not include a country we add the country
3571 // determined from the SIM MCC to provide an exact locale.
3572 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003573 if (mccLocale != null) {
3574 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3575 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003576 }
3577
Tony Hill183b2de2015-06-24 14:53:58 +01003578 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003579 return null;
3580 }
3581
3582 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 return mSubscriptionController.getAllSubInfoList(
3586 mPhone.getContext().getOpPackageName());
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
3589 }
3590 }
3591
3592 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3593 final long identity = Binder.clearCallingIdentity();
3594 try {
3595 return mSubscriptionController.getActiveSubscriptionInfoList(
3596 mPhone.getContext().getOpPackageName());
3597 } finally {
3598 Binder.restoreCallingIdentity(identity);
3599 }
3600 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003601
3602 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003603 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3604 * representing the state of the modem.
3605 *
3606 * NOTE: This clears the modem state, so there should only every be one caller.
3607 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003608 */
3609 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003610 public void requestModemActivityInfo(ResultReceiver result) {
3611 enforceModifyPermission();
3612
3613 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3614 Bundle bundle = new Bundle();
3615 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3616 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003617 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003618
3619 /**
3620 * {@hide}
3621 * Returns the service state information on specified subscription.
3622 */
3623 @Override
3624 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3625
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003626 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003627 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003628 return null;
3629 }
3630
3631 final Phone phone = getPhone(subId);
3632 if (phone == null) {
3633 return null;
3634 }
3635
3636 return phone.getServiceState();
3637 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003638
3639 /**
3640 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3641 *
3642 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3643 * voicemail ringtone.
3644 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3645 * PhoneAccount.
3646 */
3647 @Override
3648 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003649 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003650 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003651 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003652 }
3653
fionaxu7ed723d2017-05-30 18:58:54 -07003654 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003655 }
3656
3657 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003658 * Sets the per-account voicemail ringtone.
3659 *
3660 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3661 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3662 *
3663 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3664 * voicemail ringtone.
3665 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3666 * PhoneAccount.
3667 */
3668 @Override
3669 public void setVoicemailRingtoneUri(String callingPackage,
3670 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3671 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3672 if (!TextUtils.equals(callingPackage,
3673 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3675 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3676 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003677 }
3678 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3679 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003680 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003681 }
fionaxu7ed723d2017-05-30 18:58:54 -07003682 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003683 }
3684
3685 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003686 * Returns whether vibration is set for voicemail notification in Phone settings.
3687 *
3688 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3689 * voicemail vibration setting.
3690 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3691 */
3692 @Override
3693 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003694 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003695 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003696 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003697 }
3698
fionaxu7ed723d2017-05-30 18:58:54 -07003699 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003700 }
3701
Youhan Wange64578a2016-05-02 15:32:42 -07003702 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003703 * Sets the per-account voicemail vibration.
3704 *
3705 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3706 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3707 *
3708 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3709 * voicemail vibration setting.
3710 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3711 * specific PhoneAccount.
3712 */
3713 @Override
3714 public void setVoicemailVibrationEnabled(String callingPackage,
3715 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3716 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3717 if (!TextUtils.equals(callingPackage,
3718 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3720 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3721 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003722 }
3723
3724 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3725 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003726 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003727 }
fionaxu7ed723d2017-05-30 18:58:54 -07003728 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003729 }
3730
3731 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003732 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3733 *
3734 * @throws SecurityException if the caller does not have the required permission
3735 */
3736 private void enforceReadPrivilegedPermission() {
3737 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3738 null);
3739 }
3740
3741 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003742 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3743 * permission.
3744 *
3745 * @throws SecurityException if the caller does not have the required permission
3746 */
3747 private void enforceSendSmsPermission() {
3748 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3749 }
3750
3751 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003752 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003753 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003754 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003755 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003756 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003757 ComponentName componentName =
3758 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3759 if(componentName == null) {
3760 throw new SecurityException("Caller not current active visual voicemail package[null]");
3761 }
3762 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003763 if (!callingPackage.equals(vvmPackage)) {
3764 throw new SecurityException("Caller not current active visual voicemail package[" +
3765 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003766 }
3767 }
3768
3769 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003770 * Return the application ID for the app type.
3771 *
3772 * @param subId the subscription ID that this request applies to.
3773 * @param appType the uicc app type.
3774 * @return Application ID for specificied app type, or null if no uicc.
3775 */
3776 @Override
3777 public String getAidForAppType(int subId, int appType) {
3778 enforceReadPrivilegedPermission();
3779 Phone phone = getPhone(subId);
3780 if (phone == null) {
3781 return null;
3782 }
3783 String aid = null;
3784 try {
3785 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3786 .getApplicationByType(appType).getAid();
3787 } catch (Exception e) {
3788 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3789 }
3790 return aid;
3791 }
3792
Youhan Wang4001d252016-05-11 10:29:41 -07003793 /**
3794 * Return the Electronic Serial Number.
3795 *
3796 * @param subId the subscription ID that this request applies to.
3797 * @return ESN or null if error.
3798 */
3799 @Override
3800 public String getEsn(int subId) {
3801 enforceReadPrivilegedPermission();
3802 Phone phone = getPhone(subId);
3803 if (phone == null) {
3804 return null;
3805 }
3806 String esn = null;
3807 try {
3808 esn = phone.getEsn();
3809 } catch (Exception e) {
3810 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3811 }
3812 return esn;
3813 }
3814
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003815 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003816 * Return the Preferred Roaming List Version.
3817 *
3818 * @param subId the subscription ID that this request applies to.
3819 * @return PRLVersion or null if error.
3820 */
3821 @Override
3822 public String getCdmaPrlVersion(int subId) {
3823 enforceReadPrivilegedPermission();
3824 Phone phone = getPhone(subId);
3825 if (phone == null) {
3826 return null;
3827 }
3828 String cdmaPrlVersion = null;
3829 try {
3830 cdmaPrlVersion = phone.getCdmaPrlVersion();
3831 } catch (Exception e) {
3832 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3833 }
3834 return cdmaPrlVersion;
3835 }
3836
3837 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003838 * Get snapshot of Telephony histograms
3839 * @return List of Telephony histograms
3840 * @hide
3841 */
3842 @Override
3843 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3845 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003846 return RIL.getTelephonyRILTimingHistograms();
3847 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003848
3849 /**
3850 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003851 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003852 * Require system privileges. In the future we may add this to carrier APIs.
3853 *
3854 * @return The number of carriers set successfully, should match length of carriers
3855 */
3856 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003857 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003858 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003859
Meng Wang9b7c4e92017-02-17 11:41:27 -08003860 if (carriers == null) {
3861 throw new NullPointerException("carriers cannot be null");
3862 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003863
3864 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003865 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3866 return retVal[0];
3867 }
3868
3869 /**
3870 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003871 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003872 * Require system privileges. In the future we may add this to carrier APIs.
3873 *
3874 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3875 * means all carriers are allowed.
3876 */
3877 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003878 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003879 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003880 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003881 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3882 }
3883
fionaxu59545b42016-05-25 15:53:37 -07003884 /**
3885 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3886 * @param subId the subscription ID that this action applies to.
3887 * @param enabled control enable or disable metered apns.
3888 * {@hide}
3889 */
3890 @Override
3891 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3892 enforceModifyPermission();
3893 final Phone phone = getPhone(subId);
3894 if (phone == null) {
3895 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3896 return;
3897 }
3898 try {
3899 phone.carrierActionSetMeteredApnsEnabled(enabled);
3900 } catch (Exception e) {
3901 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3902 }
3903 }
3904
3905 /**
3906 * Action set from carrier signalling broadcast receivers to enable/disable radio
3907 * @param subId the subscription ID that this action applies to.
3908 * @param enabled control enable or disable radio.
3909 * {@hide}
3910 */
3911 @Override
3912 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3913 enforceModifyPermission();
3914 final Phone phone = getPhone(subId);
3915 if (phone == null) {
3916 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3917 return;
3918 }
3919 try {
3920 phone.carrierActionSetRadioEnabled(enabled);
3921 } catch (Exception e) {
3922 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3923 }
3924 }
3925
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003926 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003927 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3928 * network status based on which carrier apps could apply actions accordingly,
3929 * enable/disable default url handler for example.
3930 *
3931 * @param subId the subscription ID that this action applies to.
3932 * @param report control start/stop reporting the default network status.
3933 * {@hide}
3934 */
3935 @Override
3936 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3937 enforceModifyPermission();
3938 final Phone phone = getPhone(subId);
3939 if (phone == null) {
3940 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3941 return;
3942 }
3943 try {
3944 phone.carrierActionReportDefaultNetworkStatus(report);
3945 } catch (Exception e) {
3946 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3947 }
3948 }
3949
3950 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003951 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3952 * bug report is being generated.
3953 */
3954 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003955 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003956 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3957 != PackageManager.PERMISSION_GRANTED) {
3958 writer.println("Permission Denial: can't dump Phone from pid="
3959 + Binder.getCallingPid()
3960 + ", uid=" + Binder.getCallingUid()
3961 + "without permission "
3962 + android.Manifest.permission.DUMP);
3963 return;
3964 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003965 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003966 }
Jack Yueb89b242016-06-22 13:27:47 -07003967
3968 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003969 * Get aggregated video call data usage since boot.
3970 *
3971 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3972 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003973 * {@hide}
3974 */
3975 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003976 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003977 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3978 null);
3979
Jack Yu84291ec2017-05-26 16:07:50 -07003980 // NetworkStatsService keeps tracking the active network interface and identity. It
3981 // records the delta with the corresponding network identity. We just return the total video
3982 // call data usage snapshot since boot.
3983 Phone phone = getPhone(subId);
3984 if (phone != null) {
3985 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003986 }
Jack Yu84291ec2017-05-26 16:07:50 -07003987 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003988 }
Jack Yu75ab2952016-07-08 14:29:33 -07003989
3990 /**
3991 * Policy control of data connection. Usually used when data limit is passed.
3992 * @param enabled True if enabling the data, otherwise disabling.
3993 * @param subId Subscription index
3994 * {@hide}
3995 */
3996 @Override
3997 public void setPolicyDataEnabled(boolean enabled, int subId) {
3998 enforceModifyPermission();
3999 Phone phone = getPhone(subId);
4000 if (phone != null) {
4001 phone.setPolicyDataEnabled(enabled);
4002 }
4003 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004004
4005 /**
4006 * Get Client request stats
4007 * @return List of Client Request Stats
4008 * @hide
4009 */
4010 @Override
4011 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004013 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004014 return null;
4015 }
4016
4017 Phone phone = getPhone(subId);
4018 if (phone != null) {
4019 return phone.getClientRequestStats();
4020 }
4021
4022 return null;
4023 }
4024
4025 private WorkSource getWorkSource(WorkSource workSource, int uid) {
4026 if (workSource != null) {
4027 return workSource;
4028 }
4029
4030 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
4031 workSource = new WorkSource(uid, packageName);
4032 return workSource;
4033 }
Jack Yueb4124c2017-02-16 15:32:43 -08004034
4035 /**
Grace Chen70990072017-03-24 17:21:30 -07004036 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004037 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004038 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004039 * @param state State of SIM (power down, power up, pass through)
4040 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4041 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4042 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004043 *
4044 **/
4045 @Override
Grace Chen70990072017-03-24 17:21:30 -07004046 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004047 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004048 Phone phone = PhoneFactory.getPhone(slotIndex);
4049
Jack Yueb4124c2017-02-16 15:32:43 -08004050 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004051 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004052 }
4053 }
Shuo Qiandd210312017-04-12 22:11:33 +00004054
Tyler Gunn65d45c22017-06-05 11:22:26 -07004055 private boolean isUssdApiAllowed(int subId) {
4056 CarrierConfigManager configManager =
4057 (CarrierConfigManager) mPhone.getContext().getSystemService(
4058 Context.CARRIER_CONFIG_SERVICE);
4059 if (configManager == null) {
4060 return false;
4061 }
4062 PersistableBundle pb = configManager.getConfigForSubId(subId);
4063 if (pb == null) {
4064 return false;
4065 }
4066 return pb.getBoolean(
4067 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4068 }
4069
Shuo Qiandd210312017-04-12 22:11:33 +00004070 /**
4071 * Check if phone is in emergency callback mode
4072 * @return true if phone is in emergency callback mode
4073 * @param subId sub id
4074 */
4075 public boolean getEmergencyCallbackMode(int subId) {
4076 final Phone phone = getPhone(subId);
4077 if (phone != null) {
4078 return phone.isInEcm();
4079 } else {
4080 return false;
4081 }
4082 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004083
4084 /**
4085 * Get the current signal strength information for the given subscription.
4086 * Because this information is not updated when the device is in a low power state
4087 * it should not be relied-upon to be current.
4088 * @param subId Subscription index
4089 * @return the most recent cached signal strength info from the modem
4090 */
4091 @Override
4092 public SignalStrength getSignalStrength(int subId) {
4093 Phone p = getPhone(subId);
4094 if (p == null) {
4095 return null;
4096 }
4097
4098 return p.getSignalStrength();
4099 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004100
4101 @Override
4102 public UiccSlotInfo[] getUiccSlotsInfo() {
4103 enforceReadPrivilegedPermission();
4104
4105 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4106 if (slots == null) return null;
4107 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4108 for (int i = 0; i < slots.length; i++) {
4109 UiccSlot slot = slots[i];
4110
4111 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4112
4113 int cardState = 0;
4114 switch (slot.getCardState()) {
4115 case CARDSTATE_ABSENT:
4116 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4117 break;
4118 case CARDSTATE_PRESENT:
4119 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4120 break;
4121 case CARDSTATE_ERROR:
4122 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4123 break;
4124 case CARDSTATE_RESTRICTED:
4125 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4126 break;
4127 default:
4128 break;
4129
4130 }
4131
Qingxi Li63668902018-01-31 13:43:27 -08004132 infos[i] = new UiccSlotInfo(
Qingxi Li0ae57f72018-03-07 10:52:26 -08004133 slot.isActive(),
4134 slot.isEuicc(),
4135 cardId,
4136 cardState,
4137 slot.getPhoneId(),
4138 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004139 }
4140 return infos;
4141 }
4142
4143 @Override
4144 public boolean switchSlots(int[] physicalSlots) {
4145 enforceModifyPermission();
4146 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4147 }
Jack Yue6146032018-02-27 15:30:01 -08004148
4149 @Override
4150 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4151 enforceModifyPermission();
4152 final Phone phone = getPhone(subId);
4153 if (phone == null) {
4154 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4155 return;
4156 }
4157
4158 phone.setRadioIndicationUpdateMode(filters, mode);
4159 }
fionaxu2c8bbbd2018-03-21 00:08:13 -07004160
4161 @Override
4162 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
4163 gid1, String gid2, String plmn, String spn) {
4164 enforceModifyPermission();
4165 final Phone phone = getPhone(subId);
4166 if (phone == null) {
4167 loge("setCarrierTestOverride fails with invalid subId: " + subId);
4168 return;
4169 }
4170 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
4171 }
4172
4173 @Override
4174 public int getCarrierIdListVersion(int subId) {
4175 enforceReadPrivilegedPermission();
4176 final Phone phone = getPhone(subId);
4177 if (phone == null) {
4178 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
4179 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
4180 }
4181 return phone.getCarrierIdListVersion();
4182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004183}