blob: 9f8b7777846d9648ec3268e6940b69de6a14bde6 [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;
Brad Ebinger1f2b5082018-02-08 16:11:32 -080077import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070078import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080079import android.util.ArraySet;
Tyler Gunn67073572018-02-14 14:19:42 -080080import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080082import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080083import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080084
Andrew Lee312e8172014-10-23 17:01:36 -070085import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080086import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070087import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070088import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -070089import com.android.internal.telephony.CarrierInfoManager;
Shishir Agrawal302c8692015-06-19 13:49:39 -070090import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070091import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070093import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080094import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010095import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070096import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070097import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080099import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700100import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700101import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700102import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700103import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700104import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800105import com.android.internal.telephony.SubscriptionController;
Jonathan Basseribf5362b2017-07-19 12:22:35 -0700106import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700107import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700108import com.android.internal.telephony.uicc.IccIoResult;
109import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800110import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700111import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800112import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700113import com.android.internal.telephony.uicc.UiccController;
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) {
Tyler Gunn67073572018-02-14 14:19:42 -08001189 if (mApp.checkCallingOrSelfPermission(permission.MODIFY_PHONE_STATE)
1190 != PackageManager.PERMISSION_GRANTED) {
1191 Log.i(LOG_TAG, "endCall: called without modify phone state.");
1192 EventLog.writeEvent(0x534e4554, "67862398", -1, "");
1193 throw new SecurityException("MODIFY_PHONE_STATE permission required.");
1194 }
Stuart Scott584921c2015-01-15 17:10:34 -08001195 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001196 }
1197
1198 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001199 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001200 }
1201
Wink Savilleb564aae2014-10-23 10:18:09 -07001202 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001203 if (DBG) log("answerRingingCall...");
1204 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1205 // but that can probably wait till the big TelephonyManager API overhaul.
1206 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1207 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001208 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001209 }
1210
1211 /**
1212 * Make the actual telephony calls to implement answerRingingCall().
1213 * This should only be called from the main thread of the Phone app.
1214 * @see #answerRingingCall
1215 *
1216 * TODO: it would be nice to return true if we answered the call, or
1217 * false if there wasn't actually a ringing incoming call, or some
1218 * other error occurred. (In other words, pass back the return value
1219 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1220 * But that would require calling this method via sendRequest() rather
1221 * than sendRequestAsync(), and right now we don't actually *need* that
1222 * return value, so let's just return void for now.
1223 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001224 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001225 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001226 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001227 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1228 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001229 if (hasActiveCall && hasHoldingCall) {
1230 // Both lines are in use!
1231 // TODO: provide a flag to let the caller specify what
1232 // policy to use if both lines are in use. (The current
1233 // behavior is hardwired to "answer incoming, end ongoing",
1234 // which is how the CALL button is specced to behave.)
1235 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1236 return;
1237 } else {
1238 // answerCall() will automatically hold the current active
1239 // call, if there is one.
1240 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1241 return;
1242 }
1243 } else {
1244 // No call was ringing.
1245 return;
1246 }
1247 }
1248
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001250 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001251 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001252 public void silenceRinger() {
1253 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001254 }
1255
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001256 @Override
1257 public boolean isOffhook(String callingPackage) {
1258 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001259 }
1260
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001261 @Override
1262 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1263 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1264 return false;
1265 }
1266
Sanket Padawe356d7632015-06-22 14:03:32 -07001267 final Phone phone = getPhone(subId);
1268 if (phone != null) {
1269 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1270 } else {
1271 return false;
1272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001273 }
1274
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001275 @Override
1276 public boolean isRinging(String callingPackage) {
1277 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001278 }
1279
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001280 @Override
1281 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1282 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1283 return false;
1284 }
1285
Sanket Padawe356d7632015-06-22 14:03:32 -07001286 final Phone phone = getPhone(subId);
1287 if (phone != null) {
1288 return (phone.getState() == PhoneConstants.State.RINGING);
1289 } else {
1290 return false;
1291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001292 }
1293
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001294 @Override
1295 public boolean isIdle(String callingPackage) {
1296 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001297 }
1298
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001299 @Override
1300 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1301 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1302 return false;
1303 }
1304
Sanket Padawe356d7632015-06-22 14:03:32 -07001305 final Phone phone = getPhone(subId);
1306 if (phone != null) {
1307 return (phone.getState() == PhoneConstants.State.IDLE);
1308 } else {
1309 return false;
1310 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 }
1312
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001314 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001315 }
1316
Wink Savilleb564aae2014-10-23 10:18:09 -07001317 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001318 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001319 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1320 }
1321
1322 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001323 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001324 }
1325
Wink Savilleb564aae2014-10-23 10:18:09 -07001326 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001327 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001328 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1329 }
1330
1331 /** {@hide} */
1332 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001333 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001334 }
1335
Wink Savilleb564aae2014-10-23 10:18:09 -07001336 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001337 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001338 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 checkSimPin.start();
1340 return checkSimPin.unlockSim(null, pin);
1341 }
1342
Wink Saville9de0f752013-10-22 19:04:03 -07001343 /** {@hide} */
1344 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001345 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001346 }
1347
Wink Savilleb564aae2014-10-23 10:18:09 -07001348 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001350 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001351 checkSimPuk.start();
1352 return checkSimPuk.unlockSim(puk, pin);
1353 }
1354
1355 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001356 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001357 * a synchronous one.
1358 */
1359 private static class UnlockSim extends Thread {
1360
1361 private final IccCard mSimCard;
1362
1363 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001364 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1365 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001366
1367 // For replies from SimCard interface
1368 private Handler mHandler;
1369
1370 // For async handler to identify request type
1371 private static final int SUPPLY_PIN_COMPLETE = 100;
1372
1373 public UnlockSim(IccCard simCard) {
1374 mSimCard = simCard;
1375 }
1376
1377 @Override
1378 public void run() {
1379 Looper.prepare();
1380 synchronized (UnlockSim.this) {
1381 mHandler = new Handler() {
1382 @Override
1383 public void handleMessage(Message msg) {
1384 AsyncResult ar = (AsyncResult) msg.obj;
1385 switch (msg.what) {
1386 case SUPPLY_PIN_COMPLETE:
1387 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1388 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001389 mRetryCount = msg.arg1;
1390 if (ar.exception != null) {
1391 if (ar.exception instanceof CommandException &&
1392 ((CommandException)(ar.exception)).getCommandError()
1393 == CommandException.Error.PASSWORD_INCORRECT) {
1394 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1395 } else {
1396 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1397 }
1398 } else {
1399 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001401 mDone = true;
1402 UnlockSim.this.notifyAll();
1403 }
1404 break;
1405 }
1406 }
1407 };
1408 UnlockSim.this.notifyAll();
1409 }
1410 Looper.loop();
1411 }
1412
1413 /*
1414 * Use PIN or PUK to unlock SIM card
1415 *
1416 * If PUK is null, unlock SIM card with PIN
1417 *
1418 * If PUK is not null, unlock SIM card with PUK and set PIN code
1419 */
Wink Saville9de0f752013-10-22 19:04:03 -07001420 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001421
1422 while (mHandler == null) {
1423 try {
1424 wait();
1425 } catch (InterruptedException e) {
1426 Thread.currentThread().interrupt();
1427 }
1428 }
1429 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1430
1431 if (puk == null) {
1432 mSimCard.supplyPin(pin, callback);
1433 } else {
1434 mSimCard.supplyPuk(puk, pin, callback);
1435 }
1436
1437 while (!mDone) {
1438 try {
1439 Log.d(LOG_TAG, "wait for done");
1440 wait();
1441 } catch (InterruptedException e) {
1442 // Restore the interrupted status
1443 Thread.currentThread().interrupt();
1444 }
1445 }
1446 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001447 int[] resultArray = new int[2];
1448 resultArray[0] = mResult;
1449 resultArray[1] = mRetryCount;
1450 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 }
1452 }
1453
1454 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001456
1457 }
1458
Wink Savilleb564aae2014-10-23 10:18:09 -07001459 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 // No permission check needed here: this call is harmless, and it's
1461 // needed for the ServiceState.requestStateUpdate() call (which is
1462 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001463 final Phone phone = getPhone(subId);
1464 if (phone != null) {
1465 phone.updateServiceLocation();
1466 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001467 }
1468
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001469 @Override
1470 public boolean isRadioOn(String callingPackage) {
1471 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001472 }
1473
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001474 @Override
1475 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1476 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1477 return false;
1478 }
1479 return isRadioOnForSubscriber(subId);
1480 }
1481
1482 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001483 final Phone phone = getPhone(subId);
1484 if (phone != null) {
1485 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1486 } else {
1487 return false;
1488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 }
1490
1491 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001492 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001493
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001494 }
Wink Saville36469e72014-06-11 15:17:00 -07001495
Wink Savilleb564aae2014-10-23 10:18:09 -07001496 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001498 final Phone phone = getPhone(subId);
1499 if (phone != null) {
1500 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1501 }
Wink Saville36469e72014-06-11 15:17:00 -07001502 }
1503
1504 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001505 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001506 }
1507
Wink Savilleb564aae2014-10-23 10:18:09 -07001508 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001509 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001510 final Phone phone = getPhone(subId);
1511 if (phone == null) {
1512 return false;
1513 }
1514 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001515 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001516 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001517 }
1518 return true;
1519 }
Wink Saville36469e72014-06-11 15:17:00 -07001520
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001521 public boolean needMobileRadioShutdown() {
1522 /*
1523 * If any of the Radios are available, it will need to be
1524 * shutdown. So return true if any Radio is available.
1525 */
1526 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1527 Phone phone = PhoneFactory.getPhone(i);
1528 if (phone != null && phone.isRadioAvailable()) return true;
1529 }
1530 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1531 return false;
1532 }
1533
1534 public void shutdownMobileRadios() {
1535 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1536 logv("Shutting down Phone " + i);
1537 shutdownRadioUsingPhoneId(i);
1538 }
1539 }
1540
1541 private void shutdownRadioUsingPhoneId(int phoneId) {
1542 enforceModifyPermission();
1543 Phone phone = PhoneFactory.getPhone(phoneId);
1544 if (phone != null && phone.isRadioAvailable()) {
1545 phone.shutdownRadio();
1546 }
1547 }
1548
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001549 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001550 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001551 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1552 if (defaultPhone != null) {
1553 defaultPhone.setRadioPower(turnOn);
1554 return true;
1555 } else {
1556 loge("There's no default phone.");
1557 return false;
1558 }
Wink Saville36469e72014-06-11 15:17:00 -07001559 }
1560
Wink Savilleb564aae2014-10-23 10:18:09 -07001561 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001562 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001563 final Phone phone = getPhone(subId);
1564 if (phone != null) {
1565 phone.setRadioPower(turnOn);
1566 return true;
1567 } else {
1568 return false;
1569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 }
1571
Wink Saville36469e72014-06-11 15:17:00 -07001572 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001573 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 public boolean enableDataConnectivity() {
1575 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001576 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001577 final Phone phone = getPhone(subId);
1578 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001579 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 return true;
1581 } else {
1582 return false;
1583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001584 }
1585
Wink Saville36469e72014-06-11 15:17:00 -07001586 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001587 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001588 public boolean disableDataConnectivity() {
1589 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001590 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001591 final Phone phone = getPhone(subId);
1592 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08001593 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 return true;
1595 } else {
1596 return false;
1597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 }
1599
Sanket Padawe356d7632015-06-22 14:03:32 -07001600 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001601 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001602 final Phone phone = getPhone(subId);
1603 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001604 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001605 } else {
1606 return false;
1607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 }
1609
1610 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001611 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001612 }
1613
pkanwarae03a6b2016-11-06 20:37:09 -08001614 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001615 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001616 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1617 return;
1618 }
1619 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1620 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1621 };
1622
Wink Savilleb564aae2014-10-23 10:18:09 -07001623 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001625 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1626 return false;
1627 }
Wink Saville36469e72014-06-11 15:17:00 -07001628 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 }
1630
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001632 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001633 }
1634
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001635 public int getCallStateForSlot(int slotIndex) {
1636 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001637 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001638 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001639 }
1640
Sanket Padawe356d7632015-06-22 14:03:32 -07001641 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001643 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001644 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001645 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001646 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001647 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 }
1650
Sanket Padawe356d7632015-06-22 14:03:32 -07001651 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001653 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001654 if (phone != null) {
1655 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1656 } else {
1657 return TelephonyManager.DATA_ACTIVITY_NONE;
1658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 }
1660
1661 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001662 public Bundle getCellLocation(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001663 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001664 callingPackage, Binder.getCallingUid(), "getCellLocation")) {
Svetoslav64fad262015-04-14 14:35:21 -07001665 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001666 }
1667
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001668 if (DBG_LOC) log("getCellLocation: is active user");
1669 Bundle data = new Bundle();
1670 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1671 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001672 return null;
1673 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001675 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001676 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1677 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001678 }
1679
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001680 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001681 public String getNetworkCountryIsoForPhone(int phoneId) {
1682 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1683 // registered cell info, so return a NULL country instead.
1684 final long identity = Binder.clearCallingIdentity();
1685 try {
1686 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1687 if (TelephonyManager.NETWORK_TYPE_IWLAN
1688 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1689 return "";
1690 }
1691 } finally {
1692 Binder.restoreCallingIdentity(identity);
1693 }
1694 return TelephonyManager.getTelephonyProperty(
1695 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1696 }
1697
1698 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001700 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001701 }
1702
Sanket Padawe356d7632015-06-22 14:03:32 -07001703 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001704 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001705 mApp.enforceCallingOrSelfPermission(
1706 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001707 final Phone phone = getPhone(subId);
1708 if (phone != null) {
1709 phone.enableLocationUpdates();
1710 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 }
1712
1713 @Override
1714 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001715 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001716 }
1717
Sanket Padawe356d7632015-06-22 14:03:32 -07001718 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001719 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001720 mApp.enforceCallingOrSelfPermission(
1721 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001722 final Phone phone = getPhone(subId);
1723 if (phone != null) {
1724 phone.disableLocationUpdates();
1725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
1728 @Override
1729 @SuppressWarnings("unchecked")
1730 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001731 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001732 callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001733 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 }
1735
1736 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1737 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1738 return null;
1739 }
Svetoslav64fad262015-04-14 14:35:21 -07001740
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001741 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001742
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001743 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001745 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001746 try {
1747 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1748 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1749 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1750 } catch (RuntimeException e) {
1751 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001753 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001754 }
1755
1756
1757 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001758 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001759 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001760 callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001761 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001762 }
1763
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001764 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001765 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001766 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1767 for (Phone phone : PhoneFactory.getPhones()) {
1768 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1769 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001771 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 }
1773
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001774 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001776 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001777 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001778 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 }
1780
Shishir Agrawala9f32182016-04-12 12:00:16 -07001781 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001782 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001783 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1784 return null;
1785 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001786 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001787 return phone == null ? null : phone.getImei();
1788 }
1789
1790 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001791 public String getMeidForSlot(int slotIndex, String callingPackage) {
1792 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1793 return null;
1794 }
1795 Phone phone = PhoneFactory.getPhone(slotIndex);
1796 return phone == null ? null : phone.getMeid();
1797 }
1798
1799 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001800 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001801 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1802 return null;
1803 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001804 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001805 return phone == null ? null : phone.getDeviceSvn();
1806 }
1807
fionaxu43304da2017-11-27 22:51:16 -08001808 @Override
1809 public int getSubscriptionCarrierId(int subId) {
1810 final Phone phone = getPhone(subId);
1811 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1812 }
1813
1814 @Override
1815 public String getSubscriptionCarrierName(int subId) {
1816 final Phone phone = getPhone(subId);
1817 return phone == null ? null : phone.getCarrierName();
1818 }
1819
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 //
1821 // Internal helper methods.
1822 //
1823
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001824 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1826 *
1827 * @throws SecurityException if the caller does not have the required permission
1828 */
1829 private void enforceModifyPermission() {
1830 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1831 }
1832
1833 /**
Junda Liua2e36012014-07-09 18:30:01 -07001834 * Make sure either system app or the caller has carrier privilege.
1835 *
1836 * @throws SecurityException if the caller does not have the required permission/privilege
1837 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001838 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001839 int permission = mApp.checkCallingOrSelfPermission(
1840 android.Manifest.permission.MODIFY_PHONE_STATE);
1841 if (permission == PackageManager.PERMISSION_GRANTED) {
1842 return;
1843 }
1844
1845 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001846 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001847 }
1848
1849 /**
1850 * Make sure the caller has carrier privilege.
1851 *
1852 * @throws SecurityException if the caller does not have the required permission
1853 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001854 private void enforceCarrierPrivilege(int subId) {
1855 if (getCarrierPrivilegeStatus(subId) !=
1856 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001857 loge("No Carrier Privilege.");
1858 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001859 }
1860 }
1861
1862 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 * Make sure the caller has the CALL_PHONE permission.
1864 *
1865 * @throws SecurityException if the caller does not have the required permission
1866 */
1867 private void enforceCallPermission() {
1868 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1869 }
1870
Stuart Scott8eef64f2015-04-08 15:13:54 -07001871 private void enforceConnectivityInternalPermission() {
1872 mApp.enforceCallingOrSelfPermission(
1873 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1874 "ConnectivityService");
1875 }
1876
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 private String createTelUrl(String number) {
1878 if (TextUtils.isEmpty(number)) {
1879 return null;
1880 }
1881
Jake Hambye994d462014-02-03 13:10:13 -08001882 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001883 }
1884
Ihab Awadf9e92732013-12-05 18:02:52 -08001885 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1887 }
1888
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001889 private static void logv(String msg) {
1890 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1891 }
1892
Ihab Awadf9e92732013-12-05 18:02:52 -08001893 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1895 }
1896
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001897 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001898 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001899 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001900 }
1901
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001903 public int getActivePhoneTypeForSlot(int slotIndex) {
1904 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001905 if (phone == null) {
1906 return PhoneConstants.PHONE_TYPE_NONE;
1907 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001908 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 }
1911
1912 /**
1913 * Returns the CDMA ERI icon index to display
1914 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001915 @Override
1916 public int getCdmaEriIconIndex(String callingPackage) {
1917 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001918 }
1919
Sanket Padawe356d7632015-06-22 14:03:32 -07001920 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001921 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1922 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1923 return -1;
1924 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001925 final Phone phone = getPhone(subId);
1926 if (phone != null) {
1927 return phone.getCdmaEriIconIndex();
1928 } else {
1929 return -1;
1930 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 }
1932
1933 /**
1934 * Returns the CDMA ERI icon mode,
1935 * 0 - ON
1936 * 1 - FLASHING
1937 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001938 @Override
1939 public int getCdmaEriIconMode(String callingPackage) {
1940 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001941 }
1942
Sanket Padawe356d7632015-06-22 14:03:32 -07001943 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001944 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1945 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1946 return -1;
1947 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 final Phone phone = getPhone(subId);
1949 if (phone != null) {
1950 return phone.getCdmaEriIconMode();
1951 } else {
1952 return -1;
1953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 }
1955
1956 /**
1957 * Returns the CDMA ERI text,
1958 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001959 @Override
1960 public String getCdmaEriText(String callingPackage) {
1961 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001962 }
1963
Sanket Padawe356d7632015-06-22 14:03:32 -07001964 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001965 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1966 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1967 return null;
1968 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001969 final Phone phone = getPhone(subId);
1970 if (phone != null) {
1971 return phone.getCdmaEriText();
1972 } else {
1973 return null;
1974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 }
1976
1977 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001978 * Returns the CDMA MDN.
1979 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001980 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001981 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001982 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001983 final Phone phone = getPhone(subId);
1984 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1985 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001986 } else {
1987 return null;
1988 }
1989 }
1990
1991 /**
1992 * Returns the CDMA MIN.
1993 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001994 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001995 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001996 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 final Phone phone = getPhone(subId);
1998 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1999 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07002000 } else {
2001 return null;
2002 }
2003 }
2004
2005 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002006 * Returns true if CDMA provisioning needs to run.
2007 */
2008 public boolean needsOtaServiceProvisioning() {
2009 return mPhone.needsOtaServiceProvisioning();
2010 }
2011
2012 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002013 * Sets the voice mail number of a given subId.
2014 */
2015 @Override
2016 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002017 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002018 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2019 new Pair<String, String>(alphaTag, number), new Integer(subId));
2020 return success;
2021 }
2022
Ta-wei Yen87c49842016-05-13 21:19:52 -07002023 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002024 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2025 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2026 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2027 if (!TextUtils.equals(callingPackage, systemDialer)) {
2028 throw new SecurityException("caller must be system dialer");
2029 }
2030 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2031 if (phoneAccountHandle == null){
2032 return null;
2033 }
2034 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2035 }
2036
2037 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002038 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002039 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2040 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2041 return null;
2042 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002043 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2044 }
2045
2046 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002047 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2048 VisualVoicemailSmsFilterSettings settings) {
2049 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002050 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002051 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2052 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002053 }
2054
2055 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002056 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2057 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002058 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002059 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002060 }
2061
2062 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002063 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2064 String callingPackage, int subId) {
2065 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002066 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002067 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002068 }
2069
2070 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002071 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002072 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002073 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002074 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2075 }
2076
2077 @Override
2078 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2079 String number, int port, String text, PendingIntent sentIntent) {
2080 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002081 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002082 enforceSendSmsPermission();
2083 // Make the calls as the phone process.
2084 final long identity = Binder.clearCallingIdentity();
2085 try {
2086 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2087 if (port == 0) {
2088 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2089 sentIntent, null, false);
2090 } else {
2091 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2092 smsManager.sendDataMessageWithSelfPermissions(number, null,
2093 (short) port, data, sentIntent, null);
2094 }
2095 } finally {
2096 Binder.restoreCallingIdentity(identity);
2097 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002098 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002099 /**
fionaxu0152e512016-11-14 13:36:14 -08002100 * Sets the voice activation state of a given subId.
2101 */
2102 @Override
2103 public void setVoiceActivationState(int subId, int activationState) {
2104 enforceModifyPermissionOrCarrierPrivilege(subId);
2105 final Phone phone = getPhone(subId);
2106 if (phone != null) {
2107 phone.setVoiceActivationState(activationState);
2108 } else {
2109 loge("setVoiceActivationState fails with invalid subId: " + subId);
2110 }
2111 }
2112
2113 /**
2114 * Sets the data activation state of a given subId.
2115 */
2116 @Override
2117 public void setDataActivationState(int subId, int activationState) {
2118 enforceModifyPermissionOrCarrierPrivilege(subId);
2119 final Phone phone = getPhone(subId);
2120 if (phone != null) {
2121 phone.setDataActivationState(activationState);
2122 } else {
2123 loge("setVoiceActivationState fails with invalid subId: " + subId);
2124 }
2125 }
2126
2127 /**
2128 * Returns the voice activation state of a given subId.
2129 */
2130 @Override
2131 public int getVoiceActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002132 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002133 final Phone phone = getPhone(subId);
2134 if (phone != null) {
2135 return phone.getVoiceActivationState();
2136 } else {
2137 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2138 }
2139 }
2140
2141 /**
2142 * Returns the data activation state of a given subId.
2143 */
2144 @Override
2145 public int getDataActivationState(int subId, String callingPackage) {
goneil799f6e92017-12-13 12:57:23 -08002146 enforceReadPrivilegedPermission();
fionaxu0152e512016-11-14 13:36:14 -08002147 final Phone phone = getPhone(subId);
2148 if (phone != null) {
2149 return phone.getDataActivationState();
2150 } else {
2151 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2152 }
2153 }
2154
2155 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 * Returns the unread count of voicemails
2157 */
2158 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002159 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002160 }
2161
2162 /**
2163 * Returns the unread count of voicemails for a subId
2164 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002165 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002166 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002167 final Phone phone = getPhone(subId);
2168 if (phone != null) {
2169 return phone.getVoiceMessageCount();
2170 } else {
2171 return 0;
2172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 }
2174
2175 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002176 * returns true, if the device is in a state where both voice and data
2177 * are supported simultaneously. This can change based on location or network condition.
2178 */
2179 @Override
2180 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2181 final Phone phone = getPhone(subId);
2182 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2183 }
2184
2185 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002186 * Send the dialer code if called from the current default dialer or the caller has
2187 * carrier privilege.
2188 * @param inputCode The dialer code to send
2189 */
2190 @Override
2191 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2192 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2193 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2194 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2195 enforceCarrierPrivilege(getDefaultSubscription());
2196 }
2197 mPhone.sendDialerSpecialCode(inputCode);
2198 }
2199
2200 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002201 * Returns the data network type.
2202 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 *
2204 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2205 */
2206 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002207 public int getNetworkType() {
2208 final Phone phone = getPhone(getDefaultSubscription());
2209 if (phone != null) {
2210 return phone.getServiceState().getDataNetworkType();
2211 } else {
2212 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2213 }
Wink Saville36469e72014-06-11 15:17:00 -07002214 }
2215
2216 /**
2217 * Returns the network type for a subId
2218 */
2219 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002220 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2221 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2222 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2223 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002224
Sanket Padawe356d7632015-06-22 14:03:32 -07002225 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002226 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002227 return phone.getServiceState().getDataNetworkType();
2228 } else {
2229 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 }
2232
2233 /**
2234 * Returns the data network type
2235 */
2236 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002237 public int getDataNetworkType(String callingPackage) {
2238 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002239 }
2240
2241 /**
2242 * Returns the data network type for a subId
2243 */
2244 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002245 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2246 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2247 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2248 }
2249
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 final Phone phone = getPhone(subId);
2251 if (phone != null) {
2252 return phone.getServiceState().getDataNetworkType();
2253 } else {
2254 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002256 }
2257
2258 /**
Wink Saville36469e72014-06-11 15:17:00 -07002259 * Returns the Voice network type for a subId
2260 */
2261 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002262 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2263 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2264 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2265 }
2266
Sanket Padawe356d7632015-06-22 14:03:32 -07002267 final Phone phone = getPhone(subId);
2268 if (phone != null) {
2269 return phone.getServiceState().getVoiceNetworkType();
2270 } else {
2271 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 }
2274
2275 /**
2276 * @return true if a ICC card is present
2277 */
2278 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002279 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002280 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2281 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002282 }
2283
2284 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002285 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002286 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002287 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002288 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2289 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002290 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002291 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002292 } else {
2293 return false;
2294 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 }
2296
2297 /**
2298 * Return if the current radio is LTE on CDMA. This
2299 * is a tri-state return value as for a period of time
2300 * the mode may be unknown.
2301 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002302 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002304 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002305 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002306 @Override
2307 public int getLteOnCdmaMode(String callingPackage) {
2308 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002309 }
2310
Sanket Padawe356d7632015-06-22 14:03:32 -07002311 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002312 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2313 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2314 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2315 }
2316
Sanket Padawe356d7632015-06-22 14:03:32 -07002317 final Phone phone = getPhone(subId);
2318 if (phone == null) {
2319 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2320 } else {
2321 return phone.getLteOnCdmaMode();
2322 }
Wink Saville36469e72014-06-11 15:17:00 -07002323 }
2324
2325 public void setPhone(Phone phone) {
2326 mPhone = phone;
2327 }
2328
2329 /**
2330 * {@hide}
2331 * Returns Default subId, 0 in the case of single standby.
2332 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002333 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002334 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002335 }
2336
Shishir Agrawala9f32182016-04-12 12:00:16 -07002337 private int getSlotForDefaultSubscription() {
2338 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2339 }
2340
Wink Savilleb564aae2014-10-23 10:18:09 -07002341 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002342 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002344
2345 /**
2346 * @see android.telephony.TelephonyManager.WifiCallingChoices
2347 */
2348 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002349 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2350 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002351 }
2352
2353 /**
2354 * @see android.telephony.TelephonyManager.WifiCallingChoices
2355 */
2356 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002357 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2358 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2359 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002360 }
2361
Sailesh Nepald1e68152013-12-12 19:08:02 -08002362 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002363 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002364 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002365 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002366
Shishir Agrawal566b7612013-10-28 14:41:00 -07002367 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002368 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2369 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002370 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002371
Derek Tan740e1672017-06-27 14:56:27 -07002372 if (TextUtils.equals(ISDR_AID, aid)) {
2373 // Only allows LPA to open logical channel to ISD-R.
2374 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2375 ComponentInfo bestComponent =
2376 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2377 if (bestComponent == null
2378 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2379 loge("The calling package is not allowed to access ISD-R.");
2380 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2381 }
2382 }
2383
2384 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002385 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002386 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002387 if (DBG) log("iccOpenLogicalChannel: " + response);
2388 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002389 }
2390
2391 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002392 public boolean iccCloseLogicalChannel(int subId, int channel) {
2393 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002394
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002395 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002396 if (channel < 0) {
2397 return false;
2398 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002399 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002400 if (DBG) log("iccCloseLogicalChannel: " + success);
2401 return success;
2402 }
2403
2404 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002405 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002406 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002407 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002408
2409 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002410 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2411 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002412 " data=" + data);
2413 }
2414
2415 if (channel < 0) {
2416 return "";
2417 }
2418
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002419 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002420 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002421 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2422
Shishir Agrawal566b7612013-10-28 14:41:00 -07002423 // Append the returned status code to the end of the response payload.
2424 String s = Integer.toHexString(
2425 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002426 if (response.payload != null) {
2427 s = IccUtils.bytesToHexString(response.payload) + s;
2428 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002429 return s;
2430 }
Jake Hambye994d462014-02-03 13:10:13 -08002431
Evan Charltonc66da362014-05-16 14:06:40 -07002432 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002433 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2434 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002435 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002436
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002437 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2438 && TextUtils.equals(ISDR_AID, data)) {
2439 // Only allows LPA to select ISD-R.
2440 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2441 ComponentInfo bestComponent =
2442 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2443 if (bestComponent == null
2444 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2445 loge("The calling package is not allowed to select ISD-R.");
2446 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2447 }
2448 }
2449
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002450 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002451 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2452 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002453 }
2454
2455 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002456 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002457 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2458
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002459 // Append the returned status code to the end of the response payload.
2460 String s = Integer.toHexString(
2461 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002462 if (response.payload != null) {
2463 s = IccUtils.bytesToHexString(response.payload) + s;
2464 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002465 return s;
2466 }
2467
2468 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002469 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002470 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002471 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002472
2473 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002474 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002475 p1 + " " + p2 + " " + p3 + ":" + filePath);
2476 }
2477
2478 IccIoResult response =
2479 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002480 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2481 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002482
2483 if (DBG) {
2484 log("Exchange SIM_IO [R]" + response);
2485 }
2486
2487 byte[] result = null;
2488 int length = 2;
2489 if (response.payload != null) {
2490 length = 2 + response.payload.length;
2491 result = new byte[length];
2492 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2493 } else {
2494 result = new byte[length];
2495 }
2496
2497 result[length - 1] = (byte) response.sw2;
2498 result[length - 2] = (byte) response.sw1;
2499 return result;
2500 }
2501
Nathan Haroldb3014052017-01-25 15:57:32 -08002502 /**
2503 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2504 * on a particular subscription
2505 */
2506 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002507 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2508 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002509 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2510 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2511 return null;
2512 }
2513 Object response = sendRequest(
2514 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2515 if (response instanceof String[]) {
2516 return (String[]) response;
2517 }
2518 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2519 return null;
2520 }
2521
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002522 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002523 public String sendEnvelopeWithStatus(int subId, String content) {
2524 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002525
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002526 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002527 if (response.payload == null) {
2528 return "";
2529 }
2530
2531 // Append the returned status code to the end of the response payload.
2532 String s = Integer.toHexString(
2533 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2534 s = IccUtils.bytesToHexString(response.payload) + s;
2535 return s;
2536 }
2537
Jake Hambye994d462014-02-03 13:10:13 -08002538 /**
2539 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2540 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2541 *
2542 * @param itemID the ID of the item to read
2543 * @return the NV item as a String, or null on error.
2544 */
2545 @Override
2546 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002547 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002548 if (DBG) log("nvReadItem: item " + itemID);
2549 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2550 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2551 return value;
2552 }
2553
2554 /**
2555 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2556 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2557 *
2558 * @param itemID the ID of the item to read
2559 * @param itemValue the value to write, as a String
2560 * @return true on success; false on any failure
2561 */
2562 @Override
2563 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002564 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002565 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2566 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2567 new Pair<Integer, String>(itemID, itemValue));
2568 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2569 return success;
2570 }
2571
2572 /**
2573 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2574 * Used for device configuration by some CDMA operators.
2575 *
2576 * @param preferredRoamingList byte array containing the new PRL
2577 * @return true on success; false on any failure
2578 */
2579 @Override
2580 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002581 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002582 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2583 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2584 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2585 return success;
2586 }
2587
2588 /**
2589 * Perform the specified type of NV config reset.
2590 * Used for device configuration by some CDMA operators.
2591 *
2592 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2593 * @return true on success; false on any failure
2594 */
2595 @Override
2596 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002597 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002598 if (DBG) log("nvResetConfig: type " + resetType);
2599 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2600 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2601 return success;
2602 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002603
2604 /**
Wink Saville36469e72014-06-11 15:17:00 -07002605 * {@hide}
2606 * Returns Default sim, 0 in the case of single standby.
2607 */
2608 public int getDefaultSim() {
2609 //TODO Need to get it from Telephony Devcontroller
2610 return 0;
2611 }
2612
Svet Ganovb320e182015-04-16 12:30:10 -07002613 public String[] getPcscfAddress(String apnType, String callingPackage) {
2614 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2615 return new String[0];
2616 }
2617
2618
ram87fca6f2014-07-18 18:58:44 +05302619 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002620 }
2621
Brad Ebinger51f743a2017-01-23 13:50:20 -08002622 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002623 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2624 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002625 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002626 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002627 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002628 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002629 }
2630
2631 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002632 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2633 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002634 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002635 public void disableIms(int slotId) {
2636 enforceModifyPermission();
2637 PhoneFactory.getImsResolver().disableIms(slotId);
2638 }
2639
2640 /**
2641 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2642 * feature or {@link null} if the service is not available. If the feature is available, the
2643 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2644 */
2645 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002646 IImsServiceFeatureCallback callback) {
2647 enforceModifyPermission();
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002648 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002649 }
2650
2651 /**
2652 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2653 * feature during emergency calling or {@link null} if the service is not available. If the
2654 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2655 * listener for feature updates.
2656 */
2657 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2658 enforceModifyPermission();
2659 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002660 }
2661
Brad Ebinger5f64b052017-12-14 14:26:15 -08002662 /**
2663 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2664 * specified.
2665 */
2666 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2667 enforceModifyPermission();
2668 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2669 }
2670
Brad Ebinger22bc3e42018-01-16 09:39:35 -08002671 /**
2672 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2673 * specified.
2674 */
2675 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2676 enforceModifyPermission();
2677 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2678 }
2679
Wink Saville36469e72014-06-11 15:17:00 -07002680 public void setImsRegistrationState(boolean registered) {
2681 enforceModifyPermission();
2682 mPhone.setImsRegistrationState(registered);
2683 }
2684
2685 /**
Stuart Scott54788802015-03-30 13:18:01 -07002686 * Set the network selection mode to automatic.
2687 *
2688 */
2689 @Override
2690 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002691 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002692 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2693 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2694 }
2695
2696 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002697 * Set the network selection mode to manual with the selected carrier.
2698 */
2699 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002700 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002701 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002702 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002703 OperatorInfo operator = new OperatorInfo(
2704 /* operatorAlphaLong */ "",
2705 /* operatorAlphaShort */ "",
2706 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002707 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002708 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2709 persistSelection);
2710 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002711 }
2712
2713 /**
2714 * Scans for available networks.
2715 */
2716 @Override
2717 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002718 enforceModifyPermissionOrCarrierPrivilege(subId);
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) {
yinxub1bed742017-04-17 11:45:04 -07002737 enforceModifyPermissionOrCarrierPrivilege(subId);
2738 return mNetworkScanRequestTracker.startNetworkScan(
2739 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002740 }
2741
2742 /**
2743 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002744 *
2745 * @param subId id of the subscription
2746 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002747 */
2748 @Override
2749 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002750 enforceModifyPermissionOrCarrierPrivilege(subId);
2751 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002752 }
2753
2754 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002755 * Get the calculated preferred network type.
2756 * Used for debugging incorrect network type.
2757 *
2758 * @return the preferred network type, defined in RILConstants.java.
2759 */
2760 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002761 public int getCalculatedPreferredNetworkType(String callingPackage) {
2762 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2763 return RILConstants.PREFERRED_NETWORK_MODE;
2764 }
2765
Amit Mahajan43330e02014-11-18 11:54:45 -08002766 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002767 }
2768
2769 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002770 * Get the preferred network type.
2771 * Used for device configuration by some CDMA operators.
2772 *
2773 * @return the preferred network type, defined in RILConstants.java.
2774 */
2775 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002776 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002777 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002778 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002779 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002780 int networkType = (result != null ? result[0] : -1);
2781 if (DBG) log("getPreferredNetworkType: " + networkType);
2782 return networkType;
2783 }
2784
2785 /**
2786 * Set the preferred network type.
2787 * Used for device configuration by some CDMA operators.
2788 *
2789 * @param networkType the preferred network type, defined in RILConstants.java.
2790 * @return true on success; false on any failure.
2791 */
2792 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002793 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002794 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002795 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2796 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002797 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002798 if (success) {
2799 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002800 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002801 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002802 return success;
2803 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002804
2805 /**
Junda Liu475951f2014-11-07 16:45:03 -08002806 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2807 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2808 * tethering.
2809 *
2810 * @return 0: Not required. 1: required. 2: Not set.
2811 * @hide
2812 */
2813 @Override
2814 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002815 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002816 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2817 Settings.Global.TETHER_DUN_REQUIRED, 2);
2818 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2819 // config_tether_apndata.
2820 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2821 dunRequired = 1;
2822 }
2823 return dunRequired;
2824 }
2825
2826 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002827 * Set mobile data enabled
2828 * Used by the user through settings etc to turn on/off mobile data
2829 *
2830 * @param enable {@code true} turn turn data on, else {@code false}
2831 */
2832 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002833 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002834 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002835 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002836 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002837 Phone phone = PhoneFactory.getPhone(phoneId);
2838 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002839 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2840 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002841 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002842 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002843 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002844 }
2845
2846 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08002847 * Get the user enabled state of Mobile Data.
2848 *
2849 * TODO: remove and use isUserDataEnabled.
2850 * This can't be removed now because some vendor codes
2851 * calls through ITelephony directly while they should
2852 * use TelephonyManager.
2853 *
2854 * @return true on enabled
2855 */
2856 @Override
2857 public boolean getDataEnabled(int subId) {
2858 return isUserDataEnabled(subId);
2859 }
2860
2861 /**
2862 * Get whether mobile data is enabled per user setting.
2863 *
2864 * There are other factors deciding whether mobile data is actually enabled, but they are
2865 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002866 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002867 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002868 *
2869 * @return {@code true} if data is enabled else {@code false}
2870 */
2871 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08002872 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002873 try {
2874 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2875 null);
2876 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002877 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002878 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002879 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chen964682d2017-11-28 16:20:07 -08002880 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002881 Phone phone = PhoneFactory.getPhone(phoneId);
2882 if (phone != null) {
Malcolm Chen964682d2017-11-28 16:20:07 -08002883 boolean retVal = phone.isUserDataEnabled();
2884 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002885 return retVal;
2886 } else {
Malcolm Chen964682d2017-11-28 16:20:07 -08002887 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2888 return false;
2889 }
2890 }
2891
2892 /**
2893 * Get whether mobile data is enabled.
2894 *
2895 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2896 * whether mobile data is actually enabled.
2897 *
2898 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2899 *
2900 * @return {@code true} if data is enabled else {@code false}
2901 */
2902 @Override
2903 public boolean isDataEnabled(int subId) {
2904 try {
2905 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2906 null);
2907 } catch (Exception e) {
2908 enforceModifyPermissionOrCarrierPrivilege(subId);
2909 }
2910 int phoneId = mSubscriptionController.getPhoneId(subId);
2911 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2912 Phone phone = PhoneFactory.getPhone(phoneId);
2913 if (phone != null) {
2914 boolean retVal = phone.isDataEnabled();
2915 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2916 return retVal;
2917 } else {
2918 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002919 return false;
2920 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002921 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002922
2923 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002924 public int getCarrierPrivilegeStatus(int subId) {
2925 final Phone phone = getPhone(subId);
2926 if (phone == null) {
2927 loge("getCarrierPrivilegeStatus: Invalid subId");
2928 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2929 }
2930 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002931 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002932 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002933 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2934 }
2935 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002936 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002937 }
Junda Liu29340342014-07-10 15:23:27 -07002938
2939 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002940 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002941 if (TextUtils.isEmpty(pkgName))
2942 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002943 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002944 if (card == null) {
2945 loge("checkCarrierPrivilegesForPackage: No UICC");
2946 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2947 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002948 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2949 }
2950
2951 @Override
2952 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002953 if (TextUtils.isEmpty(pkgName))
2954 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002955 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2956 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2957 UiccCard card = UiccController.getInstance().getUiccCard(i);
2958 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002959 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002960 continue;
2961 }
2962
2963 result = card.getCarrierPrivilegeStatus(
2964 mPhone.getContext().getPackageManager(), pkgName);
2965 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2966 break;
2967 }
2968 }
2969
2970 return result;
Junda Liu29340342014-07-10 15:23:27 -07002971 }
Derek Tan89e89d42014-07-08 17:00:10 -07002972
2973 @Override
Junda Liue64de782015-04-16 17:19:16 -07002974 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2975 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2976 loge("phoneId " + phoneId + " is not valid.");
2977 return null;
2978 }
2979 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002980 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002981 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002982 return null ;
2983 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002984 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002985 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002986 }
2987
Amith Yamasani6e118872016-02-19 12:53:51 -08002988 @Override
2989 public List<String> getPackagesWithCarrierPrivileges() {
2990 PackageManager pm = mPhone.getContext().getPackageManager();
2991 List<String> privilegedPackages = new ArrayList<>();
2992 List<PackageInfo> packages = null;
2993 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2994 UiccCard card = UiccController.getInstance().getUiccCard(i);
2995 if (card == null) {
2996 // No UICC in that slot.
2997 continue;
2998 }
2999 if (card.hasCarrierPrivilegeRules()) {
3000 if (packages == null) {
3001 // Only check packages in user 0 for now
3002 packages = pm.getInstalledPackagesAsUser(
3003 PackageManager.MATCH_DISABLED_COMPONENTS
3004 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3005 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3006 }
3007 for (int p = packages.size() - 1; p >= 0; p--) {
3008 PackageInfo pkgInfo = packages.get(p);
3009 if (pkgInfo != null && pkgInfo.packageName != null
3010 && card.getCarrierPrivilegeStatus(pkgInfo)
3011 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3012 privilegedPackages.add(pkgInfo.packageName);
3013 }
3014 }
3015 }
3016 }
3017 return privilegedPackages;
3018 }
3019
Wink Savilleb564aae2014-10-23 10:18:09 -07003020 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003021 final Phone phone = getPhone(subId);
3022 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003023 if (card == null) {
3024 loge("getIccId: No UICC");
3025 return null;
3026 }
3027 String iccId = card.getIccId();
3028 if (TextUtils.isEmpty(iccId)) {
3029 loge("getIccId: ICC ID is null or empty.");
3030 return null;
3031 }
3032 return iccId;
3033 }
3034
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003035 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003036 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3037 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003038 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07003039
Jeff Sharkey85190e62014-12-05 09:40:12 -08003040 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003041 final Phone phone = getPhone(subId);
3042 if (phone == null) {
3043 return false;
3044 }
3045 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003046
3047 if (DBG_MERGE) {
3048 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3049 + subscriberId + " to " + number);
3050 }
3051
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003052 if (TextUtils.isEmpty(iccId)) {
3053 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003054 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003055
Jeff Sharkey85190e62014-12-05 09:40:12 -08003056 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3057
3058 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003059 if (alphaTag == null) {
3060 editor.remove(alphaTagPrefKey);
3061 } else {
3062 editor.putString(alphaTagPrefKey, alphaTag);
3063 }
3064
Jeff Sharkey85190e62014-12-05 09:40:12 -08003065 // Record both the line number and IMSI for this ICCID, since we need to
3066 // track all merged IMSIs based on line number
3067 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3068 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003069 if (number == null) {
3070 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003071 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003072 } else {
3073 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003074 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003075 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003076
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003077 editor.commit();
3078 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003079 }
3080
3081 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003082 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003083 // This is open to apps with WRITE_SMS.
3084 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003085 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003086 return null;
3087 }
Derek Tan97ebb422014-09-05 16:55:38 -07003088
3089 String iccId = getIccId(subId);
3090 if (iccId != null) {
3091 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003092 if (DBG_MERGE) {
3093 log("getLine1NumberForDisplay returning " +
3094 mTelephonySharedPreferences.getString(numberPrefKey, null));
3095 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003096 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003097 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003098 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003099 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003100 }
3101
3102 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003103 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3104 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3105 return null;
3106 }
Derek Tan97ebb422014-09-05 16:55:38 -07003107
3108 String iccId = getIccId(subId);
3109 if (iccId != null) {
3110 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003111 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003112 }
Derek Tan97ebb422014-09-05 16:55:38 -07003113 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003114 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003115
3116 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003117 public String[] getMergedSubscriberIds(String callingPackage) {
3118 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3119 return null;
3120 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003121 final Context context = mPhone.getContext();
3122 final TelephonyManager tele = TelephonyManager.from(context);
3123 final SubscriptionManager sub = SubscriptionManager.from(context);
3124
3125 // Figure out what subscribers are currently active
3126 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003127 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3128 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3129 final long identity = Binder.clearCallingIdentity();
3130 try {
3131 final int[] subIds = sub.getActiveSubscriptionIdList();
3132 for (int subId : subIds) {
3133 activeSubscriberIds.add(tele.getSubscriberId(subId));
3134 }
3135 } finally {
3136 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003137 }
3138
3139 // First pass, find a number override for an active subscriber
3140 String mergeNumber = null;
3141 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3142 for (String key : prefs.keySet()) {
3143 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3144 final String subscriberId = (String) prefs.get(key);
3145 if (activeSubscriberIds.contains(subscriberId)) {
3146 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3147 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3148 mergeNumber = (String) prefs.get(numberKey);
3149 if (DBG_MERGE) {
3150 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3151 + " for active subscriber " + subscriberId);
3152 }
3153 if (!TextUtils.isEmpty(mergeNumber)) {
3154 break;
3155 }
3156 }
3157 }
3158 }
3159
3160 // Shortcut when no active merged subscribers
3161 if (TextUtils.isEmpty(mergeNumber)) {
3162 return null;
3163 }
3164
3165 // Second pass, find all subscribers under that line override
3166 final ArraySet<String> result = new ArraySet<>();
3167 for (String key : prefs.keySet()) {
3168 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3169 final String number = (String) prefs.get(key);
3170 if (mergeNumber.equals(number)) {
3171 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3172 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3173 final String subscriberId = (String) prefs.get(subscriberKey);
3174 if (!TextUtils.isEmpty(subscriberId)) {
3175 result.add(subscriberId);
3176 }
3177 }
3178 }
3179 }
3180
3181 final String[] resultArray = result.toArray(new String[result.size()]);
3182 Arrays.sort(resultArray);
3183 if (DBG_MERGE) {
3184 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3185 }
3186 return resultArray;
3187 }
3188
3189 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003190 public boolean setOperatorBrandOverride(int subId, String brand) {
3191 enforceCarrierPrivilege(subId);
3192 final Phone phone = getPhone(subId);
3193 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003194 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003195
3196 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003197 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003198 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3199 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003200 enforceCarrierPrivilege(subId);
3201 final Phone phone = getPhone(subId);
3202 if (phone == null) {
3203 return false;
3204 }
3205 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003206 cdmaNonRoamingList);
3207 }
3208
3209 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003210 public void setRadioCapability(RadioAccessFamily[] rafs) {
3211 try {
3212 ProxyController.getInstance().setRadioCapability(rafs);
3213 } catch (RuntimeException e) {
3214 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3215 }
3216 }
3217
3218 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003219 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3220 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3221 return RadioAccessFamily.RAF_UNKNOWN;
3222 }
3223
Wink Saville5d475dd2014-10-17 15:00:58 -07003224 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3225 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003226
3227 @Override
3228 public void enableVideoCalling(boolean enable) {
3229 enforceModifyPermission();
Malcolm Chenfbf47712017-12-12 18:19:27 -08003230 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003231 }
3232
3233 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003234 public boolean isVideoCallingEnabled(String callingPackage) {
3235 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3236 return false;
3237 }
3238
Andrew Lee77527ac2014-10-21 16:57:39 -07003239 // Check the user preference and the system-level IMS setting. Even if the user has
3240 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3241 // In the long run, we may instead need to check if there exists a connection service
3242 // which can support video calling.
Malcolm Chenfbf47712017-12-12 18:19:27 -08003243 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3244 return imsManager.isVtEnabledByPlatform()
3245 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3246 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003247 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003248
Andrew Leea1239f22015-03-02 17:44:07 -08003249 @Override
3250 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003251 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003252 }
3253
3254 @Override
3255 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003256 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003257 }
3258
Andrew Lee9431b832015-03-09 18:46:45 -07003259 @Override
3260 public boolean isTtyModeSupported() {
3261 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3262 TelephonyManager telephonyManager =
3263 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003264 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003265 }
3266
3267 @Override
3268 public boolean isHearingAidCompatibilitySupported() {
3269 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3270 }
3271
Hall Liu98187582018-01-22 19:15:32 -08003272 public boolean isRttSupported() {
3273 boolean isCarrierSupported =
3274 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3275 boolean isDeviceSupported =
3276 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3277 return isCarrierSupported && isDeviceSupported;
3278 }
3279
Sanket Padawe7310cc72015-01-14 09:53:20 -08003280 /**
3281 * Returns the unique device ID of phone, for example, the IMEI for
3282 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3283 *
3284 * <p>Requires Permission:
3285 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3286 */
3287 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003288 public String getDeviceId(String callingPackage) {
3289 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3290 return null;
3291 }
3292
Sanket Padawe7310cc72015-01-14 09:53:20 -08003293 final Phone phone = PhoneFactory.getPhone(0);
3294 if (phone != null) {
3295 return phone.getDeviceId();
3296 } else {
3297 return null;
3298 }
3299 }
3300
Ping Sunc67b7c22016-03-02 19:16:45 +08003301 /**
3302 * {@hide}
3303 * Returns the IMS Registration Status on a particular subid
3304 *
3305 * @param subId
3306 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003307 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08003308 Phone phone = getPhone(subId);
3309 if (phone != null) {
3310 return phone.isImsRegistered();
3311 } else {
3312 return false;
3313 }
3314 }
3315
Santos Cordon7a1885b2015-02-03 11:15:19 -08003316 @Override
3317 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3318 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3319 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003320
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003321 /**
3322 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003323 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003324 public boolean isWifiCallingAvailable(int subId) {
3325 Phone phone = getPhone(subId);
3326 if (phone != null) {
3327 return phone.isWifiCallingEnabled();
3328 } else {
3329 return false;
3330 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003331 }
3332
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003333 /**
3334 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003335 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003336 public boolean isVolteAvailable(int subId) {
3337 Phone phone = getPhone(subId);
3338 if (phone != null) {
3339 return phone.isVolteEnabled();
3340 } else {
3341 return false;
3342 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003343 }
Svet Ganovb320e182015-04-16 12:30:10 -07003344
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003345 /**
3346 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003347 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08003348 public boolean isVideoTelephonyAvailable(int subId) {
3349 Phone phone = getPhone(subId);
3350 if (phone != null) {
3351 return phone.isVideoEnabled();
3352 } else {
3353 return false;
3354 }
3355 }
3356
3357 /**
3358 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3359 * defined in {@link ImsRegistrationImplBase}.
3360 */
3361 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3362 Phone phone = getPhone(subId);
3363 if (phone != null) {
3364 return phone.getImsRegistrationTech();
3365 } else {
3366 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3367 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003368 }
3369
Svet Ganovb320e182015-04-16 12:30:10 -07003370 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003371 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003372 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003373 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3374
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003375 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003376 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003377 } catch (SecurityException e) {
3378 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3379 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003380 }
Svet Ganovb320e182015-04-16 12:30:10 -07003381
3382 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3383 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3384 return false;
3385 }
3386
3387 return true;
3388 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003389
Makoto Onukifee69342015-06-29 14:44:50 -07003390 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003391 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003392 */
3393 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003394 // Default SMS app can always read it.
3395 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3396 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3397 return true;
3398 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003399
Makoto Onukie4072d12015-08-03 15:12:23 -07003400 try {
3401 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003402 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003403 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003404 // Can be read with READ_SMS too.
3405 try {
3406 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3407 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3408 if (opCode != AppOpsManager.OP_NONE) {
3409 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3410 == AppOpsManager.MODE_ALLOWED;
3411 } else {
3412 return true;
3413 }
3414 } catch (SecurityException readSmsSecurityException) {
3415 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003416 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003417 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003418 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003419 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003420 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003421 if (opCode != AppOpsManager.OP_NONE) {
3422 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3423 == AppOpsManager.MODE_ALLOWED;
3424 } else {
3425 return true;
3426 }
3427 } catch (SecurityException readPhoneNumberSecurityException) {
3428 }
3429
3430 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3431 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3432 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003433 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003434 }
3435
Stuart Scott8eef64f2015-04-08 15:13:54 -07003436 @Override
3437 public void factoryReset(int subId) {
3438 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003439 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3440 return;
3441 }
3442
Svet Ganovcc087f82015-05-12 20:35:54 -07003443 final long identity = Binder.clearCallingIdentity();
3444 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003445 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3446 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003447 // Enable data
Malcolm Chen964682d2017-11-28 16:20:07 -08003448 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003449 // Set network selection mode to automatic
3450 setNetworkSelectionModeAutomatic(subId);
3451 // Set preferred mobile network type to the best available
3452 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3453 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003454 mPhone.setDataRoamingEnabled(false);
pkanwar79ec0542017-07-31 14:10:01 -07003455 // Remove IMSI encryption keys from Carrier DB.
3456 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mPhone.getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07003457 }
3458 } finally {
3459 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003460 }
3461 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003462
3463 @Override
3464 public String getLocaleFromDefaultSim() {
3465 // We query all subscriptions instead of just the active ones, because
3466 // this might be called early on in the provisioning flow when the
3467 // subscriptions potentially aren't active yet.
3468 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3469 if (slist == null || slist.isEmpty()) {
3470 return null;
3471 }
3472
3473 // This function may be called very early, say, from the setup wizard, at
3474 // which point we won't have a default subscription set. If that's the case
3475 // we just choose the first, which will be valid in "most cases".
3476 final int defaultSubId = getDefaultSubscription();
3477 SubscriptionInfo info = null;
3478 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3479 info = slist.get(0);
3480 } else {
3481 for (SubscriptionInfo item : slist) {
3482 if (item.getSubscriptionId() == defaultSubId) {
3483 info = item;
3484 break;
3485 }
3486 }
3487
3488 if (info == null) {
3489 return null;
3490 }
3491 }
3492
3493 // Try and fetch the locale from the carrier properties or from the SIM language
3494 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003495 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003496 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003497 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003498 if (defaultPhone != null) {
3499 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3500 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003501 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003502 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3503 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003504 } else {
3505 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003506 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003507 }
3508 }
3509
Narayan Kamath011676f2015-07-29 12:04:08 +01003510 // The SIM language preferences only store a language (e.g. fr = French), not an
3511 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3512 // the SIM and carrier preferences does not include a country we add the country
3513 // determined from the SIM MCC to provide an exact locale.
3514 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003515 if (mccLocale != null) {
3516 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3517 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003518 }
3519
Tony Hill183b2de2015-06-24 14:53:58 +01003520 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003521 return null;
3522 }
3523
3524 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3525 final long identity = Binder.clearCallingIdentity();
3526 try {
3527 return mSubscriptionController.getAllSubInfoList(
3528 mPhone.getContext().getOpPackageName());
3529 } finally {
3530 Binder.restoreCallingIdentity(identity);
3531 }
3532 }
3533
3534 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 return mSubscriptionController.getActiveSubscriptionInfoList(
3538 mPhone.getContext().getOpPackageName());
3539 } finally {
3540 Binder.restoreCallingIdentity(identity);
3541 }
3542 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003543
Chenjie Yu1ba97252018-01-11 18:16:20 -08003544 private final ModemActivityInfo mLastModemActivityInfo =
3545 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
3546
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003547 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003548 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3549 * representing the state of the modem.
3550 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08003551 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
3552 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07003553 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003554 */
3555 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003556 public void requestModemActivityInfo(ResultReceiver result) {
3557 enforceModifyPermission();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003558 ModemActivityInfo ret = null;
3559 synchronized (mLastModemActivityInfo) {
3560 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO,
3561 null);
3562 if (info != null) {
3563 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
3564 for (int i = 0; i < mergedTxTimeMs.length; i++) {
3565 mergedTxTimeMs[i] =
3566 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
3567 }
3568 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
3569 mLastModemActivityInfo.setSleepTimeMillis(
3570 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
3571 mLastModemActivityInfo.setIdleTimeMillis(
3572 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
3573 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
3574 mLastModemActivityInfo.setRxTimeMillis(
3575 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
3576 mLastModemActivityInfo.setEnergyUsed(
3577 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
3578 }
3579 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
3580 mLastModemActivityInfo.getSleepTimeMillis(),
3581 mLastModemActivityInfo.getIdleTimeMillis(),
3582 mLastModemActivityInfo.getTxTimeMillis(),
3583 mLastModemActivityInfo.getRxTimeMillis(),
3584 mLastModemActivityInfo.getEnergyUsed());
3585 }
Adam Lesinski903a54c2016-04-11 14:49:52 -07003586 Bundle bundle = new Bundle();
Chenjie Yu1ba97252018-01-11 18:16:20 -08003587 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
Adam Lesinski903a54c2016-04-11 14:49:52 -07003588 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003589 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003590
3591 /**
3592 * {@hide}
3593 * Returns the service state information on specified subscription.
3594 */
3595 @Override
3596 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3597
3598 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3599 return null;
3600 }
3601
3602 final Phone phone = getPhone(subId);
3603 if (phone == null) {
3604 return null;
3605 }
3606
3607 return phone.getServiceState();
3608 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003609
3610 /**
3611 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3612 *
3613 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3614 * voicemail ringtone.
3615 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3616 * PhoneAccount.
3617 */
3618 @Override
3619 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003620 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003621 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003622 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003623 }
3624
fionaxu7ed723d2017-05-30 18:58:54 -07003625 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003626 }
3627
3628 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003629 * Sets the per-account voicemail ringtone.
3630 *
3631 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3632 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3633 *
3634 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3635 * voicemail ringtone.
3636 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3637 * PhoneAccount.
3638 */
3639 @Override
3640 public void setVoicemailRingtoneUri(String callingPackage,
3641 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3642 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3643 if (!TextUtils.equals(callingPackage,
3644 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3645 enforceModifyPermissionOrCarrierPrivilege(
3646 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3647 }
3648 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3649 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003650 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003651 }
fionaxu7ed723d2017-05-30 18:58:54 -07003652 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003653 }
3654
3655 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003656 * Returns whether vibration is set for voicemail notification in Phone settings.
3657 *
3658 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3659 * voicemail vibration setting.
3660 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3661 */
3662 @Override
3663 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003664 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003665 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003666 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003667 }
3668
fionaxu7ed723d2017-05-30 18:58:54 -07003669 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003670 }
3671
Youhan Wange64578a2016-05-02 15:32:42 -07003672 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003673 * Sets the per-account voicemail vibration.
3674 *
3675 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3676 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3677 *
3678 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3679 * voicemail vibration setting.
3680 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3681 * specific PhoneAccount.
3682 */
3683 @Override
3684 public void setVoicemailVibrationEnabled(String callingPackage,
3685 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3686 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3687 if (!TextUtils.equals(callingPackage,
3688 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3689 enforceModifyPermissionOrCarrierPrivilege(
3690 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3691 }
3692
3693 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3694 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003695 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003696 }
fionaxu7ed723d2017-05-30 18:58:54 -07003697 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003698 }
3699
3700 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003701 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3702 *
3703 * @throws SecurityException if the caller does not have the required permission
3704 */
3705 private void enforceReadPrivilegedPermission() {
3706 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3707 null);
3708 }
3709
3710 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003711 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3712 * permission.
3713 *
3714 * @throws SecurityException if the caller does not have the required permission
3715 */
3716 private void enforceSendSmsPermission() {
3717 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3718 }
3719
3720 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003721 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003722 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003723 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003724 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003725 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003726 ComponentName componentName =
3727 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3728 if(componentName == null) {
3729 throw new SecurityException("Caller not current active visual voicemail package[null]");
3730 }
3731 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003732 if (!callingPackage.equals(vvmPackage)) {
3733 throw new SecurityException("Caller not current active visual voicemail package[" +
3734 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003735 }
3736 }
3737
3738 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003739 * Return the application ID for the app type.
3740 *
3741 * @param subId the subscription ID that this request applies to.
3742 * @param appType the uicc app type.
3743 * @return Application ID for specificied app type, or null if no uicc.
3744 */
3745 @Override
3746 public String getAidForAppType(int subId, int appType) {
3747 enforceReadPrivilegedPermission();
3748 Phone phone = getPhone(subId);
3749 if (phone == null) {
3750 return null;
3751 }
3752 String aid = null;
3753 try {
3754 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3755 .getApplicationByType(appType).getAid();
3756 } catch (Exception e) {
3757 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3758 }
3759 return aid;
3760 }
3761
Youhan Wang4001d252016-05-11 10:29:41 -07003762 /**
3763 * Return the Electronic Serial Number.
3764 *
3765 * @param subId the subscription ID that this request applies to.
3766 * @return ESN or null if error.
3767 */
3768 @Override
3769 public String getEsn(int subId) {
3770 enforceReadPrivilegedPermission();
3771 Phone phone = getPhone(subId);
3772 if (phone == null) {
3773 return null;
3774 }
3775 String esn = null;
3776 try {
3777 esn = phone.getEsn();
3778 } catch (Exception e) {
3779 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3780 }
3781 return esn;
3782 }
3783
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003784 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003785 * Return the Preferred Roaming List Version.
3786 *
3787 * @param subId the subscription ID that this request applies to.
3788 * @return PRLVersion or null if error.
3789 */
3790 @Override
3791 public String getCdmaPrlVersion(int subId) {
3792 enforceReadPrivilegedPermission();
3793 Phone phone = getPhone(subId);
3794 if (phone == null) {
3795 return null;
3796 }
3797 String cdmaPrlVersion = null;
3798 try {
3799 cdmaPrlVersion = phone.getCdmaPrlVersion();
3800 } catch (Exception e) {
3801 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3802 }
3803 return cdmaPrlVersion;
3804 }
3805
3806 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003807 * Get snapshot of Telephony histograms
3808 * @return List of Telephony histograms
3809 * @hide
3810 */
3811 @Override
3812 public List<TelephonyHistogram> getTelephonyHistograms() {
3813 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3814 return RIL.getTelephonyRILTimingHistograms();
3815 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003816
3817 /**
3818 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003819 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003820 * Require system privileges. In the future we may add this to carrier APIs.
3821 *
3822 * @return The number of carriers set successfully, should match length of carriers
3823 */
3824 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003825 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003826 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003827
Meng Wang9b7c4e92017-02-17 11:41:27 -08003828 if (carriers == null) {
3829 throw new NullPointerException("carriers cannot be null");
3830 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003831
3832 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003833 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3834 return retVal[0];
3835 }
3836
3837 /**
3838 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003839 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003840 * Require system privileges. In the future we may add this to carrier APIs.
3841 *
3842 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3843 * means all carriers are allowed.
3844 */
3845 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003846 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003847 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003848 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003849 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3850 }
3851
fionaxu59545b42016-05-25 15:53:37 -07003852 /**
3853 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3854 * @param subId the subscription ID that this action applies to.
3855 * @param enabled control enable or disable metered apns.
3856 * {@hide}
3857 */
3858 @Override
3859 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3860 enforceModifyPermission();
3861 final Phone phone = getPhone(subId);
3862 if (phone == null) {
3863 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3864 return;
3865 }
3866 try {
3867 phone.carrierActionSetMeteredApnsEnabled(enabled);
3868 } catch (Exception e) {
3869 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3870 }
3871 }
3872
3873 /**
3874 * Action set from carrier signalling broadcast receivers to enable/disable radio
3875 * @param subId the subscription ID that this action applies to.
3876 * @param enabled control enable or disable radio.
3877 * {@hide}
3878 */
3879 @Override
3880 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3881 enforceModifyPermission();
3882 final Phone phone = getPhone(subId);
3883 if (phone == null) {
3884 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3885 return;
3886 }
3887 try {
3888 phone.carrierActionSetRadioEnabled(enabled);
3889 } catch (Exception e) {
3890 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3891 }
3892 }
3893
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003894 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003895 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3896 * network status based on which carrier apps could apply actions accordingly,
3897 * enable/disable default url handler for example.
3898 *
3899 * @param subId the subscription ID that this action applies to.
3900 * @param report control start/stop reporting the default network status.
3901 * {@hide}
3902 */
3903 @Override
3904 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3905 enforceModifyPermission();
3906 final Phone phone = getPhone(subId);
3907 if (phone == null) {
3908 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3909 return;
3910 }
3911 try {
3912 phone.carrierActionReportDefaultNetworkStatus(report);
3913 } catch (Exception e) {
3914 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3915 }
3916 }
3917
3918 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003919 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3920 * bug report is being generated.
3921 */
3922 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003923 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003924 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3925 != PackageManager.PERMISSION_GRANTED) {
3926 writer.println("Permission Denial: can't dump Phone from pid="
3927 + Binder.getCallingPid()
3928 + ", uid=" + Binder.getCallingUid()
3929 + "without permission "
3930 + android.Manifest.permission.DUMP);
3931 return;
3932 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003933 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003934 }
Jack Yueb89b242016-06-22 13:27:47 -07003935
3936 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003937 * Get aggregated video call data usage since boot.
3938 *
3939 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3940 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003941 * {@hide}
3942 */
3943 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003944 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003945 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3946 null);
3947
Jack Yu84291ec2017-05-26 16:07:50 -07003948 // NetworkStatsService keeps tracking the active network interface and identity. It
3949 // records the delta with the corresponding network identity. We just return the total video
3950 // call data usage snapshot since boot.
3951 Phone phone = getPhone(subId);
3952 if (phone != null) {
3953 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003954 }
Jack Yu84291ec2017-05-26 16:07:50 -07003955 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003956 }
Jack Yu75ab2952016-07-08 14:29:33 -07003957
3958 /**
3959 * Policy control of data connection. Usually used when data limit is passed.
3960 * @param enabled True if enabling the data, otherwise disabling.
3961 * @param subId Subscription index
3962 * {@hide}
3963 */
3964 @Override
3965 public void setPolicyDataEnabled(boolean enabled, int subId) {
3966 enforceModifyPermission();
3967 Phone phone = getPhone(subId);
3968 if (phone != null) {
3969 phone.setPolicyDataEnabled(enabled);
3970 }
3971 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003972
3973 /**
3974 * Get Client request stats
3975 * @return List of Client Request Stats
3976 * @hide
3977 */
3978 @Override
3979 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3980 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3981 return null;
3982 }
3983
3984 Phone phone = getPhone(subId);
3985 if (phone != null) {
3986 return phone.getClientRequestStats();
3987 }
3988
3989 return null;
3990 }
3991
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003992 private WorkSource getWorkSource(int uid) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003993 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00003994 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003995 }
Jack Yueb4124c2017-02-16 15:32:43 -08003996
3997 /**
Grace Chen70990072017-03-24 17:21:30 -07003998 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003999 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004000 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07004001 * @param state State of SIM (power down, power up, pass through)
4002 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
4003 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
4004 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08004005 *
4006 **/
4007 @Override
Grace Chen70990072017-03-24 17:21:30 -07004008 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004009 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004010 Phone phone = PhoneFactory.getPhone(slotIndex);
4011
Jack Yueb4124c2017-02-16 15:32:43 -08004012 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004013 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004014 }
4015 }
Shuo Qiandd210312017-04-12 22:11:33 +00004016
Tyler Gunn65d45c22017-06-05 11:22:26 -07004017 private boolean isUssdApiAllowed(int subId) {
4018 CarrierConfigManager configManager =
4019 (CarrierConfigManager) mPhone.getContext().getSystemService(
4020 Context.CARRIER_CONFIG_SERVICE);
4021 if (configManager == null) {
4022 return false;
4023 }
4024 PersistableBundle pb = configManager.getConfigForSubId(subId);
4025 if (pb == null) {
4026 return false;
4027 }
4028 return pb.getBoolean(
4029 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4030 }
4031
Shuo Qiandd210312017-04-12 22:11:33 +00004032 /**
4033 * Check if phone is in emergency callback mode
4034 * @return true if phone is in emergency callback mode
4035 * @param subId sub id
4036 */
goneil9c5f4872017-12-05 14:07:56 -08004037 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00004038 public boolean getEmergencyCallbackMode(int subId) {
goneil9c5f4872017-12-05 14:07:56 -08004039 enforceReadPrivilegedPermission();
Shuo Qiandd210312017-04-12 22:11:33 +00004040 final Phone phone = getPhone(subId);
4041 if (phone != null) {
4042 return phone.isInEcm();
4043 } else {
4044 return false;
4045 }
4046 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004047
4048 /**
4049 * Get the current signal strength information for the given subscription.
4050 * Because this information is not updated when the device is in a low power state
4051 * it should not be relied-upon to be current.
4052 * @param subId Subscription index
4053 * @return the most recent cached signal strength info from the modem
4054 */
4055 @Override
4056 public SignalStrength getSignalStrength(int subId) {
4057 Phone p = getPhone(subId);
4058 if (p == null) {
4059 return null;
4060 }
4061
4062 return p.getSignalStrength();
4063 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004064
4065 @Override
4066 public UiccSlotInfo[] getUiccSlotsInfo() {
4067 enforceReadPrivilegedPermission();
4068
4069 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4070 if (slots == null) return null;
4071 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4072 for (int i = 0; i < slots.length; i++) {
4073 UiccSlot slot = slots[i];
4074
4075 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4076
4077 int cardState = 0;
4078 switch (slot.getCardState()) {
4079 case CARDSTATE_ABSENT:
4080 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4081 break;
4082 case CARDSTATE_PRESENT:
4083 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4084 break;
4085 case CARDSTATE_ERROR:
4086 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4087 break;
4088 case CARDSTATE_RESTRICTED:
4089 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4090 break;
4091 default:
4092 break;
4093
4094 }
4095
Qingxi Li795c5882018-01-31 13:43:27 -08004096 infos[i] = new UiccSlotInfo(
4097 slot.isActive(), slot.isEuicc(), cardId, cardState, slot.getPhoneId());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004098 }
4099 return infos;
4100 }
4101
4102 @Override
4103 public boolean switchSlots(int[] physicalSlots) {
4104 enforceModifyPermission();
4105 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4106 }
Jack Yu4c988042018-02-27 15:30:01 -08004107
4108 @Override
4109 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4110 enforceModifyPermission();
4111 final Phone phone = getPhone(subId);
4112 if (phone == null) {
4113 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4114 return;
4115 }
4116
4117 phone.setRadioIndicationUpdateMode(filters, mode);
4118 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004119}