blob: 16996c0bfba50dd1112081eccabcd89dfd7c921b [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
Brad Ebinger304415d2018-03-02 13:43:36 -08002712 /**
2713 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2714 * available, false if the IMS resolver is idle.
2715 */
2716 public boolean isResolvingImsBinding() {
2717 enforceModifyPermission();
2718 return PhoneFactory.getImsResolver().isResolvingBinding();
2719 }
2720
Wink Saville36469e72014-06-11 15:17:00 -07002721 public void setImsRegistrationState(boolean registered) {
2722 enforceModifyPermission();
2723 mPhone.setImsRegistrationState(registered);
2724 }
2725
2726 /**
Stuart Scott54788802015-03-30 13:18:01 -07002727 * Set the network selection mode to automatic.
2728 *
2729 */
2730 @Override
2731 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2733 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002734 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2735 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2736 }
2737
2738 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002739 * Set the network selection mode to manual with the selected carrier.
2740 */
2741 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002742 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002743 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2745 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002746 OperatorInfo operator = new OperatorInfo(
2747 /* operatorAlphaLong */ "",
2748 /* operatorAlphaShort */ "",
2749 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002750 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002751 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2752 persistSelection);
2753 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002754 }
2755
2756 /**
2757 * Scans for available networks.
2758 */
2759 @Override
2760 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002761 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2762 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002763 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2764 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2765 CMD_PERFORM_NETWORK_SCAN, null, subId);
2766 return result;
2767 }
2768
2769 /**
yinxub1bed742017-04-17 11:45:04 -07002770 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002771 *
yinxub1bed742017-04-17 11:45:04 -07002772 * @param subId id of the subscription
2773 * @param request contains the radio access networks with bands/channels to scan
2774 * @param messenger callback messenger for scan results or errors
2775 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002776 * @return the id of the requested scan which can be used to stop the scan.
2777 */
2778 @Override
2779 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2780 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2782 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002783 return mNetworkScanRequestTracker.startNetworkScan(
2784 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002785 }
2786
2787 /**
2788 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002789 *
2790 * @param subId id of the subscription
2791 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002792 */
2793 @Override
2794 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2796 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002797 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002798 }
2799
2800 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002801 * Get the calculated preferred network type.
2802 * Used for debugging incorrect network type.
2803 *
2804 * @return the preferred network type, defined in RILConstants.java.
2805 */
2806 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002807 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002808 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002809 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002810 return RILConstants.PREFERRED_NETWORK_MODE;
2811 }
2812
Amit Mahajan43330e02014-11-18 11:54:45 -08002813 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002814 }
2815
2816 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002817 * Get the preferred network type.
2818 * Used for device configuration by some CDMA operators.
2819 *
2820 * @return the preferred network type, defined in RILConstants.java.
2821 */
2822 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002823 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2825 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002826 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002827 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002828 int networkType = (result != null ? result[0] : -1);
2829 if (DBG) log("getPreferredNetworkType: " + networkType);
2830 return networkType;
2831 }
2832
2833 /**
2834 * Set the preferred network type.
2835 * Used for device configuration by some CDMA operators.
2836 *
2837 * @param networkType the preferred network type, defined in RILConstants.java.
2838 * @return true on success; false on any failure.
2839 */
2840 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002841 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2843 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002844 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2845 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002846 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002847 if (success) {
2848 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002849 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002850 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002851 return success;
2852 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002853
2854 /**
Junda Liu475951f2014-11-07 16:45:03 -08002855 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2856 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2857 * tethering.
2858 *
2859 * @return 0: Not required. 1: required. 2: Not set.
2860 * @hide
2861 */
2862 @Override
2863 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002864 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002865 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2866 Settings.Global.TETHER_DUN_REQUIRED, 2);
2867 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2868 // config_tether_apndata.
2869 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2870 dunRequired = 1;
2871 }
2872 return dunRequired;
2873 }
2874
2875 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002876 * Set mobile data enabled
2877 * Used by the user through settings etc to turn on/off mobile data
2878 *
2879 * @param enable {@code true} turn turn data on, else {@code false}
2880 */
2881 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002882 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2884 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002885 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002886 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002887 Phone phone = PhoneFactory.getPhone(phoneId);
2888 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002889 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2890 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002891 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002892 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002893 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002894 }
2895
2896 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002897 * Get the user enabled state of Mobile Data.
2898 *
2899 * TODO: remove and use isUserDataEnabled.
2900 * This can't be removed now because some vendor codes
2901 * calls through ITelephony directly while they should
2902 * use TelephonyManager.
2903 *
2904 * @return true on enabled
2905 */
2906 @Override
2907 public boolean getDataEnabled(int subId) {
2908 return isUserDataEnabled(subId);
2909 }
2910
2911 /**
2912 * Get whether mobile data is enabled per user setting.
2913 *
2914 * There are other factors deciding whether mobile data is actually enabled, but they are
2915 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002916 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002917 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002918 *
2919 * @return {@code true} if data is enabled else {@code false}
2920 */
2921 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002922 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002923 try {
2924 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2925 null);
2926 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2928 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002929 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002930 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002931 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002932 Phone phone = PhoneFactory.getPhone(phoneId);
2933 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002934 boolean retVal = phone.isUserDataEnabled();
2935 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002936 return retVal;
2937 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002938 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2939 return false;
2940 }
2941 }
2942
2943 /**
2944 * Get whether mobile data is enabled.
2945 *
2946 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2947 * whether mobile data is actually enabled.
2948 *
2949 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2950 *
2951 * @return {@code true} if data is enabled else {@code false}
2952 */
2953 @Override
2954 public boolean isDataEnabled(int subId) {
2955 try {
2956 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2957 null);
2958 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2960 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08002961 }
2962 int phoneId = mSubscriptionController.getPhoneId(subId);
2963 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2964 Phone phone = PhoneFactory.getPhone(phoneId);
2965 if (phone != null) {
2966 boolean retVal = phone.isDataEnabled();
2967 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2968 return retVal;
2969 } else {
2970 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002971 return false;
2972 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002973 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002974
2975 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002976 public int getCarrierPrivilegeStatus(int subId) {
2977 final Phone phone = getPhone(subId);
2978 if (phone == null) {
2979 loge("getCarrierPrivilegeStatus: Invalid subId");
2980 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2981 }
2982 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002983 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002984 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002985 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2986 }
2987 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002988 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002989 }
Junda Liu29340342014-07-10 15:23:27 -07002990
2991 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08002992 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
2993 final Phone phone = getPhone(subId);
2994 if (phone == null) {
2995 loge("getCarrierPrivilegeStatus: Invalid subId");
2996 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2997 }
2998 UiccProfile profile =
2999 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3000 if (profile == null) {
3001 loge("getCarrierPrivilegeStatus: No UICC");
3002 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3003 }
3004 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3005 }
3006
3007 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003008 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003009 if (TextUtils.isEmpty(pkgName))
3010 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003011 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003012 if (card == null) {
3013 loge("checkCarrierPrivilegesForPackage: No UICC");
3014 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3015 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003016 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3017 }
3018
3019 @Override
3020 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003021 if (TextUtils.isEmpty(pkgName))
3022 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003023 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3024 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3025 UiccCard card = UiccController.getInstance().getUiccCard(i);
3026 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003027 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003028 continue;
3029 }
3030
3031 result = card.getCarrierPrivilegeStatus(
3032 mPhone.getContext().getPackageManager(), pkgName);
3033 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3034 break;
3035 }
3036 }
3037
3038 return result;
Junda Liu29340342014-07-10 15:23:27 -07003039 }
Derek Tan89e89d42014-07-08 17:00:10 -07003040
3041 @Override
Junda Liue64de782015-04-16 17:19:16 -07003042 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3043 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3044 loge("phoneId " + phoneId + " is not valid.");
3045 return null;
3046 }
3047 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003048 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003049 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003050 return null ;
3051 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003052 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003053 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003054 }
3055
Amith Yamasani6e118872016-02-19 12:53:51 -08003056 @Override
3057 public List<String> getPackagesWithCarrierPrivileges() {
3058 PackageManager pm = mPhone.getContext().getPackageManager();
3059 List<String> privilegedPackages = new ArrayList<>();
3060 List<PackageInfo> packages = null;
3061 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3062 UiccCard card = UiccController.getInstance().getUiccCard(i);
3063 if (card == null) {
3064 // No UICC in that slot.
3065 continue;
3066 }
3067 if (card.hasCarrierPrivilegeRules()) {
3068 if (packages == null) {
3069 // Only check packages in user 0 for now
3070 packages = pm.getInstalledPackagesAsUser(
3071 PackageManager.MATCH_DISABLED_COMPONENTS
3072 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3073 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3074 }
3075 for (int p = packages.size() - 1; p >= 0; p--) {
3076 PackageInfo pkgInfo = packages.get(p);
3077 if (pkgInfo != null && pkgInfo.packageName != null
3078 && card.getCarrierPrivilegeStatus(pkgInfo)
3079 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3080 privilegedPackages.add(pkgInfo.packageName);
3081 }
3082 }
3083 }
3084 }
3085 return privilegedPackages;
3086 }
3087
Wink Savilleb564aae2014-10-23 10:18:09 -07003088 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003089 final Phone phone = getPhone(subId);
3090 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003091 if (card == null) {
3092 loge("getIccId: No UICC");
3093 return null;
3094 }
3095 String iccId = card.getIccId();
3096 if (TextUtils.isEmpty(iccId)) {
3097 loge("getIccId: ICC ID is null or empty.");
3098 return null;
3099 }
3100 return iccId;
3101 }
3102
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003103 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003104 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3105 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003106 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3107 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003108
Jeff Sharkey85190e62014-12-05 09:40:12 -08003109 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003110 final Phone phone = getPhone(subId);
3111 if (phone == null) {
3112 return false;
3113 }
3114 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003115
3116 if (DBG_MERGE) {
3117 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3118 + subscriberId + " to " + number);
3119 }
3120
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003121 if (TextUtils.isEmpty(iccId)) {
3122 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003123 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003124
Jeff Sharkey85190e62014-12-05 09:40:12 -08003125 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3126
3127 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003128 if (alphaTag == null) {
3129 editor.remove(alphaTagPrefKey);
3130 } else {
3131 editor.putString(alphaTagPrefKey, alphaTag);
3132 }
3133
Jeff Sharkey85190e62014-12-05 09:40:12 -08003134 // Record both the line number and IMSI for this ICCID, since we need to
3135 // track all merged IMSIs based on line number
3136 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3137 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003138 if (number == null) {
3139 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003140 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003141 } else {
3142 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003143 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003144 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003145
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003146 editor.commit();
3147 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003148 }
3149
3150 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003151 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003152 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003153 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08003154 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003155 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003156 return null;
3157 }
Derek Tan97ebb422014-09-05 16:55:38 -07003158
3159 String iccId = getIccId(subId);
3160 if (iccId != null) {
3161 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003162 if (DBG_MERGE) {
3163 log("getLine1NumberForDisplay returning " +
3164 mTelephonySharedPreferences.getString(numberPrefKey, null));
3165 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003166 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003167 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003168 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003169 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003170 }
3171
3172 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003173 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003174 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003175 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003176 return null;
3177 }
Derek Tan97ebb422014-09-05 16:55:38 -07003178
3179 String iccId = getIccId(subId);
3180 if (iccId != null) {
3181 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003182 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003183 }
Derek Tan97ebb422014-09-05 16:55:38 -07003184 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003185 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003186
3187 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003188 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003189 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3190 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003192 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3193 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003194 return null;
3195 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003196 final Context context = mPhone.getContext();
3197 final TelephonyManager tele = TelephonyManager.from(context);
3198 final SubscriptionManager sub = SubscriptionManager.from(context);
3199
3200 // Figure out what subscribers are currently active
3201 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003202 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3203 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 final int[] subIds = sub.getActiveSubscriptionIdList();
3207 for (int subId : subIds) {
3208 activeSubscriberIds.add(tele.getSubscriberId(subId));
3209 }
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003212 }
3213
3214 // First pass, find a number override for an active subscriber
3215 String mergeNumber = null;
3216 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3217 for (String key : prefs.keySet()) {
3218 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3219 final String subscriberId = (String) prefs.get(key);
3220 if (activeSubscriberIds.contains(subscriberId)) {
3221 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3222 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3223 mergeNumber = (String) prefs.get(numberKey);
3224 if (DBG_MERGE) {
3225 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3226 + " for active subscriber " + subscriberId);
3227 }
3228 if (!TextUtils.isEmpty(mergeNumber)) {
3229 break;
3230 }
3231 }
3232 }
3233 }
3234
3235 // Shortcut when no active merged subscribers
3236 if (TextUtils.isEmpty(mergeNumber)) {
3237 return null;
3238 }
3239
3240 // Second pass, find all subscribers under that line override
3241 final ArraySet<String> result = new ArraySet<>();
3242 for (String key : prefs.keySet()) {
3243 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3244 final String number = (String) prefs.get(key);
3245 if (mergeNumber.equals(number)) {
3246 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3247 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3248 final String subscriberId = (String) prefs.get(subscriberKey);
3249 if (!TextUtils.isEmpty(subscriberId)) {
3250 result.add(subscriberId);
3251 }
3252 }
3253 }
3254 }
3255
3256 final String[] resultArray = result.toArray(new String[result.size()]);
3257 Arrays.sort(resultArray);
3258 if (DBG_MERGE) {
3259 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3260 }
3261 return resultArray;
3262 }
3263
3264 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003265 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003266 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3267 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003268 final Phone phone = getPhone(subId);
3269 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003270 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003271
3272 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003273 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003274 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3275 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003276 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003277 final Phone phone = getPhone(subId);
3278 if (phone == null) {
3279 return false;
3280 }
3281 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003282 cdmaNonRoamingList);
3283 }
3284
3285 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003286 public void setRadioCapability(RadioAccessFamily[] rafs) {
3287 try {
3288 ProxyController.getInstance().setRadioCapability(rafs);
3289 } catch (RuntimeException e) {
3290 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3291 }
3292 }
3293
3294 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003295 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003296 Phone phone = PhoneFactory.getPhone(phoneId);
3297 if (phone == null) {
3298 return RadioAccessFamily.RAF_UNKNOWN;
3299 }
3300 int subId = phone.getSubId();
Jeff Davidson7e17e312018-02-13 18:17:36 -08003301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003302 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003303 return RadioAccessFamily.RAF_UNKNOWN;
3304 }
3305
Wink Saville5d475dd2014-10-17 15:00:58 -07003306 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3307 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003308
3309 @Override
3310 public void enableVideoCalling(boolean enable) {
3311 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003312 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003313 }
3314
3315 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003316 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003318 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003319 return false;
3320 }
3321
Andrew Lee77527ac2014-10-21 16:57:39 -07003322 // Check the user preference and the system-level IMS setting. Even if the user has
3323 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3324 // In the long run, we may instead need to check if there exists a connection service
3325 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003326 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3327 return imsManager.isVtEnabledByPlatform()
3328 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3329 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003330 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003331
Andrew Leea1239f22015-03-02 17:44:07 -08003332 @Override
3333 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003334 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003335 }
3336
3337 @Override
3338 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003339 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003340 }
3341
Andrew Lee9431b832015-03-09 18:46:45 -07003342 @Override
3343 public boolean isTtyModeSupported() {
3344 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3345 TelephonyManager telephonyManager =
3346 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003347 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003348 }
3349
3350 @Override
3351 public boolean isHearingAidCompatibilitySupported() {
3352 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3353 }
3354
Hall Liu98187582018-01-22 19:15:32 -08003355 public boolean isRttSupported() {
3356 boolean isCarrierSupported =
3357 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3358 boolean isDeviceSupported =
3359 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3360 return isCarrierSupported && isDeviceSupported;
3361 }
3362
Sanket Padawe7310cc72015-01-14 09:53:20 -08003363 /**
3364 * Returns the unique device ID of phone, for example, the IMEI for
3365 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3366 *
3367 * <p>Requires Permission:
3368 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3369 */
3370 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003371 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003372 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08003373 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003374 return null;
3375 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003376 int subId = phone.getSubId();
3377 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3378 mApp, subId, callingPackage, "getDeviceId")) {
3379 return null;
3380 }
3381 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003382 }
3383
Ping Sunc67b7c22016-03-02 19:16:45 +08003384 /**
3385 * {@hide}
3386 * Returns the IMS Registration Status on a particular subid
3387 *
3388 * @param subId
3389 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003390 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003391 Phone phone = getPhone(subId);
3392 if (phone != null) {
3393 return phone.isImsRegistered();
3394 } else {
3395 return false;
3396 }
3397 }
3398
Santos Cordon7a1885b2015-02-03 11:15:19 -08003399 @Override
3400 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3401 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3402 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003403
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003404 /**
3405 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003406 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003407 public boolean isWifiCallingAvailable(int subId) {
3408 Phone phone = getPhone(subId);
3409 if (phone != null) {
3410 return phone.isWifiCallingEnabled();
3411 } else {
3412 return false;
3413 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003414 }
3415
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003416 /**
3417 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003418 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003419 public boolean isVolteAvailable(int subId) {
3420 Phone phone = getPhone(subId);
3421 if (phone != null) {
3422 return phone.isVolteEnabled();
3423 } else {
3424 return false;
3425 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003426 }
Svet Ganovb320e182015-04-16 12:30:10 -07003427
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003428 /**
3429 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003430 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003431 public boolean isVideoTelephonyAvailable(int subId) {
3432 Phone phone = getPhone(subId);
3433 if (phone != null) {
3434 return phone.isVideoEnabled();
3435 } else {
3436 return false;
3437 }
3438 }
3439
3440 /**
3441 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3442 * defined in {@link ImsRegistrationImplBase}.
3443 */
3444 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3445 Phone phone = getPhone(subId);
3446 if (phone != null) {
3447 return phone.getImsRegistrationTech();
3448 } else {
3449 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3450 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003451 }
3452
Stuart Scott8eef64f2015-04-08 15:13:54 -07003453 @Override
3454 public void factoryReset(int subId) {
3455 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003456 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3457 return;
3458 }
3459
Svet Ganovcc087f82015-05-12 20:35:54 -07003460 final long identity = Binder.clearCallingIdentity();
3461 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003462 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3463 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003464 // Enable data
Malcolm Chen964682d2017-11-28 16:20:07 -08003465 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003466 // Set network selection mode to automatic
3467 setNetworkSelectionModeAutomatic(subId);
3468 // Set preferred mobile network type to the best available
Kitta Koutarou792ba1c2018-03-05 14:16:45 +09003469 String defaultNetwork = TelephonyManager.getTelephonyProperty(
3470 mSubscriptionController.getPhoneId(subId),
3471 "ro.telephony.default_network",
3472 null);
3473 int networkType = !TextUtils.isEmpty(defaultNetwork)
3474 ? Integer.parseInt(defaultNetwork) : Phone.PREFERRED_NT_MODE;
3475 setPreferredNetworkType(subId, networkType);
Svet Ganovcc087f82015-05-12 20:35:54 -07003476 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003477 mPhone.setDataRoamingEnabled(false);
pkanwar79ec0542017-07-31 14:10:01 -07003478 // Remove IMSI encryption keys from Carrier DB.
3479 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003480 }
3481 } finally {
3482 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003483 }
3484 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003485
3486 @Override
3487 public String getLocaleFromDefaultSim() {
3488 // We query all subscriptions instead of just the active ones, because
3489 // this might be called early on in the provisioning flow when the
3490 // subscriptions potentially aren't active yet.
3491 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3492 if (slist == null || slist.isEmpty()) {
3493 return null;
3494 }
3495
3496 // This function may be called very early, say, from the setup wizard, at
3497 // which point we won't have a default subscription set. If that's the case
3498 // we just choose the first, which will be valid in "most cases".
3499 final int defaultSubId = getDefaultSubscription();
3500 SubscriptionInfo info = null;
3501 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3502 info = slist.get(0);
3503 } else {
3504 for (SubscriptionInfo item : slist) {
3505 if (item.getSubscriptionId() == defaultSubId) {
3506 info = item;
3507 break;
3508 }
3509 }
3510
3511 if (info == null) {
3512 return null;
3513 }
3514 }
3515
3516 // Try and fetch the locale from the carrier properties or from the SIM language
3517 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003518 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003519 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003520 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003521 if (defaultPhone != null) {
3522 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3523 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003524 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003525 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3526 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003527 } else {
3528 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003529 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003530 }
3531 }
3532
Narayan Kamath011676f2015-07-29 12:04:08 +01003533 // The SIM language preferences only store a language (e.g. fr = French), not an
3534 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3535 // the SIM and carrier preferences does not include a country we add the country
3536 // determined from the SIM MCC to provide an exact locale.
3537 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003538 if (mccLocale != null) {
3539 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3540 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003541 }
3542
Tony Hill183b2de2015-06-24 14:53:58 +01003543 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003544 return null;
3545 }
3546
3547 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 return mSubscriptionController.getAllSubInfoList(
3551 mPhone.getContext().getOpPackageName());
3552 } finally {
3553 Binder.restoreCallingIdentity(identity);
3554 }
3555 }
3556
3557 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3558 final long identity = Binder.clearCallingIdentity();
3559 try {
3560 return mSubscriptionController.getActiveSubscriptionInfoList(
3561 mPhone.getContext().getOpPackageName());
3562 } finally {
3563 Binder.restoreCallingIdentity(identity);
3564 }
3565 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003566
Chenjie Yu1ba97252018-01-11 18:16:20 -08003567 private final ModemActivityInfo mLastModemActivityInfo =
3568 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3569
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003570 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003571 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3572 * representing the state of the modem.
3573 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003574 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3575 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003576 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003577 */
3578 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003579 public void requestModemActivityInfo(ResultReceiver result) {
3580 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003581 ModemActivityInfo ret = null;
3582 synchronized (mLastModemActivityInfo) {
3583 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3584 null);
3585 if (info != null) {
3586 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3587 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3588 mergedTxTimeMs[i] =
3589 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3590 }
3591 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3592 mLastModemActivityInfo.setSleepTimeMillis(
3593 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3594 mLastModemActivityInfo.setIdleTimeMillis(
3595 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3596 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3597 mLastModemActivityInfo.setRxTimeMillis(
3598 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3599 mLastModemActivityInfo.setEnergyUsed(
3600 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3601 }
3602 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3603 mLastModemActivityInfo.getSleepTimeMillis(),
3604 mLastModemActivityInfo.getIdleTimeMillis(),
3605 mLastModemActivityInfo.getTxTimeMillis(),
3606 mLastModemActivityInfo.getRxTimeMillis(),
3607 mLastModemActivityInfo.getEnergyUsed());
3608 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003609 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003610 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003611 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003612 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003613
3614 /**
3615 * {@hide}
3616 * Returns the service state information on specified subscription.
3617 */
3618 @Override
3619 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3620
Jeff Davidson7e17e312018-02-13 18:17:36 -08003621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003622 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003623 return null;
3624 }
3625
3626 final Phone phone = getPhone(subId);
3627 if (phone == null) {
3628 return null;
3629 }
3630
3631 return phone.getServiceState();
3632 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003633
3634 /**
3635 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3636 *
3637 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3638 * voicemail ringtone.
3639 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3640 * PhoneAccount.
3641 */
3642 @Override
3643 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003644 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003645 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003646 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003647 }
3648
fionaxu7ed723d2017-05-30 18:58:54 -07003649 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003650 }
3651
3652 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003653 * Sets the per-account voicemail ringtone.
3654 *
3655 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3656 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3657 *
3658 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3659 * voicemail ringtone.
3660 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3661 * PhoneAccount.
3662 */
3663 @Override
3664 public void setVoicemailRingtoneUri(String callingPackage,
3665 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3666 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3667 if (!TextUtils.equals(callingPackage,
3668 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3670 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3671 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003672 }
3673 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3674 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003675 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003676 }
fionaxu7ed723d2017-05-30 18:58:54 -07003677 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003678 }
3679
3680 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003681 * Returns whether vibration is set for voicemail notification in Phone settings.
3682 *
3683 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3684 * voicemail vibration setting.
3685 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3686 */
3687 @Override
3688 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003689 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003690 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003691 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003692 }
3693
fionaxu7ed723d2017-05-30 18:58:54 -07003694 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003695 }
3696
Youhan Wange64578a2016-05-02 15:32:42 -07003697 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003698 * Sets the per-account voicemail vibration.
3699 *
3700 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3701 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3702 *
3703 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3704 * voicemail vibration setting.
3705 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3706 * specific PhoneAccount.
3707 */
3708 @Override
3709 public void setVoicemailVibrationEnabled(String callingPackage,
3710 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3711 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3712 if (!TextUtils.equals(callingPackage,
3713 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3715 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3716 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003717 }
3718
3719 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3720 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003721 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003722 }
fionaxu7ed723d2017-05-30 18:58:54 -07003723 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003724 }
3725
3726 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003727 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3728 *
3729 * @throws SecurityException if the caller does not have the required permission
3730 */
3731 private void enforceReadPrivilegedPermission() {
3732 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3733 null);
3734 }
3735
3736 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003737 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3738 * permission.
3739 *
3740 * @throws SecurityException if the caller does not have the required permission
3741 */
3742 private void enforceSendSmsPermission() {
3743 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3744 }
3745
3746 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003747 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003748 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003749 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003750 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003751 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003752 ComponentName componentName =
3753 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3754 if(componentName == null) {
3755 throw new SecurityException("Caller not current active visual voicemail package[null]");
3756 }
3757 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003758 if (!callingPackage.equals(vvmPackage)) {
3759 throw new SecurityException("Caller not current active visual voicemail package[" +
3760 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003761 }
3762 }
3763
3764 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003765 * Return the application ID for the app type.
3766 *
3767 * @param subId the subscription ID that this request applies to.
3768 * @param appType the uicc app type.
3769 * @return Application ID for specificied app type, or null if no uicc.
3770 */
3771 @Override
3772 public String getAidForAppType(int subId, int appType) {
3773 enforceReadPrivilegedPermission();
3774 Phone phone = getPhone(subId);
3775 if (phone == null) {
3776 return null;
3777 }
3778 String aid = null;
3779 try {
3780 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3781 .getApplicationByType(appType).getAid();
3782 } catch (Exception e) {
3783 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3784 }
3785 return aid;
3786 }
3787
Youhan Wang4001d252016-05-11 10:29:41 -07003788 /**
3789 * Return the Electronic Serial Number.
3790 *
3791 * @param subId the subscription ID that this request applies to.
3792 * @return ESN or null if error.
3793 */
3794 @Override
3795 public String getEsn(int subId) {
3796 enforceReadPrivilegedPermission();
3797 Phone phone = getPhone(subId);
3798 if (phone == null) {
3799 return null;
3800 }
3801 String esn = null;
3802 try {
3803 esn = phone.getEsn();
3804 } catch (Exception e) {
3805 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3806 }
3807 return esn;
3808 }
3809
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003810 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003811 * Return the Preferred Roaming List Version.
3812 *
3813 * @param subId the subscription ID that this request applies to.
3814 * @return PRLVersion or null if error.
3815 */
3816 @Override
3817 public String getCdmaPrlVersion(int subId) {
3818 enforceReadPrivilegedPermission();
3819 Phone phone = getPhone(subId);
3820 if (phone == null) {
3821 return null;
3822 }
3823 String cdmaPrlVersion = null;
3824 try {
3825 cdmaPrlVersion = phone.getCdmaPrlVersion();
3826 } catch (Exception e) {
3827 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3828 }
3829 return cdmaPrlVersion;
3830 }
3831
3832 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003833 * Get snapshot of Telephony histograms
3834 * @return List of Telephony histograms
3835 * @hide
3836 */
3837 @Override
3838 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3840 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003841 return RIL.getTelephonyRILTimingHistograms();
3842 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003843
3844 /**
3845 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003846 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003847 * Require system privileges. In the future we may add this to carrier APIs.
3848 *
3849 * @return The number of carriers set successfully, should match length of carriers
3850 */
3851 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003852 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003853 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003854
Meng Wang9b7c4e92017-02-17 11:41:27 -08003855 if (carriers == null) {
3856 throw new NullPointerException("carriers cannot be null");
3857 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003858
3859 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003860 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3861 return retVal[0];
3862 }
3863
3864 /**
3865 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003866 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003867 * Require system privileges. In the future we may add this to carrier APIs.
3868 *
3869 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3870 * means all carriers are allowed.
3871 */
3872 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003873 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003874 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003875 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003876 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3877 }
3878
fionaxu59545b42016-05-25 15:53:37 -07003879 /**
3880 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3881 * @param subId the subscription ID that this action applies to.
3882 * @param enabled control enable or disable metered apns.
3883 * {@hide}
3884 */
3885 @Override
3886 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3887 enforceModifyPermission();
3888 final Phone phone = getPhone(subId);
3889 if (phone == null) {
3890 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3891 return;
3892 }
3893 try {
3894 phone.carrierActionSetMeteredApnsEnabled(enabled);
3895 } catch (Exception e) {
3896 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3897 }
3898 }
3899
3900 /**
3901 * Action set from carrier signalling broadcast receivers to enable/disable radio
3902 * @param subId the subscription ID that this action applies to.
3903 * @param enabled control enable or disable radio.
3904 * {@hide}
3905 */
3906 @Override
3907 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3908 enforceModifyPermission();
3909 final Phone phone = getPhone(subId);
3910 if (phone == null) {
3911 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3912 return;
3913 }
3914 try {
3915 phone.carrierActionSetRadioEnabled(enabled);
3916 } catch (Exception e) {
3917 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3918 }
3919 }
3920
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003921 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003922 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3923 * network status based on which carrier apps could apply actions accordingly,
3924 * enable/disable default url handler for example.
3925 *
3926 * @param subId the subscription ID that this action applies to.
3927 * @param report control start/stop reporting the default network status.
3928 * {@hide}
3929 */
3930 @Override
3931 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3932 enforceModifyPermission();
3933 final Phone phone = getPhone(subId);
3934 if (phone == null) {
3935 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3936 return;
3937 }
3938 try {
3939 phone.carrierActionReportDefaultNetworkStatus(report);
3940 } catch (Exception e) {
3941 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3942 }
3943 }
3944
3945 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003946 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3947 * bug report is being generated.
3948 */
3949 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003950 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003951 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3952 != PackageManager.PERMISSION_GRANTED) {
3953 writer.println("Permission Denial: can't dump Phone from pid="
3954 + Binder.getCallingPid()
3955 + ", uid=" + Binder.getCallingUid()
3956 + "without permission "
3957 + android.Manifest.permission.DUMP);
3958 return;
3959 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003960 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003961 }
Jack Yueb89b242016-06-22 13:27:47 -07003962
3963 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003964 * Get aggregated video call data usage since boot.
3965 *
3966 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3967 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003968 * {@hide}
3969 */
3970 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003971 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003972 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3973 null);
3974
Jack Yu84291ec2017-05-26 16:07:50 -07003975 // NetworkStatsService keeps tracking the active network interface and identity. It
3976 // records the delta with the corresponding network identity. We just return the total video
3977 // call data usage snapshot since boot.
3978 Phone phone = getPhone(subId);
3979 if (phone != null) {
3980 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003981 }
Jack Yu84291ec2017-05-26 16:07:50 -07003982 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003983 }
Jack Yu75ab2952016-07-08 14:29:33 -07003984
3985 /**
3986 * Policy control of data connection. Usually used when data limit is passed.
3987 * @param enabled True if enabling the data, otherwise disabling.
3988 * @param subId Subscription index
3989 * {@hide}
3990 */
3991 @Override
3992 public void setPolicyDataEnabled(boolean enabled, int subId) {
3993 enforceModifyPermission();
3994 Phone phone = getPhone(subId);
3995 if (phone != null) {
3996 phone.setPolicyDataEnabled(enabled);
3997 }
3998 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003999
4000 /**
4001 * Get Client request stats
4002 * @return List of Client Request Stats
4003 * @hide
4004 */
4005 @Override
4006 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004007 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004008 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004009 return null;
4010 }
4011
4012 Phone phone = getPhone(subId);
4013 if (phone != null) {
4014 return phone.getClientRequestStats();
4015 }
4016
4017 return null;
4018 }
4019
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004020 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004021 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00004022 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004023 }
Jack Yueb4124c2017-02-16 15:32:43 -08004024
4025 /**
Grace Chen70990072017-03-24 17:21:30 -07004026 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004027 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004028 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004029 * @param state State of SIM (power down, power up, pass through)
4030 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4031 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4032 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004033 *
4034 **/
4035 @Override
Grace Chen70990072017-03-24 17:21:30 -07004036 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004037 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004038 Phone phone = PhoneFactory.getPhone(slotIndex);
4039
Jack Yueb4124c2017-02-16 15:32:43 -08004040 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004041 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004042 }
4043 }
Shuo Qiandd210312017-04-12 22:11:33 +00004044
Tyler Gunn65d45c22017-06-05 11:22:26 -07004045 private boolean isUssdApiAllowed(int subId) {
4046 CarrierConfigManager configManager =
4047 (CarrierConfigManager) mPhone.getContext().getSystemService(
4048 Context.CARRIER_CONFIG_SERVICE);
4049 if (configManager == null) {
4050 return false;
4051 }
4052 PersistableBundle pb = configManager.getConfigForSubId(subId);
4053 if (pb == null) {
4054 return false;
4055 }
4056 return pb.getBoolean(
4057 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4058 }
4059
Shuo Qiandd210312017-04-12 22:11:33 +00004060 /**
4061 * Check if phone is in emergency callback mode
4062 * @return true if phone is in emergency callback mode
4063 * @param subId sub id
4064 */
goneil9c5f4872017-12-05 14:07:56 -08004065 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004066 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004067 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004068 final Phone phone = getPhone(subId);
4069 if (phone != null) {
4070 return phone.isInEcm();
4071 } else {
4072 return false;
4073 }
4074 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004075
4076 /**
4077 * Get the current signal strength information for the given subscription.
4078 * Because this information is not updated when the device is in a low power state
4079 * it should not be relied-upon to be current.
4080 * @param subId Subscription index
4081 * @return the most recent cached signal strength info from the modem
4082 */
4083 @Override
4084 public SignalStrength getSignalStrength(int subId) {
4085 Phone p = getPhone(subId);
4086 if (p == null) {
4087 return null;
4088 }
4089
4090 return p.getSignalStrength();
4091 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004092
4093 @Override
4094 public UiccSlotInfo[] getUiccSlotsInfo() {
4095 enforceReadPrivilegedPermission();
4096
4097 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4098 if (slots == null) return null;
4099 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4100 for (int i = 0; i < slots.length; i++) {
4101 UiccSlot slot = slots[i];
4102
4103 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4104
4105 int cardState = 0;
4106 switch (slot.getCardState()) {
4107 case CARDSTATE_ABSENT:
4108 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4109 break;
4110 case CARDSTATE_PRESENT:
4111 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4112 break;
4113 case CARDSTATE_ERROR:
4114 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4115 break;
4116 case CARDSTATE_RESTRICTED:
4117 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4118 break;
4119 default:
4120 break;
4121
4122 }
4123
Qingxi Li795c5882018-01-31 13:43:27 -08004124 infos[i] = new UiccSlotInfo(
Qingxi Lie7245372018-03-07 10:52:26 -08004125 slot.isActive(),
4126 slot.isEuicc(),
4127 cardId,
4128 cardState,
4129 slot.getPhoneId(),
4130 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004131 }
4132 return infos;
4133 }
4134
4135 @Override
4136 public boolean switchSlots(int[] physicalSlots) {
4137 enforceModifyPermission();
4138 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4139 }
Jack Yu4c988042018-02-27 15:30:01 -08004140
4141 @Override
4142 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4143 enforceModifyPermission();
4144 final Phone phone = getPhone(subId);
4145 if (phone == null) {
4146 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4147 return;
4148 }
4149
4150 phone.setRadioIndicationUpdateMode(filters, mode);
4151 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004152}