diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2022-07-19 07:57:47 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2022-07-19 07:57:47 +0000 |
commit | ac8da5555d582be4a5b41526a9fa61c1b33e77aa (patch) | |
tree | b941df76c055fcd6785297639e8783995a84866d | |
parent | d9d6b8b0341fb2be1d89c5d89ee8dcd4e0874877 (diff) | |
parent | 97090164ab6bbcd0f4d6a606fa5fd6b76794d3c2 (diff) | |
download | Nfc-ac8da5555d582be4a5b41526a9fa61c1b33e77aa.tar.gz |
Merge "Don't trigger USER_ACTIVITY_EVENT_TOUCH when selecting NDEF AID" into tm-d1-dev
-rw-r--r-- | src/com/android/nfc/cardemulation/CardEmulationManager.java | 63 | ||||
-rw-r--r-- | src/com/android/nfc/cardemulation/HostEmulationManager.java | 2 |
2 files changed, 60 insertions, 5 deletions
diff --git a/src/com/android/nfc/cardemulation/CardEmulationManager.java b/src/com/android/nfc/cardemulation/CardEmulationManager.java index 75c08c42..d43f89a7 100644 --- a/src/com/android/nfc/cardemulation/CardEmulationManager.java +++ b/src/com/android/nfc/cardemulation/CardEmulationManager.java @@ -40,6 +40,7 @@ import com.android.nfc.NfcService; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.util.Arrays; import java.util.List; /** @@ -65,6 +66,20 @@ public class CardEmulationManager implements RegisteredServicesCache.Callback, static final int NFC_HCE_APDU = 0x01; static final int NFC_HCE_NFCF = 0x04; + /** Minimum AID length as per ISO7816 */ + static final int MINIMUM_AID_LENGTH = 5; + /** Length of Select APDU header including length byte */ + static final int SELECT_APDU_HDR_LENGTH = 5; + /** Length of the NDEF Tag application AID */ + static final int NDEF_AID_LENGTH = 7; + /** AID of the NDEF Tag application Mapping Version 1.0 */ + static final byte[] NDEF_AID_V1 = + new byte[] {(byte) 0xd2, 0x76, 0x00, 0x00, (byte) 0x85, 0x01, 0x00}; + /** AID of the NDEF Tag application Mapping Version 2.0 */ + static final byte[] NDEF_AID_V2 = + new byte[] {(byte) 0xd2, 0x76, 0x00, 0x00, (byte) 0x85, 0x01, 0x01}; + /** Select APDU header */ + static final byte[] SELECT_AID_HDR = new byte[] {0x00, (byte) 0xa4, 0x04, 0x00}; final RegisteredAidCache mAidCache; final RegisteredT3tIdentifiersCache mT3tIdentifiersCache; @@ -78,6 +93,7 @@ public class CardEmulationManager implements RegisteredServicesCache.Callback, final CardEmulationInterface mCardEmulationInterface; final NfcFCardEmulationInterface mNfcFCardEmulationInterface; final PowerManager mPowerManager; + boolean mNotSkipAid; public CardEmulationManager(Context context) { mContext = context; @@ -108,11 +124,16 @@ public class CardEmulationManager implements RegisteredServicesCache.Callback, public void onHostCardEmulationActivated(int technology) { if (mPowerManager != null) { - mPowerManager.userActivity(SystemClock.uptimeMillis(), PowerManager.USER_ACTIVITY_EVENT_TOUCH, 0); + // Use USER_ACTIVITY_FLAG_INDIRECT to applying power hints without resets + // the screen timeout + mPowerManager.userActivity(SystemClock.uptimeMillis(), + PowerManager.USER_ACTIVITY_EVENT_TOUCH, + PowerManager.USER_ACTIVITY_FLAG_INDIRECT); } if (technology == NFC_HCE_APDU) { mHostEmulationManager.onHostEmulationActivated(); mPreferredServices.onHostEmulationActivated(); + mNotSkipAid = false; } else if (technology == NFC_HCE_NFCF) { mHostNfcFEmulationManager.onHostEmulationActivated(); mNfcFServicesCache.onHostEmulationActivated(); @@ -121,14 +142,17 @@ public class CardEmulationManager implements RegisteredServicesCache.Callback, } public void onHostCardEmulationData(int technology, byte[] data) { - if (mPowerManager != null) { - mPowerManager.userActivity(SystemClock.uptimeMillis(), PowerManager.USER_ACTIVITY_EVENT_TOUCH, 0); - } if (technology == NFC_HCE_APDU) { mHostEmulationManager.onHostEmulationData(data); } else if (technology == NFC_HCE_NFCF) { mHostNfcFEmulationManager.onHostEmulationData(data); } + // Don't trigger userActivity if it's selecting NDEF AID + if (mPowerManager != null && !(technology == NFC_HCE_APDU && isSkipAid(data))) { + // Caution!! USER_ACTIVITY_EVENT_TOUCH resets the screen timeout + mPowerManager.userActivity(SystemClock.uptimeMillis(), + PowerManager.USER_ACTIVITY_EVENT_TOUCH, 0); + } } public void onHostCardEmulationDeactivated(int technology) { @@ -393,6 +417,37 @@ public class CardEmulationManager implements RegisteredServicesCache.Callback, } /** + * Returns true if it's not selecting NDEF AIDs + * It's used to skip userActivity if it only selects NDEF AIDs + */ + boolean isSkipAid(byte[] data) { + if (mNotSkipAid || data == null + || data.length < SELECT_APDU_HDR_LENGTH + MINIMUM_AID_LENGTH + || !Arrays.equals(SELECT_AID_HDR, 0, SELECT_AID_HDR.length, + data, 0, SELECT_AID_HDR.length)) { + return false; + } + int aidLength = data[SELECT_APDU_HDR_LENGTH - 1]; + if (data.length >= SELECT_APDU_HDR_LENGTH + NDEF_AID_LENGTH + && aidLength == NDEF_AID_LENGTH) { + if (Arrays.equals(data, SELECT_APDU_HDR_LENGTH, + SELECT_APDU_HDR_LENGTH + NDEF_AID_LENGTH, + NDEF_AID_V1, 0, NDEF_AID_LENGTH)) { + if (DBG) Log.d(TAG, "Skip for NDEF_V1"); + return true; + } else if (Arrays.equals(data, SELECT_APDU_HDR_LENGTH, + SELECT_APDU_HDR_LENGTH + NDEF_AID_LENGTH, + NDEF_AID_V2, 0, NDEF_AID_LENGTH)) { + if (DBG) Log.d(TAG, "Skip for NDEF_V2"); + return true; + } + } + // The data payload is not selecting the skip AID. + mNotSkipAid = true; + return false; + } + + /** * Returns whether a service in this package is preferred, * either because it's the default payment app or it's running * in the foreground. diff --git a/src/com/android/nfc/cardemulation/HostEmulationManager.java b/src/com/android/nfc/cardemulation/HostEmulationManager.java index 826f1f2b..81462024 100644 --- a/src/com/android/nfc/cardemulation/HostEmulationManager.java +++ b/src/com/android/nfc/cardemulation/HostEmulationManager.java @@ -55,7 +55,7 @@ public class HostEmulationManager { static final int STATE_W4_DEACTIVATE = 3; static final int STATE_XFER = 4; - /** Minimum AID lenth as per ISO7816 */ + /** Minimum AID length as per ISO7816 */ static final int MINIMUM_AID_LENGTH = 5; /** Length of Select APDU header including length byte */ |