blob: d181e5afbd637be1924ce72281e5b830197b249f [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger7e934f52017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
Brad Ebinger4dc095a2018-04-03 15:17:52 -070045import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070047import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070048import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070049import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080050import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070051import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080052import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080053import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070054import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070055import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070058import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080059import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070060import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080061import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070062import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070063import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070064import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080066import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070067import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080068import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080069import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070070import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070071import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000072import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070073import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070074import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebingera12246d2018-01-16 09:39:35 -080075import android.telephony.ims.aidl.IImsConfig;
76import android.telephony.ims.aidl.IImsMmTelFeature;
77import android.telephony.ims.aidl.IImsRcsFeature;
78import android.telephony.ims.aidl.IImsRegistration;
Brad Ebingere21f25f2018-02-08 16:11:32 -080079import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080081import android.util.ArraySet;
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;
Shishir Agrawal302c8692015-06-19 13:49:39 -070090import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070091import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080094import com.android.internal.telephony.IccCard;
Jack Yu8e4fdc22018-04-13 14:05:37 -070095import com.android.internal.telephony.LocaleTracker;
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;
Jack Yu8e4fdc22018-04-13 14:05:37 -0700106import com.android.internal.telephony.ServiceStateTracker;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800107import com.android.internal.telephony.SubscriptionController;
Jeff Davidsond9a1bb52018-02-13 18:17:36 -0800108import com.android.internal.telephony.TelephonyPermissions;
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 Davidsond9a1bb52018-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;
Shuo Qian74b16b12018-04-27 01:32:07 +0000169 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
170 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700171 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
172 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
173 private static final int CMD_EXCHANGE_SIM_IO = 31;
174 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800175 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
176 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700177 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
178 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700179 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
180 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700181 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
182 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
183 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
184 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700185 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
186 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
187 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
188 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700189 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800190 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
191 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000192 private static final int CMD_SWITCH_SLOTS = 50;
193 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800195 // Parameters of select command.
196 private static final int SELECT_COMMAND = 0xA4;
197 private static final int SELECT_P1 = 0x04;
198 private static final int SELECT_P2 = 0;
199 private static final int SELECT_P3 = 0x10;
200
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 /** The singleton instance. */
202 private static PhoneInterfaceManager sInstance;
203
Wink Saville3ab207e2014-11-20 13:07:20 -0800204 private PhoneGlobals mApp;
205 private Phone mPhone;
206 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700207 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800208 private AppOpsManager mAppOps;
209 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800210 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800211 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700212
Derek Tan97ebb422014-09-05 16:55:38 -0700213 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
214 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800215 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700216
Derek Tan740e1672017-06-27 14:56:27 -0700217 // The AID of ISD-R.
218 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
219
yinxub1bed742017-04-17 11:45:04 -0700220 private NetworkScanRequestTracker mNetworkScanRequestTracker;
221
Derek Tan89e89d42014-07-08 17:00:10 -0700222 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700223 * A request object to use for transmitting data to an ICC.
224 */
225 private static final class IccAPDUArgument {
226 public int channel, cla, command, p1, p2, p3;
227 public String data;
228
229 public IccAPDUArgument(int channel, int cla, int command,
230 int p1, int p2, int p3, String data) {
231 this.channel = channel;
232 this.cla = cla;
233 this.command = command;
234 this.p1 = p1;
235 this.p2 = p2;
236 this.p3 = p3;
237 this.data = data;
238 }
239 }
240
241 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700242 * A request object to use for transmitting data to an ICC.
243 */
244 private static final class ManualNetworkSelectionArgument {
245 public OperatorInfo operatorInfo;
246 public boolean persistSelection;
247
248 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
249 this.operatorInfo = operatorInfo;
250 this.persistSelection = persistSelection;
251 }
252 }
253
254 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700255 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
256 * request after sending. The main thread will notify the request when it is complete.
257 */
258 private static final class MainThreadRequest {
259 /** The argument to use for the request */
260 public Object argument;
261 /** The result of the request that is run on the main thread */
262 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800263 // The subscriber id that this request applies to. Defaults to
264 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
265 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700266
267 public MainThreadRequest(Object argument) {
268 this.argument = argument;
269 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800270
271 public MainThreadRequest(Object argument, Integer subId) {
272 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800273 if (subId != null) {
274 this.subId = subId;
275 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700277 }
278
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800279 private static final class IncomingThirdPartyCallArgs {
280 public final ComponentName component;
281 public final String callId;
282 public final String callerDisplayName;
283
284 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
285 String callerDisplayName) {
286 this.component = component;
287 this.callId = callId;
288 this.callerDisplayName = callerDisplayName;
289 }
290 }
291
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292 /**
293 * A handler that processes messages on the main thread in the phone process. Since many
294 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
295 * inbound binder threads to the main thread in the phone process. The Binder thread
296 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
297 * on, which will be notified when the operation completes and will contain the result of the
298 * request.
299 *
300 * <p>If a MainThreadRequest object is provided in the msg.obj field,
301 * note that request.result must be set to something non-null for the calling thread to
302 * unblock.
303 */
304 private final class MainThreadHandler extends Handler {
305 @Override
306 public void handleMessage(Message msg) {
307 MainThreadRequest request;
308 Message onCompleted;
309 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800310 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700311 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700312
313 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700314 case CMD_HANDLE_USSD_REQUEST: {
315 request = (MainThreadRequest) msg.obj;
316 final Phone phone = getPhoneFromRequest(request);
317 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
318 String ussdRequest = ussdObject.first;
319 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700320
321 if (!isUssdApiAllowed(request.subId)) {
322 // Carrier does not support use of this API, return failure.
323 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
324 UssdResponse response = new UssdResponse(ussdRequest, null);
325 Bundle returnData = new Bundle();
326 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
327 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
328
329 request.result = true;
330 synchronized (request) {
331 request.notifyAll();
332 }
333 return;
334 }
335
Tyler Gunn52dcf772017-04-26 11:30:31 -0700336 try {
337 request.result = phone != null ?
338 phone.handleUssdRequest(ussdRequest, wrappedCallback)
339 : false;
340 } catch (CallStateException cse) {
341 request.result = false;
342 }
pkanwar32d516d2016-10-14 19:37:38 -0700343 // Wake up the requesting thread
344 synchronized (request) {
345 request.notifyAll();
346 }
347 break;
348 }
349
Yorke Lee716f67e2015-06-17 15:39:16 -0700350 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700352 final Phone phone = getPhoneFromRequest(request);
353 request.result = phone != null ?
354 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
355 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700356 // Wake up the requesting thread
357 synchronized (request) {
358 request.notifyAll();
359 }
360 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700361 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700362
363 case CMD_HANDLE_NEIGHBORING_CELL:
364 request = (MainThreadRequest) msg.obj;
365 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
366 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700367 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 break;
369
370 case EVENT_NEIGHBORING_CELL_DONE:
371 ar = (AsyncResult) msg.obj;
372 request = (MainThreadRequest) ar.userObj;
373 if (ar.exception == null && ar.result != null) {
374 request.result = ar.result;
375 } else {
376 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800377 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 }
379 // Wake up the requesting thread
380 synchronized (request) {
381 request.notifyAll();
382 }
383 break;
384
385 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700386 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800387 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700388 answerRingingCallInternal(answer_subId);
Mengjun Lengb3369682017-10-19 18:39:20 +0800389 request.result = ""; // dummy result for notifying the waiting thread
390 // Wake up the requesting thread
391 synchronized (request) {
392 request.notifyAll();
393 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 break;
395
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 case CMD_END_CALL:
397 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800398 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700399 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700400 Phone phone = getPhone(end_subId);
401 if (phone == null) {
402 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
403 break;
404 }
405 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700406 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
407 // CDMA: If the user presses the Power button we treat it as
408 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700409 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
411 // GSM: End the call as per the Phone state
412 hungUp = PhoneUtils.hangup(mCM);
413 } else {
414 throw new IllegalStateException("Unexpected phone type: " + phoneType);
415 }
416 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
417 request.result = hungUp;
418 // Wake up the requesting thread
419 synchronized (request) {
420 request.notifyAll();
421 }
422 break;
423
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700424 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700425 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700426 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800427 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700428 if (uiccCard == null) {
429 loge("iccTransmitApduLogicalChannel: No UICC");
430 request.result = new IccIoResult(0x6F, 0, (byte[])null);
431 synchronized (request) {
432 request.notifyAll();
433 }
434 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700435 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
436 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700437 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700438 iccArgument.channel, iccArgument.cla, iccArgument.command,
439 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700440 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700441 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 break;
443
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700444 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 ar = (AsyncResult) msg.obj;
446 request = (MainThreadRequest) ar.userObj;
447 if (ar.exception == null && ar.result != null) {
448 request.result = ar.result;
449 } else {
450 request.result = new IccIoResult(0x6F, 0, (byte[])null);
451 if (ar.result == null) {
452 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800453 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800455 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 } else {
457 loge("iccTransmitApduLogicalChannel: Unknown exception");
458 }
459 }
460 synchronized (request) {
461 request.notifyAll();
462 }
463 break;
464
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
466 request = (MainThreadRequest) msg.obj;
467 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800468 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700469 if (uiccCard == null) {
470 loge("iccTransmitApduBasicChannel: No UICC");
471 request.result = new IccIoResult(0x6F, 0, (byte[])null);
472 synchronized (request) {
473 request.notifyAll();
474 }
475 } else {
476 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
477 request);
478 uiccCard.iccTransmitApduBasicChannel(
479 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
480 iccArgument.p3, iccArgument.data, onCompleted);
481 }
482 break;
483
484 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
485 ar = (AsyncResult) msg.obj;
486 request = (MainThreadRequest) ar.userObj;
487 if (ar.exception == null && ar.result != null) {
488 request.result = ar.result;
489 } else {
490 request.result = new IccIoResult(0x6F, 0, (byte[])null);
491 if (ar.result == null) {
492 loge("iccTransmitApduBasicChannel: Empty response");
493 } else if (ar.exception instanceof CommandException) {
494 loge("iccTransmitApduBasicChannel: CommandException: " +
495 ar.exception);
496 } else {
497 loge("iccTransmitApduBasicChannel: Unknown exception");
498 }
499 }
500 synchronized (request) {
501 request.notifyAll();
502 }
503 break;
504
505 case CMD_EXCHANGE_SIM_IO:
506 request = (MainThreadRequest) msg.obj;
507 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800508 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 if (uiccCard == null) {
510 loge("iccExchangeSimIO: No UICC");
511 request.result = new IccIoResult(0x6F, 0, (byte[])null);
512 synchronized (request) {
513 request.notifyAll();
514 }
515 } else {
516 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
517 request);
518 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
519 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
520 iccArgument.data, onCompleted);
521 }
522 break;
523
524 case EVENT_EXCHANGE_SIM_IO_DONE:
525 ar = (AsyncResult) msg.obj;
526 request = (MainThreadRequest) ar.userObj;
527 if (ar.exception == null && ar.result != null) {
528 request.result = ar.result;
529 } else {
530 request.result = new IccIoResult(0x6f, 0, (byte[])null);
531 }
532 synchronized (request) {
533 request.notifyAll();
534 }
535 break;
536
Derek Tan4d5e5c12014-02-04 11:54:58 -0800537 case CMD_SEND_ENVELOPE:
538 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800539 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700540 if (uiccCard == null) {
541 loge("sendEnvelopeWithStatus: No UICC");
542 request.result = new IccIoResult(0x6F, 0, (byte[])null);
543 synchronized (request) {
544 request.notifyAll();
545 }
546 } else {
547 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
548 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
549 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800550 break;
551
552 case EVENT_SEND_ENVELOPE_DONE:
553 ar = (AsyncResult) msg.obj;
554 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700555 if (ar.exception == null && ar.result != null) {
556 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800557 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700558 request.result = new IccIoResult(0x6F, 0, (byte[])null);
559 if (ar.result == null) {
560 loge("sendEnvelopeWithStatus: Empty response");
561 } else if (ar.exception instanceof CommandException) {
562 loge("sendEnvelopeWithStatus: CommandException: " +
563 ar.exception);
564 } else {
565 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
566 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800567 }
568 synchronized (request) {
569 request.notifyAll();
570 }
571 break;
572
Shishir Agrawal566b7612013-10-28 14:41:00 -0700573 case CMD_OPEN_CHANNEL:
574 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800575 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800576 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700577 if (uiccCard == null) {
578 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800579 request.result = new IccOpenLogicalChannelResponse(-1,
580 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 synchronized (request) {
582 request.notifyAll();
583 }
584 } else {
585 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800586 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
587 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700589 break;
590
591 case EVENT_OPEN_CHANNEL_DONE:
592 ar = (AsyncResult) msg.obj;
593 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700594 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 int[] result = (int[]) ar.result;
597 int channelId = result[0];
598 byte[] selectResponse = null;
599 if (result.length > 1) {
600 selectResponse = new byte[result.length - 1];
601 for (int i = 1; i < result.length; ++i) {
602 selectResponse[i - 1] = (byte) result[i];
603 }
604 }
605 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700606 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700607 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 if (ar.result == null) {
609 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 if (ar.exception != null) {
612 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
613 }
614
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700615 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700616 if (ar.exception instanceof CommandException) {
617 CommandException.Error error =
618 ((CommandException) (ar.exception)).getCommandError();
619 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700620 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700621 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700623 }
624 }
625 openChannelResp = new IccOpenLogicalChannelResponse(
626 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700628 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 synchronized (request) {
630 request.notifyAll();
631 }
632 break;
633
634 case CMD_CLOSE_CHANNEL:
635 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800636 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700637 if (uiccCard == null) {
638 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900639 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 synchronized (request) {
641 request.notifyAll();
642 }
643 } else {
644 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
645 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
646 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
649 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800650 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
651 break;
652
653 case CMD_NV_READ_ITEM:
654 request = (MainThreadRequest) msg.obj;
655 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
656 mPhone.nvReadItem((Integer) request.argument, onCompleted);
657 break;
658
659 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 ar = (AsyncResult) msg.obj;
661 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800662 if (ar.exception == null && ar.result != null) {
663 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800665 request.result = "";
666 if (ar.result == null) {
667 loge("nvReadItem: Empty response");
668 } else if (ar.exception instanceof CommandException) {
669 loge("nvReadItem: CommandException: " +
670 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700671 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800672 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 }
674 }
675 synchronized (request) {
676 request.notifyAll();
677 }
678 break;
679
Jake Hambye994d462014-02-03 13:10:13 -0800680 case CMD_NV_WRITE_ITEM:
681 request = (MainThreadRequest) msg.obj;
682 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
683 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
684 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
685 break;
686
687 case EVENT_NV_WRITE_ITEM_DONE:
688 handleNullReturnEvent(msg, "nvWriteItem");
689 break;
690
691 case CMD_NV_WRITE_CDMA_PRL:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
694 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
695 break;
696
697 case EVENT_NV_WRITE_CDMA_PRL_DONE:
698 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
699 break;
700
701 case CMD_NV_RESET_CONFIG:
702 request = (MainThreadRequest) msg.obj;
703 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
704 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
705 break;
706
707 case EVENT_NV_RESET_CONFIG_DONE:
708 handleNullReturnEvent(msg, "nvResetConfig");
709 break;
710
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 case CMD_GET_PREFERRED_NETWORK_TYPE:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700714 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800715 break;
716
717 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
718 ar = (AsyncResult) msg.obj;
719 request = (MainThreadRequest) ar.userObj;
720 if (ar.exception == null && ar.result != null) {
721 request.result = ar.result; // Integer
722 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800723 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 if (ar.result == null) {
725 loge("getPreferredNetworkType: Empty response");
726 } else if (ar.exception instanceof CommandException) {
727 loge("getPreferredNetworkType: CommandException: " +
728 ar.exception);
729 } else {
730 loge("getPreferredNetworkType: Unknown exception");
731 }
732 }
733 synchronized (request) {
734 request.notifyAll();
735 }
736 break;
737
738 case CMD_SET_PREFERRED_NETWORK_TYPE:
739 request = (MainThreadRequest) msg.obj;
740 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
741 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700742 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800743 break;
744
745 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
746 handleNullReturnEvent(msg, "setPreferredNetworkType");
747 break;
748
Shuo Qian74b16b12018-04-27 01:32:07 +0000749 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
750 request = (MainThreadRequest)msg.obj;
751 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
752 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
753 break;
754
755 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
756 ar = (AsyncResult)msg.obj;
757 request = (MainThreadRequest)ar.userObj;
758 request.result = ar;
759 synchronized (request) {
760 request.notifyAll();
761 }
762 break;
763
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800764 case CMD_SET_VOICEMAIL_NUMBER:
765 request = (MainThreadRequest) msg.obj;
766 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
767 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800768 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
769 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800770 break;
771
772 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
773 handleNullReturnEvent(msg, "setVoicemailNumber");
774 break;
775
Stuart Scott54788802015-03-30 13:18:01 -0700776 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
777 request = (MainThreadRequest) msg.obj;
778 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
779 request);
780 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
781 break;
782
783 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
784 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
785 break;
786
Shishir Agrawal302c8692015-06-19 13:49:39 -0700787 case CMD_PERFORM_NETWORK_SCAN:
788 request = (MainThreadRequest) msg.obj;
789 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
790 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
791 break;
792
793 case EVENT_PERFORM_NETWORK_SCAN_DONE:
794 ar = (AsyncResult) msg.obj;
795 request = (MainThreadRequest) ar.userObj;
796 CellNetworkScanResult cellScanResult;
797 if (ar.exception == null && ar.result != null) {
798 cellScanResult = new CellNetworkScanResult(
799 CellNetworkScanResult.STATUS_SUCCESS,
800 (List<OperatorInfo>) ar.result);
801 } else {
802 if (ar.result == null) {
803 loge("getCellNetworkScanResults: Empty response");
804 }
805 if (ar.exception != null) {
806 loge("getCellNetworkScanResults: Exception: " + ar.exception);
807 }
808 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
809 if (ar.exception instanceof CommandException) {
810 CommandException.Error error =
811 ((CommandException) (ar.exception)).getCommandError();
812 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
813 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
814 } else if (error == CommandException.Error.GENERIC_FAILURE) {
815 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
816 }
817 }
818 cellScanResult = new CellNetworkScanResult(errorCode, null);
819 }
820 request.result = cellScanResult;
821 synchronized (request) {
822 request.notifyAll();
823 }
824 break;
825
826 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
827 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700828 ManualNetworkSelectionArgument selArg =
829 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
831 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700832 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
833 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700834 break;
835
836 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
837 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
838 break;
839
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700840 case CMD_GET_MODEM_ACTIVITY_INFO:
841 request = (MainThreadRequest) msg.obj;
842 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700843 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700844 break;
845
846 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
849 if (ar.exception == null && ar.result != null) {
850 request.result = ar.result;
851 } else {
852 if (ar.result == null) {
853 loge("queryModemActivityInfo: Empty response");
854 } else if (ar.exception instanceof CommandException) {
855 loge("queryModemActivityInfo: CommandException: " +
856 ar.exception);
857 } else {
858 loge("queryModemActivityInfo: Unknown exception");
859 }
860 }
Amit Mahajand4766222016-01-28 15:28:28 -0800861 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
862 if (request.result == null) {
863 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
864 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700865 synchronized (request) {
866 request.notifyAll();
867 }
868 break;
869
Meng Wang1a7c35a2016-05-05 20:56:15 -0700870 case CMD_SET_ALLOWED_CARRIERS:
871 request = (MainThreadRequest) msg.obj;
872 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
873 mPhone.setAllowedCarriers(
874 (List<CarrierIdentifier>) request.argument,
875 onCompleted);
876 break;
877
878 case EVENT_SET_ALLOWED_CARRIERS_DONE:
879 ar = (AsyncResult) msg.obj;
880 request = (MainThreadRequest) ar.userObj;
881 if (ar.exception == null && ar.result != null) {
882 request.result = ar.result;
883 } else {
884 if (ar.result == null) {
885 loge("setAllowedCarriers: Empty response");
886 } else if (ar.exception instanceof CommandException) {
887 loge("setAllowedCarriers: CommandException: " +
888 ar.exception);
889 } else {
890 loge("setAllowedCarriers: Unknown exception");
891 }
892 }
893 // Result cannot be null. Return -1 on error.
894 if (request.result == null) {
895 request.result = new int[]{-1};
896 }
897 synchronized (request) {
898 request.notifyAll();
899 }
900 break;
901
902 case CMD_GET_ALLOWED_CARRIERS:
903 request = (MainThreadRequest) msg.obj;
904 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
905 mPhone.getAllowedCarriers(onCompleted);
906 break;
907
908 case EVENT_GET_ALLOWED_CARRIERS_DONE:
909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
911 if (ar.exception == null && ar.result != null) {
912 request.result = ar.result;
913 } else {
914 if (ar.result == null) {
915 loge("getAllowedCarriers: Empty response");
916 } else if (ar.exception instanceof CommandException) {
917 loge("getAllowedCarriers: CommandException: " +
918 ar.exception);
919 } else {
920 loge("getAllowedCarriers: Unknown exception");
921 }
922 }
923 // Result cannot be null. Return empty list of CarrierIdentifier.
924 if (request.result == null) {
925 request.result = new ArrayList<CarrierIdentifier>(0);
926 }
927 synchronized (request) {
928 request.notifyAll();
929 }
930 break;
931
Nathan Haroldb3014052017-01-25 15:57:32 -0800932 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
933 ar = (AsyncResult) msg.obj;
934 request = (MainThreadRequest) ar.userObj;
935 if (ar.exception == null && ar.result != null) {
936 request.result = ar.result;
937 } else {
938 request.result = new IllegalArgumentException(
939 "Failed to retrieve Forbidden Plmns");
940 if (ar.result == null) {
941 loge("getForbiddenPlmns: Empty response");
942 } else {
943 loge("getForbiddenPlmns: Unknown exception");
944 }
945 }
946 synchronized (request) {
947 request.notifyAll();
948 }
949 break;
950
951 case CMD_GET_FORBIDDEN_PLMNS:
952 request = (MainThreadRequest) msg.obj;
953 uiccCard = getUiccCardFromRequest(request);
954 if (uiccCard == null) {
955 loge("getForbiddenPlmns() UiccCard is null");
956 request.result = new IllegalArgumentException(
957 "getForbiddenPlmns() UiccCard is null");
958 synchronized (request) {
959 request.notifyAll();
960 }
961 break;
962 }
963 Integer appType = (Integer) request.argument;
964 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
965 if (uiccApp == null) {
966 loge("getForbiddenPlmns() no app with specified type -- "
967 + appType);
968 request.result = new IllegalArgumentException("Failed to get UICC App");
969 synchronized (request) {
970 request.notifyAll();
971 }
972 break;
973 } else {
974 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
975 + " specified type -- " + appType);
976 }
977 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
978 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
979 onCompleted);
980 break;
981
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000982 case CMD_SWITCH_SLOTS:
983 request = (MainThreadRequest) msg.obj;
984 int[] physicalSlots = (int[]) request.argument;
985 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
986 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
987 break;
988
989 case EVENT_SWITCH_SLOTS_DONE:
990 ar = (AsyncResult) msg.obj;
991 request = (MainThreadRequest) ar.userObj;
992 request.result = (ar.exception == null);
993 synchronized (request) {
994 request.notifyAll();
995 }
996 break;
997
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700998 default:
999 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1000 break;
1001 }
1002 }
Jake Hambye994d462014-02-03 13:10:13 -08001003
1004 private void handleNullReturnEvent(Message msg, String command) {
1005 AsyncResult ar = (AsyncResult) msg.obj;
1006 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1007 if (ar.exception == null) {
1008 request.result = true;
1009 } else {
1010 request.result = false;
1011 if (ar.exception instanceof CommandException) {
1012 loge(command + ": CommandException: " + ar.exception);
1013 } else {
1014 loge(command + ": Unknown exception");
1015 }
1016 }
1017 synchronized (request) {
1018 request.notifyAll();
1019 }
1020 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001021 }
1022
1023 /**
1024 * Posts the specified command to be executed on the main thread,
1025 * waits for the request to complete, and returns the result.
1026 * @see #sendRequestAsync
1027 */
1028 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001029 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001030 }
1031
1032 /**
1033 * Posts the specified command to be executed on the main thread,
1034 * waits for the request to complete, and returns the result.
1035 * @see #sendRequestAsync
1036 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001037 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001038 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1039 throw new RuntimeException("This method will deadlock if called from the main thread.");
1040 }
1041
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001042 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001043 Message msg = mMainThreadHandler.obtainMessage(command, request);
1044 msg.sendToTarget();
1045
1046 // Wait for the request to complete
1047 synchronized (request) {
1048 while (request.result == null) {
1049 try {
1050 request.wait();
1051 } catch (InterruptedException e) {
1052 // Do nothing, go back and wait until the request is complete
1053 }
1054 }
1055 }
1056 return request.result;
1057 }
1058
1059 /**
1060 * Asynchronous ("fire and forget") version of sendRequest():
1061 * Posts the specified command to be executed on the main thread, and
1062 * returns immediately.
1063 * @see #sendRequest
1064 */
1065 private void sendRequestAsync(int command) {
1066 mMainThreadHandler.sendEmptyMessage(command);
1067 }
1068
1069 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001070 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1071 * @see {@link #sendRequest(int,Object)}
1072 */
1073 private void sendRequestAsync(int command, Object argument) {
1074 MainThreadRequest request = new MainThreadRequest(argument);
1075 Message msg = mMainThreadHandler.obtainMessage(command, request);
1076 msg.sendToTarget();
1077 }
1078
1079 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001080 * Initialize the singleton PhoneInterfaceManager instance.
1081 * This is only done once, at startup, from PhoneApp.onCreate().
1082 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001083 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001084 synchronized (PhoneInterfaceManager.class) {
1085 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001086 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001087 } else {
1088 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1089 }
1090 return sInstance;
1091 }
1092 }
1093
1094 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001095 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001096 mApp = app;
1097 mPhone = phone;
1098 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001099 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001100 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1101 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001102 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001103 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001104 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001105 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001106
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001107 publish();
1108 }
1109
1110 private void publish() {
1111 if (DBG) log("publish: " + this);
1112
1113 ServiceManager.addService("phone", this);
1114 }
1115
Stuart Scott584921c2015-01-15 17:10:34 -08001116 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001117 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1118 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001119 }
1120
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001121 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1122 Phone phone = getPhoneFromRequest(request);
1123 return phone == null ? null :
1124 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1125 }
1126
Wink Saville36469e72014-06-11 15:17:00 -07001127 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001128 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001129 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001130 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001131 //
1132 // Implementation of the ITelephony interface.
1133 //
1134
1135 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001136 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001137 }
1138
Wink Savilleb564aae2014-10-23 10:18:09 -07001139 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001140 if (DBG) log("dial: " + number);
1141 // No permission check needed here: This is just a wrapper around the
1142 // ACTION_DIAL intent, which is available to any app since it puts up
1143 // the UI before it does anything.
1144
1145 String url = createTelUrl(number);
1146 if (url == null) {
1147 return;
1148 }
1149
1150 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001151 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001152 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1153 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1154 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1155 mApp.startActivity(intent);
1156 }
1157 }
1158
1159 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001160 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001161 }
1162
Wink Savilleb564aae2014-10-23 10:18:09 -07001163 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001164 if (DBG) log("call: " + number);
1165
1166 // This is just a wrapper around the ACTION_CALL intent, but we still
1167 // need to do a permission check since we're calling startActivity()
1168 // from the context of the phone app.
1169 enforceCallPermission();
1170
1171 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1172 != AppOpsManager.MODE_ALLOWED) {
1173 return;
1174 }
1175
1176 String url = createTelUrl(number);
1177 if (url == null) {
1178 return;
1179 }
1180
Wink Saville08874612014-08-31 19:19:58 -07001181 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001182 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001183 if (slist != null) {
1184 for (SubscriptionInfo subInfoRecord : slist) {
1185 if (subInfoRecord.getSubscriptionId() == subId) {
1186 isValid = true;
1187 break;
1188 }
Wink Saville08874612014-08-31 19:19:58 -07001189 }
1190 }
1191 if (isValid == false) {
1192 return;
1193 }
1194
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001195 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001196 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001197 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1198 mApp.startActivity(intent);
1199 }
1200
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001201 /**
1202 * End a call based on call state
1203 * @return true is a call was ended
1204 */
1205 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001206 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001207 }
1208
1209 /**
1210 * End a call based on the call state of the subId
1211 * @return true is a call was ended
1212 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001213 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001214 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001215 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001216 }
1217
1218 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001219 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001220 }
1221
Wink Savilleb564aae2014-10-23 10:18:09 -07001222 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001223 if (DBG) log("answerRingingCall...");
1224 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1225 // but that can probably wait till the big TelephonyManager API overhaul.
1226 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1227 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001228 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001229 }
1230
1231 /**
1232 * Make the actual telephony calls to implement answerRingingCall().
1233 * This should only be called from the main thread of the Phone app.
1234 * @see #answerRingingCall
1235 *
1236 * TODO: it would be nice to return true if we answered the call, or
1237 * false if there wasn't actually a ringing incoming call, or some
1238 * other error occurred. (In other words, pass back the return value
1239 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1240 * But that would require calling this method via sendRequest() rather
1241 * than sendRequestAsync(), and right now we don't actually *need* that
1242 * return value, so let's just return void for now.
1243 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001244 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001245 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001246 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001247 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1248 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 if (hasActiveCall && hasHoldingCall) {
1250 // Both lines are in use!
1251 // TODO: provide a flag to let the caller specify what
1252 // policy to use if both lines are in use. (The current
1253 // behavior is hardwired to "answer incoming, end ongoing",
1254 // which is how the CALL button is specced to behave.)
1255 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1256 return;
1257 } else {
1258 // answerCall() will automatically hold the current active
1259 // call, if there is one.
1260 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1261 return;
1262 }
1263 } else {
1264 // No call was ringing.
1265 return;
1266 }
1267 }
1268
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001269 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001270 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001271 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001272 public void silenceRinger() {
1273 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 }
1275
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001276 @Override
1277 public boolean isOffhook(String callingPackage) {
1278 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001279 }
1280
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001281 @Override
1282 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001283 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001284 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001285 return false;
1286 }
1287
Sanket Padawe356d7632015-06-22 14:03:32 -07001288 final Phone phone = getPhone(subId);
1289 if (phone != null) {
1290 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1291 } else {
1292 return false;
1293 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001294 }
1295
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001296 @Override
1297 public boolean isRinging(String callingPackage) {
1298 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001299 }
1300
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001301 @Override
1302 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001303 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001304 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001305 return false;
1306 }
1307
Sanket Padawe356d7632015-06-22 14:03:32 -07001308 final Phone phone = getPhone(subId);
1309 if (phone != null) {
1310 return (phone.getState() == PhoneConstants.State.RINGING);
1311 } else {
1312 return false;
1313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 }
1315
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001316 @Override
1317 public boolean isIdle(String callingPackage) {
1318 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001319 }
1320
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001321 @Override
1322 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001324 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001325 return false;
1326 }
1327
Sanket Padawe356d7632015-06-22 14:03:32 -07001328 final Phone phone = getPhone(subId);
1329 if (phone != null) {
1330 return (phone.getState() == PhoneConstants.State.IDLE);
1331 } else {
1332 return false;
1333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001334 }
1335
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001337 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001338 }
1339
Wink Savilleb564aae2014-10-23 10:18:09 -07001340 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001341 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001342 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1343 }
1344
1345 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001346 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001347 }
1348
Wink Savilleb564aae2014-10-23 10:18:09 -07001349 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001350 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001351 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1352 }
1353
1354 /** {@hide} */
1355 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001356 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001357 }
1358
Wink Savilleb564aae2014-10-23 10:18:09 -07001359 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001360 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001361 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001362 checkSimPin.start();
1363 return checkSimPin.unlockSim(null, pin);
1364 }
1365
Wink Saville9de0f752013-10-22 19:04:03 -07001366 /** {@hide} */
1367 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001368 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001369 }
1370
Wink Savilleb564aae2014-10-23 10:18:09 -07001371 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001373 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 checkSimPuk.start();
1375 return checkSimPuk.unlockSim(puk, pin);
1376 }
1377
1378 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001379 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380 * a synchronous one.
1381 */
1382 private static class UnlockSim extends Thread {
1383
1384 private final IccCard mSimCard;
1385
1386 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001387 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1388 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001389
1390 // For replies from SimCard interface
1391 private Handler mHandler;
1392
1393 // For async handler to identify request type
1394 private static final int SUPPLY_PIN_COMPLETE = 100;
1395
1396 public UnlockSim(IccCard simCard) {
1397 mSimCard = simCard;
1398 }
1399
1400 @Override
1401 public void run() {
1402 Looper.prepare();
1403 synchronized (UnlockSim.this) {
1404 mHandler = new Handler() {
1405 @Override
1406 public void handleMessage(Message msg) {
1407 AsyncResult ar = (AsyncResult) msg.obj;
1408 switch (msg.what) {
1409 case SUPPLY_PIN_COMPLETE:
1410 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1411 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001412 mRetryCount = msg.arg1;
1413 if (ar.exception != null) {
1414 if (ar.exception instanceof CommandException &&
1415 ((CommandException)(ar.exception)).getCommandError()
1416 == CommandException.Error.PASSWORD_INCORRECT) {
1417 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1418 } else {
1419 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1420 }
1421 } else {
1422 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001424 mDone = true;
1425 UnlockSim.this.notifyAll();
1426 }
1427 break;
1428 }
1429 }
1430 };
1431 UnlockSim.this.notifyAll();
1432 }
1433 Looper.loop();
1434 }
1435
1436 /*
1437 * Use PIN or PUK to unlock SIM card
1438 *
1439 * If PUK is null, unlock SIM card with PIN
1440 *
1441 * If PUK is not null, unlock SIM card with PUK and set PIN code
1442 */
Wink Saville9de0f752013-10-22 19:04:03 -07001443 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001444
1445 while (mHandler == null) {
1446 try {
1447 wait();
1448 } catch (InterruptedException e) {
1449 Thread.currentThread().interrupt();
1450 }
1451 }
1452 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1453
1454 if (puk == null) {
1455 mSimCard.supplyPin(pin, callback);
1456 } else {
1457 mSimCard.supplyPuk(puk, pin, callback);
1458 }
1459
1460 while (!mDone) {
1461 try {
1462 Log.d(LOG_TAG, "wait for done");
1463 wait();
1464 } catch (InterruptedException e) {
1465 // Restore the interrupted status
1466 Thread.currentThread().interrupt();
1467 }
1468 }
1469 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001470 int[] resultArray = new int[2];
1471 resultArray[0] = mResult;
1472 resultArray[1] = mRetryCount;
1473 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474 }
1475 }
1476
1477 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001478 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001479
1480 }
1481
Wink Savilleb564aae2014-10-23 10:18:09 -07001482 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 // No permission check needed here: this call is harmless, and it's
1484 // needed for the ServiceState.requestStateUpdate() call (which is
1485 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001486 final Phone phone = getPhone(subId);
1487 if (phone != null) {
1488 phone.updateServiceLocation();
1489 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 }
1491
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001492 @Override
1493 public boolean isRadioOn(String callingPackage) {
1494 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001495 }
1496
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001497 @Override
1498 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001500 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001501 return false;
1502 }
1503 return isRadioOnForSubscriber(subId);
1504 }
1505
1506 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001507 final Phone phone = getPhone(subId);
1508 if (phone != null) {
1509 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1510 } else {
1511 return false;
1512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001513 }
1514
1515 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001516 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001517
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001518 }
Wink Saville36469e72014-06-11 15:17:00 -07001519
Wink Savilleb564aae2014-10-23 10:18:09 -07001520 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001521 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001522 final Phone phone = getPhone(subId);
1523 if (phone != null) {
1524 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1525 }
Wink Saville36469e72014-06-11 15:17:00 -07001526 }
1527
1528 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001529 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001530 }
1531
Wink Savilleb564aae2014-10-23 10:18:09 -07001532 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001533 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001534 final Phone phone = getPhone(subId);
1535 if (phone == null) {
1536 return false;
1537 }
1538 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001539 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001540 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001541 }
1542 return true;
1543 }
Wink Saville36469e72014-06-11 15:17:00 -07001544
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001545 public boolean needMobileRadioShutdown() {
1546 /*
1547 * If any of the Radios are available, it will need to be
1548 * shutdown. So return true if any Radio is available.
1549 */
1550 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1551 Phone phone = PhoneFactory.getPhone(i);
1552 if (phone != null && phone.isRadioAvailable()) return true;
1553 }
1554 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1555 return false;
1556 }
1557
1558 public void shutdownMobileRadios() {
1559 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1560 logv("Shutting down Phone " + i);
1561 shutdownRadioUsingPhoneId(i);
1562 }
1563 }
1564
1565 private void shutdownRadioUsingPhoneId(int phoneId) {
1566 enforceModifyPermission();
1567 Phone phone = PhoneFactory.getPhone(phoneId);
1568 if (phone != null && phone.isRadioAvailable()) {
1569 phone.shutdownRadio();
1570 }
1571 }
1572
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001574 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001575 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1576 if (defaultPhone != null) {
1577 defaultPhone.setRadioPower(turnOn);
1578 return true;
1579 } else {
1580 loge("There's no default phone.");
1581 return false;
1582 }
Wink Saville36469e72014-06-11 15:17:00 -07001583 }
1584
Wink Savilleb564aae2014-10-23 10:18:09 -07001585 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001587 final Phone phone = getPhone(subId);
1588 if (phone != null) {
1589 phone.setRadioPower(turnOn);
1590 return true;
1591 } else {
1592 return false;
1593 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594 }
1595
Wink Saville36469e72014-06-11 15:17:00 -07001596 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001597 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 public boolean enableDataConnectivity() {
1599 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001600 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001601 final Phone phone = getPhone(subId);
1602 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001603 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001604 return true;
1605 } else {
1606 return false;
1607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 }
1609
Wink Saville36469e72014-06-11 15:17:00 -07001610 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001611 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 public boolean disableDataConnectivity() {
1613 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001614 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001615 final Phone phone = getPhone(subId);
1616 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001617 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001618 return true;
1619 } else {
1620 return false;
1621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 }
1623
Sanket Padawe356d7632015-06-22 14:03:32 -07001624 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001625 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001626 final Phone phone = getPhone(subId);
1627 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001628 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001629 } else {
1630 return false;
1631 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001632 }
1633
1634 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001635 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001636 }
1637
pkanwarae03a6b2016-11-06 20:37:09 -08001638 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001639 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001640 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1641 return;
1642 }
1643 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1644 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1645 };
1646
Wink Savilleb564aae2014-10-23 10:18:09 -07001647 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001649 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1650 return false;
1651 }
Wink Saville36469e72014-06-11 15:17:00 -07001652 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001653 }
1654
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001656 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001657 }
1658
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001659 public int getCallStateForSlot(int slotIndex) {
1660 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001661 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001662 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001663 }
1664
Sanket Padawe356d7632015-06-22 14:03:32 -07001665 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001667 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001668 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001669 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001670 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001671 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 }
1674
Sanket Padawe356d7632015-06-22 14:03:32 -07001675 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001677 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001678 if (phone != null) {
1679 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1680 } else {
1681 return TelephonyManager.DATA_ACTIVITY_NONE;
1682 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001683 }
1684
1685 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001686 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001687 mPhone.getContext().getSystemService(AppOpsManager.class)
1688 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001689 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001690 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001691 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 }
1693
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001694 if (DBG_LOC) log("getCellLocation: is active user");
1695 Bundle data = new Bundle();
1696 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1697 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 return null;
1699 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001700
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001701 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1702 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1703 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001704 }
1705
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001706 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001707 public String getNetworkCountryIsoForPhone(int phoneId) {
1708 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1709 // registered cell info, so return a NULL country instead.
1710 final long identity = Binder.clearCallingIdentity();
1711 try {
1712 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu8e4fdc22018-04-13 14:05:37 -07001713 // Todo: fix this when we can get the actual cellular network info when the device
1714 // is on IWLAN.
Jonathan Basseri03923952017-07-19 12:22:35 -07001715 if (TelephonyManager.NETWORK_TYPE_IWLAN
1716 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1717 return "";
1718 }
1719 } finally {
1720 Binder.restoreCallingIdentity(identity);
1721 }
Jack Yu8e4fdc22018-04-13 14:05:37 -07001722
1723 Phone phone = PhoneFactory.getPhone(phoneId);
1724 if (phone != null) {
1725 ServiceStateTracker sst = phone.getServiceStateTracker();
1726 if (sst != null) {
1727 LocaleTracker lt = sst.getLocaleTracker();
1728 if (lt != null) {
1729 return lt.getCurrentCountry();
1730 }
1731 }
1732 }
1733 return "";
Jonathan Basseri03923952017-07-19 12:22:35 -07001734 }
1735
1736 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001738 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001739 }
1740
Sanket Padawe356d7632015-06-22 14:03:32 -07001741 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001742 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 mApp.enforceCallingOrSelfPermission(
1744 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001745 final Phone phone = getPhone(subId);
1746 if (phone != null) {
1747 phone.enableLocationUpdates();
1748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 }
1750
1751 @Override
1752 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001753 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001754 }
1755
Sanket Padawe356d7632015-06-22 14:03:32 -07001756 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001757 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 mApp.enforceCallingOrSelfPermission(
1759 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001760 final Phone phone = getPhone(subId);
1761 if (phone != null) {
1762 phone.disableLocationUpdates();
1763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001764 }
1765
1766 @Override
1767 @SuppressWarnings("unchecked")
1768 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001769 mPhone.getContext().getSystemService(AppOpsManager.class)
1770 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001771 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001772 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001773 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 }
1775
1776 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1777 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1778 return null;
1779 }
Svetoslav64fad262015-04-14 14:35:21 -07001780
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001781 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001782
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001783 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001785 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1786 try {
1787 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1788 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1789 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1790 } catch (RuntimeException e) {
1791 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001793 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 }
1795
1796
1797 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001798 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001799 mPhone.getContext().getSystemService(AppOpsManager.class)
1800 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001801 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001802 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001803 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 }
1805
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001806 if (DBG_LOC) log("getAllCellInfo: is active user");
1807 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1808 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1809 for (Phone phone : PhoneFactory.getPhones()) {
1810 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1811 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001813 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 }
1815
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001816 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001818 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001819 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1820 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 }
1822
Shishir Agrawala9f32182016-04-12 12:00:16 -07001823 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001824 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001825 Phone phone = PhoneFactory.getPhone(slotIndex);
1826 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001827 return null;
1828 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001829 int subId = phone.getSubId();
1830 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1831 mApp, subId, callingPackage, "getImeiForSlot")) {
1832 return null;
1833 }
1834 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001835 }
1836
1837 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001838 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001839 Phone phone = PhoneFactory.getPhone(slotIndex);
1840 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001841 return null;
1842 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001843 int subId = phone.getSubId();
1844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1845 mApp, subId, callingPackage, "getMeidForSlot")) {
1846 return null;
1847 }
1848 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001849 }
1850
1851 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001852 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001853 Phone phone = PhoneFactory.getPhone(slotIndex);
1854 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001855 return null;
1856 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001857 int subId = phone.getSubId();
1858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1859 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1860 return null;
1861 }
1862 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001863 }
1864
fionaxuf32acdf2017-11-27 22:51:16 -08001865 @Override
1866 public int getSubscriptionCarrierId(int subId) {
1867 final Phone phone = getPhone(subId);
1868 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1869 }
1870
1871 @Override
1872 public String getSubscriptionCarrierName(int subId) {
1873 final Phone phone = getPhone(subId);
1874 return phone == null ? null : phone.getCarrierName();
1875 }
1876
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 //
1878 // Internal helper methods.
1879 //
1880
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001881 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1883 *
1884 * @throws SecurityException if the caller does not have the required permission
1885 */
1886 private void enforceModifyPermission() {
1887 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1888 }
1889
1890 /**
1891 * Make sure the caller has the CALL_PHONE permission.
1892 *
1893 * @throws SecurityException if the caller does not have the required permission
1894 */
1895 private void enforceCallPermission() {
1896 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1897 }
1898
Stuart Scott8eef64f2015-04-08 15:13:54 -07001899 private void enforceConnectivityInternalPermission() {
1900 mApp.enforceCallingOrSelfPermission(
1901 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1902 "ConnectivityService");
1903 }
1904
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 private String createTelUrl(String number) {
1906 if (TextUtils.isEmpty(number)) {
1907 return null;
1908 }
1909
Jake Hambye994d462014-02-03 13:10:13 -08001910 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001911 }
1912
Ihab Awadf9e92732013-12-05 18:02:52 -08001913 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1915 }
1916
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001917 private static void logv(String msg) {
1918 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1919 }
1920
Ihab Awadf9e92732013-12-05 18:02:52 -08001921 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1923 }
1924
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001925 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001926 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001927 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001928 }
1929
Sanket Padawe356d7632015-06-22 14:03:32 -07001930 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001931 public int getActivePhoneTypeForSlot(int slotIndex) {
1932 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001933 if (phone == null) {
1934 return PhoneConstants.PHONE_TYPE_NONE;
1935 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001936 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001937 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 }
1939
1940 /**
1941 * Returns the CDMA ERI icon index to display
1942 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001943 @Override
1944 public int getCdmaEriIconIndex(String callingPackage) {
1945 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001946 }
1947
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001949 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001950 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001951 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001952 return -1;
1953 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001954 final Phone phone = getPhone(subId);
1955 if (phone != null) {
1956 return phone.getCdmaEriIconIndex();
1957 } else {
1958 return -1;
1959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001960 }
1961
1962 /**
1963 * Returns the CDMA ERI icon mode,
1964 * 0 - ON
1965 * 1 - FLASHING
1966 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001967 @Override
1968 public int getCdmaEriIconMode(String callingPackage) {
1969 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001970 }
1971
Sanket Padawe356d7632015-06-22 14:03:32 -07001972 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001973 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001974 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001975 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001976 return -1;
1977 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001978 final Phone phone = getPhone(subId);
1979 if (phone != null) {
1980 return phone.getCdmaEriIconMode();
1981 } else {
1982 return -1;
1983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 }
1985
1986 /**
1987 * Returns the CDMA ERI text,
1988 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001989 @Override
1990 public String getCdmaEriText(String callingPackage) {
1991 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001992 }
1993
Sanket Padawe356d7632015-06-22 14:03:32 -07001994 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001995 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001996 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001997 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001998 return null;
1999 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002000 final Phone phone = getPhone(subId);
2001 if (phone != null) {
2002 return phone.getCdmaEriText();
2003 } else {
2004 return null;
2005 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002006 }
2007
2008 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002009 * Returns the CDMA MDN.
2010 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002011 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002012 public String getCdmaMdn(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2014 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07002015 final Phone phone = getPhone(subId);
2016 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2017 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002018 } else {
2019 return null;
2020 }
2021 }
2022
2023 /**
2024 * Returns the CDMA MIN.
2025 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002026 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002027 public String getCdmaMin(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2029 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002030 final Phone phone = getPhone(subId);
2031 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2032 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002033 } else {
2034 return null;
2035 }
2036 }
2037
2038 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002039 * Returns true if CDMA provisioning needs to run.
2040 */
2041 public boolean needsOtaServiceProvisioning() {
2042 return mPhone.needsOtaServiceProvisioning();
2043 }
2044
2045 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002046 * Sets the voice mail number of a given subId.
2047 */
2048 @Override
2049 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002050 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002051 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2052 new Pair<String, String>(alphaTag, number), new Integer(subId));
2053 return success;
2054 }
2055
Ta-wei Yen87c49842016-05-13 21:19:52 -07002056 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002057 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2058 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2059 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2060 if (!TextUtils.equals(callingPackage, systemDialer)) {
2061 throw new SecurityException("caller must be system dialer");
2062 }
2063 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2064 if (phoneAccountHandle == null){
2065 return null;
2066 }
2067 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2068 }
2069
2070 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002071 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002072 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002073 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002074 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002075 return null;
2076 }
Jeff Davidson87b3c102018-03-15 17:16:18 -07002077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 return RemoteVvmTaskManager
2080 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2081 } finally {
2082 Binder.restoreCallingIdentity(identity);
2083 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002084 }
2085
2086 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002087 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2088 VisualVoicemailSmsFilterSettings settings) {
2089 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002090 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002091 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2092 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002093 }
2094
2095 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002096 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2097 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002098 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002099 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002100 }
2101
2102 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002103 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2104 String callingPackage, int subId) {
2105 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002106 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002107 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002108 }
2109
2110 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002111 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002112 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002113 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002114 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2115 }
2116
2117 @Override
2118 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2119 String number, int port, String text, PendingIntent sentIntent) {
2120 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002121 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002122 enforceSendSmsPermission();
2123 // Make the calls as the phone process.
2124 final long identity = Binder.clearCallingIdentity();
2125 try {
2126 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2127 if (port == 0) {
2128 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2129 sentIntent, null, false);
2130 } else {
2131 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2132 smsManager.sendDataMessageWithSelfPermissions(number, null,
2133 (short) port, data, sentIntent, null);
2134 }
2135 } finally {
2136 Binder.restoreCallingIdentity(identity);
2137 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002138 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002139 /**
fionaxu0152e512016-11-14 13:36:14 -08002140 * Sets the voice activation state of a given subId.
2141 */
2142 @Override
2143 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2145 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002146 final Phone phone = getPhone(subId);
2147 if (phone != null) {
2148 phone.setVoiceActivationState(activationState);
2149 } else {
2150 loge("setVoiceActivationState fails with invalid subId: " + subId);
2151 }
2152 }
2153
2154 /**
2155 * Sets the data activation state of a given subId.
2156 */
2157 @Override
2158 public void setDataActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2160 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002161 final Phone phone = getPhone(subId);
2162 if (phone != null) {
2163 phone.setDataActivationState(activationState);
2164 } else {
2165 loge("setVoiceActivationState fails with invalid subId: " + subId);
2166 }
2167 }
2168
2169 /**
2170 * Returns the voice activation state of a given subId.
2171 */
2172 @Override
2173 public int getVoiceActivationState(int subId, String callingPackage) {
goneil9e8ba382017-12-13 12:57:23 -08002174 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002175 final Phone phone = getPhone(subId);
2176 if (phone != null) {
2177 return phone.getVoiceActivationState();
2178 } else {
2179 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2180 }
2181 }
2182
2183 /**
2184 * Returns the data activation state of a given subId.
2185 */
2186 @Override
2187 public int getDataActivationState(int subId, String callingPackage) {
goneil9e8ba382017-12-13 12:57:23 -08002188 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002189 final Phone phone = getPhone(subId);
2190 if (phone != null) {
2191 return phone.getDataActivationState();
2192 } else {
2193 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2194 }
2195 }
2196
2197 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 * Returns the unread count of voicemails
2199 */
2200 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002201 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002202 }
2203
2204 /**
2205 * Returns the unread count of voicemails for a subId
2206 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002207 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002208 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002209 final Phone phone = getPhone(subId);
2210 if (phone != null) {
2211 return phone.getVoiceMessageCount();
2212 } else {
2213 return 0;
2214 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 }
2216
2217 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002218 * returns true, if the device is in a state where both voice and data
2219 * are supported simultaneously. This can change based on location or network condition.
2220 */
2221 @Override
2222 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2223 final Phone phone = getPhone(subId);
2224 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2225 }
2226
2227 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002228 * Send the dialer code if called from the current default dialer or the caller has
2229 * carrier privilege.
2230 * @param inputCode The dialer code to send
2231 */
2232 @Override
2233 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2234 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2235 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2236 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002237 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2238 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002239 }
2240 mPhone.sendDialerSpecialCode(inputCode);
2241 }
2242
2243 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002244 * Returns the data network type.
2245 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 *
2247 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2248 */
2249 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002250 public int getNetworkType() {
2251 final Phone phone = getPhone(getDefaultSubscription());
2252 if (phone != null) {
2253 return phone.getServiceState().getDataNetworkType();
2254 } else {
2255 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2256 }
Wink Saville36469e72014-06-11 15:17:00 -07002257 }
2258
2259 /**
2260 * Returns the network type for a subId
2261 */
2262 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002263 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002265 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002266 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2267 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002268
Sanket Padawe356d7632015-06-22 14:03:32 -07002269 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002270 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002271 return phone.getServiceState().getDataNetworkType();
2272 } else {
2273 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2274 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 }
2276
2277 /**
2278 * Returns the data network type
2279 */
2280 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002281 public int getDataNetworkType(String callingPackage) {
2282 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002283 }
2284
2285 /**
2286 * Returns the data network type for a subId
2287 */
2288 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002289 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002290 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002291 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002292 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2293 }
2294
Sanket Padawe356d7632015-06-22 14:03:32 -07002295 final Phone phone = getPhone(subId);
2296 if (phone != null) {
2297 return phone.getServiceState().getDataNetworkType();
2298 } else {
2299 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2300 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 }
2302
2303 /**
Wink Saville36469e72014-06-11 15:17:00 -07002304 * Returns the Voice network type for a subId
2305 */
2306 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002307 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002308 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002309 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002310 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2311 }
2312
Sanket Padawe356d7632015-06-22 14:03:32 -07002313 final Phone phone = getPhone(subId);
2314 if (phone != null) {
2315 return phone.getServiceState().getVoiceNetworkType();
2316 } else {
2317 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2318 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 }
2320
2321 /**
2322 * @return true if a ICC card is present
2323 */
2324 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002325 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002326 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2327 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002328 }
2329
2330 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002331 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002332 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002333 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002334 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2335 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002336 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002337 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002338 } else {
2339 return false;
2340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002341 }
2342
2343 /**
2344 * Return if the current radio is LTE on CDMA. This
2345 * is a tri-state return value as for a period of time
2346 * the mode may be unknown.
2347 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002348 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002349 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002350 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002352 @Override
2353 public int getLteOnCdmaMode(String callingPackage) {
2354 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002355 }
2356
Sanket Padawe356d7632015-06-22 14:03:32 -07002357 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002358 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002359 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002360 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002361 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2362 }
2363
Sanket Padawe356d7632015-06-22 14:03:32 -07002364 final Phone phone = getPhone(subId);
2365 if (phone == null) {
2366 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2367 } else {
2368 return phone.getLteOnCdmaMode();
2369 }
Wink Saville36469e72014-06-11 15:17:00 -07002370 }
2371
2372 public void setPhone(Phone phone) {
2373 mPhone = phone;
2374 }
2375
2376 /**
2377 * {@hide}
2378 * Returns Default subId, 0 in the case of single standby.
2379 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002380 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002381 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002382 }
2383
Shishir Agrawala9f32182016-04-12 12:00:16 -07002384 private int getSlotForDefaultSubscription() {
2385 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2386 }
2387
Wink Savilleb564aae2014-10-23 10:18:09 -07002388 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002389 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002391
2392 /**
2393 * @see android.telephony.TelephonyManager.WifiCallingChoices
2394 */
2395 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002396 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2397 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002398 }
2399
2400 /**
2401 * @see android.telephony.TelephonyManager.WifiCallingChoices
2402 */
2403 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002404 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2405 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2406 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002407 }
2408
Sailesh Nepald1e68152013-12-12 19:08:02 -08002409 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002410 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002411 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002412 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002413
Shishir Agrawal566b7612013-10-28 14:41:00 -07002414 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002415 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2416 int subId, String callingPackage, String aid, int p2) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2418 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002419
Derek Tan740e1672017-06-27 14:56:27 -07002420 if (TextUtils.equals(ISDR_AID, aid)) {
2421 // Only allows LPA to open logical channel to ISD-R.
2422 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2423 ComponentInfo bestComponent =
2424 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2425 if (bestComponent == null
2426 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2427 loge("The calling package is not allowed to access ISD-R.");
2428 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2429 }
2430 }
2431
2432 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002433 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002434 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002435 if (DBG) log("iccOpenLogicalChannel: " + response);
2436 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002437 }
2438
2439 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002440 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2442 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002443
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002444 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002445 if (channel < 0) {
2446 return false;
2447 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002448 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002449 if (DBG) log("iccCloseLogicalChannel: " + success);
2450 return success;
2451 }
2452
2453 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002454 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002455 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2457 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002458
2459 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002460 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2461 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002462 " data=" + data);
2463 }
2464
2465 if (channel < 0) {
2466 return "";
2467 }
2468
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002469 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002470 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002471 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2472
Shishir Agrawal566b7612013-10-28 14:41:00 -07002473 // Append the returned status code to the end of the response payload.
2474 String s = Integer.toHexString(
2475 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002476 if (response.payload != null) {
2477 s = IccUtils.bytesToHexString(response.payload) + s;
2478 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002479 return s;
2480 }
Jake Hambye994d462014-02-03 13:10:13 -08002481
Evan Charltonc66da362014-05-16 14:06:40 -07002482 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002483 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2484 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002485 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2486 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002487
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002488 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2489 && TextUtils.equals(ISDR_AID, data)) {
2490 // Only allows LPA to select ISD-R.
2491 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2492 ComponentInfo bestComponent =
2493 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2494 if (bestComponent == null
2495 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2496 loge("The calling package is not allowed to select ISD-R.");
2497 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2498 }
2499 }
2500
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002501 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002502 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2503 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002504 }
2505
2506 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002507 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002508 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2509
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002510 // Append the returned status code to the end of the response payload.
2511 String s = Integer.toHexString(
2512 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002513 if (response.payload != null) {
2514 s = IccUtils.bytesToHexString(response.payload) + s;
2515 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002516 return s;
2517 }
2518
2519 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002520 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002521 String filePath) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2523 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002524
2525 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002526 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002527 p1 + " " + p2 + " " + p3 + ":" + filePath);
2528 }
2529
2530 IccIoResult response =
2531 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002532 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2533 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002534
2535 if (DBG) {
2536 log("Exchange SIM_IO [R]" + response);
2537 }
2538
2539 byte[] result = null;
2540 int length = 2;
2541 if (response.payload != null) {
2542 length = 2 + response.payload.length;
2543 result = new byte[length];
2544 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2545 } else {
2546 result = new byte[length];
2547 }
2548
2549 result[length - 1] = (byte) response.sw2;
2550 result[length - 2] = (byte) response.sw1;
2551 return result;
2552 }
2553
Nathan Haroldb3014052017-01-25 15:57:32 -08002554 /**
2555 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2556 * on a particular subscription
2557 */
2558 public String[] getForbiddenPlmns(int subId, int appType) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002559 // TODO(b/73884967): Migrate to TelephonyPermissions check.
Nathan Harold892104e2017-04-13 18:19:05 -07002560 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2561 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002562 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2563 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2564 return null;
2565 }
2566 Object response = sendRequest(
2567 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2568 if (response instanceof String[]) {
2569 return (String[]) response;
2570 }
2571 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2572 return null;
2573 }
2574
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002575 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002576 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2578 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002579
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002580 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002581 if (response.payload == null) {
2582 return "";
2583 }
2584
2585 // Append the returned status code to the end of the response payload.
2586 String s = Integer.toHexString(
2587 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2588 s = IccUtils.bytesToHexString(response.payload) + s;
2589 return s;
2590 }
2591
Jake Hambye994d462014-02-03 13:10:13 -08002592 /**
2593 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2594 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2595 *
2596 * @param itemID the ID of the item to read
2597 * @return the NV item as a String, or null on error.
2598 */
2599 @Override
2600 public String nvReadItem(int itemID) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2602 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002603 if (DBG) log("nvReadItem: item " + itemID);
2604 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2605 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2606 return value;
2607 }
2608
2609 /**
2610 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2611 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2612 *
2613 * @param itemID the ID of the item to read
2614 * @param itemValue the value to write, as a String
2615 * @return true on success; false on any failure
2616 */
2617 @Override
2618 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2620 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002621 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2622 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2623 new Pair<Integer, String>(itemID, itemValue));
2624 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2625 return success;
2626 }
2627
2628 /**
2629 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2630 * Used for device configuration by some CDMA operators.
2631 *
2632 * @param preferredRoamingList byte array containing the new PRL
2633 * @return true on success; false on any failure
2634 */
2635 @Override
2636 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2638 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002639 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2640 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2641 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2642 return success;
2643 }
2644
2645 /**
2646 * Perform the specified type of NV config reset.
2647 * Used for device configuration by some CDMA operators.
2648 *
2649 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2650 * @return true on success; false on any failure
2651 */
2652 @Override
2653 public boolean nvResetConfig(int resetType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2655 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002656 if (DBG) log("nvResetConfig: type " + resetType);
2657 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2658 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2659 return success;
2660 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002661
Svet Ganovb320e182015-04-16 12:30:10 -07002662 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002663 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002664 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002665 return new String[0];
2666 }
2667
2668
ram87fca6f2014-07-18 18:58:44 +05302669 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002670 }
2671
Brad Ebinger51f743a2017-01-23 13:50:20 -08002672 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002673 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2674 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002675 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002676 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002677 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002678 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002679 }
2680
2681 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002682 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2683 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002684 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002685 public void disableIms(int slotId) {
2686 enforceModifyPermission();
2687 PhoneFactory.getImsResolver().disableIms(slotId);
2688 }
2689
2690 /**
2691 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2692 * feature or {@link null} if the service is not available. If the feature is available, the
2693 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2694 */
2695 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002696 IImsServiceFeatureCallback callback) {
2697 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002698 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002699 }
2700
2701 /**
2702 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2703 * feature during emergency calling or {@link null} if the service is not available. If the
2704 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2705 * listener for feature updates.
2706 */
2707 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2708 enforceModifyPermission();
2709 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002710 }
2711
Brad Ebinger7e934f52017-12-14 14:26:15 -08002712 /**
2713 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2714 * specified.
2715 */
2716 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2717 enforceModifyPermission();
2718 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2719 }
2720
Brad Ebingera12246d2018-01-16 09:39:35 -08002721 /**
2722 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2723 * specified.
2724 */
2725 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2726 enforceModifyPermission();
2727 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2728 }
2729
Brad Ebinger884c07b2018-02-15 16:17:40 -08002730 /**
Brad Ebinger67801702018-03-02 13:43:36 -08002731 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2732 * available, false if the IMS resolver is idle.
2733 */
2734 public boolean isResolvingImsBinding() {
2735 enforceModifyPermission();
2736 return PhoneFactory.getImsResolver().isResolvingBinding();
2737 }
2738
Brad Ebinger4dc095a2018-04-03 15:17:52 -07002739 /**
2740 * Sets the ImsService Package Name that Telephony will bind to.
2741 *
2742 * @param slotId the slot ID that the ImsService should bind for.
2743 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
2744 * ImsService is the device default ImsService.
2745 * @param packageName The package name of the application that contains the ImsService to bind
2746 * to.
2747 * @return true if setting the ImsService to bind to succeeded, false if it did not.
2748 * @hide
2749 */
2750 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
2751 enforceModifyPermission();
2752 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
2753 isCarrierImsService, packageName);
2754 }
2755
2756 /**
2757 * Return the ImsService configuration.
2758 *
2759 * @param slotId The slot that the ImsService is associated with.
2760 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
2761 * the device default.
2762 * @return the package name of the ImsService configuration.
2763 */
2764 public String getImsService(int slotId, boolean isCarrierImsService) {
2765 enforceReadPrivilegedPermission();
2766 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
2767 isCarrierImsService);
2768 }
2769
Wink Saville36469e72014-06-11 15:17:00 -07002770 public void setImsRegistrationState(boolean registered) {
2771 enforceModifyPermission();
2772 mPhone.setImsRegistrationState(registered);
2773 }
2774
2775 /**
Stuart Scott54788802015-03-30 13:18:01 -07002776 * Set the network selection mode to automatic.
2777 *
2778 */
2779 @Override
2780 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2782 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002783 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2784 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2785 }
2786
2787 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002788 * Set the network selection mode to manual with the selected carrier.
2789 */
2790 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002791 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002792 boolean persistSelection) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2794 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002795 OperatorInfo operator = new OperatorInfo(
2796 /* operatorAlphaLong */ "",
2797 /* operatorAlphaShort */ "",
2798 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002799 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002800 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2801 persistSelection);
2802 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002803 }
2804
2805 /**
2806 * Scans for available networks.
2807 */
2808 @Override
2809 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2811 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002812 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2813 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2814 CMD_PERFORM_NETWORK_SCAN, null, subId);
2815 return result;
2816 }
2817
2818 /**
yinxub1bed742017-04-17 11:45:04 -07002819 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002820 *
yinxub1bed742017-04-17 11:45:04 -07002821 * @param subId id of the subscription
2822 * @param request contains the radio access networks with bands/channels to scan
2823 * @param messenger callback messenger for scan results or errors
2824 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002825 * @return the id of the requested scan which can be used to stop the scan.
2826 */
2827 @Override
2828 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2829 IBinder binder) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2831 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002832 return mNetworkScanRequestTracker.startNetworkScan(
2833 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002834 }
2835
2836 /**
2837 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002838 *
2839 * @param subId id of the subscription
2840 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002841 */
2842 @Override
2843 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2845 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002846 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002847 }
2848
2849 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002850 * Get the calculated preferred network type.
2851 * Used for debugging incorrect network type.
2852 *
2853 * @return the preferred network type, defined in RILConstants.java.
2854 */
2855 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002856 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002857 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002858 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002859 return RILConstants.PREFERRED_NETWORK_MODE;
2860 }
2861
Amit Mahajan43330e02014-11-18 11:54:45 -08002862 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002863 }
2864
2865 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002866 * Get the preferred network type.
2867 * Used for device configuration by some CDMA operators.
2868 *
2869 * @return the preferred network type, defined in RILConstants.java.
2870 */
2871 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002872 public int getPreferredNetworkType(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2874 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002875 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002876 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002877 int networkType = (result != null ? result[0] : -1);
2878 if (DBG) log("getPreferredNetworkType: " + networkType);
2879 return networkType;
2880 }
2881
2882 /**
2883 * Set the preferred network type.
2884 * Used for device configuration by some CDMA operators.
2885 *
2886 * @param networkType the preferred network type, defined in RILConstants.java.
2887 * @return true on success; false on any failure.
2888 */
2889 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002890 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2892 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002893 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2894 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002895 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002896 if (success) {
2897 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002898 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002899 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002900 return success;
2901 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002902
2903 /**
Junda Liu475951f2014-11-07 16:45:03 -08002904 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2905 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2906 * tethering.
2907 *
2908 * @return 0: Not required. 1: required. 2: Not set.
2909 * @hide
2910 */
2911 @Override
2912 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002913 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002914 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2915 Settings.Global.TETHER_DUN_REQUIRED, 2);
2916 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2917 // config_tether_apndata.
2918 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2919 dunRequired = 1;
2920 }
2921 return dunRequired;
2922 }
2923
2924 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002925 * Set mobile data enabled
2926 * Used by the user through settings etc to turn on/off mobile data
2927 *
2928 * @param enable {@code true} turn turn data on, else {@code false}
2929 */
2930 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002931 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2933 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002934 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002935 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002936 Phone phone = PhoneFactory.getPhone(phoneId);
2937 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002938 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2939 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002940 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002941 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002942 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002943 }
2944
2945 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002946 * Get the user enabled state of Mobile Data.
2947 *
2948 * TODO: remove and use isUserDataEnabled.
2949 * This can't be removed now because some vendor codes
2950 * calls through ITelephony directly while they should
2951 * use TelephonyManager.
2952 *
2953 * @return true on enabled
2954 */
2955 @Override
2956 public boolean getDataEnabled(int subId) {
2957 return isUserDataEnabled(subId);
2958 }
2959
2960 /**
2961 * Get whether mobile data is enabled per user setting.
2962 *
2963 * There are other factors deciding whether mobile data is actually enabled, but they are
2964 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002965 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002966 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002967 *
2968 * @return {@code true} if data is enabled else {@code false}
2969 */
2970 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002971 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002972 try {
2973 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2974 null);
2975 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2977 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002978 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002979 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002980 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002981 Phone phone = PhoneFactory.getPhone(phoneId);
2982 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002983 boolean retVal = phone.isUserDataEnabled();
2984 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002985 return retVal;
2986 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002987 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2988 return false;
2989 }
2990 }
2991
2992 /**
2993 * Get whether mobile data is enabled.
2994 *
2995 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2996 * whether mobile data is actually enabled.
2997 *
2998 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2999 *
3000 * @return {@code true} if data is enabled else {@code false}
3001 */
3002 @Override
3003 public boolean isDataEnabled(int subId) {
3004 try {
3005 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3006 null);
3007 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3009 mApp, subId, "isDataEnabled");
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003010 }
3011 int phoneId = mSubscriptionController.getPhoneId(subId);
3012 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3013 Phone phone = PhoneFactory.getPhone(phoneId);
3014 if (phone != null) {
3015 boolean retVal = phone.isDataEnabled();
3016 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3017 return retVal;
3018 } else {
3019 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08003020 return false;
3021 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003022 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003023
3024 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003025 public int getCarrierPrivilegeStatus(int subId) {
3026 final Phone phone = getPhone(subId);
3027 if (phone == null) {
3028 loge("getCarrierPrivilegeStatus: Invalid subId");
3029 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3030 }
3031 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003032 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003033 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003034 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3035 }
3036 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003037 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003038 }
Junda Liu29340342014-07-10 15:23:27 -07003039
3040 @Override
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003041 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3042 final Phone phone = getPhone(subId);
3043 if (phone == null) {
3044 loge("getCarrierPrivilegeStatus: Invalid subId");
3045 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3046 }
3047 UiccProfile profile =
3048 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3049 if (profile == null) {
3050 loge("getCarrierPrivilegeStatus: No UICC");
3051 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3052 }
3053 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3054 }
3055
3056 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003057 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003058 if (TextUtils.isEmpty(pkgName))
3059 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003060 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003061 if (card == null) {
3062 loge("checkCarrierPrivilegesForPackage: No UICC");
3063 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3064 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003065 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3066 }
3067
3068 @Override
3069 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003070 if (TextUtils.isEmpty(pkgName))
3071 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003072 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3073 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3074 UiccCard card = UiccController.getInstance().getUiccCard(i);
3075 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003076 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003077 continue;
3078 }
3079
3080 result = card.getCarrierPrivilegeStatus(
3081 mPhone.getContext().getPackageManager(), pkgName);
3082 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3083 break;
3084 }
3085 }
3086
3087 return result;
Junda Liu29340342014-07-10 15:23:27 -07003088 }
Derek Tan89e89d42014-07-08 17:00:10 -07003089
3090 @Override
Junda Liue64de782015-04-16 17:19:16 -07003091 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3092 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3093 loge("phoneId " + phoneId + " is not valid.");
3094 return null;
3095 }
3096 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003097 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003098 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003099 return null ;
3100 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003101 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003102 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003103 }
3104
Amith Yamasani6e118872016-02-19 12:53:51 -08003105 @Override
3106 public List<String> getPackagesWithCarrierPrivileges() {
3107 PackageManager pm = mPhone.getContext().getPackageManager();
3108 List<String> privilegedPackages = new ArrayList<>();
3109 List<PackageInfo> packages = null;
3110 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3111 UiccCard card = UiccController.getInstance().getUiccCard(i);
3112 if (card == null) {
3113 // No UICC in that slot.
3114 continue;
3115 }
3116 if (card.hasCarrierPrivilegeRules()) {
3117 if (packages == null) {
3118 // Only check packages in user 0 for now
3119 packages = pm.getInstalledPackagesAsUser(
3120 PackageManager.MATCH_DISABLED_COMPONENTS
3121 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3122 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3123 }
3124 for (int p = packages.size() - 1; p >= 0; p--) {
3125 PackageInfo pkgInfo = packages.get(p);
3126 if (pkgInfo != null && pkgInfo.packageName != null
3127 && card.getCarrierPrivilegeStatus(pkgInfo)
3128 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3129 privilegedPackages.add(pkgInfo.packageName);
3130 }
3131 }
3132 }
3133 }
3134 return privilegedPackages;
3135 }
3136
Wink Savilleb564aae2014-10-23 10:18:09 -07003137 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003138 final Phone phone = getPhone(subId);
3139 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003140 if (card == null) {
3141 loge("getIccId: No UICC");
3142 return null;
3143 }
3144 String iccId = card.getIccId();
3145 if (TextUtils.isEmpty(iccId)) {
3146 loge("getIccId: ICC ID is null or empty.");
3147 return null;
3148 }
3149 return iccId;
3150 }
3151
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003152 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003153 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3154 String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003155 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3156 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003157
Jeff Sharkey85190e62014-12-05 09:40:12 -08003158 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003159 final Phone phone = getPhone(subId);
3160 if (phone == null) {
3161 return false;
3162 }
3163 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003164
3165 if (DBG_MERGE) {
3166 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3167 + subscriberId + " to " + number);
3168 }
3169
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003170 if (TextUtils.isEmpty(iccId)) {
3171 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003172 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003173
Jeff Sharkey85190e62014-12-05 09:40:12 -08003174 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3175
3176 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003177 if (alphaTag == null) {
3178 editor.remove(alphaTagPrefKey);
3179 } else {
3180 editor.putString(alphaTagPrefKey, alphaTag);
3181 }
3182
Jeff Sharkey85190e62014-12-05 09:40:12 -08003183 // Record both the line number and IMSI for this ICCID, since we need to
3184 // track all merged IMSIs based on line number
3185 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3186 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003187 if (number == null) {
3188 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003189 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003190 } else {
3191 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003192 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003193 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003194
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003195 editor.commit();
3196 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003197 }
3198
3199 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003200 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003201 // This is open to apps with WRITE_SMS.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003202 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003203 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003204 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003205 return null;
3206 }
Derek Tan97ebb422014-09-05 16:55:38 -07003207
3208 String iccId = getIccId(subId);
3209 if (iccId != null) {
3210 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003211 if (DBG_MERGE) {
3212 log("getLine1NumberForDisplay returning " +
3213 mTelephonySharedPreferences.getString(numberPrefKey, null));
3214 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003215 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003216 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003217 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003218 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003219 }
3220
3221 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003222 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003224 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003225 return null;
3226 }
Derek Tan97ebb422014-09-05 16:55:38 -07003227
3228 String iccId = getIccId(subId);
3229 if (iccId != null) {
3230 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003231 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003232 }
Derek Tan97ebb422014-09-05 16:55:38 -07003233 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003234 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003235
3236 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003237 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003238 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3239 // about carrier-privileged callers not having access.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003241 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3242 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003243 return null;
3244 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003245 final Context context = mPhone.getContext();
3246 final TelephonyManager tele = TelephonyManager.from(context);
3247 final SubscriptionManager sub = SubscriptionManager.from(context);
3248
3249 // Figure out what subscribers are currently active
3250 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003251 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3252 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3253 final long identity = Binder.clearCallingIdentity();
3254 try {
3255 final int[] subIds = sub.getActiveSubscriptionIdList();
3256 for (int subId : subIds) {
3257 activeSubscriberIds.add(tele.getSubscriberId(subId));
3258 }
3259 } finally {
3260 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003261 }
3262
3263 // First pass, find a number override for an active subscriber
3264 String mergeNumber = null;
3265 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3266 for (String key : prefs.keySet()) {
3267 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3268 final String subscriberId = (String) prefs.get(key);
3269 if (activeSubscriberIds.contains(subscriberId)) {
3270 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3271 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3272 mergeNumber = (String) prefs.get(numberKey);
3273 if (DBG_MERGE) {
3274 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3275 + " for active subscriber " + subscriberId);
3276 }
3277 if (!TextUtils.isEmpty(mergeNumber)) {
3278 break;
3279 }
3280 }
3281 }
3282 }
3283
3284 // Shortcut when no active merged subscribers
3285 if (TextUtils.isEmpty(mergeNumber)) {
3286 return null;
3287 }
3288
3289 // Second pass, find all subscribers under that line override
3290 final ArraySet<String> result = new ArraySet<>();
3291 for (String key : prefs.keySet()) {
3292 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3293 final String number = (String) prefs.get(key);
3294 if (mergeNumber.equals(number)) {
3295 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3296 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3297 final String subscriberId = (String) prefs.get(subscriberKey);
3298 if (!TextUtils.isEmpty(subscriberId)) {
3299 result.add(subscriberId);
3300 }
3301 }
3302 }
3303 }
3304
3305 final String[] resultArray = result.toArray(new String[result.size()]);
3306 Arrays.sort(resultArray);
3307 if (DBG_MERGE) {
3308 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3309 }
3310 return resultArray;
3311 }
3312
3313 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003314 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003315 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3316 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003317 final Phone phone = getPhone(subId);
3318 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003319 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003320
3321 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003322 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003323 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3324 List<String> cdmaNonRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003325 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003326 final Phone phone = getPhone(subId);
3327 if (phone == null) {
3328 return false;
3329 }
3330 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003331 cdmaNonRoamingList);
3332 }
3333
3334 @Override
Shuo Qian74b16b12018-04-27 01:32:07 +00003335 @Deprecated
3336 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3337 enforceModifyPermission();
3338
3339 int returnValue = 0;
3340 try {
3341 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3342 if(result.exception == null) {
3343 if (result.result != null) {
3344 byte[] responseData = (byte[])(result.result);
3345 if(responseData.length > oemResp.length) {
3346 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3347 responseData.length + "bytes. Buffer Size is " +
3348 oemResp.length + "bytes.");
3349 }
3350 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3351 returnValue = responseData.length;
3352 }
3353 } else {
3354 CommandException ex = (CommandException) result.exception;
3355 returnValue = ex.getCommandError().ordinal();
3356 if(returnValue > 0) returnValue *= -1;
3357 }
3358 } catch (RuntimeException e) {
3359 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3360 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3361 if(returnValue > 0) returnValue *= -1;
3362 }
3363
3364 return returnValue;
3365 }
3366
3367 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003368 public void setRadioCapability(RadioAccessFamily[] rafs) {
3369 try {
3370 ProxyController.getInstance().setRadioCapability(rafs);
3371 } catch (RuntimeException e) {
3372 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3373 }
3374 }
3375
3376 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003377 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003378 Phone phone = PhoneFactory.getPhone(phoneId);
3379 if (phone == null) {
3380 return RadioAccessFamily.RAF_UNKNOWN;
3381 }
3382 int subId = phone.getSubId();
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003384 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003385 return RadioAccessFamily.RAF_UNKNOWN;
3386 }
3387
Wink Saville5d475dd2014-10-17 15:00:58 -07003388 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3389 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003390
3391 @Override
3392 public void enableVideoCalling(boolean enable) {
3393 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003394 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003395 }
3396
3397 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003398 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003399 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003400 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003401 return false;
3402 }
3403
Andrew Lee77527ac2014-10-21 16:57:39 -07003404 // Check the user preference and the system-level IMS setting. Even if the user has
3405 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3406 // In the long run, we may instead need to check if there exists a connection service
3407 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003408 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3409 return imsManager.isVtEnabledByPlatform()
3410 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3411 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003412 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003413
Andrew Leea1239f22015-03-02 17:44:07 -08003414 @Override
3415 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003416 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003417 }
3418
3419 @Override
3420 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003421 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003422 }
3423
Andrew Lee9431b832015-03-09 18:46:45 -07003424 @Override
3425 public boolean isTtyModeSupported() {
3426 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3427 TelephonyManager telephonyManager =
3428 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003429 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003430 }
3431
3432 @Override
3433 public boolean isHearingAidCompatibilitySupported() {
3434 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3435 }
3436
Hall Liu73714012018-01-22 19:15:32 -08003437 public boolean isRttSupported() {
3438 boolean isCarrierSupported =
3439 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3440 boolean isDeviceSupported =
3441 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3442 return isCarrierSupported && isDeviceSupported;
3443 }
3444
Hall Liub1585172018-04-06 16:23:39 -07003445 public boolean isRttEnabled() {
3446 return isRttSupported() && Settings.Secure.getInt(mPhone.getContext().getContentResolver(),
3447 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
3448 }
3449
Sanket Padawe7310cc72015-01-14 09:53:20 -08003450 /**
3451 * Returns the unique device ID of phone, for example, the IMEI for
3452 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3453 *
3454 * <p>Requires Permission:
3455 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3456 */
3457 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003458 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003459 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003460 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003461 return null;
3462 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003463 int subId = phone.getSubId();
3464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3465 mApp, subId, callingPackage, "getDeviceId")) {
3466 return null;
3467 }
3468 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003469 }
3470
Ping Sun014fe8e2016-03-02 19:16:45 +08003471 /**
3472 * {@hide}
3473 * Returns the IMS Registration Status on a particular subid
3474 *
3475 * @param subId
3476 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003477 public boolean isImsRegistered(int subId) {
Ping Sun014fe8e2016-03-02 19:16:45 +08003478 Phone phone = getPhone(subId);
3479 if (phone != null) {
3480 return phone.isImsRegistered();
3481 } else {
3482 return false;
3483 }
3484 }
3485
Santos Cordon7a1885b2015-02-03 11:15:19 -08003486 @Override
3487 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3488 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3489 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003490
Brad Ebingere21f25f2018-02-08 16:11:32 -08003491 /**
3492 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003493 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003494 public boolean isWifiCallingAvailable(int subId) {
3495 Phone phone = getPhone(subId);
3496 if (phone != null) {
3497 return phone.isWifiCallingEnabled();
3498 } else {
3499 return false;
3500 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003501 }
3502
Brad Ebingere21f25f2018-02-08 16:11:32 -08003503 /**
3504 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003505 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003506 public boolean isVolteAvailable(int subId) {
3507 Phone phone = getPhone(subId);
3508 if (phone != null) {
3509 return phone.isVolteEnabled();
3510 } else {
3511 return false;
3512 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003513 }
Svet Ganovb320e182015-04-16 12:30:10 -07003514
Brad Ebingere21f25f2018-02-08 16:11:32 -08003515 /**
3516 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003517 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003518 public boolean isVideoTelephonyAvailable(int subId) {
3519 Phone phone = getPhone(subId);
3520 if (phone != null) {
3521 return phone.isVideoEnabled();
3522 } else {
3523 return false;
3524 }
3525 }
3526
3527 /**
3528 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3529 * defined in {@link ImsRegistrationImplBase}.
3530 */
3531 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3532 Phone phone = getPhone(subId);
3533 if (phone != null) {
3534 return phone.getImsRegistrationTech();
3535 } else {
3536 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3537 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003538 }
3539
Stuart Scott8eef64f2015-04-08 15:13:54 -07003540 @Override
3541 public void factoryReset(int subId) {
3542 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003543 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3544 return;
3545 }
3546
Svet Ganovcc087f82015-05-12 20:35:54 -07003547 final long identity = Binder.clearCallingIdentity();
3548 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003549 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3550 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003551 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003552 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003553 // Set network selection mode to automatic
3554 setNetworkSelectionModeAutomatic(subId);
3555 // Set preferred mobile network type to the best available
Kitta Koutarouab8a69b2018-03-05 14:16:45 +09003556 String defaultNetwork = TelephonyManager.getTelephonyProperty(
3557 mSubscriptionController.getPhoneId(subId),
3558 "ro.telephony.default_network",
3559 null);
3560 int networkType = !TextUtils.isEmpty(defaultNetwork)
3561 ? Integer.parseInt(defaultNetwork) : Phone.PREFERRED_NT_MODE;
3562 setPreferredNetworkType(subId, networkType);
Svet Ganovcc087f82015-05-12 20:35:54 -07003563 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003564 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003565 }
3566 } finally {
3567 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003568 }
3569 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003570
3571 @Override
3572 public String getLocaleFromDefaultSim() {
3573 // We query all subscriptions instead of just the active ones, because
3574 // this might be called early on in the provisioning flow when the
3575 // subscriptions potentially aren't active yet.
3576 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3577 if (slist == null || slist.isEmpty()) {
3578 return null;
3579 }
3580
3581 // This function may be called very early, say, from the setup wizard, at
3582 // which point we won't have a default subscription set. If that's the case
3583 // we just choose the first, which will be valid in "most cases".
3584 final int defaultSubId = getDefaultSubscription();
3585 SubscriptionInfo info = null;
3586 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3587 info = slist.get(0);
3588 } else {
3589 for (SubscriptionInfo item : slist) {
3590 if (item.getSubscriptionId() == defaultSubId) {
3591 info = item;
3592 break;
3593 }
3594 }
3595
3596 if (info == null) {
3597 return null;
3598 }
3599 }
3600
3601 // Try and fetch the locale from the carrier properties or from the SIM language
3602 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003603 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003604 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003605 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003606 if (defaultPhone != null) {
3607 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3608 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003609 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003610 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3611 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003612 } else {
3613 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003614 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003615 }
3616 }
3617
Narayan Kamath011676f2015-07-29 12:04:08 +01003618 // The SIM language preferences only store a language (e.g. fr = French), not an
3619 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3620 // the SIM and carrier preferences does not include a country we add the country
3621 // determined from the SIM MCC to provide an exact locale.
3622 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003623 if (mccLocale != null) {
3624 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3625 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003626 }
3627
Tony Hill183b2de2015-06-24 14:53:58 +01003628 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003629 return null;
3630 }
3631
3632 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 return mSubscriptionController.getAllSubInfoList(
3636 mPhone.getContext().getOpPackageName());
3637 } finally {
3638 Binder.restoreCallingIdentity(identity);
3639 }
3640 }
3641
3642 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3643 final long identity = Binder.clearCallingIdentity();
3644 try {
3645 return mSubscriptionController.getActiveSubscriptionInfoList(
3646 mPhone.getContext().getOpPackageName());
3647 } finally {
3648 Binder.restoreCallingIdentity(identity);
3649 }
3650 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003651
3652 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003653 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3654 * representing the state of the modem.
3655 *
3656 * NOTE: This clears the modem state, so there should only every be one caller.
3657 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003658 */
3659 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003660 public void requestModemActivityInfo(ResultReceiver result) {
3661 enforceModifyPermission();
3662
3663 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3664 Bundle bundle = new Bundle();
3665 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3666 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003667 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003668
3669 /**
3670 * {@hide}
3671 * Returns the service state information on specified subscription.
3672 */
3673 @Override
3674 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3675
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003676 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003677 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003678 return null;
3679 }
3680
3681 final Phone phone = getPhone(subId);
3682 if (phone == null) {
3683 return null;
3684 }
3685
3686 return phone.getServiceState();
3687 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003688
3689 /**
3690 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3691 *
3692 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3693 * voicemail ringtone.
3694 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3695 * PhoneAccount.
3696 */
3697 @Override
3698 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003699 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003700 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003701 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003702 }
3703
fionaxu7ed723d2017-05-30 18:58:54 -07003704 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003705 }
3706
3707 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003708 * Sets the per-account voicemail ringtone.
3709 *
3710 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3711 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3712 *
3713 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3714 * voicemail ringtone.
3715 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3716 * PhoneAccount.
3717 */
3718 @Override
3719 public void setVoicemailRingtoneUri(String callingPackage,
3720 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3721 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3722 if (!TextUtils.equals(callingPackage,
3723 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3725 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3726 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003727 }
3728 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3729 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003730 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003731 }
fionaxu7ed723d2017-05-30 18:58:54 -07003732 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003733 }
3734
3735 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003736 * Returns whether vibration is set for voicemail notification in Phone settings.
3737 *
3738 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3739 * voicemail vibration setting.
3740 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3741 */
3742 @Override
3743 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003744 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003745 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003746 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003747 }
3748
fionaxu7ed723d2017-05-30 18:58:54 -07003749 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003750 }
3751
Youhan Wange64578a2016-05-02 15:32:42 -07003752 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003753 * Sets the per-account voicemail vibration.
3754 *
3755 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3756 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3757 *
3758 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3759 * voicemail vibration setting.
3760 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3761 * specific PhoneAccount.
3762 */
3763 @Override
3764 public void setVoicemailVibrationEnabled(String callingPackage,
3765 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3766 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3767 if (!TextUtils.equals(callingPackage,
3768 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3770 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3771 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003772 }
3773
3774 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3775 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003776 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003777 }
fionaxu7ed723d2017-05-30 18:58:54 -07003778 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003779 }
3780
3781 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003782 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3783 *
3784 * @throws SecurityException if the caller does not have the required permission
3785 */
3786 private void enforceReadPrivilegedPermission() {
3787 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3788 null);
3789 }
3790
3791 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003792 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3793 * permission.
3794 *
3795 * @throws SecurityException if the caller does not have the required permission
3796 */
3797 private void enforceSendSmsPermission() {
3798 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3799 }
3800
3801 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003802 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003803 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003804 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003805 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003806 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003807 ComponentName componentName =
3808 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3809 if(componentName == null) {
3810 throw new SecurityException("Caller not current active visual voicemail package[null]");
3811 }
3812 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003813 if (!callingPackage.equals(vvmPackage)) {
3814 throw new SecurityException("Caller not current active visual voicemail package[" +
3815 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003816 }
3817 }
3818
3819 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003820 * Return the application ID for the app type.
3821 *
3822 * @param subId the subscription ID that this request applies to.
3823 * @param appType the uicc app type.
3824 * @return Application ID for specificied app type, or null if no uicc.
3825 */
3826 @Override
3827 public String getAidForAppType(int subId, int appType) {
3828 enforceReadPrivilegedPermission();
3829 Phone phone = getPhone(subId);
3830 if (phone == null) {
3831 return null;
3832 }
3833 String aid = null;
3834 try {
3835 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3836 .getApplicationByType(appType).getAid();
3837 } catch (Exception e) {
3838 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3839 }
3840 return aid;
3841 }
3842
Youhan Wang4001d252016-05-11 10:29:41 -07003843 /**
3844 * Return the Electronic Serial Number.
3845 *
3846 * @param subId the subscription ID that this request applies to.
3847 * @return ESN or null if error.
3848 */
3849 @Override
3850 public String getEsn(int subId) {
3851 enforceReadPrivilegedPermission();
3852 Phone phone = getPhone(subId);
3853 if (phone == null) {
3854 return null;
3855 }
3856 String esn = null;
3857 try {
3858 esn = phone.getEsn();
3859 } catch (Exception e) {
3860 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3861 }
3862 return esn;
3863 }
3864
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003865 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003866 * Return the Preferred Roaming List Version.
3867 *
3868 * @param subId the subscription ID that this request applies to.
3869 * @return PRLVersion or null if error.
3870 */
3871 @Override
3872 public String getCdmaPrlVersion(int subId) {
3873 enforceReadPrivilegedPermission();
3874 Phone phone = getPhone(subId);
3875 if (phone == null) {
3876 return null;
3877 }
3878 String cdmaPrlVersion = null;
3879 try {
3880 cdmaPrlVersion = phone.getCdmaPrlVersion();
3881 } catch (Exception e) {
3882 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3883 }
3884 return cdmaPrlVersion;
3885 }
3886
3887 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003888 * Get snapshot of Telephony histograms
3889 * @return List of Telephony histograms
3890 * @hide
3891 */
3892 @Override
3893 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3895 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003896 return RIL.getTelephonyRILTimingHistograms();
3897 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003898
3899 /**
3900 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003901 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003902 * Require system privileges. In the future we may add this to carrier APIs.
3903 *
3904 * @return The number of carriers set successfully, should match length of carriers
3905 */
3906 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003907 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003908 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003909
Meng Wang9b7c4e92017-02-17 11:41:27 -08003910 if (carriers == null) {
3911 throw new NullPointerException("carriers cannot be null");
3912 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003913
3914 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003915 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3916 return retVal[0];
3917 }
3918
3919 /**
3920 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003921 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003922 * Require system privileges. In the future we may add this to carrier APIs.
3923 *
3924 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3925 * means all carriers are allowed.
3926 */
3927 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003928 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003929 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003930 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003931 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3932 }
3933
fionaxu59545b42016-05-25 15:53:37 -07003934 /**
3935 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3936 * @param subId the subscription ID that this action applies to.
3937 * @param enabled control enable or disable metered apns.
3938 * {@hide}
3939 */
3940 @Override
3941 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3942 enforceModifyPermission();
3943 final Phone phone = getPhone(subId);
3944 if (phone == null) {
3945 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3946 return;
3947 }
3948 try {
3949 phone.carrierActionSetMeteredApnsEnabled(enabled);
3950 } catch (Exception e) {
3951 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3952 }
3953 }
3954
3955 /**
3956 * Action set from carrier signalling broadcast receivers to enable/disable radio
3957 * @param subId the subscription ID that this action applies to.
3958 * @param enabled control enable or disable radio.
3959 * {@hide}
3960 */
3961 @Override
3962 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3963 enforceModifyPermission();
3964 final Phone phone = getPhone(subId);
3965 if (phone == null) {
3966 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3967 return;
3968 }
3969 try {
3970 phone.carrierActionSetRadioEnabled(enabled);
3971 } catch (Exception e) {
3972 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3973 }
3974 }
3975
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003976 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003977 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3978 * network status based on which carrier apps could apply actions accordingly,
3979 * enable/disable default url handler for example.
3980 *
3981 * @param subId the subscription ID that this action applies to.
3982 * @param report control start/stop reporting the default network status.
3983 * {@hide}
3984 */
3985 @Override
3986 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3987 enforceModifyPermission();
3988 final Phone phone = getPhone(subId);
3989 if (phone == null) {
3990 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3991 return;
3992 }
3993 try {
3994 phone.carrierActionReportDefaultNetworkStatus(report);
3995 } catch (Exception e) {
3996 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3997 }
3998 }
3999
4000 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004001 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4002 * bug report is being generated.
4003 */
4004 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004005 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004006 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4007 != PackageManager.PERMISSION_GRANTED) {
4008 writer.println("Permission Denial: can't dump Phone from pid="
4009 + Binder.getCallingPid()
4010 + ", uid=" + Binder.getCallingUid()
4011 + "without permission "
4012 + android.Manifest.permission.DUMP);
4013 return;
4014 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004015 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004016 }
Jack Yueb89b242016-06-22 13:27:47 -07004017
Brad Ebinger4dc095a2018-04-03 15:17:52 -07004018 @Override
4019 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4020 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4021 throws RemoteException {
4022 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4023 }
4024
Jack Yueb89b242016-06-22 13:27:47 -07004025 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004026 * Get aggregated video call data usage since boot.
4027 *
4028 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4029 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004030 * {@hide}
4031 */
4032 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004033 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004034 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4035 null);
4036
Jack Yu84291ec2017-05-26 16:07:50 -07004037 // NetworkStatsService keeps tracking the active network interface and identity. It
4038 // records the delta with the corresponding network identity. We just return the total video
4039 // call data usage snapshot since boot.
4040 Phone phone = getPhone(subId);
4041 if (phone != null) {
4042 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07004043 }
Jack Yu84291ec2017-05-26 16:07:50 -07004044 return null;
Jack Yueb89b242016-06-22 13:27:47 -07004045 }
Jack Yu75ab2952016-07-08 14:29:33 -07004046
4047 /**
4048 * Policy control of data connection. Usually used when data limit is passed.
4049 * @param enabled True if enabling the data, otherwise disabling.
4050 * @param subId Subscription index
4051 * {@hide}
4052 */
4053 @Override
4054 public void setPolicyDataEnabled(boolean enabled, int subId) {
4055 enforceModifyPermission();
4056 Phone phone = getPhone(subId);
4057 if (phone != null) {
4058 phone.setPolicyDataEnabled(enabled);
4059 }
4060 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004061
4062 /**
4063 * Get Client request stats
4064 * @return List of Client Request Stats
4065 * @hide
4066 */
4067 @Override
4068 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004070 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004071 return null;
4072 }
4073
4074 Phone phone = getPhone(subId);
4075 if (phone != null) {
4076 return phone.getClientRequestStats();
4077 }
4078
4079 return null;
4080 }
4081
4082 private WorkSource getWorkSource(WorkSource workSource, int uid) {
4083 if (workSource != null) {
4084 return workSource;
4085 }
4086
4087 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
4088 workSource = new WorkSource(uid, packageName);
4089 return workSource;
4090 }
Jack Yueb4124c2017-02-16 15:32:43 -08004091
4092 /**
Grace Chen70990072017-03-24 17:21:30 -07004093 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004094 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004095 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004096 * @param state State of SIM (power down, power up, pass through)
4097 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4098 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4099 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004100 *
4101 **/
4102 @Override
Grace Chen70990072017-03-24 17:21:30 -07004103 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004104 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004105 Phone phone = PhoneFactory.getPhone(slotIndex);
4106
Jack Yueb4124c2017-02-16 15:32:43 -08004107 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004108 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004109 }
4110 }
Shuo Qiandd210312017-04-12 22:11:33 +00004111
Tyler Gunn65d45c22017-06-05 11:22:26 -07004112 private boolean isUssdApiAllowed(int subId) {
4113 CarrierConfigManager configManager =
4114 (CarrierConfigManager) mPhone.getContext().getSystemService(
4115 Context.CARRIER_CONFIG_SERVICE);
4116 if (configManager == null) {
4117 return false;
4118 }
4119 PersistableBundle pb = configManager.getConfigForSubId(subId);
4120 if (pb == null) {
4121 return false;
4122 }
4123 return pb.getBoolean(
4124 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4125 }
4126
Shuo Qiandd210312017-04-12 22:11:33 +00004127 /**
4128 * Check if phone is in emergency callback mode
4129 * @return true if phone is in emergency callback mode
4130 * @param subId sub id
4131 */
4132 public boolean getEmergencyCallbackMode(int subId) {
4133 final Phone phone = getPhone(subId);
4134 if (phone != null) {
4135 return phone.isInEcm();
4136 } else {
4137 return false;
4138 }
4139 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004140
4141 /**
4142 * Get the current signal strength information for the given subscription.
4143 * Because this information is not updated when the device is in a low power state
4144 * it should not be relied-upon to be current.
4145 * @param subId Subscription index
4146 * @return the most recent cached signal strength info from the modem
4147 */
4148 @Override
4149 public SignalStrength getSignalStrength(int subId) {
4150 Phone p = getPhone(subId);
4151 if (p == null) {
4152 return null;
4153 }
4154
4155 return p.getSignalStrength();
4156 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004157
4158 @Override
4159 public UiccSlotInfo[] getUiccSlotsInfo() {
4160 enforceReadPrivilegedPermission();
4161
4162 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4163 if (slots == null) return null;
4164 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4165 for (int i = 0; i < slots.length; i++) {
4166 UiccSlot slot = slots[i];
4167
4168 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4169
4170 int cardState = 0;
4171 switch (slot.getCardState()) {
4172 case CARDSTATE_ABSENT:
4173 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4174 break;
4175 case CARDSTATE_PRESENT:
4176 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4177 break;
4178 case CARDSTATE_ERROR:
4179 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4180 break;
4181 case CARDSTATE_RESTRICTED:
4182 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4183 break;
4184 default:
4185 break;
4186
4187 }
4188
Qingxi Li63668902018-01-31 13:43:27 -08004189 infos[i] = new UiccSlotInfo(
Qingxi Li0ae57f72018-03-07 10:52:26 -08004190 slot.isActive(),
4191 slot.isEuicc(),
4192 cardId,
4193 cardState,
4194 slot.getPhoneId(),
4195 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004196 }
4197 return infos;
4198 }
4199
4200 @Override
4201 public boolean switchSlots(int[] physicalSlots) {
4202 enforceModifyPermission();
4203 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4204 }
Jack Yue6146032018-02-27 15:30:01 -08004205
4206 @Override
4207 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4208 enforceModifyPermission();
4209 final Phone phone = getPhone(subId);
4210 if (phone == null) {
4211 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4212 return;
4213 }
4214
4215 phone.setRadioIndicationUpdateMode(filters, mode);
4216 }
fionaxu2c8bbbd2018-03-21 00:08:13 -07004217
4218 @Override
4219 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
4220 gid1, String gid2, String plmn, String spn) {
4221 enforceModifyPermission();
4222 final Phone phone = getPhone(subId);
4223 if (phone == null) {
4224 loge("setCarrierTestOverride fails with invalid subId: " + subId);
4225 return;
4226 }
4227 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
4228 }
4229
4230 @Override
4231 public int getCarrierIdListVersion(int subId) {
4232 enforceReadPrivilegedPermission();
4233 final Phone phone = getPhone(subId);
4234 if (phone == null) {
4235 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
4236 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
4237 }
4238 return phone.getCarrierIdListVersion();
4239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004240}