blob: aac22938b13b8840da23a945577b96d0a5766cf7 [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(
1260 mApp, 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(
1280 mApp, 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(
1300 mApp, 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(
1476 mApp, 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 Davidsond9a1bb52018-02-13 18:17:36 -08001789 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1790 mApp, callingPackage, "getImeiForSlot")) {
1791 return null;
1792 }
1793 Phone phone = PhoneFactory.getPhone(slotIndex);
1794 return phone == null ? null : phone.getImei();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001795 }
1796
1797 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07001798 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001799 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1800 mApp, callingPackage, "getMeidForSlot")) {
Jack Yu2af8d712017-03-15 17:14:14 -07001801 return null;
1802 }
1803 Phone phone = PhoneFactory.getPhone(slotIndex);
1804 return phone == null ? null : phone.getMeid();
1805 }
1806
1807 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001808 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1810 mApp, callingPackage, "getDeviceSoftwareVersionForSlot")) {
1811 return null;
1812 }
1813 Phone phone = PhoneFactory.getPhone(slotIndex);
1814 return phone == null ? null : phone.getDeviceSvn();
Shishir Agrawala9f32182016-04-12 12:00:16 -07001815 }
1816
fionaxuf32acdf2017-11-27 22:51:16 -08001817 @Override
1818 public int getSubscriptionCarrierId(int subId) {
1819 final Phone phone = getPhone(subId);
1820 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
1821 }
1822
1823 @Override
1824 public String getSubscriptionCarrierName(int subId) {
1825 final Phone phone = getPhone(subId);
1826 return phone == null ? null : phone.getCarrierName();
1827 }
1828
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 //
1830 // Internal helper methods.
1831 //
1832
Sanket Padaweee13a9b2016-03-08 17:30:28 -08001833 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001834 * Make sure the caller has the MODIFY_PHONE_STATE permission.
1835 *
1836 * @throws SecurityException if the caller does not have the required permission
1837 */
1838 private void enforceModifyPermission() {
1839 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
1840 }
1841
1842 /**
1843 * Make sure the caller has the CALL_PHONE permission.
1844 *
1845 * @throws SecurityException if the caller does not have the required permission
1846 */
1847 private void enforceCallPermission() {
1848 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
1849 }
1850
Stuart Scott8eef64f2015-04-08 15:13:54 -07001851 private void enforceConnectivityInternalPermission() {
1852 mApp.enforceCallingOrSelfPermission(
1853 android.Manifest.permission.CONNECTIVITY_INTERNAL,
1854 "ConnectivityService");
1855 }
1856
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 private String createTelUrl(String number) {
1858 if (TextUtils.isEmpty(number)) {
1859 return null;
1860 }
1861
Jake Hambye994d462014-02-03 13:10:13 -08001862 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 }
1864
Ihab Awadf9e92732013-12-05 18:02:52 -08001865 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001866 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
1867 }
1868
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001869 private static void logv(String msg) {
1870 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
1871 }
1872
Ihab Awadf9e92732013-12-05 18:02:52 -08001873 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
1875 }
1876
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001877 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001878 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001879 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001880 }
1881
Sanket Padawe356d7632015-06-22 14:03:32 -07001882 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001883 public int getActivePhoneTypeForSlot(int slotIndex) {
1884 final Phone phone = PhoneFactory.getPhone(slotIndex);
Sanket Padawe356d7632015-06-22 14:03:32 -07001885 if (phone == null) {
1886 return PhoneConstants.PHONE_TYPE_NONE;
1887 } else {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001888 return phone.getPhoneType();
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 }
1891
1892 /**
1893 * Returns the CDMA ERI icon index to display
1894 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001895 @Override
1896 public int getCdmaEriIconIndex(String callingPackage) {
1897 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001898 }
1899
Sanket Padawe356d7632015-06-22 14:03:32 -07001900 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001901 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001902 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1903 mApp, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001904 return -1;
1905 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001906 final Phone phone = getPhone(subId);
1907 if (phone != null) {
1908 return phone.getCdmaEriIconIndex();
1909 } else {
1910 return -1;
1911 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001912 }
1913
1914 /**
1915 * Returns the CDMA ERI icon mode,
1916 * 0 - ON
1917 * 1 - FLASHING
1918 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001919 @Override
1920 public int getCdmaEriIconMode(String callingPackage) {
1921 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001922 }
1923
Sanket Padawe356d7632015-06-22 14:03:32 -07001924 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001925 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1927 mApp, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001928 return -1;
1929 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001930 final Phone phone = getPhone(subId);
1931 if (phone != null) {
1932 return phone.getCdmaEriIconMode();
1933 } else {
1934 return -1;
1935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
1938 /**
1939 * Returns the CDMA ERI text,
1940 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001941 @Override
1942 public String getCdmaEriText(String callingPackage) {
1943 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001944 }
1945
Sanket Padawe356d7632015-06-22 14:03:32 -07001946 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001947 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001948 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1949 mApp, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001950 return null;
1951 }
Sanket Padawe356d7632015-06-22 14:03:32 -07001952 final Phone phone = getPhone(subId);
1953 if (phone != null) {
1954 return phone.getCdmaEriText();
1955 } else {
1956 return null;
1957 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958 }
1959
1960 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07001961 * Returns the CDMA MDN.
1962 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001963 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001964 public String getCdmaMdn(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1966 mApp, subId, "getCdmaMdn");
Sanket Padawe356d7632015-06-22 14:03:32 -07001967 final Phone phone = getPhone(subId);
1968 if (mPhone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA && phone != null) {
1969 return phone.getLine1Number();
Junda Liuca05d5d2014-08-14 22:36:34 -07001970 } else {
1971 return null;
1972 }
1973 }
1974
1975 /**
1976 * Returns the CDMA MIN.
1977 */
Sanket Padawe356d7632015-06-22 14:03:32 -07001978 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001979 public String getCdmaMin(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08001980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1981 mApp, subId, "getCdmaMin");
Sanket Padawe356d7632015-06-22 14:03:32 -07001982 final Phone phone = getPhone(subId);
1983 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
1984 return phone.getCdmaMin();
Junda Liuca05d5d2014-08-14 22:36:34 -07001985 } else {
1986 return null;
1987 }
1988 }
1989
1990 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 * Returns true if CDMA provisioning needs to run.
1992 */
1993 public boolean needsOtaServiceProvisioning() {
1994 return mPhone.needsOtaServiceProvisioning();
1995 }
1996
1997 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001998 * Sets the voice mail number of a given subId.
1999 */
2000 @Override
2001 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002002 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002003 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2004 new Pair<String, String>(alphaTag, number), new Integer(subId));
2005 return success;
2006 }
2007
Ta-wei Yen87c49842016-05-13 21:19:52 -07002008 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002009 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2010 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2011 String systemDialer = TelecomManager.from(mPhone.getContext()).getSystemDialerPackage();
2012 if (!TextUtils.equals(callingPackage, systemDialer)) {
2013 throw new SecurityException("caller must be system dialer");
2014 }
2015 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2016 if (phoneAccountHandle == null){
2017 return null;
2018 }
2019 return VisualVoicemailSettingsUtil.dump(mPhone.getContext(), phoneAccountHandle);
2020 }
2021
2022 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002023 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002024 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002025 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2026 mApp, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002027 return null;
2028 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002029 return RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId).getPackageName();
2030 }
2031
2032 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002033 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2034 VisualVoicemailSmsFilterSettings settings) {
2035 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002036 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002037 .enableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId,
2038 settings);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002039 }
2040
2041 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002042 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2043 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002044 VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002045 .disableVisualVoicemailSmsFilter(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002046 }
2047
2048 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002049 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2050 String callingPackage, int subId) {
2051 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002052 return VisualVoicemailSmsFilterConfig
Ta-wei Yenb6929602016-05-24 15:48:27 -07002053 .getVisualVoicemailSmsFilterSettings(mPhone.getContext(), callingPackage, subId);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002054 }
2055
2056 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002057 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Ta-wei Yenb6929602016-05-24 15:48:27 -07002058 enforceReadPrivilegedPermission();
Ta-wei Yen87c49842016-05-13 21:19:52 -07002059 return VisualVoicemailSmsFilterConfig
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002060 .getActiveVisualVoicemailSmsFilterSettings(mPhone.getContext(), subId);
2061 }
2062
2063 @Override
2064 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2065 String number, int port, String text, PendingIntent sentIntent) {
2066 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002067 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002068 enforceSendSmsPermission();
2069 // Make the calls as the phone process.
2070 final long identity = Binder.clearCallingIdentity();
2071 try {
2072 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2073 if (port == 0) {
2074 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2075 sentIntent, null, false);
2076 } else {
2077 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2078 smsManager.sendDataMessageWithSelfPermissions(number, null,
2079 (short) port, data, sentIntent, null);
2080 }
2081 } finally {
2082 Binder.restoreCallingIdentity(identity);
2083 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002084 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002085 /**
fionaxu0152e512016-11-14 13:36:14 -08002086 * Sets the voice activation state of a given subId.
2087 */
2088 @Override
2089 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002090 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2091 mApp, subId, "setVoiceActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002092 final Phone phone = getPhone(subId);
2093 if (phone != null) {
2094 phone.setVoiceActivationState(activationState);
2095 } else {
2096 loge("setVoiceActivationState fails with invalid subId: " + subId);
2097 }
2098 }
2099
2100 /**
2101 * Sets the data activation state of a given subId.
2102 */
2103 @Override
2104 public void setDataActivationState(int subId, int activationState) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2106 mApp, subId, "setDataActivationState");
fionaxu0152e512016-11-14 13:36:14 -08002107 final Phone phone = getPhone(subId);
2108 if (phone != null) {
2109 phone.setDataActivationState(activationState);
2110 } else {
2111 loge("setVoiceActivationState fails with invalid subId: " + subId);
2112 }
2113 }
2114
2115 /**
2116 * Returns the voice activation state of a given subId.
2117 */
2118 @Override
2119 public int getVoiceActivationState(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002120 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2121 mApp, callingPackage, "getVoiceActivationStateForSubscriber")) {
fionaxu0152e512016-11-14 13:36:14 -08002122 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2123 }
2124 final Phone phone = getPhone(subId);
2125 if (phone != null) {
2126 return phone.getVoiceActivationState();
2127 } else {
2128 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2129 }
2130 }
2131
2132 /**
2133 * Returns the data activation state of a given subId.
2134 */
2135 @Override
2136 public int getDataActivationState(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002137 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2138 mApp, callingPackage, "getDataActivationStateForSubscriber")) {
fionaxu0152e512016-11-14 13:36:14 -08002139 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2140 }
2141 final Phone phone = getPhone(subId);
2142 if (phone != null) {
2143 return phone.getDataActivationState();
2144 } else {
2145 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2146 }
2147 }
2148
2149 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002150 * Returns the unread count of voicemails
2151 */
2152 public int getVoiceMessageCount() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002153 return getVoiceMessageCountForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002154 }
2155
2156 /**
2157 * Returns the unread count of voicemails for a subId
2158 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002159 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002160 public int getVoiceMessageCountForSubscriber( int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002161 final Phone phone = getPhone(subId);
2162 if (phone != null) {
2163 return phone.getVoiceMessageCount();
2164 } else {
2165 return 0;
2166 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 }
2168
2169 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002170 * returns true, if the device is in a state where both voice and data
2171 * are supported simultaneously. This can change based on location or network condition.
2172 */
2173 @Override
2174 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
2175 final Phone phone = getPhone(subId);
2176 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2177 }
2178
2179 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002180 * Send the dialer code if called from the current default dialer or the caller has
2181 * carrier privilege.
2182 * @param inputCode The dialer code to send
2183 */
2184 @Override
2185 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
2186 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2187 String defaultDialer = TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage();
2188 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002189 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2190 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002191 }
2192 mPhone.sendDialerSpecialCode(inputCode);
2193 }
2194
2195 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002196 * Returns the data network type.
2197 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 *
2199 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2200 */
2201 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002202 public int getNetworkType() {
2203 final Phone phone = getPhone(getDefaultSubscription());
2204 if (phone != null) {
2205 return phone.getServiceState().getDataNetworkType();
2206 } else {
2207 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2208 }
Wink Saville36469e72014-06-11 15:17:00 -07002209 }
2210
2211 /**
2212 * Returns the network type for a subId
2213 */
2214 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002215 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002216 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2217 mApp, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002218 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2219 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002220
Sanket Padawe356d7632015-06-22 14:03:32 -07002221 final Phone phone = getPhone(subId);
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002222 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002223 return phone.getServiceState().getDataNetworkType();
2224 } else {
2225 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 }
2228
2229 /**
2230 * Returns the data network type
2231 */
2232 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002233 public int getDataNetworkType(String callingPackage) {
2234 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002235 }
2236
2237 /**
2238 * Returns the data network type for a subId
2239 */
2240 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002241 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2243 mApp, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002244 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2245 }
2246
Sanket Padawe356d7632015-06-22 14:03:32 -07002247 final Phone phone = getPhone(subId);
2248 if (phone != null) {
2249 return phone.getServiceState().getDataNetworkType();
2250 } else {
2251 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 }
2254
2255 /**
Wink Saville36469e72014-06-11 15:17:00 -07002256 * Returns the Voice network type for a subId
2257 */
2258 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002259 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2261 mApp, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002262 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2263 }
2264
Sanket Padawe356d7632015-06-22 14:03:32 -07002265 final Phone phone = getPhone(subId);
2266 if (phone != null) {
2267 return phone.getServiceState().getVoiceNetworkType();
2268 } else {
2269 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2270 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002271 }
2272
2273 /**
2274 * @return true if a ICC card is present
2275 */
2276 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07002277 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002278 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
2279 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07002280 }
2281
2282 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002283 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07002284 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002285 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002286 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
2287 final Phone phone = PhoneFactory.getPhone(slotIndex);
fionaxu6e6c68b2016-06-23 13:31:32 -07002288 if (phone != null) {
Sanket Padawe356d7632015-06-22 14:03:32 -07002289 return phone.getIccCard().hasIccCard();
Amit Mahajana6fc2a82015-01-06 11:53:51 -08002290 } else {
2291 return false;
2292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 }
2294
2295 /**
2296 * Return if the current radio is LTE on CDMA. This
2297 * is a tri-state return value as for a period of time
2298 * the mode may be unknown.
2299 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002300 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08002302 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002304 @Override
2305 public int getLteOnCdmaMode(String callingPackage) {
2306 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002307 }
2308
Sanket Padawe356d7632015-06-22 14:03:32 -07002309 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002310 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2312 mApp, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002313 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2314 }
2315
Sanket Padawe356d7632015-06-22 14:03:32 -07002316 final Phone phone = getPhone(subId);
2317 if (phone == null) {
2318 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
2319 } else {
2320 return phone.getLteOnCdmaMode();
2321 }
Wink Saville36469e72014-06-11 15:17:00 -07002322 }
2323
2324 public void setPhone(Phone phone) {
2325 mPhone = phone;
2326 }
2327
2328 /**
2329 * {@hide}
2330 * Returns Default subId, 0 in the case of single standby.
2331 */
Wink Savilleb564aae2014-10-23 10:18:09 -07002332 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002333 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07002334 }
2335
Shishir Agrawala9f32182016-04-12 12:00:16 -07002336 private int getSlotForDefaultSubscription() {
2337 return mSubscriptionController.getPhoneId(getDefaultSubscription());
2338 }
2339
Wink Savilleb564aae2014-10-23 10:18:09 -07002340 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002341 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 }
Ihab Awadf2177b72013-11-25 13:33:23 -08002343
2344 /**
2345 * @see android.telephony.TelephonyManager.WifiCallingChoices
2346 */
2347 public int getWhenToMakeWifiCalls() {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002348 return Settings.System.getInt(mPhone.getContext().getContentResolver(),
2349 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, getWhenToMakeWifiCallsDefaultPreference());
Ihab Awadf2177b72013-11-25 13:33:23 -08002350 }
2351
2352 /**
2353 * @see android.telephony.TelephonyManager.WifiCallingChoices
2354 */
2355 public void setWhenToMakeWifiCalls(int preference) {
Sailesh Nepald1e68152013-12-12 19:08:02 -08002356 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
2357 Settings.System.putInt(mPhone.getContext().getContentResolver(),
2358 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
Ihab Awadf9e92732013-12-05 18:02:52 -08002359 }
2360
Sailesh Nepald1e68152013-12-12 19:08:02 -08002361 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07002362 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08002363 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08002364 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08002365
Shishir Agrawal566b7612013-10-28 14:41:00 -07002366 @Override
Derek Tan740e1672017-06-27 14:56:27 -07002367 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
2368 int subId, String callingPackage, String aid, int p2) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002369 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2370 mApp, subId, "iccOpenLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002371
Derek Tan740e1672017-06-27 14:56:27 -07002372 if (TextUtils.equals(ISDR_AID, aid)) {
2373 // Only allows LPA to open logical channel to ISD-R.
2374 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2375 ComponentInfo bestComponent =
2376 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2377 if (bestComponent == null
2378 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2379 loge("The calling package is not allowed to access ISD-R.");
2380 throw new SecurityException("The calling package is not allowed to access ISD-R.");
2381 }
2382 }
2383
2384 if (DBG) log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002385 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse)sendRequest(
Derek Tan740e1672017-06-27 14:56:27 -07002386 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002387 if (DBG) log("iccOpenLogicalChannel: " + response);
2388 return response;
Shishir Agrawal566b7612013-10-28 14:41:00 -07002389 }
2390
2391 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002392 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2394 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002395
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002396 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002397 if (channel < 0) {
2398 return false;
2399 }
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002400 Boolean success = (Boolean)sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002401 if (DBG) log("iccCloseLogicalChannel: " + success);
2402 return success;
2403 }
2404
2405 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002406 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07002407 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2409 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07002410
2411 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002412 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel +
2413 " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 +
Shishir Agrawal566b7612013-10-28 14:41:00 -07002414 " data=" + data);
2415 }
2416
2417 if (channel < 0) {
2418 return "";
2419 }
2420
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002421 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002422 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
Shishir Agrawal566b7612013-10-28 14:41:00 -07002423 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
2424
Shishir Agrawal566b7612013-10-28 14:41:00 -07002425 // Append the returned status code to the end of the response payload.
2426 String s = Integer.toHexString(
2427 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002428 if (response.payload != null) {
2429 s = IccUtils.bytesToHexString(response.payload) + s;
2430 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07002431 return s;
2432 }
Jake Hambye994d462014-02-03 13:10:13 -08002433
Evan Charltonc66da362014-05-16 14:06:40 -07002434 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002435 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
2436 int command, int p1, int p2, int p3, String data) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2438 mApp, subId, "iccTransmitApduBasicChannel");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002439
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08002440 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
2441 && TextUtils.equals(ISDR_AID, data)) {
2442 // Only allows LPA to select ISD-R.
2443 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2444 ComponentInfo bestComponent =
2445 EuiccConnector.findBestComponent(mPhone.getContext().getPackageManager());
2446 if (bestComponent == null
2447 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
2448 loge("The calling package is not allowed to select ISD-R.");
2449 throw new SecurityException("The calling package is not allowed to select ISD-R.");
2450 }
2451 }
2452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002453 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002454 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" + command
2455 + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002456 }
2457
2458 IccIoResult response = (IccIoResult)sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002459 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002460 if (DBG) log("iccTransmitApduBasicChannel: " + response);
2461
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002462 // Append the returned status code to the end of the response payload.
2463 String s = Integer.toHexString(
2464 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07002465 if (response.payload != null) {
2466 s = IccUtils.bytesToHexString(response.payload) + s;
2467 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002468 return s;
2469 }
2470
2471 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002472 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002473 String filePath) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2475 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002476
2477 if (DBG) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002478 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " +
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002479 p1 + " " + p2 + " " + p3 + ":" + filePath);
2480 }
2481
2482 IccIoResult response =
2483 (IccIoResult)sendRequest(CMD_EXCHANGE_SIM_IO,
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002484 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
2485 subId);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002486
2487 if (DBG) {
2488 log("Exchange SIM_IO [R]" + response);
2489 }
2490
2491 byte[] result = null;
2492 int length = 2;
2493 if (response.payload != null) {
2494 length = 2 + response.payload.length;
2495 result = new byte[length];
2496 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
2497 } else {
2498 result = new byte[length];
2499 }
2500
2501 result[length - 1] = (byte) response.sw2;
2502 result[length - 2] = (byte) response.sw1;
2503 return result;
2504 }
2505
Nathan Haroldb3014052017-01-25 15:57:32 -08002506 /**
2507 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
2508 * on a particular subscription
2509 */
2510 public String[] getForbiddenPlmns(int subId, int appType) {
Nathan Harold892104e2017-04-13 18:19:05 -07002511 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
2512 "Requires READ_PHONE_STATE");
Nathan Haroldb3014052017-01-25 15:57:32 -08002513 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
2514 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
2515 return null;
2516 }
2517 Object response = sendRequest(
2518 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
2519 if (response instanceof String[]) {
2520 return (String[]) response;
2521 }
2522 // Response is an Exception of some kind, which is signalled to the user as a NULL retval
2523 return null;
2524 }
2525
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07002526 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002527 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2529 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07002530
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002531 IccIoResult response = (IccIoResult)sendRequest(CMD_SEND_ENVELOPE, content, subId);
Evan Charltonc66da362014-05-16 14:06:40 -07002532 if (response.payload == null) {
2533 return "";
2534 }
2535
2536 // Append the returned status code to the end of the response payload.
2537 String s = Integer.toHexString(
2538 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
2539 s = IccUtils.bytesToHexString(response.payload) + s;
2540 return s;
2541 }
2542
Jake Hambye994d462014-02-03 13:10:13 -08002543 /**
2544 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2545 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2546 *
2547 * @param itemID the ID of the item to read
2548 * @return the NV item as a String, or null on error.
2549 */
2550 @Override
2551 public String nvReadItem(int itemID) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2553 mApp, getDefaultSubscription(), "nvReadItem");
Jake Hambye994d462014-02-03 13:10:13 -08002554 if (DBG) log("nvReadItem: item " + itemID);
2555 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID);
2556 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
2557 return value;
2558 }
2559
2560 /**
2561 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
2562 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
2563 *
2564 * @param itemID the ID of the item to read
2565 * @param itemValue the value to write, as a String
2566 * @return true on success; false on any failure
2567 */
2568 @Override
2569 public boolean nvWriteItem(int itemID, String itemValue) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002570 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2571 mApp, getDefaultSubscription(), "nvWriteItem");
Jake Hambye994d462014-02-03 13:10:13 -08002572 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
2573 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
2574 new Pair<Integer, String>(itemID, itemValue));
2575 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
2576 return success;
2577 }
2578
2579 /**
2580 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
2581 * Used for device configuration by some CDMA operators.
2582 *
2583 * @param preferredRoamingList byte array containing the new PRL
2584 * @return true on success; false on any failure
2585 */
2586 @Override
2587 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2589 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Jake Hambye994d462014-02-03 13:10:13 -08002590 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
2591 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
2592 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
2593 return success;
2594 }
2595
2596 /**
2597 * Perform the specified type of NV config reset.
2598 * Used for device configuration by some CDMA operators.
2599 *
2600 * @param resetType the type of reset to perform (1 == factory reset; 2 == NV-only reset)
2601 * @return true on success; false on any failure
2602 */
2603 @Override
2604 public boolean nvResetConfig(int resetType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2606 mApp, getDefaultSubscription(), "nvResetConfig");
Jake Hambye994d462014-02-03 13:10:13 -08002607 if (DBG) log("nvResetConfig: type " + resetType);
2608 Boolean success = (Boolean) sendRequest(CMD_NV_RESET_CONFIG, resetType);
2609 if (DBG) log("nvResetConfig: type " + resetType + ' ' + (success ? "ok" : "fail"));
2610 return success;
2611 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002612
2613 /**
Wink Saville36469e72014-06-11 15:17:00 -07002614 * {@hide}
2615 * Returns Default sim, 0 in the case of single standby.
2616 */
2617 public int getDefaultSim() {
2618 //TODO Need to get it from Telephony Devcontroller
2619 return 0;
2620 }
2621
Svet Ganovb320e182015-04-16 12:30:10 -07002622 public String[] getPcscfAddress(String apnType, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002623 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2624 mApp, callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002625 return new String[0];
2626 }
2627
2628
ram87fca6f2014-07-18 18:58:44 +05302629 return mPhone.getPcscfAddress(apnType);
Wink Saville36469e72014-06-11 15:17:00 -07002630 }
2631
Brad Ebinger51f743a2017-01-23 13:50:20 -08002632 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002633 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
2634 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08002635 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002636 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08002637 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002638 PhoneFactory.getImsResolver().enableIms(slotId);
Brad Ebinger34bef922017-11-09 10:27:08 -08002639 }
2640
2641 /**
Brad Ebingera12246d2018-01-16 09:39:35 -08002642 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
2643 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08002644 */
Brad Ebingera12246d2018-01-16 09:39:35 -08002645 public void disableIms(int slotId) {
2646 enforceModifyPermission();
2647 PhoneFactory.getImsResolver().disableIms(slotId);
2648 }
2649
2650 /**
2651 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
2652 * feature or {@link null} if the service is not available. If the feature is available, the
2653 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
2654 */
2655 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08002656 IImsServiceFeatureCallback callback) {
2657 enforceModifyPermission();
Brad Ebingera12246d2018-01-16 09:39:35 -08002658 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
Brad Ebinger34bef922017-11-09 10:27:08 -08002659 }
2660
2661 /**
2662 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
2663 * feature during emergency calling or {@link null} if the service is not available. If the
2664 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
2665 * listener for feature updates.
2666 */
2667 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
2668 enforceModifyPermission();
2669 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
Brad Ebinger51f743a2017-01-23 13:50:20 -08002670 }
2671
Brad Ebinger7e934f52017-12-14 14:26:15 -08002672 /**
2673 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
2674 * specified.
2675 */
2676 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
2677 enforceModifyPermission();
2678 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
2679 }
2680
Brad Ebingera12246d2018-01-16 09:39:35 -08002681 /**
2682 * Returns the {@link IImsConfig} structure associated with the slotId and feature
2683 * specified.
2684 */
2685 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
2686 enforceModifyPermission();
2687 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
2688 }
2689
Brad Ebinger884c07b2018-02-15 16:17:40 -08002690 /**
2691 * @return true if emergency calling is available on IMS, false if it should fallback to CS.
2692 */
2693 public boolean isEmergencyMmTelAvailable(int slotId) {
2694 enforceModifyPermission();
2695 return PhoneFactory.getImsResolver().isEmergencyMmTelAvailable(slotId);
2696 }
2697
Brad Ebinger67801702018-03-02 13:43:36 -08002698 /**
2699 * @return true if the IMS resolver is busy resolving a binding and should not be considered
2700 * available, false if the IMS resolver is idle.
2701 */
2702 public boolean isResolvingImsBinding() {
2703 enforceModifyPermission();
2704 return PhoneFactory.getImsResolver().isResolvingBinding();
2705 }
2706
Wink Saville36469e72014-06-11 15:17:00 -07002707 public void setImsRegistrationState(boolean registered) {
2708 enforceModifyPermission();
2709 mPhone.setImsRegistrationState(registered);
2710 }
2711
2712 /**
Stuart Scott54788802015-03-30 13:18:01 -07002713 * Set the network selection mode to automatic.
2714 *
2715 */
2716 @Override
2717 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2719 mApp, subId, "setNetworkSelectionModeAutomatic");
Stuart Scott54788802015-03-30 13:18:01 -07002720 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
2721 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
2722 }
2723
2724 /**
Shishir Agrawal302c8692015-06-19 13:49:39 -07002725 * Set the network selection mode to manual with the selected carrier.
2726 */
2727 @Override
yinxu6e5abd72017-12-01 11:35:19 -08002728 public boolean setNetworkSelectionModeManual(int subId, String operatorNumeric,
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002729 boolean persistSelection) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2731 mApp, subId, "setNetworkSelectionModeManual");
yinxu6e5abd72017-12-01 11:35:19 -08002732 OperatorInfo operator = new OperatorInfo(
2733 /* operatorAlphaLong */ "",
2734 /* operatorAlphaShort */ "",
2735 operatorNumeric);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002736 if (DBG) log("setNetworkSelectionModeManual: subId:" + subId + " operator:" + operator);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07002737 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operator,
2738 persistSelection);
2739 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07002740 }
2741
2742 /**
2743 * Scans for available networks.
2744 */
2745 @Override
2746 public CellNetworkScanResult getCellNetworkScanResults(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2748 mApp, subId, "getCellNetworkScanResults");
Shishir Agrawal302c8692015-06-19 13:49:39 -07002749 if (DBG) log("getCellNetworkScanResults: subId " + subId);
2750 CellNetworkScanResult result = (CellNetworkScanResult) sendRequest(
2751 CMD_PERFORM_NETWORK_SCAN, null, subId);
2752 return result;
2753 }
2754
2755 /**
yinxub1bed742017-04-17 11:45:04 -07002756 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07002757 *
yinxub1bed742017-04-17 11:45:04 -07002758 * @param subId id of the subscription
2759 * @param request contains the radio access networks with bands/channels to scan
2760 * @param messenger callback messenger for scan results or errors
2761 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07002762 * @return the id of the requested scan which can be used to stop the scan.
2763 */
2764 @Override
2765 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
2766 IBinder binder) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2768 mApp, subId, "requestNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002769 return mNetworkScanRequestTracker.startNetworkScan(
2770 request, messenger, binder, getPhone(subId));
yinxu504e1392017-04-12 16:03:22 -07002771 }
2772
2773 /**
2774 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07002775 *
2776 * @param subId id of the subscription
2777 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07002778 */
2779 @Override
2780 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2782 mApp, subId, "stopNetworkScan");
yinxub1bed742017-04-17 11:45:04 -07002783 mNetworkScanRequestTracker.stopNetworkScan(scanId);
yinxu504e1392017-04-12 16:03:22 -07002784 }
2785
2786 /**
Junda Liu84d15a22014-07-02 11:21:04 -07002787 * Get the calculated preferred network type.
2788 * Used for debugging incorrect network type.
2789 *
2790 * @return the preferred network type, defined in RILConstants.java.
2791 */
2792 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07002793 public int getCalculatedPreferredNetworkType(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2795 mApp, callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07002796 return RILConstants.PREFERRED_NETWORK_MODE;
2797 }
2798
Amit Mahajan43330e02014-11-18 11:54:45 -08002799 return PhoneFactory.calculatePreferredNetworkType(mPhone.getContext(), 0); // wink FIXME: need to get SubId from somewhere.
Junda Liu84d15a22014-07-02 11:21:04 -07002800 }
2801
2802 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08002803 * Get the preferred network type.
2804 * Used for device configuration by some CDMA operators.
2805 *
2806 * @return the preferred network type, defined in RILConstants.java.
2807 */
2808 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002809 public int getPreferredNetworkType(int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002810 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2811 mApp, subId, "getPreferredNetworkType");
Jake Hamby7c27be32014-03-03 13:25:59 -08002812 if (DBG) log("getPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002813 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002814 int networkType = (result != null ? result[0] : -1);
2815 if (DBG) log("getPreferredNetworkType: " + networkType);
2816 return networkType;
2817 }
2818
2819 /**
2820 * Set the preferred network type.
2821 * Used for device configuration by some CDMA operators.
2822 *
2823 * @param networkType the preferred network type, defined in RILConstants.java.
2824 * @return true on success; false on any failure.
2825 */
2826 @Override
Stuart Scott54788802015-03-30 13:18:01 -07002827 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2829 mApp, subId, "setPreferredNetworkType");
Stuart Scott54788802015-03-30 13:18:01 -07002830 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
2831 Boolean success = (Boolean) sendRequest(CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
Jake Hamby7c27be32014-03-03 13:25:59 -08002832 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
Junda Liu80bc0d12014-07-14 16:36:44 -07002833 if (success) {
2834 Settings.Global.putInt(mPhone.getContext().getContentResolver(),
Stuart Scott54788802015-03-30 13:18:01 -07002835 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
Junda Liu80bc0d12014-07-14 16:36:44 -07002836 }
Jake Hamby7c27be32014-03-03 13:25:59 -08002837 return success;
2838 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002839
2840 /**
Junda Liu475951f2014-11-07 16:45:03 -08002841 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
2842 * SystemProperty, and config_tether_apndata to decide whether DUN APN is required for
2843 * tethering.
2844 *
2845 * @return 0: Not required. 1: required. 2: Not set.
2846 * @hide
2847 */
2848 @Override
2849 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002850 enforceModifyPermission();
Junda Liu475951f2014-11-07 16:45:03 -08002851 int dunRequired = Settings.Global.getInt(mPhone.getContext().getContentResolver(),
2852 Settings.Global.TETHER_DUN_REQUIRED, 2);
2853 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting and
2854 // config_tether_apndata.
2855 if (dunRequired == 2 && mPhone.hasMatchedTetherApnSetting()) {
2856 dunRequired = 1;
2857 }
2858 return dunRequired;
2859 }
2860
2861 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07002862 * Set mobile data enabled
2863 * Used by the user through settings etc to turn on/off mobile data
2864 *
2865 * @param enable {@code true} turn turn data on, else {@code false}
2866 */
2867 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002868 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2870 mApp, subId, "setUserDataEnabled");
Wink Savillee7353bb2014-12-05 14:21:41 -08002871 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002872 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002873 Phone phone = PhoneFactory.getPhone(phoneId);
2874 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002875 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
2876 phone.setUserDataEnabled(enable);
Wink Savillee7353bb2014-12-05 14:21:41 -08002877 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002878 loge("setUserDataEnabled: no phone for subId=" + subId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002879 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002880 }
2881
2882 /**
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002883 * Get the user enabled state of Mobile Data.
2884 *
2885 * TODO: remove and use isUserDataEnabled.
2886 * This can't be removed now because some vendor codes
2887 * calls through ITelephony directly while they should
2888 * use TelephonyManager.
2889 *
2890 * @return true on enabled
2891 */
2892 @Override
2893 public boolean getDataEnabled(int subId) {
2894 return isUserDataEnabled(subId);
2895 }
2896
2897 /**
2898 * Get whether mobile data is enabled per user setting.
2899 *
2900 * There are other factors deciding whether mobile data is actually enabled, but they are
2901 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07002902 *
Jeff Davidsona1920712016-11-18 17:05:56 -08002903 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07002904 *
2905 * @return {@code true} if data is enabled else {@code false}
2906 */
2907 @Override
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002908 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07002909 try {
2910 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2911 null);
2912 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2914 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07002915 }
Wink Savillee7353bb2014-12-05 14:21:41 -08002916 int phoneId = mSubscriptionController.getPhoneId(subId);
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002917 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
Wink Savillee7353bb2014-12-05 14:21:41 -08002918 Phone phone = PhoneFactory.getPhone(phoneId);
2919 if (phone != null) {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002920 boolean retVal = phone.isUserDataEnabled();
2921 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
Wink Savillee7353bb2014-12-05 14:21:41 -08002922 return retVal;
2923 } else {
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002924 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
2925 return false;
2926 }
2927 }
2928
2929 /**
2930 * Get whether mobile data is enabled.
2931 *
2932 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
2933 * whether mobile data is actually enabled.
2934 *
2935 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
2936 *
2937 * @return {@code true} if data is enabled else {@code false}
2938 */
2939 @Override
2940 public boolean isDataEnabled(int subId) {
2941 try {
2942 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
2943 null);
2944 } catch (Exception e) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2946 mApp, subId, "isDataEnabled");
Malcolm Chenfd5068e2017-11-28 16:20:07 -08002947 }
2948 int phoneId = mSubscriptionController.getPhoneId(subId);
2949 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
2950 Phone phone = PhoneFactory.getPhone(phoneId);
2951 if (phone != null) {
2952 boolean retVal = phone.isDataEnabled();
2953 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
2954 return retVal;
2955 } else {
2956 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
Wink Savillee7353bb2014-12-05 14:21:41 -08002957 return false;
2958 }
Robert Greenwalted86e582014-05-21 20:03:20 -07002959 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002960
2961 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002962 public int getCarrierPrivilegeStatus(int subId) {
2963 final Phone phone = getPhone(subId);
2964 if (phone == null) {
2965 loge("getCarrierPrivilegeStatus: Invalid subId");
2966 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2967 }
2968 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002969 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08002970 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002971 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2972 }
2973 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002974 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07002975 }
Junda Liu29340342014-07-10 15:23:27 -07002976
2977 @Override
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08002978 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
2979 final Phone phone = getPhone(subId);
2980 if (phone == null) {
2981 loge("getCarrierPrivilegeStatus: Invalid subId");
2982 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
2983 }
2984 UiccProfile profile =
2985 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
2986 if (profile == null) {
2987 loge("getCarrierPrivilegeStatus: No UICC");
2988 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
2989 }
2990 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
2991 }
2992
2993 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07002994 public int checkCarrierPrivilegesForPackage(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08002995 if (TextUtils.isEmpty(pkgName))
2996 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Shishir Agrawal21409252015-01-15 23:33:50 -08002997 UiccCard card = UiccController.getInstance().getUiccCard(mPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07002998 if (card == null) {
2999 loge("checkCarrierPrivilegesForPackage: No UICC");
3000 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3001 }
Zach Johnson50ecba32015-05-19 00:24:21 -07003002 return card.getCarrierPrivilegeStatus(mPhone.getContext().getPackageManager(), pkgName);
3003 }
3004
3005 @Override
3006 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08003007 if (TextUtils.isEmpty(pkgName))
3008 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07003009 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
3010 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3011 UiccCard card = UiccController.getInstance().getUiccCard(i);
3012 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07003013 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07003014 continue;
3015 }
3016
3017 result = card.getCarrierPrivilegeStatus(
3018 mPhone.getContext().getPackageManager(), pkgName);
3019 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3020 break;
3021 }
3022 }
3023
3024 return result;
Junda Liu29340342014-07-10 15:23:27 -07003025 }
Derek Tan89e89d42014-07-08 17:00:10 -07003026
3027 @Override
Junda Liue64de782015-04-16 17:19:16 -07003028 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
3029 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
3030 loge("phoneId " + phoneId + " is not valid.");
3031 return null;
3032 }
3033 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003034 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003035 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003036 return null ;
3037 }
Diego Pontorieroaf74c862014-08-28 11:51:16 -07003038 return card.getCarrierPackageNamesForIntent(
Svetoslav483aff72015-04-21 14:16:07 -07003039 mPhone.getContext().getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003040 }
3041
Amith Yamasani6e118872016-02-19 12:53:51 -08003042 @Override
3043 public List<String> getPackagesWithCarrierPrivileges() {
3044 PackageManager pm = mPhone.getContext().getPackageManager();
3045 List<String> privilegedPackages = new ArrayList<>();
3046 List<PackageInfo> packages = null;
3047 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
3048 UiccCard card = UiccController.getInstance().getUiccCard(i);
3049 if (card == null) {
3050 // No UICC in that slot.
3051 continue;
3052 }
3053 if (card.hasCarrierPrivilegeRules()) {
3054 if (packages == null) {
3055 // Only check packages in user 0 for now
3056 packages = pm.getInstalledPackagesAsUser(
3057 PackageManager.MATCH_DISABLED_COMPONENTS
3058 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
3059 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
3060 }
3061 for (int p = packages.size() - 1; p >= 0; p--) {
3062 PackageInfo pkgInfo = packages.get(p);
3063 if (pkgInfo != null && pkgInfo.packageName != null
3064 && card.getCarrierPrivilegeStatus(pkgInfo)
3065 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
3066 privilegedPackages.add(pkgInfo.packageName);
3067 }
3068 }
3069 }
3070 }
3071 return privilegedPackages;
3072 }
3073
Wink Savilleb564aae2014-10-23 10:18:09 -07003074 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07003075 final Phone phone = getPhone(subId);
3076 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07003077 if (card == null) {
3078 loge("getIccId: No UICC");
3079 return null;
3080 }
3081 String iccId = card.getIccId();
3082 if (TextUtils.isEmpty(iccId)) {
3083 loge("getIccId: ICC ID is null or empty.");
3084 return null;
3085 }
3086 return iccId;
3087 }
3088
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07003089 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08003090 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
3091 String number) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003092 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3093 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07003094
Jeff Sharkey85190e62014-12-05 09:40:12 -08003095 final String iccId = getIccId(subId);
Sanket Padawe356d7632015-06-22 14:03:32 -07003096 final Phone phone = getPhone(subId);
3097 if (phone == null) {
3098 return false;
3099 }
3100 final String subscriberId = phone.getSubscriberId();
Jeff Sharkey85190e62014-12-05 09:40:12 -08003101
3102 if (DBG_MERGE) {
3103 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
3104 + subscriberId + " to " + number);
3105 }
3106
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003107 if (TextUtils.isEmpty(iccId)) {
3108 return false;
Derek Tan97ebb422014-09-05 16:55:38 -07003109 }
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003110
Jeff Sharkey85190e62014-12-05 09:40:12 -08003111 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3112
3113 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003114 if (alphaTag == null) {
3115 editor.remove(alphaTagPrefKey);
3116 } else {
3117 editor.putString(alphaTagPrefKey, alphaTag);
3118 }
3119
Jeff Sharkey85190e62014-12-05 09:40:12 -08003120 // Record both the line number and IMSI for this ICCID, since we need to
3121 // track all merged IMSIs based on line number
3122 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3123 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003124 if (number == null) {
3125 editor.remove(numberPrefKey);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003126 editor.remove(subscriberPrefKey);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003127 } else {
3128 editor.putString(numberPrefKey, number);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003129 editor.putString(subscriberPrefKey, subscriberId);
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003130 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003131
Shishir Agrawal495d7e12014-12-01 11:50:28 -08003132 editor.commit();
3133 return true;
Derek Tan7226c842014-07-02 17:42:23 -07003134 }
3135
3136 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003137 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07003138 // This is open to apps with WRITE_SMS.
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003139 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
3140 mApp, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08003141 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07003142 return null;
3143 }
Derek Tan97ebb422014-09-05 16:55:38 -07003144
3145 String iccId = getIccId(subId);
3146 if (iccId != null) {
3147 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
Amit Mahajan9cf11512015-11-09 11:40:48 -08003148 if (DBG_MERGE) {
3149 log("getLine1NumberForDisplay returning " +
3150 mTelephonySharedPreferences.getString(numberPrefKey, null));
3151 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003152 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003153 }
Amit Mahajan9cf11512015-11-09 11:40:48 -08003154 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
Derek Tan97ebb422014-09-05 16:55:38 -07003155 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003156 }
3157
3158 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003159 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003160 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3161 mApp, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003162 return null;
3163 }
Derek Tan97ebb422014-09-05 16:55:38 -07003164
3165 String iccId = getIccId(subId);
3166 if (iccId != null) {
3167 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
Andrew Leedf14ead2014-10-17 14:22:52 -07003168 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
Derek Tan7226c842014-07-02 17:42:23 -07003169 }
Derek Tan97ebb422014-09-05 16:55:38 -07003170 return null;
Derek Tan7226c842014-07-02 17:42:23 -07003171 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003172
3173 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003174 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003175 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3176 mApp, callingPackage, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003177 return null;
3178 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08003179 final Context context = mPhone.getContext();
3180 final TelephonyManager tele = TelephonyManager.from(context);
3181 final SubscriptionManager sub = SubscriptionManager.from(context);
3182
3183 // Figure out what subscribers are currently active
3184 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07003185 // Clear calling identity, when calling TelephonyManager, because callerUid must be
3186 // the process, where TelephonyManager was instantiated. Otherwise AppOps check will fail.
3187 final long identity = Binder.clearCallingIdentity();
3188 try {
3189 final int[] subIds = sub.getActiveSubscriptionIdList();
3190 for (int subId : subIds) {
3191 activeSubscriberIds.add(tele.getSubscriberId(subId));
3192 }
3193 } finally {
3194 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08003195 }
3196
3197 // First pass, find a number override for an active subscriber
3198 String mergeNumber = null;
3199 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
3200 for (String key : prefs.keySet()) {
3201 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
3202 final String subscriberId = (String) prefs.get(key);
3203 if (activeSubscriberIds.contains(subscriberId)) {
3204 final String iccId = key.substring(PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
3205 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
3206 mergeNumber = (String) prefs.get(numberKey);
3207 if (DBG_MERGE) {
3208 Slog.d(LOG_TAG, "Found line number " + mergeNumber
3209 + " for active subscriber " + subscriberId);
3210 }
3211 if (!TextUtils.isEmpty(mergeNumber)) {
3212 break;
3213 }
3214 }
3215 }
3216 }
3217
3218 // Shortcut when no active merged subscribers
3219 if (TextUtils.isEmpty(mergeNumber)) {
3220 return null;
3221 }
3222
3223 // Second pass, find all subscribers under that line override
3224 final ArraySet<String> result = new ArraySet<>();
3225 for (String key : prefs.keySet()) {
3226 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
3227 final String number = (String) prefs.get(key);
3228 if (mergeNumber.equals(number)) {
3229 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
3230 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
3231 final String subscriberId = (String) prefs.get(subscriberKey);
3232 if (!TextUtils.isEmpty(subscriberId)) {
3233 result.add(subscriberId);
3234 }
3235 }
3236 }
3237 }
3238
3239 final String[] resultArray = result.toArray(new String[result.size()]);
3240 Arrays.sort(resultArray);
3241 if (DBG_MERGE) {
3242 Slog.d(LOG_TAG, "Found subscribers " + Arrays.toString(resultArray) + " after merge");
3243 }
3244 return resultArray;
3245 }
3246
3247 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003248 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003249 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3250 subId, "setOperatorBrandOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003251 final Phone phone = getPhone(subId);
3252 return phone == null ? false : phone.setOperatorBrandOverride(brand);
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07003253 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05003254
3255 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003256 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003257 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
3258 List<String> cdmaNonRoamingList) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003259 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003260 final Phone phone = getPhone(subId);
3261 if (phone == null) {
3262 return false;
3263 }
3264 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08003265 cdmaNonRoamingList);
3266 }
3267
3268 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07003269 public void setRadioCapability(RadioAccessFamily[] rafs) {
3270 try {
3271 ProxyController.getInstance().setRadioCapability(rafs);
3272 } catch (RuntimeException e) {
3273 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
3274 }
3275 }
3276
3277 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003278 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3280 mApp, callingPackage, "getRadioAccessFamily")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003281 return RadioAccessFamily.RAF_UNKNOWN;
3282 }
3283
Wink Saville5d475dd2014-10-17 15:00:58 -07003284 return ProxyController.getInstance().getRadioAccessFamily(phoneId);
3285 }
Andrew Leedf14ead2014-10-17 14:22:52 -07003286
3287 @Override
3288 public void enableVideoCalling(boolean enable) {
3289 enforceModifyPermission();
Malcolm Chen995721f2017-12-12 18:19:27 -08003290 ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId()).setVtSetting(enable);
Andrew Leedf14ead2014-10-17 14:22:52 -07003291 }
3292
3293 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003294 public boolean isVideoCallingEnabled(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003295 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3296 mApp, callingPackage, "isVideoCallingEnabled")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003297 return false;
3298 }
3299
Andrew Lee77527ac2014-10-21 16:57:39 -07003300 // Check the user preference and the system-level IMS setting. Even if the user has
3301 // enabled video calling, if IMS is disabled we aren't able to support video calling.
3302 // In the long run, we may instead need to check if there exists a connection service
3303 // which can support video calling.
Malcolm Chen995721f2017-12-12 18:19:27 -08003304 ImsManager imsManager = ImsManager.getInstance(mPhone.getContext(), mPhone.getPhoneId());
3305 return imsManager.isVtEnabledByPlatform()
3306 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
3307 && imsManager.isVtEnabledByUser();
Andrew Leedf14ead2014-10-17 14:22:52 -07003308 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06003309
Andrew Leea1239f22015-03-02 17:44:07 -08003310 @Override
3311 public boolean canChangeDtmfToneLength() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003312 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003313 }
3314
3315 @Override
3316 public boolean isWorldPhone() {
Jonathan Basseri9504c6b2015-06-04 14:23:32 -07003317 return mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
Andrew Leea1239f22015-03-02 17:44:07 -08003318 }
3319
Andrew Lee9431b832015-03-09 18:46:45 -07003320 @Override
3321 public boolean isTtyModeSupported() {
3322 TelecomManager telecomManager = TelecomManager.from(mPhone.getContext());
3323 TelephonyManager telephonyManager =
3324 (TelephonyManager) mPhone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08003325 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07003326 }
3327
3328 @Override
3329 public boolean isHearingAidCompatibilitySupported() {
3330 return mPhone.getContext().getResources().getBoolean(R.bool.hac_enabled);
3331 }
3332
Hall Liu73714012018-01-22 19:15:32 -08003333 public boolean isRttSupported() {
3334 boolean isCarrierSupported =
3335 mApp.getCarrierConfig().getBoolean(CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
3336 boolean isDeviceSupported =
3337 mPhone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
3338 return isCarrierSupported && isDeviceSupported;
3339 }
3340
Sanket Padawe7310cc72015-01-14 09:53:20 -08003341 /**
3342 * Returns the unique device ID of phone, for example, the IMEI for
3343 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
3344 *
3345 * <p>Requires Permission:
3346 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
3347 */
3348 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07003349 public String getDeviceId(String callingPackage) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003350 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3351 mApp, callingPackage, "getDeviceId")) {
Svet Ganovb320e182015-04-16 12:30:10 -07003352 return null;
3353 }
3354
Sanket Padawe7310cc72015-01-14 09:53:20 -08003355 final Phone phone = PhoneFactory.getPhone(0);
3356 if (phone != null) {
3357 return phone.getDeviceId();
3358 } else {
3359 return null;
3360 }
3361 }
3362
Ping Sun014fe8e2016-03-02 19:16:45 +08003363 /**
3364 * {@hide}
3365 * Returns the IMS Registration Status on a particular subid
3366 *
3367 * @param subId
3368 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003369 public boolean isImsRegistered(int subId) {
Ping Sun014fe8e2016-03-02 19:16:45 +08003370 Phone phone = getPhone(subId);
3371 if (phone != null) {
3372 return phone.isImsRegistered();
3373 } else {
3374 return false;
3375 }
3376 }
3377
Santos Cordon7a1885b2015-02-03 11:15:19 -08003378 @Override
3379 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
3380 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
3381 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07003382
Brad Ebingere21f25f2018-02-08 16:11:32 -08003383 /**
3384 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003385 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003386 public boolean isWifiCallingAvailable(int subId) {
3387 Phone phone = getPhone(subId);
3388 if (phone != null) {
3389 return phone.isWifiCallingEnabled();
3390 } else {
3391 return false;
3392 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003393 }
3394
Brad Ebingere21f25f2018-02-08 16:11:32 -08003395 /**
3396 * @return the VoLTE availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07003397 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003398 public boolean isVolteAvailable(int subId) {
3399 Phone phone = getPhone(subId);
3400 if (phone != null) {
3401 return phone.isVolteEnabled();
3402 } else {
3403 return false;
3404 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07003405 }
Svet Ganovb320e182015-04-16 12:30:10 -07003406
Brad Ebingere21f25f2018-02-08 16:11:32 -08003407 /**
3408 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003409 */
Brad Ebingere21f25f2018-02-08 16:11:32 -08003410 public boolean isVideoTelephonyAvailable(int subId) {
3411 Phone phone = getPhone(subId);
3412 if (phone != null) {
3413 return phone.isVideoEnabled();
3414 } else {
3415 return false;
3416 }
3417 }
3418
3419 /**
3420 * @return the IMS registration technology for the MMTEL feature. Valid return values are
3421 * defined in {@link ImsRegistrationImplBase}.
3422 */
3423 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
3424 Phone phone = getPhone(subId);
3425 if (phone != null) {
3426 return phone.getImsRegistrationTech();
3427 } else {
3428 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
3429 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07003430 }
3431
Stuart Scott8eef64f2015-04-08 15:13:54 -07003432 @Override
3433 public void factoryReset(int subId) {
3434 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07003435 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
3436 return;
3437 }
3438
Svet Ganovcc087f82015-05-12 20:35:54 -07003439 final long identity = Binder.clearCallingIdentity();
3440 try {
Stuart Scott981d8582015-04-21 14:09:50 -07003441 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
3442 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Svet Ganovcc087f82015-05-12 20:35:54 -07003443 // Enable data
Malcolm Chenfd5068e2017-11-28 16:20:07 -08003444 setUserDataEnabled(subId, true);
Svet Ganovcc087f82015-05-12 20:35:54 -07003445 // Set network selection mode to automatic
3446 setNetworkSelectionModeAutomatic(subId);
3447 // Set preferred mobile network type to the best available
3448 setPreferredNetworkType(subId, Phone.PREFERRED_NT_MODE);
3449 // Turn off roaming
Malcolm Chenf6b97f42017-04-19 16:03:24 -07003450 mPhone.setDataRoamingEnabled(false);
Svet Ganovcc087f82015-05-12 20:35:54 -07003451 }
3452 } finally {
3453 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003454 }
3455 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003456
3457 @Override
3458 public String getLocaleFromDefaultSim() {
3459 // We query all subscriptions instead of just the active ones, because
3460 // this might be called early on in the provisioning flow when the
3461 // subscriptions potentially aren't active yet.
3462 final List<SubscriptionInfo> slist = getAllSubscriptionInfoList();
3463 if (slist == null || slist.isEmpty()) {
3464 return null;
3465 }
3466
3467 // This function may be called very early, say, from the setup wizard, at
3468 // which point we won't have a default subscription set. If that's the case
3469 // we just choose the first, which will be valid in "most cases".
3470 final int defaultSubId = getDefaultSubscription();
3471 SubscriptionInfo info = null;
3472 if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
3473 info = slist.get(0);
3474 } else {
3475 for (SubscriptionInfo item : slist) {
3476 if (item.getSubscriptionId() == defaultSubId) {
3477 info = item;
3478 break;
3479 }
3480 }
3481
3482 if (info == null) {
3483 return null;
3484 }
3485 }
3486
3487 // Try and fetch the locale from the carrier properties or from the SIM language
3488 // preferences (EF-PL and EF-LI)...
Tony Hill183b2de2015-06-24 14:53:58 +01003489 final int mcc = info.getMcc();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003490 final Phone defaultPhone = getPhone(info.getSubscriptionId());
Narayan Kamath011676f2015-07-29 12:04:08 +01003491 String simLanguage = null;
Narayan Kamath1c496c22015-04-16 14:40:19 +01003492 if (defaultPhone != null) {
3493 final Locale localeFromDefaultSim = defaultPhone.getLocaleFromSimAndCarrierPrefs();
3494 if (localeFromDefaultSim != null) {
Narayan Kamath011676f2015-07-29 12:04:08 +01003495 if (!localeFromDefaultSim.getCountry().isEmpty()) {
Tony Hill183b2de2015-06-24 14:53:58 +01003496 if (DBG) log("Using locale from default SIM:" + localeFromDefaultSim);
3497 return localeFromDefaultSim.toLanguageTag();
Narayan Kamath011676f2015-07-29 12:04:08 +01003498 } else {
3499 simLanguage = localeFromDefaultSim.getLanguage();
Tony Hill183b2de2015-06-24 14:53:58 +01003500 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01003501 }
3502 }
3503
Narayan Kamath011676f2015-07-29 12:04:08 +01003504 // The SIM language preferences only store a language (e.g. fr = French), not an
3505 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
3506 // the SIM and carrier preferences does not include a country we add the country
3507 // determined from the SIM MCC to provide an exact locale.
3508 final Locale mccLocale = MccTable.getLocaleFromMcc(mPhone.getContext(), mcc, simLanguage);
Tony Hill183b2de2015-06-24 14:53:58 +01003509 if (mccLocale != null) {
3510 if (DBG) log("No locale from default SIM, using mcc locale:" + mccLocale);
3511 return mccLocale.toLanguageTag();
Narayan Kamath1c496c22015-04-16 14:40:19 +01003512 }
3513
Tony Hill183b2de2015-06-24 14:53:58 +01003514 if (DBG) log("No locale found - returning null");
Narayan Kamath1c496c22015-04-16 14:40:19 +01003515 return null;
3516 }
3517
3518 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
3519 final long identity = Binder.clearCallingIdentity();
3520 try {
3521 return mSubscriptionController.getAllSubInfoList(
3522 mPhone.getContext().getOpPackageName());
3523 } finally {
3524 Binder.restoreCallingIdentity(identity);
3525 }
3526 }
3527
3528 private List<SubscriptionInfo> getActiveSubscriptionInfoList() {
3529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 return mSubscriptionController.getActiveSubscriptionInfoList(
3532 mPhone.getContext().getOpPackageName());
3533 } finally {
3534 Binder.restoreCallingIdentity(identity);
3535 }
3536 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003537
3538 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07003539 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
3540 * representing the state of the modem.
3541 *
3542 * NOTE: This clears the modem state, so there should only every be one caller.
3543 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003544 */
3545 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07003546 public void requestModemActivityInfo(ResultReceiver result) {
3547 enforceModifyPermission();
3548
3549 ModemActivityInfo info = (ModemActivityInfo) sendRequest(CMD_GET_MODEM_ACTIVITY_INFO, null);
3550 Bundle bundle = new Bundle();
3551 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, info);
3552 result.send(0, bundle);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07003553 }
Jack Yu85bd38a2015-11-09 11:34:32 -08003554
3555 /**
3556 * {@hide}
3557 * Returns the service state information on specified subscription.
3558 */
3559 @Override
3560 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
3561
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003562 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3563 mApp, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08003564 return null;
3565 }
3566
3567 final Phone phone = getPhone(subId);
3568 if (phone == null) {
3569 return null;
3570 }
3571
3572 return phone.getServiceState();
3573 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08003574
3575 /**
3576 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
3577 *
3578 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3579 * voicemail ringtone.
3580 * @return The URI for the ringtone to play when receiving a voicemail from a specific
3581 * PhoneAccount.
3582 */
3583 @Override
3584 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003585 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003586 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003587 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003588 }
3589
fionaxu7ed723d2017-05-30 18:58:54 -07003590 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003591 }
3592
3593 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003594 * Sets the per-account voicemail ringtone.
3595 *
3596 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3597 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3598 *
3599 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3600 * voicemail ringtone.
3601 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
3602 * PhoneAccount.
3603 */
3604 @Override
3605 public void setVoicemailRingtoneUri(String callingPackage,
3606 PhoneAccountHandle phoneAccountHandle, Uri uri) {
3607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3608 if (!TextUtils.equals(callingPackage,
3609 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3611 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3612 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003613 }
3614 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3615 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003616 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003617 }
fionaxu7ed723d2017-05-30 18:58:54 -07003618 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003619 }
3620
3621 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08003622 * Returns whether vibration is set for voicemail notification in Phone settings.
3623 *
3624 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
3625 * voicemail vibration setting.
3626 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
3627 */
3628 @Override
3629 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003630 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
Nancy Chen31f9ba12016-01-06 11:42:12 -08003631 if (phone == null) {
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003632 phone = mPhone;
Nancy Chen31f9ba12016-01-06 11:42:12 -08003633 }
3634
fionaxu7ed723d2017-05-30 18:58:54 -07003635 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
Nancy Chen31f9ba12016-01-06 11:42:12 -08003636 }
3637
Youhan Wange64578a2016-05-02 15:32:42 -07003638 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003639 * Sets the per-account voicemail vibration.
3640 *
3641 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
3642 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
3643 *
3644 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
3645 * voicemail vibration setting.
3646 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
3647 * specific PhoneAccount.
3648 */
3649 @Override
3650 public void setVoicemailVibrationEnabled(String callingPackage,
3651 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
3652 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3653 if (!TextUtils.equals(callingPackage,
3654 TelecomManager.from(mPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3656 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
3657 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003658 }
3659
3660 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
3661 if (phone == null){
Ta-wei Yen00b4ab52017-04-11 13:24:26 -07003662 phone = mPhone;
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003663 }
fionaxu7ed723d2017-05-30 18:58:54 -07003664 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08003665 }
3666
3667 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003668 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
3669 *
3670 * @throws SecurityException if the caller does not have the required permission
3671 */
3672 private void enforceReadPrivilegedPermission() {
3673 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
3674 null);
3675 }
3676
3677 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003678 * Make sure either called from same process as self (phone) or IPC caller has send SMS
3679 * permission.
3680 *
3681 * @throws SecurityException if the caller does not have the required permission
3682 */
3683 private void enforceSendSmsPermission() {
3684 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
3685 }
3686
3687 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003688 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003689 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003690 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003691 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003692 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Ta-wei Yen5d81b0c2017-03-03 16:32:26 -08003693 ComponentName componentName =
3694 RemoteVvmTaskManager.getRemotePackage(mPhone.getContext(), subId);
3695 if(componentName == null) {
3696 throw new SecurityException("Caller not current active visual voicemail package[null]");
3697 }
3698 String vvmPackage = componentName.getPackageName();
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003699 if (!callingPackage.equals(vvmPackage)) {
3700 throw new SecurityException("Caller not current active visual voicemail package[" +
3701 vvmPackage + "]");
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003702 }
3703 }
3704
3705 /**
Youhan Wange64578a2016-05-02 15:32:42 -07003706 * Return the application ID for the app type.
3707 *
3708 * @param subId the subscription ID that this request applies to.
3709 * @param appType the uicc app type.
3710 * @return Application ID for specificied app type, or null if no uicc.
3711 */
3712 @Override
3713 public String getAidForAppType(int subId, int appType) {
3714 enforceReadPrivilegedPermission();
3715 Phone phone = getPhone(subId);
3716 if (phone == null) {
3717 return null;
3718 }
3719 String aid = null;
3720 try {
3721 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
3722 .getApplicationByType(appType).getAid();
3723 } catch (Exception e) {
3724 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
3725 }
3726 return aid;
3727 }
3728
Youhan Wang4001d252016-05-11 10:29:41 -07003729 /**
3730 * Return the Electronic Serial Number.
3731 *
3732 * @param subId the subscription ID that this request applies to.
3733 * @return ESN or null if error.
3734 */
3735 @Override
3736 public String getEsn(int subId) {
3737 enforceReadPrivilegedPermission();
3738 Phone phone = getPhone(subId);
3739 if (phone == null) {
3740 return null;
3741 }
3742 String esn = null;
3743 try {
3744 esn = phone.getEsn();
3745 } catch (Exception e) {
3746 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
3747 }
3748 return esn;
3749 }
3750
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003751 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07003752 * Return the Preferred Roaming List Version.
3753 *
3754 * @param subId the subscription ID that this request applies to.
3755 * @return PRLVersion or null if error.
3756 */
3757 @Override
3758 public String getCdmaPrlVersion(int subId) {
3759 enforceReadPrivilegedPermission();
3760 Phone phone = getPhone(subId);
3761 if (phone == null) {
3762 return null;
3763 }
3764 String cdmaPrlVersion = null;
3765 try {
3766 cdmaPrlVersion = phone.getCdmaPrlVersion();
3767 } catch (Exception e) {
3768 Log.e(LOG_TAG, "Not getting PRLVersion", e);
3769 }
3770 return cdmaPrlVersion;
3771 }
3772
3773 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003774 * Get snapshot of Telephony histograms
3775 * @return List of Telephony histograms
3776 * @hide
3777 */
3778 @Override
3779 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3781 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Sanket Padawe99ef1e32016-05-18 16:12:33 -07003782 return RIL.getTelephonyRILTimingHistograms();
3783 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07003784
3785 /**
3786 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003787 * Set the allowed carrier list for slotIndex
Meng Wang1a7c35a2016-05-05 20:56:15 -07003788 * Require system privileges. In the future we may add this to carrier APIs.
3789 *
3790 * @return The number of carriers set successfully, should match length of carriers
3791 */
3792 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003793 public int setAllowedCarriers(int slotIndex, List<CarrierIdentifier> carriers) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003794 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003795
Meng Wang9b7c4e92017-02-17 11:41:27 -08003796 if (carriers == null) {
3797 throw new NullPointerException("carriers cannot be null");
3798 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003799
3800 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003801 int[] retVal = (int[]) sendRequest(CMD_SET_ALLOWED_CARRIERS, carriers, subId);
3802 return retVal[0];
3803 }
3804
3805 /**
3806 * {@hide}
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003807 * Get the allowed carrier list for slotIndex.
Meng Wang1a7c35a2016-05-05 20:56:15 -07003808 * Require system privileges. In the future we may add this to carrier APIs.
3809 *
3810 * @return List of {@link android.service.telephony.CarrierIdentifier}; empty list
3811 * means all carriers are allowed.
3812 */
3813 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003814 public List<CarrierIdentifier> getAllowedCarriers(int slotIndex) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07003815 enforceReadPrivilegedPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003816 int subId = SubscriptionManager.getSubId(slotIndex)[0];
Meng Wang1a7c35a2016-05-05 20:56:15 -07003817 return (List<CarrierIdentifier>) sendRequest(CMD_GET_ALLOWED_CARRIERS, null, subId);
3818 }
3819
fionaxu59545b42016-05-25 15:53:37 -07003820 /**
3821 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
3822 * @param subId the subscription ID that this action applies to.
3823 * @param enabled control enable or disable metered apns.
3824 * {@hide}
3825 */
3826 @Override
3827 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
3828 enforceModifyPermission();
3829 final Phone phone = getPhone(subId);
3830 if (phone == null) {
3831 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
3832 return;
3833 }
3834 try {
3835 phone.carrierActionSetMeteredApnsEnabled(enabled);
3836 } catch (Exception e) {
3837 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
3838 }
3839 }
3840
3841 /**
3842 * Action set from carrier signalling broadcast receivers to enable/disable radio
3843 * @param subId the subscription ID that this action applies to.
3844 * @param enabled control enable or disable radio.
3845 * {@hide}
3846 */
3847 @Override
3848 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
3849 enforceModifyPermission();
3850 final Phone phone = getPhone(subId);
3851 if (phone == null) {
3852 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
3853 return;
3854 }
3855 try {
3856 phone.carrierActionSetRadioEnabled(enabled);
3857 } catch (Exception e) {
3858 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
3859 }
3860 }
3861
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003862 /**
fionaxu8da9cb12017-05-23 15:02:46 -07003863 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
3864 * network status based on which carrier apps could apply actions accordingly,
3865 * enable/disable default url handler for example.
3866 *
3867 * @param subId the subscription ID that this action applies to.
3868 * @param report control start/stop reporting the default network status.
3869 * {@hide}
3870 */
3871 @Override
3872 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
3873 enforceModifyPermission();
3874 final Phone phone = getPhone(subId);
3875 if (phone == null) {
3876 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
3877 return;
3878 }
3879 try {
3880 phone.carrierActionReportDefaultNetworkStatus(report);
3881 } catch (Exception e) {
3882 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
3883 }
3884 }
3885
3886 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003887 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
3888 * bug report is being generated.
3889 */
3890 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07003891 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
dcashman22b950d2016-06-27 11:39:02 -07003892 if (mPhone.getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
3893 != PackageManager.PERMISSION_GRANTED) {
3894 writer.println("Permission Denial: can't dump Phone from pid="
3895 + Binder.getCallingPid()
3896 + ", uid=" + Binder.getCallingUid()
3897 + "without permission "
3898 + android.Manifest.permission.DUMP);
3899 return;
3900 }
Ta-wei Yen99282e02016-06-21 18:19:35 -07003901 DumpsysHandler.dump(mPhone.getContext(), fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07003902 }
Jack Yueb89b242016-06-22 13:27:47 -07003903
3904 /**
Jack Yu84291ec2017-05-26 16:07:50 -07003905 * Get aggregated video call data usage since boot.
3906 *
3907 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
3908 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07003909 * {@hide}
3910 */
3911 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07003912 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07003913 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
3914 null);
3915
Jack Yu84291ec2017-05-26 16:07:50 -07003916 // NetworkStatsService keeps tracking the active network interface and identity. It
3917 // records the delta with the corresponding network identity. We just return the total video
3918 // call data usage snapshot since boot.
3919 Phone phone = getPhone(subId);
3920 if (phone != null) {
3921 return phone.getVtDataUsage(perUidStats);
Jack Yueb89b242016-06-22 13:27:47 -07003922 }
Jack Yu84291ec2017-05-26 16:07:50 -07003923 return null;
Jack Yueb89b242016-06-22 13:27:47 -07003924 }
Jack Yu75ab2952016-07-08 14:29:33 -07003925
3926 /**
3927 * Policy control of data connection. Usually used when data limit is passed.
3928 * @param enabled True if enabling the data, otherwise disabling.
3929 * @param subId Subscription index
3930 * {@hide}
3931 */
3932 @Override
3933 public void setPolicyDataEnabled(boolean enabled, int subId) {
3934 enforceModifyPermission();
3935 Phone phone = getPhone(subId);
3936 if (phone != null) {
3937 phone.setPolicyDataEnabled(enabled);
3938 }
3939 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003940
3941 /**
3942 * Get Client request stats
3943 * @return List of Client Request Stats
3944 * @hide
3945 */
3946 @Override
3947 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidsond9a1bb52018-02-13 18:17:36 -08003948 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3949 mApp, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07003950 return null;
3951 }
3952
3953 Phone phone = getPhone(subId);
3954 if (phone != null) {
3955 return phone.getClientRequestStats();
3956 }
3957
3958 return null;
3959 }
3960
3961 private WorkSource getWorkSource(WorkSource workSource, int uid) {
3962 if (workSource != null) {
3963 return workSource;
3964 }
3965
3966 String packageName = mPhone.getContext().getPackageManager().getNameForUid(uid);
3967 workSource = new WorkSource(uid, packageName);
3968 return workSource;
3969 }
Jack Yueb4124c2017-02-16 15:32:43 -08003970
3971 /**
Grace Chen70990072017-03-24 17:21:30 -07003972 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08003973 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003974 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07003975 * @param state State of SIM (power down, power up, pass through)
3976 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
3977 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
3978 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08003979 *
3980 **/
3981 @Override
Grace Chen70990072017-03-24 17:21:30 -07003982 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08003983 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003984 Phone phone = PhoneFactory.getPhone(slotIndex);
3985
Jack Yueb4124c2017-02-16 15:32:43 -08003986 if (phone != null) {
Grace Chen70990072017-03-24 17:21:30 -07003987 phone.setSimPowerState(state);
Jack Yueb4124c2017-02-16 15:32:43 -08003988 }
3989 }
Shuo Qiandd210312017-04-12 22:11:33 +00003990
Tyler Gunn65d45c22017-06-05 11:22:26 -07003991 private boolean isUssdApiAllowed(int subId) {
3992 CarrierConfigManager configManager =
3993 (CarrierConfigManager) mPhone.getContext().getSystemService(
3994 Context.CARRIER_CONFIG_SERVICE);
3995 if (configManager == null) {
3996 return false;
3997 }
3998 PersistableBundle pb = configManager.getConfigForSubId(subId);
3999 if (pb == null) {
4000 return false;
4001 }
4002 return pb.getBoolean(
4003 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
4004 }
4005
Shuo Qiandd210312017-04-12 22:11:33 +00004006 /**
4007 * Check if phone is in emergency callback mode
4008 * @return true if phone is in emergency callback mode
4009 * @param subId sub id
4010 */
4011 public boolean getEmergencyCallbackMode(int subId) {
4012 final Phone phone = getPhone(subId);
4013 if (phone != null) {
4014 return phone.isInEcm();
4015 } else {
4016 return false;
4017 }
4018 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08004019
4020 /**
4021 * Get the current signal strength information for the given subscription.
4022 * Because this information is not updated when the device is in a low power state
4023 * it should not be relied-upon to be current.
4024 * @param subId Subscription index
4025 * @return the most recent cached signal strength info from the modem
4026 */
4027 @Override
4028 public SignalStrength getSignalStrength(int subId) {
4029 Phone p = getPhone(subId);
4030 if (p == null) {
4031 return null;
4032 }
4033
4034 return p.getSignalStrength();
4035 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004036
4037 @Override
4038 public UiccSlotInfo[] getUiccSlotsInfo() {
4039 enforceReadPrivilegedPermission();
4040
4041 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
4042 if (slots == null) return null;
4043 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
4044 for (int i = 0; i < slots.length; i++) {
4045 UiccSlot slot = slots[i];
4046
4047 String cardId = UiccController.getInstance().getUiccCard(i).getCardId();
4048
4049 int cardState = 0;
4050 switch (slot.getCardState()) {
4051 case CARDSTATE_ABSENT:
4052 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
4053 break;
4054 case CARDSTATE_PRESENT:
4055 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
4056 break;
4057 case CARDSTATE_ERROR:
4058 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
4059 break;
4060 case CARDSTATE_RESTRICTED:
4061 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
4062 break;
4063 default:
4064 break;
4065
4066 }
4067
Qingxi Li63668902018-01-31 13:43:27 -08004068 infos[i] = new UiccSlotInfo(
4069 slot.isActive(), slot.isEuicc(), cardId, cardState, slot.getPhoneId());
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00004070 }
4071 return infos;
4072 }
4073
4074 @Override
4075 public boolean switchSlots(int[] physicalSlots) {
4076 enforceModifyPermission();
4077 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
4078 }
Jack Yue6146032018-02-27 15:30:01 -08004079
4080 @Override
4081 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
4082 enforceModifyPermission();
4083 final Phone phone = getPhone(subId);
4084 if (phone == null) {
4085 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
4086 return;
4087 }
4088
4089 phone.setRadioIndicationUpdateMode(filters, mode);
4090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004091}