blob: 0026311eb911f6b02ca0fcefefc33db98879379c [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
David Kelly5e06a7f2018-03-12 14:10:59 +0000222 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
223 private static final int MANUFACTURER_CODE_LENGTH = 8;
224
Derek Tan89e89d42014-07-08 17:00:10 -0700225 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700226 * A request object to use for transmitting data to an ICC.
227 */
228 private static final class IccAPDUArgument {
229 public int channel, cla, command, p1, p2, p3;
230 public String data;
231
232 public IccAPDUArgument(int channel, int cla, int command,
233 int p1, int p2, int p3, String data) {
234 this.channel = channel;
235 this.cla = cla;
236 this.command = command;
237 this.p1 = p1;
238 this.p2 = p2;
239 this.p3 = p3;
240 this.data = data;
241 }
242 }
243
244 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700245 * A request object to use for transmitting data to an ICC.
246 */
247 private static final class ManualNetworkSelectionArgument {
248 public OperatorInfo operatorInfo;
249 public boolean persistSelection;
250
251 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
252 this.operatorInfo = operatorInfo;
253 this.persistSelection = persistSelection;
254 }
255 }
256
257 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
259 * request after sending. The main thread will notify the request when it is complete.
260 */
261 private static final class MainThreadRequest {
262 /** The argument to use for the request */
263 public Object argument;
264 /** The result of the request that is run on the main thread */
265 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800266 // The subscriber id that this request applies to. Defaults to
267 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
268 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269
270 public MainThreadRequest(Object argument) {
271 this.argument = argument;
272 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800273
274 public MainThreadRequest(Object argument, Integer subId) {
275 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800276 if (subId != null) {
277 this.subId = subId;
278 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280 }
281
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800282 private static final class IncomingThirdPartyCallArgs {
283 public final ComponentName component;
284 public final String callId;
285 public final String callerDisplayName;
286
287 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
288 String callerDisplayName) {
289 this.component = component;
290 this.callId = callId;
291 this.callerDisplayName = callerDisplayName;
292 }
293 }
294
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295 /**
296 * A handler that processes messages on the main thread in the phone process. Since many
297 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
298 * inbound binder threads to the main thread in the phone process. The Binder thread
299 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
300 * on, which will be notified when the operation completes and will contain the result of the
301 * request.
302 *
303 * <p>If a MainThreadRequest object is provided in the msg.obj field,
304 * note that request.result must be set to something non-null for the calling thread to
305 * unblock.
306 */
307 private final class MainThreadHandler extends Handler {
308 @Override
309 public void handleMessage(Message msg) {
310 MainThreadRequest request;
311 Message onCompleted;
312 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800313 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700314 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315
316 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700317 case CMD_HANDLE_USSD_REQUEST: {
318 request = (MainThreadRequest) msg.obj;
319 final Phone phone = getPhoneFromRequest(request);
320 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
321 String ussdRequest = ussdObject.first;
322 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700323
324 if (!isUssdApiAllowed(request.subId)) {
325 // Carrier does not support use of this API, return failure.
326 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
327 UssdResponse response = new UssdResponse(ussdRequest, null);
328 Bundle returnData = new Bundle();
329 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
330 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
331
332 request.result = true;
333 synchronized (request) {
334 request.notifyAll();
335 }
336 return;
337 }
338
Tyler Gunn52dcf772017-04-26 11:30:31 -0700339 try {
340 request.result = phone != null ?
341 phone.handleUssdRequest(ussdRequest, wrappedCallback)
342 : false;
343 } catch (CallStateException cse) {
344 request.result = false;
345 }
pkanwar32d516d2016-10-14 19:37:38 -0700346 // Wake up the requesting thread
347 synchronized (request) {
348 request.notifyAll();
349 }
350 break;
351 }
352
Yorke Lee716f67e2015-06-17 15:39:16 -0700353 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700355 final Phone phone = getPhoneFromRequest(request);
356 request.result = phone != null ?
357 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
358 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 // Wake up the requesting thread
360 synchronized (request) {
361 request.notifyAll();
362 }
363 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700364 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365
366 case CMD_HANDLE_NEIGHBORING_CELL:
367 request = (MainThreadRequest) msg.obj;
368 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
369 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700370 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 break;
372
373 case EVENT_NEIGHBORING_CELL_DONE:
374 ar = (AsyncResult) msg.obj;
375 request = (MainThreadRequest) ar.userObj;
376 if (ar.exception == null && ar.result != null) {
377 request.result = ar.result;
378 } else {
379 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800380 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 }
382 // Wake up the requesting thread
383 synchronized (request) {
384 request.notifyAll();
385 }
386 break;
387
388 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700389 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800390 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700391 answerRingingCallInternal(answer_subId);
Mengjun Lengb3369682017-10-19 18:39:20 +0800392 request.result = ""; // dummy result for notifying the waiting thread
393 // Wake up the requesting thread
394 synchronized (request) {
395 request.notifyAll();
396 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 break;
398
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 case CMD_END_CALL:
400 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800401 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700402 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700403 Phone phone = getPhone(end_subId);
404 if (phone == null) {
405 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
406 break;
407 }
408 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
410 // CDMA: If the user presses the Power button we treat it as
411 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700412 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700413 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
414 // GSM: End the call as per the Phone state
415 hungUp = PhoneUtils.hangup(mCM);
416 } else {
417 throw new IllegalStateException("Unexpected phone type: " + phoneType);
418 }
419 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
420 request.result = hungUp;
421 // Wake up the requesting thread
422 synchronized (request) {
423 request.notifyAll();
424 }
425 break;
426
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700427 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700428 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700429 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800430 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700431 if (uiccCard == null) {
432 loge("iccTransmitApduLogicalChannel: No UICC");
433 request.result = new IccIoResult(0x6F, 0, (byte[])null);
434 synchronized (request) {
435 request.notifyAll();
436 }
437 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700438 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
439 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700440 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 iccArgument.channel, iccArgument.cla, iccArgument.command,
442 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700443 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700444 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 break;
446
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700448 ar = (AsyncResult) msg.obj;
449 request = (MainThreadRequest) ar.userObj;
450 if (ar.exception == null && ar.result != null) {
451 request.result = ar.result;
452 } else {
453 request.result = new IccIoResult(0x6F, 0, (byte[])null);
454 if (ar.result == null) {
455 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800456 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700457 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800458 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 } else {
460 loge("iccTransmitApduLogicalChannel: Unknown exception");
461 }
462 }
463 synchronized (request) {
464 request.notifyAll();
465 }
466 break;
467
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700468 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
469 request = (MainThreadRequest) msg.obj;
470 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800471 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 if (uiccCard == null) {
473 loge("iccTransmitApduBasicChannel: No UICC");
474 request.result = new IccIoResult(0x6F, 0, (byte[])null);
475 synchronized (request) {
476 request.notifyAll();
477 }
478 } else {
479 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
480 request);
481 uiccCard.iccTransmitApduBasicChannel(
482 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
483 iccArgument.p3, iccArgument.data, onCompleted);
484 }
485 break;
486
487 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
488 ar = (AsyncResult) msg.obj;
489 request = (MainThreadRequest) ar.userObj;
490 if (ar.exception == null && ar.result != null) {
491 request.result = ar.result;
492 } else {
493 request.result = new IccIoResult(0x6F, 0, (byte[])null);
494 if (ar.result == null) {
495 loge("iccTransmitApduBasicChannel: Empty response");
496 } else if (ar.exception instanceof CommandException) {
497 loge("iccTransmitApduBasicChannel: CommandException: " +
498 ar.exception);
499 } else {
500 loge("iccTransmitApduBasicChannel: Unknown exception");
501 }
502 }
503 synchronized (request) {
504 request.notifyAll();
505 }
506 break;
507
508 case CMD_EXCHANGE_SIM_IO:
509 request = (MainThreadRequest) msg.obj;
510 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800511 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700512 if (uiccCard == null) {
513 loge("iccExchangeSimIO: No UICC");
514 request.result = new IccIoResult(0x6F, 0, (byte[])null);
515 synchronized (request) {
516 request.notifyAll();
517 }
518 } else {
519 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
520 request);
521 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
522 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
523 iccArgument.data, onCompleted);
524 }
525 break;
526
527 case EVENT_EXCHANGE_SIM_IO_DONE:
528 ar = (AsyncResult) msg.obj;
529 request = (MainThreadRequest) ar.userObj;
530 if (ar.exception == null && ar.result != null) {
531 request.result = ar.result;
532 } else {
533 request.result = new IccIoResult(0x6f, 0, (byte[])null);
534 }
535 synchronized (request) {
536 request.notifyAll();
537 }
538 break;
539
Derek Tan4d5e5c12014-02-04 11:54:58 -0800540 case CMD_SEND_ENVELOPE:
541 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800542 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 if (uiccCard == null) {
544 loge("sendEnvelopeWithStatus: No UICC");
545 request.result = new IccIoResult(0x6F, 0, (byte[])null);
546 synchronized (request) {
547 request.notifyAll();
548 }
549 } else {
550 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
551 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
552 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800553 break;
554
555 case EVENT_SEND_ENVELOPE_DONE:
556 ar = (AsyncResult) msg.obj;
557 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700558 if (ar.exception == null && ar.result != null) {
559 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800560 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700561 request.result = new IccIoResult(0x6F, 0, (byte[])null);
562 if (ar.result == null) {
563 loge("sendEnvelopeWithStatus: Empty response");
564 } else if (ar.exception instanceof CommandException) {
565 loge("sendEnvelopeWithStatus: CommandException: " +
566 ar.exception);
567 } else {
568 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
569 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800570 }
571 synchronized (request) {
572 request.notifyAll();
573 }
574 break;
575
Shishir Agrawal566b7612013-10-28 14:41:00 -0700576 case CMD_OPEN_CHANNEL:
577 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800578 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800579 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700580 if (uiccCard == null) {
581 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800582 request.result = new IccOpenLogicalChannelResponse(-1,
583 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700584 synchronized (request) {
585 request.notifyAll();
586 }
587 } else {
588 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800589 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
590 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 break;
593
594 case EVENT_OPEN_CHANNEL_DONE:
595 ar = (AsyncResult) msg.obj;
596 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 int[] result = (int[]) ar.result;
600 int channelId = result[0];
601 byte[] selectResponse = null;
602 if (result.length > 1) {
603 selectResponse = new byte[result.length - 1];
604 for (int i = 1; i < result.length; ++i) {
605 selectResponse[i - 1] = (byte) result[i];
606 }
607 }
608 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700609 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700610 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.result == null) {
612 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 if (ar.exception != null) {
615 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
616 }
617
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700618 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700619 if (ar.exception instanceof CommandException) {
620 CommandException.Error error =
621 ((CommandException) (ar.exception)).getCommandError();
622 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700623 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700624 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700626 }
627 }
628 openChannelResp = new IccOpenLogicalChannelResponse(
629 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700631 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 synchronized (request) {
633 request.notifyAll();
634 }
635 break;
636
637 case CMD_CLOSE_CHANNEL:
638 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800639 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 if (uiccCard == null) {
641 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900642 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 synchronized (request) {
644 request.notifyAll();
645 }
646 } else {
647 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
648 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
649 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
652 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800653 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
654 break;
655
656 case CMD_NV_READ_ITEM:
657 request = (MainThreadRequest) msg.obj;
658 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
659 mPhone.nvReadItem((Integer) request.argument, onCompleted);
660 break;
661
662 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 ar = (AsyncResult) msg.obj;
664 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800665 if (ar.exception == null && ar.result != null) {
666 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800668 request.result = "";
669 if (ar.result == null) {
670 loge("nvReadItem: Empty response");
671 } else if (ar.exception instanceof CommandException) {
672 loge("nvReadItem: CommandException: " +
673 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800675 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 }
677 }
678 synchronized (request) {
679 request.notifyAll();
680 }
681 break;
682
Jake Hambye994d462014-02-03 13:10:13 -0800683 case CMD_NV_WRITE_ITEM:
684 request = (MainThreadRequest) msg.obj;
685 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
686 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
687 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
688 break;
689
690 case EVENT_NV_WRITE_ITEM_DONE:
691 handleNullReturnEvent(msg, "nvWriteItem");
692 break;
693
694 case CMD_NV_WRITE_CDMA_PRL:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
697 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
698 break;
699
700 case EVENT_NV_WRITE_CDMA_PRL_DONE:
701 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
702 break;
703
704 case CMD_NV_RESET_CONFIG:
705 request = (MainThreadRequest) msg.obj;
706 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
707 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
708 break;
709
710 case EVENT_NV_RESET_CONFIG_DONE:
711 handleNullReturnEvent(msg, "nvResetConfig");
712 break;
713
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 case CMD_GET_PREFERRED_NETWORK_TYPE:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700717 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800718 break;
719
720 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
721 ar = (AsyncResult) msg.obj;
722 request = (MainThreadRequest) ar.userObj;
723 if (ar.exception == null && ar.result != null) {
724 request.result = ar.result; // Integer
725 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800726 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 if (ar.result == null) {
728 loge("getPreferredNetworkType: Empty response");
729 } else if (ar.exception instanceof CommandException) {
730 loge("getPreferredNetworkType: CommandException: " +
731 ar.exception);
732 } else {
733 loge("getPreferredNetworkType: Unknown exception");
734 }
735 }
736 synchronized (request) {
737 request.notifyAll();
738 }
739 break;
740
741 case CMD_SET_PREFERRED_NETWORK_TYPE:
742 request = (MainThreadRequest) msg.obj;
743 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
744 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700745 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800746 break;
747
748 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
749 handleNullReturnEvent(msg, "setPreferredNetworkType");
750 break;
751
Shuo Qian74b16b12018-04-27 01:32:07 +0000752 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
753 request = (MainThreadRequest)msg.obj;
754 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
755 mPhone.invokeOemRilRequestRaw((byte[])request.argument, onCompleted);
756 break;
757
758 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
759 ar = (AsyncResult)msg.obj;
760 request = (MainThreadRequest)ar.userObj;
761 request.result = ar;
762 synchronized (request) {
763 request.notifyAll();
764 }
765 break;
766
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800767 case CMD_SET_VOICEMAIL_NUMBER:
768 request = (MainThreadRequest) msg.obj;
769 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
770 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800771 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
772 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800773 break;
774
775 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
776 handleNullReturnEvent(msg, "setVoicemailNumber");
777 break;
778
Stuart Scott54788802015-03-30 13:18:01 -0700779 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
782 request);
783 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
784 break;
785
786 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
787 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
788 break;
789
Shishir Agrawal302c8692015-06-19 13:49:39 -0700790 case CMD_PERFORM_NETWORK_SCAN:
791 request = (MainThreadRequest) msg.obj;
792 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
793 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
794 break;
795
796 case EVENT_PERFORM_NETWORK_SCAN_DONE:
797 ar = (AsyncResult) msg.obj;
798 request = (MainThreadRequest) ar.userObj;
799 CellNetworkScanResult cellScanResult;
800 if (ar.exception == null && ar.result != null) {
801 cellScanResult = new CellNetworkScanResult(
802 CellNetworkScanResult.STATUS_SUCCESS,
803 (List<OperatorInfo>) ar.result);
804 } else {
805 if (ar.result == null) {
806 loge("getCellNetworkScanResults: Empty response");
807 }
808 if (ar.exception != null) {
809 loge("getCellNetworkScanResults: Exception: " + ar.exception);
810 }
811 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
812 if (ar.exception instanceof CommandException) {
813 CommandException.Error error =
814 ((CommandException) (ar.exception)).getCommandError();
815 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
816 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
817 } else if (error == CommandException.Error.GENERIC_FAILURE) {
818 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
819 }
820 }
821 cellScanResult = new CellNetworkScanResult(errorCode, null);
822 }
823 request.result = cellScanResult;
824 synchronized (request) {
825 request.notifyAll();
826 }
827 break;
828
829 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
830 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700831 ManualNetworkSelectionArgument selArg =
832 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700833 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
834 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700835 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
836 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700837 break;
838
839 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
840 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
841 break;
842
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700843 case CMD_GET_MODEM_ACTIVITY_INFO:
844 request = (MainThreadRequest) msg.obj;
845 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700846 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700847 break;
848
849 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null && ar.result != null) {
853 request.result = ar.result;
854 } else {
855 if (ar.result == null) {
856 loge("queryModemActivityInfo: Empty response");
857 } else if (ar.exception instanceof CommandException) {
858 loge("queryModemActivityInfo: CommandException: " +
859 ar.exception);
860 } else {
861 loge("queryModemActivityInfo: Unknown exception");
862 }
863 }
Amit Mahajand4766222016-01-28 15:28:28 -0800864 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
865 if (request.result == null) {
866 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
867 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700868 synchronized (request) {
869 request.notifyAll();
870 }
871 break;
872
Meng Wang1a7c35a2016-05-05 20:56:15 -0700873 case CMD_SET_ALLOWED_CARRIERS:
874 request = (MainThreadRequest) msg.obj;
875 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
876 mPhone.setAllowedCarriers(
877 (List<CarrierIdentifier>) request.argument,
878 onCompleted);
879 break;
880
881 case EVENT_SET_ALLOWED_CARRIERS_DONE:
882 ar = (AsyncResult) msg.obj;
883 request = (MainThreadRequest) ar.userObj;
884 if (ar.exception == null && ar.result != null) {
885 request.result = ar.result;
886 } else {
887 if (ar.result == null) {
888 loge("setAllowedCarriers: Empty response");
889 } else if (ar.exception instanceof CommandException) {
890 loge("setAllowedCarriers: CommandException: " +
891 ar.exception);
892 } else {
893 loge("setAllowedCarriers: Unknown exception");
894 }
895 }
896 // Result cannot be null. Return -1 on error.
897 if (request.result == null) {
898 request.result = new int[]{-1};
899 }
900 synchronized (request) {
901 request.notifyAll();
902 }
903 break;
904
905 case CMD_GET_ALLOWED_CARRIERS:
906 request = (MainThreadRequest) msg.obj;
907 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
908 mPhone.getAllowedCarriers(onCompleted);
909 break;
910
911 case EVENT_GET_ALLOWED_CARRIERS_DONE:
912 ar = (AsyncResult) msg.obj;
913 request = (MainThreadRequest) ar.userObj;
914 if (ar.exception == null && ar.result != null) {
915 request.result = ar.result;
916 } else {
917 if (ar.result == null) {
918 loge("getAllowedCarriers: Empty response");
919 } else if (ar.exception instanceof CommandException) {
920 loge("getAllowedCarriers: CommandException: " +
921 ar.exception);
922 } else {
923 loge("getAllowedCarriers: Unknown exception");
924 }
925 }
926 // Result cannot be null. Return empty list of CarrierIdentifier.
927 if (request.result == null) {
928 request.result = new ArrayList<CarrierIdentifier>(0);
929 }
930 synchronized (request) {
931 request.notifyAll();
932 }
933 break;
934
Nathan Haroldb3014052017-01-25 15:57:32 -0800935 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
936 ar = (AsyncResult) msg.obj;
937 request = (MainThreadRequest) ar.userObj;
938 if (ar.exception == null && ar.result != null) {
939 request.result = ar.result;
940 } else {
941 request.result = new IllegalArgumentException(
942 "Failed to retrieve Forbidden Plmns");
943 if (ar.result == null) {
944 loge("getForbiddenPlmns: Empty response");
945 } else {
946 loge("getForbiddenPlmns: Unknown exception");
947 }
948 }
949 synchronized (request) {
950 request.notifyAll();
951 }
952 break;
953
954 case CMD_GET_FORBIDDEN_PLMNS:
955 request = (MainThreadRequest) msg.obj;
956 uiccCard = getUiccCardFromRequest(request);
957 if (uiccCard == null) {
958 loge("getForbiddenPlmns() UiccCard is null");
959 request.result = new IllegalArgumentException(
960 "getForbiddenPlmns() UiccCard is null");
961 synchronized (request) {
962 request.notifyAll();
963 }
964 break;
965 }
966 Integer appType = (Integer) request.argument;
967 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
968 if (uiccApp == null) {
969 loge("getForbiddenPlmns() no app with specified type -- "
970 + appType);
971 request.result = new IllegalArgumentException("Failed to get UICC App");
972 synchronized (request) {
973 request.notifyAll();
974 }
975 break;
976 } else {
977 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
978 + " specified type -- " + appType);
979 }
980 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
981 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
982 onCompleted);
983 break;
984
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000985 case CMD_SWITCH_SLOTS:
986 request = (MainThreadRequest) msg.obj;
987 int[] physicalSlots = (int[]) request.argument;
988 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
989 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
990 break;
991
992 case EVENT_SWITCH_SLOTS_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 request.result = (ar.exception == null);
996 synchronized (request) {
997 request.notifyAll();
998 }
999 break;
1000
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001001 default:
1002 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1003 break;
1004 }
1005 }
Jake Hambye994d462014-02-03 13:10:13 -08001006
1007 private void handleNullReturnEvent(Message msg, String command) {
1008 AsyncResult ar = (AsyncResult) msg.obj;
1009 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1010 if (ar.exception == null) {
1011 request.result = true;
1012 } else {
1013 request.result = false;
1014 if (ar.exception instanceof CommandException) {
1015 loge(command + ": CommandException: " + ar.exception);
1016 } else {
1017 loge(command + ": Unknown exception");
1018 }
1019 }
1020 synchronized (request) {
1021 request.notifyAll();
1022 }
1023 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001024 }
1025
1026 /**
1027 * Posts the specified command to be executed on the main thread,
1028 * waits for the request to complete, and returns the result.
1029 * @see #sendRequestAsync
1030 */
1031 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001032 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001033 }
1034
1035 /**
1036 * Posts the specified command to be executed on the main thread,
1037 * waits for the request to complete, and returns the result.
1038 * @see #sendRequestAsync
1039 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001040 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001041 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1042 throw new RuntimeException("This method will deadlock if called from the main thread.");
1043 }
1044
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001045 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001046 Message msg = mMainThreadHandler.obtainMessage(command, request);
1047 msg.sendToTarget();
1048
1049 // Wait for the request to complete
1050 synchronized (request) {
1051 while (request.result == null) {
1052 try {
1053 request.wait();
1054 } catch (InterruptedException e) {
1055 // Do nothing, go back and wait until the request is complete
1056 }
1057 }
1058 }
1059 return request.result;
1060 }
1061
1062 /**
1063 * Asynchronous ("fire and forget") version of sendRequest():
1064 * Posts the specified command to be executed on the main thread, and
1065 * returns immediately.
1066 * @see #sendRequest
1067 */
1068 private void sendRequestAsync(int command) {
1069 mMainThreadHandler.sendEmptyMessage(command);
1070 }
1071
1072 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001073 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1074 * @see {@link #sendRequest(int,Object)}
1075 */
1076 private void sendRequestAsync(int command, Object argument) {
1077 MainThreadRequest request = new MainThreadRequest(argument);
1078 Message msg = mMainThreadHandler.obtainMessage(command, request);
1079 msg.sendToTarget();
1080 }
1081
1082 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 * Initialize the singleton PhoneInterfaceManager instance.
1084 * This is only done once, at startup, from PhoneApp.onCreate().
1085 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001086 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001087 synchronized (PhoneInterfaceManager.class) {
1088 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001089 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001090 } else {
1091 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1092 }
1093 return sInstance;
1094 }
1095 }
1096
1097 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001098 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001099 mApp = app;
1100 mPhone = phone;
1101 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001102 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001103 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1104 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001105 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001106 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001107 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001108 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001109
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001110 publish();
1111 }
1112
1113 private void publish() {
1114 if (DBG) log("publish: " + this);
1115
1116 ServiceManager.addService("phone", this);
1117 }
1118
Stuart Scott584921c2015-01-15 17:10:34 -08001119 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001120 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1121 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001122 }
1123
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001124 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1125 Phone phone = getPhoneFromRequest(request);
1126 return phone == null ? null :
1127 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1128 }
1129
Wink Saville36469e72014-06-11 15:17:00 -07001130 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001131 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001132 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001133 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001134 //
1135 // Implementation of the ITelephony interface.
1136 //
1137
1138 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001139 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001140 }
1141
Wink Savilleb564aae2014-10-23 10:18:09 -07001142 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001143 if (DBG) log("dial: " + number);
1144 // No permission check needed here: This is just a wrapper around the
1145 // ACTION_DIAL intent, which is available to any app since it puts up
1146 // the UI before it does anything.
1147
1148 String url = createTelUrl(number);
1149 if (url == null) {
1150 return;
1151 }
1152
1153 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001154 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001155 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1156 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1157 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1158 mApp.startActivity(intent);
1159 }
1160 }
1161
1162 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001163 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001164 }
1165
Wink Savilleb564aae2014-10-23 10:18:09 -07001166 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001167 if (DBG) log("call: " + number);
1168
1169 // This is just a wrapper around the ACTION_CALL intent, but we still
1170 // need to do a permission check since we're calling startActivity()
1171 // from the context of the phone app.
1172 enforceCallPermission();
1173
1174 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1175 != AppOpsManager.MODE_ALLOWED) {
1176 return;
1177 }
1178
1179 String url = createTelUrl(number);
1180 if (url == null) {
1181 return;
1182 }
1183
Wink Saville08874612014-08-31 19:19:58 -07001184 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001185 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001186 if (slist != null) {
1187 for (SubscriptionInfo subInfoRecord : slist) {
1188 if (subInfoRecord.getSubscriptionId() == subId) {
1189 isValid = true;
1190 break;
1191 }
Wink Saville08874612014-08-31 19:19:58 -07001192 }
1193 }
1194 if (isValid == false) {
1195 return;
1196 }
1197
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001198 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001199 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001200 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1201 mApp.startActivity(intent);
1202 }
1203
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001204 /**
1205 * End a call based on call state
1206 * @return true is a call was ended
1207 */
1208 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001209 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001210 }
1211
1212 /**
1213 * End a call based on the call state of the subId
1214 * @return true is a call was ended
1215 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001216 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001217 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001218 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 }
1220
1221 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001222 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001223 }
1224
Wink Savilleb564aae2014-10-23 10:18:09 -07001225 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001226 if (DBG) log("answerRingingCall...");
1227 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1228 // but that can probably wait till the big TelephonyManager API overhaul.
1229 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1230 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001231 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232 }
1233
1234 /**
1235 * Make the actual telephony calls to implement answerRingingCall().
1236 * This should only be called from the main thread of the Phone app.
1237 * @see #answerRingingCall
1238 *
1239 * TODO: it would be nice to return true if we answered the call, or
1240 * false if there wasn't actually a ringing incoming call, or some
1241 * other error occurred. (In other words, pass back the return value
1242 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1243 * But that would require calling this method via sendRequest() rather
1244 * than sendRequestAsync(), and right now we don't actually *need* that
1245 * return value, so let's just return void for now.
1246 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001247 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001248 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001250 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1251 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001252 if (hasActiveCall && hasHoldingCall) {
1253 // Both lines are in use!
1254 // TODO: provide a flag to let the caller specify what
1255 // policy to use if both lines are in use. (The current
1256 // behavior is hardwired to "answer incoming, end ongoing",
1257 // which is how the CALL button is specced to behave.)
1258 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1259 return;
1260 } else {
1261 // answerCall() will automatically hold the current active
1262 // call, if there is one.
1263 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1264 return;
1265 }
1266 } else {
1267 // No call was ringing.
1268 return;
1269 }
1270 }
1271
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001272 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001273 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001275 public void silenceRinger() {
1276 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 }
1278
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001279 @Override
1280 public boolean isOffhook(String callingPackage) {
1281 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001282 }
1283
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001284 @Override
1285 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001286 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001287 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001288 return false;
1289 }
1290
Sanket Padawe356d7632015-06-22 14:03:32 -07001291 final Phone phone = getPhone(subId);
1292 if (phone != null) {
1293 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1294 } else {
1295 return false;
1296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001297 }
1298
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001299 @Override
1300 public boolean isRinging(String callingPackage) {
1301 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001302 }
1303
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001304 @Override
1305 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001307 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001308 return false;
1309 }
1310
Sanket Padawe356d7632015-06-22 14:03:32 -07001311 final Phone phone = getPhone(subId);
1312 if (phone != null) {
1313 return (phone.getState() == PhoneConstants.State.RINGING);
1314 } else {
1315 return false;
1316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 }
1318
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001319 @Override
1320 public boolean isIdle(String callingPackage) {
1321 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001322 }
1323
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001324 @Override
1325 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001327 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001328 return false;
1329 }
1330
Sanket Padawe356d7632015-06-22 14:03:32 -07001331 final Phone phone = getPhone(subId);
1332 if (phone != null) {
1333 return (phone.getState() == PhoneConstants.State.IDLE);
1334 } else {
1335 return false;
1336 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001337 }
1338
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001340 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001341 }
1342
Wink Savilleb564aae2014-10-23 10:18:09 -07001343 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001344 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001345 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1346 }
1347
1348 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001349 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001350 }
1351
Wink Savilleb564aae2014-10-23 10:18:09 -07001352 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001353 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001354 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1355 }
1356
1357 /** {@hide} */
1358 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001359 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001360 }
1361
Wink Savilleb564aae2014-10-23 10:18:09 -07001362 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001363 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001364 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365 checkSimPin.start();
1366 return checkSimPin.unlockSim(null, pin);
1367 }
1368
Wink Saville9de0f752013-10-22 19:04:03 -07001369 /** {@hide} */
1370 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001371 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001372 }
1373
Wink Savilleb564aae2014-10-23 10:18:09 -07001374 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001376 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 checkSimPuk.start();
1378 return checkSimPuk.unlockSim(puk, pin);
1379 }
1380
1381 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001382 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001383 * a synchronous one.
1384 */
1385 private static class UnlockSim extends Thread {
1386
1387 private final IccCard mSimCard;
1388
1389 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001390 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1391 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392
1393 // For replies from SimCard interface
1394 private Handler mHandler;
1395
1396 // For async handler to identify request type
1397 private static final int SUPPLY_PIN_COMPLETE = 100;
1398
1399 public UnlockSim(IccCard simCard) {
1400 mSimCard = simCard;
1401 }
1402
1403 @Override
1404 public void run() {
1405 Looper.prepare();
1406 synchronized (UnlockSim.this) {
1407 mHandler = new Handler() {
1408 @Override
1409 public void handleMessage(Message msg) {
1410 AsyncResult ar = (AsyncResult) msg.obj;
1411 switch (msg.what) {
1412 case SUPPLY_PIN_COMPLETE:
1413 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1414 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001415 mRetryCount = msg.arg1;
1416 if (ar.exception != null) {
1417 if (ar.exception instanceof CommandException &&
1418 ((CommandException)(ar.exception)).getCommandError()
1419 == CommandException.Error.PASSWORD_INCORRECT) {
1420 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1421 } else {
1422 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1423 }
1424 } else {
1425 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427 mDone = true;
1428 UnlockSim.this.notifyAll();
1429 }
1430 break;
1431 }
1432 }
1433 };
1434 UnlockSim.this.notifyAll();
1435 }
1436 Looper.loop();
1437 }
1438
1439 /*
1440 * Use PIN or PUK to unlock SIM card
1441 *
1442 * If PUK is null, unlock SIM card with PIN
1443 *
1444 * If PUK is not null, unlock SIM card with PUK and set PIN code
1445 */
Wink Saville9de0f752013-10-22 19:04:03 -07001446 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001447
1448 while (mHandler == null) {
1449 try {
1450 wait();
1451 } catch (InterruptedException e) {
1452 Thread.currentThread().interrupt();
1453 }
1454 }
1455 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1456
1457 if (puk == null) {
1458 mSimCard.supplyPin(pin, callback);
1459 } else {
1460 mSimCard.supplyPuk(puk, pin, callback);
1461 }
1462
1463 while (!mDone) {
1464 try {
1465 Log.d(LOG_TAG, "wait for done");
1466 wait();
1467 } catch (InterruptedException e) {
1468 // Restore the interrupted status
1469 Thread.currentThread().interrupt();
1470 }
1471 }
1472 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001473 int[] resultArray = new int[2];
1474 resultArray[0] = mResult;
1475 resultArray[1] = mRetryCount;
1476 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001477 }
1478 }
1479
1480 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001481 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001482
1483 }
1484
Wink Savilleb564aae2014-10-23 10:18:09 -07001485 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486 // No permission check needed here: this call is harmless, and it's
1487 // needed for the ServiceState.requestStateUpdate() call (which is
1488 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001489 final Phone phone = getPhone(subId);
1490 if (phone != null) {
1491 phone.updateServiceLocation();
1492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001493 }
1494
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001495 @Override
1496 public boolean isRadioOn(String callingPackage) {
1497 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001498 }
1499
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001500 @Override
1501 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001503 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001504 return false;
1505 }
1506 return isRadioOnForSubscriber(subId);
1507 }
1508
1509 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001510 final Phone phone = getPhone(subId);
1511 if (phone != null) {
1512 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1513 } else {
1514 return false;
1515 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001516 }
1517
1518 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001519 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001520
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001521 }
Wink Saville36469e72014-06-11 15:17:00 -07001522
Wink Savilleb564aae2014-10-23 10:18:09 -07001523 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001525 final Phone phone = getPhone(subId);
1526 if (phone != null) {
1527 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1528 }
Wink Saville36469e72014-06-11 15:17:00 -07001529 }
1530
1531 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001532 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001533 }
1534
Wink Savilleb564aae2014-10-23 10:18:09 -07001535 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001536 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001537 final Phone phone = getPhone(subId);
1538 if (phone == null) {
1539 return false;
1540 }
1541 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001542 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001543 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 }
1545 return true;
1546 }
Wink Saville36469e72014-06-11 15:17:00 -07001547
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001548 public boolean needMobileRadioShutdown() {
1549 /*
1550 * If any of the Radios are available, it will need to be
1551 * shutdown. So return true if any Radio is available.
1552 */
1553 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1554 Phone phone = PhoneFactory.getPhone(i);
1555 if (phone != null && phone.isRadioAvailable()) return true;
1556 }
1557 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1558 return false;
1559 }
1560
1561 public void shutdownMobileRadios() {
1562 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1563 logv("Shutting down Phone " + i);
1564 shutdownRadioUsingPhoneId(i);
1565 }
1566 }
1567
1568 private void shutdownRadioUsingPhoneId(int phoneId) {
1569 enforceModifyPermission();
1570 Phone phone = PhoneFactory.getPhone(phoneId);
1571 if (phone != null && phone.isRadioAvailable()) {
1572 phone.shutdownRadio();
1573 }
1574 }
1575
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001576 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001577 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001578 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1579 if (defaultPhone != null) {
1580 defaultPhone.setRadioPower(turnOn);
1581 return true;
1582 } else {
1583 loge("There's no default phone.");
1584 return false;
1585 }
Wink Saville36469e72014-06-11 15:17:00 -07001586 }
1587
Wink Savilleb564aae2014-10-23 10:18:09 -07001588 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001589 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001590 final Phone phone = getPhone(subId);
1591 if (phone != null) {
1592 phone.setRadioPower(turnOn);
1593 return true;
1594 } else {
1595 return false;
1596 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597 }
1598
Wink Saville36469e72014-06-11 15:17:00 -07001599 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001600 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 public boolean enableDataConnectivity() {
1602 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001603 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001604 final Phone phone = getPhone(subId);
1605 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001606 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001607 return true;
1608 } else {
1609 return false;
1610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001611 }
1612
Wink Saville36469e72014-06-11 15:17:00 -07001613 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001614 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 public boolean disableDataConnectivity() {
1616 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001617 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001618 final Phone phone = getPhone(subId);
1619 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001620 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001621 return true;
1622 } else {
1623 return false;
1624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 }
1626
Sanket Padawe356d7632015-06-22 14:03:32 -07001627 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001628 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001629 final Phone phone = getPhone(subId);
1630 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001631 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001632 } else {
1633 return false;
1634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 }
1636
1637 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001638 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001639 }
1640
pkanwarae03a6b2016-11-06 20:37:09 -08001641 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001642 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001643 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1644 return;
1645 }
1646 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1647 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1648 };
1649
Wink Savilleb564aae2014-10-23 10:18:09 -07001650 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001652 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1653 return false;
1654 }
Wink Saville36469e72014-06-11 15:17:00 -07001655 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 }
1657
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001659 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001660 }
1661
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001662 public int getCallStateForSlot(int slotIndex) {
1663 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001664 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001665 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 }
1667
Sanket Padawe356d7632015-06-22 14:03:32 -07001668 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001670 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001671 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001672 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001673 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001674 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 }
1677
Sanket Padawe356d7632015-06-22 14:03:32 -07001678 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001680 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001681 if (phone != null) {
1682 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1683 } else {
1684 return TelephonyManager.DATA_ACTIVITY_NONE;
1685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 }
1687
1688 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001689 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001690 mPhone.getContext().getSystemService(AppOpsManager.class)
1691 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001692 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001693 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001694 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 }
1696
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001697 if (DBG_LOC) log("getCellLocation: is active user");
1698 Bundle data = new Bundle();
1699 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1700 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 return null;
1702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001704 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1705 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1706 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001707 }
1708
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001710 public String getNetworkCountryIsoForPhone(int phoneId) {
1711 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1712 // registered cell info, so return a NULL country instead.
1713 final long identity = Binder.clearCallingIdentity();
1714 try {
1715 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu8e4fdc22018-04-13 14:05:37 -07001716 // Todo: fix this when we can get the actual cellular network info when the device
1717 // is on IWLAN.
Jonathan Basseri03923952017-07-19 12:22:35 -07001718 if (TelephonyManager.NETWORK_TYPE_IWLAN
1719 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1720 return "";
1721 }
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
1724 }
Jack Yu8e4fdc22018-04-13 14:05:37 -07001725
1726 Phone phone = PhoneFactory.getPhone(phoneId);
1727 if (phone != null) {
1728 ServiceStateTracker sst = phone.getServiceStateTracker();
1729 if (sst != null) {
1730 LocaleTracker lt = sst.getLocaleTracker();
1731 if (lt != null) {
1732 return lt.getCurrentCountry();
1733 }
1734 }
1735 }
1736 return "";
Jonathan Basseri03923952017-07-19 12:22:35 -07001737 }
1738
1739 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001741 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001742 }
1743
Sanket Padawe356d7632015-06-22 14:03:32 -07001744 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001745 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 mApp.enforceCallingOrSelfPermission(
1747 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 final Phone phone = getPhone(subId);
1749 if (phone != null) {
1750 phone.enableLocationUpdates();
1751 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 }
1753
1754 @Override
1755 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001756 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001757 }
1758
Sanket Padawe356d7632015-06-22 14:03:32 -07001759 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001760 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 mApp.enforceCallingOrSelfPermission(
1762 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001763 final Phone phone = getPhone(subId);
1764 if (phone != null) {
1765 phone.disableLocationUpdates();
1766 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001767 }
1768
1769 @Override
1770 @SuppressWarnings("unchecked")
1771 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001772 mPhone.getContext().getSystemService(AppOpsManager.class)
1773 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001774 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001775 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001776 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 }
1778
1779 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1780 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1781 return null;
1782 }
Svetoslav64fad262015-04-14 14:35:21 -07001783
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001784 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001786 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001788 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1789 try {
1790 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1791 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1792 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1793 } catch (RuntimeException e) {
1794 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001795 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001796 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 }
1798
1799
1800 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001801 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001802 mPhone.getContext().getSystemService(AppOpsManager.class)
1803 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001804 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001805 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001806 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001807 }
1808
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001809 if (DBG_LOC) log("getAllCellInfo: is active user");
1810 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1811 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1812 for (Phone phone : PhoneFactory.getPhones()) {
1813 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1814 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001816 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 }
1818
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001819 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001821 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001822 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1823 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
1825
Shishir Agrawala9f32182016-04-12 12:00:16 -07001826 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001827 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001828 Phone phone = PhoneFactory.getPhone(slotIndex);
1829 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001830 return null;
1831 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001832 int subId = phone.getSubId();
1833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1834 mApp, subId, callingPackage, "getImeiForSlot")) {
1835 return null;
1836 }
1837 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001838 }
1839
1840 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001841 public String getTypeAllocationCodeForSlot(int slotIndex) {
1842 Phone phone = PhoneFactory.getPhone(slotIndex);
1843 String tac = null;
1844 if (phone != null) {
1845 String imei = phone.getImei();
1846 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
1847 }
1848 return tac;
1849 }
1850
1851 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001852 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001853 Phone phone = PhoneFactory.getPhone(slotIndex);
1854 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001855 return null;
1856 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001857 int subId = phone.getSubId();
1858 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1859 mApp, subId, callingPackage, "getMeidForSlot")) {
1860 return null;
1861 }
1862 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001863 }
1864
1865 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00001866 public String getManufacturerCodeForSlot(int slotIndex) {
1867 Phone phone = PhoneFactory.getPhone(slotIndex);
1868 String manufacturerCode = null;
1869 if (phone != null) {
1870 String meid = phone.getMeid();
1871 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
1872 }
1873 return manufacturerCode;
1874 }
1875
1876 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001877 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001878 Phone phone = PhoneFactory.getPhone(slotIndex);
1879 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001880 return null;
1881 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001882 int subId = phone.getSubId();
1883 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1884 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1885 return null;
1886 }
1887 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001888 }
1889
fionaxuf32acdf2017-11-27 22:51:16 -08001890 @Override
1891 public int getSubscriptionCarrierId(int subId) {
1892 final Phone phone = getPhone(subId);
1893 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1894 }
1895
1896 @Override
1897 public String getSubscriptionCarrierName(int subId) {
1898 final Phone phone = getPhone(subId);
1899 return phone == null ? null : phone.getCarrierName();
1900 }
1901
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 //
1903 // Internal helper methods.
1904 //
1905
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001906 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001907 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1908 *
1909 * @throws SecurityException if the caller does not have the required permission
1910 */
1911 private void enforceModifyPermission() {
1912 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1913 }
1914
1915 /**
1916 * Make sure the caller has the CALL_PHONE permission.
1917 *
1918 * @throws SecurityException if the caller does not have the required permission
1919 */
1920 private void enforceCallPermission() {
1921 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1922 }
1923
Stuart Scott8eef64f2015-04-08 15:13:54 -07001924 private void enforceConnectivityInternalPermission() {
1925 mApp.enforceCallingOrSelfPermission(
1926 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1927 "ConnectivityService");
1928 }
1929
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001930 private String createTelUrl(String number) {
1931 if (TextUtils.isEmpty(number)) {
1932 return null;
1933 }
1934
Jake Hambye994d462014-02-03 13:10:13 -08001935 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
Ihab Awadf9e92732013-12-05 18:02:52 -08001938 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1940 }
1941
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001942 private static void logv(String msg) {
1943 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1944 }
1945
Ihab Awadf9e92732013-12-05 18:02:52 -08001946 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1948 }
1949
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001950 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001952 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001953 }
1954
Sanket Padawe356d7632015-06-22 14:03:32 -07001955 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001956 public int getActivePhoneTypeForSlot(int slotIndex) {
1957 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001958 if (phone == null) {
1959 return PhoneConstants.PHONE_TYPE_NONE;
1960 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001961 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001962 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001963 }
1964
1965 /**
1966 * Returns the CDMA ERI icon index to display
1967 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001968 @Override
1969 public int getCdmaEriIconIndex(String callingPackage) {
1970 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001971 }
1972
Sanket Padawe356d7632015-06-22 14:03:32 -07001973 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001974 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001975 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001976 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001977 return -1;
1978 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001979 final Phone phone = getPhone(subId);
1980 if (phone != null) {
1981 return phone.getCdmaEriIconIndex();
1982 } else {
1983 return -1;
1984 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001985 }
1986
1987 /**
1988 * Returns the CDMA ERI icon mode,
1989 * 0 - ON
1990 * 1 - FLASHING
1991 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001992 @Override
1993 public int getCdmaEriIconMode(String callingPackage) {
1994 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001995 }
1996
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001998 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001999 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002000 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002001 return -1;
2002 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002003 final Phone phone = getPhone(subId);
2004 if (phone != null) {
2005 return phone.getCdmaEriIconMode();
2006 } else {
2007 return -1;
2008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010
2011 /**
2012 * Returns the CDMA ERI text,
2013 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002014 @Override
2015 public String getCdmaEriText(String callingPackage) {
2016 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002017 }
2018
Sanket Padawe356d7632015-06-22 14:03:32 -07002019 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002020 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002022 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002023 return null;
2024 }
Sanket Padawe356d7632015-06-22 14:03:32 -07002025 final Phone phone = getPhone(subId);
2026 if (phone != null) {
2027 return phone.getCdmaEriText();
2028 } else {
2029 return null;
2030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 }
2032
2033 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002034 * Returns the CDMA MDN.
2035 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002036 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002037 public String getCdmaMdn(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2039 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07002040 final Phone phone = getPhone(subId);
2041 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
2042 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07002043 } else {
2044 return null;
2045 }
2046 }
2047
2048 /**
2049 * Returns the CDMA MIN.
2050 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002051 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002052 public String getCdmaMin(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2054 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07002055 final Phone phone = getPhone(subId);
2056 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2057 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002058 } else {
2059 return null;
2060 }
2061 }
2062
2063 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064 * Returns true if CDMA provisioning needs to run.
2065 */
2066 public boolean needsOtaServiceProvisioning() {
2067 return mPhone.needsOtaServiceProvisioning();
2068 }
2069
2070 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002071 * Sets the voice mail number of a given subId.
2072 */
2073 @Override
2074 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002075 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002076 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2077 new Pair<String, String>(alphaTag, number), new Integer(subId));
2078 return success;
2079 }
2080
Ta-wei Yen87c49842016-05-13 21:19:52 -07002081 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002082 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2083 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2084 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2085 if (!TextUtils.equals(callingPackage, systemDialer)) {
2086 throw new SecurityException("caller must be system dialer");
2087 }
2088 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2089 if (phoneAccountHandle == null){
2090 return null;
2091 }
2092 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2093 }
2094
2095 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002096 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002097 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002098 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002099 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002100 return null;
2101 }
Jeff Davidson87b3c102018-03-15 17:16:18 -07002102 final long identity = Binder.clearCallingIdentity();
2103 try {
2104 return RemoteVvmTaskManager
2105 .getRemotePackage(mPhone.getContext(), subId).getPackageName();
2106 } finally {
2107 Binder.restoreCallingIdentity(identity);
2108 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002109 }
2110
2111 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002112 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2113 VisualVoicemailSmsFilterSettings settings) {
2114 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002115 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002116 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2117 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002118 }
2119
2120 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002121 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2122 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002123 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002124 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002125 }
2126
2127 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002128 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2129 String callingPackage, int subId) {
2130 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002131 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002132 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002133 }
2134
2135 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002136 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002137 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002138 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002139 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2140 }
2141
2142 @Override
2143 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2144 String number, int port, String text, PendingIntent sentIntent) {
2145 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002146 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002147 enforceSendSmsPermission();
2148 // Make the calls as the phone process.
2149 final long identity = Binder.clearCallingIdentity();
2150 try {
2151 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2152 if (port == 0) {
2153 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2154 sentIntent, null, false);
2155 } else {
2156 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2157 smsManager.sendDataMessageWithSelfPermissions(number, null,
2158 (short) port, data, sentIntent, null);
2159 }
2160 } finally {
2161 Binder.restoreCallingIdentity(identity);
2162 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002163 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002164 /**
fionaxu0152e512016-11-14 13:36:14 -08002165 * Sets the voice activation state of a given subId.
2166 */
2167 @Override
2168 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002169 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2170 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002171 final Phone phone = getPhone(subId);
2172 if (phone != null) {
2173 phone.setVoiceActivationState(activationState);
2174 } else {
2175 loge("setVoiceActivationState fails with invalid subId: " + subId);
2176 }
2177 }
2178
2179 /**
2180 * Sets the data activation state of a given subId.
2181 */
2182 @Override
2183 public void setDataActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002184 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2185 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002186 final Phone phone = getPhone(subId);
2187 if (phone != null) {
2188 phone.setDataActivationState(activationState);
2189 } else {
2190 loge("setVoiceActivationState fails with invalid subId: " + subId);
2191 }
2192 }
2193
2194 /**
2195 * Returns the voice activation state of a given subId.
2196 */
2197 @Override
2198 public int getVoiceActivationState(int subId, String callingPackage) {
goneil9e8ba382017-12-13 12:57:23 -08002199 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002200 final Phone phone = getPhone(subId);
2201 if (phone != null) {
2202 return phone.getVoiceActivationState();
2203 } else {
2204 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2205 }
2206 }
2207
2208 /**
2209 * Returns the data activation state of a given subId.
2210 */
2211 @Override
2212 public int getDataActivationState(int subId, String callingPackage) {
goneil9e8ba382017-12-13 12:57:23 -08002213 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002214 final Phone phone = getPhone(subId);
2215 if (phone != null) {
2216 return phone.getDataActivationState();
2217 } else {
2218 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2219 }
2220 }
2221
2222 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 * Returns the unread count of voicemails
2224 */
2225 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002226 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002227 }
2228
2229 /**
2230 * Returns the unread count of voicemails for a subId
2231 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002232 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002233 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002234 final Phone phone = getPhone(subId);
2235 if (phone != null) {
2236 return phone.getVoiceMessageCount();
2237 } else {
2238 return 0;
2239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 }
2241
2242 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002243 * returns true, if the device is in a state where both voice and data
2244 * are supported simultaneously. This can change based on location or network condition.
2245 */
2246 @Override
2247 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2248 final Phone phone = getPhone(subId);
2249 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2250 }
2251
2252 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002253 * Send the dialer code if called from the current default dialer or the caller has
2254 * carrier privilege.
2255 * @param inputCode The dialer code to send
2256 */
2257 @Override
2258 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2259 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2260 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2261 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002262 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2263 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002264 }
2265 mPhone.sendDialerSpecialCode(inputCode);
2266 }
2267
2268 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002269 * Returns the data network type.
2270 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 *
2272 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2273 */
2274 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002275 public int getNetworkType() {
2276 final Phone phone = getPhone(getDefaultSubscription());
2277 if (phone != null) {
2278 return phone.getServiceState().getDataNetworkType();
2279 } else {
2280 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2281 }
Wink Saville36469e72014-06-11 15:17:00 -07002282 }
2283
2284 /**
2285 * Returns the network type for a subId
2286 */
2287 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002288 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002290 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002291 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2292 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002293
Sanket Padawe356d7632015-06-22 14:03:32 -07002294 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002295 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002296 return phone.getServiceState().getDataNetworkType();
2297 } else {
2298 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 }
2301
2302 /**
2303 * Returns the data network type
2304 */
2305 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002306 public int getDataNetworkType(String callingPackage) {
2307 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002308 }
2309
2310 /**
2311 * Returns the data network type for a subId
2312 */
2313 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002314 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002315 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002316 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002317 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2318 }
2319
Sanket Padawe356d7632015-06-22 14:03:32 -07002320 final Phone phone = getPhone(subId);
2321 if (phone != null) {
2322 return phone.getServiceState().getDataNetworkType();
2323 } else {
2324 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2325 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002326 }
2327
2328 /**
Wink Saville36469e72014-06-11 15:17:00 -07002329 * Returns the Voice network type for a subId
2330 */
2331 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002332 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002333 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002334 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002335 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2336 }
2337
Sanket Padawe356d7632015-06-22 14:03:32 -07002338 final Phone phone = getPhone(subId);
2339 if (phone != null) {
2340 return phone.getServiceState().getVoiceNetworkType();
2341 } else {
2342 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 }
2345
2346 /**
2347 * @return true if a ICC card is present
2348 */
2349 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002350 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002351 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2352 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002353 }
2354
2355 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002356 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002357 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002358 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002359 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2360 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002361 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002362 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002363 } else {
2364 return false;
2365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 }
2367
2368 /**
2369 * Return if the current radio is LTE on CDMA. This
2370 * is a tri-state return value as for a period of time
2371 * the mode may be unknown.
2372 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002373 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002375 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002376 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002377 @Override
2378 public int getLteOnCdmaMode(String callingPackage) {
2379 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002380 }
2381
Sanket Padawe356d7632015-06-22 14:03:32 -07002382 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002383 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002385 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002386 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2387 }
2388
Sanket Padawe356d7632015-06-22 14:03:32 -07002389 final Phone phone = getPhone(subId);
2390 if (phone == null) {
2391 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2392 } else {
2393 return phone.getLteOnCdmaMode();
2394 }
Wink Saville36469e72014-06-11 15:17:00 -07002395 }
2396
2397 public void setPhone(Phone phone) {
2398 mPhone = phone;
2399 }
2400
2401 /**
2402 * {@hide}
2403 * Returns Default subId, 0 in the case of single standby.
2404 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002405 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002406 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002407 }
2408
Shishir Agrawala9f32182016-04-12 12:00:16 -07002409 private int getSlotForDefaultSubscription() {
2410 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2411 }
2412
Wink Savilleb564aae2014-10-23 10:18:09 -07002413 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002414 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002416
2417 /**
2418 * @see android.telephony.TelephonyManager.WifiCallingChoices
2419 */
2420 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002421 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2422 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002423 }
2424
2425 /**
2426 * @see android.telephony.TelephonyManager.WifiCallingChoices
2427 */
2428 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002429 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2430 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2431 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002432 }
2433
Sailesh Nepald1e68152013-12-12 19:08:02 -08002434 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002435 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002436 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002437 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002438
Shishir Agrawal566b7612013-10-28 14:41:00 -07002439 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002440 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2441 int subId, String callingPackage, String aid, int p2) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2443 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002444
Derek Tan740e1672017-06-27 14:56:27 -07002445 if (TextUtils.equals(ISDR_AID, aid)) {
2446 // Only allows LPA to open logical channel to ISD-R.
2447 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2448 ComponentInfo bestComponent =
2449 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2450 if (bestComponent == null
2451 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2452 loge("The calling package is not allowed to access ISD-R.");
2453 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2454 }
2455 }
2456
2457 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002458 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002459 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002460 if (DBG) log("iccOpenLogicalChannel: " + response);
2461 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002462 }
2463
2464 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002465 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2467 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002468
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002469 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002470 if (channel < 0) {
2471 return false;
2472 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002473 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002474 if (DBG) log("iccCloseLogicalChannel: " + success);
2475 return success;
2476 }
2477
2478 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002479 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002480 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2482 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002483
2484 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002485 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2486 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002487 " data=" + data);
2488 }
2489
2490 if (channel < 0) {
2491 return "";
2492 }
2493
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002494 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002495 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002496 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2497
Shishir Agrawal566b7612013-10-28 14:41:00 -07002498 // Append the returned status code to the end of the response payload.
2499 String s = Integer.toHexString(
2500 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002501 if (response.payload != null) {
2502 s = IccUtils.bytesToHexString(response.payload) + s;
2503 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002504 return s;
2505 }
Jake Hambye994d462014-02-03 13:10:13 -08002506
Evan Charltonc66da362014-05-16 14:06:40 -07002507 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002508 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2509 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2511 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002512
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002513 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2514 && TextUtils.equals(ISDR_AID, data)) {
2515 // Only allows LPA to select ISD-R.
2516 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2517 ComponentInfo bestComponent =
2518 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2519 if (bestComponent == null
2520 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2521 loge("The calling package is not allowed to select ISD-R.");
2522 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2523 }
2524 }
2525
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002526 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002527 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2528 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002529 }
2530
2531 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002532 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002533 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2534
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002535 // Append the returned status code to the end of the response payload.
2536 String s = Integer.toHexString(
2537 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002538 if (response.payload != null) {
2539 s = IccUtils.bytesToHexString(response.payload) + s;
2540 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002541 return s;
2542 }
2543
2544 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002545 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002546 String filePath) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2548 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002549
2550 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002551 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002552 p1 + " " + p2 + " " + p3 + ":" + filePath);
2553 }
2554
2555 IccIoResult response =
2556 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002557 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2558 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002559
2560 if (DBG) {
2561 log("Exchange SIM_IO [R]" + response);
2562 }
2563
2564 byte[] result = null;
2565 int length = 2;
2566 if (response.payload != null) {
2567 length = 2 + response.payload.length;
2568 result = new byte[length];
2569 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2570 } else {
2571 result = new byte[length];
2572 }
2573
2574 result[length - 1] = (byte) response.sw2;
2575 result[length - 2] = (byte) response.sw1;
2576 return result;
2577 }
2578
Nathan Haroldb3014052017-01-25 15:57:32 -08002579 /**
2580 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2581 * on a particular subscription
2582 */
2583 public String[] getForbiddenPlmns(int subId, int appType) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002584 // TODO(b/73884967): Migrate to TelephonyPermissions check.
Nathan Harold892104e2017-04-13 18:19:05 -07002585 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2586 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002587 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2588 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2589 return null;
2590 }
2591 Object response = sendRequest(
2592 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2593 if (response instanceof String[]) {
2594 return (String[]) response;
2595 }
2596 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2597 return null;
2598 }
2599
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002600 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002601 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2603 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002604
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002605 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002606 if (response.payload == null) {
2607 return "";
2608 }
2609
2610 // Append the returned status code to the end of the response payload.
2611 String s = Integer.toHexString(
2612 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2613 s = IccUtils.bytesToHexString(response.payload) + s;
2614 return s;
2615 }
2616
Jake Hambye994d462014-02-03 13:10:13 -08002617 /**
2618 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2619 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2620 *
2621 * @param itemID the ID of the item to read
2622 * @return the NV item as a String, or null on error.
2623 */
2624 @Override
2625 public String nvReadItem(int itemID) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002626 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2627 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002628 if (DBG) log("nvReadItem: item " + itemID);
2629 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2630 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2631 return value;
2632 }
2633
2634 /**
2635 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2636 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2637 *
2638 * @param itemID the ID of the item to read
2639 * @param itemValue the value to write, as a String
2640 * @return true on success; false on any failure
2641 */
2642 @Override
2643 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2645 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002646 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2647 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2648 new Pair<Integer, String>(itemID, itemValue));
2649 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2650 return success;
2651 }
2652
2653 /**
2654 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2655 * Used for device configuration by some CDMA operators.
2656 *
2657 * @param preferredRoamingList byte array containing the new PRL
2658 * @return true on success; false on any failure
2659 */
2660 @Override
2661 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2663 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002664 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2665 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2666 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2667 return success;
2668 }
2669
2670 /**
2671 * Perform the specified type of NV config reset.
2672 * Used for device configuration by some CDMA operators.
2673 *
2674 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2675 * @return true on success; false on any failure
2676 */
2677 @Override
2678 public boolean nvResetConfig(int resetType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2680 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002681 if (DBG) log("nvResetConfig: type " + resetType);
2682 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2683 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2684 return success;
2685 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002686
Svet Ganovb320e182015-04-16 12:30:10 -07002687 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002689 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002690 return new String[0];
2691 }
2692
2693
ram87fca6f2014-07-18 18:58:44 +05302694 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002695 }
2696
Brad Ebinger51f743a2017-01-23 13:50:20 -08002697 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002698 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2699 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002700 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002701 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002702 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002703 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002704 }
2705
2706 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002707 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2708 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002709 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002710 public void disableIms(int slotId) {
2711 enforceModifyPermission();
2712 PhoneFactory.getImsResolver().disableIms(slotId);
2713 }
2714
2715 /**
2716 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2717 * feature or {@link null} if the service is not available. If the feature is available, the
2718 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2719 */
2720 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002721 IImsServiceFeatureCallback callback) {
2722 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002723 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002724 }
2725
2726 /**
2727 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2728 * feature during emergency calling or {@link null} if the service is not available. If the
2729 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2730 * listener for feature updates.
2731 */
2732 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2733 enforceModifyPermission();
2734 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002735 }
2736
Brad Ebinger7e934f52017-12-14 14:26:15 -08002737 /**
2738 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2739 * specified.
2740 */
2741 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2742 enforceModifyPermission();
2743 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2744 }
2745
Brad Ebingera12246d2018-01-16 09:39:35 -08002746 /**
2747 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2748 * specified.
2749 */
2750 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2751 enforceModifyPermission();
2752 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2753 }
2754
Brad Ebinger884c07b2018-02-15 16:17:40 -08002755 /**
Brad Ebinger67801702018-03-02 13:43:36 -08002756 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2757 * available, false if the IMS resolver is idle.
2758 */
2759 public boolean isResolvingImsBinding() {
2760 enforceModifyPermission();
2761 return PhoneFactory.getImsResolver().isResolvingBinding();
2762 }
2763
Brad Ebinger4dc095a2018-04-03 15:17:52 -07002764 /**
2765 * Sets the ImsService Package Name that Telephony will bind to.
2766 *
2767 * @param slotId the slot ID that the ImsService should bind for.
2768 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
2769 * ImsService is the device default ImsService.
2770 * @param packageName The package name of the application that contains the ImsService to bind
2771 * to.
2772 * @return true if setting the ImsService to bind to succeeded, false if it did not.
2773 * @hide
2774 */
2775 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingera6377d92018-04-06 09:56:40 -07002776 int[] subIds = SubscriptionManager.getSubId(slotId);
2777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2778 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2779 "setImsService");
2780
Brad Ebinger4dc095a2018-04-03 15:17:52 -07002781 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
2782 isCarrierImsService, packageName);
2783 }
2784
2785 /**
2786 * Return the ImsService configuration.
2787 *
2788 * @param slotId The slot that the ImsService is associated with.
2789 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
2790 * the device default.
2791 * @return the package name of the ImsService configuration.
2792 */
2793 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingera6377d92018-04-06 09:56:40 -07002794 int[] subIds = SubscriptionManager.getSubId(slotId);
2795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
2796 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
2797 "getImsService");
2798
Brad Ebinger4dc095a2018-04-03 15:17:52 -07002799 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
2800 isCarrierImsService);
2801 }
2802
Wink Saville36469e72014-06-11 15:17:00 -07002803 public void setImsRegistrationState(boolean registered) {
2804 enforceModifyPermission();
2805 mPhone.setImsRegistrationState(registered);
2806 }
2807
2808 /**
Stuart Scott54788802015-03-30 13:18:01 -07002809 * Set the network selection mode to automatic.
2810 *
2811 */
2812 @Override
2813 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2815 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002816 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2817 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2818 }
2819
2820 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002821 * Set the network selection mode to manual with the selected carrier.
2822 */
2823 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002824 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002825 boolean persistSelection) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002826 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2827 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002828 OperatorInfo operator = new OperatorInfo(
2829 /* operatorAlphaLong */ "",
2830 /* operatorAlphaShort */ "",
2831 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002832 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002833 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2834 persistSelection);
2835 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002836 }
2837
2838 /**
2839 * Scans for available networks.
2840 */
2841 @Override
2842 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2844 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002845 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2846 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2847 CMD_PERFORM_NETWORK_SCAN, null, subId);
2848 return result;
2849 }
2850
2851 /**
yinxub1bed742017-04-17 11:45:04 -07002852 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002853 *
yinxub1bed742017-04-17 11:45:04 -07002854 * @param subId id of the subscription
2855 * @param request contains the radio access networks with bands/channels to scan
2856 * @param messenger callback messenger for scan results or errors
2857 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002858 * @return the id of the requested scan which can be used to stop the scan.
2859 */
2860 @Override
2861 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2862 IBinder binder) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002863 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2864 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002865 return mNetworkScanRequestTracker.startNetworkScan(
2866 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002867 }
2868
2869 /**
2870 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002871 *
2872 * @param subId id of the subscription
2873 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002874 */
2875 @Override
2876 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2878 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002879 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002880 }
2881
2882 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002883 * Get the calculated preferred network type.
2884 * Used for debugging incorrect network type.
2885 *
2886 * @return the preferred network type, defined in RILConstants.java.
2887 */
2888 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002889 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002890 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002891 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002892 return RILConstants.PREFERRED_NETWORK_MODE;
2893 }
2894
Amit Mahajan43330e02014-11-18 11:54:45 -08002895 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002896 }
2897
2898 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002899 * Get the preferred network type.
2900 * Used for device configuration by some CDMA operators.
2901 *
2902 * @return the preferred network type, defined in RILConstants.java.
2903 */
2904 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002905 public int getPreferredNetworkType(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2907 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002908 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002909 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002910 int networkType = (result != null ? result[0] : -1);
2911 if (DBG) log("getPreferredNetworkType: " + networkType);
2912 return networkType;
2913 }
2914
2915 /**
2916 * Set the preferred network type.
2917 * Used for device configuration by some CDMA operators.
2918 *
2919 * @param networkType the preferred network type, defined in RILConstants.java.
2920 * @return true on success; false on any failure.
2921 */
2922 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002923 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002924 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2925 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002926 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2927 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002928 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002929 if (success) {
2930 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002931 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002932 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002933 return success;
2934 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002935
2936 /**
Junda Liu475951f2014-11-07 16:45:03 -08002937 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2938 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2939 * tethering.
2940 *
2941 * @return 0: Not required. 1: required. 2: Not set.
2942 * @hide
2943 */
2944 @Override
2945 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002946 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002947 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2948 Settings.Global.TETHER_DUN_REQUIRED, 2);
2949 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2950 // config_tether_apndata.
2951 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2952 dunRequired = 1;
2953 }
2954 return dunRequired;
2955 }
2956
2957 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002958 * Set mobile data enabled
2959 * Used by the user through settings etc to turn on/off mobile data
2960 *
2961 * @param enable {@code true} turn turn data on, else {@code false}
2962 */
2963 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002964 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2966 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002967 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002968 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002969 Phone phone = PhoneFactory.getPhone(phoneId);
2970 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002971 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2972 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002973 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002974 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002975 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002976 }
2977
2978 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002979 * Get the user enabled state of Mobile Data.
2980 *
2981 * TODO: remove and use isUserDataEnabled.
2982 * This can't be removed now because some vendor codes
2983 * calls through ITelephony directly while they should
2984 * use TelephonyManager.
2985 *
2986 * @return true on enabled
2987 */
2988 @Override
2989 public boolean getDataEnabled(int subId) {
2990 return isUserDataEnabled(subId);
2991 }
2992
2993 /**
2994 * Get whether mobile data is enabled per user setting.
2995 *
2996 * There are other factors deciding whether mobile data is actually enabled, but they are
2997 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002998 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002999 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07003000 *
3001 * @return {@code true} if data is enabled else {@code false}
3002 */
3003 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003004 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07003005 try {
3006 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3007 null);
3008 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3010 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07003011 }
Wink Savillee7353bb2014-12-05 14:21:41 -08003012 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003013 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08003014 Phone phone = PhoneFactory.getPhone(phoneId);
3015 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003016 boolean retVal = phone.isUserDataEnabled();
3017 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08003018 return retVal;
3019 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003020 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
3021 return false;
3022 }
3023 }
3024
3025 /**
3026 * Get whether mobile data is enabled.
3027 *
3028 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
3029 * whether mobile data is actually enabled.
3030 *
3031 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
3032 *
3033 * @return {@code true} if data is enabled else {@code false}
3034 */
3035 @Override
3036 public boolean isDataEnabled(int subId) {
3037 try {
3038 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
3039 null);
3040 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3042 mApp, subId, "isDataEnabled");
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003043 }
3044 int phoneId = mSubscriptionController.getPhoneId(subId);
3045 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
3046 Phone phone = PhoneFactory.getPhone(phoneId);
3047 if (phone != null) {
3048 boolean retVal = phone.isDataEnabled();
3049 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
3050 return retVal;
3051 } else {
3052 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08003053 return false;
3054 }
Robert Greenwalted86e582014-05-21 20:03:20 -07003055 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003056
3057 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003058 public int getCarrierPrivilegeStatus(int subId) {
3059 final Phone phone = getPhone(subId);
3060 if (phone == null) {
3061 loge("getCarrierPrivilegeStatus: Invalid subId");
3062 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3063 }
3064 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003065 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08003066 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003067 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3068 }
3069 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003070 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07003071 }
Junda Liu29340342014-07-10 15:23:27 -07003072
3073 @Override
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003074 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
3075 final Phone phone = getPhone(subId);
3076 if (phone == null) {
3077 loge("getCarrierPrivilegeStatus: Invalid subId");
3078 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
3079 }
3080 UiccProfile profile =
3081 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
3082 if (profile == null) {
3083 loge("getCarrierPrivilegeStatus: No UICC");
3084 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3085 }
3086 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
3087 }
3088
3089 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07003090 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003091 if (TextUtils.isEmpty(pkgName))
3092 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003093 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003094 if (card == null) {
3095 loge("checkCarrierPrivilegesForPackage: No UICC");
3096 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3097 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003098 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3099 }
3100
3101 @Override
3102 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003103 if (TextUtils.isEmpty(pkgName))
3104 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003105 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3106 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3107 UiccCard card = UiccController.getInstance().getUiccCard(i);
3108 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003109 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003110 continue;
3111 }
3112
3113 result = card.getCarrierPrivilegeStatus(
3114 mPhone.getContext().getPackageManager(), pkgName);
3115 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3116 break;
3117 }
3118 }
3119
3120 return result;
Junda Liu29340342014-07-10 15:23:27 -07003121 }
Derek Tan89e89d42014-07-08 17:00:10 -07003122
3123 @Override
Junda Liue64de782015-04-16 17:19:16 -07003124 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3125 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3126 loge("phoneId " + phoneId + " is not valid.");
3127 return null;
3128 }
3129 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003130 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003131 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003132 return null ;
3133 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003134 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003135 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003136 }
3137
Amith Yamasani6e118872016-02-19 12:53:51 -08003138 @Override
3139 public List<String> getPackagesWithCarrierPrivileges() {
3140 PackageManager pm = mPhone.getContext().getPackageManager();
3141 List<String> privilegedPackages = new ArrayList<>();
3142 List<PackageInfo> packages = null;
3143 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3144 UiccCard card = UiccController.getInstance().getUiccCard(i);
3145 if (card == null) {
3146 // No UICC in that slot.
3147 continue;
3148 }
3149 if (card.hasCarrierPrivilegeRules()) {
3150 if (packages == null) {
3151 // Only check packages in user 0 for now
3152 packages = pm.getInstalledPackagesAsUser(
3153 PackageManager.MATCH_DISABLED_COMPONENTS
3154 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3155 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3156 }
3157 for (int p = packages.size() - 1; p >= 0; p--) {
3158 PackageInfo pkgInfo = packages.get(p);
3159 if (pkgInfo != null && pkgInfo.packageName != null
3160 && card.getCarrierPrivilegeStatus(pkgInfo)
3161 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3162 privilegedPackages.add(pkgInfo.packageName);
3163 }
3164 }
3165 }
3166 }
3167 return privilegedPackages;
3168 }
3169
Wink Savilleb564aae2014-10-23 10:18:09 -07003170 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003171 final Phone phone = getPhone(subId);
3172 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003173 if (card == null) {
3174 loge("getIccId: No UICC");
3175 return null;
3176 }
3177 String iccId = card.getIccId();
3178 if (TextUtils.isEmpty(iccId)) {
3179 loge("getIccId: ICC ID is null or empty.");
3180 return null;
3181 }
3182 return iccId;
3183 }
3184
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003185 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003186 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3187 String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003188 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3189 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003190
Jeff Sharkey85190e62014-12-05 09:40:12 -08003191 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003192 final Phone phone = getPhone(subId);
3193 if (phone == null) {
3194 return false;
3195 }
3196 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003197
3198 if (DBG_MERGE) {
3199 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3200 + subscriberId + " to " + number);
3201 }
3202
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003203 if (TextUtils.isEmpty(iccId)) {
3204 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003205 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003206
Jeff Sharkey85190e62014-12-05 09:40:12 -08003207 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3208
3209 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003210 if (alphaTag == null) {
3211 editor.remove(alphaTagPrefKey);
3212 } else {
3213 editor.putString(alphaTagPrefKey, alphaTag);
3214 }
3215
Jeff Sharkey85190e62014-12-05 09:40:12 -08003216 // Record both the line number and IMSI for this ICCID, since we need to
3217 // track all merged IMSIs based on line number
3218 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3219 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003220 if (number == null) {
3221 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003222 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003223 } else {
3224 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003225 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003226 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003227
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003228 editor.commit();
3229 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003230 }
3231
3232 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003233 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003234 // This is open to apps with WRITE_SMS.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003236 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003237 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003238 return null;
3239 }
Derek Tan97ebb422014-09-05 16:55:38 -07003240
3241 String iccId = getIccId(subId);
3242 if (iccId != null) {
3243 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003244 if (DBG_MERGE) {
3245 log("getLine1NumberForDisplay returning " +
3246 mTelephonySharedPreferences.getString(numberPrefKey, null));
3247 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003248 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003249 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003250 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003251 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003252 }
3253
3254 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003255 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003256 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003257 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003258 return null;
3259 }
Derek Tan97ebb422014-09-05 16:55:38 -07003260
3261 String iccId = getIccId(subId);
3262 if (iccId != null) {
3263 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003264 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003265 }
Derek Tan97ebb422014-09-05 16:55:38 -07003266 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003267 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003268
3269 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003270 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003271 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3272 // about carrier-privileged callers not having access.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003273 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003274 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3275 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003276 return null;
3277 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003278 final Context context = mPhone.getContext();
3279 final TelephonyManager tele = TelephonyManager.from(context);
3280 final SubscriptionManager sub = SubscriptionManager.from(context);
3281
3282 // Figure out what subscribers are currently active
3283 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003284 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3285 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3286 final long identity = Binder.clearCallingIdentity();
3287 try {
3288 final int[] subIds = sub.getActiveSubscriptionIdList();
3289 for (int subId : subIds) {
3290 activeSubscriberIds.add(tele.getSubscriberId(subId));
3291 }
3292 } finally {
3293 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003294 }
3295
3296 // First pass, find a number override for an active subscriber
3297 String mergeNumber = null;
3298 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3299 for (String key : prefs.keySet()) {
3300 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3301 final String subscriberId = (String) prefs.get(key);
3302 if (activeSubscriberIds.contains(subscriberId)) {
3303 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3304 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3305 mergeNumber = (String) prefs.get(numberKey);
3306 if (DBG_MERGE) {
3307 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3308 + " for active subscriber " + subscriberId);
3309 }
3310 if (!TextUtils.isEmpty(mergeNumber)) {
3311 break;
3312 }
3313 }
3314 }
3315 }
3316
3317 // Shortcut when no active merged subscribers
3318 if (TextUtils.isEmpty(mergeNumber)) {
3319 return null;
3320 }
3321
3322 // Second pass, find all subscribers under that line override
3323 final ArraySet<String> result = new ArraySet<>();
3324 for (String key : prefs.keySet()) {
3325 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3326 final String number = (String) prefs.get(key);
3327 if (mergeNumber.equals(number)) {
3328 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3329 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3330 final String subscriberId = (String) prefs.get(subscriberKey);
3331 if (!TextUtils.isEmpty(subscriberId)) {
3332 result.add(subscriberId);
3333 }
3334 }
3335 }
3336 }
3337
3338 final String[] resultArray = result.toArray(new String[result.size()]);
3339 Arrays.sort(resultArray);
3340 if (DBG_MERGE) {
3341 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3342 }
3343 return resultArray;
3344 }
3345
3346 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003347 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003348 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3349 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003350 final Phone phone = getPhone(subId);
3351 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003352 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003353
3354 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003355 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003356 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3357 List<String> cdmaNonRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003358 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003359 final Phone phone = getPhone(subId);
3360 if (phone == null) {
3361 return false;
3362 }
3363 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003364 cdmaNonRoamingList);
3365 }
3366
3367 @Override
Shuo Qian74b16b12018-04-27 01:32:07 +00003368 @Deprecated
3369 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
3370 enforceModifyPermission();
3371
3372 int returnValue = 0;
3373 try {
3374 AsyncResult result = (AsyncResult)sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
3375 if(result.exception == null) {
3376 if (result.result != null) {
3377 byte[] responseData = (byte[])(result.result);
3378 if(responseData.length > oemResp.length) {
3379 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
3380 responseData.length + "bytes. Buffer Size is " +
3381 oemResp.length + "bytes.");
3382 }
3383 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
3384 returnValue = responseData.length;
3385 }
3386 } else {
3387 CommandException ex = (CommandException) result.exception;
3388 returnValue = ex.getCommandError().ordinal();
3389 if(returnValue > 0) returnValue *= -1;
3390 }
3391 } catch (RuntimeException e) {
3392 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
3393 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
3394 if(returnValue > 0) returnValue *= -1;
3395 }
3396
3397 return returnValue;
3398 }
3399
3400 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003401 public void setRadioCapability(RadioAccessFamily[] rafs) {
3402 try {
3403 ProxyController.getInstance().setRadioCapability(rafs);
3404 } catch (RuntimeException e) {
3405 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3406 }
3407 }
3408
3409 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003410 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003411 Phone phone = PhoneFactory.getPhone(phoneId);
3412 if (phone == null) {
3413 return RadioAccessFamily.RAF_UNKNOWN;
3414 }
3415 int subId = phone.getSubId();
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003416 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003417 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003418 return RadioAccessFamily.RAF_UNKNOWN;
3419 }
3420
Wink Saville5d475dd2014-10-17 15:00:58 -07003421 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3422 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003423
3424 @Override
3425 public void enableVideoCalling(boolean enable) {
3426 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003427 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003428 }
3429
3430 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003431 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003432 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003433 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003434 return false;
3435 }
3436
Andrew Lee77527ac2014-10-21 16:57:39 -07003437 // Check the user preference and the system-level IMS setting. Even if the user has
3438 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3439 // In the long run, we may instead need to check if there exists a connection service
3440 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003441 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3442 return imsManager.isVtEnabledByPlatform()
3443 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3444 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003445 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003446
Andrew Leea1239f22015-03-02 17:44:07 -08003447 @Override
3448 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003449 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003450 }
3451
3452 @Override
3453 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003454 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003455 }
3456
Andrew Lee9431b832015-03-09 18:46:45 -07003457 @Override
3458 public boolean isTtyModeSupported() {
3459 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3460 TelephonyManager telephonyManager =
3461 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003462 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003463 }
3464
3465 @Override
3466 public boolean isHearingAidCompatibilitySupported() {
3467 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3468 }
3469
Hall Liu73714012018-01-22 19:15:32 -08003470 public boolean isRttSupported() {
3471 boolean isCarrierSupported =
3472 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3473 boolean isDeviceSupported =
3474 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3475 return isCarrierSupported && isDeviceSupported;
3476 }
3477
Hall Liub1585172018-04-06 16:23:39 -07003478 public boolean isRttEnabled() {
3479 return isRttSupported() && Settings.Secure.getInt(mPhone.getContext().getContentResolver(),
3480 Settings.Secure.RTT_CALLING_MODE, 0) != 0;
3481 }
3482
Sanket Padawe7310cc72015-01-14 09:53:20 -08003483 /**
3484 * Returns the unique device ID of phone, for example, the IMEI for
3485 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3486 *
3487 * <p>Requires Permission:
3488 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3489 */
3490 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003491 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003492 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003493 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003494 return null;
3495 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003496 int subId = phone.getSubId();
3497 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3498 mApp, subId, callingPackage, "getDeviceId")) {
3499 return null;
3500 }
3501 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003502 }
3503
Ping Sun014fe8e2016-03-02 19:16:45 +08003504 /**
3505 * {@hide}
3506 * Returns the IMS Registration Status on a particular subid
3507 *
3508 * @param subId
3509 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003510 public boolean isImsRegistered(int subId) {
Ping Sun014fe8e2016-03-02 19:16:45 +08003511 Phone phone = getPhone(subId);
3512 if (phone != null) {
3513 return phone.isImsRegistered();
3514 } else {
3515 return false;
3516 }
3517 }
3518
Santos Cordon7a1885b2015-02-03 11:15:19 -08003519 @Override
3520 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3521 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3522 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003523
Brad Ebingere21f25f2018-02-08 16:11:32 -08003524 /**
3525 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003526 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003527 public boolean isWifiCallingAvailable(int subId) {
3528 Phone phone = getPhone(subId);
3529 if (phone != null) {
3530 return phone.isWifiCallingEnabled();
3531 } else {
3532 return false;
3533 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003534 }
3535
Brad Ebingere21f25f2018-02-08 16:11:32 -08003536 /**
3537 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003538 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003539 public boolean isVolteAvailable(int subId) {
3540 Phone phone = getPhone(subId);
3541 if (phone != null) {
3542 return phone.isVolteEnabled();
3543 } else {
3544 return false;
3545 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003546 }
Svet Ganovb320e182015-04-16 12:30:10 -07003547
Brad Ebingere21f25f2018-02-08 16:11:32 -08003548 /**
3549 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003550 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003551 public boolean isVideoTelephonyAvailable(int subId) {
3552 Phone phone = getPhone(subId);
3553 if (phone != null) {
3554 return phone.isVideoEnabled();
3555 } else {
3556 return false;
3557 }
3558 }
3559
3560 /**
3561 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3562 * defined in {@link ImsRegistrationImplBase}.
3563 */
3564 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3565 Phone phone = getPhone(subId);
3566 if (phone != null) {
3567 return phone.getImsRegistrationTech();
3568 } else {
3569 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3570 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003571 }
3572
Stuart Scott8eef64f2015-04-08 15:13:54 -07003573 @Override
3574 public void factoryReset(int subId) {
3575 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003576 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3577 return;
3578 }
3579
Svet Ganovcc087f82015-05-12 20:35:54 -07003580 final long identity = Binder.clearCallingIdentity();
3581 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003582 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3583 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003584 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003585 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003586 // Set network selection mode to automatic
3587 setNetworkSelectionModeAutomatic(subId);
3588 // Set preferred mobile network type to the best available
Kitta Koutarouab8a69b2018-03-05 14:16:45 +09003589 String defaultNetwork = TelephonyManager.getTelephonyProperty(
3590 mSubscriptionController.getPhoneId(subId),
3591 "ro.telephony.default_network",
3592 null);
3593 int networkType = !TextUtils.isEmpty(defaultNetwork)
3594 ? Integer.parseInt(defaultNetwork) : Phone.PREFERRED_NT_MODE;
3595 setPreferredNetworkType(subId, networkType);
Svet Ganovcc087f82015-05-12 20:35:54 -07003596 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003597 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003598 }
3599 } finally {
3600 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003601 }
3602 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003603
3604 @Override
3605 public String getLocaleFromDefaultSim() {
3606 // We query all subscriptions instead of just the active ones, because
3607 // this might be called early on in the provisioning flow when the
3608 // subscriptions potentially aren't active yet.
3609 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3610 if (slist == null || slist.isEmpty()) {
3611 return null;
3612 }
3613
3614 // This function may be called very early, say, from the setup wizard, at
3615 // which point we won't have a default subscription set. If that's the case
3616 // we just choose the first, which will be valid in "most cases".
3617 final int defaultSubId = getDefaultSubscription();
3618 SubscriptionInfo info = null;
3619 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3620 info = slist.get(0);
3621 } else {
3622 for (SubscriptionInfo item : slist) {
3623 if (item.getSubscriptionId() == defaultSubId) {
3624 info = item;
3625 break;
3626 }
3627 }
3628
3629 if (info == null) {
3630 return null;
3631 }
3632 }
3633
3634 // Try and fetch the locale from the carrier properties or from the SIM language
3635 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003636 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003637 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003638 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003639 if (defaultPhone != null) {
3640 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3641 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003642 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003643 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3644 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003645 } else {
3646 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003647 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003648 }
3649 }
3650
Narayan Kamath011676f2015-07-29 12:04:08 +01003651 // The SIM language preferences only store a language (e.g. fr = French), not an
3652 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3653 // the SIM and carrier preferences does not include a country we add the country
3654 // determined from the SIM MCC to provide an exact locale.
3655 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003656 if (mccLocale != null) {
3657 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3658 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003659 }
3660
Tony Hill183b2de2015-06-24 14:53:58 +01003661 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003662 return null;
3663 }
3664
3665 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 return mSubscriptionController.getAllSubInfoList(
3669 mPhone.getContext().getOpPackageName());
3670 } finally {
3671 Binder.restoreCallingIdentity(identity);
3672 }
3673 }
3674
3675 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3676 final long identity = Binder.clearCallingIdentity();
3677 try {
3678 return mSubscriptionController.getActiveSubscriptionInfoList(
3679 mPhone.getContext().getOpPackageName());
3680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
3683 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003684
3685 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003686 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3687 * representing the state of the modem.
3688 *
3689 * NOTE: This clears the modem state, so there should only every be one caller.
3690 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003691 */
3692 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003693 public void requestModemActivityInfo(ResultReceiver result) {
3694 enforceModifyPermission();
3695
3696 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3697 Bundle bundle = new Bundle();
3698 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3699 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003700 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003701
3702 /**
3703 * {@hide}
3704 * Returns the service state information on specified subscription.
3705 */
3706 @Override
3707 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3708
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003710 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003711 return null;
3712 }
3713
3714 final Phone phone = getPhone(subId);
3715 if (phone == null) {
3716 return null;
3717 }
3718
3719 return phone.getServiceState();
3720 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003721
3722 /**
3723 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3724 *
3725 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3726 * voicemail ringtone.
3727 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3728 * PhoneAccount.
3729 */
3730 @Override
3731 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003732 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003733 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003734 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003735 }
3736
fionaxu7ed723d2017-05-30 18:58:54 -07003737 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003738 }
3739
3740 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003741 * Sets the per-account voicemail ringtone.
3742 *
3743 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3744 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3745 *
3746 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3747 * voicemail ringtone.
3748 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3749 * PhoneAccount.
3750 */
3751 @Override
3752 public void setVoicemailRingtoneUri(String callingPackage,
3753 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3754 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3755 if (!TextUtils.equals(callingPackage,
3756 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3758 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3759 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003760 }
3761 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3762 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003763 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003764 }
fionaxu7ed723d2017-05-30 18:58:54 -07003765 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003766 }
3767
3768 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003769 * Returns whether vibration is set for voicemail notification in Phone settings.
3770 *
3771 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3772 * voicemail vibration setting.
3773 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3774 */
3775 @Override
3776 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003777 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003778 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003779 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003780 }
3781
fionaxu7ed723d2017-05-30 18:58:54 -07003782 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003783 }
3784
Youhan Wange64578a2016-05-02 15:32:42 -07003785 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003786 * Sets the per-account voicemail vibration.
3787 *
3788 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3789 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3790 *
3791 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3792 * voicemail vibration setting.
3793 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3794 * specific PhoneAccount.
3795 */
3796 @Override
3797 public void setVoicemailVibrationEnabled(String callingPackage,
3798 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3799 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3800 if (!TextUtils.equals(callingPackage,
3801 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3803 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3804 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003805 }
3806
3807 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3808 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003809 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003810 }
fionaxu7ed723d2017-05-30 18:58:54 -07003811 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003812 }
3813
3814 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003815 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3816 *
3817 * @throws SecurityException if the caller does not have the required permission
3818 */
3819 private void enforceReadPrivilegedPermission() {
3820 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3821 null);
3822 }
3823
3824 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003825 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3826 * permission.
3827 *
3828 * @throws SecurityException if the caller does not have the required permission
3829 */
3830 private void enforceSendSmsPermission() {
3831 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3832 }
3833
3834 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003835 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003836 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003837 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003838 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003839 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003840 ComponentName componentName =
3841 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3842 if(componentName == null) {
3843 throw new SecurityException("Caller not current active visual voicemail package[null]");
3844 }
3845 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003846 if (!callingPackage.equals(vvmPackage)) {
3847 throw new SecurityException("Caller not current active visual voicemail package[" +
3848 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003849 }
3850 }
3851
3852 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003853 * Return the application ID for the app type.
3854 *
3855 * @param subId the subscription ID that this request applies to.
3856 * @param appType the uicc app type.
3857 * @return Application ID for specificied app type, or null if no uicc.
3858 */
3859 @Override
3860 public String getAidForAppType(int subId, int appType) {
3861 enforceReadPrivilegedPermission();
3862 Phone phone = getPhone(subId);
3863 if (phone == null) {
3864 return null;
3865 }
3866 String aid = null;
3867 try {
3868 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3869 .getApplicationByType(appType).getAid();
3870 } catch (Exception e) {
3871 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3872 }
3873 return aid;
3874 }
3875
Youhan Wang4001d252016-05-11 10:29:41 -07003876 /**
3877 * Return the Electronic Serial Number.
3878 *
3879 * @param subId the subscription ID that this request applies to.
3880 * @return ESN or null if error.
3881 */
3882 @Override
3883 public String getEsn(int subId) {
3884 enforceReadPrivilegedPermission();
3885 Phone phone = getPhone(subId);
3886 if (phone == null) {
3887 return null;
3888 }
3889 String esn = null;
3890 try {
3891 esn = phone.getEsn();
3892 } catch (Exception e) {
3893 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3894 }
3895 return esn;
3896 }
3897
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003898 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003899 * Return the Preferred Roaming List Version.
3900 *
3901 * @param subId the subscription ID that this request applies to.
3902 * @return PRLVersion or null if error.
3903 */
3904 @Override
3905 public String getCdmaPrlVersion(int subId) {
3906 enforceReadPrivilegedPermission();
3907 Phone phone = getPhone(subId);
3908 if (phone == null) {
3909 return null;
3910 }
3911 String cdmaPrlVersion = null;
3912 try {
3913 cdmaPrlVersion = phone.getCdmaPrlVersion();
3914 } catch (Exception e) {
3915 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3916 }
3917 return cdmaPrlVersion;
3918 }
3919
3920 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003921 * Get snapshot of Telephony histograms
3922 * @return List of Telephony histograms
3923 * @hide
3924 */
3925 @Override
3926 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3928 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003929 return RIL.getTelephonyRILTimingHistograms();
3930 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003931
3932 /**
3933 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003934 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003935 * Require system privileges. In the future we may add this to carrier APIs.
3936 *
3937 * @return The number of carriers set successfully, should match length of carriers
3938 */
3939 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003940 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003941 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003942
Meng Wang9b7c4e92017-02-17 11:41:27 -08003943 if (carriers == null) {
3944 throw new NullPointerException("carriers cannot be null");
3945 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003946
3947 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003948 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3949 return retVal[0];
3950 }
3951
3952 /**
3953 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003954 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003955 * Require system privileges. In the future we may add this to carrier APIs.
3956 *
3957 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3958 * means all carriers are allowed.
3959 */
3960 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003961 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003962 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003963 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003964 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3965 }
3966
fionaxu59545b42016-05-25 15:53:37 -07003967 /**
3968 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3969 * @param subId the subscription ID that this action applies to.
3970 * @param enabled control enable or disable metered apns.
3971 * {@hide}
3972 */
3973 @Override
3974 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3975 enforceModifyPermission();
3976 final Phone phone = getPhone(subId);
3977 if (phone == null) {
3978 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3979 return;
3980 }
3981 try {
3982 phone.carrierActionSetMeteredApnsEnabled(enabled);
3983 } catch (Exception e) {
3984 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3985 }
3986 }
3987
3988 /**
3989 * Action set from carrier signalling broadcast receivers to enable/disable radio
3990 * @param subId the subscription ID that this action applies to.
3991 * @param enabled control enable or disable radio.
3992 * {@hide}
3993 */
3994 @Override
3995 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3996 enforceModifyPermission();
3997 final Phone phone = getPhone(subId);
3998 if (phone == null) {
3999 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
4000 return;
4001 }
4002 try {
4003 phone.carrierActionSetRadioEnabled(enabled);
4004 } catch (Exception e) {
4005 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
4006 }
4007 }
4008
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004009 /**
fionaxu8da9cb12017-05-23 15:02:46 -07004010 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
4011 * network status based on which carrier apps could apply actions accordingly,
4012 * enable/disable default url handler for example.
4013 *
4014 * @param subId the subscription ID that this action applies to.
4015 * @param report control start/stop reporting the default network status.
4016 * {@hide}
4017 */
4018 @Override
4019 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
4020 enforceModifyPermission();
4021 final Phone phone = getPhone(subId);
4022 if (phone == null) {
4023 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
4024 return;
4025 }
4026 try {
4027 phone.carrierActionReportDefaultNetworkStatus(report);
4028 } catch (Exception e) {
4029 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
4030 }
4031 }
4032
4033 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004034 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
4035 * bug report is being generated.
4036 */
4037 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07004038 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07004039 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
4040 != PackageManager.PERMISSION_GRANTED) {
4041 writer.println("Permission Denial: can't dump Phone from pid="
4042 + Binder.getCallingPid()
4043 + ", uid=" + Binder.getCallingUid()
4044 + "without permission "
4045 + android.Manifest.permission.DUMP);
4046 return;
4047 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07004048 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07004049 }
Jack Yueb89b242016-06-22 13:27:47 -07004050
Brad Ebinger4dc095a2018-04-03 15:17:52 -07004051 @Override
4052 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
4053 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
4054 throws RemoteException {
4055 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
4056 }
4057
Jack Yueb89b242016-06-22 13:27:47 -07004058 /**
Jack Yu84291ec2017-05-26 16:07:50 -07004059 * Get aggregated video call data usage since boot.
4060 *
4061 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
4062 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07004063 * {@hide}
4064 */
4065 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07004066 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07004067 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
4068 null);
4069
Jack Yu84291ec2017-05-26 16:07:50 -07004070 // NetworkStatsService keeps tracking the active network interface and identity. It
4071 // records the delta with the corresponding network identity. We just return the total video
4072 // call data usage snapshot since boot.
4073 Phone phone = getPhone(subId);
4074 if (phone != null) {
4075 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07004076 }
Jack Yu84291ec2017-05-26 16:07:50 -07004077 return null;
Jack Yueb89b242016-06-22 13:27:47 -07004078 }
Jack Yu75ab2952016-07-08 14:29:33 -07004079
4080 /**
4081 * Policy control of data connection. Usually used when data limit is passed.
4082 * @param enabled True if enabling the data, otherwise disabling.
4083 * @param subId Subscription index
4084 * {@hide}
4085 */
4086 @Override
4087 public void setPolicyDataEnabled(boolean enabled, int subId) {
4088 enforceModifyPermission();
4089 Phone phone = getPhone(subId);
4090 if (phone != null) {
4091 phone.setPolicyDataEnabled(enabled);
4092 }
4093 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004094
4095 /**
4096 * Get Client request stats
4097 * @return List of Client Request Stats
4098 * @hide
4099 */
4100 @Override
4101 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08004102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08004103 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07004104 return null;
4105 }
4106
4107 Phone phone = getPhone(subId);
4108 if (phone != null) {
4109 return phone.getClientRequestStats();
4110 }
4111
4112 return null;
4113 }
4114
4115 private WorkSource getWorkSource(WorkSource workSource, int uid) {
4116 if (workSource != null) {
4117 return workSource;
4118 }
4119
4120 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
4121 workSource = new WorkSource(uid, packageName);
4122 return workSource;
4123 }
Jack Yueb4124c2017-02-16 15:32:43 -08004124
4125 /**
Grace Chen70990072017-03-24 17:21:30 -07004126 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08004127 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004128 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004129 * @param state State of SIM (power down, power up, pass through)
4130 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4131 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4132 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004133 *
4134 **/
4135 @Override
Grace Chen70990072017-03-24 17:21:30 -07004136 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004137 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004138 Phone phone = PhoneFactory.getPhone(slotIndex);
4139
Jack Yueb4124c2017-02-16 15:32:43 -08004140 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004141 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004142 }
4143 }
Shuo Qiandd210312017-04-12 22:11:33 +00004144
Tyler Gunn65d45c22017-06-05 11:22:26 -07004145 private boolean isUssdApiAllowed(int subId) {
4146 CarrierConfigManager configManager =
4147 (CarrierConfigManager) mPhone.getContext().getSystemService(
4148 Context.CARRIER_CONFIG_SERVICE);
4149 if (configManager == null) {
4150 return false;
4151 }
4152 PersistableBundle pb = configManager.getConfigForSubId(subId);
4153 if (pb == null) {
4154 return false;
4155 }
4156 return pb.getBoolean(
4157 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4158 }
4159
Shuo Qiandd210312017-04-12 22:11:33 +00004160 /**
4161 * Check if phone is in emergency callback mode
4162 * @return true if phone is in emergency callback mode
4163 * @param subId sub id
4164 */
4165 public boolean getEmergencyCallbackMode(int subId) {
4166 final Phone phone = getPhone(subId);
4167 if (phone != null) {
4168 return phone.isInEcm();
4169 } else {
4170 return false;
4171 }
4172 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004173
4174 /**
4175 * Get the current signal strength information for the given subscription.
4176 * Because this information is not updated when the device is in a low power state
4177 * it should not be relied-upon to be current.
4178 * @param subId Subscription index
4179 * @return the most recent cached signal strength info from the modem
4180 */
4181 @Override
4182 public SignalStrength getSignalStrength(int subId) {
4183 Phone p = getPhone(subId);
4184 if (p == null) {
4185 return null;
4186 }
4187
4188 return p.getSignalStrength();
4189 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004190
4191 @Override
4192 public UiccSlotInfo[] getUiccSlotsInfo() {
4193 enforceReadPrivilegedPermission();
4194
4195 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4196 if (slots == null) return null;
4197 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4198 for (int i = 0; i < slots.length; i++) {
4199 UiccSlot slot = slots[i];
4200
4201 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4202
4203 int cardState = 0;
4204 switch (slot.getCardState()) {
4205 case CARDSTATE_ABSENT:
4206 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4207 break;
4208 case CARDSTATE_PRESENT:
4209 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4210 break;
4211 case CARDSTATE_ERROR:
4212 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4213 break;
4214 case CARDSTATE_RESTRICTED:
4215 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4216 break;
4217 default:
4218 break;
4219
4220 }
4221
Qingxi Li63668902018-01-31 13:43:27 -08004222 infos[i] = new UiccSlotInfo(
Qingxi Li0ae57f72018-03-07 10:52:26 -08004223 slot.isActive(),
4224 slot.isEuicc(),
4225 cardId,
4226 cardState,
4227 slot.getPhoneId(),
4228 slot.isExtendedApduSupported());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004229 }
4230 return infos;
4231 }
4232
4233 @Override
4234 public boolean switchSlots(int[] physicalSlots) {
4235 enforceModifyPermission();
4236 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4237 }
Jack Yue6146032018-02-27 15:30:01 -08004238
4239 @Override
4240 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4241 enforceModifyPermission();
4242 final Phone phone = getPhone(subId);
4243 if (phone == null) {
4244 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4245 return;
4246 }
4247
4248 phone.setRadioIndicationUpdateMode(filters, mode);
4249 }
fionaxu2c8bbbd2018-03-21 00:08:13 -07004250
4251 @Override
4252 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
4253 gid1, String gid2, String plmn, String spn) {
4254 enforceModifyPermission();
4255 final Phone phone = getPhone(subId);
4256 if (phone == null) {
4257 loge("setCarrierTestOverride fails with invalid subId: " + subId);
4258 return;
4259 }
4260 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
4261 }
4262
4263 @Override
4264 public int getCarrierIdListVersion(int subId) {
4265 enforceReadPrivilegedPermission();
4266 final Phone phone = getPhone(subId);
4267 if (phone == null) {
4268 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
4269 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
4270 }
4271 return phone.getCarrierIdListVersion();
4272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004273}