blob: 58e2ad63f18cd2bfd54b314dcfc68173bdd92247 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Ta-wei Yen87c49842016-05-13 21:19:52 -070019import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
20
Ta-wei Yen30a69c82016-12-27 14:52:32 -080021import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070022import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070024import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.content.Context;
26import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070027import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070028import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080029import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070030import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070031import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.net.Uri;
33import android.os.AsyncResult;
34import android.os.Binder;
35import android.os.Bundle;
36import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070037import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.os.Looper;
39import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070040import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070041import android.os.PersistableBundle;
Brad Ebinger7e934f52017-12-14 14:26:15 -080042import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070043import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.ServiceManager;
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 Ebingera12246d2018-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 Ebingere21f25f2018-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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070080import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080082import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080083
Andrew Lee312e8172014-10-23 17:01:36 -070084import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080085import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070086import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070087import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070088import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070089import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080092import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010093import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070094import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070095import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070096import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080097import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070098import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -070099import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700100import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700101import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700102import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800103import com.android.internal.telephony.SubscriptionController;
Jonathan Basseri03923952017-07-19 12:22:35 -0700104import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700105import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700106import com.android.internal.telephony.uicc.IccIoResult;
107import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800108import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700109import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800110import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700111import com.android.internal.telephony.uicc.UiccController;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000112import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700113import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800114import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700115import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800116import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700117import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700118import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800119
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700120import java.io.FileDescriptor;
121import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800122import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800124import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800125import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100126import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800127import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128
129/**
130 * Implementation of the ITelephony interface.
131 */
Santos Cordon117fee72014-05-16 17:56:12 -0700132public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133 private static final String LOG_TAG = "PhoneInterfaceManager";
134 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
135 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800136 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137
138 // Message codes used with mMainThreadHandler
139 private static final int CMD_HANDLE_PIN_MMI = 1;
140 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
141 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
142 private static final int CMD_ANSWER_RINGING_CALL = 4;
143 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700144 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
145 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700146 private static final int CMD_OPEN_CHANNEL = 9;
147 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
148 private static final int CMD_CLOSE_CHANNEL = 11;
149 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800150 private static final int CMD_NV_READ_ITEM = 13;
151 private static final int EVENT_NV_READ_ITEM_DONE = 14;
152 private static final int CMD_NV_WRITE_ITEM = 15;
153 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
154 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
155 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
156 private static final int CMD_NV_RESET_CONFIG = 19;
157 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800158 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
159 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
160 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
161 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800162 private static final int CMD_SEND_ENVELOPE = 25;
163 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700164 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
165 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
166 private static final int CMD_EXCHANGE_SIM_IO = 31;
167 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800168 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
169 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700170 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
171 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700172 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
173 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700174 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
175 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
176 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
177 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700178 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
179 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
180 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
181 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700182 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800183 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
184 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000185 private static final int CMD_SWITCH_SLOTS = 50;
186 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800188 // Parameters of select command.
189 private static final int SELECT_COMMAND = 0xA4;
190 private static final int SELECT_P1 = 0x04;
191 private static final int SELECT_P2 = 0;
192 private static final int SELECT_P3 = 0x10;
193
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 /** The singleton instance. */
195 private static PhoneInterfaceManager sInstance;
196
Wink Saville3ab207e2014-11-20 13:07:20 -0800197 private PhoneGlobals mApp;
198 private Phone mPhone;
199 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700200 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800201 private AppOpsManager mAppOps;
202 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800203 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800204 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205
Derek Tan97ebb422014-09-05 16:55:38 -0700206 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
207 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800208 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700209
Derek Tan740e1672017-06-27 14:56:27 -0700210 // The AID of ISD-R.
211 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
212
yinxub1bed742017-04-17 11:45:04 -0700213 private NetworkScanRequestTracker mNetworkScanRequestTracker;
214
Derek Tan89e89d42014-07-08 17:00:10 -0700215 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700216 * A request object to use for transmitting data to an ICC.
217 */
218 private static final class IccAPDUArgument {
219 public int channel, cla, command, p1, p2, p3;
220 public String data;
221
222 public IccAPDUArgument(int channel, int cla, int command,
223 int p1, int p2, int p3, String data) {
224 this.channel = channel;
225 this.cla = cla;
226 this.command = command;
227 this.p1 = p1;
228 this.p2 = p2;
229 this.p3 = p3;
230 this.data = data;
231 }
232 }
233
234 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700235 * A request object to use for transmitting data to an ICC.
236 */
237 private static final class ManualNetworkSelectionArgument {
238 public OperatorInfo operatorInfo;
239 public boolean persistSelection;
240
241 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
242 this.operatorInfo = operatorInfo;
243 this.persistSelection = persistSelection;
244 }
245 }
246
247 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700248 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
249 * request after sending. The main thread will notify the request when it is complete.
250 */
251 private static final class MainThreadRequest {
252 /** The argument to use for the request */
253 public Object argument;
254 /** The result of the request that is run on the main thread */
255 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800256 // The subscriber id that this request applies to. Defaults to
257 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
258 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700259
260 public MainThreadRequest(Object argument) {
261 this.argument = argument;
262 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800263
264 public MainThreadRequest(Object argument, Integer subId) {
265 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800266 if (subId != null) {
267 this.subId = subId;
268 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270 }
271
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800272 private static final class IncomingThirdPartyCallArgs {
273 public final ComponentName component;
274 public final String callId;
275 public final String callerDisplayName;
276
277 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
278 String callerDisplayName) {
279 this.component = component;
280 this.callId = callId;
281 this.callerDisplayName = callerDisplayName;
282 }
283 }
284
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700285 /**
286 * A handler that processes messages on the main thread in the phone process. Since many
287 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
288 * inbound binder threads to the main thread in the phone process. The Binder thread
289 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
290 * on, which will be notified when the operation completes and will contain the result of the
291 * request.
292 *
293 * <p>If a MainThreadRequest object is provided in the msg.obj field,
294 * note that request.result must be set to something non-null for the calling thread to
295 * unblock.
296 */
297 private final class MainThreadHandler extends Handler {
298 @Override
299 public void handleMessage(Message msg) {
300 MainThreadRequest request;
301 Message onCompleted;
302 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800303 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700304 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700305
306 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700307 case CMD_HANDLE_USSD_REQUEST: {
308 request = (MainThreadRequest) msg.obj;
309 final Phone phone = getPhoneFromRequest(request);
310 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
311 String ussdRequest = ussdObject.first;
312 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700313
314 if (!isUssdApiAllowed(request.subId)) {
315 // Carrier does not support use of this API, return failure.
316 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
317 UssdResponse response = new UssdResponse(ussdRequest, null);
318 Bundle returnData = new Bundle();
319 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
320 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
321
322 request.result = true;
323 synchronized (request) {
324 request.notifyAll();
325 }
326 return;
327 }
328
Tyler Gunn52dcf772017-04-26 11:30:31 -0700329 try {
330 request.result = phone != null ?
331 phone.handleUssdRequest(ussdRequest, wrappedCallback)
332 : false;
333 } catch (CallStateException cse) {
334 request.result = false;
335 }
pkanwar32d516d2016-10-14 19:37:38 -0700336 // Wake up the requesting thread
337 synchronized (request) {
338 request.notifyAll();
339 }
340 break;
341 }
342
Yorke Lee716f67e2015-06-17 15:39:16 -0700343 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700345 final Phone phone = getPhoneFromRequest(request);
346 request.result = phone != null ?
347 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
348 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 // Wake up the requesting thread
350 synchronized (request) {
351 request.notifyAll();
352 }
353 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700354 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355
356 case CMD_HANDLE_NEIGHBORING_CELL:
357 request = (MainThreadRequest) msg.obj;
358 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
359 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700360 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700361 break;
362
363 case EVENT_NEIGHBORING_CELL_DONE:
364 ar = (AsyncResult) msg.obj;
365 request = (MainThreadRequest) ar.userObj;
366 if (ar.exception == null && ar.result != null) {
367 request.result = ar.result;
368 } else {
369 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800370 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 }
372 // Wake up the requesting thread
373 synchronized (request) {
374 request.notifyAll();
375 }
376 break;
377
378 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700379 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800380 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700381 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 break;
383
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 case CMD_END_CALL:
385 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800386 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700387 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700388 Phone phone = getPhone(end_subId);
389 if (phone == null) {
390 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
391 break;
392 }
393 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
395 // CDMA: If the user presses the Power button we treat it as
396 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700397 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
399 // GSM: End the call as per the Phone state
400 hungUp = PhoneUtils.hangup(mCM);
401 } else {
402 throw new IllegalStateException("Unexpected phone type: " + phoneType);
403 }
404 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
405 request.result = hungUp;
406 // Wake up the requesting thread
407 synchronized (request) {
408 request.notifyAll();
409 }
410 break;
411
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700413 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700414 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800415 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700416 if (uiccCard == null) {
417 loge("iccTransmitApduLogicalChannel: No UICC");
418 request.result = new IccIoResult(0x6F, 0, (byte[])null);
419 synchronized (request) {
420 request.notifyAll();
421 }
422 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700423 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
424 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700425 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700426 iccArgument.channel, iccArgument.cla, iccArgument.command,
427 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700428 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700429 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700430 break;
431
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700432 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 ar = (AsyncResult) msg.obj;
434 request = (MainThreadRequest) ar.userObj;
435 if (ar.exception == null && ar.result != null) {
436 request.result = ar.result;
437 } else {
438 request.result = new IccIoResult(0x6F, 0, (byte[])null);
439 if (ar.result == null) {
440 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800441 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700442 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800443 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700444 } else {
445 loge("iccTransmitApduLogicalChannel: Unknown exception");
446 }
447 }
448 synchronized (request) {
449 request.notifyAll();
450 }
451 break;
452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
454 request = (MainThreadRequest) msg.obj;
455 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800456 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 if (uiccCard == null) {
458 loge("iccTransmitApduBasicChannel: No UICC");
459 request.result = new IccIoResult(0x6F, 0, (byte[])null);
460 synchronized (request) {
461 request.notifyAll();
462 }
463 } else {
464 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
465 request);
466 uiccCard.iccTransmitApduBasicChannel(
467 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
468 iccArgument.p3, iccArgument.data, onCompleted);
469 }
470 break;
471
472 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
473 ar = (AsyncResult) msg.obj;
474 request = (MainThreadRequest) ar.userObj;
475 if (ar.exception == null && ar.result != null) {
476 request.result = ar.result;
477 } else {
478 request.result = new IccIoResult(0x6F, 0, (byte[])null);
479 if (ar.result == null) {
480 loge("iccTransmitApduBasicChannel: Empty response");
481 } else if (ar.exception instanceof CommandException) {
482 loge("iccTransmitApduBasicChannel: CommandException: " +
483 ar.exception);
484 } else {
485 loge("iccTransmitApduBasicChannel: Unknown exception");
486 }
487 }
488 synchronized (request) {
489 request.notifyAll();
490 }
491 break;
492
493 case CMD_EXCHANGE_SIM_IO:
494 request = (MainThreadRequest) msg.obj;
495 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800496 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 if (uiccCard == null) {
498 loge("iccExchangeSimIO: No UICC");
499 request.result = new IccIoResult(0x6F, 0, (byte[])null);
500 synchronized (request) {
501 request.notifyAll();
502 }
503 } else {
504 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
505 request);
506 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
507 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
508 iccArgument.data, onCompleted);
509 }
510 break;
511
512 case EVENT_EXCHANGE_SIM_IO_DONE:
513 ar = (AsyncResult) msg.obj;
514 request = (MainThreadRequest) ar.userObj;
515 if (ar.exception == null && ar.result != null) {
516 request.result = ar.result;
517 } else {
518 request.result = new IccIoResult(0x6f, 0, (byte[])null);
519 }
520 synchronized (request) {
521 request.notifyAll();
522 }
523 break;
524
Derek Tan4d5e5c12014-02-04 11:54:58 -0800525 case CMD_SEND_ENVELOPE:
526 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800527 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700528 if (uiccCard == null) {
529 loge("sendEnvelopeWithStatus: No UICC");
530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
531 synchronized (request) {
532 request.notifyAll();
533 }
534 } else {
535 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
536 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
537 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800538 break;
539
540 case EVENT_SEND_ENVELOPE_DONE:
541 ar = (AsyncResult) msg.obj;
542 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700543 if (ar.exception == null && ar.result != null) {
544 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800545 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700546 request.result = new IccIoResult(0x6F, 0, (byte[])null);
547 if (ar.result == null) {
548 loge("sendEnvelopeWithStatus: Empty response");
549 } else if (ar.exception instanceof CommandException) {
550 loge("sendEnvelopeWithStatus: CommandException: " +
551 ar.exception);
552 } else {
553 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
554 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800555 }
556 synchronized (request) {
557 request.notifyAll();
558 }
559 break;
560
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 case CMD_OPEN_CHANNEL:
562 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800564 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700565 if (uiccCard == null) {
566 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800567 request.result = new IccOpenLogicalChannelResponse(-1,
568 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 synchronized (request) {
570 request.notifyAll();
571 }
572 } else {
573 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800574 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
575 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700576 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700577 break;
578
579 case EVENT_OPEN_CHANNEL_DONE:
580 ar = (AsyncResult) msg.obj;
581 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700582 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700583 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 int[] result = (int[]) ar.result;
585 int channelId = result[0];
586 byte[] selectResponse = null;
587 if (result.length > 1) {
588 selectResponse = new byte[result.length - 1];
589 for (int i = 1; i < result.length; ++i) {
590 selectResponse[i - 1] = (byte) result[i];
591 }
592 }
593 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700594 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 if (ar.result == null) {
597 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 if (ar.exception != null) {
600 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
601 }
602
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700603 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700604 if (ar.exception instanceof CommandException) {
605 CommandException.Error error =
606 ((CommandException) (ar.exception)).getCommandError();
607 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700608 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700609 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 }
612 }
613 openChannelResp = new IccOpenLogicalChannelResponse(
614 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700616 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 synchronized (request) {
618 request.notifyAll();
619 }
620 break;
621
622 case CMD_CLOSE_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800624 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700625 if (uiccCard == null) {
626 loge("iccCloseLogicalChannel: No UICC");
627 request.result = new IccIoResult(0x6F, 0, (byte[])null);
628 synchronized (request) {
629 request.notifyAll();
630 }
631 } else {
632 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
633 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
634 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 break;
636
637 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800638 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
639 break;
640
641 case CMD_NV_READ_ITEM:
642 request = (MainThreadRequest) msg.obj;
643 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
644 mPhone.nvReadItem((Integer) request.argument, onCompleted);
645 break;
646
647 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 ar = (AsyncResult) msg.obj;
649 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800650 if (ar.exception == null && ar.result != null) {
651 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800653 request.result = "";
654 if (ar.result == null) {
655 loge("nvReadItem: Empty response");
656 } else if (ar.exception instanceof CommandException) {
657 loge("nvReadItem: CommandException: " +
658 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800660 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 }
662 }
663 synchronized (request) {
664 request.notifyAll();
665 }
666 break;
667
Jake Hambye994d462014-02-03 13:10:13 -0800668 case CMD_NV_WRITE_ITEM:
669 request = (MainThreadRequest) msg.obj;
670 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
671 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
672 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
673 break;
674
675 case EVENT_NV_WRITE_ITEM_DONE:
676 handleNullReturnEvent(msg, "nvWriteItem");
677 break;
678
679 case CMD_NV_WRITE_CDMA_PRL:
680 request = (MainThreadRequest) msg.obj;
681 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
682 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
683 break;
684
685 case EVENT_NV_WRITE_CDMA_PRL_DONE:
686 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
687 break;
688
689 case CMD_NV_RESET_CONFIG:
690 request = (MainThreadRequest) msg.obj;
691 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
692 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
693 break;
694
695 case EVENT_NV_RESET_CONFIG_DONE:
696 handleNullReturnEvent(msg, "nvResetConfig");
697 break;
698
Jake Hamby7c27be32014-03-03 13:25:59 -0800699 case CMD_GET_PREFERRED_NETWORK_TYPE:
700 request = (MainThreadRequest) msg.obj;
701 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700702 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800703 break;
704
705 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
706 ar = (AsyncResult) msg.obj;
707 request = (MainThreadRequest) ar.userObj;
708 if (ar.exception == null && ar.result != null) {
709 request.result = ar.result; // Integer
710 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800711 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800712 if (ar.result == null) {
713 loge("getPreferredNetworkType: Empty response");
714 } else if (ar.exception instanceof CommandException) {
715 loge("getPreferredNetworkType: CommandException: " +
716 ar.exception);
717 } else {
718 loge("getPreferredNetworkType: Unknown exception");
719 }
720 }
721 synchronized (request) {
722 request.notifyAll();
723 }
724 break;
725
726 case CMD_SET_PREFERRED_NETWORK_TYPE:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
729 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700730 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 break;
732
733 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
734 handleNullReturnEvent(msg, "setPreferredNetworkType");
735 break;
736
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800737 case CMD_SET_VOICEMAIL_NUMBER:
738 request = (MainThreadRequest) msg.obj;
739 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
740 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800741 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
742 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800743 break;
744
745 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
746 handleNullReturnEvent(msg, "setVoicemailNumber");
747 break;
748
Stuart Scott54788802015-03-30 13:18:01 -0700749 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
750 request = (MainThreadRequest) msg.obj;
751 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
752 request);
753 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
754 break;
755
756 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
757 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
758 break;
759
Shishir Agrawal302c8692015-06-19 13:49:39 -0700760 case CMD_PERFORM_NETWORK_SCAN:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
763 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
764 break;
765
766 case EVENT_PERFORM_NETWORK_SCAN_DONE:
767 ar = (AsyncResult) msg.obj;
768 request = (MainThreadRequest) ar.userObj;
769 CellNetworkScanResult cellScanResult;
770 if (ar.exception == null && ar.result != null) {
771 cellScanResult = new CellNetworkScanResult(
772 CellNetworkScanResult.STATUS_SUCCESS,
773 (List<OperatorInfo>) ar.result);
774 } else {
775 if (ar.result == null) {
776 loge("getCellNetworkScanResults: Empty response");
777 }
778 if (ar.exception != null) {
779 loge("getCellNetworkScanResults: Exception: " + ar.exception);
780 }
781 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
782 if (ar.exception instanceof CommandException) {
783 CommandException.Error error =
784 ((CommandException) (ar.exception)).getCommandError();
785 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
786 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
787 } else if (error == CommandException.Error.GENERIC_FAILURE) {
788 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
789 }
790 }
791 cellScanResult = new CellNetworkScanResult(errorCode, null);
792 }
793 request.result = cellScanResult;
794 synchronized (request) {
795 request.notifyAll();
796 }
797 break;
798
799 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
800 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700801 ManualNetworkSelectionArgument selArg =
802 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700803 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
804 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700805 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
806 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700807 break;
808
809 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
810 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
811 break;
812
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700813 case CMD_GET_MODEM_ACTIVITY_INFO:
814 request = (MainThreadRequest) msg.obj;
815 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700816 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700817 break;
818
819 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
820 ar = (AsyncResult) msg.obj;
821 request = (MainThreadRequest) ar.userObj;
822 if (ar.exception == null && ar.result != null) {
823 request.result = ar.result;
824 } else {
825 if (ar.result == null) {
826 loge("queryModemActivityInfo: Empty response");
827 } else if (ar.exception instanceof CommandException) {
828 loge("queryModemActivityInfo: CommandException: " +
829 ar.exception);
830 } else {
831 loge("queryModemActivityInfo: Unknown exception");
832 }
833 }
Amit Mahajand4766222016-01-28 15:28:28 -0800834 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
835 if (request.result == null) {
836 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
837 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700838 synchronized (request) {
839 request.notifyAll();
840 }
841 break;
842
Meng Wang1a7c35a2016-05-05 20:56:15 -0700843 case CMD_SET_ALLOWED_CARRIERS:
844 request = (MainThreadRequest) msg.obj;
845 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
846 mPhone.setAllowedCarriers(
847 (List<CarrierIdentifier>) request.argument,
848 onCompleted);
849 break;
850
851 case EVENT_SET_ALLOWED_CARRIERS_DONE:
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null && ar.result != null) {
855 request.result = ar.result;
856 } else {
857 if (ar.result == null) {
858 loge("setAllowedCarriers: Empty response");
859 } else if (ar.exception instanceof CommandException) {
860 loge("setAllowedCarriers: CommandException: " +
861 ar.exception);
862 } else {
863 loge("setAllowedCarriers: Unknown exception");
864 }
865 }
866 // Result cannot be null. Return -1 on error.
867 if (request.result == null) {
868 request.result = new int[]{-1};
869 }
870 synchronized (request) {
871 request.notifyAll();
872 }
873 break;
874
875 case CMD_GET_ALLOWED_CARRIERS:
876 request = (MainThreadRequest) msg.obj;
877 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
878 mPhone.getAllowedCarriers(onCompleted);
879 break;
880
881 case EVENT_GET_ALLOWED_CARRIERS_DONE:
882 ar = (AsyncResult) msg.obj;
883 request = (MainThreadRequest) ar.userObj;
884 if (ar.exception == null && ar.result != null) {
885 request.result = ar.result;
886 } else {
887 if (ar.result == null) {
888 loge("getAllowedCarriers: Empty response");
889 } else if (ar.exception instanceof CommandException) {
890 loge("getAllowedCarriers: CommandException: " +
891 ar.exception);
892 } else {
893 loge("getAllowedCarriers: Unknown exception");
894 }
895 }
896 // Result cannot be null. Return empty list of CarrierIdentifier.
897 if (request.result == null) {
898 request.result = new ArrayList<CarrierIdentifier>(0);
899 }
900 synchronized (request) {
901 request.notifyAll();
902 }
903 break;
904
Nathan Haroldb3014052017-01-25 15:57:32 -0800905 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
906 ar = (AsyncResult) msg.obj;
907 request = (MainThreadRequest) ar.userObj;
908 if (ar.exception == null && ar.result != null) {
909 request.result = ar.result;
910 } else {
911 request.result = new IllegalArgumentException(
912 "Failed to retrieve Forbidden Plmns");
913 if (ar.result == null) {
914 loge("getForbiddenPlmns: Empty response");
915 } else {
916 loge("getForbiddenPlmns: Unknown exception");
917 }
918 }
919 synchronized (request) {
920 request.notifyAll();
921 }
922 break;
923
924 case CMD_GET_FORBIDDEN_PLMNS:
925 request = (MainThreadRequest) msg.obj;
926 uiccCard = getUiccCardFromRequest(request);
927 if (uiccCard == null) {
928 loge("getForbiddenPlmns() UiccCard is null");
929 request.result = new IllegalArgumentException(
930 "getForbiddenPlmns() UiccCard is null");
931 synchronized (request) {
932 request.notifyAll();
933 }
934 break;
935 }
936 Integer appType = (Integer) request.argument;
937 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
938 if (uiccApp == null) {
939 loge("getForbiddenPlmns() no app with specified type -- "
940 + appType);
941 request.result = new IllegalArgumentException("Failed to get UICC App");
942 synchronized (request) {
943 request.notifyAll();
944 }
945 break;
946 } else {
947 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
948 + " specified type -- " + appType);
949 }
950 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
951 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
952 onCompleted);
953 break;
954
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000955 case CMD_SWITCH_SLOTS:
956 request = (MainThreadRequest) msg.obj;
957 int[] physicalSlots = (int[]) request.argument;
958 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
959 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
960 break;
961
962 case EVENT_SWITCH_SLOTS_DONE:
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 request.result = (ar.exception == null);
966 synchronized (request) {
967 request.notifyAll();
968 }
969 break;
970
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700971 default:
972 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
973 break;
974 }
975 }
Jake Hambye994d462014-02-03 13:10:13 -0800976
977 private void handleNullReturnEvent(Message msg, String command) {
978 AsyncResult ar = (AsyncResult) msg.obj;
979 MainThreadRequest request = (MainThreadRequest) ar.userObj;
980 if (ar.exception == null) {
981 request.result = true;
982 } else {
983 request.result = false;
984 if (ar.exception instanceof CommandException) {
985 loge(command + ": CommandException: " + ar.exception);
986 } else {
987 loge(command + ": Unknown exception");
988 }
989 }
990 synchronized (request) {
991 request.notifyAll();
992 }
993 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700994 }
995
996 /**
997 * Posts the specified command to be executed on the main thread,
998 * waits for the request to complete, and returns the result.
999 * @see #sendRequestAsync
1000 */
1001 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001002 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001003 }
1004
1005 /**
1006 * Posts the specified command to be executed on the main thread,
1007 * waits for the request to complete, and returns the result.
1008 * @see #sendRequestAsync
1009 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001010 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001011 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1012 throw new RuntimeException("This method will deadlock if called from the main thread.");
1013 }
1014
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001015 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001016 Message msg = mMainThreadHandler.obtainMessage(command, request);
1017 msg.sendToTarget();
1018
1019 // Wait for the request to complete
1020 synchronized (request) {
1021 while (request.result == null) {
1022 try {
1023 request.wait();
1024 } catch (InterruptedException e) {
1025 // Do nothing, go back and wait until the request is complete
1026 }
1027 }
1028 }
1029 return request.result;
1030 }
1031
1032 /**
1033 * Asynchronous ("fire and forget") version of sendRequest():
1034 * Posts the specified command to be executed on the main thread, and
1035 * returns immediately.
1036 * @see #sendRequest
1037 */
1038 private void sendRequestAsync(int command) {
1039 mMainThreadHandler.sendEmptyMessage(command);
1040 }
1041
1042 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001043 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1044 * @see {@link #sendRequest(int,Object)}
1045 */
1046 private void sendRequestAsync(int command, Object argument) {
1047 MainThreadRequest request = new MainThreadRequest(argument);
1048 Message msg = mMainThreadHandler.obtainMessage(command, request);
1049 msg.sendToTarget();
1050 }
1051
1052 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001053 * Initialize the singleton PhoneInterfaceManager instance.
1054 * This is only done once, at startup, from PhoneApp.onCreate().
1055 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001056 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001057 synchronized (PhoneInterfaceManager.class) {
1058 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001059 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001060 } else {
1061 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1062 }
1063 return sInstance;
1064 }
1065 }
1066
1067 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001068 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001069 mApp = app;
1070 mPhone = phone;
1071 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001072 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001073 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1074 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001075 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001076 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001077 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001078 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001079
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001080 publish();
1081 }
1082
1083 private void publish() {
1084 if (DBG) log("publish: " + this);
1085
1086 ServiceManager.addService("phone", this);
1087 }
1088
Stuart Scott584921c2015-01-15 17:10:34 -08001089 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001090 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1091 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001092 }
1093
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001094 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1095 Phone phone = getPhoneFromRequest(request);
1096 return phone == null ? null :
1097 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1098 }
1099
Wink Saville36469e72014-06-11 15:17:00 -07001100 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001101 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001102 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001103 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001104 //
1105 // Implementation of the ITelephony interface.
1106 //
1107
1108 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001109 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001110 }
1111
Wink Savilleb564aae2014-10-23 10:18:09 -07001112 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001113 if (DBG) log("dial: " + number);
1114 // No permission check needed here: This is just a wrapper around the
1115 // ACTION_DIAL intent, which is available to any app since it puts up
1116 // the UI before it does anything.
1117
1118 String url = createTelUrl(number);
1119 if (url == null) {
1120 return;
1121 }
1122
1123 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001124 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001125 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1126 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1127 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1128 mApp.startActivity(intent);
1129 }
1130 }
1131
1132 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001133 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001134 }
1135
Wink Savilleb564aae2014-10-23 10:18:09 -07001136 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001137 if (DBG) log("call: " + number);
1138
1139 // This is just a wrapper around the ACTION_CALL intent, but we still
1140 // need to do a permission check since we're calling startActivity()
1141 // from the context of the phone app.
1142 enforceCallPermission();
1143
1144 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1145 != AppOpsManager.MODE_ALLOWED) {
1146 return;
1147 }
1148
1149 String url = createTelUrl(number);
1150 if (url == null) {
1151 return;
1152 }
1153
Wink Saville08874612014-08-31 19:19:58 -07001154 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001155 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001156 if (slist != null) {
1157 for (SubscriptionInfo subInfoRecord : slist) {
1158 if (subInfoRecord.getSubscriptionId() == subId) {
1159 isValid = true;
1160 break;
1161 }
Wink Saville08874612014-08-31 19:19:58 -07001162 }
1163 }
1164 if (isValid == false) {
1165 return;
1166 }
1167
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001168 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001169 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001170 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1171 mApp.startActivity(intent);
1172 }
1173
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001174 /**
1175 * End a call based on call state
1176 * @return true is a call was ended
1177 */
1178 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001179 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001180 }
1181
1182 /**
1183 * End a call based on the call state of the subId
1184 * @return true is a call was ended
1185 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001186 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001187 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001188 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001189 }
1190
1191 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001192 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001193 }
1194
Wink Savilleb564aae2014-10-23 10:18:09 -07001195 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001196 if (DBG) log("answerRingingCall...");
1197 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1198 // but that can probably wait till the big TelephonyManager API overhaul.
1199 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1200 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001201 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001202 }
1203
1204 /**
1205 * Make the actual telephony calls to implement answerRingingCall().
1206 * This should only be called from the main thread of the Phone app.
1207 * @see #answerRingingCall
1208 *
1209 * TODO: it would be nice to return true if we answered the call, or
1210 * false if there wasn't actually a ringing incoming call, or some
1211 * other error occurred. (In other words, pass back the return value
1212 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1213 * But that would require calling this method via sendRequest() rather
1214 * than sendRequestAsync(), and right now we don't actually *need* that
1215 * return value, so let's just return void for now.
1216 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001217 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001218 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001220 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1221 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001222 if (hasActiveCall && hasHoldingCall) {
1223 // Both lines are in use!
1224 // TODO: provide a flag to let the caller specify what
1225 // policy to use if both lines are in use. (The current
1226 // behavior is hardwired to "answer incoming, end ongoing",
1227 // which is how the CALL button is specced to behave.)
1228 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1229 return;
1230 } else {
1231 // answerCall() will automatically hold the current active
1232 // call, if there is one.
1233 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1234 return;
1235 }
1236 } else {
1237 // No call was ringing.
1238 return;
1239 }
1240 }
1241
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001242 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001243 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001244 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001245 public void silenceRinger() {
1246 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247 }
1248
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001249 @Override
1250 public boolean isOffhook(String callingPackage) {
1251 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001252 }
1253
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001254 @Override
1255 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
1256 if (!canReadPhoneState(callingPackage, "isOffhookForSubscriber")) {
1257 return false;
1258 }
1259
Sanket Padawe356d7632015-06-22 14:03:32 -07001260 final Phone phone = getPhone(subId);
1261 if (phone != null) {
1262 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1263 } else {
1264 return false;
1265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001266 }
1267
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001268 @Override
1269 public boolean isRinging(String callingPackage) {
1270 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001271 }
1272
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001273 @Override
1274 public boolean isRingingForSubscriber(int subId, String callingPackage) {
1275 if (!canReadPhoneState(callingPackage, "isRingingForSubscriber")) {
1276 return false;
1277 }
1278
Sanket Padawe356d7632015-06-22 14:03:32 -07001279 final Phone phone = getPhone(subId);
1280 if (phone != null) {
1281 return (phone.getState() == PhoneConstants.State.RINGING);
1282 } else {
1283 return false;
1284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001285 }
1286
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001287 @Override
1288 public boolean isIdle(String callingPackage) {
1289 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001290 }
1291
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001292 @Override
1293 public boolean isIdleForSubscriber(int subId, String callingPackage) {
1294 if (!canReadPhoneState(callingPackage, "isIdleForSubscriber")) {
1295 return false;
1296 }
1297
Sanket Padawe356d7632015-06-22 14:03:32 -07001298 final Phone phone = getPhone(subId);
1299 if (phone != null) {
1300 return (phone.getState() == PhoneConstants.State.IDLE);
1301 } else {
1302 return false;
1303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001304 }
1305
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001306 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001307 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001308 }
1309
Wink Savilleb564aae2014-10-23 10:18:09 -07001310 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001311 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001312 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1313 }
1314
1315 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001316 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001317 }
1318
Wink Savilleb564aae2014-10-23 10:18:09 -07001319 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001320 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001321 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1322 }
1323
1324 /** {@hide} */
1325 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001326 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001327 }
1328
Wink Savilleb564aae2014-10-23 10:18:09 -07001329 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001330 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001331 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001332 checkSimPin.start();
1333 return checkSimPin.unlockSim(null, pin);
1334 }
1335
Wink Saville9de0f752013-10-22 19:04:03 -07001336 /** {@hide} */
1337 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001338 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001339 }
1340
Wink Savilleb564aae2014-10-23 10:18:09 -07001341 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001342 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001343 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001344 checkSimPuk.start();
1345 return checkSimPuk.unlockSim(puk, pin);
1346 }
1347
1348 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001349 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001350 * a synchronous one.
1351 */
1352 private static class UnlockSim extends Thread {
1353
1354 private final IccCard mSimCard;
1355
1356 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001357 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1358 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359
1360 // For replies from SimCard interface
1361 private Handler mHandler;
1362
1363 // For async handler to identify request type
1364 private static final int SUPPLY_PIN_COMPLETE = 100;
1365
1366 public UnlockSim(IccCard simCard) {
1367 mSimCard = simCard;
1368 }
1369
1370 @Override
1371 public void run() {
1372 Looper.prepare();
1373 synchronized (UnlockSim.this) {
1374 mHandler = new Handler() {
1375 @Override
1376 public void handleMessage(Message msg) {
1377 AsyncResult ar = (AsyncResult) msg.obj;
1378 switch (msg.what) {
1379 case SUPPLY_PIN_COMPLETE:
1380 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1381 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001382 mRetryCount = msg.arg1;
1383 if (ar.exception != null) {
1384 if (ar.exception instanceof CommandException &&
1385 ((CommandException)(ar.exception)).getCommandError()
1386 == CommandException.Error.PASSWORD_INCORRECT) {
1387 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1388 } else {
1389 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1390 }
1391 } else {
1392 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1393 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mDone = true;
1395 UnlockSim.this.notifyAll();
1396 }
1397 break;
1398 }
1399 }
1400 };
1401 UnlockSim.this.notifyAll();
1402 }
1403 Looper.loop();
1404 }
1405
1406 /*
1407 * Use PIN or PUK to unlock SIM card
1408 *
1409 * If PUK is null, unlock SIM card with PIN
1410 *
1411 * If PUK is not null, unlock SIM card with PUK and set PIN code
1412 */
Wink Saville9de0f752013-10-22 19:04:03 -07001413 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001414
1415 while (mHandler == null) {
1416 try {
1417 wait();
1418 } catch (InterruptedException e) {
1419 Thread.currentThread().interrupt();
1420 }
1421 }
1422 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1423
1424 if (puk == null) {
1425 mSimCard.supplyPin(pin, callback);
1426 } else {
1427 mSimCard.supplyPuk(puk, pin, callback);
1428 }
1429
1430 while (!mDone) {
1431 try {
1432 Log.d(LOG_TAG, "wait for done");
1433 wait();
1434 } catch (InterruptedException e) {
1435 // Restore the interrupted status
1436 Thread.currentThread().interrupt();
1437 }
1438 }
1439 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001440 int[] resultArray = new int[2];
1441 resultArray[0] = mResult;
1442 resultArray[1] = mRetryCount;
1443 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001444 }
1445 }
1446
1447 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001448 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001449
1450 }
1451
Wink Savilleb564aae2014-10-23 10:18:09 -07001452 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001453 // No permission check needed here: this call is harmless, and it's
1454 // needed for the ServiceState.requestStateUpdate() call (which is
1455 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001456 final Phone phone = getPhone(subId);
1457 if (phone != null) {
1458 phone.updateServiceLocation();
1459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 }
1461
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001462 @Override
1463 public boolean isRadioOn(String callingPackage) {
1464 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001465 }
1466
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001467 @Override
1468 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1469 if (!canReadPhoneState(callingPackage, "isRadioOnForSubscriber")) {
1470 return false;
1471 }
1472 return isRadioOnForSubscriber(subId);
1473 }
1474
1475 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001476 final Phone phone = getPhone(subId);
1477 if (phone != null) {
1478 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1479 } else {
1480 return false;
1481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001482 }
1483
1484 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001485 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001486
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001487 }
Wink Saville36469e72014-06-11 15:17:00 -07001488
Wink Savilleb564aae2014-10-23 10:18:09 -07001489 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001490 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001491 final Phone phone = getPhone(subId);
1492 if (phone != null) {
1493 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1494 }
Wink Saville36469e72014-06-11 15:17:00 -07001495 }
1496
1497 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001498 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001499 }
1500
Wink Savilleb564aae2014-10-23 10:18:09 -07001501 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001502 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001503 final Phone phone = getPhone(subId);
1504 if (phone == null) {
1505 return false;
1506 }
1507 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001508 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001509 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001510 }
1511 return true;
1512 }
Wink Saville36469e72014-06-11 15:17:00 -07001513
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001514 public boolean needMobileRadioShutdown() {
1515 /*
1516 * If any of the Radios are available, it will need to be
1517 * shutdown. So return true if any Radio is available.
1518 */
1519 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1520 Phone phone = PhoneFactory.getPhone(i);
1521 if (phone != null && phone.isRadioAvailable()) return true;
1522 }
1523 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1524 return false;
1525 }
1526
1527 public void shutdownMobileRadios() {
1528 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1529 logv("Shutting down Phone " + i);
1530 shutdownRadioUsingPhoneId(i);
1531 }
1532 }
1533
1534 private void shutdownRadioUsingPhoneId(int phoneId) {
1535 enforceModifyPermission();
1536 Phone phone = PhoneFactory.getPhone(phoneId);
1537 if (phone != null && phone.isRadioAvailable()) {
1538 phone.shutdownRadio();
1539 }
1540 }
1541
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001542 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001543 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001544 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1545 if (defaultPhone != null) {
1546 defaultPhone.setRadioPower(turnOn);
1547 return true;
1548 } else {
1549 loge("There's no default phone.");
1550 return false;
1551 }
Wink Saville36469e72014-06-11 15:17:00 -07001552 }
1553
Wink Savilleb564aae2014-10-23 10:18:09 -07001554 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001556 final Phone phone = getPhone(subId);
1557 if (phone != null) {
1558 phone.setRadioPower(turnOn);
1559 return true;
1560 } else {
1561 return false;
1562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 }
1564
Wink Saville36469e72014-06-11 15:17:00 -07001565 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001566 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567 public boolean enableDataConnectivity() {
1568 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001569 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001570 final Phone phone = getPhone(subId);
1571 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001572 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001573 return true;
1574 } else {
1575 return false;
1576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 }
1578
Wink Saville36469e72014-06-11 15:17:00 -07001579 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 public boolean disableDataConnectivity() {
1582 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001583 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001584 final Phone phone = getPhone(subId);
1585 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001586 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001587 return true;
1588 } else {
1589 return false;
1590 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001591 }
1592
Sanket Padawe356d7632015-06-22 14:03:32 -07001593 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001594 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001595 final Phone phone = getPhone(subId);
1596 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001597 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001598 } else {
1599 return false;
1600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 }
1602
1603 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001604 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001605 }
1606
pkanwarae03a6b2016-11-06 20:37:09 -08001607 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001608 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001609 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1610 return;
1611 }
1612 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1613 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1614 };
1615
Wink Savilleb564aae2014-10-23 10:18:09 -07001616 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001617 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001618 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1619 return false;
1620 }
Wink Saville36469e72014-06-11 15:17:00 -07001621 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 }
1623
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001625 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001626 }
1627
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001628 public int getCallStateForSlot(int slotIndex) {
1629 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001630 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001631 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001632 }
1633
Sanket Padawe356d7632015-06-22 14:03:32 -07001634 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001636 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001637 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001638 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001639 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001640 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001641 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 }
1643
Sanket Padawe356d7632015-06-22 14:03:32 -07001644 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001646 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001647 if (phone != null) {
1648 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1649 } else {
1650 return TelephonyManager.DATA_ACTIVITY_NONE;
1651 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 }
1653
1654 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001655 public Bundle getCellLocation(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001656 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001657 callingPackage, Binder.getCallingUid(), "getCellLocation")) {
Svetoslav64fad262015-04-14 14:35:21 -07001658 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 }
1660
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001661 if (DBG_LOC) log("getCellLocation: is active user");
1662 Bundle data = new Bundle();
1663 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1664 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 return null;
1666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001668 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1669 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1670 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001671 }
1672
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001674 public String getNetworkCountryIsoForPhone(int phoneId) {
1675 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1676 // registered cell info, so return a NULL country instead.
1677 final long identity = Binder.clearCallingIdentity();
1678 try {
1679 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1680 if (TelephonyManager.NETWORK_TYPE_IWLAN
1681 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1682 return "";
1683 }
1684 } finally {
1685 Binder.restoreCallingIdentity(identity);
1686 }
1687 return TelephonyManager.getTelephonyProperty(
1688 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1689 }
1690
1691 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001692 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001693 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001694 }
1695
Sanket Padawe356d7632015-06-22 14:03:32 -07001696 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001697 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 mApp.enforceCallingOrSelfPermission(
1699 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001700 final Phone phone = getPhone(subId);
1701 if (phone != null) {
1702 phone.enableLocationUpdates();
1703 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001704 }
1705
1706 @Override
1707 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001708 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001709 }
1710
Sanket Padawe356d7632015-06-22 14:03:32 -07001711 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001712 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 mApp.enforceCallingOrSelfPermission(
1714 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001715 final Phone phone = getPhone(subId);
1716 if (phone != null) {
1717 phone.disableLocationUpdates();
1718 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 }
1720
1721 @Override
1722 @SuppressWarnings("unchecked")
1723 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001724 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001725 callingPackage, Binder.getCallingUid(), "getNeighboringCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001726 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001727 }
1728
1729 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1730 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1731 return null;
1732 }
Svetoslav64fad262015-04-14 14:35:21 -07001733
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001734 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001736 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001738 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1739 try {
1740 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1741 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1742 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1743 } catch (RuntimeException e) {
1744 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001746 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 }
1748
1749
1750 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001751 public List<CellInfo> getAllCellInfo(String callingPackage) {
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001752 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu3dae9d42018-02-06 18:12:43 +00001753 callingPackage, Binder.getCallingUid(), "getAllCellInfo")) {
Svetoslav64fad262015-04-14 14:35:21 -07001754 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 }
1756
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001757 if (DBG_LOC) log("getAllCellInfo: is active user");
1758 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1759 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1760 for (Phone phone : PhoneFactory.getPhones()) {
1761 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1762 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001763 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001764 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001765 }
1766
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001767 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001769 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001770 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1771 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001772 }
1773
Shishir Agrawala9f32182016-04-12 12:00:16 -07001774 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001775 public String getImeiForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001776 if (!canReadPhoneState(callingPackage, "getImeiForSlot")) {
1777 return null;
1778 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001779 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001780 return phone == null ? null : phone.getImei();
1781 }
1782
1783 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001784 public String getMeidForSlot(int slotIndex, String callingPackage) {
1785 if (!canReadPhoneState(callingPackage, "getMeidForSlot")) {
1786 return null;
1787 }
1788 Phone phone = PhoneFactory.getPhone(slotIndex);
1789 return phone == null ? null : phone.getMeid();
1790 }
1791
1792 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001793 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001794 if (!canReadPhoneState(callingPackage, "getDeviceSoftwareVersionForSlot")) {
1795 return null;
1796 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001797 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001798 return phone == null ? null : phone.getDeviceSvn();
1799 }
1800
fionaxuf32acdf2017-11-27 22:51:16 -08001801 @Override
1802 public int getSubscriptionCarrierId(int subId) {
1803 final Phone phone = getPhone(subId);
1804 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1805 }
1806
1807 @Override
1808 public String getSubscriptionCarrierName(int subId) {
1809 final Phone phone = getPhone(subId);
1810 return phone == null ? null : phone.getCarrierName();
1811 }
1812
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 //
1814 // Internal helper methods.
1815 //
1816
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001817 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1819 *
1820 * @throws SecurityException if the caller does not have the required permission
1821 */
1822 private void enforceModifyPermission() {
1823 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1824 }
1825
1826 /**
Junda Liua2e36012014-07-09 18:30:01 -07001827 * Make sure either system app or the caller has carrier privilege.
1828 *
1829 * @throws SecurityException if the caller does not have the required permission/privilege
1830 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001831 private void enforceModifyPermissionOrCarrierPrivilege(int subId) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001832 int permission = mApp.checkCallingOrSelfPermission(
1833 android.Manifest.permission.MODIFY_PHONE_STATE);
1834 if (permission == PackageManager.PERMISSION_GRANTED) {
1835 return;
1836 }
1837
1838 log("No modify permission, check carrier privilege next.");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001839 enforceCarrierPrivilege(subId);
Junda Liua2e36012014-07-09 18:30:01 -07001840 }
1841
1842 /**
1843 * Make sure the caller has carrier privilege.
1844 *
1845 * @throws SecurityException if the caller does not have the required permission
1846 */
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001847 private void enforceCarrierPrivilege(int subId) {
1848 if (getCarrierPrivilegeStatus(subId) !=
1849 TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Shishir Agrawalf1ac4c92014-07-14 13:54:28 -07001850 loge("No Carrier Privilege.");
1851 throw new SecurityException("No Carrier Privilege.");
Junda Liua2e36012014-07-09 18:30:01 -07001852 }
1853 }
1854
1855 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001856 * Make sure the caller has the CALL_PHONE permission.
1857 *
1858 * @throws SecurityException if the caller does not have the required permission
1859 */
1860 private void enforceCallPermission() {
1861 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1862 }
1863
Stuart Scott8eef64f2015-04-08 15:13:54 -07001864 private void enforceConnectivityInternalPermission() {
1865 mApp.enforceCallingOrSelfPermission(
1866 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1867 "ConnectivityService");
1868 }
1869
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 private String createTelUrl(String number) {
1871 if (TextUtils.isEmpty(number)) {
1872 return null;
1873 }
1874
Jake Hambye994d462014-02-03 13:10:13 -08001875 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 }
1877
Ihab Awadf9e92732013-12-05 18:02:52 -08001878 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1880 }
1881
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001882 private static void logv(String msg) {
1883 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1884 }
1885
Ihab Awadf9e92732013-12-05 18:02:52 -08001886 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001887 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1888 }
1889
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001890 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001892 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001893 }
1894
Sanket Padawe356d7632015-06-22 14:03:32 -07001895 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001896 public int getActivePhoneTypeForSlot(int slotIndex) {
1897 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001898 if (phone == null) {
1899 return PhoneConstants.PHONE_TYPE_NONE;
1900 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001901 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001902 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001903 }
1904
1905 /**
1906 * Returns the CDMA ERI icon index to display
1907 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001908 @Override
1909 public int getCdmaEriIconIndex(String callingPackage) {
1910 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001911 }
1912
Sanket Padawe356d7632015-06-22 14:03:32 -07001913 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001914 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
1915 if (!canReadPhoneState(callingPackage, "getCdmaEriIconIndexForSubscriber")) {
1916 return -1;
1917 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001918 final Phone phone = getPhone(subId);
1919 if (phone != null) {
1920 return phone.getCdmaEriIconIndex();
1921 } else {
1922 return -1;
1923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 }
1925
1926 /**
1927 * Returns the CDMA ERI icon mode,
1928 * 0 - ON
1929 * 1 - FLASHING
1930 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001931 @Override
1932 public int getCdmaEriIconMode(String callingPackage) {
1933 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001934 }
1935
Sanket Padawe356d7632015-06-22 14:03:32 -07001936 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001937 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
1938 if (!canReadPhoneState(callingPackage, "getCdmaEriIconModeForSubscriber")) {
1939 return -1;
1940 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 final Phone phone = getPhone(subId);
1942 if (phone != null) {
1943 return phone.getCdmaEriIconMode();
1944 } else {
1945 return -1;
1946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 }
1948
1949 /**
1950 * Returns the CDMA ERI text,
1951 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001952 @Override
1953 public String getCdmaEriText(String callingPackage) {
1954 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001955 }
1956
Sanket Padawe356d7632015-06-22 14:03:32 -07001957 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001958 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
1959 if (!canReadPhoneState(callingPackage, "getCdmaEriIconTextForSubscriber")) {
1960 return null;
1961 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001962 final Phone phone = getPhone(subId);
1963 if (phone != null) {
1964 return phone.getCdmaEriText();
1965 } else {
1966 return null;
1967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 }
1969
1970 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001971 * Returns the CDMA MDN.
1972 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001973 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001974 public String getCdmaMdn(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001975 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 final Phone phone = getPhone(subId);
1977 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1978 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001979 } else {
1980 return null;
1981 }
1982 }
1983
1984 /**
1985 * Returns the CDMA MIN.
1986 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001987 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001988 public String getCdmaMin(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001989 enforceModifyPermissionOrCarrierPrivilege(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 final Phone phone = getPhone(subId);
1991 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1992 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001993 } else {
1994 return null;
1995 }
1996 }
1997
1998 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 * Returns true if CDMA provisioning needs to run.
2000 */
2001 public boolean needsOtaServiceProvisioning() {
2002 return mPhone.needsOtaServiceProvisioning();
2003 }
2004
2005 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002006 * Sets the voice mail number of a given subId.
2007 */
2008 @Override
2009 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002010 enforceCarrierPrivilege(subId);
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002011 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2012 new Pair<String, String>(alphaTag, number), new Integer(subId));
2013 return success;
2014 }
2015
Ta-wei Yen87c49842016-05-13 21:19:52 -07002016 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002017 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2018 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2019 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2020 if (!TextUtils.equals(callingPackage, systemDialer)) {
2021 throw new SecurityException("caller must be system dialer");
2022 }
2023 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2024 if (phoneAccountHandle == null){
2025 return null;
2026 }
2027 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2028 }
2029
2030 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002031 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002032 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2033 if (!canReadPhoneState(callingPackage, "getVisualVoicemailPackageName")) {
2034 return null;
2035 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002036 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2037 }
2038
2039 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002040 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2041 VisualVoicemailSmsFilterSettings settings) {
2042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002043 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002044 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2045 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002046 }
2047
2048 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002049 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2050 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002051 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002052 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002053 }
2054
2055 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002056 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2057 String callingPackage, int subId) {
2058 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002059 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002060 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002061 }
2062
2063 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002064 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002065 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002066 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002067 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2068 }
2069
2070 @Override
2071 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2072 String number, int port, String text, PendingIntent sentIntent) {
2073 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002074 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002075 enforceSendSmsPermission();
2076 // Make the calls as the phone process.
2077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2080 if (port == 0) {
2081 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2082 sentIntent, null, false);
2083 } else {
2084 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2085 smsManager.sendDataMessageWithSelfPermissions(number, null,
2086 (short) port, data, sentIntent, null);
2087 }
2088 } finally {
2089 Binder.restoreCallingIdentity(identity);
2090 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002091 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002092 /**
fionaxu0152e512016-11-14 13:36:14 -08002093 * Sets the voice activation state of a given subId.
2094 */
2095 @Override
2096 public void setVoiceActivationState(int subId, int activationState) {
2097 enforceModifyPermissionOrCarrierPrivilege(subId);
2098 final Phone phone = getPhone(subId);
2099 if (phone != null) {
2100 phone.setVoiceActivationState(activationState);
2101 } else {
2102 loge("setVoiceActivationState fails with invalid subId: " + subId);
2103 }
2104 }
2105
2106 /**
2107 * Sets the data activation state of a given subId.
2108 */
2109 @Override
2110 public void setDataActivationState(int subId, int activationState) {
2111 enforceModifyPermissionOrCarrierPrivilege(subId);
2112 final Phone phone = getPhone(subId);
2113 if (phone != null) {
2114 phone.setDataActivationState(activationState);
2115 } else {
2116 loge("setVoiceActivationState fails with invalid subId: " + subId);
2117 }
2118 }
2119
2120 /**
2121 * Returns the voice activation state of a given subId.
2122 */
2123 @Override
2124 public int getVoiceActivationState(int subId, String callingPackage) {
2125 if (!canReadPhoneState(callingPackage, "getVoiceActivationStateForSubscriber")) {
2126 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2127 }
2128 final Phone phone = getPhone(subId);
2129 if (phone != null) {
2130 return phone.getVoiceActivationState();
2131 } else {
2132 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2133 }
2134 }
2135
2136 /**
2137 * Returns the data activation state of a given subId.
2138 */
2139 @Override
2140 public int getDataActivationState(int subId, String callingPackage) {
2141 if (!canReadPhoneState(callingPackage, "getDataActivationStateForSubscriber")) {
2142 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2143 }
2144 final Phone phone = getPhone(subId);
2145 if (phone != null) {
2146 return phone.getDataActivationState();
2147 } else {
2148 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2149 }
2150 }
2151
2152 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 * Returns the unread count of voicemails
2154 */
2155 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002156 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002157 }
2158
2159 /**
2160 * Returns the unread count of voicemails for a subId
2161 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002162 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002163 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002164 final Phone phone = getPhone(subId);
2165 if (phone != null) {
2166 return phone.getVoiceMessageCount();
2167 } else {
2168 return 0;
2169 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 }
2171
2172 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002173 * returns true, if the device is in a state where both voice and data
2174 * are supported simultaneously. This can change based on location or network condition.
2175 */
2176 @Override
2177 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2178 final Phone phone = getPhone(subId);
2179 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2180 }
2181
2182 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002183 * Send the dialer code if called from the current default dialer or the caller has
2184 * carrier privilege.
2185 * @param inputCode The dialer code to send
2186 */
2187 @Override
2188 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2189 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2190 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2191 if (!TextUtils.equals(callingPackage, defaultDialer)) {
2192 enforceCarrierPrivilege(getDefaultSubscription());
2193 }
2194 mPhone.sendDialerSpecialCode(inputCode);
2195 }
2196
2197 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002198 * Returns the data network type.
2199 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002200 *
2201 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2202 */
2203 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002204 public int getNetworkType() {
2205 final Phone phone = getPhone(getDefaultSubscription());
2206 if (phone != null) {
2207 return phone.getServiceState().getDataNetworkType();
2208 } else {
2209 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2210 }
Wink Saville36469e72014-06-11 15:17:00 -07002211 }
2212
2213 /**
2214 * Returns the network type for a subId
2215 */
2216 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002217 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
2218 if (!canReadPhoneState(callingPackage, "getNetworkTypeForSubscriber")) {
2219 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2220 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002221
Sanket Padawe356d7632015-06-22 14:03:32 -07002222 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002223 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002224 return phone.getServiceState().getDataNetworkType();
2225 } else {
2226 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2227 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002228 }
2229
2230 /**
2231 * Returns the data network type
2232 */
2233 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002234 public int getDataNetworkType(String callingPackage) {
2235 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002236 }
2237
2238 /**
2239 * Returns the data network type for a subId
2240 */
2241 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002242 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
2243 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2244 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2245 }
2246
Sanket Padawe356d7632015-06-22 14:03:32 -07002247 final Phone phone = getPhone(subId);
2248 if (phone != null) {
2249 return phone.getServiceState().getDataNetworkType();
2250 } else {
2251 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 }
2254
2255 /**
Wink Saville36469e72014-06-11 15:17:00 -07002256 * Returns the Voice network type for a subId
2257 */
2258 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002259 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
2260 if (!canReadPhoneState(callingPackage, "getDataNetworkTypeForSubscriber")) {
2261 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2262 }
2263
Sanket Padawe356d7632015-06-22 14:03:32 -07002264 final Phone phone = getPhone(subId);
2265 if (phone != null) {
2266 return phone.getServiceState().getVoiceNetworkType();
2267 } else {
2268 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 }
2271
2272 /**
2273 * @return true if a ICC card is present
2274 */
2275 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002276 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002277 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2278 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002279 }
2280
2281 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002282 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002283 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002284 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002285 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2286 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002287 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002288 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002289 } else {
2290 return false;
2291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 }
2293
2294 /**
2295 * Return if the current radio is LTE on CDMA. This
2296 * is a tri-state return value as for a period of time
2297 * the mode may be unknown.
2298 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002299 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002301 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002302 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002303 @Override
2304 public int getLteOnCdmaMode(String callingPackage) {
2305 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002306 }
2307
Sanket Padawe356d7632015-06-22 14:03:32 -07002308 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002309 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
2310 if (!canReadPhoneState(callingPackage, "getLteOnCdmaModeForSubscriber")) {
2311 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2312 }
2313
Sanket Padawe356d7632015-06-22 14:03:32 -07002314 final Phone phone = getPhone(subId);
2315 if (phone == null) {
2316 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2317 } else {
2318 return phone.getLteOnCdmaMode();
2319 }
Wink Saville36469e72014-06-11 15:17:00 -07002320 }
2321
2322 public void setPhone(Phone phone) {
2323 mPhone = phone;
2324 }
2325
2326 /**
2327 * {@hide}
2328 * Returns Default subId, 0 in the case of single standby.
2329 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002330 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002331 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002332 }
2333
Shishir Agrawala9f32182016-04-12 12:00:16 -07002334 private int getSlotForDefaultSubscription() {
2335 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2336 }
2337
Wink Savilleb564aae2014-10-23 10:18:09 -07002338 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002339 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002340 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002341
2342 /**
2343 * @see android.telephony.TelephonyManager.WifiCallingChoices
2344 */
2345 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002346 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2347 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002348 }
2349
2350 /**
2351 * @see android.telephony.TelephonyManager.WifiCallingChoices
2352 */
2353 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002354 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2355 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2356 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002357 }
2358
Sailesh Nepald1e68152013-12-12 19:08:02 -08002359 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002360 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002361 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002362 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002363
Shishir Agrawal566b7612013-10-28 14:41:00 -07002364 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002365 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2366 int subId, String callingPackage, String aid, int p2) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002367 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002368
Derek Tan740e1672017-06-27 14:56:27 -07002369 if (TextUtils.equals(ISDR_AID, aid)) {
2370 // Only allows LPA to open logical channel to ISD-R.
2371 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2372 ComponentInfo bestComponent =
2373 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2374 if (bestComponent == null
2375 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2376 loge("The calling package is not allowed to access ISD-R.");
2377 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2378 }
2379 }
2380
2381 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002382 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002383 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002384 if (DBG) log("iccOpenLogicalChannel: " + response);
2385 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002386 }
2387
2388 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002389 public boolean iccCloseLogicalChannel(int subId, int channel) {
2390 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002391
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002392 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002393 if (channel < 0) {
2394 return false;
2395 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002396 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002397 if (DBG) log("iccCloseLogicalChannel: " + success);
2398 return success;
2399 }
2400
2401 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002402 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002403 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002404 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002405
2406 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002407 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2408 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002409 " data=" + data);
2410 }
2411
2412 if (channel < 0) {
2413 return "";
2414 }
2415
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002416 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002417 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002418 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2419
Shishir Agrawal566b7612013-10-28 14:41:00 -07002420 // Append the returned status code to the end of the response payload.
2421 String s = Integer.toHexString(
2422 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002423 if (response.payload != null) {
2424 s = IccUtils.bytesToHexString(response.payload) + s;
2425 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002426 return s;
2427 }
Jake Hambye994d462014-02-03 13:10:13 -08002428
Evan Charltonc66da362014-05-16 14:06:40 -07002429 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002430 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2431 int command, int p1, int p2, int p3, String data) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002432 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002433
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002434 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2435 && TextUtils.equals(ISDR_AID, data)) {
2436 // Only allows LPA to select ISD-R.
2437 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2438 ComponentInfo bestComponent =
2439 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2440 if (bestComponent == null
2441 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2442 loge("The calling package is not allowed to select ISD-R.");
2443 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2444 }
2445 }
2446
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002447 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002448 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2449 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002450 }
2451
2452 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002453 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002454 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2455
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002456 // Append the returned status code to the end of the response payload.
2457 String s = Integer.toHexString(
2458 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002459 if (response.payload != null) {
2460 s = IccUtils.bytesToHexString(response.payload) + s;
2461 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002462 return s;
2463 }
2464
2465 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002466 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002467 String filePath) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002468 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002469
2470 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002471 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002472 p1 + " " + p2 + " " + p3 + ":" + filePath);
2473 }
2474
2475 IccIoResult response =
2476 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002477 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2478 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002479
2480 if (DBG) {
2481 log("Exchange SIM_IO [R]" + response);
2482 }
2483
2484 byte[] result = null;
2485 int length = 2;
2486 if (response.payload != null) {
2487 length = 2 + response.payload.length;
2488 result = new byte[length];
2489 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2490 } else {
2491 result = new byte[length];
2492 }
2493
2494 result[length - 1] = (byte) response.sw2;
2495 result[length - 2] = (byte) response.sw1;
2496 return result;
2497 }
2498
Nathan Haroldb3014052017-01-25 15:57:32 -08002499 /**
2500 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2501 * on a particular subscription
2502 */
2503 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002504 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2505 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002506 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2507 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2508 return null;
2509 }
2510 Object response = sendRequest(
2511 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2512 if (response instanceof String[]) {
2513 return (String[]) response;
2514 }
2515 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2516 return null;
2517 }
2518
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002519 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002520 public String sendEnvelopeWithStatus(int subId, String content) {
2521 enforceModifyPermissionOrCarrierPrivilege(subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002522
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002523 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002524 if (response.payload == null) {
2525 return "";
2526 }
2527
2528 // Append the returned status code to the end of the response payload.
2529 String s = Integer.toHexString(
2530 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2531 s = IccUtils.bytesToHexString(response.payload) + s;
2532 return s;
2533 }
2534
Jake Hambye994d462014-02-03 13:10:13 -08002535 /**
2536 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2537 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2538 *
2539 * @param itemID the ID of the item to read
2540 * @return the NV item as a String, or null on error.
2541 */
2542 @Override
2543 public String nvReadItem(int itemID) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002544 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002545 if (DBG) log("nvReadItem: item " + itemID);
2546 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2547 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2548 return value;
2549 }
2550
2551 /**
2552 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2553 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2554 *
2555 * @param itemID the ID of the item to read
2556 * @param itemValue the value to write, as a String
2557 * @return true on success; false on any failure
2558 */
2559 @Override
2560 public boolean nvWriteItem(int itemID, String itemValue) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002561 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002562 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2563 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2564 new Pair<Integer, String>(itemID, itemValue));
2565 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2566 return success;
2567 }
2568
2569 /**
2570 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2571 * Used for device configuration by some CDMA operators.
2572 *
2573 * @param preferredRoamingList byte array containing the new PRL
2574 * @return true on success; false on any failure
2575 */
2576 @Override
2577 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002578 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002579 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2580 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2581 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2582 return success;
2583 }
2584
2585 /**
2586 * Perform the specified type of NV config reset.
2587 * Used for device configuration by some CDMA operators.
2588 *
2589 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2590 * @return true on success; false on any failure
2591 */
2592 @Override
2593 public boolean nvResetConfig(int resetType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002594 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
Jake Hambye994d462014-02-03 13:10:13 -08002595 if (DBG) log("nvResetConfig: type " + resetType);
2596 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2597 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2598 return success;
2599 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002600
2601 /**
Wink Saville36469e72014-06-11 15:17:00 -07002602 * {@hide}
2603 * Returns Default sim, 0 in the case of single standby.
2604 */
2605 public int getDefaultSim() {
2606 //TODO Need to get it from Telephony Devcontroller
2607 return 0;
2608 }
2609
Svet Ganovb320e182015-04-16 12:30:10 -07002610 public String[] getPcscfAddress(String apnType, String callingPackage) {
2611 if (!canReadPhoneState(callingPackage, "getPcscfAddress")) {
2612 return new String[0];
2613 }
2614
2615
ram87fca6f2014-07-18 18:58:44 +05302616 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002617 }
2618
Brad Ebinger51f743a2017-01-23 13:50:20 -08002619 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002620 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2621 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002622 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002623 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002624 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002625 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002626 }
2627
2628 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002629 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2630 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002631 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002632 public void disableIms(int slotId) {
2633 enforceModifyPermission();
2634 PhoneFactory.getImsResolver().disableIms(slotId);
2635 }
2636
2637 /**
2638 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2639 * feature or {@link null} if the service is not available. If the feature is available, the
2640 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2641 */
2642 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002643 IImsServiceFeatureCallback callback) {
2644 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002645 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002646 }
2647
2648 /**
2649 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2650 * feature during emergency calling or {@link null} if the service is not available. If the
2651 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2652 * listener for feature updates.
2653 */
2654 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2655 enforceModifyPermission();
2656 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002657 }
2658
Brad Ebinger7e934f52017-12-14 14:26:15 -08002659 /**
2660 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2661 * specified.
2662 */
2663 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2664 enforceModifyPermission();
2665 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2666 }
2667
Brad Ebingera12246d2018-01-16 09:39:35 -08002668 /**
2669 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2670 * specified.
2671 */
2672 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2673 enforceModifyPermission();
2674 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2675 }
2676
Wink Saville36469e72014-06-11 15:17:00 -07002677 public void setImsRegistrationState(boolean registered) {
2678 enforceModifyPermission();
2679 mPhone.setImsRegistrationState(registered);
2680 }
2681
2682 /**
Stuart Scott54788802015-03-30 13:18:01 -07002683 * Set the network selection mode to automatic.
2684 *
2685 */
2686 @Override
2687 public void setNetworkSelectionModeAutomatic(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002688 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002689 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2690 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2691 }
2692
2693 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002694 * Set the network selection mode to manual with the selected carrier.
2695 */
2696 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002697 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002698 boolean persistSelection) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002699 enforceModifyPermissionOrCarrierPrivilege(subId);
yinxu6e5abd72017-12-01 11:35:19 -08002700 OperatorInfo operator = new OperatorInfo(
2701 /* operatorAlphaLong */ "",
2702 /* operatorAlphaShort */ "",
2703 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002704 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002705 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2706 persistSelection);
2707 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002708 }
2709
2710 /**
2711 * Scans for available networks.
2712 */
2713 @Override
2714 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002715 enforceModifyPermissionOrCarrierPrivilege(subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002716 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2717 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2718 CMD_PERFORM_NETWORK_SCAN, null, subId);
2719 return result;
2720 }
2721
2722 /**
yinxub1bed742017-04-17 11:45:04 -07002723 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002724 *
yinxub1bed742017-04-17 11:45:04 -07002725 * @param subId id of the subscription
2726 * @param request contains the radio access networks with bands/channels to scan
2727 * @param messenger callback messenger for scan results or errors
2728 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002729 * @return the id of the requested scan which can be used to stop the scan.
2730 */
2731 @Override
2732 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2733 IBinder binder) {
yinxub1bed742017-04-17 11:45:04 -07002734 enforceModifyPermissionOrCarrierPrivilege(subId);
2735 return mNetworkScanRequestTracker.startNetworkScan(
2736 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002737 }
2738
2739 /**
2740 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002741 *
2742 * @param subId id of the subscription
2743 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002744 */
2745 @Override
2746 public void stopNetworkScan(int subId, int scanId) {
yinxub1bed742017-04-17 11:45:04 -07002747 enforceModifyPermissionOrCarrierPrivilege(subId);
2748 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002749 }
2750
2751 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002752 * Get the calculated preferred network type.
2753 * Used for debugging incorrect network type.
2754 *
2755 * @return the preferred network type, defined in RILConstants.java.
2756 */
2757 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002758 public int getCalculatedPreferredNetworkType(String callingPackage) {
2759 if (!canReadPhoneState(callingPackage, "getCalculatedPreferredNetworkType")) {
2760 return RILConstants.PREFERRED_NETWORK_MODE;
2761 }
2762
Amit Mahajan43330e02014-11-18 11:54:45 -08002763 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002764 }
2765
2766 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002767 * Get the preferred network type.
2768 * Used for device configuration by some CDMA operators.
2769 *
2770 * @return the preferred network type, defined in RILConstants.java.
2771 */
2772 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002773 public int getPreferredNetworkType(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002774 enforceModifyPermissionOrCarrierPrivilege(subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002775 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002776 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002777 int networkType = (result != null ? result[0] : -1);
2778 if (DBG) log("getPreferredNetworkType: " + networkType);
2779 return networkType;
2780 }
2781
2782 /**
2783 * Set the preferred network type.
2784 * Used for device configuration by some CDMA operators.
2785 *
2786 * @param networkType the preferred network type, defined in RILConstants.java.
2787 * @return true on success; false on any failure.
2788 */
2789 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002790 public boolean setPreferredNetworkType(int subId, int networkType) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002791 enforceModifyPermissionOrCarrierPrivilege(subId);
Stuart Scott54788802015-03-30 13:18:01 -07002792 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2793 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002794 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002795 if (success) {
2796 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002797 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002798 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002799 return success;
2800 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002801
2802 /**
Junda Liu475951f2014-11-07 16:45:03 -08002803 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2804 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2805 * tethering.
2806 *
2807 * @return 0: Not required. 1: required. 2: Not set.
2808 * @hide
2809 */
2810 @Override
2811 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002812 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002813 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2814 Settings.Global.TETHER_DUN_REQUIRED, 2);
2815 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2816 // config_tether_apndata.
2817 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2818 dunRequired = 1;
2819 }
2820 return dunRequired;
2821 }
2822
2823 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002824 * Set mobile data enabled
2825 * Used by the user through settings etc to turn on/off mobile data
2826 *
2827 * @param enable {@code true} turn turn data on, else {@code false}
2828 */
2829 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002830 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002831 enforceModifyPermissionOrCarrierPrivilege(subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002832 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002833 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002834 Phone phone = PhoneFactory.getPhone(phoneId);
2835 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002836 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2837 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002838 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002839 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002840 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002841 }
2842
2843 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002844 * Get the user enabled state of Mobile Data.
2845 *
2846 * TODO: remove and use isUserDataEnabled.
2847 * This can't be removed now because some vendor codes
2848 * calls through ITelephony directly while they should
2849 * use TelephonyManager.
2850 *
2851 * @return true on enabled
2852 */
2853 @Override
2854 public boolean getDataEnabled(int subId) {
2855 return isUserDataEnabled(subId);
2856 }
2857
2858 /**
2859 * Get whether mobile data is enabled per user setting.
2860 *
2861 * There are other factors deciding whether mobile data is actually enabled, but they are
2862 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002863 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002864 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002865 *
2866 * @return {@code true} if data is enabled else {@code false}
2867 */
2868 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002869 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002870 try {
2871 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2872 null);
2873 } catch (Exception e) {
Jeff Davidsona1920712016-11-18 17:05:56 -08002874 enforceModifyPermissionOrCarrierPrivilege(subId);
Robert Greenwalt646120a2014-05-23 11:54:03 -07002875 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002876 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002877 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002878 Phone phone = PhoneFactory.getPhone(phoneId);
2879 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002880 boolean retVal = phone.isUserDataEnabled();
2881 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002882 return retVal;
2883 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002884 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2885 return false;
2886 }
2887 }
2888
2889 /**
2890 * Get whether mobile data is enabled.
2891 *
2892 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2893 * whether mobile data is actually enabled.
2894 *
2895 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2896 *
2897 * @return {@code true} if data is enabled else {@code false}
2898 */
2899 @Override
2900 public boolean isDataEnabled(int subId) {
2901 try {
2902 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2903 null);
2904 } catch (Exception e) {
2905 enforceModifyPermissionOrCarrierPrivilege(subId);
2906 }
2907 int phoneId = mSubscriptionController.getPhoneId(subId);
2908 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2909 Phone phone = PhoneFactory.getPhone(phoneId);
2910 if (phone != null) {
2911 boolean retVal = phone.isDataEnabled();
2912 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2913 return retVal;
2914 } else {
2915 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002916 return false;
2917 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002918 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002919
2920 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002921 public int getCarrierPrivilegeStatus(int subId) {
2922 final Phone phone = getPhone(subId);
2923 if (phone == null) {
2924 loge("getCarrierPrivilegeStatus: Invalid subId");
2925 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2926 }
2927 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002928 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002929 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002930 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2931 }
2932 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002933 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002934 }
Junda Liu29340342014-07-10 15:23:27 -07002935
2936 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002937 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002938 if (TextUtils.isEmpty(pkgName))
2939 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002940 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002941 if (card == null) {
2942 loge("checkCarrierPrivilegesForPackage: No UICC");
2943 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2944 }
Zach Johnson50ecba32015-05-19 00:24:21 -07002945 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
2946 }
2947
2948 @Override
2949 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002950 if (TextUtils.isEmpty(pkgName))
2951 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07002952 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2953 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2954 UiccCard card = UiccController.getInstance().getUiccCard(i);
2955 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07002956 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07002957 continue;
2958 }
2959
2960 result = card.getCarrierPrivilegeStatus(
2961 mPhone.getContext().getPackageManager(), pkgName);
2962 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
2963 break;
2964 }
2965 }
2966
2967 return result;
Junda Liu29340342014-07-10 15:23:27 -07002968 }
Derek Tan89e89d42014-07-08 17:00:10 -07002969
2970 @Override
Junda Liue64de782015-04-16 17:19:16 -07002971 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
2972 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
2973 loge("phoneId " + phoneId + " is not valid.");
2974 return null;
2975 }
2976 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002977 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002978 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002979 return null ;
2980 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07002981 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07002982 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07002983 }
2984
Amith Yamasani6e118872016-02-19 12:53:51 -08002985 @Override
2986 public List<String> getPackagesWithCarrierPrivileges() {
2987 PackageManager pm = mPhone.getContext().getPackageManager();
2988 List<String> privilegedPackages = new ArrayList<>();
2989 List<PackageInfo> packages = null;
2990 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2991 UiccCard card = UiccController.getInstance().getUiccCard(i);
2992 if (card == null) {
2993 // No UICC in that slot.
2994 continue;
2995 }
2996 if (card.hasCarrierPrivilegeRules()) {
2997 if (packages == null) {
2998 // Only check packages in user 0 for now
2999 packages = pm.getInstalledPackagesAsUser(
3000 PackageManager.MATCH_DISABLED_COMPONENTS
3001 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3002 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3003 }
3004 for (int p = packages.size() - 1; p >= 0; p--) {
3005 PackageInfo pkgInfo = packages.get(p);
3006 if (pkgInfo != null && pkgInfo.packageName != null
3007 && card.getCarrierPrivilegeStatus(pkgInfo)
3008 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3009 privilegedPackages.add(pkgInfo.packageName);
3010 }
3011 }
3012 }
3013 }
3014 return privilegedPackages;
3015 }
3016
Wink Savilleb564aae2014-10-23 10:18:09 -07003017 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003018 final Phone phone = getPhone(subId);
3019 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003020 if (card == null) {
3021 loge("getIccId: No UICC");
3022 return null;
3023 }
3024 String iccId = card.getIccId();
3025 if (TextUtils.isEmpty(iccId)) {
3026 loge("getIccId: ICC ID is null or empty.");
3027 return null;
3028 }
3029 return iccId;
3030 }
3031
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003032 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003033 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3034 String number) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003035 enforceCarrierPrivilege(subId);
Derek Tan97ebb422014-09-05 16:55:38 -07003036
Jeff Sharkey85190e62014-12-05 09:40:12 -08003037 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003038 final Phone phone = getPhone(subId);
3039 if (phone == null) {
3040 return false;
3041 }
3042 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003043
3044 if (DBG_MERGE) {
3045 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3046 + subscriberId + " to " + number);
3047 }
3048
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003049 if (TextUtils.isEmpty(iccId)) {
3050 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003051 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003052
Jeff Sharkey85190e62014-12-05 09:40:12 -08003053 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3054
3055 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003056 if (alphaTag == null) {
3057 editor.remove(alphaTagPrefKey);
3058 } else {
3059 editor.putString(alphaTagPrefKey, alphaTag);
3060 }
3061
Jeff Sharkey85190e62014-12-05 09:40:12 -08003062 // Record both the line number and IMSI for this ICCID, since we need to
3063 // track all merged IMSIs based on line number
3064 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3065 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003066 if (number == null) {
3067 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003068 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003069 } else {
3070 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003071 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003072 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003073
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003074 editor.commit();
3075 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003076 }
3077
3078 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003079 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003080 // This is open to apps with WRITE_SMS.
3081 if (!canReadPhoneNumber(callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003082 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003083 return null;
3084 }
Derek Tan97ebb422014-09-05 16:55:38 -07003085
3086 String iccId = getIccId(subId);
3087 if (iccId != null) {
3088 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003089 if (DBG_MERGE) {
3090 log("getLine1NumberForDisplay returning " +
3091 mTelephonySharedPreferences.getString(numberPrefKey, null));
3092 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003093 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003094 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003095 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003096 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003097 }
3098
3099 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003100 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
3101 if (!canReadPhoneState(callingPackage, "getLine1AlphaTagForDisplay")) {
3102 return null;
3103 }
Derek Tan97ebb422014-09-05 16:55:38 -07003104
3105 String iccId = getIccId(subId);
3106 if (iccId != null) {
3107 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003108 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003109 }
Derek Tan97ebb422014-09-05 16:55:38 -07003110 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003111 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003112
3113 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003114 public String[] getMergedSubscriberIds(String callingPackage) {
3115 if (!canReadPhoneState(callingPackage, "getMergedSubscriberIds")) {
3116 return null;
3117 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003118 final Context context = mPhone.getContext();
3119 final TelephonyManager tele = TelephonyManager.from(context);
3120 final SubscriptionManager sub = SubscriptionManager.from(context);
3121
3122 // Figure out what subscribers are currently active
3123 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003124 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3125 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3126 final long identity = Binder.clearCallingIdentity();
3127 try {
3128 final int[] subIds = sub.getActiveSubscriptionIdList();
3129 for (int subId : subIds) {
3130 activeSubscriberIds.add(tele.getSubscriberId(subId));
3131 }
3132 } finally {
3133 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003134 }
3135
3136 // First pass, find a number override for an active subscriber
3137 String mergeNumber = null;
3138 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3139 for (String key : prefs.keySet()) {
3140 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3141 final String subscriberId = (String) prefs.get(key);
3142 if (activeSubscriberIds.contains(subscriberId)) {
3143 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3144 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3145 mergeNumber = (String) prefs.get(numberKey);
3146 if (DBG_MERGE) {
3147 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3148 + " for active subscriber " + subscriberId);
3149 }
3150 if (!TextUtils.isEmpty(mergeNumber)) {
3151 break;
3152 }
3153 }
3154 }
3155 }
3156
3157 // Shortcut when no active merged subscribers
3158 if (TextUtils.isEmpty(mergeNumber)) {
3159 return null;
3160 }
3161
3162 // Second pass, find all subscribers under that line override
3163 final ArraySet<String> result = new ArraySet<>();
3164 for (String key : prefs.keySet()) {
3165 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3166 final String number = (String) prefs.get(key);
3167 if (mergeNumber.equals(number)) {
3168 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3169 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3170 final String subscriberId = (String) prefs.get(subscriberKey);
3171 if (!TextUtils.isEmpty(subscriberId)) {
3172 result.add(subscriberId);
3173 }
3174 }
3175 }
3176 }
3177
3178 final String[] resultArray = result.toArray(new String[result.size()]);
3179 Arrays.sort(resultArray);
3180 if (DBG_MERGE) {
3181 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3182 }
3183 return resultArray;
3184 }
3185
3186 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003187 public boolean setOperatorBrandOverride(int subId, String brand) {
3188 enforceCarrierPrivilege(subId);
3189 final Phone phone = getPhone(subId);
3190 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003191 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003192
3193 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003194 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003195 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3196 List<String> cdmaNonRoamingList) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003197 enforceCarrierPrivilege(subId);
3198 final Phone phone = getPhone(subId);
3199 if (phone == null) {
3200 return false;
3201 }
3202 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003203 cdmaNonRoamingList);
3204 }
3205
3206 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003207 public void setRadioCapability(RadioAccessFamily[] rafs) {
3208 try {
3209 ProxyController.getInstance().setRadioCapability(rafs);
3210 } catch (RuntimeException e) {
3211 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3212 }
3213 }
3214
3215 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003216 public int getRadioAccessFamily(int phoneId, String callingPackage) {
3217 if (!canReadPhoneState(callingPackage, "getRadioAccessFamily")) {
3218 return RadioAccessFamily.RAF_UNKNOWN;
3219 }
3220
Wink Saville5d475dd2014-10-17 15:00:58 -07003221 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3222 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003223
3224 @Override
3225 public void enableVideoCalling(boolean enable) {
3226 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003227 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003228 }
3229
3230 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003231 public boolean isVideoCallingEnabled(String callingPackage) {
3232 if (!canReadPhoneState(callingPackage, "isVideoCallingEnabled")) {
3233 return false;
3234 }
3235
Andrew Lee77527ac2014-10-21 16:57:39 -07003236 // Check the user preference and the system-level IMS setting. Even if the user has
3237 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3238 // In the long run, we may instead need to check if there exists a connection service
3239 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003240 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3241 return imsManager.isVtEnabledByPlatform()
3242 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3243 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003244 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003245
Andrew Leea1239f22015-03-02 17:44:07 -08003246 @Override
3247 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003248 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003249 }
3250
3251 @Override
3252 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003253 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003254 }
3255
Andrew Lee9431b832015-03-09 18:46:45 -07003256 @Override
3257 public boolean isTtyModeSupported() {
3258 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3259 TelephonyManager telephonyManager =
3260 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003261 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003262 }
3263
3264 @Override
3265 public boolean isHearingAidCompatibilitySupported() {
3266 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3267 }
3268
Sanket Padawe7310cc72015-01-14 09:53:20 -08003269 /**
3270 * Returns the unique device ID of phone, for example, the IMEI for
3271 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3272 *
3273 * <p>Requires Permission:
3274 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3275 */
3276 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003277 public String getDeviceId(String callingPackage) {
3278 if (!canReadPhoneState(callingPackage, "getDeviceId")) {
3279 return null;
3280 }
3281
Sanket Padawe7310cc72015-01-14 09:53:20 -08003282 final Phone phone = PhoneFactory.getPhone(0);
3283 if (phone != null) {
3284 return phone.getDeviceId();
3285 } else {
3286 return null;
3287 }
3288 }
3289
Ping Sun014fe8e2016-03-02 19:16:45 +08003290 /**
3291 * {@hide}
3292 * Returns the IMS Registration Status on a particular subid
3293 *
3294 * @param subId
3295 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003296 public boolean isImsRegistered(int subId) {
Ping Sun014fe8e2016-03-02 19:16:45 +08003297 Phone phone = getPhone(subId);
3298 if (phone != null) {
3299 return phone.isImsRegistered();
3300 } else {
3301 return false;
3302 }
3303 }
3304
Santos Cordon7a1885b2015-02-03 11:15:19 -08003305 @Override
3306 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3307 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3308 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003309
Brad Ebingere21f25f2018-02-08 16:11:32 -08003310 /**
3311 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003312 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003313 public boolean isWifiCallingAvailable(int subId) {
3314 Phone phone = getPhone(subId);
3315 if (phone != null) {
3316 return phone.isWifiCallingEnabled();
3317 } else {
3318 return false;
3319 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003320 }
3321
Brad Ebingere21f25f2018-02-08 16:11:32 -08003322 /**
3323 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003324 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003325 public boolean isVolteAvailable(int subId) {
3326 Phone phone = getPhone(subId);
3327 if (phone != null) {
3328 return phone.isVolteEnabled();
3329 } else {
3330 return false;
3331 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003332 }
Svet Ganovb320e182015-04-16 12:30:10 -07003333
Brad Ebingere21f25f2018-02-08 16:11:32 -08003334 /**
3335 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003336 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003337 public boolean isVideoTelephonyAvailable(int subId) {
3338 Phone phone = getPhone(subId);
3339 if (phone != null) {
3340 return phone.isVideoEnabled();
3341 } else {
3342 return false;
3343 }
3344 }
3345
3346 /**
3347 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3348 * defined in {@link ImsRegistrationImplBase}.
3349 */
3350 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3351 Phone phone = getPhone(subId);
3352 if (phone != null) {
3353 return phone.getImsRegistrationTech();
3354 } else {
3355 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3356 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003357 }
3358
Svet Ganovb320e182015-04-16 12:30:10 -07003359 private boolean canReadPhoneState(String callingPackage, String message) {
Etan Cohen921655c2015-06-24 13:54:50 -07003360 try {
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003361 mApp.enforceCallingOrSelfPermission(
Etan Cohen921655c2015-06-24 13:54:50 -07003362 android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, message);
3363
Amit Mahajan83ea23b2015-07-30 16:05:11 -07003364 // SKIP checking for run-time permission since caller or self has PRIVILEDGED permission
Etan Cohen921655c2015-06-24 13:54:50 -07003365 return true;
Amit Mahajan785783f2015-06-29 10:36:50 -07003366 } catch (SecurityException e) {
3367 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
3368 message);
Etan Cohen921655c2015-06-24 13:54:50 -07003369 }
Svet Ganovb320e182015-04-16 12:30:10 -07003370
3371 if (mAppOps.noteOp(AppOpsManager.OP_READ_PHONE_STATE, Binder.getCallingUid(),
3372 callingPackage) != AppOpsManager.MODE_ALLOWED) {
3373 return false;
3374 }
3375
3376 return true;
3377 }
Stuart Scott8eef64f2015-04-08 15:13:54 -07003378
Makoto Onukifee69342015-06-29 14:44:50 -07003379 /**
Amit Mahajanb9b49782015-09-15 18:16:32 -07003380 * Besides READ_PHONE_STATE, WRITE_SMS and READ_SMS also allow apps to get phone numbers.
Makoto Onukifee69342015-06-29 14:44:50 -07003381 */
3382 private boolean canReadPhoneNumber(String callingPackage, String message) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003383 // Default SMS app can always read it.
3384 if (mAppOps.noteOp(AppOpsManager.OP_WRITE_SMS,
3385 Binder.getCallingUid(), callingPackage) == AppOpsManager.MODE_ALLOWED) {
3386 return true;
3387 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003388
Makoto Onukie4072d12015-08-03 15:12:23 -07003389 try {
3390 return canReadPhoneState(callingPackage, message);
Amit Mahajanb9b49782015-09-15 18:16:32 -07003391 } catch (SecurityException readPhoneStateSecurityException) {
Makoto Onukie4072d12015-08-03 15:12:23 -07003392 }
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003393 // Can be read with READ_SMS too.
3394 try {
3395 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_SMS, message);
3396 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_SMS);
3397 if (opCode != AppOpsManager.OP_NONE) {
3398 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3399 == AppOpsManager.MODE_ALLOWED;
3400 } else {
3401 return true;
3402 }
3403 } catch (SecurityException readSmsSecurityException) {
3404 }
Chad Brubakerf342a982017-03-30 16:27:34 -07003405 // Can be read with READ_PHONE_NUMBERS too.
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003406 try {
Chad Brubakerf342a982017-03-30 16:27:34 -07003407 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_NUMBERS,
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003408 message);
Chad Brubakerf342a982017-03-30 16:27:34 -07003409 int opCode = mAppOps.permissionToOpCode(android.Manifest.permission.READ_PHONE_NUMBERS);
Chad Brubaker7a8fba22016-11-10 11:23:18 -08003410 if (opCode != AppOpsManager.OP_NONE) {
3411 return mAppOps.noteOp(opCode, Binder.getCallingUid(), callingPackage)
3412 == AppOpsManager.MODE_ALLOWED;
3413 } else {
3414 return true;
3415 }
3416 } catch (SecurityException readPhoneNumberSecurityException) {
3417 }
3418
3419 throw new SecurityException(message + ": Neither user " + Binder.getCallingUid() +
3420 " nor current process has" + android.Manifest.permission.READ_PHONE_STATE +
3421 ", " + android.Manifest.permission.READ_SMS + ", or " +
Chad Brubakerf342a982017-03-30 16:27:34 -07003422 android.Manifest.permission.READ_PHONE_NUMBERS);
Makoto Onukifee69342015-06-29 14:44:50 -07003423 }
3424
Stuart Scott8eef64f2015-04-08 15:13:54 -07003425 @Override
3426 public void factoryReset(int subId) {
3427 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003428 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3429 return;
3430 }
3431
Svet Ganovcc087f82015-05-12 20:35:54 -07003432 final long identity = Binder.clearCallingIdentity();
3433 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003434 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3435 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003436 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003437 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003438 // Set network selection mode to automatic
3439 setNetworkSelectionModeAutomatic(subId);
3440 // Set preferred mobile network type to the best available
3441 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3442 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003443 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003444 }
3445 } finally {
3446 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003447 }
3448 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003449
3450 @Override
3451 public String getLocaleFromDefaultSim() {
3452 // We query all subscriptions instead of just the active ones, because
3453 // this might be called early on in the provisioning flow when the
3454 // subscriptions potentially aren't active yet.
3455 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3456 if (slist == null || slist.isEmpty()) {
3457 return null;
3458 }
3459
3460 // This function may be called very early, say, from the setup wizard, at
3461 // which point we won't have a default subscription set. If that's the case
3462 // we just choose the first, which will be valid in "most cases".
3463 final int defaultSubId = getDefaultSubscription();
3464 SubscriptionInfo info = null;
3465 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3466 info = slist.get(0);
3467 } else {
3468 for (SubscriptionInfo item : slist) {
3469 if (item.getSubscriptionId() == defaultSubId) {
3470 info = item;
3471 break;
3472 }
3473 }
3474
3475 if (info == null) {
3476 return null;
3477 }
3478 }
3479
3480 // Try and fetch the locale from the carrier properties or from the SIM language
3481 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003482 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003483 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003484 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003485 if (defaultPhone != null) {
3486 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3487 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003488 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003489 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3490 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003491 } else {
3492 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003493 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003494 }
3495 }
3496
Narayan Kamath011676f2015-07-29 12:04:08 +01003497 // The SIM language preferences only store a language (e.g. fr = French), not an
3498 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3499 // the SIM and carrier preferences does not include a country we add the country
3500 // determined from the SIM MCC to provide an exact locale.
3501 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003502 if (mccLocale != null) {
3503 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3504 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003505 }
3506
Tony Hill183b2de2015-06-24 14:53:58 +01003507 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003508 return null;
3509 }
3510
3511 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3512 final long identity = Binder.clearCallingIdentity();
3513 try {
3514 return mSubscriptionController.getAllSubInfoList(
3515 mPhone.getContext().getOpPackageName());
3516 } finally {
3517 Binder.restoreCallingIdentity(identity);
3518 }
3519 }
3520
3521 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3522 final long identity = Binder.clearCallingIdentity();
3523 try {
3524 return mSubscriptionController.getActiveSubscriptionInfoList(
3525 mPhone.getContext().getOpPackageName());
3526 } finally {
3527 Binder.restoreCallingIdentity(identity);
3528 }
3529 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003530
3531 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003532 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3533 * representing the state of the modem.
3534 *
3535 * NOTE: This clears the modem state, so there should only every be one caller.
3536 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003537 */
3538 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003539 public void requestModemActivityInfo(ResultReceiver result) {
3540 enforceModifyPermission();
3541
3542 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3543 Bundle bundle = new Bundle();
3544 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3545 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003546 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003547
3548 /**
3549 * {@hide}
3550 * Returns the service state information on specified subscription.
3551 */
3552 @Override
3553 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3554
3555 if (!canReadPhoneState(callingPackage, "getServiceStateForSubscriber")) {
3556 return null;
3557 }
3558
3559 final Phone phone = getPhone(subId);
3560 if (phone == null) {
3561 return null;
3562 }
3563
3564 return phone.getServiceState();
3565 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003566
3567 /**
3568 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3569 *
3570 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3571 * voicemail ringtone.
3572 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3573 * PhoneAccount.
3574 */
3575 @Override
3576 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003577 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003578 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003579 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003580 }
3581
fionaxu7ed723d2017-05-30 18:58:54 -07003582 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003583 }
3584
3585 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003586 * Sets the per-account voicemail ringtone.
3587 *
3588 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3589 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3590 *
3591 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3592 * voicemail ringtone.
3593 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3594 * PhoneAccount.
3595 */
3596 @Override
3597 public void setVoicemailRingtoneUri(String callingPackage,
3598 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3599 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3600 if (!TextUtils.equals(callingPackage,
3601 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3602 enforceModifyPermissionOrCarrierPrivilege(
3603 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3604 }
3605 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3606 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003607 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003608 }
fionaxu7ed723d2017-05-30 18:58:54 -07003609 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003610 }
3611
3612 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003613 * Returns whether vibration is set for voicemail notification in Phone settings.
3614 *
3615 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3616 * voicemail vibration setting.
3617 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3618 */
3619 @Override
3620 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003621 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003622 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003623 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003624 }
3625
fionaxu7ed723d2017-05-30 18:58:54 -07003626 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003627 }
3628
Youhan Wange64578a2016-05-02 15:32:42 -07003629 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003630 * Sets the per-account voicemail vibration.
3631 *
3632 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3633 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3634 *
3635 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3636 * voicemail vibration setting.
3637 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3638 * specific PhoneAccount.
3639 */
3640 @Override
3641 public void setVoicemailVibrationEnabled(String callingPackage,
3642 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3643 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3644 if (!TextUtils.equals(callingPackage,
3645 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
3646 enforceModifyPermissionOrCarrierPrivilege(
3647 PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle));
3648 }
3649
3650 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3651 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003652 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003653 }
fionaxu7ed723d2017-05-30 18:58:54 -07003654 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003655 }
3656
3657 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003658 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3659 *
3660 * @throws SecurityException if the caller does not have the required permission
3661 */
3662 private void enforceReadPrivilegedPermission() {
3663 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3664 null);
3665 }
3666
3667 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003668 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3669 * permission.
3670 *
3671 * @throws SecurityException if the caller does not have the required permission
3672 */
3673 private void enforceSendSmsPermission() {
3674 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3675 }
3676
3677 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003678 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003679 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003680 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003681 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003682 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003683 ComponentName componentName =
3684 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3685 if(componentName == null) {
3686 throw new SecurityException("Caller not current active visual voicemail package[null]");
3687 }
3688 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003689 if (!callingPackage.equals(vvmPackage)) {
3690 throw new SecurityException("Caller not current active visual voicemail package[" +
3691 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003692 }
3693 }
3694
3695 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003696 * Return the application ID for the app type.
3697 *
3698 * @param subId the subscription ID that this request applies to.
3699 * @param appType the uicc app type.
3700 * @return Application ID for specificied app type, or null if no uicc.
3701 */
3702 @Override
3703 public String getAidForAppType(int subId, int appType) {
3704 enforceReadPrivilegedPermission();
3705 Phone phone = getPhone(subId);
3706 if (phone == null) {
3707 return null;
3708 }
3709 String aid = null;
3710 try {
3711 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3712 .getApplicationByType(appType).getAid();
3713 } catch (Exception e) {
3714 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3715 }
3716 return aid;
3717 }
3718
Youhan Wang4001d252016-05-11 10:29:41 -07003719 /**
3720 * Return the Electronic Serial Number.
3721 *
3722 * @param subId the subscription ID that this request applies to.
3723 * @return ESN or null if error.
3724 */
3725 @Override
3726 public String getEsn(int subId) {
3727 enforceReadPrivilegedPermission();
3728 Phone phone = getPhone(subId);
3729 if (phone == null) {
3730 return null;
3731 }
3732 String esn = null;
3733 try {
3734 esn = phone.getEsn();
3735 } catch (Exception e) {
3736 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3737 }
3738 return esn;
3739 }
3740
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003741 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003742 * Return the Preferred Roaming List Version.
3743 *
3744 * @param subId the subscription ID that this request applies to.
3745 * @return PRLVersion or null if error.
3746 */
3747 @Override
3748 public String getCdmaPrlVersion(int subId) {
3749 enforceReadPrivilegedPermission();
3750 Phone phone = getPhone(subId);
3751 if (phone == null) {
3752 return null;
3753 }
3754 String cdmaPrlVersion = null;
3755 try {
3756 cdmaPrlVersion = phone.getCdmaPrlVersion();
3757 } catch (Exception e) {
3758 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3759 }
3760 return cdmaPrlVersion;
3761 }
3762
3763 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003764 * Get snapshot of Telephony histograms
3765 * @return List of Telephony histograms
3766 * @hide
3767 */
3768 @Override
3769 public List<TelephonyHistogram> getTelephonyHistograms() {
3770 enforceModifyPermissionOrCarrierPrivilege(getDefaultSubscription());
3771 return RIL.getTelephonyRILTimingHistograms();
3772 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003773
3774 /**
3775 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003776 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003777 * Require system privileges. In the future we may add this to carrier APIs.
3778 *
3779 * @return The number of carriers set successfully, should match length of carriers
3780 */
3781 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003782 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003783 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003784
Meng Wang9b7c4e92017-02-17 11:41:27 -08003785 if (carriers == null) {
3786 throw new NullPointerException("carriers cannot be null");
3787 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003788
3789 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003790 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3791 return retVal[0];
3792 }
3793
3794 /**
3795 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003796 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003797 * Require system privileges. In the future we may add this to carrier APIs.
3798 *
3799 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3800 * means all carriers are allowed.
3801 */
3802 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003803 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003804 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003805 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003806 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3807 }
3808
fionaxu59545b42016-05-25 15:53:37 -07003809 /**
3810 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3811 * @param subId the subscription ID that this action applies to.
3812 * @param enabled control enable or disable metered apns.
3813 * {@hide}
3814 */
3815 @Override
3816 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3817 enforceModifyPermission();
3818 final Phone phone = getPhone(subId);
3819 if (phone == null) {
3820 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3821 return;
3822 }
3823 try {
3824 phone.carrierActionSetMeteredApnsEnabled(enabled);
3825 } catch (Exception e) {
3826 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3827 }
3828 }
3829
3830 /**
3831 * Action set from carrier signalling broadcast receivers to enable/disable radio
3832 * @param subId the subscription ID that this action applies to.
3833 * @param enabled control enable or disable radio.
3834 * {@hide}
3835 */
3836 @Override
3837 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3838 enforceModifyPermission();
3839 final Phone phone = getPhone(subId);
3840 if (phone == null) {
3841 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3842 return;
3843 }
3844 try {
3845 phone.carrierActionSetRadioEnabled(enabled);
3846 } catch (Exception e) {
3847 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3848 }
3849 }
3850
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003851 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003852 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3853 * network status based on which carrier apps could apply actions accordingly,
3854 * enable/disable default url handler for example.
3855 *
3856 * @param subId the subscription ID that this action applies to.
3857 * @param report control start/stop reporting the default network status.
3858 * {@hide}
3859 */
3860 @Override
3861 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3862 enforceModifyPermission();
3863 final Phone phone = getPhone(subId);
3864 if (phone == null) {
3865 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3866 return;
3867 }
3868 try {
3869 phone.carrierActionReportDefaultNetworkStatus(report);
3870 } catch (Exception e) {
3871 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3872 }
3873 }
3874
3875 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003876 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3877 * bug report is being generated.
3878 */
3879 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003880 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003881 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3882 != PackageManager.PERMISSION_GRANTED) {
3883 writer.println("Permission Denial: can't dump Phone from pid="
3884 + Binder.getCallingPid()
3885 + ", uid=" + Binder.getCallingUid()
3886 + "without permission "
3887 + android.Manifest.permission.DUMP);
3888 return;
3889 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003890 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003891 }
Jack Yueb89b242016-06-22 13:27:47 -07003892
3893 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003894 * Get aggregated video call data usage since boot.
3895 *
3896 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3897 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003898 * {@hide}
3899 */
3900 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003901 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003902 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3903 null);
3904
Jack Yu84291ec2017-05-26 16:07:50 -07003905 // NetworkStatsService keeps tracking the active network interface and identity. It
3906 // records the delta with the corresponding network identity. We just return the total video
3907 // call data usage snapshot since boot.
3908 Phone phone = getPhone(subId);
3909 if (phone != null) {
3910 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003911 }
Jack Yu84291ec2017-05-26 16:07:50 -07003912 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003913 }
Jack Yu75ab2952016-07-08 14:29:33 -07003914
3915 /**
3916 * Policy control of data connection. Usually used when data limit is passed.
3917 * @param enabled True if enabling the data, otherwise disabling.
3918 * @param subId Subscription index
3919 * {@hide}
3920 */
3921 @Override
3922 public void setPolicyDataEnabled(boolean enabled, int subId) {
3923 enforceModifyPermission();
3924 Phone phone = getPhone(subId);
3925 if (phone != null) {
3926 phone.setPolicyDataEnabled(enabled);
3927 }
3928 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003929
3930 /**
3931 * Get Client request stats
3932 * @return List of Client Request Stats
3933 * @hide
3934 */
3935 @Override
3936 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
3937 if (!canReadPhoneState(callingPackage, "getClientRequestStats")) {
3938 return null;
3939 }
3940
3941 Phone phone = getPhone(subId);
3942 if (phone != null) {
3943 return phone.getClientRequestStats();
3944 }
3945
3946 return null;
3947 }
3948
3949 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3950 if (workSource != null) {
3951 return workSource;
3952 }
3953
3954 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3955 workSource = new WorkSource(uid, packageName);
3956 return workSource;
3957 }
Jack Yueb4124c2017-02-16 15:32:43 -08003958
3959 /**
Grace Chen70990072017-03-24 17:21:30 -07003960 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003961 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003962 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003963 * @param state State of SIM (power down, power up, pass through)
3964 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3965 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3966 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003967 *
3968 **/
3969 @Override
Grace Chen70990072017-03-24 17:21:30 -07003970 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003971 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003972 Phone phone = PhoneFactory.getPhone(slotIndex);
3973
Jack Yueb4124c2017-02-16 15:32:43 -08003974 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003975 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003976 }
3977 }
Shuo Qiandd210312017-04-12 22:11:33 +00003978
Tyler Gunn65d45c22017-06-05 11:22:26 -07003979 private boolean isUssdApiAllowed(int subId) {
3980 CarrierConfigManager configManager =
3981 (CarrierConfigManager) mPhone.getContext().getSystemService(
3982 Context.CARRIER_CONFIG_SERVICE);
3983 if (configManager == null) {
3984 return false;
3985 }
3986 PersistableBundle pb = configManager.getConfigForSubId(subId);
3987 if (pb == null) {
3988 return false;
3989 }
3990 return pb.getBoolean(
3991 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
3992 }
3993
Shuo Qiandd210312017-04-12 22:11:33 +00003994 /**
3995 * Check if phone is in emergency callback mode
3996 * @return true if phone is in emergency callback mode
3997 * @param subId sub id
3998 */
3999 public boolean getEmergencyCallbackMode(int subId) {
4000 final Phone phone = getPhone(subId);
4001 if (phone != null) {
4002 return phone.isInEcm();
4003 } else {
4004 return false;
4005 }
4006 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004007
4008 /**
4009 * Get the current signal strength information for the given subscription.
4010 * Because this information is not updated when the device is in a low power state
4011 * it should not be relied-upon to be current.
4012 * @param subId Subscription index
4013 * @return the most recent cached signal strength info from the modem
4014 */
4015 @Override
4016 public SignalStrength getSignalStrength(int subId) {
4017 Phone p = getPhone(subId);
4018 if (p == null) {
4019 return null;
4020 }
4021
4022 return p.getSignalStrength();
4023 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004024
4025 @Override
4026 public UiccSlotInfo[] getUiccSlotsInfo() {
4027 enforceReadPrivilegedPermission();
4028
4029 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4030 if (slots == null) return null;
4031 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4032 for (int i = 0; i < slots.length; i++) {
4033 UiccSlot slot = slots[i];
4034
4035 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4036
4037 int cardState = 0;
4038 switch (slot.getCardState()) {
4039 case CARDSTATE_ABSENT:
4040 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4041 break;
4042 case CARDSTATE_PRESENT:
4043 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4044 break;
4045 case CARDSTATE_ERROR:
4046 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4047 break;
4048 case CARDSTATE_RESTRICTED:
4049 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4050 break;
4051 default:
4052 break;
4053
4054 }
4055
4056 infos[i] = new UiccSlotInfo(slot.isActive(), slot.isEuicc(), cardId, cardState);
4057 }
4058 return infos;
4059 }
4060
4061 @Override
4062 public boolean switchSlots(int[] physicalSlots) {
4063 enforceModifyPermission();
4064 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4065 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004066}