blob: 0b4e9f161145e0cdabd9c752e043523658c3bc4e [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;
Hall Liu1aa510f2017-11-22 17:40:08 -080058import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070059import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080060import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070061import android.telephony.NetworkScanRequest;
Wink Saville5d475dd2014-10-17 15:00:58 -070062import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070063import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070064import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080065import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070066import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080067import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080068import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070069import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070070import android.telephony.TelephonyManager;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000071import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070072import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070073import android.telephony.VisualVoicemailSmsFilterSettings;
Brad Ebingera12246d2018-01-16 09:39:35 -080074import android.telephony.ims.aidl.IImsConfig;
75import android.telephony.ims.aidl.IImsMmTelFeature;
76import android.telephony.ims.aidl.IImsRcsFeature;
77import android.telephony.ims.aidl.IImsRegistration;
Brad Ebingere21f25f2018-02-08 16:11:32 -080078import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -080080import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -080082import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -080083import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080084
Andrew Lee312e8172014-10-23 17:01:36 -070085import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -080086import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -070087import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -070088import com.android.internal.telephony.CallStateException;
Shishir Agrawal302c8692015-06-19 13:49:39 -070089import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -070090import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import com.android.internal.telephony.DefaultPhoneNotifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -080093import com.android.internal.telephony.IccCard;
Narayan Kamath1c496c22015-04-16 14:40:19 +010094import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -070095import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -070096import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070097import com.android.internal.telephony.Phone;
Nathan Harolda667c152016-12-14 11:27:20 -080098import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -070099import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700100import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700101import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700102import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700103import com.android.internal.telephony.RILConstants;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800104import com.android.internal.telephony.SubscriptionController;
Jeff Davidsond9a1bb52018-02-13 18:17:36 -0800105import com.android.internal.telephony.TelephonyPermissions;
Jonathan Basseri03923952017-07-19 12:22:35 -0700106import com.android.internal.telephony.TelephonyProperties;
Derek Tan740e1672017-06-27 14:56:27 -0700107import com.android.internal.telephony.euicc.EuiccConnector;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700108import com.android.internal.telephony.uicc.IccIoResult;
109import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800110import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700111import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800112import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700113import com.android.internal.telephony.uicc.UiccController;
Jeff Davidsond9a1bb52018-02-13 18:17:36 -0800114import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000115import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700116import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800117import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700118import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800119import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700120import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700121import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800122
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700123import java.io.FileDescriptor;
124import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800125import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800127import java.util.Arrays;
Jake Hambye994d462014-02-03 13:10:13 -0800128import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100129import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800130import java.util.Map;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131
132/**
133 * Implementation of the ITelephony interface.
134 */
Santos Cordon117fee72014-05-16 17:56:12 -0700135public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136 private static final String LOG_TAG = "PhoneInterfaceManager";
137 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
138 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800139 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140
141 // Message codes used with mMainThreadHandler
142 private static final int CMD_HANDLE_PIN_MMI = 1;
143 private static final int CMD_HANDLE_NEIGHBORING_CELL = 2;
144 private static final int EVENT_NEIGHBORING_CELL_DONE = 3;
145 private static final int CMD_ANSWER_RINGING_CALL = 4;
146 private static final int CMD_END_CALL = 5; // not used yet
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700147 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
148 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149 private static final int CMD_OPEN_CHANNEL = 9;
150 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
151 private static final int CMD_CLOSE_CHANNEL = 11;
152 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800153 private static final int CMD_NV_READ_ITEM = 13;
154 private static final int EVENT_NV_READ_ITEM_DONE = 14;
155 private static final int CMD_NV_WRITE_ITEM = 15;
156 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
157 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
158 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
159 private static final int CMD_NV_RESET_CONFIG = 19;
160 private static final int EVENT_NV_RESET_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800161 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
162 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
163 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
164 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800165 private static final int CMD_SEND_ENVELOPE = 25;
166 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Derek Tan6b088ee2014-09-05 14:15:18 -0700167 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
168 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
169 private static final int CMD_EXCHANGE_SIM_IO = 31;
170 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800171 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
172 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700173 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
174 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700175 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
176 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700177 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
178 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
179 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
180 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700181 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
182 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
183 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
184 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700185 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800186 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
187 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000188 private static final int CMD_SWITCH_SLOTS = 50;
189 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800191 // Parameters of select command.
192 private static final int SELECT_COMMAND = 0xA4;
193 private static final int SELECT_P1 = 0x04;
194 private static final int SELECT_P2 = 0;
195 private static final int SELECT_P3 = 0x10;
196
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197 /** The singleton instance. */
198 private static PhoneInterfaceManager sInstance;
199
Wink Saville3ab207e2014-11-20 13:07:20 -0800200 private PhoneGlobals mApp;
201 private Phone mPhone;
202 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700203 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800204 private AppOpsManager mAppOps;
205 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800206 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800207 private SharedPreferences mTelephonySharedPreferences;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208
Derek Tan97ebb422014-09-05 16:55:38 -0700209 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
210 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800211 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Derek Tan89e89d42014-07-08 17:00:10 -0700212
Derek Tan740e1672017-06-27 14:56:27 -0700213 // The AID of ISD-R.
214 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
215
yinxub1bed742017-04-17 11:45:04 -0700216 private NetworkScanRequestTracker mNetworkScanRequestTracker;
217
Derek Tan89e89d42014-07-08 17:00:10 -0700218 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700219 * A request object to use for transmitting data to an ICC.
220 */
221 private static final class IccAPDUArgument {
222 public int channel, cla, command, p1, p2, p3;
223 public String data;
224
225 public IccAPDUArgument(int channel, int cla, int command,
226 int p1, int p2, int p3, String data) {
227 this.channel = channel;
228 this.cla = cla;
229 this.command = command;
230 this.p1 = p1;
231 this.p2 = p2;
232 this.p3 = p3;
233 this.data = data;
234 }
235 }
236
237 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700238 * A request object to use for transmitting data to an ICC.
239 */
240 private static final class ManualNetworkSelectionArgument {
241 public OperatorInfo operatorInfo;
242 public boolean persistSelection;
243
244 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
245 this.operatorInfo = operatorInfo;
246 this.persistSelection = persistSelection;
247 }
248 }
249
250 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700251 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
252 * request after sending. The main thread will notify the request when it is complete.
253 */
254 private static final class MainThreadRequest {
255 /** The argument to use for the request */
256 public Object argument;
257 /** The result of the request that is run on the main thread */
258 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800259 // The subscriber id that this request applies to. Defaults to
260 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
261 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700262
263 public MainThreadRequest(Object argument) {
264 this.argument = argument;
265 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800266
267 public MainThreadRequest(Object argument, Integer subId) {
268 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800269 if (subId != null) {
270 this.subId = subId;
271 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700273 }
274
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800275 private static final class IncomingThirdPartyCallArgs {
276 public final ComponentName component;
277 public final String callId;
278 public final String callerDisplayName;
279
280 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
281 String callerDisplayName) {
282 this.component = component;
283 this.callId = callId;
284 this.callerDisplayName = callerDisplayName;
285 }
286 }
287
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700288 /**
289 * A handler that processes messages on the main thread in the phone process. Since many
290 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
291 * inbound binder threads to the main thread in the phone process. The Binder thread
292 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
293 * on, which will be notified when the operation completes and will contain the result of the
294 * request.
295 *
296 * <p>If a MainThreadRequest object is provided in the msg.obj field,
297 * note that request.result must be set to something non-null for the calling thread to
298 * unblock.
299 */
300 private final class MainThreadHandler extends Handler {
301 @Override
302 public void handleMessage(Message msg) {
303 MainThreadRequest request;
304 Message onCompleted;
305 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800306 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700307 IccAPDUArgument iccArgument;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700308
309 switch (msg.what) {
pkanwar32d516d2016-10-14 19:37:38 -0700310 case CMD_HANDLE_USSD_REQUEST: {
311 request = (MainThreadRequest) msg.obj;
312 final Phone phone = getPhoneFromRequest(request);
313 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
314 String ussdRequest = ussdObject.first;
315 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700316
317 if (!isUssdApiAllowed(request.subId)) {
318 // Carrier does not support use of this API, return failure.
319 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
320 UssdResponse response = new UssdResponse(ussdRequest, null);
321 Bundle returnData = new Bundle();
322 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
323 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
324
325 request.result = true;
326 synchronized (request) {
327 request.notifyAll();
328 }
329 return;
330 }
331
Tyler Gunn52dcf772017-04-26 11:30:31 -0700332 try {
333 request.result = phone != null ?
334 phone.handleUssdRequest(ussdRequest, wrappedCallback)
335 : false;
336 } catch (CallStateException cse) {
337 request.result = false;
338 }
pkanwar32d516d2016-10-14 19:37:38 -0700339 // Wake up the requesting thread
340 synchronized (request) {
341 request.notifyAll();
342 }
343 break;
344 }
345
Yorke Lee716f67e2015-06-17 15:39:16 -0700346 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700348 final Phone phone = getPhoneFromRequest(request);
349 request.result = phone != null ?
350 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
351 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352 // Wake up the requesting thread
353 synchronized (request) {
354 request.notifyAll();
355 }
356 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700358
359 case CMD_HANDLE_NEIGHBORING_CELL:
360 request = (MainThreadRequest) msg.obj;
361 onCompleted = obtainMessage(EVENT_NEIGHBORING_CELL_DONE,
362 request);
Sooraj Sasindran9a909312016-07-18 11:57:25 -0700363 mPhone.getNeighboringCids(onCompleted, (WorkSource)request.argument);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700364 break;
365
366 case EVENT_NEIGHBORING_CELL_DONE:
367 ar = (AsyncResult) msg.obj;
368 request = (MainThreadRequest) ar.userObj;
369 if (ar.exception == null && ar.result != null) {
370 request.result = ar.result;
371 } else {
372 // create an empty list to notify the waiting thread
Jake Hambye994d462014-02-03 13:10:13 -0800373 request.result = new ArrayList<NeighboringCellInfo>(0);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 }
375 // Wake up the requesting thread
376 synchronized (request) {
377 request.notifyAll();
378 }
379 break;
380
381 case CMD_ANSWER_RINGING_CALL:
Wink Saville08874612014-08-31 19:19:58 -0700382 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800383 int answer_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700384 answerRingingCallInternal(answer_subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 break;
386
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700387 case CMD_END_CALL:
388 request = (MainThreadRequest) msg.obj;
Stuart Scott584921c2015-01-15 17:10:34 -0800389 int end_subId = request.subId;
Wink Saville08874612014-08-31 19:19:58 -0700390 final boolean hungUp;
Anthony Leeae4e36d2015-05-21 07:17:46 -0700391 Phone phone = getPhone(end_subId);
392 if (phone == null) {
393 if (DBG) log("CMD_END_CALL: no phone for id: " + end_subId);
394 break;
395 }
396 int phoneType = phone.getPhoneType();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700397 if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
398 // CDMA: If the user presses the Power button we treat it as
399 // ending the complete call session
Wink Saville08874612014-08-31 19:19:58 -0700400 hungUp = PhoneUtils.hangupRingingAndActive(getPhone(end_subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
402 // GSM: End the call as per the Phone state
403 hungUp = PhoneUtils.hangup(mCM);
404 } else {
405 throw new IllegalStateException("Unexpected phone type: " + phoneType);
406 }
407 if (DBG) log("CMD_END_CALL: " + (hungUp ? "hung up!" : "no call to hang up"));
408 request.result = hungUp;
409 // Wake up the requesting thread
410 synchronized (request) {
411 request.notifyAll();
412 }
413 break;
414
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700415 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700416 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700417 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800418 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700419 if (uiccCard == null) {
420 loge("iccTransmitApduLogicalChannel: No UICC");
421 request.result = new IccIoResult(0x6F, 0, (byte[])null);
422 synchronized (request) {
423 request.notifyAll();
424 }
425 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700426 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
427 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700428 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700429 iccArgument.channel, iccArgument.cla, iccArgument.command,
430 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700431 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700432 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 break;
434
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700435 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 ar = (AsyncResult) msg.obj;
437 request = (MainThreadRequest) ar.userObj;
438 if (ar.exception == null && ar.result != null) {
439 request.result = ar.result;
440 } else {
441 request.result = new IccIoResult(0x6F, 0, (byte[])null);
442 if (ar.result == null) {
443 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800444 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700445 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800446 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 } else {
448 loge("iccTransmitApduLogicalChannel: Unknown exception");
449 }
450 }
451 synchronized (request) {
452 request.notifyAll();
453 }
454 break;
455
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700456 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
457 request = (MainThreadRequest) msg.obj;
458 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800459 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 if (uiccCard == null) {
461 loge("iccTransmitApduBasicChannel: No UICC");
462 request.result = new IccIoResult(0x6F, 0, (byte[])null);
463 synchronized (request) {
464 request.notifyAll();
465 }
466 } else {
467 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
468 request);
469 uiccCard.iccTransmitApduBasicChannel(
470 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
471 iccArgument.p3, iccArgument.data, onCompleted);
472 }
473 break;
474
475 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
476 ar = (AsyncResult) msg.obj;
477 request = (MainThreadRequest) ar.userObj;
478 if (ar.exception == null && ar.result != null) {
479 request.result = ar.result;
480 } else {
481 request.result = new IccIoResult(0x6F, 0, (byte[])null);
482 if (ar.result == null) {
483 loge("iccTransmitApduBasicChannel: Empty response");
484 } else if (ar.exception instanceof CommandException) {
485 loge("iccTransmitApduBasicChannel: CommandException: " +
486 ar.exception);
487 } else {
488 loge("iccTransmitApduBasicChannel: Unknown exception");
489 }
490 }
491 synchronized (request) {
492 request.notifyAll();
493 }
494 break;
495
496 case CMD_EXCHANGE_SIM_IO:
497 request = (MainThreadRequest) msg.obj;
498 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800499 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 if (uiccCard == null) {
501 loge("iccExchangeSimIO: No UICC");
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
503 synchronized (request) {
504 request.notifyAll();
505 }
506 } else {
507 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
508 request);
509 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
510 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
511 iccArgument.data, onCompleted);
512 }
513 break;
514
515 case EVENT_EXCHANGE_SIM_IO_DONE:
516 ar = (AsyncResult) msg.obj;
517 request = (MainThreadRequest) ar.userObj;
518 if (ar.exception == null && ar.result != null) {
519 request.result = ar.result;
520 } else {
521 request.result = new IccIoResult(0x6f, 0, (byte[])null);
522 }
523 synchronized (request) {
524 request.notifyAll();
525 }
526 break;
527
Derek Tan4d5e5c12014-02-04 11:54:58 -0800528 case CMD_SEND_ENVELOPE:
529 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800530 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700531 if (uiccCard == null) {
532 loge("sendEnvelopeWithStatus: No UICC");
533 request.result = new IccIoResult(0x6F, 0, (byte[])null);
534 synchronized (request) {
535 request.notifyAll();
536 }
537 } else {
538 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
539 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
540 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800541 break;
542
543 case EVENT_SEND_ENVELOPE_DONE:
544 ar = (AsyncResult) msg.obj;
545 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700546 if (ar.exception == null && ar.result != null) {
547 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800548 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
550 if (ar.result == null) {
551 loge("sendEnvelopeWithStatus: Empty response");
552 } else if (ar.exception instanceof CommandException) {
553 loge("sendEnvelopeWithStatus: CommandException: " +
554 ar.exception);
555 } else {
556 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
557 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800558 }
559 synchronized (request) {
560 request.notifyAll();
561 }
562 break;
563
Shishir Agrawal566b7612013-10-28 14:41:00 -0700564 case CMD_OPEN_CHANNEL:
565 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800566 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800567 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700568 if (uiccCard == null) {
569 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800570 request.result = new IccOpenLogicalChannelResponse(-1,
571 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700572 synchronized (request) {
573 request.notifyAll();
574 }
575 } else {
576 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800577 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
578 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 break;
581
582 case EVENT_OPEN_CHANNEL_DONE:
583 ar = (AsyncResult) msg.obj;
584 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 int[] result = (int[]) ar.result;
588 int channelId = result[0];
589 byte[] selectResponse = null;
590 if (result.length > 1) {
591 selectResponse = new byte[result.length - 1];
592 for (int i = 1; i < result.length; ++i) {
593 selectResponse[i - 1] = (byte) result[i];
594 }
595 }
596 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700597 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 if (ar.result == null) {
600 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 if (ar.exception != null) {
603 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
604 }
605
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700606 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700607 if (ar.exception instanceof CommandException) {
608 CommandException.Error error =
609 ((CommandException) (ar.exception)).getCommandError();
610 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700611 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700612 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 }
615 }
616 openChannelResp = new IccOpenLogicalChannelResponse(
617 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700619 request.result = openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 synchronized (request) {
621 request.notifyAll();
622 }
623 break;
624
625 case CMD_CLOSE_CHANNEL:
626 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800627 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700628 if (uiccCard == null) {
629 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900630 request.result = false;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 synchronized (request) {
632 request.notifyAll();
633 }
634 } else {
635 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
636 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
637 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 break;
639
640 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800641 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
642 break;
643
644 case CMD_NV_READ_ITEM:
645 request = (MainThreadRequest) msg.obj;
646 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
647 mPhone.nvReadItem((Integer) request.argument, onCompleted);
648 break;
649
650 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 ar = (AsyncResult) msg.obj;
652 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800653 if (ar.exception == null && ar.result != null) {
654 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800656 request.result = "";
657 if (ar.result == null) {
658 loge("nvReadItem: Empty response");
659 } else if (ar.exception instanceof CommandException) {
660 loge("nvReadItem: CommandException: " +
661 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800663 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 }
665 }
666 synchronized (request) {
667 request.notifyAll();
668 }
669 break;
670
Jake Hambye994d462014-02-03 13:10:13 -0800671 case CMD_NV_WRITE_ITEM:
672 request = (MainThreadRequest) msg.obj;
673 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
674 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
675 mPhone.nvWriteItem(idValue.first, idValue.second, onCompleted);
676 break;
677
678 case EVENT_NV_WRITE_ITEM_DONE:
679 handleNullReturnEvent(msg, "nvWriteItem");
680 break;
681
682 case CMD_NV_WRITE_CDMA_PRL:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
685 mPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
686 break;
687
688 case EVENT_NV_WRITE_CDMA_PRL_DONE:
689 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
690 break;
691
692 case CMD_NV_RESET_CONFIG:
693 request = (MainThreadRequest) msg.obj;
694 onCompleted = obtainMessage(EVENT_NV_RESET_CONFIG_DONE, request);
695 mPhone.nvResetConfig((Integer) request.argument, onCompleted);
696 break;
697
698 case EVENT_NV_RESET_CONFIG_DONE:
699 handleNullReturnEvent(msg, "nvResetConfig");
700 break;
701
Jake Hamby7c27be32014-03-03 13:25:59 -0800702 case CMD_GET_PREFERRED_NETWORK_TYPE:
703 request = (MainThreadRequest) msg.obj;
704 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700705 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800706 break;
707
708 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
709 ar = (AsyncResult) msg.obj;
710 request = (MainThreadRequest) ar.userObj;
711 if (ar.exception == null && ar.result != null) {
712 request.result = ar.result; // Integer
713 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800714 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800715 if (ar.result == null) {
716 loge("getPreferredNetworkType: Empty response");
717 } else if (ar.exception instanceof CommandException) {
718 loge("getPreferredNetworkType: CommandException: " +
719 ar.exception);
720 } else {
721 loge("getPreferredNetworkType: Unknown exception");
722 }
723 }
724 synchronized (request) {
725 request.notifyAll();
726 }
727 break;
728
729 case CMD_SET_PREFERRED_NETWORK_TYPE:
730 request = (MainThreadRequest) msg.obj;
731 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
732 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700733 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800734 break;
735
736 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
737 handleNullReturnEvent(msg, "setPreferredNetworkType");
738 break;
739
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800740 case CMD_SET_VOICEMAIL_NUMBER:
741 request = (MainThreadRequest) msg.obj;
742 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
743 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800744 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
745 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800746 break;
747
748 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
749 handleNullReturnEvent(msg, "setVoicemailNumber");
750 break;
751
Stuart Scott54788802015-03-30 13:18:01 -0700752 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
755 request);
756 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
757 break;
758
759 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
760 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
761 break;
762
Shishir Agrawal302c8692015-06-19 13:49:39 -0700763 case CMD_PERFORM_NETWORK_SCAN:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
766 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
767 break;
768
769 case EVENT_PERFORM_NETWORK_SCAN_DONE:
770 ar = (AsyncResult) msg.obj;
771 request = (MainThreadRequest) ar.userObj;
772 CellNetworkScanResult cellScanResult;
773 if (ar.exception == null && ar.result != null) {
774 cellScanResult = new CellNetworkScanResult(
775 CellNetworkScanResult.STATUS_SUCCESS,
776 (List<OperatorInfo>) ar.result);
777 } else {
778 if (ar.result == null) {
779 loge("getCellNetworkScanResults: Empty response");
780 }
781 if (ar.exception != null) {
782 loge("getCellNetworkScanResults: Exception: " + ar.exception);
783 }
784 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
785 if (ar.exception instanceof CommandException) {
786 CommandException.Error error =
787 ((CommandException) (ar.exception)).getCommandError();
788 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
789 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
790 } else if (error == CommandException.Error.GENERIC_FAILURE) {
791 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
792 }
793 }
794 cellScanResult = new CellNetworkScanResult(errorCode, null);
795 }
796 request.result = cellScanResult;
797 synchronized (request) {
798 request.notifyAll();
799 }
800 break;
801
802 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
803 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700804 ManualNetworkSelectionArgument selArg =
805 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700806 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
807 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700808 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
809 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700810 break;
811
812 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
813 handleNullReturnEvent(msg, "setNetworkSelectionModeManual");
814 break;
815
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700816 case CMD_GET_MODEM_ACTIVITY_INFO:
817 request = (MainThreadRequest) msg.obj;
818 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Prerepa Viswanadham61a60ad2015-06-08 18:07:51 -0700819 mPhone.getModemActivityInfo(onCompleted);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700820 break;
821
822 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
823 ar = (AsyncResult) msg.obj;
824 request = (MainThreadRequest) ar.userObj;
825 if (ar.exception == null && ar.result != null) {
826 request.result = ar.result;
827 } else {
828 if (ar.result == null) {
829 loge("queryModemActivityInfo: Empty response");
830 } else if (ar.exception instanceof CommandException) {
831 loge("queryModemActivityInfo: CommandException: " +
832 ar.exception);
833 } else {
834 loge("queryModemActivityInfo: Unknown exception");
835 }
836 }
Amit Mahajand4766222016-01-28 15:28:28 -0800837 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
838 if (request.result == null) {
839 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
840 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700841 synchronized (request) {
842 request.notifyAll();
843 }
844 break;
845
Meng Wang1a7c35a2016-05-05 20:56:15 -0700846 case CMD_SET_ALLOWED_CARRIERS:
847 request = (MainThreadRequest) msg.obj;
848 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
849 mPhone.setAllowedCarriers(
850 (List<CarrierIdentifier>) request.argument,
851 onCompleted);
852 break;
853
854 case EVENT_SET_ALLOWED_CARRIERS_DONE:
855 ar = (AsyncResult) msg.obj;
856 request = (MainThreadRequest) ar.userObj;
857 if (ar.exception == null && ar.result != null) {
858 request.result = ar.result;
859 } else {
860 if (ar.result == null) {
861 loge("setAllowedCarriers: Empty response");
862 } else if (ar.exception instanceof CommandException) {
863 loge("setAllowedCarriers: CommandException: " +
864 ar.exception);
865 } else {
866 loge("setAllowedCarriers: Unknown exception");
867 }
868 }
869 // Result cannot be null. Return -1 on error.
870 if (request.result == null) {
871 request.result = new int[]{-1};
872 }
873 synchronized (request) {
874 request.notifyAll();
875 }
876 break;
877
878 case CMD_GET_ALLOWED_CARRIERS:
879 request = (MainThreadRequest) msg.obj;
880 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
881 mPhone.getAllowedCarriers(onCompleted);
882 break;
883
884 case EVENT_GET_ALLOWED_CARRIERS_DONE:
885 ar = (AsyncResult) msg.obj;
886 request = (MainThreadRequest) ar.userObj;
887 if (ar.exception == null && ar.result != null) {
888 request.result = ar.result;
889 } else {
890 if (ar.result == null) {
891 loge("getAllowedCarriers: Empty response");
892 } else if (ar.exception instanceof CommandException) {
893 loge("getAllowedCarriers: CommandException: " +
894 ar.exception);
895 } else {
896 loge("getAllowedCarriers: Unknown exception");
897 }
898 }
899 // Result cannot be null. Return empty list of CarrierIdentifier.
900 if (request.result == null) {
901 request.result = new ArrayList<CarrierIdentifier>(0);
902 }
903 synchronized (request) {
904 request.notifyAll();
905 }
906 break;
907
Nathan Haroldb3014052017-01-25 15:57:32 -0800908 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
909 ar = (AsyncResult) msg.obj;
910 request = (MainThreadRequest) ar.userObj;
911 if (ar.exception == null && ar.result != null) {
912 request.result = ar.result;
913 } else {
914 request.result = new IllegalArgumentException(
915 "Failed to retrieve Forbidden Plmns");
916 if (ar.result == null) {
917 loge("getForbiddenPlmns: Empty response");
918 } else {
919 loge("getForbiddenPlmns: Unknown exception");
920 }
921 }
922 synchronized (request) {
923 request.notifyAll();
924 }
925 break;
926
927 case CMD_GET_FORBIDDEN_PLMNS:
928 request = (MainThreadRequest) msg.obj;
929 uiccCard = getUiccCardFromRequest(request);
930 if (uiccCard == null) {
931 loge("getForbiddenPlmns() UiccCard is null");
932 request.result = new IllegalArgumentException(
933 "getForbiddenPlmns() UiccCard is null");
934 synchronized (request) {
935 request.notifyAll();
936 }
937 break;
938 }
939 Integer appType = (Integer) request.argument;
940 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
941 if (uiccApp == null) {
942 loge("getForbiddenPlmns() no app with specified type -- "
943 + appType);
944 request.result = new IllegalArgumentException("Failed to get UICC App");
945 synchronized (request) {
946 request.notifyAll();
947 }
948 break;
949 } else {
950 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
951 + " specified type -- " + appType);
952 }
953 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
954 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
955 onCompleted);
956 break;
957
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000958 case CMD_SWITCH_SLOTS:
959 request = (MainThreadRequest) msg.obj;
960 int[] physicalSlots = (int[]) request.argument;
961 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
962 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
963 break;
964
965 case EVENT_SWITCH_SLOTS_DONE:
966 ar = (AsyncResult) msg.obj;
967 request = (MainThreadRequest) ar.userObj;
968 request.result = (ar.exception == null);
969 synchronized (request) {
970 request.notifyAll();
971 }
972 break;
973
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700974 default:
975 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
976 break;
977 }
978 }
Jake Hambye994d462014-02-03 13:10:13 -0800979
980 private void handleNullReturnEvent(Message msg, String command) {
981 AsyncResult ar = (AsyncResult) msg.obj;
982 MainThreadRequest request = (MainThreadRequest) ar.userObj;
983 if (ar.exception == null) {
984 request.result = true;
985 } else {
986 request.result = false;
987 if (ar.exception instanceof CommandException) {
988 loge(command + ": CommandException: " + ar.exception);
989 } else {
990 loge(command + ": Unknown exception");
991 }
992 }
993 synchronized (request) {
994 request.notifyAll();
995 }
996 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700997 }
998
999 /**
1000 * Posts the specified command to be executed on the main thread,
1001 * waits for the request to complete, and returns the result.
1002 * @see #sendRequestAsync
1003 */
1004 private Object sendRequest(int command, Object argument) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001005 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
Wink Saville36469e72014-06-11 15:17:00 -07001006 }
1007
1008 /**
1009 * Posts the specified command to be executed on the main thread,
1010 * waits for the request to complete, and returns the result.
1011 * @see #sendRequestAsync
1012 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001013 private Object sendRequest(int command, Object argument, Integer subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001014 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1015 throw new RuntimeException("This method will deadlock if called from the main thread.");
1016 }
1017
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001018 MainThreadRequest request = new MainThreadRequest(argument, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001019 Message msg = mMainThreadHandler.obtainMessage(command, request);
1020 msg.sendToTarget();
1021
1022 // Wait for the request to complete
1023 synchronized (request) {
1024 while (request.result == null) {
1025 try {
1026 request.wait();
1027 } catch (InterruptedException e) {
1028 // Do nothing, go back and wait until the request is complete
1029 }
1030 }
1031 }
1032 return request.result;
1033 }
1034
1035 /**
1036 * Asynchronous ("fire and forget") version of sendRequest():
1037 * Posts the specified command to be executed on the main thread, and
1038 * returns immediately.
1039 * @see #sendRequest
1040 */
1041 private void sendRequestAsync(int command) {
1042 mMainThreadHandler.sendEmptyMessage(command);
1043 }
1044
1045 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001046 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
1047 * @see {@link #sendRequest(int,Object)}
1048 */
1049 private void sendRequestAsync(int command, Object argument) {
1050 MainThreadRequest request = new MainThreadRequest(argument);
1051 Message msg = mMainThreadHandler.obtainMessage(command, request);
1052 msg.sendToTarget();
1053 }
1054
1055 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001056 * Initialize the singleton PhoneInterfaceManager instance.
1057 * This is only done once, at startup, from PhoneApp.onCreate().
1058 */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001059 /* package */ static PhoneInterfaceManager init(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001060 synchronized (PhoneInterfaceManager.class) {
1061 if (sInstance == null) {
Sailesh Nepal194161e2014-07-03 08:57:44 -07001062 sInstance = new PhoneInterfaceManager(app, phone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001063 } else {
1064 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1065 }
1066 return sInstance;
1067 }
1068 }
1069
1070 /** Private constructor; @see init() */
Sailesh Nepal194161e2014-07-03 08:57:44 -07001071 private PhoneInterfaceManager(PhoneGlobals app, Phone phone) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001072 mApp = app;
1073 mPhone = phone;
1074 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001075 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001076 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1077 mMainThreadHandler = new MainThreadHandler();
Andrew Leedf14ead2014-10-17 14:22:52 -07001078 mTelephonySharedPreferences =
Derek Tan97ebb422014-09-05 16:55:38 -07001079 PreferenceManager.getDefaultSharedPreferences(mPhone.getContext());
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001080 mSubscriptionController = SubscriptionController.getInstance();
yinxub1bed742017-04-17 11:45:04 -07001081 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Wink Saville3ab207e2014-11-20 13:07:20 -08001082
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001083 publish();
1084 }
1085
1086 private void publish() {
1087 if (DBG) log("publish: " + this);
1088
1089 ServiceManager.addService("phone", this);
1090 }
1091
Stuart Scott584921c2015-01-15 17:10:34 -08001092 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001093 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1094 ? mPhone : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001095 }
1096
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001097 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1098 Phone phone = getPhoneFromRequest(request);
1099 return phone == null ? null :
1100 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1101 }
1102
Wink Saville36469e72014-06-11 15:17:00 -07001103 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001104 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001105 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001107 //
1108 // Implementation of the ITelephony interface.
1109 //
1110
1111 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001112 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001113 }
1114
Wink Savilleb564aae2014-10-23 10:18:09 -07001115 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001116 if (DBG) log("dial: " + number);
1117 // No permission check needed here: This is just a wrapper around the
1118 // ACTION_DIAL intent, which is available to any app since it puts up
1119 // the UI before it does anything.
1120
1121 String url = createTelUrl(number);
1122 if (url == null) {
1123 return;
1124 }
1125
1126 // PENDING: should we just silently fail if phone is offhook or ringing?
Wink Saville36469e72014-06-11 15:17:00 -07001127 PhoneConstants.State state = mCM.getState(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001128 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1129 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1130 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1131 mApp.startActivity(intent);
1132 }
1133 }
1134
1135 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001136 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001137 }
1138
Wink Savilleb564aae2014-10-23 10:18:09 -07001139 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001140 if (DBG) log("call: " + number);
1141
1142 // This is just a wrapper around the ACTION_CALL intent, but we still
1143 // need to do a permission check since we're calling startActivity()
1144 // from the context of the phone app.
1145 enforceCallPermission();
1146
1147 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1148 != AppOpsManager.MODE_ALLOWED) {
1149 return;
1150 }
1151
1152 String url = createTelUrl(number);
1153 if (url == null) {
1154 return;
1155 }
1156
Wink Saville08874612014-08-31 19:19:58 -07001157 boolean isValid = false;
Narayan Kamath1c496c22015-04-16 14:40:19 +01001158 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoList();
Wink Saville3ab207e2014-11-20 13:07:20 -08001159 if (slist != null) {
1160 for (SubscriptionInfo subInfoRecord : slist) {
1161 if (subInfoRecord.getSubscriptionId() == subId) {
1162 isValid = true;
1163 break;
1164 }
Wink Saville08874612014-08-31 19:19:58 -07001165 }
1166 }
1167 if (isValid == false) {
1168 return;
1169 }
1170
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001171 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
Wink Saville36469e72014-06-11 15:17:00 -07001172 intent.putExtra(SUBSCRIPTION_KEY, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001173 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1174 mApp.startActivity(intent);
1175 }
1176
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001177 /**
1178 * End a call based on call state
1179 * @return true is a call was ended
1180 */
1181 public boolean endCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001182 return endCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001183 }
1184
1185 /**
1186 * End a call based on the call state of the subId
1187 * @return true is a call was ended
1188 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001189 public boolean endCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001190 enforceCallPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001191 return (Boolean) sendRequest(CMD_END_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 }
1193
1194 public void answerRingingCall() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001195 answerRingingCallForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001196 }
1197
Wink Savilleb564aae2014-10-23 10:18:09 -07001198 public void answerRingingCallForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001199 if (DBG) log("answerRingingCall...");
1200 // TODO: there should eventually be a separate "ANSWER_PHONE" permission,
1201 // but that can probably wait till the big TelephonyManager API overhaul.
1202 // For now, protect this call with the MODIFY_PHONE_STATE permission.
1203 enforceModifyPermission();
Stuart Scott584921c2015-01-15 17:10:34 -08001204 sendRequest(CMD_ANSWER_RINGING_CALL, null, new Integer(subId));
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001205 }
1206
1207 /**
1208 * Make the actual telephony calls to implement answerRingingCall().
1209 * This should only be called from the main thread of the Phone app.
1210 * @see #answerRingingCall
1211 *
1212 * TODO: it would be nice to return true if we answered the call, or
1213 * false if there wasn't actually a ringing incoming call, or some
1214 * other error occurred. (In other words, pass back the return value
1215 * from PhoneUtils.answerCall() or PhoneUtils.answerAndEndActive().)
1216 * But that would require calling this method via sendRequest() rather
1217 * than sendRequestAsync(), and right now we don't actually *need* that
1218 * return value, so let's just return void for now.
1219 */
Wink Savilleb564aae2014-10-23 10:18:09 -07001220 private void answerRingingCallInternal(int subId) {
Wink Saville08874612014-08-31 19:19:58 -07001221 final boolean hasRingingCall = !getPhone(subId).getRingingCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001222 if (hasRingingCall) {
Wink Saville08874612014-08-31 19:19:58 -07001223 final boolean hasActiveCall = !getPhone(subId).getForegroundCall().isIdle();
1224 final boolean hasHoldingCall = !getPhone(subId).getBackgroundCall().isIdle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001225 if (hasActiveCall && hasHoldingCall) {
1226 // Both lines are in use!
1227 // TODO: provide a flag to let the caller specify what
1228 // policy to use if both lines are in use. (The current
1229 // behavior is hardwired to "answer incoming, end ongoing",
1230 // which is how the CALL button is specced to behave.)
1231 PhoneUtils.answerAndEndActive(mCM, mCM.getFirstActiveRingingCall());
1232 return;
1233 } else {
1234 // answerCall() will automatically hold the current active
1235 // call, if there is one.
1236 PhoneUtils.answerCall(mCM.getFirstActiveRingingCall());
1237 return;
1238 }
1239 } else {
1240 // No call was ringing.
1241 return;
1242 }
1243 }
1244
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 /**
Santos Cordon5422a8d2014-09-12 04:20:56 -07001246 * This method is no longer used and can be removed once TelephonyManager stops referring to it.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001247 */
Santos Cordon5422a8d2014-09-12 04:20:56 -07001248 public void silenceRinger() {
1249 Log.e(LOG_TAG, "silenseRinger not supported");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001250 }
1251
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001252 @Override
1253 public boolean isOffhook(String callingPackage) {
1254 return isOffhookForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001255 }
1256
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001257 @Override
1258 public boolean isOffhookForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001260 mApp, subId, callingPackage, "isOffhookForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001261 return false;
1262 }
1263
Sanket Padawe356d7632015-06-22 14:03:32 -07001264 final Phone phone = getPhone(subId);
1265 if (phone != null) {
1266 return (phone.getState() == PhoneConstants.State.OFFHOOK);
1267 } else {
1268 return false;
1269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001270 }
1271
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001272 @Override
1273 public boolean isRinging(String callingPackage) {
1274 return (isRingingForSubscriber(getDefaultSubscription(), callingPackage));
Wink Saville36469e72014-06-11 15:17:00 -07001275 }
1276
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001277 @Override
1278 public boolean isRingingForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001280 mApp, subId, callingPackage, "isRingingForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001281 return false;
1282 }
1283
Sanket Padawe356d7632015-06-22 14:03:32 -07001284 final Phone phone = getPhone(subId);
1285 if (phone != null) {
1286 return (phone.getState() == PhoneConstants.State.RINGING);
1287 } else {
1288 return false;
1289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290 }
1291
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001292 @Override
1293 public boolean isIdle(String callingPackage) {
1294 return isIdleForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001295 }
1296
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001297 @Override
1298 public boolean isIdleForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001300 mApp, subId, callingPackage, "isIdleForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001301 return false;
1302 }
1303
Sanket Padawe356d7632015-06-22 14:03:32 -07001304 final Phone phone = getPhone(subId);
1305 if (phone != null) {
1306 return (phone.getState() == PhoneConstants.State.IDLE);
1307 } else {
1308 return false;
1309 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001310 }
1311
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001313 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001314 }
1315
Wink Savilleb564aae2014-10-23 10:18:09 -07001316 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001317 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001318 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1319 }
1320
1321 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001322 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001323 }
1324
Wink Savilleb564aae2014-10-23 10:18:09 -07001325 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001326 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001327 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1328 }
1329
1330 /** {@hide} */
1331 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001332 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001333 }
1334
Wink Savilleb564aae2014-10-23 10:18:09 -07001335 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001337 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001338 checkSimPin.start();
1339 return checkSimPin.unlockSim(null, pin);
1340 }
1341
Wink Saville9de0f752013-10-22 19:04:03 -07001342 /** {@hide} */
1343 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001344 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001345 }
1346
Wink Savilleb564aae2014-10-23 10:18:09 -07001347 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001348 enforceModifyPermission();
Wink Saville36469e72014-06-11 15:17:00 -07001349 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001350 checkSimPuk.start();
1351 return checkSimPuk.unlockSim(puk, pin);
1352 }
1353
1354 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001355 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001356 * a synchronous one.
1357 */
1358 private static class UnlockSim extends Thread {
1359
1360 private final IccCard mSimCard;
1361
1362 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001363 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1364 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365
1366 // For replies from SimCard interface
1367 private Handler mHandler;
1368
1369 // For async handler to identify request type
1370 private static final int SUPPLY_PIN_COMPLETE = 100;
1371
1372 public UnlockSim(IccCard simCard) {
1373 mSimCard = simCard;
1374 }
1375
1376 @Override
1377 public void run() {
1378 Looper.prepare();
1379 synchronized (UnlockSim.this) {
1380 mHandler = new Handler() {
1381 @Override
1382 public void handleMessage(Message msg) {
1383 AsyncResult ar = (AsyncResult) msg.obj;
1384 switch (msg.what) {
1385 case SUPPLY_PIN_COMPLETE:
1386 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1387 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001388 mRetryCount = msg.arg1;
1389 if (ar.exception != null) {
1390 if (ar.exception instanceof CommandException &&
1391 ((CommandException)(ar.exception)).getCommandError()
1392 == CommandException.Error.PASSWORD_INCORRECT) {
1393 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1394 } else {
1395 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1396 }
1397 } else {
1398 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1399 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 mDone = true;
1401 UnlockSim.this.notifyAll();
1402 }
1403 break;
1404 }
1405 }
1406 };
1407 UnlockSim.this.notifyAll();
1408 }
1409 Looper.loop();
1410 }
1411
1412 /*
1413 * Use PIN or PUK to unlock SIM card
1414 *
1415 * If PUK is null, unlock SIM card with PIN
1416 *
1417 * If PUK is not null, unlock SIM card with PUK and set PIN code
1418 */
Wink Saville9de0f752013-10-22 19:04:03 -07001419 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001420
1421 while (mHandler == null) {
1422 try {
1423 wait();
1424 } catch (InterruptedException e) {
1425 Thread.currentThread().interrupt();
1426 }
1427 }
1428 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1429
1430 if (puk == null) {
1431 mSimCard.supplyPin(pin, callback);
1432 } else {
1433 mSimCard.supplyPuk(puk, pin, callback);
1434 }
1435
1436 while (!mDone) {
1437 try {
1438 Log.d(LOG_TAG, "wait for done");
1439 wait();
1440 } catch (InterruptedException e) {
1441 // Restore the interrupted status
1442 Thread.currentThread().interrupt();
1443 }
1444 }
1445 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001446 int[] resultArray = new int[2];
1447 resultArray[0] = mResult;
1448 resultArray[1] = mRetryCount;
1449 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 }
1451 }
1452
1453 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001455
1456 }
1457
Wink Savilleb564aae2014-10-23 10:18:09 -07001458 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 // No permission check needed here: this call is harmless, and it's
1460 // needed for the ServiceState.requestStateUpdate() call (which is
1461 // already intentionally exposed to 3rd parties.)
Sanket Padawe356d7632015-06-22 14:03:32 -07001462 final Phone phone = getPhone(subId);
1463 if (phone != null) {
1464 phone.updateServiceLocation();
1465 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001466 }
1467
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001468 @Override
1469 public boolean isRadioOn(String callingPackage) {
1470 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001471 }
1472
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001473 @Override
1474 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001475 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001476 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001477 return false;
1478 }
1479 return isRadioOnForSubscriber(subId);
1480 }
1481
1482 private boolean isRadioOnForSubscriber(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001483 final Phone phone = getPhone(subId);
1484 if (phone != null) {
1485 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1486 } else {
1487 return false;
1488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 }
1490
1491 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001492 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001493
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001494 }
Wink Saville36469e72014-06-11 15:17:00 -07001495
Wink Savilleb564aae2014-10-23 10:18:09 -07001496 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001498 final Phone phone = getPhone(subId);
1499 if (phone != null) {
1500 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1501 }
Wink Saville36469e72014-06-11 15:17:00 -07001502 }
1503
1504 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001505 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001506 }
1507
Wink Savilleb564aae2014-10-23 10:18:09 -07001508 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001509 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001510 final Phone phone = getPhone(subId);
1511 if (phone == null) {
1512 return false;
1513 }
1514 if ((phone.getServiceState().getState() !=
Wink Saville36469e72014-06-11 15:17:00 -07001515 ServiceState.STATE_POWER_OFF) != turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001516 toggleRadioOnOffForSubscriber(subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001517 }
1518 return true;
1519 }
Wink Saville36469e72014-06-11 15:17:00 -07001520
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001521 public boolean needMobileRadioShutdown() {
1522 /*
1523 * If any of the Radios are available, it will need to be
1524 * shutdown. So return true if any Radio is available.
1525 */
1526 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1527 Phone phone = PhoneFactory.getPhone(i);
1528 if (phone != null && phone.isRadioAvailable()) return true;
1529 }
1530 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1531 return false;
1532 }
1533
1534 public void shutdownMobileRadios() {
1535 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1536 logv("Shutting down Phone " + i);
1537 shutdownRadioUsingPhoneId(i);
1538 }
1539 }
1540
1541 private void shutdownRadioUsingPhoneId(int phoneId) {
1542 enforceModifyPermission();
1543 Phone phone = PhoneFactory.getPhone(phoneId);
1544 if (phone != null && phone.isRadioAvailable()) {
1545 phone.shutdownRadio();
1546 }
1547 }
1548
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001549 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001550 enforceModifyPermission();
Wei Liu9ae2a062016-08-08 11:09:34 -07001551 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1552 if (defaultPhone != null) {
1553 defaultPhone.setRadioPower(turnOn);
1554 return true;
1555 } else {
1556 loge("There's no default phone.");
1557 return false;
1558 }
Wink Saville36469e72014-06-11 15:17:00 -07001559 }
1560
Wink Savilleb564aae2014-10-23 10:18:09 -07001561 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001562 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001563 final Phone phone = getPhone(subId);
1564 if (phone != null) {
1565 phone.setRadioPower(turnOn);
1566 return true;
1567 } else {
1568 return false;
1569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 }
1571
Wink Saville36469e72014-06-11 15:17:00 -07001572 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001573 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 public boolean enableDataConnectivity() {
1575 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001576 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001577 final Phone phone = getPhone(subId);
1578 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001579 phone.setUserDataEnabled(true);
Sanket Padawe356d7632015-06-22 14:03:32 -07001580 return true;
1581 } else {
1582 return false;
1583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001584 }
1585
Wink Saville36469e72014-06-11 15:17:00 -07001586 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001587 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001588 public boolean disableDataConnectivity() {
1589 enforceModifyPermission();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001590 int subId = mSubscriptionController.getDefaultDataSubId();
Sanket Padawe356d7632015-06-22 14:03:32 -07001591 final Phone phone = getPhone(subId);
1592 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08001593 phone.setUserDataEnabled(false);
Sanket Padawe356d7632015-06-22 14:03:32 -07001594 return true;
1595 } else {
1596 return false;
1597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 }
1599
Sanket Padawe356d7632015-06-22 14:03:32 -07001600 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001601 public boolean isDataConnectivityPossible(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07001602 final Phone phone = getPhone(subId);
1603 if (phone != null) {
Jack Yuacf8a132017-05-01 17:00:48 -07001604 return phone.isDataAllowed();
Sanket Padawe356d7632015-06-22 14:03:32 -07001605 } else {
1606 return false;
1607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 }
1609
1610 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001611 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001612 }
1613
pkanwarae03a6b2016-11-06 20:37:09 -08001614 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
pkanwar32d516d2016-10-14 19:37:38 -07001615 enforceCallPermission();
pkanwar32d516d2016-10-14 19:37:38 -07001616 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1617 return;
1618 }
1619 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1620 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1621 };
1622
Wink Savilleb564aae2014-10-23 10:18:09 -07001623 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 enforceModifyPermission();
Sanket Padawe356d7632015-06-22 14:03:32 -07001625 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1626 return false;
1627 }
Wink Saville36469e72014-06-11 15:17:00 -07001628 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001629 }
1630
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001632 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001633 }
1634
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001635 public int getCallStateForSlot(int slotIndex) {
1636 Phone phone = PhoneFactory.getPhone(slotIndex);
Shishir Agrawala9f32182016-04-12 12:00:16 -07001637 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
Nathan Harolda667c152016-12-14 11:27:20 -08001638 PhoneConstantConversions.convertCallState(phone.getState());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001639 }
1640
Sanket Padawe356d7632015-06-22 14:03:32 -07001641 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 public int getDataState() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001643 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001644 if (phone != null) {
Nathan Harolda667c152016-12-14 11:27:20 -08001645 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
Sanket Padawe356d7632015-06-22 14:03:32 -07001646 } else {
Nathan Harolda667c152016-12-14 11:27:20 -08001647 return PhoneConstantConversions.convertDataState(PhoneConstants.DataState.DISCONNECTED);
Sanket Padawe356d7632015-06-22 14:03:32 -07001648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 }
1650
Sanket Padawe356d7632015-06-22 14:03:32 -07001651 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 public int getDataActivity() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001653 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
Sanket Padawe356d7632015-06-22 14:03:32 -07001654 if (phone != null) {
1655 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1656 } else {
1657 return TelephonyManager.DATA_ACTIVITY_NONE;
1658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 }
1660
1661 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001662 public Bundle getCellLocation(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001663 mPhone.getContext().getSystemService(AppOpsManager.class)
1664 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001665 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001666 callingPackage, Binder.getCallingUid(),Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001667 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001668 }
1669
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001670 if (DBG_LOC) log("getCellLocation: is active user");
1671 Bundle data = new Bundle();
1672 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1673 if (phone == null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001674 return null;
1675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001677 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1678 phone.getCellLocation(workSource).fillInNotifierBundle(data);
1679 return data;
Svetoslav64fad262015-04-14 14:35:21 -07001680 }
1681
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 @Override
Jonathan Basseri03923952017-07-19 12:22:35 -07001683 public String getNetworkCountryIsoForPhone(int phoneId) {
1684 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1685 // registered cell info, so return a NULL country instead.
1686 final long identity = Binder.clearCallingIdentity();
1687 try {
1688 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1689 if (TelephonyManager.NETWORK_TYPE_IWLAN
1690 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1691 return "";
1692 }
1693 } finally {
1694 Binder.restoreCallingIdentity(identity);
1695 }
1696 return TelephonyManager.getTelephonyProperty(
1697 phoneId, TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, "");
1698 }
1699
1700 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001702 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001703 }
1704
Sanket Padawe356d7632015-06-22 14:03:32 -07001705 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001706 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 mApp.enforceCallingOrSelfPermission(
1708 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001709 final Phone phone = getPhone(subId);
1710 if (phone != null) {
1711 phone.enableLocationUpdates();
1712 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 }
1714
1715 @Override
1716 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001717 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001718 }
1719
Sanket Padawe356d7632015-06-22 14:03:32 -07001720 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001721 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001722 mApp.enforceCallingOrSelfPermission(
1723 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 final Phone phone = getPhone(subId);
1725 if (phone != null) {
1726 phone.disableLocationUpdates();
1727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 }
1729
1730 @Override
1731 @SuppressWarnings("unchecked")
1732 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001733 mPhone.getContext().getSystemService(AppOpsManager.class)
1734 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001735 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001736 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001737 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 }
1739
1740 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1741 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1742 return null;
1743 }
Svetoslav64fad262015-04-14 14:35:21 -07001744
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001745 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001747 ArrayList<NeighboringCellInfo> cells = null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001749 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1750 try {
1751 cells = (ArrayList<NeighboringCellInfo>) sendRequest(
1752 CMD_HANDLE_NEIGHBORING_CELL, workSource,
1753 SubscriptionManager.INVALID_SUBSCRIPTION_ID);
1754 } catch (RuntimeException e) {
1755 Log.e(LOG_TAG, "getNeighboringCellInfo " + e);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001757 return cells;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 }
1759
1760
1761 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001762 public List<CellInfo> getAllCellInfo(String callingPackage) {
Hall Liu1aa510f2017-11-22 17:40:08 -08001763 mPhone.getContext().getSystemService(AppOpsManager.class)
1764 .checkPackage(Binder.getCallingUid(), callingPackage);
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001765 if (!LocationAccessPolicy.canAccessCellLocation(mPhone.getContext(),
Hall Liu1aa510f2017-11-22 17:40:08 -08001766 callingPackage, Binder.getCallingUid(), Binder.getCallingPid())) {
Svetoslav64fad262015-04-14 14:35:21 -07001767 return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
1769
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001770 if (DBG_LOC) log("getAllCellInfo: is active user");
1771 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1772 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
1773 for (Phone phone : PhoneFactory.getPhones()) {
1774 final List<CellInfo> info = phone.getAllCellInfo(workSource);
1775 if (info != null) cellInfos.addAll(info);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 }
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001777 return cellInfos;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001778 }
1779
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001780 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08001782 enforceModifyPermission();
Sooraj Sasindran9a909312016-07-18 11:57:25 -07001783 WorkSource workSource = getWorkSource(null, Binder.getCallingUid());
1784 mPhone.setCellInfoListRate(rateInMillis, workSource);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 }
1786
Shishir Agrawala9f32182016-04-12 12:00:16 -07001787 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001788 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001789 Phone phone = PhoneFactory.getPhone(slotIndex);
1790 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001791 return null;
1792 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001793 int subId = phone.getSubId();
1794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1795 mApp, subId, callingPackage, "getImeiForSlot")) {
1796 return null;
1797 }
1798 return phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001799 }
1800
1801 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001802 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001803 Phone phone = PhoneFactory.getPhone(slotIndex);
1804 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07001805 return null;
1806 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001807 int subId = phone.getSubId();
1808 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1809 mApp, subId, callingPackage, "getMeidForSlot")) {
1810 return null;
1811 }
1812 return phone.getMeid();
Jack Yu2af8d712017-03-15 17:14:14 -07001813 }
1814
1815 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001816 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001817 Phone phone = PhoneFactory.getPhone(slotIndex);
1818 if (phone == null) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001819 return null;
1820 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001821 int subId = phone.getSubId();
1822 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1823 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1824 return null;
1825 }
1826 return phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001827 }
1828
fionaxuf32acdf2017-11-27 22:51:16 -08001829 @Override
1830 public int getSubscriptionCarrierId(int subId) {
1831 final Phone phone = getPhone(subId);
1832 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1833 }
1834
1835 @Override
1836 public String getSubscriptionCarrierName(int subId) {
1837 final Phone phone = getPhone(subId);
1838 return phone == null ? null : phone.getCarrierName();
1839 }
1840
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001841 //
1842 // Internal helper methods.
1843 //
1844
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001845 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1847 *
1848 * @throws SecurityException if the caller does not have the required permission
1849 */
1850 private void enforceModifyPermission() {
1851 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1852 }
1853
1854 /**
1855 * Make sure the caller has the CALL_PHONE permission.
1856 *
1857 * @throws SecurityException if the caller does not have the required permission
1858 */
1859 private void enforceCallPermission() {
1860 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1861 }
1862
Stuart Scott8eef64f2015-04-08 15:13:54 -07001863 private void enforceConnectivityInternalPermission() {
1864 mApp.enforceCallingOrSelfPermission(
1865 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1866 "ConnectivityService");
1867 }
1868
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 private String createTelUrl(String number) {
1870 if (TextUtils.isEmpty(number)) {
1871 return null;
1872 }
1873
Jake Hambye994d462014-02-03 13:10:13 -08001874 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 }
1876
Ihab Awadf9e92732013-12-05 18:02:52 -08001877 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1879 }
1880
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001881 private static void logv(String msg) {
1882 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1883 }
1884
Ihab Awadf9e92732013-12-05 18:02:52 -08001885 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1887 }
1888
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001889 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001891 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001892 }
1893
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001895 public int getActivePhoneTypeForSlot(int slotIndex) {
1896 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001897 if (phone == null) {
1898 return PhoneConstants.PHONE_TYPE_NONE;
1899 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001900 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001901 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902 }
1903
1904 /**
1905 * Returns the CDMA ERI icon index to display
1906 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001907 @Override
1908 public int getCdmaEriIconIndex(String callingPackage) {
1909 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001910 }
1911
Sanket Padawe356d7632015-06-22 14:03:32 -07001912 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001913 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001914 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001915 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001916 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) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001938 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001939 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001940 return -1;
1941 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001942 final Phone phone = getPhone(subId);
1943 if (phone != null) {
1944 return phone.getCdmaEriIconMode();
1945 } else {
1946 return -1;
1947 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001948 }
1949
1950 /**
1951 * Returns the CDMA ERI text,
1952 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001953 @Override
1954 public String getCdmaEriText(String callingPackage) {
1955 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001956 }
1957
Sanket Padawe356d7632015-06-22 14:03:32 -07001958 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001959 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08001961 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001962 return null;
1963 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001964 final Phone phone = getPhone(subId);
1965 if (phone != null) {
1966 return phone.getCdmaEriText();
1967 } else {
1968 return null;
1969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 }
1971
1972 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001973 * Returns the CDMA MDN.
1974 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001975 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001976 public String getCdmaMdn(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1978 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07001979 final Phone phone = getPhone(subId);
1980 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1981 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001982 } else {
1983 return null;
1984 }
1985 }
1986
1987 /**
1988 * Returns the CDMA MIN.
1989 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001990 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001991 public String getCdmaMin(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1993 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07001994 final Phone phone = getPhone(subId);
1995 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1996 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001997 } else {
1998 return null;
1999 }
2000 }
2001
2002 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 * Returns true if CDMA provisioning needs to run.
2004 */
2005 public boolean needsOtaServiceProvisioning() {
2006 return mPhone.needsOtaServiceProvisioning();
2007 }
2008
2009 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002010 * Sets the voice mail number of a given subId.
2011 */
2012 @Override
2013 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002014 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002015 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2016 new Pair<String, String>(alphaTag, number), new Integer(subId));
2017 return success;
2018 }
2019
Ta-wei Yen87c49842016-05-13 21:19:52 -07002020 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002021 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2022 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2023 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2024 if (!TextUtils.equals(callingPackage, systemDialer)) {
2025 throw new SecurityException("caller must be system dialer");
2026 }
2027 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2028 if (phoneAccountHandle == null){
2029 return null;
2030 }
2031 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2032 }
2033
2034 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002035 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002036 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002038 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002039 return null;
2040 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002041 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2042 }
2043
2044 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002045 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2046 VisualVoicemailSmsFilterSettings settings) {
2047 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002048 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002049 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2050 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002051 }
2052
2053 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002054 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2055 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002056 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002057 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002058 }
2059
2060 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002061 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2062 String callingPackage, int subId) {
2063 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002064 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002065 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002066 }
2067
2068 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002069 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002070 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002071 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002072 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2073 }
2074
2075 @Override
2076 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2077 String number, int port, String text, PendingIntent sentIntent) {
2078 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002079 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002080 enforceSendSmsPermission();
2081 // Make the calls as the phone process.
2082 final long identity = Binder.clearCallingIdentity();
2083 try {
2084 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2085 if (port == 0) {
2086 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2087 sentIntent, null, false);
2088 } else {
2089 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2090 smsManager.sendDataMessageWithSelfPermissions(number, null,
2091 (short) port, data, sentIntent, null);
2092 }
2093 } finally {
2094 Binder.restoreCallingIdentity(identity);
2095 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002096 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002097 /**
fionaxu0152e512016-11-14 13:36:14 -08002098 * Sets the voice activation state of a given subId.
2099 */
2100 @Override
2101 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2103 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002104 final Phone phone = getPhone(subId);
2105 if (phone != null) {
2106 phone.setVoiceActivationState(activationState);
2107 } else {
2108 loge("setVoiceActivationState fails with invalid subId: " + subId);
2109 }
2110 }
2111
2112 /**
2113 * Sets the data activation state of a given subId.
2114 */
2115 @Override
2116 public void setDataActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2118 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002119 final Phone phone = getPhone(subId);
2120 if (phone != null) {
2121 phone.setDataActivationState(activationState);
2122 } else {
2123 loge("setVoiceActivationState fails with invalid subId: " + subId);
2124 }
2125 }
2126
2127 /**
2128 * Returns the voice activation state of a given subId.
2129 */
2130 @Override
2131 public int getVoiceActivationState(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002132 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002133 mApp, subId, callingPackage, "getVoiceActivationStateForSubscriber")) {
fionaxu0152e512016-11-14 13:36:14 -08002134 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2135 }
2136 final Phone phone = getPhone(subId);
2137 if (phone != null) {
2138 return phone.getVoiceActivationState();
2139 } else {
2140 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2141 }
2142 }
2143
2144 /**
2145 * Returns the data activation state of a given subId.
2146 */
2147 @Override
2148 public int getDataActivationState(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002149 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002150 mApp, subId, callingPackage, "getDataActivationStateForSubscriber")) {
fionaxu0152e512016-11-14 13:36:14 -08002151 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2152 }
2153 final Phone phone = getPhone(subId);
2154 if (phone != null) {
2155 return phone.getDataActivationState();
2156 } else {
2157 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2158 }
2159 }
2160
2161 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002162 * Returns the unread count of voicemails
2163 */
2164 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002165 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002166 }
2167
2168 /**
2169 * Returns the unread count of voicemails for a subId
2170 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002171 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002172 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002173 final Phone phone = getPhone(subId);
2174 if (phone != null) {
2175 return phone.getVoiceMessageCount();
2176 } else {
2177 return 0;
2178 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 }
2180
2181 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002182 * returns true, if the device is in a state where both voice and data
2183 * are supported simultaneously. This can change based on location or network condition.
2184 */
2185 @Override
2186 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2187 final Phone phone = getPhone(subId);
2188 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2189 }
2190
2191 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002192 * Send the dialer code if called from the current default dialer or the caller has
2193 * carrier privilege.
2194 * @param inputCode The dialer code to send
2195 */
2196 @Override
2197 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2198 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2199 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2200 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002201 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2202 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002203 }
2204 mPhone.sendDialerSpecialCode(inputCode);
2205 }
2206
2207 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002208 * Returns the data network type.
2209 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210 *
2211 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2212 */
2213 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002214 public int getNetworkType() {
2215 final Phone phone = getPhone(getDefaultSubscription());
2216 if (phone != null) {
2217 return phone.getServiceState().getDataNetworkType();
2218 } else {
2219 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2220 }
Wink Saville36469e72014-06-11 15:17:00 -07002221 }
2222
2223 /**
2224 * Returns the network type for a subId
2225 */
2226 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002227 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002228 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002229 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002230 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2231 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002232
Sanket Padawe356d7632015-06-22 14:03:32 -07002233 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002234 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002235 return phone.getServiceState().getDataNetworkType();
2236 } else {
2237 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 }
2240
2241 /**
2242 * Returns the data network type
2243 */
2244 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002245 public int getDataNetworkType(String callingPackage) {
2246 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002247 }
2248
2249 /**
2250 * Returns the data network type for a subId
2251 */
2252 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002253 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002254 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002255 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002256 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2257 }
2258
Sanket Padawe356d7632015-06-22 14:03:32 -07002259 final Phone phone = getPhone(subId);
2260 if (phone != null) {
2261 return phone.getServiceState().getDataNetworkType();
2262 } else {
2263 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2264 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 }
2266
2267 /**
Wink Saville36469e72014-06-11 15:17:00 -07002268 * Returns the Voice network type for a subId
2269 */
2270 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002271 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002273 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002274 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2275 }
2276
Sanket Padawe356d7632015-06-22 14:03:32 -07002277 final Phone phone = getPhone(subId);
2278 if (phone != null) {
2279 return phone.getServiceState().getVoiceNetworkType();
2280 } else {
2281 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 }
2284
2285 /**
2286 * @return true if a ICC card is present
2287 */
2288 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002289 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002290 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2291 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002292 }
2293
2294 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002295 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002296 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002297 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002298 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2299 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002300 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002301 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002302 } else {
2303 return false;
2304 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002305 }
2306
2307 /**
2308 * Return if the current radio is LTE on CDMA. This
2309 * is a tri-state return value as for a period of time
2310 * the mode may be unknown.
2311 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002312 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002314 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002316 @Override
2317 public int getLteOnCdmaMode(String callingPackage) {
2318 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002319 }
2320
Sanket Padawe356d7632015-06-22 14:03:32 -07002321 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002322 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002324 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002325 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2326 }
2327
Sanket Padawe356d7632015-06-22 14:03:32 -07002328 final Phone phone = getPhone(subId);
2329 if (phone == null) {
2330 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2331 } else {
2332 return phone.getLteOnCdmaMode();
2333 }
Wink Saville36469e72014-06-11 15:17:00 -07002334 }
2335
2336 public void setPhone(Phone phone) {
2337 mPhone = phone;
2338 }
2339
2340 /**
2341 * {@hide}
2342 * Returns Default subId, 0 in the case of single standby.
2343 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002344 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002345 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002346 }
2347
Shishir Agrawala9f32182016-04-12 12:00:16 -07002348 private int getSlotForDefaultSubscription() {
2349 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2350 }
2351
Wink Savilleb564aae2014-10-23 10:18:09 -07002352 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002353 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002355
2356 /**
2357 * @see android.telephony.TelephonyManager.WifiCallingChoices
2358 */
2359 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002360 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2361 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002362 }
2363
2364 /**
2365 * @see android.telephony.TelephonyManager.WifiCallingChoices
2366 */
2367 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002368 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2369 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2370 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002371 }
2372
Sailesh Nepald1e68152013-12-12 19:08:02 -08002373 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002374 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002375 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002376 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002377
Shishir Agrawal566b7612013-10-28 14:41:00 -07002378 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002379 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2380 int subId, String callingPackage, String aid, int p2) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002381 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2382 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002383
Derek Tan740e1672017-06-27 14:56:27 -07002384 if (TextUtils.equals(ISDR_AID, aid)) {
2385 // Only allows LPA to open logical channel to ISD-R.
2386 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2387 ComponentInfo bestComponent =
2388 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2389 if (bestComponent == null
2390 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2391 loge("The calling package is not allowed to access ISD-R.");
2392 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2393 }
2394 }
2395
2396 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002397 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002398 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002399 if (DBG) log("iccOpenLogicalChannel: " + response);
2400 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002401 }
2402
2403 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002404 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2406 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002407
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002408 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002409 if (channel < 0) {
2410 return false;
2411 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002412 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002413 if (DBG) log("iccCloseLogicalChannel: " + success);
2414 return success;
2415 }
2416
2417 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002418 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002419 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2421 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002422
2423 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002424 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2425 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002426 " data=" + data);
2427 }
2428
2429 if (channel < 0) {
2430 return "";
2431 }
2432
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002433 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002434 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002435 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2436
Shishir Agrawal566b7612013-10-28 14:41:00 -07002437 // Append the returned status code to the end of the response payload.
2438 String s = Integer.toHexString(
2439 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002440 if (response.payload != null) {
2441 s = IccUtils.bytesToHexString(response.payload) + s;
2442 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002443 return s;
2444 }
Jake Hambye994d462014-02-03 13:10:13 -08002445
Evan Charltonc66da362014-05-16 14:06:40 -07002446 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002447 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2448 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2450 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002451
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002452 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2453 && TextUtils.equals(ISDR_AID, data)) {
2454 // Only allows LPA to select ISD-R.
2455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2456 ComponentInfo bestComponent =
2457 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2458 if (bestComponent == null
2459 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2460 loge("The calling package is not allowed to select ISD-R.");
2461 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2462 }
2463 }
2464
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002465 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002466 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2467 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002468 }
2469
2470 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002471 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002472 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2473
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002474 // Append the returned status code to the end of the response payload.
2475 String s = Integer.toHexString(
2476 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002477 if (response.payload != null) {
2478 s = IccUtils.bytesToHexString(response.payload) + s;
2479 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002480 return s;
2481 }
2482
2483 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002484 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002485 String filePath) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002486 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2487 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002488
2489 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002490 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002491 p1 + " " + p2 + " " + p3 + ":" + filePath);
2492 }
2493
2494 IccIoResult response =
2495 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002496 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2497 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002498
2499 if (DBG) {
2500 log("Exchange SIM_IO [R]" + response);
2501 }
2502
2503 byte[] result = null;
2504 int length = 2;
2505 if (response.payload != null) {
2506 length = 2 + response.payload.length;
2507 result = new byte[length];
2508 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2509 } else {
2510 result = new byte[length];
2511 }
2512
2513 result[length - 1] = (byte) response.sw2;
2514 result[length - 2] = (byte) response.sw1;
2515 return result;
2516 }
2517
Nathan Haroldb3014052017-01-25 15:57:32 -08002518 /**
2519 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2520 * on a particular subscription
2521 */
2522 public String[] getForbiddenPlmns(int subId, int appType) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002523 // TODO(b/73884967): Migrate to TelephonyPermissions check.
Nathan Harold892104e2017-04-13 18:19:05 -07002524 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2525 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002526 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2527 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2528 return null;
2529 }
2530 Object response = sendRequest(
2531 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2532 if (response instanceof String[]) {
2533 return (String[]) response;
2534 }
2535 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2536 return null;
2537 }
2538
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002539 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002540 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2542 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002543
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002544 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002545 if (response.payload == null) {
2546 return "";
2547 }
2548
2549 // Append the returned status code to the end of the response payload.
2550 String s = Integer.toHexString(
2551 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2552 s = IccUtils.bytesToHexString(response.payload) + s;
2553 return s;
2554 }
2555
Jake Hambye994d462014-02-03 13:10:13 -08002556 /**
2557 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2558 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2559 *
2560 * @param itemID the ID of the item to read
2561 * @return the NV item as a String, or null on error.
2562 */
2563 @Override
2564 public String nvReadItem(int itemID) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2566 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002567 if (DBG) log("nvReadItem: item " + itemID);
2568 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2569 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2570 return value;
2571 }
2572
2573 /**
2574 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2575 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2576 *
2577 * @param itemID the ID of the item to read
2578 * @param itemValue the value to write, as a String
2579 * @return true on success; false on any failure
2580 */
2581 @Override
2582 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2584 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002585 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2586 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2587 new Pair<Integer, String>(itemID, itemValue));
2588 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2589 return success;
2590 }
2591
2592 /**
2593 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2594 * Used for device configuration by some CDMA operators.
2595 *
2596 * @param preferredRoamingList byte array containing the new PRL
2597 * @return true on success; false on any failure
2598 */
2599 @Override
2600 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2602 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002603 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2604 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2605 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2606 return success;
2607 }
2608
2609 /**
2610 * Perform the specified type of NV config reset.
2611 * Used for device configuration by some CDMA operators.
2612 *
2613 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2614 * @return true on success; false on any failure
2615 */
2616 @Override
2617 public boolean nvResetConfig(int resetType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2619 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002620 if (DBG) log("nvResetConfig: type " + resetType);
2621 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2622 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2623 return success;
2624 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002625
2626 /**
Wink Saville36469e72014-06-11 15:17:00 -07002627 * {@hide}
2628 * Returns Default sim, 0 in the case of single standby.
2629 */
2630 public int getDefaultSim() {
2631 //TODO Need to get it from Telephony Devcontroller
2632 return 0;
2633 }
2634
Svet Ganovb320e182015-04-16 12:30:10 -07002635 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002636 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002637 mApp, mPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002638 return new String[0];
2639 }
2640
2641
ram87fca6f2014-07-18 18:58:44 +05302642 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002643 }
2644
Brad Ebinger51f743a2017-01-23 13:50:20 -08002645 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002646 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2647 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002648 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002649 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002650 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002651 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002652 }
2653
2654 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002655 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2656 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002657 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002658 public void disableIms(int slotId) {
2659 enforceModifyPermission();
2660 PhoneFactory.getImsResolver().disableIms(slotId);
2661 }
2662
2663 /**
2664 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2665 * feature or {@link null} if the service is not available. If the feature is available, the
2666 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2667 */
2668 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002669 IImsServiceFeatureCallback callback) {
2670 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002671 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002672 }
2673
2674 /**
2675 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2676 * feature during emergency calling or {@link null} if the service is not available. If the
2677 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2678 * listener for feature updates.
2679 */
2680 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2681 enforceModifyPermission();
2682 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002683 }
2684
Brad Ebinger7e934f52017-12-14 14:26:15 -08002685 /**
2686 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2687 * specified.
2688 */
2689 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2690 enforceModifyPermission();
2691 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2692 }
2693
Brad Ebingera12246d2018-01-16 09:39:35 -08002694 /**
2695 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2696 * specified.
2697 */
2698 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2699 enforceModifyPermission();
2700 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2701 }
2702
Brad Ebinger884c07b2018-02-15 16:17:40 -08002703 /**
2704 * @return true if emergency calling is available on IMS, false if it should fallback to CS.
2705 */
2706 public boolean isEmergencyMmTelAvailable(int slotId) {
2707 enforceModifyPermission();
2708 return PhoneFactory.getImsResolver().isEmergencyMmTelAvailable(slotId);
2709 }
2710
Wink Saville36469e72014-06-11 15:17:00 -07002711 public void setImsRegistrationState(boolean registered) {
2712 enforceModifyPermission();
2713 mPhone.setImsRegistrationState(registered);
2714 }
2715
2716 /**
Stuart Scott54788802015-03-30 13:18:01 -07002717 * Set the network selection mode to automatic.
2718 *
2719 */
2720 @Override
2721 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002722 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2723 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002724 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2725 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2726 }
2727
2728 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002729 * Set the network selection mode to manual with the selected carrier.
2730 */
2731 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002732 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002733 boolean persistSelection) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2735 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002736 OperatorInfo operator = new OperatorInfo(
2737 /* operatorAlphaLong */ "",
2738 /* operatorAlphaShort */ "",
2739 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002740 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002741 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2742 persistSelection);
2743 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002744 }
2745
2746 /**
2747 * Scans for available networks.
2748 */
2749 @Override
2750 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2752 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002753 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2754 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2755 CMD_PERFORM_NETWORK_SCAN, null, subId);
2756 return result;
2757 }
2758
2759 /**
yinxub1bed742017-04-17 11:45:04 -07002760 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002761 *
yinxub1bed742017-04-17 11:45:04 -07002762 * @param subId id of the subscription
2763 * @param request contains the radio access networks with bands/channels to scan
2764 * @param messenger callback messenger for scan results or errors
2765 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002766 * @return the id of the requested scan which can be used to stop the scan.
2767 */
2768 @Override
2769 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2770 IBinder binder) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2772 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002773 return mNetworkScanRequestTracker.startNetworkScan(
2774 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002775 }
2776
2777 /**
2778 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002779 *
2780 * @param subId id of the subscription
2781 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002782 */
2783 @Override
2784 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2786 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002787 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002788 }
2789
2790 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002791 * Get the calculated preferred network type.
2792 * Used for debugging incorrect network type.
2793 *
2794 * @return the preferred network type, defined in RILConstants.java.
2795 */
2796 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002797 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002798 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08002799 mApp, mPhone.getSubId(), callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002800 return RILConstants.PREFERRED_NETWORK_MODE;
2801 }
2802
Amit Mahajan43330e02014-11-18 11:54:45 -08002803 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002804 }
2805
2806 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002807 * Get the preferred network type.
2808 * Used for device configuration by some CDMA operators.
2809 *
2810 * @return the preferred network type, defined in RILConstants.java.
2811 */
2812 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002813 public int getPreferredNetworkType(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2815 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002816 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002817 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002818 int networkType = (result != null ? result[0] : -1);
2819 if (DBG) log("getPreferredNetworkType: " + networkType);
2820 return networkType;
2821 }
2822
2823 /**
2824 * Set the preferred network type.
2825 * Used for device configuration by some CDMA operators.
2826 *
2827 * @param networkType the preferred network type, defined in RILConstants.java.
2828 * @return true on success; false on any failure.
2829 */
2830 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002831 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002832 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2833 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002834 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2835 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002836 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002837 if (success) {
2838 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002839 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002840 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002841 return success;
2842 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002843
2844 /**
Junda Liu475951f2014-11-07 16:45:03 -08002845 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2846 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2847 * tethering.
2848 *
2849 * @return 0: Not required. 1: required. 2: Not set.
2850 * @hide
2851 */
2852 @Override
2853 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002854 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002855 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2856 Settings.Global.TETHER_DUN_REQUIRED, 2);
2857 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2858 // config_tether_apndata.
2859 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2860 dunRequired = 1;
2861 }
2862 return dunRequired;
2863 }
2864
2865 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002866 * Set mobile data enabled
2867 * Used by the user through settings etc to turn on/off mobile data
2868 *
2869 * @param enable {@code true} turn turn data on, else {@code false}
2870 */
2871 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002872 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2874 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002875 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002876 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002877 Phone phone = PhoneFactory.getPhone(phoneId);
2878 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002879 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2880 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002881 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002882 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002883 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002884 }
2885
2886 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002887 * Get the user enabled state of Mobile Data.
2888 *
2889 * TODO: remove and use isUserDataEnabled.
2890 * This can't be removed now because some vendor codes
2891 * calls through ITelephony directly while they should
2892 * use TelephonyManager.
2893 *
2894 * @return true on enabled
2895 */
2896 @Override
2897 public boolean getDataEnabled(int subId) {
2898 return isUserDataEnabled(subId);
2899 }
2900
2901 /**
2902 * Get whether mobile data is enabled per user setting.
2903 *
2904 * There are other factors deciding whether mobile data is actually enabled, but they are
2905 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002906 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002907 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002908 *
2909 * @return {@code true} if data is enabled else {@code false}
2910 */
2911 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002912 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002913 try {
2914 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2915 null);
2916 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2918 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002919 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002920 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002921 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002922 Phone phone = PhoneFactory.getPhone(phoneId);
2923 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002924 boolean retVal = phone.isUserDataEnabled();
2925 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002926 return retVal;
2927 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002928 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2929 return false;
2930 }
2931 }
2932
2933 /**
2934 * Get whether mobile data is enabled.
2935 *
2936 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2937 * whether mobile data is actually enabled.
2938 *
2939 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2940 *
2941 * @return {@code true} if data is enabled else {@code false}
2942 */
2943 @Override
2944 public boolean isDataEnabled(int subId) {
2945 try {
2946 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2947 null);
2948 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2950 mApp, subId, "isDataEnabled");
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002951 }
2952 int phoneId = mSubscriptionController.getPhoneId(subId);
2953 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2954 Phone phone = PhoneFactory.getPhone(phoneId);
2955 if (phone != null) {
2956 boolean retVal = phone.isDataEnabled();
2957 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2958 return retVal;
2959 } else {
2960 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002961 return false;
2962 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002963 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002964
2965 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002966 public int getCarrierPrivilegeStatus(int subId) {
2967 final Phone phone = getPhone(subId);
2968 if (phone == null) {
2969 loge("getCarrierPrivilegeStatus: Invalid subId");
2970 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2971 }
2972 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002973 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002974 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002975 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2976 }
2977 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002978 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002979 }
Junda Liu29340342014-07-10 15:23:27 -07002980
2981 @Override
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002982 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
2983 final Phone phone = getPhone(subId);
2984 if (phone == null) {
2985 loge("getCarrierPrivilegeStatus: Invalid subId");
2986 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2987 }
2988 UiccProfile profile =
2989 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
2990 if (profile == null) {
2991 loge("getCarrierPrivilegeStatus: No UICC");
2992 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2993 }
2994 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
2995 }
2996
2997 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002998 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002999 if (TextUtils.isEmpty(pkgName))
3000 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08003001 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07003002 if (card == null) {
3003 loge("checkCarrierPrivilegesForPackage: No UICC");
3004 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3005 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003006 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3007 }
3008
3009 @Override
3010 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003011 if (TextUtils.isEmpty(pkgName))
3012 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003013 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3014 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3015 UiccCard card = UiccController.getInstance().getUiccCard(i);
3016 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003017 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003018 continue;
3019 }
3020
3021 result = card.getCarrierPrivilegeStatus(
3022 mPhone.getContext().getPackageManager(), pkgName);
3023 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3024 break;
3025 }
3026 }
3027
3028 return result;
Junda Liu29340342014-07-10 15:23:27 -07003029 }
Derek Tan89e89d42014-07-08 17:00:10 -07003030
3031 @Override
Junda Liue64de782015-04-16 17:19:16 -07003032 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3033 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3034 loge("phoneId " + phoneId + " is not valid.");
3035 return null;
3036 }
3037 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003038 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003039 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003040 return null ;
3041 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003042 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003043 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003044 }
3045
Amith Yamasani6e118872016-02-19 12:53:51 -08003046 @Override
3047 public List<String> getPackagesWithCarrierPrivileges() {
3048 PackageManager pm = mPhone.getContext().getPackageManager();
3049 List<String> privilegedPackages = new ArrayList<>();
3050 List<PackageInfo> packages = null;
3051 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3052 UiccCard card = UiccController.getInstance().getUiccCard(i);
3053 if (card == null) {
3054 // No UICC in that slot.
3055 continue;
3056 }
3057 if (card.hasCarrierPrivilegeRules()) {
3058 if (packages == null) {
3059 // Only check packages in user 0 for now
3060 packages = pm.getInstalledPackagesAsUser(
3061 PackageManager.MATCH_DISABLED_COMPONENTS
3062 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3063 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3064 }
3065 for (int p = packages.size() - 1; p >= 0; p--) {
3066 PackageInfo pkgInfo = packages.get(p);
3067 if (pkgInfo != null && pkgInfo.packageName != null
3068 && card.getCarrierPrivilegeStatus(pkgInfo)
3069 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3070 privilegedPackages.add(pkgInfo.packageName);
3071 }
3072 }
3073 }
3074 }
3075 return privilegedPackages;
3076 }
3077
Wink Savilleb564aae2014-10-23 10:18:09 -07003078 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003079 final Phone phone = getPhone(subId);
3080 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003081 if (card == null) {
3082 loge("getIccId: No UICC");
3083 return null;
3084 }
3085 String iccId = card.getIccId();
3086 if (TextUtils.isEmpty(iccId)) {
3087 loge("getIccId: ICC ID is null or empty.");
3088 return null;
3089 }
3090 return iccId;
3091 }
3092
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003093 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003094 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3095 String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003096 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3097 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003098
Jeff Sharkey85190e62014-12-05 09:40:12 -08003099 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003100 final Phone phone = getPhone(subId);
3101 if (phone == null) {
3102 return false;
3103 }
3104 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003105
3106 if (DBG_MERGE) {
3107 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3108 + subscriberId + " to " + number);
3109 }
3110
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003111 if (TextUtils.isEmpty(iccId)) {
3112 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003113 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003114
Jeff Sharkey85190e62014-12-05 09:40:12 -08003115 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3116
3117 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003118 if (alphaTag == null) {
3119 editor.remove(alphaTagPrefKey);
3120 } else {
3121 editor.putString(alphaTagPrefKey, alphaTag);
3122 }
3123
Jeff Sharkey85190e62014-12-05 09:40:12 -08003124 // Record both the line number and IMSI for this ICCID, since we need to
3125 // track all merged IMSIs based on line number
3126 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3127 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003128 if (number == null) {
3129 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003130 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003131 } else {
3132 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003133 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003134 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003135
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003136 editor.commit();
3137 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003138 }
3139
3140 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003141 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003142 // This is open to apps with WRITE_SMS.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003144 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003145 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003146 return null;
3147 }
Derek Tan97ebb422014-09-05 16:55:38 -07003148
3149 String iccId = getIccId(subId);
3150 if (iccId != null) {
3151 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003152 if (DBG_MERGE) {
3153 log("getLine1NumberForDisplay returning " +
3154 mTelephonySharedPreferences.getString(numberPrefKey, null));
3155 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003156 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003157 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003158 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003159 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003160 }
3161
3162 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003163 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003165 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003166 return null;
3167 }
Derek Tan97ebb422014-09-05 16:55:38 -07003168
3169 String iccId = getIccId(subId);
3170 if (iccId != null) {
3171 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003172 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003173 }
Derek Tan97ebb422014-09-05 16:55:38 -07003174 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003175 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003176
3177 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003178 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003179 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
3180 // about carrier-privileged callers not having access.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003181 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003182 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
3183 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003184 return null;
3185 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003186 final Context context = mPhone.getContext();
3187 final TelephonyManager tele = TelephonyManager.from(context);
3188 final SubscriptionManager sub = SubscriptionManager.from(context);
3189
3190 // Figure out what subscribers are currently active
3191 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003192 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3193 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 final int[] subIds = sub.getActiveSubscriptionIdList();
3197 for (int subId : subIds) {
3198 activeSubscriberIds.add(tele.getSubscriberId(subId));
3199 }
3200 } finally {
3201 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003202 }
3203
3204 // First pass, find a number override for an active subscriber
3205 String mergeNumber = null;
3206 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3207 for (String key : prefs.keySet()) {
3208 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3209 final String subscriberId = (String) prefs.get(key);
3210 if (activeSubscriberIds.contains(subscriberId)) {
3211 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3212 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3213 mergeNumber = (String) prefs.get(numberKey);
3214 if (DBG_MERGE) {
3215 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3216 + " for active subscriber " + subscriberId);
3217 }
3218 if (!TextUtils.isEmpty(mergeNumber)) {
3219 break;
3220 }
3221 }
3222 }
3223 }
3224
3225 // Shortcut when no active merged subscribers
3226 if (TextUtils.isEmpty(mergeNumber)) {
3227 return null;
3228 }
3229
3230 // Second pass, find all subscribers under that line override
3231 final ArraySet<String> result = new ArraySet<>();
3232 for (String key : prefs.keySet()) {
3233 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3234 final String number = (String) prefs.get(key);
3235 if (mergeNumber.equals(number)) {
3236 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3237 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3238 final String subscriberId = (String) prefs.get(subscriberKey);
3239 if (!TextUtils.isEmpty(subscriberId)) {
3240 result.add(subscriberId);
3241 }
3242 }
3243 }
3244 }
3245
3246 final String[] resultArray = result.toArray(new String[result.size()]);
3247 Arrays.sort(resultArray);
3248 if (DBG_MERGE) {
3249 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3250 }
3251 return resultArray;
3252 }
3253
3254 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003255 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003256 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3257 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003258 final Phone phone = getPhone(subId);
3259 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003260 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003261
3262 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003263 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003264 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3265 List<String> cdmaNonRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003266 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003267 final Phone phone = getPhone(subId);
3268 if (phone == null) {
3269 return false;
3270 }
3271 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003272 cdmaNonRoamingList);
3273 }
3274
3275 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003276 public void setRadioCapability(RadioAccessFamily[] rafs) {
3277 try {
3278 ProxyController.getInstance().setRadioCapability(rafs);
3279 } catch (RuntimeException e) {
3280 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3281 }
3282 }
3283
3284 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003285 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003286 Phone phone = PhoneFactory.getPhone(phoneId);
3287 if (phone == null) {
3288 return RadioAccessFamily.RAF_UNKNOWN;
3289 }
3290 int subId = phone.getSubId();
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003291 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003292 mApp, subId, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003293 return RadioAccessFamily.RAF_UNKNOWN;
3294 }
3295
Wink Saville5d475dd2014-10-17 15:00:58 -07003296 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3297 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003298
3299 @Override
3300 public void enableVideoCalling(boolean enable) {
3301 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003302 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003303 }
3304
3305 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003306 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003308 mApp, mPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003309 return false;
3310 }
3311
Andrew Lee77527ac2014-10-21 16:57:39 -07003312 // Check the user preference and the system-level IMS setting. Even if the user has
3313 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3314 // In the long run, we may instead need to check if there exists a connection service
3315 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003316 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3317 return imsManager.isVtEnabledByPlatform()
3318 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3319 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003320 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003321
Andrew Leea1239f22015-03-02 17:44:07 -08003322 @Override
3323 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003324 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003325 }
3326
3327 @Override
3328 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003329 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003330 }
3331
Andrew Lee9431b832015-03-09 18:46:45 -07003332 @Override
3333 public boolean isTtyModeSupported() {
3334 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3335 TelephonyManager telephonyManager =
3336 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003337 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003338 }
3339
3340 @Override
3341 public boolean isHearingAidCompatibilitySupported() {
3342 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3343 }
3344
Hall Liu73714012018-01-22 19:15:32 -08003345 public boolean isRttSupported() {
3346 boolean isCarrierSupported =
3347 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3348 boolean isDeviceSupported =
3349 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3350 return isCarrierSupported && isDeviceSupported;
3351 }
3352
Sanket Padawe7310cc72015-01-14 09:53:20 -08003353 /**
3354 * Returns the unique device ID of phone, for example, the IMEI for
3355 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3356 *
3357 * <p>Requires Permission:
3358 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3359 */
3360 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003361 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003362 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003363 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08003364 return null;
3365 }
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003366 int subId = phone.getSubId();
3367 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3368 mApp, subId, callingPackage, "getDeviceId")) {
3369 return null;
3370 }
3371 return phone.getDeviceId();
Sanket Padawe7310cc72015-01-14 09:53:20 -08003372 }
3373
Ping Sun014fe8e2016-03-02 19:16:45 +08003374 /**
3375 * {@hide}
3376 * Returns the IMS Registration Status on a particular subid
3377 *
3378 * @param subId
3379 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003380 public boolean isImsRegistered(int subId) {
Ping Sun014fe8e2016-03-02 19:16:45 +08003381 Phone phone = getPhone(subId);
3382 if (phone != null) {
3383 return phone.isImsRegistered();
3384 } else {
3385 return false;
3386 }
3387 }
3388
Santos Cordon7a1885b2015-02-03 11:15:19 -08003389 @Override
3390 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3391 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3392 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003393
Brad Ebingere21f25f2018-02-08 16:11:32 -08003394 /**
3395 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003396 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003397 public boolean isWifiCallingAvailable(int subId) {
3398 Phone phone = getPhone(subId);
3399 if (phone != null) {
3400 return phone.isWifiCallingEnabled();
3401 } else {
3402 return false;
3403 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003404 }
3405
Brad Ebingere21f25f2018-02-08 16:11:32 -08003406 /**
3407 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003408 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003409 public boolean isVolteAvailable(int subId) {
3410 Phone phone = getPhone(subId);
3411 if (phone != null) {
3412 return phone.isVolteEnabled();
3413 } else {
3414 return false;
3415 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003416 }
Svet Ganovb320e182015-04-16 12:30:10 -07003417
Brad Ebingere21f25f2018-02-08 16:11:32 -08003418 /**
3419 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003420 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003421 public boolean isVideoTelephonyAvailable(int subId) {
3422 Phone phone = getPhone(subId);
3423 if (phone != null) {
3424 return phone.isVideoEnabled();
3425 } else {
3426 return false;
3427 }
3428 }
3429
3430 /**
3431 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3432 * defined in {@link ImsRegistrationImplBase}.
3433 */
3434 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3435 Phone phone = getPhone(subId);
3436 if (phone != null) {
3437 return phone.getImsRegistrationTech();
3438 } else {
3439 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3440 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003441 }
3442
Stuart Scott8eef64f2015-04-08 15:13:54 -07003443 @Override
3444 public void factoryReset(int subId) {
3445 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003446 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3447 return;
3448 }
3449
Svet Ganovcc087f82015-05-12 20:35:54 -07003450 final long identity = Binder.clearCallingIdentity();
3451 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003452 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3453 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003454 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003455 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003456 // Set network selection mode to automatic
3457 setNetworkSelectionModeAutomatic(subId);
3458 // Set preferred mobile network type to the best available
Kitta Koutarouab8a69b2018-03-05 14:16:45 +09003459 String defaultNetwork = TelephonyManager.getTelephonyProperty(
3460 mSubscriptionController.getPhoneId(subId),
3461 "ro.telephony.default_network",
3462 null);
3463 int networkType = !TextUtils.isEmpty(defaultNetwork)
3464 ? Integer.parseInt(defaultNetwork) : Phone.PREFERRED_NT_MODE;
3465 setPreferredNetworkType(subId, networkType);
Svet Ganovcc087f82015-05-12 20:35:54 -07003466 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003467 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003468 }
3469 } finally {
3470 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003471 }
3472 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003473
3474 @Override
3475 public String getLocaleFromDefaultSim() {
3476 // We query all subscriptions instead of just the active ones, because
3477 // this might be called early on in the provisioning flow when the
3478 // subscriptions potentially aren't active yet.
3479 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3480 if (slist == null || slist.isEmpty()) {
3481 return null;
3482 }
3483
3484 // This function may be called very early, say, from the setup wizard, at
3485 // which point we won't have a default subscription set. If that's the case
3486 // we just choose the first, which will be valid in "most cases".
3487 final int defaultSubId = getDefaultSubscription();
3488 SubscriptionInfo info = null;
3489 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3490 info = slist.get(0);
3491 } else {
3492 for (SubscriptionInfo item : slist) {
3493 if (item.getSubscriptionId() == defaultSubId) {
3494 info = item;
3495 break;
3496 }
3497 }
3498
3499 if (info == null) {
3500 return null;
3501 }
3502 }
3503
3504 // Try and fetch the locale from the carrier properties or from the SIM language
3505 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003506 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003507 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003508 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003509 if (defaultPhone != null) {
3510 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3511 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003512 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003513 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3514 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003515 } else {
3516 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003517 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003518 }
3519 }
3520
Narayan Kamath011676f2015-07-29 12:04:08 +01003521 // The SIM language preferences only store a language (e.g. fr = French), not an
3522 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3523 // the SIM and carrier preferences does not include a country we add the country
3524 // determined from the SIM MCC to provide an exact locale.
3525 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003526 if (mccLocale != null) {
3527 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3528 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003529 }
3530
Tony Hill183b2de2015-06-24 14:53:58 +01003531 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003532 return null;
3533 }
3534
3535 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3536 final long identity = Binder.clearCallingIdentity();
3537 try {
3538 return mSubscriptionController.getAllSubInfoList(
3539 mPhone.getContext().getOpPackageName());
3540 } finally {
3541 Binder.restoreCallingIdentity(identity);
3542 }
3543 }
3544
3545 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 return mSubscriptionController.getActiveSubscriptionInfoList(
3549 mPhone.getContext().getOpPackageName());
3550 } finally {
3551 Binder.restoreCallingIdentity(identity);
3552 }
3553 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003554
3555 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003556 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3557 * representing the state of the modem.
3558 *
3559 * NOTE: This clears the modem state, so there should only every be one caller.
3560 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003561 */
3562 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003563 public void requestModemActivityInfo(ResultReceiver result) {
3564 enforceModifyPermission();
3565
3566 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3567 Bundle bundle = new Bundle();
3568 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3569 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003570 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003571
3572 /**
3573 * {@hide}
3574 * Returns the service state information on specified subscription.
3575 */
3576 @Override
3577 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3578
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003579 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003580 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003581 return null;
3582 }
3583
3584 final Phone phone = getPhone(subId);
3585 if (phone == null) {
3586 return null;
3587 }
3588
3589 return phone.getServiceState();
3590 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003591
3592 /**
3593 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3594 *
3595 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3596 * voicemail ringtone.
3597 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3598 * PhoneAccount.
3599 */
3600 @Override
3601 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003602 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003603 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003604 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003605 }
3606
fionaxu7ed723d2017-05-30 18:58:54 -07003607 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003608 }
3609
3610 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003611 * Sets the per-account voicemail ringtone.
3612 *
3613 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3614 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3615 *
3616 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3617 * voicemail ringtone.
3618 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3619 * PhoneAccount.
3620 */
3621 @Override
3622 public void setVoicemailRingtoneUri(String callingPackage,
3623 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3624 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3625 if (!TextUtils.equals(callingPackage,
3626 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3628 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3629 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003630 }
3631 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3632 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003633 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003634 }
fionaxu7ed723d2017-05-30 18:58:54 -07003635 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003636 }
3637
3638 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003639 * Returns whether vibration is set for voicemail notification in Phone settings.
3640 *
3641 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3642 * voicemail vibration setting.
3643 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3644 */
3645 @Override
3646 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003647 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003648 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003649 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003650 }
3651
fionaxu7ed723d2017-05-30 18:58:54 -07003652 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003653 }
3654
Youhan Wange64578a2016-05-02 15:32:42 -07003655 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003656 * Sets the per-account voicemail vibration.
3657 *
3658 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3659 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3660 *
3661 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3662 * voicemail vibration setting.
3663 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3664 * specific PhoneAccount.
3665 */
3666 @Override
3667 public void setVoicemailVibrationEnabled(String callingPackage,
3668 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3669 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3670 if (!TextUtils.equals(callingPackage,
3671 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3673 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3674 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003675 }
3676
3677 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3678 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003679 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003680 }
fionaxu7ed723d2017-05-30 18:58:54 -07003681 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003682 }
3683
3684 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003685 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3686 *
3687 * @throws SecurityException if the caller does not have the required permission
3688 */
3689 private void enforceReadPrivilegedPermission() {
3690 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3691 null);
3692 }
3693
3694 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003695 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3696 * permission.
3697 *
3698 * @throws SecurityException if the caller does not have the required permission
3699 */
3700 private void enforceSendSmsPermission() {
3701 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3702 }
3703
3704 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003705 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003706 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003707 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003708 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003709 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003710 ComponentName componentName =
3711 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3712 if(componentName == null) {
3713 throw new SecurityException("Caller not current active visual voicemail package[null]");
3714 }
3715 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003716 if (!callingPackage.equals(vvmPackage)) {
3717 throw new SecurityException("Caller not current active visual voicemail package[" +
3718 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003719 }
3720 }
3721
3722 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003723 * Return the application ID for the app type.
3724 *
3725 * @param subId the subscription ID that this request applies to.
3726 * @param appType the uicc app type.
3727 * @return Application ID for specificied app type, or null if no uicc.
3728 */
3729 @Override
3730 public String getAidForAppType(int subId, int appType) {
3731 enforceReadPrivilegedPermission();
3732 Phone phone = getPhone(subId);
3733 if (phone == null) {
3734 return null;
3735 }
3736 String aid = null;
3737 try {
3738 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3739 .getApplicationByType(appType).getAid();
3740 } catch (Exception e) {
3741 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3742 }
3743 return aid;
3744 }
3745
Youhan Wang4001d252016-05-11 10:29:41 -07003746 /**
3747 * Return the Electronic Serial Number.
3748 *
3749 * @param subId the subscription ID that this request applies to.
3750 * @return ESN or null if error.
3751 */
3752 @Override
3753 public String getEsn(int subId) {
3754 enforceReadPrivilegedPermission();
3755 Phone phone = getPhone(subId);
3756 if (phone == null) {
3757 return null;
3758 }
3759 String esn = null;
3760 try {
3761 esn = phone.getEsn();
3762 } catch (Exception e) {
3763 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3764 }
3765 return esn;
3766 }
3767
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003768 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003769 * Return the Preferred Roaming List Version.
3770 *
3771 * @param subId the subscription ID that this request applies to.
3772 * @return PRLVersion or null if error.
3773 */
3774 @Override
3775 public String getCdmaPrlVersion(int subId) {
3776 enforceReadPrivilegedPermission();
3777 Phone phone = getPhone(subId);
3778 if (phone == null) {
3779 return null;
3780 }
3781 String cdmaPrlVersion = null;
3782 try {
3783 cdmaPrlVersion = phone.getCdmaPrlVersion();
3784 } catch (Exception e) {
3785 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3786 }
3787 return cdmaPrlVersion;
3788 }
3789
3790 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003791 * Get snapshot of Telephony histograms
3792 * @return List of Telephony histograms
3793 * @hide
3794 */
3795 @Override
3796 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3798 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003799 return RIL.getTelephonyRILTimingHistograms();
3800 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003801
3802 /**
3803 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003804 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003805 * Require system privileges. In the future we may add this to carrier APIs.
3806 *
3807 * @return The number of carriers set successfully, should match length of carriers
3808 */
3809 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003810 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003811 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003812
Meng Wang9b7c4e92017-02-17 11:41:27 -08003813 if (carriers == null) {
3814 throw new NullPointerException("carriers cannot be null");
3815 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003816
3817 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003818 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3819 return retVal[0];
3820 }
3821
3822 /**
3823 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003824 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003825 * Require system privileges. In the future we may add this to carrier APIs.
3826 *
3827 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3828 * means all carriers are allowed.
3829 */
3830 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003831 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003832 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003833 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003834 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3835 }
3836
fionaxu59545b42016-05-25 15:53:37 -07003837 /**
3838 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3839 * @param subId the subscription ID that this action applies to.
3840 * @param enabled control enable or disable metered apns.
3841 * {@hide}
3842 */
3843 @Override
3844 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3845 enforceModifyPermission();
3846 final Phone phone = getPhone(subId);
3847 if (phone == null) {
3848 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3849 return;
3850 }
3851 try {
3852 phone.carrierActionSetMeteredApnsEnabled(enabled);
3853 } catch (Exception e) {
3854 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3855 }
3856 }
3857
3858 /**
3859 * Action set from carrier signalling broadcast receivers to enable/disable radio
3860 * @param subId the subscription ID that this action applies to.
3861 * @param enabled control enable or disable radio.
3862 * {@hide}
3863 */
3864 @Override
3865 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3866 enforceModifyPermission();
3867 final Phone phone = getPhone(subId);
3868 if (phone == null) {
3869 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3870 return;
3871 }
3872 try {
3873 phone.carrierActionSetRadioEnabled(enabled);
3874 } catch (Exception e) {
3875 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3876 }
3877 }
3878
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003879 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003880 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3881 * network status based on which carrier apps could apply actions accordingly,
3882 * enable/disable default url handler for example.
3883 *
3884 * @param subId the subscription ID that this action applies to.
3885 * @param report control start/stop reporting the default network status.
3886 * {@hide}
3887 */
3888 @Override
3889 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3890 enforceModifyPermission();
3891 final Phone phone = getPhone(subId);
3892 if (phone == null) {
3893 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3894 return;
3895 }
3896 try {
3897 phone.carrierActionReportDefaultNetworkStatus(report);
3898 } catch (Exception e) {
3899 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3900 }
3901 }
3902
3903 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003904 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3905 * bug report is being generated.
3906 */
3907 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003908 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003909 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3910 != PackageManager.PERMISSION_GRANTED) {
3911 writer.println("Permission Denial: can't dump Phone from pid="
3912 + Binder.getCallingPid()
3913 + ", uid=" + Binder.getCallingUid()
3914 + "without permission "
3915 + android.Manifest.permission.DUMP);
3916 return;
3917 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003918 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003919 }
Jack Yueb89b242016-06-22 13:27:47 -07003920
3921 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003922 * Get aggregated video call data usage since boot.
3923 *
3924 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3925 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003926 * {@hide}
3927 */
3928 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003929 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003930 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3931 null);
3932
Jack Yu84291ec2017-05-26 16:07:50 -07003933 // NetworkStatsService keeps tracking the active network interface and identity. It
3934 // records the delta with the corresponding network identity. We just return the total video
3935 // call data usage snapshot since boot.
3936 Phone phone = getPhone(subId);
3937 if (phone != null) {
3938 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003939 }
Jack Yu84291ec2017-05-26 16:07:50 -07003940 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003941 }
Jack Yu75ab2952016-07-08 14:29:33 -07003942
3943 /**
3944 * Policy control of data connection. Usually used when data limit is passed.
3945 * @param enabled True if enabling the data, otherwise disabling.
3946 * @param subId Subscription index
3947 * {@hide}
3948 */
3949 @Override
3950 public void setPolicyDataEnabled(boolean enabled, int subId) {
3951 enforceModifyPermission();
3952 Phone phone = getPhone(subId);
3953 if (phone != null) {
3954 phone.setPolicyDataEnabled(enabled);
3955 }
3956 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003957
3958 /**
3959 * Get Client request stats
3960 * @return List of Client Request Stats
3961 * @hide
3962 */
3963 @Override
3964 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003965 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidsone371a1a2018-02-23 17:11:49 -08003966 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003967 return null;
3968 }
3969
3970 Phone phone = getPhone(subId);
3971 if (phone != null) {
3972 return phone.getClientRequestStats();
3973 }
3974
3975 return null;
3976 }
3977
3978 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3979 if (workSource != null) {
3980 return workSource;
3981 }
3982
3983 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3984 workSource = new WorkSource(uid, packageName);
3985 return workSource;
3986 }
Jack Yueb4124c2017-02-16 15:32:43 -08003987
3988 /**
Grace Chen70990072017-03-24 17:21:30 -07003989 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003990 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003991 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003992 * @param state State of SIM (power down, power up, pass through)
3993 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3994 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3995 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003996 *
3997 **/
3998 @Override
Grace Chen70990072017-03-24 17:21:30 -07003999 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08004000 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004001 Phone phone = PhoneFactory.getPhone(slotIndex);
4002
Jack Yueb4124c2017-02-16 15:32:43 -08004003 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07004004 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08004005 }
4006 }
Shuo Qiandd210312017-04-12 22:11:33 +00004007
Tyler Gunn65d45c22017-06-05 11:22:26 -07004008 private boolean isUssdApiAllowed(int subId) {
4009 CarrierConfigManager configManager =
4010 (CarrierConfigManager) mPhone.getContext().getSystemService(
4011 Context.CARRIER_CONFIG_SERVICE);
4012 if (configManager == null) {
4013 return false;
4014 }
4015 PersistableBundle pb = configManager.getConfigForSubId(subId);
4016 if (pb == null) {
4017 return false;
4018 }
4019 return pb.getBoolean(
4020 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4021 }
4022
Shuo Qiandd210312017-04-12 22:11:33 +00004023 /**
4024 * Check if phone is in emergency callback mode
4025 * @return true if phone is in emergency callback mode
4026 * @param subId sub id
4027 */
4028 public boolean getEmergencyCallbackMode(int subId) {
4029 final Phone phone = getPhone(subId);
4030 if (phone != null) {
4031 return phone.isInEcm();
4032 } else {
4033 return false;
4034 }
4035 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004036
4037 /**
4038 * Get the current signal strength information for the given subscription.
4039 * Because this information is not updated when the device is in a low power state
4040 * it should not be relied-upon to be current.
4041 * @param subId Subscription index
4042 * @return the most recent cached signal strength info from the modem
4043 */
4044 @Override
4045 public SignalStrength getSignalStrength(int subId) {
4046 Phone p = getPhone(subId);
4047 if (p == null) {
4048 return null;
4049 }
4050
4051 return p.getSignalStrength();
4052 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004053
4054 @Override
4055 public UiccSlotInfo[] getUiccSlotsInfo() {
4056 enforceReadPrivilegedPermission();
4057
4058 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4059 if (slots == null) return null;
4060 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4061 for (int i = 0; i < slots.length; i++) {
4062 UiccSlot slot = slots[i];
4063
4064 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4065
4066 int cardState = 0;
4067 switch (slot.getCardState()) {
4068 case CARDSTATE_ABSENT:
4069 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4070 break;
4071 case CARDSTATE_PRESENT:
4072 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4073 break;
4074 case CARDSTATE_ERROR:
4075 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4076 break;
4077 case CARDSTATE_RESTRICTED:
4078 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4079 break;
4080 default:
4081 break;
4082
4083 }
4084
Qingxi Li63668902018-01-31 13:43:27 -08004085 infos[i] = new UiccSlotInfo(
4086 slot.isActive(), slot.isEuicc(), cardId, cardState, slot.getPhoneId());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004087 }
4088 return infos;
4089 }
4090
4091 @Override
4092 public boolean switchSlots(int[] physicalSlots) {
4093 enforceModifyPermission();
4094 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4095 }
Jack Yue6146032018-02-27 15:30:01 -08004096
4097 @Override
4098 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4099 enforceModifyPermission();
4100 final Phone phone = getPhone(subId);
4101 if (phone == null) {
4102 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4103 return;
4104 }
4105
4106 phone.setRadioIndicationUpdateMode(filters, mode);
4107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004108}