Save the last selected payment service
Save the last payment service which was bound. This will prevent
accepting connections to stale services.
Test: HCE with test application
Bug: 72156674
Change-Id: I19124e5927823394e27df2099e113da684717cd5
diff --git a/src/com/android/nfc/cardemulation/HostEmulationManager.java b/src/com/android/nfc/cardemulation/HostEmulationManager.java
index 19ffa0b..bd6de46 100644
--- a/src/com/android/nfc/cardemulation/HostEmulationManager.java
+++ b/src/com/android/nfc/cardemulation/HostEmulationManager.java
@@ -85,6 +85,7 @@
Messenger mPaymentService;
boolean mPaymentServiceBound;
ComponentName mPaymentServiceName;
+ ComponentName mLastBoundPaymentServiceName;
// mActiveService denotes the service interface
// that is the current active one, until a new SELECT AID
@@ -350,6 +351,7 @@
Intent intent = new Intent(HostApduService.SERVICE_INTERFACE);
intent.setComponent(service);
+ mLastBoundPaymentServiceName = service;
if (!mContext.bindServiceAsUser(intent, mPaymentConnection,
Context.BIND_AUTO_CREATE, new UserHandle(userId))) {
Log.e(TAG, "Could not bind (persistent) payment service.");
@@ -414,6 +416,10 @@
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
synchronized (mLock) {
+ /* Preferred Payment Service has been changed. */
+ if (!mLastBoundPaymentServiceName.equals(name)) {
+ return;
+ }
mPaymentServiceName = name;
mPaymentService = new Messenger(service);
mPaymentServiceBound = true;