Revert "Do not set default contactless application without user interaction"
Revert due to a possible regression in Google Pay. To be updated once
there is more clarity on the issue.
This reverts commit 2ebfcfee313e60bdb57bcb877785d66865405a1b.
Issue: FP3SEC-322
Change-Id: I8784a26bd10a5f75b43217749e15a9105e6ba936
(cherry picked from commit 12a9545a0a58de8b68d4b1c01abaf516050949a2)
diff --git a/src/com/android/nfc/cardemulation/CardEmulationManager.java b/src/com/android/nfc/cardemulation/CardEmulationManager.java
index 5c93a92..489196e 100644
--- a/src/com/android/nfc/cardemulation/CardEmulationManager.java
+++ b/src/com/android/nfc/cardemulation/CardEmulationManager.java
@@ -262,9 +262,28 @@
getDefaultServiceForCategory(userId, CardEmulation.CATEGORY_PAYMENT, true);
if (DBG) Log.d(TAG, "Current default: " + defaultPaymentService);
if (defaultPaymentService == null) {
- // A payment service may have been removed, set default payment selection to "not set".
- if (DBG) Log.d(TAG, "No default set, last payment service removed.");
- setDefaultServiceForCategoryChecked(userId, null, CardEmulation.CATEGORY_PAYMENT);
+ // A payment service may have been removed, leaving only one;
+ // in that case, automatically set that app as default.
+ int numPaymentServices = 0;
+ ComponentName lastFoundPaymentService = null;
+ for (ApduServiceInfo service : services) {
+ if (service.hasCategory(CardEmulation.CATEGORY_PAYMENT)) {
+ numPaymentServices++;
+ lastFoundPaymentService = service.getComponent();
+ }
+ }
+ if (numPaymentServices > 1) {
+ // More than one service left, leave default unset
+ if (DBG) Log.d(TAG, "No default set, more than one service left.");
+ } else if (numPaymentServices == 1) {
+ // Make single found payment service the default
+ if (DBG) Log.d(TAG, "No default set, making single service default.");
+ setDefaultServiceForCategoryChecked(userId, lastFoundPaymentService,
+ CardEmulation.CATEGORY_PAYMENT);
+ } else {
+ // No payment services left, leave default at null
+ if (DBG) Log.d(TAG, "No default set, last payment service removed.");
+ }
}
}