From a949c74321b17f8ef1c93692064969f60815c7e4 Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Thu, 4 Oct 2012 16:52:51 -0700 Subject: Fast-fail SE open if it's activated in listen mode. Users of the NFC-extras API usually want to talk to the SE once it has completed a transaction. The hard part is knowing when it is safe to connect to the SE, as it will break the connection to any reader. And when relinquishing the connection to the SE, the reader may find the device again and process another transaction. This patch adds the following two conditions for allowing to open the SE from the DH: 1) The SE may not be activated in listen mode 2) The RF field must have been off for at least 50 ms Bug: 7275484 Change-Id: Ibde32a8e2aef045c17ab76ef08c72f96edfedaef --- src/com/android/nfc/DeviceHost.java | 10 ++++++++++ src/com/android/nfc/NfcService.java | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) (limited to 'src') diff --git a/src/com/android/nfc/DeviceHost.java b/src/com/android/nfc/DeviceHost.java index b7336ad..fa3d17c 100644 --- a/src/com/android/nfc/DeviceHost.java +++ b/src/com/android/nfc/DeviceHost.java @@ -49,6 +49,16 @@ public interface DeviceHost { public void onRemoteFieldDeactivated(); + /** + * Notifies that the SE has been activated in listen mode + */ + public void onSeListenActivated(); + + /** + * Notifies that the SE has been deactivated + */ + public void onSeListenDeactivated(); + public void onSeApduReceived(byte[] apdu); public void onSeEmvCardRemoval(); diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java index 62512e5..d7bb2ef 100755 --- a/src/com/android/nfc/NfcService.java +++ b/src/com/android/nfc/NfcService.java @@ -112,6 +112,8 @@ public class NfcService extends Application implements DeviceHostListener { static final int MSG_SE_APDU_RECEIVED = 10; static final int MSG_SE_EMV_CARD_REMOVAL = 11; static final int MSG_SE_MIFARE_ACCESS = 12; + static final int MSG_SE_LISTEN_ACTIVATED = 13; + static final int MSG_SE_LISTEN_DEACTIVATED = 14; static final int TASK_ENABLE = 1; static final int TASK_DISABLE = 2; @@ -158,6 +160,11 @@ public class NfcService extends Application implements DeviceHostListener { public static final String EXTRA_MIFARE_BLOCK = "com.android.nfc_extras.extra.MIFARE_BLOCK"; + public static final String ACTION_SE_LISTEN_ACTIVATED = + "com.android.nfc_extras.action.SE_LISTEN_ACTIVATED"; + public static final String ACTION_SE_LISTEN_DEACTIVATED = + "com.android.nfc_extras.action.SE_LISTEN_DEACTIVATED"; + // NFC Execution Environment // fields below are protected by this private NativeNfcSecureElement mSecureElement; @@ -275,6 +282,17 @@ public class NfcService extends Application implements DeviceHostListener { } @Override + public void onSeListenActivated() { + sendMessage(NfcService.MSG_SE_LISTEN_ACTIVATED, null); + } + + @Override + public void onSeListenDeactivated() { + sendMessage(NfcService.MSG_SE_LISTEN_DEACTIVATED, null); + } + + + @Override public void onSeApduReceived(byte[] apdu) { sendMessage(NfcService.MSG_SE_APDU_RECEIVED, apdu); } @@ -1743,6 +1761,22 @@ public class NfcService extends Application implements DeviceHostListener { break; } + case MSG_SE_LISTEN_ACTIVATED: { + if (DBG) Log.d(TAG, "SE LISTEN MODE ACTIVATED"); + Intent listenModeActivated = new Intent(); + listenModeActivated.setAction(ACTION_SE_LISTEN_ACTIVATED); + sendSeBroadcast(listenModeActivated); + break; + } + + case MSG_SE_LISTEN_DEACTIVATED: { + if (DBG) Log.d(TAG, "SE LISTEN MODE DEACTIVATED"); + Intent listenModeDeactivated = new Intent(); + listenModeDeactivated.setAction(ACTION_SE_LISTEN_DEACTIVATED); + sendSeBroadcast(listenModeDeactivated); + break; + } + default: Log.e(TAG, "Unknown message received"); break; -- cgit v1.1