blob: 308a8324d008d20d9edd2fc5ec0487fce3c16645 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
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 Ebinger22bc3e42018-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 Ebinger1f2b5082018-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;
Tyler Gunn67073572018-02-14 14:19:42 -080081import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080083import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080085
Andrew Lee312e8172014-10-23 17:01:36 -070086import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080087import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070088import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070089import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070090import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070091import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070092import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070094import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080095import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010096import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070097import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070098import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -0800100import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700101import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700102import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700103import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700104import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700105import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800106import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800107import com.android.internal.telephony.TelephonyPermissions;
Jonathan Basseribf5362b2017-07-19 12:22:35 -0700108import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700109import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700110import com.android.internal.telephony.uicc.IccIoResult;
111import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800112import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700113import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800114import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700115import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800116import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000117import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700118import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800119import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700120import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800121import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700122import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700123import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800124
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700125import java.io.FileDescriptor;
126import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800127import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800129import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800130import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100131import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800132import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133
134/**
135 * Implementation of the ITelephony interface.
136 */
Santos Cordon117fee72014-05-16 17:56:12 -0700137public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138 private static final String LOG_TAG = "PhoneInterfaceManager";
139 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
140 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800141 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142
143 // Message codes used with mMainThreadHandler
144 private static final int CMD_HANDLE_PIN_MMI = 1;
145 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
146 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
147 private static final int CMD_ANSWER_RINGING_CALL = 4;
148 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700149 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
150 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700151 private static final int CMD_OPEN_CHANNEL = 9;
152 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
153 private static final int CMD_CLOSE_CHANNEL = 11;
154 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800155 private static final int CMD_NV_READ_ITEM = 13;
156 private static final int EVENT_NV_READ_ITEM_DONE = 14;
157 private static final int CMD_NV_WRITE_ITEM = 15;
158 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
159 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
160 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
161 private static final int CMD_NV_RESET_CONFIG = 19;
162 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800163 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
164 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
165 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
166 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800167 private static final int CMD_SEND_ENVELOPE = 25;
168 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
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
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800742 case CMD_SET_VOICEMAIL_NUMBER:
743 request = (MainThreadRequest) msg.obj;
744 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
745 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800746 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
747 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800748 break;
749
750 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
751 handleNullReturnEvent(msg, "setVoicemailNumber");
752 break;
753
Stuart Scott54788802015-03-30 13:18:01 -0700754 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
757 request);
758 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
759 break;
760
761 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
762 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
763 break;
764
Shishir Agrawal302c8692015-06-19 13:49:39 -0700765 case CMD_PERFORM_NETWORK_SCAN:
766 request = (MainThreadRequest) msg.obj;
767 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
768 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
769 break;
770
771 case EVENT_PERFORM_NETWORK_SCAN_DONE:
772 ar = (AsyncResult) msg.obj;
773 request = (MainThreadRequest) ar.userObj;
774 CellNetworkScanResult cellScanResult;
775 if (ar.exception == null && ar.result != null) {
776 cellScanResult = new CellNetworkScanResult(
777 CellNetworkScanResult.STATUS_SUCCESS,
778 (List<OperatorInfo>) ar.result);
779 } else {
780 if (ar.result == null) {
781 loge("getCellNetworkScanResults: Empty response");
782 }
783 if (ar.exception != null) {
784 loge("getCellNetworkScanResults: Exception: " + ar.exception);
785 }
786 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
787 if (ar.exception instanceof CommandException) {
788 CommandException.Error error =
789 ((CommandException) (ar.exception)).getCommandError();
790 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
791 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
792 } else if (error == CommandException.Error.GENERIC_FAILURE) {
793 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
794 }
795 }
796 cellScanResult = new CellNetworkScanResult(errorCode, null);
797 }
798 request.result = cellScanResult;
799 synchronized (request) {
800 request.notifyAll();
801 }
802 break;
803
804 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
805 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700806 ManualNetworkSelectionArgument selArg =
807 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700808 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
809 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700810 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
811 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700812 break;
813
814 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
815 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
816 break;
817
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700818 case CMD_GET_MODEM_ACTIVITY_INFO:
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700821 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700822 break;
823
824 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
825 ar = (AsyncResult) msg.obj;
826 request = (MainThreadRequest) ar.userObj;
827 if (ar.exception == null && ar.result != null) {
828 request.result = ar.result;
829 } else {
830 if (ar.result == null) {
831 loge("queryModemActivityInfo: Empty response");
832 } else if (ar.exception instanceof CommandException) {
833 loge("queryModemActivityInfo: CommandException: " +
834 ar.exception);
835 } else {
836 loge("queryModemActivityInfo: Unknown exception");
837 }
838 }
Amit Mahajand4766222016-01-28 15:28:28 -0800839 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
840 if (request.result == null) {
841 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
842 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700843 synchronized (request) {
844 request.notifyAll();
845 }
846 break;
847
Meng Wang1a7c35a2016-05-05 20:56:15 -0700848 case CMD_SET_ALLOWED_CARRIERS:
849 request = (MainThreadRequest) msg.obj;
850 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
851 mPhone.setAllowedCarriers(
852 (List<CarrierIdentifier>) request.argument,
853 onCompleted);
854 break;
855
856 case EVENT_SET_ALLOWED_CARRIERS_DONE:
857 ar = (AsyncResult) msg.obj;
858 request = (MainThreadRequest) ar.userObj;
859 if (ar.exception == null && ar.result != null) {
860 request.result = ar.result;
861 } else {
862 if (ar.result == null) {
863 loge("setAllowedCarriers: Empty response");
864 } else if (ar.exception instanceof CommandException) {
865 loge("setAllowedCarriers: CommandException: " +
866 ar.exception);
867 } else {
868 loge("setAllowedCarriers: Unknown exception");
869 }
870 }
871 // Result cannot be null. Return -1 on error.
872 if (request.result == null) {
873 request.result = new int[]{-1};
874 }
875 synchronized (request) {
876 request.notifyAll();
877 }
878 break;
879
880 case CMD_GET_ALLOWED_CARRIERS:
881 request = (MainThreadRequest) msg.obj;
882 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
883 mPhone.getAllowedCarriers(onCompleted);
884 break;
885
886 case EVENT_GET_ALLOWED_CARRIERS_DONE:
887 ar = (AsyncResult) msg.obj;
888 request = (MainThreadRequest) ar.userObj;
889 if (ar.exception == null && ar.result != null) {
890 request.result = ar.result;
891 } else {
892 if (ar.result == null) {
893 loge("getAllowedCarriers: Empty response");
894 } else if (ar.exception instanceof CommandException) {
895 loge("getAllowedCarriers: CommandException: " +
896 ar.exception);
897 } else {
898 loge("getAllowedCarriers: Unknown exception");
899 }
900 }
901 // Result cannot be null. Return empty list of CarrierIdentifier.
902 if (request.result == null) {
903 request.result = new ArrayList<CarrierIdentifier>(0);
904 }
905 synchronized (request) {
906 request.notifyAll();
907 }
908 break;
909
Nathan Haroldb3014052017-01-25 15:57:32 -0800910 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
913 if (ar.exception == null && ar.result != null) {
914 request.result = ar.result;
915 } else {
916 request.result = new IllegalArgumentException(
917 "Failed to retrieve Forbidden Plmns");
918 if (ar.result == null) {
919 loge("getForbiddenPlmns: Empty response");
920 } else {
921 loge("getForbiddenPlmns: Unknown exception");
922 }
923 }
924 synchronized (request) {
925 request.notifyAll();
926 }
927 break;
928
929 case CMD_GET_FORBIDDEN_PLMNS:
930 request = (MainThreadRequest) msg.obj;
931 uiccCard = getUiccCardFromRequest(request);
932 if (uiccCard == null) {
933 loge("getForbiddenPlmns() UiccCard is null");
934 request.result = new IllegalArgumentException(
935 "getForbiddenPlmns() UiccCard is null");
936 synchronized (request) {
937 request.notifyAll();
938 }
939 break;
940 }
941 Integer appType = (Integer) request.argument;
942 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
943 if (uiccApp == null) {
944 loge("getForbiddenPlmns() no app with specified type -- "
945 + appType);
946 request.result = new IllegalArgumentException("Failed to get UICC App");
947 synchronized (request) {
948 request.notifyAll();
949 }
950 break;
951 } else {
952 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
953 + " specified type -- " + appType);
954 }
955 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
956 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
957 onCompleted);
958 break;
959
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000960 case CMD_SWITCH_SLOTS:
961 request = (MainThreadRequest) msg.obj;
962 int[] physicalSlots = (int[]) request.argument;
963 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
964 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
965 break;
966
967 case EVENT_SWITCH_SLOTS_DONE:
968 ar = (AsyncResult) msg.obj;
969 request = (MainThreadRequest) ar.userObj;
970 request.result = (ar.exception == null);
971 synchronized (request) {
972 request.notifyAll();
973 }
974 break;
975
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700976 default:
977 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
978 break;
979 }
980 }
Jake Hambye994d462014-02-03 13:10:13 -0800981
982 private void handleNullReturnEvent(Message msg, String command) {
983 AsyncResult ar = (AsyncResult) msg.obj;
984 MainThreadRequest request = (MainThreadRequest) ar.userObj;
985 if (ar.exception == null) {
986 request.result = true;
987 } else {
988 request.result = false;
989 if (ar.exception instanceof CommandException) {
990 loge(command + ": CommandException: " + ar.exception);
991 } else {
992 loge(command + ": Unknown exception");
993 }
994 }
995 synchronized (request) {
996 request.notifyAll();
997 }
998 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700999 }
1000
1001 /**
1002 * Posts the specified command to be executed on the main thread,
1003 * waits for the request to complete, and returns the result.
1004 * @see #sendRequestAsync
1005 */
1006 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001007 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001008 }
1009
1010 /**
1011 * Posts the specified command to be executed on the main thread,
1012 * waits for the request to complete, and returns the result.
1013 * @see #sendRequestAsync
1014 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001015 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001016 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1017 throw new RuntimeException("This method will deadlock if called from the main thread.");
1018 }
1019
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001020 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001021 Message msg = mMainThreadHandler.obtainMessage(command, request);
1022 msg.sendToTarget();
1023
1024 // Wait for the request to complete
1025 synchronized (request) {
1026 while (request.result == null) {
1027 try {
1028 request.wait();
1029 } catch (InterruptedException e) {
1030 // Do nothing, go back and wait until the request is complete
1031 }
1032 }
1033 }
1034 return request.result;
1035 }
1036
1037 /**
1038 * Asynchronous ("fire and forget") version of sendRequest():
1039 * Posts the specified command to be executed on the main thread, and
1040 * returns immediately.
1041 * @see #sendRequest
1042 */
1043 private void sendRequestAsync(int command) {
1044 mMainThreadHandler.sendEmptyMessage(command);
1045 }
1046
1047 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001048 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1049 * @see {@link #sendRequest(int,Object)}
1050 */
1051 private void sendRequestAsync(int command, Object argument) {
1052 MainThreadRequest request = new MainThreadRequest(argument);
1053 Message msg = mMainThreadHandler.obtainMessage(command, request);
1054 msg.sendToTarget();
1055 }
1056
1057 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001058 * Initialize the singleton PhoneInterfaceManager instance.
1059 * This is only done once, at startup, from PhoneApp.onCreate().
1060 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001061 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001062 synchronized (PhoneInterfaceManager.class) {
1063 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001064 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001065 } else {
1066 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1067 }
1068 return sInstance;
1069 }
1070 }
1071
1072 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001073 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001074 mApp = app;
1075 mPhone = phone;
1076 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001077 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001078 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1079 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001080 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001081 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001082 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001083 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001084
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001085 publish();
1086 }
1087
1088 private void publish() {
1089 if (DBG) log("publish: " + this);
1090
1091 ServiceManager.addService("phone", this);
1092 }
1093
Stuart Scott584921c2015-01-15 17:10:34 -08001094 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001095 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1096 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001097 }
1098
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001099 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1100 Phone phone = getPhoneFromRequest(request);
1101 return phone == null ? null :
1102 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1103 }
1104
Wink Saville36469e72014-06-11 15:17:00 -07001105 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001106 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001107 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001108 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001109 //
1110 // Implementation of the ITelephony interface.
1111 //
1112
1113 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001114 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001115 }
1116
Wink Savilleb564aae2014-10-23 10:18:09 -07001117 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001118 if (DBG) log("dial: " + number);
1119 // No permission check needed here: This is just a wrapper around the
1120 // ACTION_DIAL intent, which is available to any app since it puts up
1121 // the UI before it does anything.
1122
1123 String url = createTelUrl(number);
1124 if (url == null) {
1125 return;
1126 }
1127
1128 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001129 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001130 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1131 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1132 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1133 mApp.startActivity(intent);
1134 }
1135 }
1136
1137 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001138 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001139 }
1140
Wink Savilleb564aae2014-10-23 10:18:09 -07001141 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001142 if (DBG) log("call: " + number);
1143
1144 // This is just a wrapper around the ACTION_CALL intent, but we still
1145 // need to do a permission check since we're calling startActivity()
1146 // from the context of the phone app.
1147 enforceCallPermission();
1148
1149 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1150 != AppOpsManager.MODE_ALLOWED) {
1151 return;
1152 }
1153
1154 String url = createTelUrl(number);
1155 if (url == null) {
1156 return;
1157 }
1158
Wink Saville08874612014-08-31 19:19:58 -07001159 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001160 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001161 if (slist != null) {
1162 for (SubscriptionInfo subInfoRecord : slist) {
1163 if (subInfoRecord.getSubscriptionId() == subId) {
1164 isValid = true;
1165 break;
1166 }
Wink Saville08874612014-08-31 19:19:58 -07001167 }
1168 }
1169 if (isValid == false) {
1170 return;
1171 }
1172
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001173 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001174 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001175 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1176 mApp.startActivity(intent);
1177 }
1178
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001179 /**
1180 * End a call based on call state
1181 * @return true is a call was ended
1182 */
1183 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001184 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001185 }
1186
1187 /**
1188 * End a call based on the call state of the subId
1189 * @return true is a call was ended
1190 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001191 public boolean endCallForSubscriber(int subId) {
Tyler Gunn67073572018-02-14 14:19:42 -08001192 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1193 != PackageManager.PERMISSION_GRANTED) {
1194 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1195 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1196 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1197 }
Stuart Scott584921c2015-01-15 17:10:34 -08001198 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001199 }
1200
1201 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001202 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001203 }
1204
Wink Savilleb564aae2014-10-23 10:18:09 -07001205 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001206 if (DBG) log("answerRingingCall...");
1207 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1208 // but that can probably wait till the big TelephonyManager API overhaul.
1209 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1210 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001211 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001212 }
1213
1214 /**
1215 * Make the actual telephony calls to implement answerRingingCall().
1216 * This should only be called from the main thread of the Phone app.
1217 * @see #answerRingingCall
1218 *
1219 * TODO: it would be nice to return true if we answered the call, or
1220 * false if there wasn't actually a ringing incoming call, or some
1221 * other error occurred. (In other words, pass back the return value
1222 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1223 * But that would require calling this method via sendRequest() rather
1224 * than sendRequestAsync(), and right now we don't actually *need* that
1225 * return value, so let's just return void for now.
1226 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001227 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001228 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001229 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001230 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1231 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232 if (hasActiveCall && hasHoldingCall) {
1233 // Both lines are in use!
1234 // TODO: provide a flag to let the caller specify what
1235 // policy to use if both lines are in use. (The current
1236 // behavior is hardwired to "answer incoming, end ongoing",
1237 // which is how the CALL button is specced to behave.)
1238 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1239 return;
1240 } else {
1241 // answerCall() will automatically hold the current active
1242 // call, if there is one.
1243 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1244 return;
1245 }
1246 } else {
1247 // No call was ringing.
1248 return;
1249 }
1250 }
1251
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001252 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001253 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001254 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001255 public void silenceRinger() {
1256 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001257 }
1258
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001259 @Override
1260 public boolean isOffhook(String callingPackage) {
1261 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001262 }
1263
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001264 @Override
1265 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001266 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001267 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001268 return false;
1269 }
1270
Sanket Padawe356d7632015-06-22 14:03:32 -07001271 final Phone phone = getPhone(subId);
1272 if (phone != null) {
1273 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1274 } else {
1275 return false;
1276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 }
1278
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001279 @Override
1280 public boolean isRinging(String callingPackage) {
1281 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001282 }
1283
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001284 @Override
1285 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001287 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001288 return false;
1289 }
1290
Sanket Padawe356d7632015-06-22 14:03:32 -07001291 final Phone phone = getPhone(subId);
1292 if (phone != null) {
1293 return (phone.getState() == PhoneConstants.State.RINGING);
1294 } else {
1295 return false;
1296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001297 }
1298
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001299 @Override
1300 public boolean isIdle(String callingPackage) {
1301 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001302 }
1303
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001304 @Override
1305 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001307 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001308 return false;
1309 }
1310
Sanket Padawe356d7632015-06-22 14:03:32 -07001311 final Phone phone = getPhone(subId);
1312 if (phone != null) {
1313 return (phone.getState() == PhoneConstants.State.IDLE);
1314 } else {
1315 return false;
1316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 }
1318
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001320 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001321 }
1322
Wink Savilleb564aae2014-10-23 10:18:09 -07001323 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001324 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001325 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1326 }
1327
1328 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001329 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001330 }
1331
Wink Savilleb564aae2014-10-23 10:18:09 -07001332 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001333 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001334 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1335 }
1336
1337 /** {@hide} */
1338 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001339 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001340 }
1341
Wink Savilleb564aae2014-10-23 10:18:09 -07001342 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001344 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001345 checkSimPin.start();
1346 return checkSimPin.unlockSim(null, pin);
1347 }
1348
Wink Saville9de0f752013-10-22 19:04:03 -07001349 /** {@hide} */
1350 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001351 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001352 }
1353
Wink Savilleb564aae2014-10-23 10:18:09 -07001354 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001355 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001356 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001357 checkSimPuk.start();
1358 return checkSimPuk.unlockSim(puk, pin);
1359 }
1360
1361 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001362 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363 * a synchronous one.
1364 */
1365 private static class UnlockSim extends Thread {
1366
1367 private final IccCard mSimCard;
1368
1369 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001370 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1371 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372
1373 // For replies from SimCard interface
1374 private Handler mHandler;
1375
1376 // For async handler to identify request type
1377 private static final int SUPPLY_PIN_COMPLETE = 100;
1378
1379 public UnlockSim(IccCard simCard) {
1380 mSimCard = simCard;
1381 }
1382
1383 @Override
1384 public void run() {
1385 Looper.prepare();
1386 synchronized (UnlockSim.this) {
1387 mHandler = new Handler() {
1388 @Override
1389 public void handleMessage(Message msg) {
1390 AsyncResult ar = (AsyncResult) msg.obj;
1391 switch (msg.what) {
1392 case SUPPLY_PIN_COMPLETE:
1393 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1394 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001395 mRetryCount = msg.arg1;
1396 if (ar.exception != null) {
1397 if (ar.exception instanceof CommandException &&
1398 ((CommandException)(ar.exception)).getCommandError()
1399 == CommandException.Error.PASSWORD_INCORRECT) {
1400 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1401 } else {
1402 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1403 }
1404 } else {
1405 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 mDone = true;
1408 UnlockSim.this.notifyAll();
1409 }
1410 break;
1411 }
1412 }
1413 };
1414 UnlockSim.this.notifyAll();
1415 }
1416 Looper.loop();
1417 }
1418
1419 /*
1420 * Use PIN or PUK to unlock SIM card
1421 *
1422 * If PUK is null, unlock SIM card with PIN
1423 *
1424 * If PUK is not null, unlock SIM card with PUK and set PIN code
1425 */
Wink Saville9de0f752013-10-22 19:04:03 -07001426 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427
1428 while (mHandler == null) {
1429 try {
1430 wait();
1431 } catch (InterruptedException e) {
1432 Thread.currentThread().interrupt();
1433 }
1434 }
1435 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1436
1437 if (puk == null) {
1438 mSimCard.supplyPin(pin, callback);
1439 } else {
1440 mSimCard.supplyPuk(puk, pin, callback);
1441 }
1442
1443 while (!mDone) {
1444 try {
1445 Log.d(LOG_TAG, "wait for done");
1446 wait();
1447 } catch (InterruptedException e) {
1448 // Restore the interrupted status
1449 Thread.currentThread().interrupt();
1450 }
1451 }
1452 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001453 int[] resultArray = new int[2];
1454 resultArray[0] = mResult;
1455 resultArray[1] = mRetryCount;
1456 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001457 }
1458 }
1459
1460 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001461 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001462
1463 }
1464
Wink Savilleb564aae2014-10-23 10:18:09 -07001465 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001466 // No permission check needed here: this call is harmless, and it's
1467 // needed for the ServiceState.requestStateUpdate() call (which is
1468 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001469 final Phone phone = getPhone(subId);
1470 if (phone != null) {
1471 phone.updateServiceLocation();
1472 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473 }
1474
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001475 @Override
1476 public boolean isRadioOn(String callingPackage) {
1477 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001478 }
1479
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001480 @Override
1481 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001482 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001483 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001484 return false;
1485 }
1486 return isRadioOnForSubscriber(subId);
1487 }
1488
1489 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001490 final Phone phone = getPhone(subId);
1491 if (phone != null) {
1492 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1493 } else {
1494 return false;
1495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 }
1497
1498 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001499 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001500
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 }
Wink Saville36469e72014-06-11 15:17:00 -07001502
Wink Savilleb564aae2014-10-23 10:18:09 -07001503 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001505 final Phone phone = getPhone(subId);
1506 if (phone != null) {
1507 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1508 }
Wink Saville36469e72014-06-11 15:17:00 -07001509 }
1510
1511 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001512 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001513 }
1514
Wink Savilleb564aae2014-10-23 10:18:09 -07001515 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001516 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001517 final Phone phone = getPhone(subId);
1518 if (phone == null) {
1519 return false;
1520 }
1521 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001522 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001523 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 }
1525 return true;
1526 }
Wink Saville36469e72014-06-11 15:17:00 -07001527
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001528 public boolean needMobileRadioShutdown() {
1529 /*
1530 * If any of the Radios are available, it will need to be
1531 * shutdown. So return true if any Radio is available.
1532 */
1533 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1534 Phone phone = PhoneFactory.getPhone(i);
1535 if (phone != null && phone.isRadioAvailable()) return true;
1536 }
1537 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1538 return false;
1539 }
1540
1541 public void shutdownMobileRadios() {
1542 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1543 logv("Shutting down Phone " + i);
1544 shutdownRadioUsingPhoneId(i);
1545 }
1546 }
1547
1548 private void shutdownRadioUsingPhoneId(int phoneId) {
1549 enforceModifyPermission();
1550 Phone phone = PhoneFactory.getPhone(phoneId);
1551 if (phone != null && phone.isRadioAvailable()) {
1552 phone.shutdownRadio();
1553 }
1554 }
1555
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001557 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001558 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1559 if (defaultPhone != null) {
1560 defaultPhone.setRadioPower(turnOn);
1561 return true;
1562 } else {
1563 loge("There's no default phone.");
1564 return false;
1565 }
Wink Saville36469e72014-06-11 15:17:00 -07001566 }
1567
Wink Savilleb564aae2014-10-23 10:18:09 -07001568 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001570 final Phone phone = getPhone(subId);
1571 if (phone != null) {
1572 phone.setRadioPower(turnOn);
1573 return true;
1574 } else {
1575 return false;
1576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 }
1578
Wink Saville36469e72014-06-11 15:17:00 -07001579 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 public boolean enableDataConnectivity() {
1582 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001583 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001584 final Phone phone = getPhone(subId);
1585 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001586 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001587 return true;
1588 } else {
1589 return false;
1590 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 }
1592
Wink Saville36469e72014-06-11 15:17:00 -07001593 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 public boolean disableDataConnectivity() {
1596 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001597 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001598 final Phone phone = getPhone(subId);
1599 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001600 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001601 return true;
1602 } else {
1603 return false;
1604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 }
1606
Sanket Padawe356d7632015-06-22 14:03:32 -07001607 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001608 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001609 final Phone phone = getPhone(subId);
1610 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001611 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001612 } else {
1613 return false;
1614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 }
1616
1617 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001618 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001619 }
1620
pkanwarae03a6b2016-11-06 20:37:09 -08001621 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001622 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001623 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1624 return;
1625 }
1626 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1627 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1628 };
1629
Wink Savilleb564aae2014-10-23 10:18:09 -07001630 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001632 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1633 return false;
1634 }
Wink Saville36469e72014-06-11 15:17:00 -07001635 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 }
1637
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001639 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001640 }
1641
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001642 public int getCallStateForSlot(int slotIndex) {
1643 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001644 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001645 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 }
1647
Sanket Padawe356d7632015-06-22 14:03:32 -07001648 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001650 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001651 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001652 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001654 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001655 }
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 getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001660 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001661 if (phone != null) {
1662 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1663 } else {
1664 return TelephonyManager.DATA_ACTIVITY_NONE;
1665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 }
1667
1668 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001669 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001670 mPhone.getContext().getSystemService(AppOpsManager.class)
1671 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001672 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001673 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001674 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 }
1676
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001677 if (DBG_LOC) log("getCellLocation: is active user");
1678 Bundle data = new Bundle();
1679 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1680 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 return null;
1682 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001684 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001685 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1686 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001687 }
1688
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001690 public String getNetworkCountryIsoForPhone(int phoneId) {
1691 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1692 // registered cell info, so return a NULL country instead.
1693 final long identity = Binder.clearCallingIdentity();
1694 try {
1695 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1696 if (TelephonyManager.NETWORK_TYPE_IWLAN
1697 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1698 return "";
1699 }
1700 } finally {
1701 Binder.restoreCallingIdentity(identity);
1702 }
1703 return TelephonyManager.getTelephonyProperty(
1704 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1705 }
1706
1707 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001708 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001709 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001710 }
1711
Sanket Padawe356d7632015-06-22 14:03:32 -07001712 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001713 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 mApp.enforceCallingOrSelfPermission(
1715 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
1718 phone.enableLocationUpdates();
1719 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 }
1721
1722 @Override
1723 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001724 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001725 }
1726
Sanket Padawe356d7632015-06-22 14:03:32 -07001727 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001728 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 mApp.enforceCallingOrSelfPermission(
1730 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001731 final Phone phone = getPhone(subId);
1732 if (phone != null) {
1733 phone.disableLocationUpdates();
1734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 }
1736
1737 @Override
1738 @SuppressWarnings("unchecked")
1739 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001740 mPhone.getContext().getSystemService(AppOpsManager.class)
1741 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001742 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001743 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001744 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
1746
1747 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1748 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1749 return null;
1750 }
Svetoslav64fad262015-04-14 14:35:21 -07001751
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001752 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001754 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001756 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001757 try {
1758 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1759 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1760 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1761 } catch (RuntimeException e) {
1762 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001763 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001764 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 }
1766
1767
1768 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001769 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001770 mPhone.getContext().getSystemService(AppOpsManager.class)
1771 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001772 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001773 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001774 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 }
1776
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001777 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001778 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001779 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1780 for (Phone phone : PhoneFactory.getPhones()) {
1781 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1782 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001784 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
1786
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001787 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001789 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001790 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001791 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 }
1793
Shishir Agrawala9f32182016-04-12 12:00:16 -07001794 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001795 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001796 Phone phone = PhoneFactory.getPhone(slotIndex);
1797 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001798 return null;
1799 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001800 int subId = phone.getSubId();
1801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1802 mApp, subId, callingPackage, "getImeiForSlot")) {
1803 return null;
1804 }
1805 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001806 }
1807
1808 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001809 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001810 Phone phone = PhoneFactory.getPhone(slotIndex);
1811 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001812 return null;
1813 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001814 int subId = phone.getSubId();
1815 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1816 mApp, subId, callingPackage, "getMeidForSlot")) {
1817 return null;
1818 }
1819 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001820 }
1821
1822 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001823 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08001824 Phone phone = PhoneFactory.getPhone(slotIndex);
1825 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001826 return null;
1827 }
Jeff Davidson913390f2018-02-23 17:11:49 -08001828 int subId = phone.getSubId();
1829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1830 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1831 return null;
1832 }
1833 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001834 }
1835
fionaxu43304da2017-11-27 22:51:16 -08001836 @Override
1837 public int getSubscriptionCarrierId(int subId) {
1838 final Phone phone = getPhone(subId);
1839 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1840 }
1841
1842 @Override
1843 public String getSubscriptionCarrierName(int subId) {
1844 final Phone phone = getPhone(subId);
1845 return phone == null ? null : phone.getCarrierName();
1846 }
1847
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 //
1849 // Internal helper methods.
1850 //
1851
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001852 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001853 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1854 *
1855 * @throws SecurityException if the caller does not have the required permission
1856 */
1857 private void enforceModifyPermission() {
1858 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1859 }
1860
1861 /**
1862 * Make sure the caller has the CALL_PHONE permission.
1863 *
1864 * @throws SecurityException if the caller does not have the required permission
1865 */
1866 private void enforceCallPermission() {
1867 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1868 }
1869
Stuart Scott8eef64f2015-04-08 15:13:54 -07001870 private void enforceConnectivityInternalPermission() {
1871 mApp.enforceCallingOrSelfPermission(
1872 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1873 "ConnectivityService");
1874 }
1875
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 private String createTelUrl(String number) {
1877 if (TextUtils.isEmpty(number)) {
1878 return null;
1879 }
1880
Jake Hambye994d462014-02-03 13:10:13 -08001881 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 }
1883
Ihab Awadf9e92732013-12-05 18:02:52 -08001884 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1886 }
1887
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001888 private static void logv(String msg) {
1889 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1890 }
1891
Ihab Awadf9e92732013-12-05 18:02:52 -08001892 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1894 }
1895
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001896 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001898 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001899 }
1900
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001902 public int getActivePhoneTypeForSlot(int slotIndex) {
1903 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 if (phone == null) {
1905 return PhoneConstants.PHONE_TYPE_NONE;
1906 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001907 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 }
1910
1911 /**
1912 * Returns the CDMA ERI icon index to display
1913 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001914 @Override
1915 public int getCdmaEriIconIndex(String callingPackage) {
1916 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001917 }
1918
Sanket Padawe356d7632015-06-22 14:03:32 -07001919 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001920 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001922 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001923 return -1;
1924 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001925 final Phone phone = getPhone(subId);
1926 if (phone != null) {
1927 return phone.getCdmaEriIconIndex();
1928 } else {
1929 return -1;
1930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 }
1932
1933 /**
1934 * Returns the CDMA ERI icon mode,
1935 * 0 - ON
1936 * 1 - FLASHING
1937 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001938 @Override
1939 public int getCdmaEriIconMode(String callingPackage) {
1940 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001941 }
1942
Sanket Padawe356d7632015-06-22 14:03:32 -07001943 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001944 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001945 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001946 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001947 return -1;
1948 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001949 final Phone phone = getPhone(subId);
1950 if (phone != null) {
1951 return phone.getCdmaEriIconMode();
1952 } else {
1953 return -1;
1954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 }
1956
1957 /**
1958 * Returns the CDMA ERI text,
1959 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001960 @Override
1961 public String getCdmaEriText(String callingPackage) {
1962 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001963 }
1964
Sanket Padawe356d7632015-06-22 14:03:32 -07001965 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001966 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001968 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001969 return null;
1970 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001971 final Phone phone = getPhone(subId);
1972 if (phone != null) {
1973 return phone.getCdmaEriText();
1974 } else {
1975 return null;
1976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 }
1978
1979 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001980 * Returns the CDMA MDN.
1981 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001982 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001983 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001984 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1985 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07001986 final Phone phone = getPhone(subId);
1987 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1988 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001989 } else {
1990 return null;
1991 }
1992 }
1993
1994 /**
1995 * Returns the CDMA MIN.
1996 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001998 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2000 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002001 final Phone phone = getPhone(subId);
2002 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2003 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002004 } else {
2005 return null;
2006 }
2007 }
2008
2009 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002010 * Returns true if CDMA provisioning needs to run.
2011 */
2012 public boolean needsOtaServiceProvisioning() {
2013 return mPhone.needsOtaServiceProvisioning();
2014 }
2015
2016 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002017 * Sets the voice mail number of a given subId.
2018 */
2019 @Override
2020 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002021 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002022 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2023 new Pair<String, String>(alphaTag, number), new Integer(subId));
2024 return success;
2025 }
2026
Ta-wei Yen87c49842016-05-13 21:19:52 -07002027 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002028 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2029 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2030 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2031 if (!TextUtils.equals(callingPackage, systemDialer)) {
2032 throw new SecurityException("caller must be system dialer");
2033 }
2034 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2035 if (phoneAccountHandle == null){
2036 return null;
2037 }
2038 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2039 }
2040
2041 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002042 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002043 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002044 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002045 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002046 return null;
2047 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002048 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2049 }
2050
2051 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002052 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2053 VisualVoicemailSmsFilterSettings settings) {
2054 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002055 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002056 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2057 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002058 }
2059
2060 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002061 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2062 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002063 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002064 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002065 }
2066
2067 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002068 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2069 String callingPackage, int subId) {
2070 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002071 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002072 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002073 }
2074
2075 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002076 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002077 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002078 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002079 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2080 }
2081
2082 @Override
2083 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2084 String number, int port, String text, PendingIntent sentIntent) {
2085 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002086 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002087 enforceSendSmsPermission();
2088 // Make the calls as the phone process.
2089 final long identity = Binder.clearCallingIdentity();
2090 try {
2091 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2092 if (port == 0) {
2093 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2094 sentIntent, null, false);
2095 } else {
2096 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2097 smsManager.sendDataMessageWithSelfPermissions(number, null,
2098 (short) port, data, sentIntent, null);
2099 }
2100 } finally {
2101 Binder.restoreCallingIdentity(identity);
2102 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002103 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002104 /**
fionaxu0152e512016-11-14 13:36:14 -08002105 * Sets the voice activation state of a given subId.
2106 */
2107 @Override
2108 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2110 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002111 final Phone phone = getPhone(subId);
2112 if (phone != null) {
2113 phone.setVoiceActivationState(activationState);
2114 } else {
2115 loge("setVoiceActivationState fails with invalid subId: " + subId);
2116 }
2117 }
2118
2119 /**
2120 * Sets the data activation state of a given subId.
2121 */
2122 @Override
2123 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2125 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002126 final Phone phone = getPhone(subId);
2127 if (phone != null) {
2128 phone.setDataActivationState(activationState);
2129 } else {
2130 loge("setVoiceActivationState fails with invalid subId: " + subId);
2131 }
2132 }
2133
2134 /**
2135 * Returns the voice activation state of a given subId.
2136 */
2137 @Override
2138 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002139 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002140 final Phone phone = getPhone(subId);
2141 if (phone != null) {
2142 return phone.getVoiceActivationState();
2143 } else {
2144 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2145 }
2146 }
2147
2148 /**
2149 * Returns the data activation state of a given subId.
2150 */
2151 @Override
2152 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002153 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002154 final Phone phone = getPhone(subId);
2155 if (phone != null) {
2156 return phone.getDataActivationState();
2157 } else {
2158 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2159 }
2160 }
2161
2162 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 * Returns the unread count of voicemails
2164 */
2165 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002166 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002167 }
2168
2169 /**
2170 * Returns the unread count of voicemails for a subId
2171 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002172 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002173 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002174 final Phone phone = getPhone(subId);
2175 if (phone != null) {
2176 return phone.getVoiceMessageCount();
2177 } else {
2178 return 0;
2179 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180 }
2181
2182 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002183 * returns true, if the device is in a state where both voice and data
2184 * are supported simultaneously. This can change based on location or network condition.
2185 */
2186 @Override
2187 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2188 final Phone phone = getPhone(subId);
2189 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2190 }
2191
2192 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002193 * Send the dialer code if called from the current default dialer or the caller has
2194 * carrier privilege.
2195 * @param inputCode The dialer code to send
2196 */
2197 @Override
2198 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2199 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2200 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2201 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002202 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2203 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002204 }
2205 mPhone.sendDialerSpecialCode(inputCode);
2206 }
2207
2208 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002209 * Returns the data network type.
2210 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002211 *
2212 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2213 */
2214 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002215 public int getNetworkType() {
2216 final Phone phone = getPhone(getDefaultSubscription());
2217 if (phone != null) {
2218 return phone.getServiceState().getDataNetworkType();
2219 } else {
2220 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2221 }
Wink Saville36469e72014-06-11 15:17:00 -07002222 }
2223
2224 /**
2225 * Returns the network type for a subId
2226 */
2227 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002228 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002230 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002231 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2232 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002233
Sanket Padawe356d7632015-06-22 14:03:32 -07002234 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002235 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002236 return phone.getServiceState().getDataNetworkType();
2237 } else {
2238 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 }
2241
2242 /**
2243 * Returns the data network type
2244 */
2245 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002246 public int getDataNetworkType(String callingPackage) {
2247 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002248 }
2249
2250 /**
2251 * Returns the data network type for a subId
2252 */
2253 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002254 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002255 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002256 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002257 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2258 }
2259
Sanket Padawe356d7632015-06-22 14:03:32 -07002260 final Phone phone = getPhone(subId);
2261 if (phone != null) {
2262 return phone.getServiceState().getDataNetworkType();
2263 } else {
2264 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267
2268 /**
Wink Saville36469e72014-06-11 15:17:00 -07002269 * Returns the Voice network type for a subId
2270 */
2271 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002272 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002273 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002274 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002275 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2276 }
2277
Sanket Padawe356d7632015-06-22 14:03:32 -07002278 final Phone phone = getPhone(subId);
2279 if (phone != null) {
2280 return phone.getServiceState().getVoiceNetworkType();
2281 } else {
2282 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002284 }
2285
2286 /**
2287 * @return true if a ICC card is present
2288 */
2289 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002290 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002291 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2292 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002293 }
2294
2295 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002296 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002297 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002298 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002299 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2300 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002301 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002302 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002303 } else {
2304 return false;
2305 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002306 }
2307
2308 /**
2309 * Return if the current radio is LTE on CDMA. This
2310 * is a tri-state return value as for a period of time
2311 * the mode may be unknown.
2312 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002313 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002314 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002315 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002317 @Override
2318 public int getLteOnCdmaMode(String callingPackage) {
2319 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002320 }
2321
Sanket Padawe356d7632015-06-22 14:03:32 -07002322 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002323 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002325 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002326 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2327 }
2328
Sanket Padawe356d7632015-06-22 14:03:32 -07002329 final Phone phone = getPhone(subId);
2330 if (phone == null) {
2331 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2332 } else {
2333 return phone.getLteOnCdmaMode();
2334 }
Wink Saville36469e72014-06-11 15:17:00 -07002335 }
2336
2337 public void setPhone(Phone phone) {
2338 mPhone = phone;
2339 }
2340
2341 /**
2342 * {@hide}
2343 * Returns Default subId, 0 in the case of single standby.
2344 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002345 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002346 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002347 }
2348
Shishir Agrawala9f32182016-04-12 12:00:16 -07002349 private int getSlotForDefaultSubscription() {
2350 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2351 }
2352
Wink Savilleb564aae2014-10-23 10:18:09 -07002353 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002354 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002356
2357 /**
2358 * @see android.telephony.TelephonyManager.WifiCallingChoices
2359 */
2360 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002361 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2362 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002363 }
2364
2365 /**
2366 * @see android.telephony.TelephonyManager.WifiCallingChoices
2367 */
2368 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002369 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2370 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2371 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002372 }
2373
Sailesh Nepald1e68152013-12-12 19:08:02 -08002374 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002375 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002376 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002377 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002378
Shishir Agrawal566b7612013-10-28 14:41:00 -07002379 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002380 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2381 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2383 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002384
Derek Tan740e1672017-06-27 14:56:27 -07002385 if (TextUtils.equals(ISDR_AID, aid)) {
2386 // Only allows LPA to open logical channel to ISD-R.
2387 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2388 ComponentInfo bestComponent =
2389 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2390 if (bestComponent == null
2391 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2392 loge("The calling package is not allowed to access ISD-R.");
2393 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2394 }
2395 }
2396
2397 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002398 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002399 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002400 if (DBG) log("iccOpenLogicalChannel: " + response);
2401 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002402 }
2403
2404 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002405 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2407 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002408
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002409 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002410 if (channel < 0) {
2411 return false;
2412 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002413 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002414 if (DBG) log("iccCloseLogicalChannel: " + success);
2415 return success;
2416 }
2417
2418 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002419 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002420 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2422 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002423
2424 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002425 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2426 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002427 " data=" + data);
2428 }
2429
2430 if (channel < 0) {
2431 return "";
2432 }
2433
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002434 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002435 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002436 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2437
Shishir Agrawal566b7612013-10-28 14:41:00 -07002438 // Append the returned status code to the end of the response payload.
2439 String s = Integer.toHexString(
2440 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002441 if (response.payload != null) {
2442 s = IccUtils.bytesToHexString(response.payload) + s;
2443 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002444 return s;
2445 }
Jake Hambye994d462014-02-03 13:10:13 -08002446
Evan Charltonc66da362014-05-16 14:06:40 -07002447 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002448 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2449 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2451 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002452
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002453 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2454 && TextUtils.equals(ISDR_AID, data)) {
2455 // Only allows LPA to select ISD-R.
2456 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2457 ComponentInfo bestComponent =
2458 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2459 if (bestComponent == null
2460 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2461 loge("The calling package is not allowed to select ISD-R.");
2462 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2463 }
2464 }
2465
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002466 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002467 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2468 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002469 }
2470
2471 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002472 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002473 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2474
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002475 // Append the returned status code to the end of the response payload.
2476 String s = Integer.toHexString(
2477 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002478 if (response.payload != null) {
2479 s = IccUtils.bytesToHexString(response.payload) + s;
2480 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002481 return s;
2482 }
2483
2484 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002485 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002486 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2488 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002489
2490 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002491 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002492 p1 + " " + p2 + " " + p3 + ":" + filePath);
2493 }
2494
2495 IccIoResult response =
2496 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002497 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2498 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002499
2500 if (DBG) {
2501 log("Exchange SIM_IO [R]" + response);
2502 }
2503
2504 byte[] result = null;
2505 int length = 2;
2506 if (response.payload != null) {
2507 length = 2 + response.payload.length;
2508 result = new byte[length];
2509 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2510 } else {
2511 result = new byte[length];
2512 }
2513
2514 result[length - 1] = (byte) response.sw2;
2515 result[length - 2] = (byte) response.sw1;
2516 return result;
2517 }
2518
Nathan Haroldb3014052017-01-25 15:57:32 -08002519 /**
2520 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2521 * on a particular subscription
2522 */
2523 public String[] getForbiddenPlmns(int subId, int appType) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002524 // TODO(b/73884967): Migrate to TelephonyPermissions check.
Nathan Harold892104e2017-04-13 18:19:05 -07002525 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2526 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002527 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2528 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2529 return null;
2530 }
2531 Object response = sendRequest(
2532 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2533 if (response instanceof String[]) {
2534 return (String[]) response;
2535 }
2536 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2537 return null;
2538 }
2539
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002540 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002541 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2543 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002544
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002545 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002546 if (response.payload == null) {
2547 return "";
2548 }
2549
2550 // Append the returned status code to the end of the response payload.
2551 String s = Integer.toHexString(
2552 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2553 s = IccUtils.bytesToHexString(response.payload) + s;
2554 return s;
2555 }
2556
Jake Hambye994d462014-02-03 13:10:13 -08002557 /**
2558 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2559 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2560 *
2561 * @param itemID the ID of the item to read
2562 * @return the NV item as a String, or null on error.
2563 */
2564 @Override
2565 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002566 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2567 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002568 if (DBG) log("nvReadItem: item " + itemID);
2569 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2570 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2571 return value;
2572 }
2573
2574 /**
2575 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2576 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2577 *
2578 * @param itemID the ID of the item to read
2579 * @param itemValue the value to write, as a String
2580 * @return true on success; false on any failure
2581 */
2582 @Override
2583 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2585 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002586 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2587 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2588 new Pair<Integer, String>(itemID, itemValue));
2589 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2590 return success;
2591 }
2592
2593 /**
2594 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2595 * Used for device configuration by some CDMA operators.
2596 *
2597 * @param preferredRoamingList byte array containing the new PRL
2598 * @return true on success; false on any failure
2599 */
2600 @Override
2601 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2603 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002604 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2605 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2606 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2607 return success;
2608 }
2609
2610 /**
2611 * Perform the specified type of NV config reset.
2612 * Used for device configuration by some CDMA operators.
2613 *
2614 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2615 * @return true on success; false on any failure
2616 */
2617 @Override
2618 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2620 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002621 if (DBG) log("nvResetConfig: type " + resetType);
2622 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2623 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2624 return success;
2625 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002626
2627 /**
Wink Saville36469e72014-06-11 15:17:00 -07002628 * {@hide}
2629 * Returns Default sim, 0 in the case of single standby.
2630 */
2631 public int getDefaultSim() {
2632 //TODO Need to get it from Telephony Devcontroller
2633 return 0;
2634 }
2635
Svet Ganovb320e182015-04-16 12:30:10 -07002636 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002637 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002638 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002639 return new String[0];
2640 }
2641
2642
ram87fca6f2014-07-18 18:58:44 +05302643 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002644 }
2645
Brad Ebinger51f743a2017-01-23 13:50:20 -08002646 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002647 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2648 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002649 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002650 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002651 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002652 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002653 }
2654
2655 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002656 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2657 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002658 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002659 public void disableIms(int slotId) {
2660 enforceModifyPermission();
2661 PhoneFactory.getImsResolver().disableIms(slotId);
2662 }
2663
2664 /**
2665 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2666 * feature or {@link null} if the service is not available. If the feature is available, the
2667 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2668 */
2669 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002670 IImsServiceFeatureCallback callback) {
2671 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002672 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002673 }
2674
2675 /**
2676 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2677 * feature during emergency calling or {@link null} if the service is not available. If the
2678 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2679 * listener for feature updates.
2680 */
2681 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2682 enforceModifyPermission();
2683 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002684 }
2685
Brad Ebinger5f64b052017-12-14 14:26:15 -08002686 /**
2687 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2688 * specified.
2689 */
2690 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2691 enforceModifyPermission();
2692 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2693 }
2694
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002695 /**
2696 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2697 * specified.
2698 */
2699 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2700 enforceModifyPermission();
2701 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2702 }
2703
Brad Ebinger884c07b2018-02-15 16:17:40 -08002704 /**
2705 * @return true if emergency calling is available on IMS, false if it should fallback to CS.
2706 */
2707 public boolean isEmergencyMmTelAvailable(int slotId) {
2708 enforceModifyPermission();
2709 return PhoneFactory.getImsResolver().isEmergencyMmTelAvailable(slotId);
2710 }
2711
Wink Saville36469e72014-06-11 15:17:00 -07002712 public void setImsRegistrationState(boolean registered) {
2713 enforceModifyPermission();
2714 mPhone.setImsRegistrationState(registered);
2715 }
2716
2717 /**
Stuart Scott54788802015-03-30 13:18:01 -07002718 * Set the network selection mode to automatic.
2719 *
2720 */
2721 @Override
2722 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002723 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2724 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002725 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2726 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2727 }
2728
2729 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002730 * Set the network selection mode to manual with the selected carrier.
2731 */
2732 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002733 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002734 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2736 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002737 OperatorInfo operator = new OperatorInfo(
2738 /* operatorAlphaLong */ "",
2739 /* operatorAlphaShort */ "",
2740 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002741 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002742 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2743 persistSelection);
2744 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002745 }
2746
2747 /**
2748 * Scans for available networks.
2749 */
2750 @Override
2751 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2753 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002754 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2755 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2756 CMD_PERFORM_NETWORK_SCAN, null, subId);
2757 return result;
2758 }
2759
2760 /**
yinxub1bed742017-04-17 11:45:04 -07002761 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002762 *
yinxub1bed742017-04-17 11:45:04 -07002763 * @param subId id of the subscription
2764 * @param request contains the radio access networks with bands/channels to scan
2765 * @param messenger callback messenger for scan results or errors
2766 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002767 * @return the id of the requested scan which can be used to stop the scan.
2768 */
2769 @Override
2770 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2771 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2773 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002774 return mNetworkScanRequestTracker.startNetworkScan(
2775 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002776 }
2777
2778 /**
2779 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002780 *
2781 * @param subId id of the subscription
2782 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002783 */
2784 @Override
2785 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2787 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002788 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002789 }
2790
2791 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002792 * Get the calculated preferred network type.
2793 * Used for debugging incorrect network type.
2794 *
2795 * @return the preferred network type, defined in RILConstants.java.
2796 */
2797 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002798 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002799 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002800 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002801 return RILConstants.PREFERRED_NETWORK_MODE;
2802 }
2803
Amit Mahajan43330e02014-11-18 11:54:45 -08002804 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002805 }
2806
2807 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002808 * Get the preferred network type.
2809 * Used for device configuration by some CDMA operators.
2810 *
2811 * @return the preferred network type, defined in RILConstants.java.
2812 */
2813 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002814 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2816 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002817 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002818 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002819 int networkType = (result != null ? result[0] : -1);
2820 if (DBG) log("getPreferredNetworkType: " + networkType);
2821 return networkType;
2822 }
2823
2824 /**
2825 * Set the preferred network type.
2826 * Used for device configuration by some CDMA operators.
2827 *
2828 * @param networkType the preferred network type, defined in RILConstants.java.
2829 * @return true on success; false on any failure.
2830 */
2831 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002832 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2834 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002835 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2836 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002837 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002838 if (success) {
2839 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002840 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002841 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002842 return success;
2843 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002844
2845 /**
Junda Liu475951f2014-11-07 16:45:03 -08002846 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2847 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2848 * tethering.
2849 *
2850 * @return 0: Not required. 1: required. 2: Not set.
2851 * @hide
2852 */
2853 @Override
2854 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002855 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002856 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2857 Settings.Global.TETHER_DUN_REQUIRED, 2);
2858 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2859 // config_tether_apndata.
2860 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2861 dunRequired = 1;
2862 }
2863 return dunRequired;
2864 }
2865
2866 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002867 * Set mobile data enabled
2868 * Used by the user through settings etc to turn on/off mobile data
2869 *
2870 * @param enable {@code true} turn turn data on, else {@code false}
2871 */
2872 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002873 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002874 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2875 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002876 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002877 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002878 Phone phone = PhoneFactory.getPhone(phoneId);
2879 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002880 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2881 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002882 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002883 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002884 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002885 }
2886
2887 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002888 * Get the user enabled state of Mobile Data.
2889 *
2890 * TODO: remove and use isUserDataEnabled.
2891 * This can't be removed now because some vendor codes
2892 * calls through ITelephony directly while they should
2893 * use TelephonyManager.
2894 *
2895 * @return true on enabled
2896 */
2897 @Override
2898 public boolean getDataEnabled(int subId) {
2899 return isUserDataEnabled(subId);
2900 }
2901
2902 /**
2903 * Get whether mobile data is enabled per user setting.
2904 *
2905 * There are other factors deciding whether mobile data is actually enabled, but they are
2906 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002907 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002908 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002909 *
2910 * @return {@code true} if data is enabled else {@code false}
2911 */
2912 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002913 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002914 try {
2915 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2916 null);
2917 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2919 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002920 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002921 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002922 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002923 Phone phone = PhoneFactory.getPhone(phoneId);
2924 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002925 boolean retVal = phone.isUserDataEnabled();
2926 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002927 return retVal;
2928 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002929 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2930 return false;
2931 }
2932 }
2933
2934 /**
2935 * Get whether mobile data is enabled.
2936 *
2937 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2938 * whether mobile data is actually enabled.
2939 *
2940 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2941 *
2942 * @return {@code true} if data is enabled else {@code false}
2943 */
2944 @Override
2945 public boolean isDataEnabled(int subId) {
2946 try {
2947 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2948 null);
2949 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2951 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08002952 }
2953 int phoneId = mSubscriptionController.getPhoneId(subId);
2954 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2955 Phone phone = PhoneFactory.getPhone(phoneId);
2956 if (phone != null) {
2957 boolean retVal = phone.isDataEnabled();
2958 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2959 return retVal;
2960 } else {
2961 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002962 return false;
2963 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002964 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002965
2966 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002967 public int getCarrierPrivilegeStatus(int subId) {
2968 final Phone phone = getPhone(subId);
2969 if (phone == null) {
2970 loge("getCarrierPrivilegeStatus: Invalid subId");
2971 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2972 }
2973 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002974 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002975 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002976 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2977 }
2978 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002979 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002980 }
Junda Liu29340342014-07-10 15:23:27 -07002981
2982 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08002983 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
2984 final Phone phone = getPhone(subId);
2985 if (phone == null) {
2986 loge("getCarrierPrivilegeStatus: Invalid subId");
2987 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2988 }
2989 UiccProfile profile =
2990 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
2991 if (profile == null) {
2992 loge("getCarrierPrivilegeStatus: No UICC");
2993 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2994 }
2995 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
2996 }
2997
2998 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002999 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003000 if (TextUtils.isEmpty(pkgName))
3001 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003002 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003003 if (card == null) {
3004 loge("checkCarrierPrivilegesForPackage: No UICC");
3005 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3006 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003007 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3008 }
3009
3010 @Override
3011 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003012 if (TextUtils.isEmpty(pkgName))
3013 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003014 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3015 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3016 UiccCard card = UiccController.getInstance().getUiccCard(i);
3017 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003018 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003019 continue;
3020 }
3021
3022 result = card.getCarrierPrivilegeStatus(
3023 mPhone.getContext().getPackageManager(), pkgName);
3024 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3025 break;
3026 }
3027 }
3028
3029 return result;
Junda Liu29340342014-07-10 15:23:27 -07003030 }
Derek Tan89e89d42014-07-08 17:00:10 -07003031
3032 @Override
Junda Liue64de782015-04-16 17:19:16 -07003033 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3034 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3035 loge("phoneId " + phoneId + " is not valid.");
3036 return null;
3037 }
3038 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003039 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003040 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003041 return null ;
3042 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003043 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003044 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003045 }
3046
Amith Yamasani6e118872016-02-19 12:53:51 -08003047 @Override
3048 public List<String> getPackagesWithCarrierPrivileges() {
3049 PackageManager pm = mPhone.getContext().getPackageManager();
3050 List<String> privilegedPackages = new ArrayList<>();
3051 List<PackageInfo> packages = null;
3052 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3053 UiccCard card = UiccController.getInstance().getUiccCard(i);
3054 if (card == null) {
3055 // No UICC in that slot.
3056 continue;
3057 }
3058 if (card.hasCarrierPrivilegeRules()) {
3059 if (packages == null) {
3060 // Only check packages in user 0 for now
3061 packages = pm.getInstalledPackagesAsUser(
3062 PackageManager.MATCH_DISABLED_COMPONENTS
3063 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3064 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3065 }
3066 for (int p = packages.size() - 1; p >= 0; p--) {
3067 PackageInfo pkgInfo = packages.get(p);
3068 if (pkgInfo != null && pkgInfo.packageName != null
3069 && card.getCarrierPrivilegeStatus(pkgInfo)
3070 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3071 privilegedPackages.add(pkgInfo.packageName);
3072 }
3073 }
3074 }
3075 }
3076 return privilegedPackages;
3077 }
3078
Wink Savilleb564aae2014-10-23 10:18:09 -07003079 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003080 final Phone phone = getPhone(subId);
3081 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003082 if (card == null) {
3083 loge("getIccId: No UICC");
3084 return null;
3085 }
3086 String iccId = card.getIccId();
3087 if (TextUtils.isEmpty(iccId)) {
3088 loge("getIccId: ICC ID is null or empty.");
3089 return null;
3090 }
3091 return iccId;
3092 }
3093
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003094 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003095 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3096 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003097 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3098 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003099
Jeff Sharkey85190e62014-12-05 09:40:12 -08003100 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003101 final Phone phone = getPhone(subId);
3102 if (phone == null) {
3103 return false;
3104 }
3105 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003106
3107 if (DBG_MERGE) {
3108 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3109 + subscriberId + " to " + number);
3110 }
3111
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003112 if (TextUtils.isEmpty(iccId)) {
3113 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003114 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003115
Jeff Sharkey85190e62014-12-05 09:40:12 -08003116 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3117
3118 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003119 if (alphaTag == null) {
3120 editor.remove(alphaTagPrefKey);
3121 } else {
3122 editor.putString(alphaTagPrefKey, alphaTag);
3123 }
3124
Jeff Sharkey85190e62014-12-05 09:40:12 -08003125 // Record both the line number and IMSI for this ICCID, since we need to
3126 // track all merged IMSIs based on line number
3127 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3128 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003129 if (number == null) {
3130 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003131 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003132 } else {
3133 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003134 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003135 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003136
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003137 editor.commit();
3138 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003139 }
3140
3141 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003142 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003143 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003145 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003146 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003147 return null;
3148 }
Derek Tan97ebb422014-09-05 16:55:38 -07003149
3150 String iccId = getIccId(subId);
3151 if (iccId != null) {
3152 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003153 if (DBG_MERGE) {
3154 log("getLine1NumberForDisplay returning " +
3155 mTelephonySharedPreferences.getString(numberPrefKey, null));
3156 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003157 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003158 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003159 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003160 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003161 }
3162
3163 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003164 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003165 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003166 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003167 return null;
3168 }
Derek Tan97ebb422014-09-05 16:55:38 -07003169
3170 String iccId = getIccId(subId);
3171 if (iccId != null) {
3172 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003173 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003174 }
Derek Tan97ebb422014-09-05 16:55:38 -07003175 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003176 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003177
3178 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003179 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003180 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3181 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003183 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3184 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003185 return null;
3186 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003187 final Context context = mPhone.getContext();
3188 final TelephonyManager tele = TelephonyManager.from(context);
3189 final SubscriptionManager sub = SubscriptionManager.from(context);
3190
3191 // Figure out what subscribers are currently active
3192 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003193 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3194 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3195 final long identity = Binder.clearCallingIdentity();
3196 try {
3197 final int[] subIds = sub.getActiveSubscriptionIdList();
3198 for (int subId : subIds) {
3199 activeSubscriberIds.add(tele.getSubscriberId(subId));
3200 }
3201 } finally {
3202 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003203 }
3204
3205 // First pass, find a number override for an active subscriber
3206 String mergeNumber = null;
3207 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3208 for (String key : prefs.keySet()) {
3209 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3210 final String subscriberId = (String) prefs.get(key);
3211 if (activeSubscriberIds.contains(subscriberId)) {
3212 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3213 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3214 mergeNumber = (String) prefs.get(numberKey);
3215 if (DBG_MERGE) {
3216 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3217 + " for active subscriber " + subscriberId);
3218 }
3219 if (!TextUtils.isEmpty(mergeNumber)) {
3220 break;
3221 }
3222 }
3223 }
3224 }
3225
3226 // Shortcut when no active merged subscribers
3227 if (TextUtils.isEmpty(mergeNumber)) {
3228 return null;
3229 }
3230
3231 // Second pass, find all subscribers under that line override
3232 final ArraySet<String> result = new ArraySet<>();
3233 for (String key : prefs.keySet()) {
3234 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3235 final String number = (String) prefs.get(key);
3236 if (mergeNumber.equals(number)) {
3237 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3238 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3239 final String subscriberId = (String) prefs.get(subscriberKey);
3240 if (!TextUtils.isEmpty(subscriberId)) {
3241 result.add(subscriberId);
3242 }
3243 }
3244 }
3245 }
3246
3247 final String[] resultArray = result.toArray(new String[result.size()]);
3248 Arrays.sort(resultArray);
3249 if (DBG_MERGE) {
3250 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3251 }
3252 return resultArray;
3253 }
3254
3255 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003256 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003257 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3258 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003259 final Phone phone = getPhone(subId);
3260 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003261 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003262
3263 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003264 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003265 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3266 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003267 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003268 final Phone phone = getPhone(subId);
3269 if (phone == null) {
3270 return false;
3271 }
3272 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003273 cdmaNonRoamingList);
3274 }
3275
3276 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003277 public void setRadioCapability(RadioAccessFamily[] rafs) {
3278 try {
3279 ProxyController.getInstance().setRadioCapability(rafs);
3280 } catch (RuntimeException e) {
3281 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3282 }
3283 }
3284
3285 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003286 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003287 Phone phone = PhoneFactory.getPhone(phoneId);
3288 if (phone == null) {
3289 return RadioAccessFamily.RAF_UNKNOWN;
3290 }
3291 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003293 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003294 return RadioAccessFamily.RAF_UNKNOWN;
3295 }
3296
Wink Saville5d475dd2014-10-17 15:00:58 -07003297 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3298 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003299
3300 @Override
3301 public void enableVideoCalling(boolean enable) {
3302 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003303 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003304 }
3305
3306 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003307 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003309 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003310 return false;
3311 }
3312
Andrew Lee77527ac2014-10-21 16:57:39 -07003313 // Check the user preference and the system-level IMS setting. Even if the user has
3314 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3315 // In the long run, we may instead need to check if there exists a connection service
3316 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003317 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3318 return imsManager.isVtEnabledByPlatform()
3319 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3320 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003321 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003322
Andrew Leea1239f22015-03-02 17:44:07 -08003323 @Override
3324 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003325 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003326 }
3327
3328 @Override
3329 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003330 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003331 }
3332
Andrew Lee9431b832015-03-09 18:46:45 -07003333 @Override
3334 public boolean isTtyModeSupported() {
3335 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3336 TelephonyManager telephonyManager =
3337 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003338 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003339 }
3340
3341 @Override
3342 public boolean isHearingAidCompatibilitySupported() {
3343 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3344 }
3345
Hall Liu98187582018-01-22 19:15:32 -08003346 public boolean isRttSupported() {
3347 boolean isCarrierSupported =
3348 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3349 boolean isDeviceSupported =
3350 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3351 return isCarrierSupported && isDeviceSupported;
3352 }
3353
Sanket Padawe7310cc72015-01-14 09:53:20 -08003354 /**
3355 * Returns the unique device ID of phone, for example, the IMEI for
3356 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3357 *
3358 * <p>Requires Permission:
3359 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3360 */
3361 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003362 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003363 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08003364 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003365 return null;
3366 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003367 int subId = phone.getSubId();
3368 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3369 mApp, subId, callingPackage, "getDeviceId")) {
3370 return null;
3371 }
3372 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003373 }
3374
Ping Sunc67b7c22016-03-02 19:16:45 +08003375 /**
3376 * {@hide}
3377 * Returns the IMS Registration Status on a particular subid
3378 *
3379 * @param subId
3380 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003381 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003382 Phone phone = getPhone(subId);
3383 if (phone != null) {
3384 return phone.isImsRegistered();
3385 } else {
3386 return false;
3387 }
3388 }
3389
Santos Cordon7a1885b2015-02-03 11:15:19 -08003390 @Override
3391 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3392 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3393 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003394
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003395 /**
3396 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003397 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003398 public boolean isWifiCallingAvailable(int subId) {
3399 Phone phone = getPhone(subId);
3400 if (phone != null) {
3401 return phone.isWifiCallingEnabled();
3402 } else {
3403 return false;
3404 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003405 }
3406
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003407 /**
3408 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003409 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003410 public boolean isVolteAvailable(int subId) {
3411 Phone phone = getPhone(subId);
3412 if (phone != null) {
3413 return phone.isVolteEnabled();
3414 } else {
3415 return false;
3416 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003417 }
Svet Ganovb320e182015-04-16 12:30:10 -07003418
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003419 /**
3420 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003421 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003422 public boolean isVideoTelephonyAvailable(int subId) {
3423 Phone phone = getPhone(subId);
3424 if (phone != null) {
3425 return phone.isVideoEnabled();
3426 } else {
3427 return false;
3428 }
3429 }
3430
3431 /**
3432 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3433 * defined in {@link ImsRegistrationImplBase}.
3434 */
3435 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3436 Phone phone = getPhone(subId);
3437 if (phone != null) {
3438 return phone.getImsRegistrationTech();
3439 } else {
3440 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3441 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003442 }
3443
Stuart Scott8eef64f2015-04-08 15:13:54 -07003444 @Override
3445 public void factoryReset(int subId) {
3446 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003447 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3448 return;
3449 }
3450
Svet Ganovcc087f82015-05-12 20:35:54 -07003451 final long identity = Binder.clearCallingIdentity();
3452 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003453 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3454 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003455 // Enable data
Malcolm Chen964682d2017-11-28 16:20:07 -08003456 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003457 // Set network selection mode to automatic
3458 setNetworkSelectionModeAutomatic(subId);
3459 // Set preferred mobile network type to the best available
3460 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3461 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003462 mPhone.setDataRoamingEnabled(false);
pkanwar79ec0542017-07-31 14:10:01 -07003463 // Remove IMSI encryption keys from Carrier DB.
3464 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003465 }
3466 } finally {
3467 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003468 }
3469 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003470
3471 @Override
3472 public String getLocaleFromDefaultSim() {
3473 // We query all subscriptions instead of just the active ones, because
3474 // this might be called early on in the provisioning flow when the
3475 // subscriptions potentially aren't active yet.
3476 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3477 if (slist == null || slist.isEmpty()) {
3478 return null;
3479 }
3480
3481 // This function may be called very early, say, from the setup wizard, at
3482 // which point we won't have a default subscription set. If that's the case
3483 // we just choose the first, which will be valid in "most cases".
3484 final int defaultSubId = getDefaultSubscription();
3485 SubscriptionInfo info = null;
3486 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3487 info = slist.get(0);
3488 } else {
3489 for (SubscriptionInfo item : slist) {
3490 if (item.getSubscriptionId() == defaultSubId) {
3491 info = item;
3492 break;
3493 }
3494 }
3495
3496 if (info == null) {
3497 return null;
3498 }
3499 }
3500
3501 // Try and fetch the locale from the carrier properties or from the SIM language
3502 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003503 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003504 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003505 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003506 if (defaultPhone != null) {
3507 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3508 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003509 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003510 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3511 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003512 } else {
3513 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003514 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003515 }
3516 }
3517
Narayan Kamath011676f2015-07-29 12:04:08 +01003518 // The SIM language preferences only store a language (e.g. fr = French), not an
3519 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3520 // the SIM and carrier preferences does not include a country we add the country
3521 // determined from the SIM MCC to provide an exact locale.
3522 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003523 if (mccLocale != null) {
3524 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3525 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003526 }
3527
Tony Hill183b2de2015-06-24 14:53:58 +01003528 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003529 return null;
3530 }
3531
3532 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 return mSubscriptionController.getAllSubInfoList(
3536 mPhone.getContext().getOpPackageName());
3537 } finally {
3538 Binder.restoreCallingIdentity(identity);
3539 }
3540 }
3541
3542 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 return mSubscriptionController.getActiveSubscriptionInfoList(
3546 mPhone.getContext().getOpPackageName());
3547 } finally {
3548 Binder.restoreCallingIdentity(identity);
3549 }
3550 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003551
Chenjie Yu1ba97252018-01-11 18:16:20 -08003552 private final ModemActivityInfo mLastModemActivityInfo =
3553 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3554
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003555 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003556 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3557 * representing the state of the modem.
3558 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003559 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3560 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003561 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003562 */
3563 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003564 public void requestModemActivityInfo(ResultReceiver result) {
3565 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003566 ModemActivityInfo ret = null;
3567 synchronized (mLastModemActivityInfo) {
3568 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3569 null);
3570 if (info != null) {
3571 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3572 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3573 mergedTxTimeMs[i] =
3574 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3575 }
3576 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3577 mLastModemActivityInfo.setSleepTimeMillis(
3578 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3579 mLastModemActivityInfo.setIdleTimeMillis(
3580 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3581 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3582 mLastModemActivityInfo.setRxTimeMillis(
3583 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3584 mLastModemActivityInfo.setEnergyUsed(
3585 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3586 }
3587 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3588 mLastModemActivityInfo.getSleepTimeMillis(),
3589 mLastModemActivityInfo.getIdleTimeMillis(),
3590 mLastModemActivityInfo.getTxTimeMillis(),
3591 mLastModemActivityInfo.getRxTimeMillis(),
3592 mLastModemActivityInfo.getEnergyUsed());
3593 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003594 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003595 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003596 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003597 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003598
3599 /**
3600 * {@hide}
3601 * Returns the service state information on specified subscription.
3602 */
3603 @Override
3604 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3605
Jeff Davidson7e17e312018-02-13 18:17:36 -08003606 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003607 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003608 return null;
3609 }
3610
3611 final Phone phone = getPhone(subId);
3612 if (phone == null) {
3613 return null;
3614 }
3615
3616 return phone.getServiceState();
3617 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003618
3619 /**
3620 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3621 *
3622 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3623 * voicemail ringtone.
3624 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3625 * PhoneAccount.
3626 */
3627 @Override
3628 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003629 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003630 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003631 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003632 }
3633
fionaxu7ed723d2017-05-30 18:58:54 -07003634 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003635 }
3636
3637 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003638 * Sets the per-account voicemail ringtone.
3639 *
3640 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3641 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3642 *
3643 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3644 * voicemail ringtone.
3645 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3646 * PhoneAccount.
3647 */
3648 @Override
3649 public void setVoicemailRingtoneUri(String callingPackage,
3650 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3651 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3652 if (!TextUtils.equals(callingPackage,
3653 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3655 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3656 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003657 }
3658 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3659 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003660 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003661 }
fionaxu7ed723d2017-05-30 18:58:54 -07003662 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003663 }
3664
3665 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003666 * Returns whether vibration is set for voicemail notification in Phone settings.
3667 *
3668 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3669 * voicemail vibration setting.
3670 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3671 */
3672 @Override
3673 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003674 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003675 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003676 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003677 }
3678
fionaxu7ed723d2017-05-30 18:58:54 -07003679 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003680 }
3681
Youhan Wange64578a2016-05-02 15:32:42 -07003682 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003683 * Sets the per-account voicemail vibration.
3684 *
3685 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3686 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3687 *
3688 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3689 * voicemail vibration setting.
3690 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3691 * specific PhoneAccount.
3692 */
3693 @Override
3694 public void setVoicemailVibrationEnabled(String callingPackage,
3695 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3696 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3697 if (!TextUtils.equals(callingPackage,
3698 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3700 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3701 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003702 }
3703
3704 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3705 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003706 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003707 }
fionaxu7ed723d2017-05-30 18:58:54 -07003708 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003709 }
3710
3711 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003712 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3713 *
3714 * @throws SecurityException if the caller does not have the required permission
3715 */
3716 private void enforceReadPrivilegedPermission() {
3717 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3718 null);
3719 }
3720
3721 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003722 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3723 * permission.
3724 *
3725 * @throws SecurityException if the caller does not have the required permission
3726 */
3727 private void enforceSendSmsPermission() {
3728 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3729 }
3730
3731 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003732 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003733 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003734 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003735 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003736 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003737 ComponentName componentName =
3738 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3739 if(componentName == null) {
3740 throw new SecurityException("Caller not current active visual voicemail package[null]");
3741 }
3742 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003743 if (!callingPackage.equals(vvmPackage)) {
3744 throw new SecurityException("Caller not current active visual voicemail package[" +
3745 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003746 }
3747 }
3748
3749 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003750 * Return the application ID for the app type.
3751 *
3752 * @param subId the subscription ID that this request applies to.
3753 * @param appType the uicc app type.
3754 * @return Application ID for specificied app type, or null if no uicc.
3755 */
3756 @Override
3757 public String getAidForAppType(int subId, int appType) {
3758 enforceReadPrivilegedPermission();
3759 Phone phone = getPhone(subId);
3760 if (phone == null) {
3761 return null;
3762 }
3763 String aid = null;
3764 try {
3765 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3766 .getApplicationByType(appType).getAid();
3767 } catch (Exception e) {
3768 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3769 }
3770 return aid;
3771 }
3772
Youhan Wang4001d252016-05-11 10:29:41 -07003773 /**
3774 * Return the Electronic Serial Number.
3775 *
3776 * @param subId the subscription ID that this request applies to.
3777 * @return ESN or null if error.
3778 */
3779 @Override
3780 public String getEsn(int subId) {
3781 enforceReadPrivilegedPermission();
3782 Phone phone = getPhone(subId);
3783 if (phone == null) {
3784 return null;
3785 }
3786 String esn = null;
3787 try {
3788 esn = phone.getEsn();
3789 } catch (Exception e) {
3790 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3791 }
3792 return esn;
3793 }
3794
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003795 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003796 * Return the Preferred Roaming List Version.
3797 *
3798 * @param subId the subscription ID that this request applies to.
3799 * @return PRLVersion or null if error.
3800 */
3801 @Override
3802 public String getCdmaPrlVersion(int subId) {
3803 enforceReadPrivilegedPermission();
3804 Phone phone = getPhone(subId);
3805 if (phone == null) {
3806 return null;
3807 }
3808 String cdmaPrlVersion = null;
3809 try {
3810 cdmaPrlVersion = phone.getCdmaPrlVersion();
3811 } catch (Exception e) {
3812 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3813 }
3814 return cdmaPrlVersion;
3815 }
3816
3817 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003818 * Get snapshot of Telephony histograms
3819 * @return List of Telephony histograms
3820 * @hide
3821 */
3822 @Override
3823 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3825 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003826 return RIL.getTelephonyRILTimingHistograms();
3827 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003828
3829 /**
3830 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003831 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003832 * Require system privileges. In the future we may add this to carrier APIs.
3833 *
3834 * @return The number of carriers set successfully, should match length of carriers
3835 */
3836 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003837 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003838 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003839
Meng Wang9b7c4e92017-02-17 11:41:27 -08003840 if (carriers == null) {
3841 throw new NullPointerException("carriers cannot be null");
3842 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003843
3844 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003845 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3846 return retVal[0];
3847 }
3848
3849 /**
3850 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003851 * Get 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 List of {@link android.service.telephony.CarrierIdentifier}; empty list
3855 * means all carriers are allowed.
3856 */
3857 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003858 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003859 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003860 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003861 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3862 }
3863
fionaxu59545b42016-05-25 15:53:37 -07003864 /**
3865 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3866 * @param subId the subscription ID that this action applies to.
3867 * @param enabled control enable or disable metered apns.
3868 * {@hide}
3869 */
3870 @Override
3871 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3872 enforceModifyPermission();
3873 final Phone phone = getPhone(subId);
3874 if (phone == null) {
3875 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3876 return;
3877 }
3878 try {
3879 phone.carrierActionSetMeteredApnsEnabled(enabled);
3880 } catch (Exception e) {
3881 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3882 }
3883 }
3884
3885 /**
3886 * Action set from carrier signalling broadcast receivers to enable/disable radio
3887 * @param subId the subscription ID that this action applies to.
3888 * @param enabled control enable or disable radio.
3889 * {@hide}
3890 */
3891 @Override
3892 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3893 enforceModifyPermission();
3894 final Phone phone = getPhone(subId);
3895 if (phone == null) {
3896 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3897 return;
3898 }
3899 try {
3900 phone.carrierActionSetRadioEnabled(enabled);
3901 } catch (Exception e) {
3902 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3903 }
3904 }
3905
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003906 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003907 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3908 * network status based on which carrier apps could apply actions accordingly,
3909 * enable/disable default url handler for example.
3910 *
3911 * @param subId the subscription ID that this action applies to.
3912 * @param report control start/stop reporting the default network status.
3913 * {@hide}
3914 */
3915 @Override
3916 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3917 enforceModifyPermission();
3918 final Phone phone = getPhone(subId);
3919 if (phone == null) {
3920 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3921 return;
3922 }
3923 try {
3924 phone.carrierActionReportDefaultNetworkStatus(report);
3925 } catch (Exception e) {
3926 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3927 }
3928 }
3929
3930 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003931 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3932 * bug report is being generated.
3933 */
3934 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003935 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003936 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3937 != PackageManager.PERMISSION_GRANTED) {
3938 writer.println("Permission Denial: can't dump Phone from pid="
3939 + Binder.getCallingPid()
3940 + ", uid=" + Binder.getCallingUid()
3941 + "without permission "
3942 + android.Manifest.permission.DUMP);
3943 return;
3944 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003945 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003946 }
Jack Yueb89b242016-06-22 13:27:47 -07003947
3948 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003949 * Get aggregated video call data usage since boot.
3950 *
3951 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3952 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003953 * {@hide}
3954 */
3955 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003956 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003957 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3958 null);
3959
Jack Yu84291ec2017-05-26 16:07:50 -07003960 // NetworkStatsService keeps tracking the active network interface and identity. It
3961 // records the delta with the corresponding network identity. We just return the total video
3962 // call data usage snapshot since boot.
3963 Phone phone = getPhone(subId);
3964 if (phone != null) {
3965 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003966 }
Jack Yu84291ec2017-05-26 16:07:50 -07003967 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003968 }
Jack Yu75ab2952016-07-08 14:29:33 -07003969
3970 /**
3971 * Policy control of data connection. Usually used when data limit is passed.
3972 * @param enabled True if enabling the data, otherwise disabling.
3973 * @param subId Subscription index
3974 * {@hide}
3975 */
3976 @Override
3977 public void setPolicyDataEnabled(boolean enabled, int subId) {
3978 enforceModifyPermission();
3979 Phone phone = getPhone(subId);
3980 if (phone != null) {
3981 phone.setPolicyDataEnabled(enabled);
3982 }
3983 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003984
3985 /**
3986 * Get Client request stats
3987 * @return List of Client Request Stats
3988 * @hide
3989 */
3990 @Override
3991 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003992 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003993 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003994 return null;
3995 }
3996
3997 Phone phone = getPhone(subId);
3998 if (phone != null) {
3999 return phone.getClientRequestStats();
4000 }
4001
4002 return null;
4003 }
4004
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004005 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004006 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004007 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004008 }
Jack Yueb4124c2017-02-16 15:32:43 -08004009
4010 /**
Grace Chen70990072017-03-24 17:21:30 -07004011 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004012 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004013 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004014 * @param state State of SIM (power down, power up, pass through)
4015 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4016 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4017 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004018 *
4019 **/
4020 @Override
Grace Chen70990072017-03-24 17:21:30 -07004021 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004022 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004023 Phone phone = PhoneFactory.getPhone(slotIndex);
4024
Jack Yueb4124c2017-02-16 15:32:43 -08004025 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004026 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004027 }
4028 }
Shuo Qiandd210312017-04-12 22:11:33 +00004029
Tyler Gunn65d45c22017-06-05 11:22:26 -07004030 private boolean isUssdApiAllowed(int subId) {
4031 CarrierConfigManager configManager =
4032 (CarrierConfigManager) mPhone.getContext().getSystemService(
4033 Context.CARRIER_CONFIG_SERVICE);
4034 if (configManager == null) {
4035 return false;
4036 }
4037 PersistableBundle pb = configManager.getConfigForSubId(subId);
4038 if (pb == null) {
4039 return false;
4040 }
4041 return pb.getBoolean(
4042 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4043 }
4044
Shuo Qiandd210312017-04-12 22:11:33 +00004045 /**
4046 * Check if phone is in emergency callback mode
4047 * @return true if phone is in emergency callback mode
4048 * @param subId sub id
4049 */
goneil9c5f4872017-12-05 14:07:56 -08004050 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004051 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004052 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004053 final Phone phone = getPhone(subId);
4054 if (phone != null) {
4055 return phone.isInEcm();
4056 } else {
4057 return false;
4058 }
4059 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004060
4061 /**
4062 * Get the current signal strength information for the given subscription.
4063 * Because this information is not updated when the device is in a low power state
4064 * it should not be relied-upon to be current.
4065 * @param subId Subscription index
4066 * @return the most recent cached signal strength info from the modem
4067 */
4068 @Override
4069 public SignalStrength getSignalStrength(int subId) {
4070 Phone p = getPhone(subId);
4071 if (p == null) {
4072 return null;
4073 }
4074
4075 return p.getSignalStrength();
4076 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004077
4078 @Override
4079 public UiccSlotInfo[] getUiccSlotsInfo() {
4080 enforceReadPrivilegedPermission();
4081
4082 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4083 if (slots == null) return null;
4084 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4085 for (int i = 0; i < slots.length; i++) {
4086 UiccSlot slot = slots[i];
4087
4088 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4089
4090 int cardState = 0;
4091 switch (slot.getCardState()) {
4092 case CARDSTATE_ABSENT:
4093 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4094 break;
4095 case CARDSTATE_PRESENT:
4096 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4097 break;
4098 case CARDSTATE_ERROR:
4099 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4100 break;
4101 case CARDSTATE_RESTRICTED:
4102 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4103 break;
4104 default:
4105 break;
4106
4107 }
4108
Qingxi Li795c5882018-01-31 13:43:27 -08004109 infos[i] = new UiccSlotInfo(
4110 slot.isActive(), slot.isEuicc(), cardId, cardState, slot.getPhoneId());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004111 }
4112 return infos;
4113 }
4114
4115 @Override
4116 public boolean switchSlots(int[] physicalSlots) {
4117 enforceModifyPermission();
4118 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4119 }
Jack Yu4c988042018-02-27 15:30:01 -08004120
4121 @Override
4122 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4123 enforceModifyPermission();
4124 final Phone phone = getPhone(subId);
4125 if (phone == null) {
4126 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4127 return;
4128 }
4129
4130 phone.setRadioIndicationUpdateMode(filters, mode);
4131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004132}