blob: cfd33ccfcef2f9dea1733270e06a44dc4fa7473d [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
45import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070046import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070047import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070048import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080049import android.provider.Settings;
Meng Wang1a7c35a2016-05-05 20:56:15 -070050import android.service.carrier.CarrierIdentifier;
Santos Cordon7a1885b2015-02-03 11:15:19 -080051import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080052import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070053import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070054import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.telephony.CellInfo;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.telephony.ClientRequestStats;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070057import android.telephony.IccOpenLogicalChannelResponse;
Ta-wei Yen87c49842016-05-13 21:19:52 -070058import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080059import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070060import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070061import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070062import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080064import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070065import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080066import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080067import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070068import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070069import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000070import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070071import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070072import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080073import android.telephony.ims.aidl.IImsConfig;
74import android.telephony.ims.aidl.IImsMmTelFeature;
75import android.telephony.ims.aidl.IImsRcsFeature;
76import android.telephony.ims.aidl.IImsRegistration;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070077import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080078import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080080import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080081import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080082
Andrew Lee312e8172014-10-23 17:01:36 -070083import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080084import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070085import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070086import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070087import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070088import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070089import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080092import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010093import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070094import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070095import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080097import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070098import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070099import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700100import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700101import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700102import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800103import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800104import com.android.internal.telephony.TelephonyPermissions;
Jonathan Basseribf5362b2017-07-19 12:22:35 -0700105import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700106import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700107import com.android.internal.telephony.uicc.IccIoResult;
108import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800109import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700110import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800111import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700112import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800113import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000114import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700115import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800116import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700117import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800118import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700119import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700120import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700122import java.io.FileDescriptor;
123import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800124import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800126import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800127import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100128import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800129import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130
131/**
132 * Implementation of the ITelephony interface.
133 */
Santos Cordon117fee72014-05-16 17:56:12 -0700134public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135 private static final String LOG_TAG = "PhoneInterfaceManager";
136 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
137 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800138 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139
140 // Message codes used with mMainThreadHandler
141 private static final int CMD_HANDLE_PIN_MMI = 1;
142 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
143 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
144 private static final int CMD_ANSWER_RINGING_CALL = 4;
145 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700146 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
147 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700148 private static final int CMD_OPEN_CHANNEL = 9;
149 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
150 private static final int CMD_CLOSE_CHANNEL = 11;
151 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800152 private static final int CMD_NV_READ_ITEM = 13;
153 private static final int EVENT_NV_READ_ITEM_DONE = 14;
154 private static final int CMD_NV_WRITE_ITEM = 15;
155 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
156 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
157 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
158 private static final int CMD_NV_RESET_CONFIG = 19;
159 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800160 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
161 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
162 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
163 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800164 private static final int CMD_SEND_ENVELOPE = 25;
165 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700166 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
167 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
168 private static final int CMD_EXCHANGE_SIM_IO = 31;
169 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800170 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
171 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700172 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
173 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700174 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
175 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700176 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
177 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
178 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
179 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700180 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
181 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
182 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
183 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700184 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800185 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
186 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000187 private static final int CMD_SWITCH_SLOTS = 50;
188 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800190 // Parameters of select command.
191 private static final int SELECT_COMMAND = 0xA4;
192 private static final int SELECT_P1 = 0x04;
193 private static final int SELECT_P2 = 0;
194 private static final int SELECT_P3 = 0x10;
195
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196 /** The singleton instance. */
197 private static PhoneInterfaceManager sInstance;
198
Wink Saville3ab207e2014-11-20 13:07:20 -0800199 private PhoneGlobals mApp;
200 private Phone mPhone;
201 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700202 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800203 private AppOpsManager mAppOps;
204 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800205 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800206 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207
Derek Tan97ebb422014-09-05 16:55:38 -0700208 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
209 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800210 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700211
Derek Tan740e1672017-06-27 14:56:27 -0700212 // The AID of ISD-R.
213 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
214
yinxub1bed742017-04-17 11:45:04 -0700215 private NetworkScanRequestTracker mNetworkScanRequestTracker;
216
Derek Tan89e89d42014-07-08 17:00:10 -0700217 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700218 * A request object to use for transmitting data to an ICC.
219 */
220 private static final class IccAPDUArgument {
221 public int channel, cla, command, p1, p2, p3;
222 public String data;
223
224 public IccAPDUArgument(int channel, int cla, int command,
225 int p1, int p2, int p3, String data) {
226 this.channel = channel;
227 this.cla = cla;
228 this.command = command;
229 this.p1 = p1;
230 this.p2 = p2;
231 this.p3 = p3;
232 this.data = data;
233 }
234 }
235
236 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700237 * A request object to use for transmitting data to an ICC.
238 */
239 private static final class ManualNetworkSelectionArgument {
240 public OperatorInfo operatorInfo;
241 public boolean persistSelection;
242
243 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
244 this.operatorInfo = operatorInfo;
245 this.persistSelection = persistSelection;
246 }
247 }
248
249 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700250 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
251 * request after sending. The main thread will notify the request when it is complete.
252 */
253 private static final class MainThreadRequest {
254 /** The argument to use for the request */
255 public Object argument;
256 /** The result of the request that is run on the main thread */
257 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800258 // The subscriber id that this request applies to. Defaults to
259 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
260 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700261
262 public MainThreadRequest(Object argument) {
263 this.argument = argument;
264 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800265
266 public MainThreadRequest(Object argument, Integer subId) {
267 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800268 if (subId != null) {
269 this.subId = subId;
270 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272 }
273
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800274 private static final class IncomingThirdPartyCallArgs {
275 public final ComponentName component;
276 public final String callId;
277 public final String callerDisplayName;
278
279 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
280 String callerDisplayName) {
281 this.component = component;
282 this.callId = callId;
283 this.callerDisplayName = callerDisplayName;
284 }
285 }
286
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287 /**
288 * A handler that processes messages on the main thread in the phone process. Since many
289 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
290 * inbound binder threads to the main thread in the phone process. The Binder thread
291 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
292 * on, which will be notified when the operation completes and will contain the result of the
293 * request.
294 *
295 * <p>If a MainThreadRequest object is provided in the msg.obj field,
296 * note that request.result must be set to something non-null for the calling thread to
297 * unblock.
298 */
299 private final class MainThreadHandler extends Handler {
300 @Override
301 public void handleMessage(Message msg) {
302 MainThreadRequest request;
303 Message onCompleted;
304 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800305 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700306 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700307
308 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700309 case CMD_HANDLE_USSD_REQUEST: {
310 request = (MainThreadRequest) msg.obj;
311 final Phone phone = getPhoneFromRequest(request);
312 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
313 String ussdRequest = ussdObject.first;
314 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700315
316 if (!isUssdApiAllowed(request.subId)) {
317 // Carrier does not support use of this API, return failure.
318 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
319 UssdResponse response = new UssdResponse(ussdRequest, null);
320 Bundle returnData = new Bundle();
321 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
322 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
323
324 request.result = true;
325 synchronized (request) {
326 request.notifyAll();
327 }
328 return;
329 }
330
Tyler Gunn52dcf772017-04-26 11:30:31 -0700331 try {
332 request.result = phone != null ?
333 phone.handleUssdRequest(ussdRequest, wrappedCallback)
334 : false;
335 } catch (CallStateException cse) {
336 request.result = false;
337 }
pkanwar32d516d2016-10-14 19:37:38 -0700338 // Wake up the requesting thread
339 synchronized (request) {
340 request.notifyAll();
341 }
342 break;
343 }
344
Yorke Lee716f67e2015-06-17 15:39:16 -0700345 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700347 final Phone phone = getPhoneFromRequest(request);
348 request.result = phone != null ?
349 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
350 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700351 // Wake up the requesting thread
352 synchronized (request) {
353 request.notifyAll();
354 }
355 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700356 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357
358 case CMD_HANDLE_NEIGHBORING_CELL:
359 request = (MainThreadRequest) msg.obj;
360 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
361 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700362 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700363 break;
364
365 case EVENT_NEIGHBORING_CELL_DONE:
366 ar = (AsyncResult) msg.obj;
367 request = (MainThreadRequest) ar.userObj;
368 if (ar.exception == null && ar.result != null) {
369 request.result = ar.result;
370 } else {
371 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800372 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 }
374 // Wake up the requesting thread
375 synchronized (request) {
376 request.notifyAll();
377 }
378 break;
379
380 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700381 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800382 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700383 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 break;
385
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 case CMD_END_CALL:
387 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800388 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700389 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700390 Phone phone = getPhone(end_subId);
391 if (phone == null) {
392 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
393 break;
394 }
395 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700396 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
397 // CDMA: If the user presses the Power button we treat it as
398 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700399 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
401 // GSM: End the call as per the Phone state
402 hungUp = PhoneUtils.hangup(mCM);
403 } else {
404 throw new IllegalStateException("Unexpected phone type: " + phoneType);
405 }
406 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
407 request.result = hungUp;
408 // Wake up the requesting thread
409 synchronized (request) {
410 request.notifyAll();
411 }
412 break;
413
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700415 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700416 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800417 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700418 if (uiccCard == null) {
419 loge("iccTransmitApduLogicalChannel: No UICC");
420 request.result = new IccIoResult(0x6F, 0, (byte[])null);
421 synchronized (request) {
422 request.notifyAll();
423 }
424 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700425 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
426 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700427 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700428 iccArgument.channel, iccArgument.cla, iccArgument.command,
429 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700431 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700432 break;
433
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 ar = (AsyncResult) msg.obj;
436 request = (MainThreadRequest) ar.userObj;
437 if (ar.exception == null && ar.result != null) {
438 request.result = ar.result;
439 } else {
440 request.result = new IccIoResult(0x6F, 0, (byte[])null);
441 if (ar.result == null) {
442 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800443 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800445 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 } else {
447 loge("iccTransmitApduLogicalChannel: Unknown exception");
448 }
449 }
450 synchronized (request) {
451 request.notifyAll();
452 }
453 break;
454
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
456 request = (MainThreadRequest) msg.obj;
457 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800458 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 if (uiccCard == null) {
460 loge("iccTransmitApduBasicChannel: No UICC");
461 request.result = new IccIoResult(0x6F, 0, (byte[])null);
462 synchronized (request) {
463 request.notifyAll();
464 }
465 } else {
466 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
467 request);
468 uiccCard.iccTransmitApduBasicChannel(
469 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
470 iccArgument.p3, iccArgument.data, onCompleted);
471 }
472 break;
473
474 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
475 ar = (AsyncResult) msg.obj;
476 request = (MainThreadRequest) ar.userObj;
477 if (ar.exception == null && ar.result != null) {
478 request.result = ar.result;
479 } else {
480 request.result = new IccIoResult(0x6F, 0, (byte[])null);
481 if (ar.result == null) {
482 loge("iccTransmitApduBasicChannel: Empty response");
483 } else if (ar.exception instanceof CommandException) {
484 loge("iccTransmitApduBasicChannel: CommandException: " +
485 ar.exception);
486 } else {
487 loge("iccTransmitApduBasicChannel: Unknown exception");
488 }
489 }
490 synchronized (request) {
491 request.notifyAll();
492 }
493 break;
494
495 case CMD_EXCHANGE_SIM_IO:
496 request = (MainThreadRequest) msg.obj;
497 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800498 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 if (uiccCard == null) {
500 loge("iccExchangeSimIO: No UICC");
501 request.result = new IccIoResult(0x6F, 0, (byte[])null);
502 synchronized (request) {
503 request.notifyAll();
504 }
505 } else {
506 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
507 request);
508 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
509 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
510 iccArgument.data, onCompleted);
511 }
512 break;
513
514 case EVENT_EXCHANGE_SIM_IO_DONE:
515 ar = (AsyncResult) msg.obj;
516 request = (MainThreadRequest) ar.userObj;
517 if (ar.exception == null && ar.result != null) {
518 request.result = ar.result;
519 } else {
520 request.result = new IccIoResult(0x6f, 0, (byte[])null);
521 }
522 synchronized (request) {
523 request.notifyAll();
524 }
525 break;
526
Derek Tan4d5e5c12014-02-04 11:54:58 -0800527 case CMD_SEND_ENVELOPE:
528 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700530 if (uiccCard == null) {
531 loge("sendEnvelopeWithStatus: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
533 synchronized (request) {
534 request.notifyAll();
535 }
536 } else {
537 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
538 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
539 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800540 break;
541
542 case EVENT_SEND_ENVELOPE_DONE:
543 ar = (AsyncResult) msg.obj;
544 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700545 if (ar.exception == null && ar.result != null) {
546 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700548 request.result = new IccIoResult(0x6F, 0, (byte[])null);
549 if (ar.result == null) {
550 loge("sendEnvelopeWithStatus: Empty response");
551 } else if (ar.exception instanceof CommandException) {
552 loge("sendEnvelopeWithStatus: CommandException: " +
553 ar.exception);
554 } else {
555 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
556 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800557 }
558 synchronized (request) {
559 request.notifyAll();
560 }
561 break;
562
Shishir Agrawal566b7612013-10-28 14:41:00 -0700563 case CMD_OPEN_CHANNEL:
564 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800566 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700567 if (uiccCard == null) {
568 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800569 request.result = new IccOpenLogicalChannelResponse(-1,
570 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700571 synchronized (request) {
572 request.notifyAll();
573 }
574 } else {
575 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800576 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
577 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700578 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 break;
580
581 case EVENT_OPEN_CHANNEL_DONE:
582 ar = (AsyncResult) msg.obj;
583 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 int[] result = (int[]) ar.result;
587 int channelId = result[0];
588 byte[] selectResponse = null;
589 if (result.length > 1) {
590 selectResponse = new byte[result.length - 1];
591 for (int i = 1; i < result.length; ++i) {
592 selectResponse[i - 1] = (byte) result[i];
593 }
594 }
595 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 if (ar.result == null) {
599 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 if (ar.exception != null) {
602 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
603 }
604
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700605 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700606 if (ar.exception instanceof CommandException) {
607 CommandException.Error error =
608 ((CommandException) (ar.exception)).getCommandError();
609 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700611 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700612 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 }
614 }
615 openChannelResp = new IccOpenLogicalChannelResponse(
616 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700618 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 synchronized (request) {
620 request.notifyAll();
621 }
622 break;
623
624 case CMD_CLOSE_CHANNEL:
625 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800626 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700627 if (uiccCard == null) {
628 loge("iccCloseLogicalChannel: No UICC");
629 request.result = new IccIoResult(0x6F, 0, (byte[])null);
630 synchronized (request) {
631 request.notifyAll();
632 }
633 } else {
634 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
635 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
636 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 break;
638
639 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800640 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
641 break;
642
643 case CMD_NV_READ_ITEM:
644 request = (MainThreadRequest) msg.obj;
645 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
646 mPhone.nvReadItem((Integer) request.argument, onCompleted);
647 break;
648
649 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 ar = (AsyncResult) msg.obj;
651 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800652 if (ar.exception == null && ar.result != null) {
653 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800655 request.result = "";
656 if (ar.result == null) {
657 loge("nvReadItem: Empty response");
658 } else if (ar.exception instanceof CommandException) {
659 loge("nvReadItem: CommandException: " +
660 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800662 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 }
664 }
665 synchronized (request) {
666 request.notifyAll();
667 }
668 break;
669
Jake Hambye994d462014-02-03 13:10:13 -0800670 case CMD_NV_WRITE_ITEM:
671 request = (MainThreadRequest) msg.obj;
672 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
673 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
674 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
675 break;
676
677 case EVENT_NV_WRITE_ITEM_DONE:
678 handleNullReturnEvent(msg, "nvWriteItem");
679 break;
680
681 case CMD_NV_WRITE_CDMA_PRL:
682 request = (MainThreadRequest) msg.obj;
683 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
684 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
685 break;
686
687 case EVENT_NV_WRITE_CDMA_PRL_DONE:
688 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
689 break;
690
691 case CMD_NV_RESET_CONFIG:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
694 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
695 break;
696
697 case EVENT_NV_RESET_CONFIG_DONE:
698 handleNullReturnEvent(msg, "nvResetConfig");
699 break;
700
Jake Hamby7c27be32014-03-03 13:25:59 -0800701 case CMD_GET_PREFERRED_NETWORK_TYPE:
702 request = (MainThreadRequest) msg.obj;
703 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700704 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800705 break;
706
707 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
708 ar = (AsyncResult) msg.obj;
709 request = (MainThreadRequest) ar.userObj;
710 if (ar.exception == null && ar.result != null) {
711 request.result = ar.result; // Integer
712 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800713 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 if (ar.result == null) {
715 loge("getPreferredNetworkType: Empty response");
716 } else if (ar.exception instanceof CommandException) {
717 loge("getPreferredNetworkType: CommandException: " +
718 ar.exception);
719 } else {
720 loge("getPreferredNetworkType: Unknown exception");
721 }
722 }
723 synchronized (request) {
724 request.notifyAll();
725 }
726 break;
727
728 case CMD_SET_PREFERRED_NETWORK_TYPE:
729 request = (MainThreadRequest) msg.obj;
730 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
731 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700732 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800733 break;
734
735 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
736 handleNullReturnEvent(msg, "setPreferredNetworkType");
737 break;
738
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800739 case CMD_SET_VOICEMAIL_NUMBER:
740 request = (MainThreadRequest) msg.obj;
741 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
742 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800743 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
744 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800745 break;
746
747 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
748 handleNullReturnEvent(msg, "setVoicemailNumber");
749 break;
750
Stuart Scott54788802015-03-30 13:18:01 -0700751 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
754 request);
755 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
756 break;
757
758 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
759 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
760 break;
761
Shishir Agrawal302c8692015-06-19 13:49:39 -0700762 case CMD_PERFORM_NETWORK_SCAN:
763 request = (MainThreadRequest) msg.obj;
764 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
765 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
766 break;
767
768 case EVENT_PERFORM_NETWORK_SCAN_DONE:
769 ar = (AsyncResult) msg.obj;
770 request = (MainThreadRequest) ar.userObj;
771 CellNetworkScanResult cellScanResult;
772 if (ar.exception == null && ar.result != null) {
773 cellScanResult = new CellNetworkScanResult(
774 CellNetworkScanResult.STATUS_SUCCESS,
775 (List<OperatorInfo>) ar.result);
776 } else {
777 if (ar.result == null) {
778 loge("getCellNetworkScanResults: Empty response");
779 }
780 if (ar.exception != null) {
781 loge("getCellNetworkScanResults: Exception: " + ar.exception);
782 }
783 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
784 if (ar.exception instanceof CommandException) {
785 CommandException.Error error =
786 ((CommandException) (ar.exception)).getCommandError();
787 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
788 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
789 } else if (error == CommandException.Error.GENERIC_FAILURE) {
790 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
791 }
792 }
793 cellScanResult = new CellNetworkScanResult(errorCode, null);
794 }
795 request.result = cellScanResult;
796 synchronized (request) {
797 request.notifyAll();
798 }
799 break;
800
801 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
802 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700803 ManualNetworkSelectionArgument selArg =
804 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700805 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
806 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700807 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
808 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700809 break;
810
811 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
812 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
813 break;
814
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700815 case CMD_GET_MODEM_ACTIVITY_INFO:
816 request = (MainThreadRequest) msg.obj;
817 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700818 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700819 break;
820
821 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
822 ar = (AsyncResult) msg.obj;
823 request = (MainThreadRequest) ar.userObj;
824 if (ar.exception == null && ar.result != null) {
825 request.result = ar.result;
826 } else {
827 if (ar.result == null) {
828 loge("queryModemActivityInfo: Empty response");
829 } else if (ar.exception instanceof CommandException) {
830 loge("queryModemActivityInfo: CommandException: " +
831 ar.exception);
832 } else {
833 loge("queryModemActivityInfo: Unknown exception");
834 }
835 }
Amit Mahajand4766222016-01-28 15:28:28 -0800836 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
837 if (request.result == null) {
838 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
839 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700840 synchronized (request) {
841 request.notifyAll();
842 }
843 break;
844
Meng Wang1a7c35a2016-05-05 20:56:15 -0700845 case CMD_SET_ALLOWED_CARRIERS:
846 request = (MainThreadRequest) msg.obj;
847 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
848 mPhone.setAllowedCarriers(
849 (List<CarrierIdentifier>) request.argument,
850 onCompleted);
851 break;
852
853 case EVENT_SET_ALLOWED_CARRIERS_DONE:
854 ar = (AsyncResult) msg.obj;
855 request = (MainThreadRequest) ar.userObj;
856 if (ar.exception == null && ar.result != null) {
857 request.result = ar.result;
858 } else {
859 if (ar.result == null) {
860 loge("setAllowedCarriers: Empty response");
861 } else if (ar.exception instanceof CommandException) {
862 loge("setAllowedCarriers: CommandException: " +
863 ar.exception);
864 } else {
865 loge("setAllowedCarriers: Unknown exception");
866 }
867 }
868 // Result cannot be null. Return -1 on error.
869 if (request.result == null) {
870 request.result = new int[]{-1};
871 }
872 synchronized (request) {
873 request.notifyAll();
874 }
875 break;
876
877 case CMD_GET_ALLOWED_CARRIERS:
878 request = (MainThreadRequest) msg.obj;
879 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
880 mPhone.getAllowedCarriers(onCompleted);
881 break;
882
883 case EVENT_GET_ALLOWED_CARRIERS_DONE:
884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null && ar.result != null) {
887 request.result = ar.result;
888 } else {
889 if (ar.result == null) {
890 loge("getAllowedCarriers: Empty response");
891 } else if (ar.exception instanceof CommandException) {
892 loge("getAllowedCarriers: CommandException: " +
893 ar.exception);
894 } else {
895 loge("getAllowedCarriers: Unknown exception");
896 }
897 }
898 // Result cannot be null. Return empty list of CarrierIdentifier.
899 if (request.result == null) {
900 request.result = new ArrayList<CarrierIdentifier>(0);
901 }
902 synchronized (request) {
903 request.notifyAll();
904 }
905 break;
906
Nathan Haroldb3014052017-01-25 15:57:32 -0800907 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
908 ar = (AsyncResult) msg.obj;
909 request = (MainThreadRequest) ar.userObj;
910 if (ar.exception == null && ar.result != null) {
911 request.result = ar.result;
912 } else {
913 request.result = new IllegalArgumentException(
914 "Failed to retrieve Forbidden Plmns");
915 if (ar.result == null) {
916 loge("getForbiddenPlmns: Empty response");
917 } else {
918 loge("getForbiddenPlmns: Unknown exception");
919 }
920 }
921 synchronized (request) {
922 request.notifyAll();
923 }
924 break;
925
926 case CMD_GET_FORBIDDEN_PLMNS:
927 request = (MainThreadRequest) msg.obj;
928 uiccCard = getUiccCardFromRequest(request);
929 if (uiccCard == null) {
930 loge("getForbiddenPlmns() UiccCard is null");
931 request.result = new IllegalArgumentException(
932 "getForbiddenPlmns() UiccCard is null");
933 synchronized (request) {
934 request.notifyAll();
935 }
936 break;
937 }
938 Integer appType = (Integer) request.argument;
939 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
940 if (uiccApp == null) {
941 loge("getForbiddenPlmns() no app with specified type -- "
942 + appType);
943 request.result = new IllegalArgumentException("Failed to get UICC App");
944 synchronized (request) {
945 request.notifyAll();
946 }
947 break;
948 } else {
949 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
950 + " specified type -- " + appType);
951 }
952 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
953 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
954 onCompleted);
955 break;
956
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000957 case CMD_SWITCH_SLOTS:
958 request = (MainThreadRequest) msg.obj;
959 int[] physicalSlots = (int[]) request.argument;
960 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
961 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
962 break;
963
964 case EVENT_SWITCH_SLOTS_DONE:
965 ar = (AsyncResult) msg.obj;
966 request = (MainThreadRequest) ar.userObj;
967 request.result = (ar.exception == null);
968 synchronized (request) {
969 request.notifyAll();
970 }
971 break;
972
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700973 default:
974 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
975 break;
976 }
977 }
Jake Hambye994d462014-02-03 13:10:13 -0800978
979 private void handleNullReturnEvent(Message msg, String command) {
980 AsyncResult ar = (AsyncResult) msg.obj;
981 MainThreadRequest request = (MainThreadRequest) ar.userObj;
982 if (ar.exception == null) {
983 request.result = true;
984 } else {
985 request.result = false;
986 if (ar.exception instanceof CommandException) {
987 loge(command + ": CommandException: " + ar.exception);
988 } else {
989 loge(command + ": Unknown exception");
990 }
991 }
992 synchronized (request) {
993 request.notifyAll();
994 }
995 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700996 }
997
998 /**
999 * Posts the specified command to be executed on the main thread,
1000 * waits for the request to complete, and returns the result.
1001 * @see #sendRequestAsync
1002 */
1003 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001004 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001005 }
1006
1007 /**
1008 * Posts the specified command to be executed on the main thread,
1009 * waits for the request to complete, and returns the result.
1010 * @see #sendRequestAsync
1011 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001012 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001013 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1014 throw new RuntimeException("This method will deadlock if called from the main thread.");
1015 }
1016
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001017 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001018 Message msg = mMainThreadHandler.obtainMessage(command, request);
1019 msg.sendToTarget();
1020
1021 // Wait for the request to complete
1022 synchronized (request) {
1023 while (request.result == null) {
1024 try {
1025 request.wait();
1026 } catch (InterruptedException e) {
1027 // Do nothing, go back and wait until the request is complete
1028 }
1029 }
1030 }
1031 return request.result;
1032 }
1033
1034 /**
1035 * Asynchronous ("fire and forget") version of sendRequest():
1036 * Posts the specified command to be executed on the main thread, and
1037 * returns immediately.
1038 * @see #sendRequest
1039 */
1040 private void sendRequestAsync(int command) {
1041 mMainThreadHandler.sendEmptyMessage(command);
1042 }
1043
1044 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001045 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1046 * @see {@link #sendRequest(int,Object)}
1047 */
1048 private void sendRequestAsync(int command, Object argument) {
1049 MainThreadRequest request = new MainThreadRequest(argument);
1050 Message msg = mMainThreadHandler.obtainMessage(command, request);
1051 msg.sendToTarget();
1052 }
1053
1054 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001055 * Initialize the singleton PhoneInterfaceManager instance.
1056 * This is only done once, at startup, from PhoneApp.onCreate().
1057 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001058 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001059 synchronized (PhoneInterfaceManager.class) {
1060 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001061 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001062 } else {
1063 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1064 }
1065 return sInstance;
1066 }
1067 }
1068
1069 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001070 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001071 mApp = app;
1072 mPhone = phone;
1073 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001074 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001075 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1076 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001077 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001078 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001079 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001080 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001081
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001082 publish();
1083 }
1084
1085 private void publish() {
1086 if (DBG) log("publish: " + this);
1087
1088 ServiceManager.addService("phone", this);
1089 }
1090
Stuart Scott584921c2015-01-15 17:10:34 -08001091 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001092 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1093 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001094 }
1095
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001096 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1097 Phone phone = getPhoneFromRequest(request);
1098 return phone == null ? null :
1099 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1100 }
1101
Wink Saville36469e72014-06-11 15:17:00 -07001102 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001103 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001104 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001106 //
1107 // Implementation of the ITelephony interface.
1108 //
1109
1110 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001111 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001112 }
1113
Wink Savilleb564aae2014-10-23 10:18:09 -07001114 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001115 if (DBG) log("dial: " + number);
1116 // No permission check needed here: This is just a wrapper around the
1117 // ACTION_DIAL intent, which is available to any app since it puts up
1118 // the UI before it does anything.
1119
1120 String url = createTelUrl(number);
1121 if (url == null) {
1122 return;
1123 }
1124
1125 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001126 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001127 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1128 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1129 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1130 mApp.startActivity(intent);
1131 }
1132 }
1133
1134 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001135 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001136 }
1137
Wink Savilleb564aae2014-10-23 10:18:09 -07001138 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001139 if (DBG) log("call: " + number);
1140
1141 // This is just a wrapper around the ACTION_CALL intent, but we still
1142 // need to do a permission check since we're calling startActivity()
1143 // from the context of the phone app.
1144 enforceCallPermission();
1145
1146 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1147 != AppOpsManager.MODE_ALLOWED) {
1148 return;
1149 }
1150
1151 String url = createTelUrl(number);
1152 if (url == null) {
1153 return;
1154 }
1155
Wink Saville08874612014-08-31 19:19:58 -07001156 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001157 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001158 if (slist != null) {
1159 for (SubscriptionInfo subInfoRecord : slist) {
1160 if (subInfoRecord.getSubscriptionId() == subId) {
1161 isValid = true;
1162 break;
1163 }
Wink Saville08874612014-08-31 19:19:58 -07001164 }
1165 }
1166 if (isValid == false) {
1167 return;
1168 }
1169
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001170 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001171 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001172 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1173 mApp.startActivity(intent);
1174 }
1175
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001176 /**
1177 * End a call based on call state
1178 * @return true is a call was ended
1179 */
1180 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001181 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001182 }
1183
1184 /**
1185 * End a call based on the call state of the subId
1186 * @return true is a call was ended
1187 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001188 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001189 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001190 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001191 }
1192
1193 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001194 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001195 }
1196
Wink Savilleb564aae2014-10-23 10:18:09 -07001197 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001198 if (DBG) log("answerRingingCall...");
1199 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1200 // but that can probably wait till the big TelephonyManager API overhaul.
1201 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1202 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001203 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001204 }
1205
1206 /**
1207 * Make the actual telephony calls to implement answerRingingCall().
1208 * This should only be called from the main thread of the Phone app.
1209 * @see #answerRingingCall
1210 *
1211 * TODO: it would be nice to return true if we answered the call, or
1212 * false if there wasn't actually a ringing incoming call, or some
1213 * other error occurred. (In other words, pass back the return value
1214 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1215 * But that would require calling this method via sendRequest() rather
1216 * than sendRequestAsync(), and right now we don't actually *need* that
1217 * return value, so let's just return void for now.
1218 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001219 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001220 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001221 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001222 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1223 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001224 if (hasActiveCall && hasHoldingCall) {
1225 // Both lines are in use!
1226 // TODO: provide a flag to let the caller specify what
1227 // policy to use if both lines are in use. (The current
1228 // behavior is hardwired to "answer incoming, end ongoing",
1229 // which is how the CALL button is specced to behave.)
1230 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1231 return;
1232 } else {
1233 // answerCall() will automatically hold the current active
1234 // call, if there is one.
1235 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1236 return;
1237 }
1238 } else {
1239 // No call was ringing.
1240 return;
1241 }
1242 }
1243
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001245 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001246 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001247 public void silenceRinger() {
1248 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 }
1250
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001251 @Override
1252 public boolean isOffhook(String callingPackage) {
1253 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001254 }
1255
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001256 @Override
1257 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001258 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1259 mApp, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001260 return false;
1261 }
1262
Sanket Padawe356d7632015-06-22 14:03:32 -07001263 final Phone phone = getPhone(subId);
1264 if (phone != null) {
1265 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1266 } else {
1267 return false;
1268 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001269 }
1270
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001271 @Override
1272 public boolean isRinging(String callingPackage) {
1273 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001274 }
1275
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001276 @Override
1277 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1279 mApp, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001280 return false;
1281 }
1282
Sanket Padawe356d7632015-06-22 14:03:32 -07001283 final Phone phone = getPhone(subId);
1284 if (phone != null) {
1285 return (phone.getState() == PhoneConstants.State.RINGING);
1286 } else {
1287 return false;
1288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001289 }
1290
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001291 @Override
1292 public boolean isIdle(String callingPackage) {
1293 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001294 }
1295
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001296 @Override
1297 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001298 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1299 mApp, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001300 return false;
1301 }
1302
Sanket Padawe356d7632015-06-22 14:03:32 -07001303 final Phone phone = getPhone(subId);
1304 if (phone != null) {
1305 return (phone.getState() == PhoneConstants.State.IDLE);
1306 } else {
1307 return false;
1308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001309 }
1310
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001312 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001313 }
1314
Wink Savilleb564aae2014-10-23 10:18:09 -07001315 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001316 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001317 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1318 }
1319
1320 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001321 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001322 }
1323
Wink Savilleb564aae2014-10-23 10:18:09 -07001324 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001325 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001326 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1327 }
1328
1329 /** {@hide} */
1330 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001331 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001332 }
1333
Wink Savilleb564aae2014-10-23 10:18:09 -07001334 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001336 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001337 checkSimPin.start();
1338 return checkSimPin.unlockSim(null, pin);
1339 }
1340
Wink Saville9de0f752013-10-22 19:04:03 -07001341 /** {@hide} */
1342 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001343 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001344 }
1345
Wink Savilleb564aae2014-10-23 10:18:09 -07001346 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001347 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001348 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349 checkSimPuk.start();
1350 return checkSimPuk.unlockSim(puk, pin);
1351 }
1352
1353 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001354 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001355 * a synchronous one.
1356 */
1357 private static class UnlockSim extends Thread {
1358
1359 private final IccCard mSimCard;
1360
1361 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001362 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1363 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364
1365 // For replies from SimCard interface
1366 private Handler mHandler;
1367
1368 // For async handler to identify request type
1369 private static final int SUPPLY_PIN_COMPLETE = 100;
1370
1371 public UnlockSim(IccCard simCard) {
1372 mSimCard = simCard;
1373 }
1374
1375 @Override
1376 public void run() {
1377 Looper.prepare();
1378 synchronized (UnlockSim.this) {
1379 mHandler = new Handler() {
1380 @Override
1381 public void handleMessage(Message msg) {
1382 AsyncResult ar = (AsyncResult) msg.obj;
1383 switch (msg.what) {
1384 case SUPPLY_PIN_COMPLETE:
1385 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1386 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001387 mRetryCount = msg.arg1;
1388 if (ar.exception != null) {
1389 if (ar.exception instanceof CommandException &&
1390 ((CommandException)(ar.exception)).getCommandError()
1391 == CommandException.Error.PASSWORD_INCORRECT) {
1392 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1393 } else {
1394 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1395 }
1396 } else {
1397 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1398 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001399 mDone = true;
1400 UnlockSim.this.notifyAll();
1401 }
1402 break;
1403 }
1404 }
1405 };
1406 UnlockSim.this.notifyAll();
1407 }
1408 Looper.loop();
1409 }
1410
1411 /*
1412 * Use PIN or PUK to unlock SIM card
1413 *
1414 * If PUK is null, unlock SIM card with PIN
1415 *
1416 * If PUK is not null, unlock SIM card with PUK and set PIN code
1417 */
Wink Saville9de0f752013-10-22 19:04:03 -07001418 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419
1420 while (mHandler == null) {
1421 try {
1422 wait();
1423 } catch (InterruptedException e) {
1424 Thread.currentThread().interrupt();
1425 }
1426 }
1427 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1428
1429 if (puk == null) {
1430 mSimCard.supplyPin(pin, callback);
1431 } else {
1432 mSimCard.supplyPuk(puk, pin, callback);
1433 }
1434
1435 while (!mDone) {
1436 try {
1437 Log.d(LOG_TAG, "wait for done");
1438 wait();
1439 } catch (InterruptedException e) {
1440 // Restore the interrupted status
1441 Thread.currentThread().interrupt();
1442 }
1443 }
1444 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001445 int[] resultArray = new int[2];
1446 resultArray[0] = mResult;
1447 resultArray[1] = mRetryCount;
1448 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449 }
1450 }
1451
1452 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001453 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001454
1455 }
1456
Wink Savilleb564aae2014-10-23 10:18:09 -07001457 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458 // No permission check needed here: this call is harmless, and it's
1459 // needed for the ServiceState.requestStateUpdate() call (which is
1460 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001461 final Phone phone = getPhone(subId);
1462 if (phone != null) {
1463 phone.updateServiceLocation();
1464 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001465 }
1466
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001467 @Override
1468 public boolean isRadioOn(String callingPackage) {
1469 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001470 }
1471
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001472 @Override
1473 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1475 mApp, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001476 return false;
1477 }
1478 return isRadioOnForSubscriber(subId);
1479 }
1480
1481 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001482 final Phone phone = getPhone(subId);
1483 if (phone != null) {
1484 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1485 } else {
1486 return false;
1487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 }
1489
1490 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001491 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001492
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001493 }
Wink Saville36469e72014-06-11 15:17:00 -07001494
Wink Savilleb564aae2014-10-23 10:18:09 -07001495 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001497 final Phone phone = getPhone(subId);
1498 if (phone != null) {
1499 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1500 }
Wink Saville36469e72014-06-11 15:17:00 -07001501 }
1502
1503 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001504 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001505 }
1506
Wink Savilleb564aae2014-10-23 10:18:09 -07001507 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001508 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001509 final Phone phone = getPhone(subId);
1510 if (phone == null) {
1511 return false;
1512 }
1513 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001514 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001515 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001516 }
1517 return true;
1518 }
Wink Saville36469e72014-06-11 15:17:00 -07001519
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001520 public boolean needMobileRadioShutdown() {
1521 /*
1522 * If any of the Radios are available, it will need to be
1523 * shutdown. So return true if any Radio is available.
1524 */
1525 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1526 Phone phone = PhoneFactory.getPhone(i);
1527 if (phone != null && phone.isRadioAvailable()) return true;
1528 }
1529 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1530 return false;
1531 }
1532
1533 public void shutdownMobileRadios() {
1534 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1535 logv("Shutting down Phone " + i);
1536 shutdownRadioUsingPhoneId(i);
1537 }
1538 }
1539
1540 private void shutdownRadioUsingPhoneId(int phoneId) {
1541 enforceModifyPermission();
1542 Phone phone = PhoneFactory.getPhone(phoneId);
1543 if (phone != null && phone.isRadioAvailable()) {
1544 phone.shutdownRadio();
1545 }
1546 }
1547
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001549 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001550 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1551 if (defaultPhone != null) {
1552 defaultPhone.setRadioPower(turnOn);
1553 return true;
1554 } else {
1555 loge("There's no default phone.");
1556 return false;
1557 }
Wink Saville36469e72014-06-11 15:17:00 -07001558 }
1559
Wink Savilleb564aae2014-10-23 10:18:09 -07001560 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001561 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001562 final Phone phone = getPhone(subId);
1563 if (phone != null) {
1564 phone.setRadioPower(turnOn);
1565 return true;
1566 } else {
1567 return false;
1568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 }
1570
Wink Saville36469e72014-06-11 15:17:00 -07001571 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001572 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 public boolean enableDataConnectivity() {
1574 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001575 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001576 final Phone phone = getPhone(subId);
1577 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001578 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001579 return true;
1580 } else {
1581 return false;
1582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
Wink Saville36469e72014-06-11 15:17:00 -07001585 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001586 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 public boolean disableDataConnectivity() {
1588 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001589 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001590 final Phone phone = getPhone(subId);
1591 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001592 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001593 return true;
1594 } else {
1595 return false;
1596 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001597 }
1598
Sanket Padawe356d7632015-06-22 14:03:32 -07001599 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001600 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001601 final Phone phone = getPhone(subId);
1602 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001603 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001604 } else {
1605 return false;
1606 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001607 }
1608
1609 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001610 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001611 }
1612
pkanwarae03a6b2016-11-06 20:37:09 -08001613 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001614 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001615 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1616 return;
1617 }
1618 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1619 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1620 };
1621
Wink Savilleb564aae2014-10-23 10:18:09 -07001622 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001623 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001624 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1625 return false;
1626 }
Wink Saville36469e72014-06-11 15:17:00 -07001627 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001628 }
1629
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001631 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001632 }
1633
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001634 public int getCallStateForSlot(int slotIndex) {
1635 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001636 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001637 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 }
1639
Sanket Padawe356d7632015-06-22 14:03:32 -07001640 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001642 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001643 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001644 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001645 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001646 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 }
1649
Sanket Padawe356d7632015-06-22 14:03:32 -07001650 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001652 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 if (phone != null) {
1654 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1655 } else {
1656 return TelephonyManager.DATA_ACTIVITY_NONE;
1657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
1659
1660 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001661 public Bundle getCellLocation(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001662 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001663 callingPackage, Binder.getCallingUid(), "getCellLocation")) {
Svetoslav64fad262015-04-14 14:35:21 -07001664 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 }
1666
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001667 if (DBG_LOC) log("getCellLocation: is active user");
1668 Bundle data = new Bundle();
1669 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1670 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001671 return null;
1672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001674 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001675 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1676 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001677 }
1678
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001679 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001680 public String getNetworkCountryIsoForPhone(int phoneId) {
1681 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1682 // registered cell info, so return a NULL country instead.
1683 final long identity = Binder.clearCallingIdentity();
1684 try {
1685 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1686 if (TelephonyManager.NETWORK_TYPE_IWLAN
1687 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1688 return "";
1689 }
1690 } finally {
1691 Binder.restoreCallingIdentity(identity);
1692 }
1693 return TelephonyManager.getTelephonyProperty(
1694 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1695 }
1696
1697 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001699 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001700 }
1701
Sanket Padawe356d7632015-06-22 14:03:32 -07001702 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001703 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 mApp.enforceCallingOrSelfPermission(
1705 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001706 final Phone phone = getPhone(subId);
1707 if (phone != null) {
1708 phone.enableLocationUpdates();
1709 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 }
1711
1712 @Override
1713 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001714 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001715 }
1716
Sanket Padawe356d7632015-06-22 14:03:32 -07001717 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001718 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 mApp.enforceCallingOrSelfPermission(
1720 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001721 final Phone phone = getPhone(subId);
1722 if (phone != null) {
1723 phone.disableLocationUpdates();
1724 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001725 }
1726
1727 @Override
1728 @SuppressWarnings("unchecked")
1729 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001730 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001731 callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001732 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 }
1734
1735 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1736 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1737 return null;
1738 }
Svetoslav64fad262015-04-14 14:35:21 -07001739
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001740 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001741
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001742 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001744 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001745 try {
1746 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1747 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1748 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1749 } catch (RuntimeException e) {
1750 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001752 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753 }
1754
1755
1756 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001757 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001758 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001759 callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001760 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 }
1762
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001763 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001764 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001765 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1766 for (Phone phone : PhoneFactory.getPhones()) {
1767 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1768 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001770 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 }
1772
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001773 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001775 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001776 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001777 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 }
1779
Shishir Agrawala9f32182016-04-12 12:00:16 -07001780 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001781 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001782 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1783 mApp, callingPackage, "getImeiForSlot")) {
1784 return null;
1785 }
1786 Phone phone = PhoneFactory.getPhone(slotIndex);
1787 return phone == null ? null : phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001788 }
1789
1790 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001791 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1793 mApp, callingPackage, "getMeidForSlot")) {
Jack Yu2af8d712017-03-15 17:14:14 -07001794 return null;
1795 }
1796 Phone phone = PhoneFactory.getPhone(slotIndex);
1797 return phone == null ? null : phone.getMeid();
1798 }
1799
1800 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001801 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1803 mApp, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1804 return null;
1805 }
1806 Phone phone = PhoneFactory.getPhone(slotIndex);
1807 return phone == null ? null : phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001808 }
1809
fionaxu43304da2017-11-27 22:51:16 -08001810 @Override
1811 public int getSubscriptionCarrierId(int subId) {
1812 final Phone phone = getPhone(subId);
1813 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1814 }
1815
1816 @Override
1817 public String getSubscriptionCarrierName(int subId) {
1818 final Phone phone = getPhone(subId);
1819 return phone == null ? null : phone.getCarrierName();
1820 }
1821
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 //
1823 // Internal helper methods.
1824 //
1825
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001826 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1828 *
1829 * @throws SecurityException if the caller does not have the required permission
1830 */
1831 private void enforceModifyPermission() {
1832 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1833 }
1834
1835 /**
1836 * Make sure the caller has the CALL_PHONE permission.
1837 *
1838 * @throws SecurityException if the caller does not have the required permission
1839 */
1840 private void enforceCallPermission() {
1841 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1842 }
1843
Stuart Scott8eef64f2015-04-08 15:13:54 -07001844 private void enforceConnectivityInternalPermission() {
1845 mApp.enforceCallingOrSelfPermission(
1846 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1847 "ConnectivityService");
1848 }
1849
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 private String createTelUrl(String number) {
1851 if (TextUtils.isEmpty(number)) {
1852 return null;
1853 }
1854
Jake Hambye994d462014-02-03 13:10:13 -08001855 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 }
1857
Ihab Awadf9e92732013-12-05 18:02:52 -08001858 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1860 }
1861
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001862 private static void logv(String msg) {
1863 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1864 }
1865
Ihab Awadf9e92732013-12-05 18:02:52 -08001866 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001867 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1868 }
1869
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001870 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001871 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001872 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001873 }
1874
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001876 public int getActivePhoneTypeForSlot(int slotIndex) {
1877 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001878 if (phone == null) {
1879 return PhoneConstants.PHONE_TYPE_NONE;
1880 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001881 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001882 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001883 }
1884
1885 /**
1886 * Returns the CDMA ERI icon index to display
1887 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001888 @Override
1889 public int getCdmaEriIconIndex(String callingPackage) {
1890 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001891 }
1892
Sanket Padawe356d7632015-06-22 14:03:32 -07001893 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001894 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1896 mApp, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001897 return -1;
1898 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001899 final Phone phone = getPhone(subId);
1900 if (phone != null) {
1901 return phone.getCdmaEriIconIndex();
1902 } else {
1903 return -1;
1904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
1907 /**
1908 * Returns the CDMA ERI icon mode,
1909 * 0 - ON
1910 * 1 - FLASHING
1911 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001912 @Override
1913 public int getCdmaEriIconMode(String callingPackage) {
1914 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001915 }
1916
Sanket Padawe356d7632015-06-22 14:03:32 -07001917 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001918 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001919 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1920 mApp, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001921 return -1;
1922 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001923 final Phone phone = getPhone(subId);
1924 if (phone != null) {
1925 return phone.getCdmaEriIconMode();
1926 } else {
1927 return -1;
1928 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 }
1930
1931 /**
1932 * Returns the CDMA ERI text,
1933 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001934 @Override
1935 public String getCdmaEriText(String callingPackage) {
1936 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001937 }
1938
Sanket Padawe356d7632015-06-22 14:03:32 -07001939 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001940 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001941 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1942 mApp, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001943 return null;
1944 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001945 final Phone phone = getPhone(subId);
1946 if (phone != null) {
1947 return phone.getCdmaEriText();
1948 } else {
1949 return null;
1950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951 }
1952
1953 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001954 * Returns the CDMA MDN.
1955 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001956 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001957 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1959 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07001960 final Phone phone = getPhone(subId);
1961 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1962 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001963 } else {
1964 return null;
1965 }
1966 }
1967
1968 /**
1969 * Returns the CDMA MIN.
1970 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001971 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001972 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1974 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07001975 final Phone phone = getPhone(subId);
1976 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1977 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001978 } else {
1979 return null;
1980 }
1981 }
1982
1983 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 * Returns true if CDMA provisioning needs to run.
1985 */
1986 public boolean needsOtaServiceProvisioning() {
1987 return mPhone.needsOtaServiceProvisioning();
1988 }
1989
1990 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001991 * Sets the voice mail number of a given subId.
1992 */
1993 @Override
1994 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001995 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001996 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
1997 new Pair<String, String>(alphaTag, number), new Integer(subId));
1998 return success;
1999 }
2000
Ta-wei Yen87c49842016-05-13 21:19:52 -07002001 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002002 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2003 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2004 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2005 if (!TextUtils.equals(callingPackage, systemDialer)) {
2006 throw new SecurityException("caller must be system dialer");
2007 }
2008 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2009 if (phoneAccountHandle == null){
2010 return null;
2011 }
2012 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2013 }
2014
2015 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002016 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002017 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002018 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2019 mApp, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002020 return null;
2021 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002022 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2023 }
2024
2025 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002026 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2027 VisualVoicemailSmsFilterSettings settings) {
2028 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002029 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002030 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2031 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002032 }
2033
2034 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002035 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2036 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002037 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002038 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002039 }
2040
2041 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002042 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2043 String callingPackage, int subId) {
2044 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002045 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002046 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002047 }
2048
2049 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002050 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002051 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002052 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002053 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2054 }
2055
2056 @Override
2057 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2058 String number, int port, String text, PendingIntent sentIntent) {
2059 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002060 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002061 enforceSendSmsPermission();
2062 // Make the calls as the phone process.
2063 final long identity = Binder.clearCallingIdentity();
2064 try {
2065 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2066 if (port == 0) {
2067 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2068 sentIntent, null, false);
2069 } else {
2070 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2071 smsManager.sendDataMessageWithSelfPermissions(number, null,
2072 (short) port, data, sentIntent, null);
2073 }
2074 } finally {
2075 Binder.restoreCallingIdentity(identity);
2076 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002077 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002078 /**
fionaxu0152e512016-11-14 13:36:14 -08002079 * Sets the voice activation state of a given subId.
2080 */
2081 @Override
2082 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2084 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002085 final Phone phone = getPhone(subId);
2086 if (phone != null) {
2087 phone.setVoiceActivationState(activationState);
2088 } else {
2089 loge("setVoiceActivationState fails with invalid subId: " + subId);
2090 }
2091 }
2092
2093 /**
2094 * Sets the data activation state of a given subId.
2095 */
2096 @Override
2097 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2099 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002100 final Phone phone = getPhone(subId);
2101 if (phone != null) {
2102 phone.setDataActivationState(activationState);
2103 } else {
2104 loge("setVoiceActivationState fails with invalid subId: " + subId);
2105 }
2106 }
2107
2108 /**
2109 * Returns the voice activation state of a given subId.
2110 */
2111 @Override
2112 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002113 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002114 final Phone phone = getPhone(subId);
2115 if (phone != null) {
2116 return phone.getVoiceActivationState();
2117 } else {
2118 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2119 }
2120 }
2121
2122 /**
2123 * Returns the data activation state of a given subId.
2124 */
2125 @Override
2126 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002127 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002128 final Phone phone = getPhone(subId);
2129 if (phone != null) {
2130 return phone.getDataActivationState();
2131 } else {
2132 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2133 }
2134 }
2135
2136 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137 * Returns the unread count of voicemails
2138 */
2139 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002140 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002141 }
2142
2143 /**
2144 * Returns the unread count of voicemails for a subId
2145 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002146 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002147 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002148 final Phone phone = getPhone(subId);
2149 if (phone != null) {
2150 return phone.getVoiceMessageCount();
2151 } else {
2152 return 0;
2153 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 }
2155
2156 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002157 * returns true, if the device is in a state where both voice and data
2158 * are supported simultaneously. This can change based on location or network condition.
2159 */
2160 @Override
2161 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2162 final Phone phone = getPhone(subId);
2163 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2164 }
2165
2166 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002167 * Send the dialer code if called from the current default dialer or the caller has
2168 * carrier privilege.
2169 * @param inputCode The dialer code to send
2170 */
2171 @Override
2172 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2173 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2174 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2175 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002176 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2177 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002178 }
2179 mPhone.sendDialerSpecialCode(inputCode);
2180 }
2181
2182 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002183 * Returns the data network type.
2184 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 *
2186 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2187 */
2188 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002189 public int getNetworkType() {
2190 final Phone phone = getPhone(getDefaultSubscription());
2191 if (phone != null) {
2192 return phone.getServiceState().getDataNetworkType();
2193 } else {
2194 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2195 }
Wink Saville36469e72014-06-11 15:17:00 -07002196 }
2197
2198 /**
2199 * Returns the network type for a subId
2200 */
2201 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002202 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002203 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2204 mApp, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002205 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2206 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002207
Sanket Padawe356d7632015-06-22 14:03:32 -07002208 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002209 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002210 return phone.getServiceState().getDataNetworkType();
2211 } else {
2212 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2213 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002214 }
2215
2216 /**
2217 * Returns the data network type
2218 */
2219 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002220 public int getDataNetworkType(String callingPackage) {
2221 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002222 }
2223
2224 /**
2225 * Returns the data network type for a subId
2226 */
2227 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002228 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2230 mApp, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002231 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2232 }
2233
Sanket Padawe356d7632015-06-22 14:03:32 -07002234 final Phone phone = getPhone(subId);
2235 if (phone != null) {
2236 return phone.getServiceState().getDataNetworkType();
2237 } else {
2238 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 }
2241
2242 /**
Wink Saville36469e72014-06-11 15:17:00 -07002243 * Returns the Voice network type for a subId
2244 */
2245 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002246 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002247 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2248 mApp, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002249 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2250 }
2251
Sanket Padawe356d7632015-06-22 14:03:32 -07002252 final Phone phone = getPhone(subId);
2253 if (phone != null) {
2254 return phone.getServiceState().getVoiceNetworkType();
2255 } else {
2256 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 }
2259
2260 /**
2261 * @return true if a ICC card is present
2262 */
2263 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002264 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002265 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2266 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002267 }
2268
2269 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002270 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002271 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002272 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002273 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2274 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002275 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002276 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002277 } else {
2278 return false;
2279 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002280 }
2281
2282 /**
2283 * Return if the current radio is LTE on CDMA. This
2284 * is a tri-state return value as for a period of time
2285 * the mode may be unknown.
2286 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002287 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002289 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002291 @Override
2292 public int getLteOnCdmaMode(String callingPackage) {
2293 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002294 }
2295
Sanket Padawe356d7632015-06-22 14:03:32 -07002296 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002297 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002298 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2299 mApp, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002300 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2301 }
2302
Sanket Padawe356d7632015-06-22 14:03:32 -07002303 final Phone phone = getPhone(subId);
2304 if (phone == null) {
2305 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2306 } else {
2307 return phone.getLteOnCdmaMode();
2308 }
Wink Saville36469e72014-06-11 15:17:00 -07002309 }
2310
2311 public void setPhone(Phone phone) {
2312 mPhone = phone;
2313 }
2314
2315 /**
2316 * {@hide}
2317 * Returns Default subId, 0 in the case of single standby.
2318 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002319 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002320 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002321 }
2322
Shishir Agrawala9f32182016-04-12 12:00:16 -07002323 private int getSlotForDefaultSubscription() {
2324 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2325 }
2326
Wink Savilleb564aae2014-10-23 10:18:09 -07002327 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002328 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002330
2331 /**
2332 * @see android.telephony.TelephonyManager.WifiCallingChoices
2333 */
2334 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002335 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2336 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002337 }
2338
2339 /**
2340 * @see android.telephony.TelephonyManager.WifiCallingChoices
2341 */
2342 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002343 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2344 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2345 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002346 }
2347
Sailesh Nepald1e68152013-12-12 19:08:02 -08002348 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002349 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002350 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002351 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002352
Shishir Agrawal566b7612013-10-28 14:41:00 -07002353 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002354 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2355 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2357 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002358
Derek Tan740e1672017-06-27 14:56:27 -07002359 if (TextUtils.equals(ISDR_AID, aid)) {
2360 // Only allows LPA to open logical channel to ISD-R.
2361 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2362 ComponentInfo bestComponent =
2363 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2364 if (bestComponent == null
2365 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2366 loge("The calling package is not allowed to access ISD-R.");
2367 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2368 }
2369 }
2370
2371 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002372 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002373 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002374 if (DBG) log("iccOpenLogicalChannel: " + response);
2375 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002376 }
2377
2378 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002379 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2381 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002382
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002383 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002384 if (channel < 0) {
2385 return false;
2386 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002387 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002388 if (DBG) log("iccCloseLogicalChannel: " + success);
2389 return success;
2390 }
2391
2392 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002393 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002394 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2396 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002397
2398 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002399 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2400 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002401 " data=" + data);
2402 }
2403
2404 if (channel < 0) {
2405 return "";
2406 }
2407
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002408 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002409 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002410 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2411
Shishir Agrawal566b7612013-10-28 14:41:00 -07002412 // Append the returned status code to the end of the response payload.
2413 String s = Integer.toHexString(
2414 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002415 if (response.payload != null) {
2416 s = IccUtils.bytesToHexString(response.payload) + s;
2417 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002418 return s;
2419 }
Jake Hambye994d462014-02-03 13:10:13 -08002420
Evan Charltonc66da362014-05-16 14:06:40 -07002421 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002422 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2423 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2425 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002426
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002427 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2428 && TextUtils.equals(ISDR_AID, data)) {
2429 // Only allows LPA to select ISD-R.
2430 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2431 ComponentInfo bestComponent =
2432 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2433 if (bestComponent == null
2434 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2435 loge("The calling package is not allowed to select ISD-R.");
2436 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2437 }
2438 }
2439
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002440 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002441 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2442 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002443 }
2444
2445 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002446 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002447 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2448
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002449 // Append the returned status code to the end of the response payload.
2450 String s = Integer.toHexString(
2451 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002452 if (response.payload != null) {
2453 s = IccUtils.bytesToHexString(response.payload) + s;
2454 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002455 return s;
2456 }
2457
2458 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002459 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002460 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2462 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002463
2464 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002465 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002466 p1 + " " + p2 + " " + p3 + ":" + filePath);
2467 }
2468
2469 IccIoResult response =
2470 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002471 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2472 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002473
2474 if (DBG) {
2475 log("Exchange SIM_IO [R]" + response);
2476 }
2477
2478 byte[] result = null;
2479 int length = 2;
2480 if (response.payload != null) {
2481 length = 2 + response.payload.length;
2482 result = new byte[length];
2483 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2484 } else {
2485 result = new byte[length];
2486 }
2487
2488 result[length - 1] = (byte) response.sw2;
2489 result[length - 2] = (byte) response.sw1;
2490 return result;
2491 }
2492
Nathan Haroldb3014052017-01-25 15:57:32 -08002493 /**
2494 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2495 * on a particular subscription
2496 */
2497 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002498 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2499 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002500 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2501 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2502 return null;
2503 }
2504 Object response = sendRequest(
2505 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2506 if (response instanceof String[]) {
2507 return (String[]) response;
2508 }
2509 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2510 return null;
2511 }
2512
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002513 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002514 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2516 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002517
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002518 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002519 if (response.payload == null) {
2520 return "";
2521 }
2522
2523 // Append the returned status code to the end of the response payload.
2524 String s = Integer.toHexString(
2525 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2526 s = IccUtils.bytesToHexString(response.payload) + s;
2527 return s;
2528 }
2529
Jake Hambye994d462014-02-03 13:10:13 -08002530 /**
2531 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2532 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2533 *
2534 * @param itemID the ID of the item to read
2535 * @return the NV item as a String, or null on error.
2536 */
2537 @Override
2538 public String nvReadItem(int itemID) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2540 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002541 if (DBG) log("nvReadItem: item " + itemID);
2542 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2543 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2544 return value;
2545 }
2546
2547 /**
2548 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2549 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2550 *
2551 * @param itemID the ID of the item to read
2552 * @param itemValue the value to write, as a String
2553 * @return true on success; false on any failure
2554 */
2555 @Override
2556 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2558 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002559 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2560 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2561 new Pair<Integer, String>(itemID, itemValue));
2562 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2563 return success;
2564 }
2565
2566 /**
2567 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2568 * Used for device configuration by some CDMA operators.
2569 *
2570 * @param preferredRoamingList byte array containing the new PRL
2571 * @return true on success; false on any failure
2572 */
2573 @Override
2574 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2576 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002577 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2578 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2579 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2580 return success;
2581 }
2582
2583 /**
2584 * Perform the specified type of NV config reset.
2585 * Used for device configuration by some CDMA operators.
2586 *
2587 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2588 * @return true on success; false on any failure
2589 */
2590 @Override
2591 public boolean nvResetConfig(int resetType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2593 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002594 if (DBG) log("nvResetConfig: type " + resetType);
2595 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2596 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2597 return success;
2598 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002599
2600 /**
Wink Saville36469e72014-06-11 15:17:00 -07002601 * {@hide}
2602 * Returns Default sim, 0 in the case of single standby.
2603 */
2604 public int getDefaultSim() {
2605 //TODO Need to get it from Telephony Devcontroller
2606 return 0;
2607 }
2608
Svet Ganovb320e182015-04-16 12:30:10 -07002609 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2611 mApp, callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002612 return new String[0];
2613 }
2614
2615
ram87fca6f2014-07-18 18:58:44 +05302616 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002617 }
2618
Brad Ebinger51f743a2017-01-23 13:50:20 -08002619 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002620 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2621 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002622 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002623 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002624 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002625 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002626 }
2627
2628 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002629 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2630 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002631 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002632 public void disableIms(int slotId) {
2633 enforceModifyPermission();
2634 PhoneFactory.getImsResolver().disableIms(slotId);
2635 }
2636
2637 /**
2638 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2639 * feature or {@link null} if the service is not available. If the feature is available, the
2640 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2641 */
2642 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002643 IImsServiceFeatureCallback callback) {
2644 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002645 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002646 }
2647
2648 /**
2649 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2650 * feature during emergency calling or {@link null} if the service is not available. If the
2651 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2652 * listener for feature updates.
2653 */
2654 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2655 enforceModifyPermission();
2656 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002657 }
2658
Brad Ebinger5f64b052017-12-14 14:26:15 -08002659 /**
2660 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2661 * specified.
2662 */
2663 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2664 enforceModifyPermission();
2665 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2666 }
2667
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002668 /**
2669 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2670 * specified.
2671 */
2672 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2673 enforceModifyPermission();
2674 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2675 }
2676
Wink Saville36469e72014-06-11 15:17:00 -07002677 public void setImsRegistrationState(boolean registered) {
2678 enforceModifyPermission();
2679 mPhone.setImsRegistrationState(registered);
2680 }
2681
2682 /**
Stuart Scott54788802015-03-30 13:18:01 -07002683 * Set the network selection mode to automatic.
2684 *
2685 */
2686 @Override
2687 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2689 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002690 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2691 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2692 }
2693
2694 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002695 * Set the network selection mode to manual with the selected carrier.
2696 */
2697 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002698 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002699 boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2701 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002702 OperatorInfo operator = new OperatorInfo(
2703 /* operatorAlphaLong */ "",
2704 /* operatorAlphaShort */ "",
2705 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002706 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002707 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2708 persistSelection);
2709 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002710 }
2711
2712 /**
2713 * Scans for available networks.
2714 */
2715 @Override
2716 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002717 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2718 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002719 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2720 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2721 CMD_PERFORM_NETWORK_SCAN, null, subId);
2722 return result;
2723 }
2724
2725 /**
yinxub1bed742017-04-17 11:45:04 -07002726 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002727 *
yinxub1bed742017-04-17 11:45:04 -07002728 * @param subId id of the subscription
2729 * @param request contains the radio access networks with bands/channels to scan
2730 * @param messenger callback messenger for scan results or errors
2731 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002732 * @return the id of the requested scan which can be used to stop the scan.
2733 */
2734 @Override
2735 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2736 IBinder binder) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2738 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002739 return mNetworkScanRequestTracker.startNetworkScan(
2740 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002741 }
2742
2743 /**
2744 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002745 *
2746 * @param subId id of the subscription
2747 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002748 */
2749 @Override
2750 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2752 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002753 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002754 }
2755
2756 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002757 * Get the calculated preferred network type.
2758 * Used for debugging incorrect network type.
2759 *
2760 * @return the preferred network type, defined in RILConstants.java.
2761 */
2762 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002763 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2765 mApp, callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002766 return RILConstants.PREFERRED_NETWORK_MODE;
2767 }
2768
Amit Mahajan43330e02014-11-18 11:54:45 -08002769 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002770 }
2771
2772 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002773 * Get the preferred network type.
2774 * Used for device configuration by some CDMA operators.
2775 *
2776 * @return the preferred network type, defined in RILConstants.java.
2777 */
2778 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002779 public int getPreferredNetworkType(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2781 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002782 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002783 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002784 int networkType = (result != null ? result[0] : -1);
2785 if (DBG) log("getPreferredNetworkType: " + networkType);
2786 return networkType;
2787 }
2788
2789 /**
2790 * Set the preferred network type.
2791 * Used for device configuration by some CDMA operators.
2792 *
2793 * @param networkType the preferred network type, defined in RILConstants.java.
2794 * @return true on success; false on any failure.
2795 */
2796 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002797 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2799 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002800 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2801 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002802 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002803 if (success) {
2804 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002805 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002806 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002807 return success;
2808 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002809
2810 /**
Junda Liu475951f2014-11-07 16:45:03 -08002811 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2812 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2813 * tethering.
2814 *
2815 * @return 0: Not required. 1: required. 2: Not set.
2816 * @hide
2817 */
2818 @Override
2819 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002820 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002821 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2822 Settings.Global.TETHER_DUN_REQUIRED, 2);
2823 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2824 // config_tether_apndata.
2825 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2826 dunRequired = 1;
2827 }
2828 return dunRequired;
2829 }
2830
2831 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002832 * Set mobile data enabled
2833 * Used by the user through settings etc to turn on/off mobile data
2834 *
2835 * @param enable {@code true} turn turn data on, else {@code false}
2836 */
2837 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002838 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002839 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2840 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002841 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002842 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002843 Phone phone = PhoneFactory.getPhone(phoneId);
2844 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002845 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2846 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002847 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002848 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002849 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002850 }
2851
2852 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002853 * Get the user enabled state of Mobile Data.
2854 *
2855 * TODO: remove and use isUserDataEnabled.
2856 * This can't be removed now because some vendor codes
2857 * calls through ITelephony directly while they should
2858 * use TelephonyManager.
2859 *
2860 * @return true on enabled
2861 */
2862 @Override
2863 public boolean getDataEnabled(int subId) {
2864 return isUserDataEnabled(subId);
2865 }
2866
2867 /**
2868 * Get whether mobile data is enabled per user setting.
2869 *
2870 * There are other factors deciding whether mobile data is actually enabled, but they are
2871 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002872 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002873 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002874 *
2875 * @return {@code true} if data is enabled else {@code false}
2876 */
2877 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002878 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002879 try {
2880 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2881 null);
2882 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2884 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002885 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002886 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002887 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002888 Phone phone = PhoneFactory.getPhone(phoneId);
2889 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002890 boolean retVal = phone.isUserDataEnabled();
2891 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002892 return retVal;
2893 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002894 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2895 return false;
2896 }
2897 }
2898
2899 /**
2900 * Get whether mobile data is enabled.
2901 *
2902 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2903 * whether mobile data is actually enabled.
2904 *
2905 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2906 *
2907 * @return {@code true} if data is enabled else {@code false}
2908 */
2909 @Override
2910 public boolean isDataEnabled(int subId) {
2911 try {
2912 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2913 null);
2914 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2916 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08002917 }
2918 int phoneId = mSubscriptionController.getPhoneId(subId);
2919 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2920 Phone phone = PhoneFactory.getPhone(phoneId);
2921 if (phone != null) {
2922 boolean retVal = phone.isDataEnabled();
2923 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2924 return retVal;
2925 } else {
2926 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002927 return false;
2928 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002929 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002930
2931 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002932 public int getCarrierPrivilegeStatus(int subId) {
2933 final Phone phone = getPhone(subId);
2934 if (phone == null) {
2935 loge("getCarrierPrivilegeStatus: Invalid subId");
2936 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2937 }
2938 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002939 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002940 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002941 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2942 }
2943 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002944 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002945 }
Junda Liu29340342014-07-10 15:23:27 -07002946
2947 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08002948 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
2949 final Phone phone = getPhone(subId);
2950 if (phone == null) {
2951 loge("getCarrierPrivilegeStatus: Invalid subId");
2952 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2953 }
2954 UiccProfile profile =
2955 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
2956 if (profile == null) {
2957 loge("getCarrierPrivilegeStatus: No UICC");
2958 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2959 }
2960 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
2961 }
2962
2963 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002964 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002965 if (TextUtils.isEmpty(pkgName))
2966 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002967 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002968 if (card == null) {
2969 loge("checkCarrierPrivilegesForPackage: No UICC");
2970 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2971 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002972 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2973 }
2974
2975 @Override
2976 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002977 if (TextUtils.isEmpty(pkgName))
2978 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002979 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2980 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2981 UiccCard card = UiccController.getInstance().getUiccCard(i);
2982 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002983 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002984 continue;
2985 }
2986
2987 result = card.getCarrierPrivilegeStatus(
2988 mPhone.getContext().getPackageManager(), pkgName);
2989 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2990 break;
2991 }
2992 }
2993
2994 return result;
Junda Liu29340342014-07-10 15:23:27 -07002995 }
Derek Tan89e89d42014-07-08 17:00:10 -07002996
2997 @Override
Junda Liue64de782015-04-16 17:19:16 -07002998 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2999 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3000 loge("phoneId " + phoneId + " is not valid.");
3001 return null;
3002 }
3003 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003004 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003005 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003006 return null ;
3007 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003008 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003009 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003010 }
3011
Amith Yamasani6e118872016-02-19 12:53:51 -08003012 @Override
3013 public List<String> getPackagesWithCarrierPrivileges() {
3014 PackageManager pm = mPhone.getContext().getPackageManager();
3015 List<String> privilegedPackages = new ArrayList<>();
3016 List<PackageInfo> packages = null;
3017 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3018 UiccCard card = UiccController.getInstance().getUiccCard(i);
3019 if (card == null) {
3020 // No UICC in that slot.
3021 continue;
3022 }
3023 if (card.hasCarrierPrivilegeRules()) {
3024 if (packages == null) {
3025 // Only check packages in user 0 for now
3026 packages = pm.getInstalledPackagesAsUser(
3027 PackageManager.MATCH_DISABLED_COMPONENTS
3028 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3029 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3030 }
3031 for (int p = packages.size() - 1; p >= 0; p--) {
3032 PackageInfo pkgInfo = packages.get(p);
3033 if (pkgInfo != null && pkgInfo.packageName != null
3034 && card.getCarrierPrivilegeStatus(pkgInfo)
3035 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3036 privilegedPackages.add(pkgInfo.packageName);
3037 }
3038 }
3039 }
3040 }
3041 return privilegedPackages;
3042 }
3043
Wink Savilleb564aae2014-10-23 10:18:09 -07003044 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003045 final Phone phone = getPhone(subId);
3046 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003047 if (card == null) {
3048 loge("getIccId: No UICC");
3049 return null;
3050 }
3051 String iccId = card.getIccId();
3052 if (TextUtils.isEmpty(iccId)) {
3053 loge("getIccId: ICC ID is null or empty.");
3054 return null;
3055 }
3056 return iccId;
3057 }
3058
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003059 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003060 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3061 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003062 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3063 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003064
Jeff Sharkey85190e62014-12-05 09:40:12 -08003065 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003066 final Phone phone = getPhone(subId);
3067 if (phone == null) {
3068 return false;
3069 }
3070 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003071
3072 if (DBG_MERGE) {
3073 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3074 + subscriberId + " to " + number);
3075 }
3076
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003077 if (TextUtils.isEmpty(iccId)) {
3078 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003079 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003080
Jeff Sharkey85190e62014-12-05 09:40:12 -08003081 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3082
3083 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003084 if (alphaTag == null) {
3085 editor.remove(alphaTagPrefKey);
3086 } else {
3087 editor.putString(alphaTagPrefKey, alphaTag);
3088 }
3089
Jeff Sharkey85190e62014-12-05 09:40:12 -08003090 // Record both the line number and IMSI for this ICCID, since we need to
3091 // track all merged IMSIs based on line number
3092 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3093 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003094 if (number == null) {
3095 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003096 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003097 } else {
3098 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003099 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003100 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003101
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003102 editor.commit();
3103 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003104 }
3105
3106 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003107 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003108 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08003109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
3110 mApp, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003111 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003112 return null;
3113 }
Derek Tan97ebb422014-09-05 16:55:38 -07003114
3115 String iccId = getIccId(subId);
3116 if (iccId != null) {
3117 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003118 if (DBG_MERGE) {
3119 log("getLine1NumberForDisplay returning " +
3120 mTelephonySharedPreferences.getString(numberPrefKey, null));
3121 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003122 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003123 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003124 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003125 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003126 }
3127
3128 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003129 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003130 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3131 mApp, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003132 return null;
3133 }
Derek Tan97ebb422014-09-05 16:55:38 -07003134
3135 String iccId = getIccId(subId);
3136 if (iccId != null) {
3137 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003138 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003139 }
Derek Tan97ebb422014-09-05 16:55:38 -07003140 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003141 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003142
3143 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003144 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003145 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3146 mApp, callingPackage, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003147 return null;
3148 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003149 final Context context = mPhone.getContext();
3150 final TelephonyManager tele = TelephonyManager.from(context);
3151 final SubscriptionManager sub = SubscriptionManager.from(context);
3152
3153 // Figure out what subscribers are currently active
3154 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003155 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3156 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3157 final long identity = Binder.clearCallingIdentity();
3158 try {
3159 final int[] subIds = sub.getActiveSubscriptionIdList();
3160 for (int subId : subIds) {
3161 activeSubscriberIds.add(tele.getSubscriberId(subId));
3162 }
3163 } finally {
3164 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003165 }
3166
3167 // First pass, find a number override for an active subscriber
3168 String mergeNumber = null;
3169 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3170 for (String key : prefs.keySet()) {
3171 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3172 final String subscriberId = (String) prefs.get(key);
3173 if (activeSubscriberIds.contains(subscriberId)) {
3174 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3175 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3176 mergeNumber = (String) prefs.get(numberKey);
3177 if (DBG_MERGE) {
3178 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3179 + " for active subscriber " + subscriberId);
3180 }
3181 if (!TextUtils.isEmpty(mergeNumber)) {
3182 break;
3183 }
3184 }
3185 }
3186 }
3187
3188 // Shortcut when no active merged subscribers
3189 if (TextUtils.isEmpty(mergeNumber)) {
3190 return null;
3191 }
3192
3193 // Second pass, find all subscribers under that line override
3194 final ArraySet<String> result = new ArraySet<>();
3195 for (String key : prefs.keySet()) {
3196 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3197 final String number = (String) prefs.get(key);
3198 if (mergeNumber.equals(number)) {
3199 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3200 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3201 final String subscriberId = (String) prefs.get(subscriberKey);
3202 if (!TextUtils.isEmpty(subscriberId)) {
3203 result.add(subscriberId);
3204 }
3205 }
3206 }
3207 }
3208
3209 final String[] resultArray = result.toArray(new String[result.size()]);
3210 Arrays.sort(resultArray);
3211 if (DBG_MERGE) {
3212 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3213 }
3214 return resultArray;
3215 }
3216
3217 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003218 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003219 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3220 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003221 final Phone phone = getPhone(subId);
3222 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003223 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003224
3225 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003226 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003227 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3228 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003229 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003230 final Phone phone = getPhone(subId);
3231 if (phone == null) {
3232 return false;
3233 }
3234 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003235 cdmaNonRoamingList);
3236 }
3237
3238 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003239 public void setRadioCapability(RadioAccessFamily[] rafs) {
3240 try {
3241 ProxyController.getInstance().setRadioCapability(rafs);
3242 } catch (RuntimeException e) {
3243 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3244 }
3245 }
3246
3247 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003248 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003249 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3250 mApp, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003251 return RadioAccessFamily.RAF_UNKNOWN;
3252 }
3253
Wink Saville5d475dd2014-10-17 15:00:58 -07003254 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3255 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003256
3257 @Override
3258 public void enableVideoCalling(boolean enable) {
3259 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003260 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003261 }
3262
3263 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003264 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3266 mApp, callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003267 return false;
3268 }
3269
Andrew Lee77527ac2014-10-21 16:57:39 -07003270 // Check the user preference and the system-level IMS setting. Even if the user has
3271 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3272 // In the long run, we may instead need to check if there exists a connection service
3273 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003274 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3275 return imsManager.isVtEnabledByPlatform()
3276 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3277 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003278 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003279
Andrew Leea1239f22015-03-02 17:44:07 -08003280 @Override
3281 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003282 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003283 }
3284
3285 @Override
3286 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003287 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003288 }
3289
Andrew Lee9431b832015-03-09 18:46:45 -07003290 @Override
3291 public boolean isTtyModeSupported() {
3292 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3293 TelephonyManager telephonyManager =
3294 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003295 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003296 }
3297
3298 @Override
3299 public boolean isHearingAidCompatibilitySupported() {
3300 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3301 }
3302
Hall Liu98187582018-01-22 19:15:32 -08003303 public boolean isRttSupported() {
3304 boolean isCarrierSupported =
3305 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3306 boolean isDeviceSupported =
3307 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3308 return isCarrierSupported && isDeviceSupported;
3309 }
3310
Sanket Padawe7310cc72015-01-14 09:53:20 -08003311 /**
3312 * Returns the unique device ID of phone, for example, the IMEI for
3313 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3314 *
3315 * <p>Requires Permission:
3316 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3317 */
3318 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003319 public String getDeviceId(String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3321 mApp, callingPackage, "getDeviceId")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003322 return null;
3323 }
3324
Sanket Padawe7310cc72015-01-14 09:53:20 -08003325 final Phone phone = PhoneFactory.getPhone(0);
3326 if (phone != null) {
3327 return phone.getDeviceId();
3328 } else {
3329 return null;
3330 }
3331 }
3332
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003333 /*
3334 * {@hide}
3335 * Returns the IMS Registration Status
3336 */
Santos Cordon7a1885b2015-02-03 11:15:19 -08003337 @Override
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003338 public boolean isImsRegistered() {
3339 return mPhone.isImsRegistered();
3340 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08003341
Ping Sunc67b7c22016-03-02 19:16:45 +08003342 /**
3343 * {@hide}
3344 * Returns the IMS Registration Status on a particular subid
3345 *
3346 * @param subId
3347 */
3348 public boolean isImsRegisteredForSubscriber(int subId) {
3349 Phone phone = getPhone(subId);
3350 if (phone != null) {
3351 return phone.isImsRegistered();
3352 } else {
3353 return false;
3354 }
3355 }
3356
Santos Cordon7a1885b2015-02-03 11:15:19 -08003357 @Override
3358 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3359 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3360 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003361
Nathan Haroldc55097a2015-03-11 18:14:50 -07003362 /*
3363 * {@hide}
3364 * Returns the IMS Registration Status
3365 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003366 public boolean isWifiCallingAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003367 return mPhone.isWifiCallingEnabled();
3368 }
3369
3370 /*
3371 * {@hide}
3372 * Returns the IMS Registration Status
3373 */
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003374 public boolean isVolteAvailable() {
Nathan Haroldc55097a2015-03-11 18:14:50 -07003375 return mPhone.isVolteEnabled();
3376 }
Svet Ganovb320e182015-04-16 12:30:10 -07003377
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003378 /*
3379 * {@hide} Returns the IMS Registration Status
3380 */
3381 public boolean isVideoTelephonyAvailable() {
3382 return mPhone.isVideoEnabled();
3383 }
3384
Stuart Scott8eef64f2015-04-08 15:13:54 -07003385 @Override
3386 public void factoryReset(int subId) {
3387 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003388 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3389 return;
3390 }
3391
Svet Ganovcc087f82015-05-12 20:35:54 -07003392 final long identity = Binder.clearCallingIdentity();
3393 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003394 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3395 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003396 // Enable data
Malcolm Chen964682d2017-11-28 16:20:07 -08003397 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003398 // Set network selection mode to automatic
3399 setNetworkSelectionModeAutomatic(subId);
3400 // Set preferred mobile network type to the best available
3401 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3402 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003403 mPhone.setDataRoamingEnabled(false);
pkanwar79ec0542017-07-31 14:10:01 -07003404 // Remove IMSI encryption keys from Carrier DB.
3405 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003406 }
3407 } finally {
3408 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003409 }
3410 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003411
3412 @Override
3413 public String getLocaleFromDefaultSim() {
3414 // We query all subscriptions instead of just the active ones, because
3415 // this might be called early on in the provisioning flow when the
3416 // subscriptions potentially aren't active yet.
3417 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3418 if (slist == null || slist.isEmpty()) {
3419 return null;
3420 }
3421
3422 // This function may be called very early, say, from the setup wizard, at
3423 // which point we won't have a default subscription set. If that's the case
3424 // we just choose the first, which will be valid in "most cases".
3425 final int defaultSubId = getDefaultSubscription();
3426 SubscriptionInfo info = null;
3427 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3428 info = slist.get(0);
3429 } else {
3430 for (SubscriptionInfo item : slist) {
3431 if (item.getSubscriptionId() == defaultSubId) {
3432 info = item;
3433 break;
3434 }
3435 }
3436
3437 if (info == null) {
3438 return null;
3439 }
3440 }
3441
3442 // Try and fetch the locale from the carrier properties or from the SIM language
3443 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003444 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003445 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003446 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003447 if (defaultPhone != null) {
3448 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3449 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003450 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003451 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3452 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003453 } else {
3454 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003455 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003456 }
3457 }
3458
Narayan Kamath011676f2015-07-29 12:04:08 +01003459 // The SIM language preferences only store a language (e.g. fr = French), not an
3460 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3461 // the SIM and carrier preferences does not include a country we add the country
3462 // determined from the SIM MCC to provide an exact locale.
3463 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003464 if (mccLocale != null) {
3465 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3466 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003467 }
3468
Tony Hill183b2de2015-06-24 14:53:58 +01003469 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003470 return null;
3471 }
3472
3473 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3474 final long identity = Binder.clearCallingIdentity();
3475 try {
3476 return mSubscriptionController.getAllSubInfoList(
3477 mPhone.getContext().getOpPackageName());
3478 } finally {
3479 Binder.restoreCallingIdentity(identity);
3480 }
3481 }
3482
3483 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3484 final long identity = Binder.clearCallingIdentity();
3485 try {
3486 return mSubscriptionController.getActiveSubscriptionInfoList(
3487 mPhone.getContext().getOpPackageName());
3488 } finally {
3489 Binder.restoreCallingIdentity(identity);
3490 }
3491 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003492
Chenjie Yu1ba97252018-01-11 18:16:20 -08003493 private final ModemActivityInfo mLastModemActivityInfo =
3494 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3495
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003496 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003497 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3498 * representing the state of the modem.
3499 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003500 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3501 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003502 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003503 */
3504 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003505 public void requestModemActivityInfo(ResultReceiver result) {
3506 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003507 ModemActivityInfo ret = null;
3508 synchronized (mLastModemActivityInfo) {
3509 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3510 null);
3511 if (info != null) {
3512 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3513 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3514 mergedTxTimeMs[i] =
3515 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3516 }
3517 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3518 mLastModemActivityInfo.setSleepTimeMillis(
3519 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3520 mLastModemActivityInfo.setIdleTimeMillis(
3521 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3522 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3523 mLastModemActivityInfo.setRxTimeMillis(
3524 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3525 mLastModemActivityInfo.setEnergyUsed(
3526 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3527 }
3528 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3529 mLastModemActivityInfo.getSleepTimeMillis(),
3530 mLastModemActivityInfo.getIdleTimeMillis(),
3531 mLastModemActivityInfo.getTxTimeMillis(),
3532 mLastModemActivityInfo.getRxTimeMillis(),
3533 mLastModemActivityInfo.getEnergyUsed());
3534 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003535 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003536 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003537 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003538 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003539
3540 /**
3541 * {@hide}
3542 * Returns the service state information on specified subscription.
3543 */
3544 @Override
3545 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3546
Jeff Davidson7e17e312018-02-13 18:17:36 -08003547 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3548 mApp, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003549 return null;
3550 }
3551
3552 final Phone phone = getPhone(subId);
3553 if (phone == null) {
3554 return null;
3555 }
3556
3557 return phone.getServiceState();
3558 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003559
3560 /**
3561 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3562 *
3563 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3564 * voicemail ringtone.
3565 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3566 * PhoneAccount.
3567 */
3568 @Override
3569 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003570 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003571 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003572 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003573 }
3574
fionaxu7ed723d2017-05-30 18:58:54 -07003575 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003576 }
3577
3578 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003579 * Sets the per-account voicemail ringtone.
3580 *
3581 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3582 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3583 *
3584 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3585 * voicemail ringtone.
3586 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3587 * PhoneAccount.
3588 */
3589 @Override
3590 public void setVoicemailRingtoneUri(String callingPackage,
3591 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3592 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3593 if (!TextUtils.equals(callingPackage,
3594 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3596 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3597 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003598 }
3599 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3600 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003601 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003602 }
fionaxu7ed723d2017-05-30 18:58:54 -07003603 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003604 }
3605
3606 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003607 * Returns whether vibration is set for voicemail notification in Phone settings.
3608 *
3609 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3610 * voicemail vibration setting.
3611 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3612 */
3613 @Override
3614 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003615 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003616 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003617 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003618 }
3619
fionaxu7ed723d2017-05-30 18:58:54 -07003620 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003621 }
3622
Youhan Wange64578a2016-05-02 15:32:42 -07003623 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003624 * Sets the per-account voicemail vibration.
3625 *
3626 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3627 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3628 *
3629 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3630 * voicemail vibration setting.
3631 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3632 * specific PhoneAccount.
3633 */
3634 @Override
3635 public void setVoicemailVibrationEnabled(String callingPackage,
3636 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3637 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3638 if (!TextUtils.equals(callingPackage,
3639 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3641 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3642 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003643 }
3644
3645 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3646 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003647 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003648 }
fionaxu7ed723d2017-05-30 18:58:54 -07003649 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003650 }
3651
3652 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003653 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3654 *
3655 * @throws SecurityException if the caller does not have the required permission
3656 */
3657 private void enforceReadPrivilegedPermission() {
3658 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3659 null);
3660 }
3661
3662 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003663 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3664 * permission.
3665 *
3666 * @throws SecurityException if the caller does not have the required permission
3667 */
3668 private void enforceSendSmsPermission() {
3669 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3670 }
3671
3672 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003673 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003674 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003675 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003676 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003677 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003678 ComponentName componentName =
3679 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3680 if(componentName == null) {
3681 throw new SecurityException("Caller not current active visual voicemail package[null]");
3682 }
3683 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003684 if (!callingPackage.equals(vvmPackage)) {
3685 throw new SecurityException("Caller not current active visual voicemail package[" +
3686 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003687 }
3688 }
3689
3690 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003691 * Return the application ID for the app type.
3692 *
3693 * @param subId the subscription ID that this request applies to.
3694 * @param appType the uicc app type.
3695 * @return Application ID for specificied app type, or null if no uicc.
3696 */
3697 @Override
3698 public String getAidForAppType(int subId, int appType) {
3699 enforceReadPrivilegedPermission();
3700 Phone phone = getPhone(subId);
3701 if (phone == null) {
3702 return null;
3703 }
3704 String aid = null;
3705 try {
3706 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3707 .getApplicationByType(appType).getAid();
3708 } catch (Exception e) {
3709 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3710 }
3711 return aid;
3712 }
3713
Youhan Wang4001d252016-05-11 10:29:41 -07003714 /**
3715 * Return the Electronic Serial Number.
3716 *
3717 * @param subId the subscription ID that this request applies to.
3718 * @return ESN or null if error.
3719 */
3720 @Override
3721 public String getEsn(int subId) {
3722 enforceReadPrivilegedPermission();
3723 Phone phone = getPhone(subId);
3724 if (phone == null) {
3725 return null;
3726 }
3727 String esn = null;
3728 try {
3729 esn = phone.getEsn();
3730 } catch (Exception e) {
3731 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3732 }
3733 return esn;
3734 }
3735
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003736 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003737 * Return the Preferred Roaming List Version.
3738 *
3739 * @param subId the subscription ID that this request applies to.
3740 * @return PRLVersion or null if error.
3741 */
3742 @Override
3743 public String getCdmaPrlVersion(int subId) {
3744 enforceReadPrivilegedPermission();
3745 Phone phone = getPhone(subId);
3746 if (phone == null) {
3747 return null;
3748 }
3749 String cdmaPrlVersion = null;
3750 try {
3751 cdmaPrlVersion = phone.getCdmaPrlVersion();
3752 } catch (Exception e) {
3753 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3754 }
3755 return cdmaPrlVersion;
3756 }
3757
3758 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003759 * Get snapshot of Telephony histograms
3760 * @return List of Telephony histograms
3761 * @hide
3762 */
3763 @Override
3764 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3766 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003767 return RIL.getTelephonyRILTimingHistograms();
3768 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003769
3770 /**
3771 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003772 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003773 * Require system privileges. In the future we may add this to carrier APIs.
3774 *
3775 * @return The number of carriers set successfully, should match length of carriers
3776 */
3777 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003778 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003779 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003780
Meng Wang9b7c4e92017-02-17 11:41:27 -08003781 if (carriers == null) {
3782 throw new NullPointerException("carriers cannot be null");
3783 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003784
3785 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003786 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3787 return retVal[0];
3788 }
3789
3790 /**
3791 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003792 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003793 * Require system privileges. In the future we may add this to carrier APIs.
3794 *
3795 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3796 * means all carriers are allowed.
3797 */
3798 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003799 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003800 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003801 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003802 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3803 }
3804
fionaxu59545b42016-05-25 15:53:37 -07003805 /**
3806 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3807 * @param subId the subscription ID that this action applies to.
3808 * @param enabled control enable or disable metered apns.
3809 * {@hide}
3810 */
3811 @Override
3812 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3813 enforceModifyPermission();
3814 final Phone phone = getPhone(subId);
3815 if (phone == null) {
3816 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3817 return;
3818 }
3819 try {
3820 phone.carrierActionSetMeteredApnsEnabled(enabled);
3821 } catch (Exception e) {
3822 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3823 }
3824 }
3825
3826 /**
3827 * Action set from carrier signalling broadcast receivers to enable/disable radio
3828 * @param subId the subscription ID that this action applies to.
3829 * @param enabled control enable or disable radio.
3830 * {@hide}
3831 */
3832 @Override
3833 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3834 enforceModifyPermission();
3835 final Phone phone = getPhone(subId);
3836 if (phone == null) {
3837 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3838 return;
3839 }
3840 try {
3841 phone.carrierActionSetRadioEnabled(enabled);
3842 } catch (Exception e) {
3843 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3844 }
3845 }
3846
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003847 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003848 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3849 * network status based on which carrier apps could apply actions accordingly,
3850 * enable/disable default url handler for example.
3851 *
3852 * @param subId the subscription ID that this action applies to.
3853 * @param report control start/stop reporting the default network status.
3854 * {@hide}
3855 */
3856 @Override
3857 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3858 enforceModifyPermission();
3859 final Phone phone = getPhone(subId);
3860 if (phone == null) {
3861 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3862 return;
3863 }
3864 try {
3865 phone.carrierActionReportDefaultNetworkStatus(report);
3866 } catch (Exception e) {
3867 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3868 }
3869 }
3870
3871 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003872 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3873 * bug report is being generated.
3874 */
3875 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003876 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003877 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3878 != PackageManager.PERMISSION_GRANTED) {
3879 writer.println("Permission Denial: can't dump Phone from pid="
3880 + Binder.getCallingPid()
3881 + ", uid=" + Binder.getCallingUid()
3882 + "without permission "
3883 + android.Manifest.permission.DUMP);
3884 return;
3885 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003886 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003887 }
Jack Yueb89b242016-06-22 13:27:47 -07003888
3889 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003890 * Get aggregated video call data usage since boot.
3891 *
3892 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3893 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003894 * {@hide}
3895 */
3896 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003897 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003898 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3899 null);
3900
Jack Yu84291ec2017-05-26 16:07:50 -07003901 // NetworkStatsService keeps tracking the active network interface and identity. It
3902 // records the delta with the corresponding network identity. We just return the total video
3903 // call data usage snapshot since boot.
3904 Phone phone = getPhone(subId);
3905 if (phone != null) {
3906 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003907 }
Jack Yu84291ec2017-05-26 16:07:50 -07003908 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003909 }
Jack Yu75ab2952016-07-08 14:29:33 -07003910
3911 /**
3912 * Policy control of data connection. Usually used when data limit is passed.
3913 * @param enabled True if enabling the data, otherwise disabling.
3914 * @param subId Subscription index
3915 * {@hide}
3916 */
3917 @Override
3918 public void setPolicyDataEnabled(boolean enabled, int subId) {
3919 enforceModifyPermission();
3920 Phone phone = getPhone(subId);
3921 if (phone != null) {
3922 phone.setPolicyDataEnabled(enabled);
3923 }
3924 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003925
3926 /**
3927 * Get Client request stats
3928 * @return List of Client Request Stats
3929 * @hide
3930 */
3931 @Override
3932 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003933 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3934 mApp, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003935 return null;
3936 }
3937
3938 Phone phone = getPhone(subId);
3939 if (phone != null) {
3940 return phone.getClientRequestStats();
3941 }
3942
3943 return null;
3944 }
3945
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003946 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003947 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003948 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003949 }
Jack Yueb4124c2017-02-16 15:32:43 -08003950
3951 /**
Grace Chen70990072017-03-24 17:21:30 -07003952 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003953 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003954 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003955 * @param state State of SIM (power down, power up, pass through)
3956 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3957 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3958 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003959 *
3960 **/
3961 @Override
Grace Chen70990072017-03-24 17:21:30 -07003962 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003963 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003964 Phone phone = PhoneFactory.getPhone(slotIndex);
3965
Jack Yueb4124c2017-02-16 15:32:43 -08003966 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003967 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003968 }
3969 }
Shuo Qiandd210312017-04-12 22:11:33 +00003970
Tyler Gunn65d45c22017-06-05 11:22:26 -07003971 private boolean isUssdApiAllowed(int subId) {
3972 CarrierConfigManager configManager =
3973 (CarrierConfigManager) mPhone.getContext().getSystemService(
3974 Context.CARRIER_CONFIG_SERVICE);
3975 if (configManager == null) {
3976 return false;
3977 }
3978 PersistableBundle pb = configManager.getConfigForSubId(subId);
3979 if (pb == null) {
3980 return false;
3981 }
3982 return pb.getBoolean(
3983 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3984 }
3985
Shuo Qiandd210312017-04-12 22:11:33 +00003986 /**
3987 * Check if phone is in emergency callback mode
3988 * @return true if phone is in emergency callback mode
3989 * @param subId sub id
3990 */
goneil9c5f4872017-12-05 14:07:56 -08003991 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00003992 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08003993 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00003994 final Phone phone = getPhone(subId);
3995 if (phone != null) {
3996 return phone.isInEcm();
3997 } else {
3998 return false;
3999 }
4000 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004001
4002 /**
4003 * Get the current signal strength information for the given subscription.
4004 * Because this information is not updated when the device is in a low power state
4005 * it should not be relied-upon to be current.
4006 * @param subId Subscription index
4007 * @return the most recent cached signal strength info from the modem
4008 */
4009 @Override
4010 public SignalStrength getSignalStrength(int subId) {
4011 Phone p = getPhone(subId);
4012 if (p == null) {
4013 return null;
4014 }
4015
4016 return p.getSignalStrength();
4017 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004018
4019 @Override
4020 public UiccSlotInfo[] getUiccSlotsInfo() {
4021 enforceReadPrivilegedPermission();
4022
4023 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4024 if (slots == null) return null;
4025 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4026 for (int i = 0; i < slots.length; i++) {
4027 UiccSlot slot = slots[i];
4028
4029 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4030
4031 int cardState = 0;
4032 switch (slot.getCardState()) {
4033 case CARDSTATE_ABSENT:
4034 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4035 break;
4036 case CARDSTATE_PRESENT:
4037 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4038 break;
4039 case CARDSTATE_ERROR:
4040 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4041 break;
4042 case CARDSTATE_RESTRICTED:
4043 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4044 break;
4045 default:
4046 break;
4047
4048 }
4049
Qingxi Li795c5882018-01-31 13:43:27 -08004050 infos[i] = new UiccSlotInfo(
4051 slot.isActive(), slot.isEuicc(), cardId, cardState, slot.getPhoneId());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004052 }
4053 return infos;
4054 }
4055
4056 @Override
4057 public boolean switchSlots(int[] physicalSlots) {
4058 enforceModifyPermission();
4059 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4060 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004061}