diff options
author | Martijn Coenen <maco@google.com> | 2014-07-02 20:28:45 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-07-02 18:11:52 +0000 |
commit | 8d61b672348a4ac37363606d4562e6e1ac513858 (patch) | |
tree | 628f43ecbf5c1709a3c43ba21a90f77364d0be3a /core | |
parent | 287554ca953bfa20f6050b0d68d685378106f58e (diff) | |
parent | b51441163fc4c493cddce08f5418021a31d0a719 (diff) | |
download | frameworks_base-8d61b672348a4ac37363606d4562e6e1ac513858.zip frameworks_base-8d61b672348a4ac37363606d4562e6e1ac513858.tar.gz frameworks_base-8d61b672348a4ac37363606d4562e6e1ac513858.tar.bz2 |
Merge "Move AID validation to CardEmulation."
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/nfc/cardemulation/AidGroup.java | 2 | ||||
-rw-r--r-- | core/java/android/nfc/cardemulation/ApduServiceInfo.java | 36 | ||||
-rw-r--r-- | core/java/android/nfc/cardemulation/CardEmulation.java | 37 |
3 files changed, 39 insertions, 36 deletions
diff --git a/core/java/android/nfc/cardemulation/AidGroup.java b/core/java/android/nfc/cardemulation/AidGroup.java index 34568c2..54b517a 100644 --- a/core/java/android/nfc/cardemulation/AidGroup.java +++ b/core/java/android/nfc/cardemulation/AidGroup.java @@ -51,7 +51,7 @@ public final class AidGroup implements Parcelable { throw new IllegalArgumentException("Too many AIDs in AID group."); } for (String aid : aids) { - if (!ApduServiceInfo.isValidAid(aid)) { + if (!CardEmulation.isValidAid(aid)) { throw new IllegalArgumentException("AID " + aid + " is not a valid AID."); } } diff --git a/core/java/android/nfc/cardemulation/ApduServiceInfo.java b/core/java/android/nfc/cardemulation/ApduServiceInfo.java index 930cf11..0df87c1 100644 --- a/core/java/android/nfc/cardemulation/ApduServiceInfo.java +++ b/core/java/android/nfc/cardemulation/ApduServiceInfo.java @@ -218,7 +218,7 @@ public final class ApduServiceInfo implements Parcelable { com.android.internal.R.styleable.AidFilter); String aid = a.getString(com.android.internal.R.styleable.AidFilter_name). toUpperCase(); - if (isValidAid(aid) && !currentGroup.aids.contains(aid)) { + if (CardEmulation.isValidAid(aid) && !currentGroup.aids.contains(aid)) { currentGroup.aids.add(aid); } else { Log.e(TAG, "Ignoring invalid or duplicate aid: " + aid); @@ -351,40 +351,6 @@ public final class ApduServiceInfo implements Parcelable { } } - /** - * A valid AID according to ISO/IEC 7816-4: - * <ul> - * <li>Has >= 5 bytes and <=16 bytes (>=10 hex chars and <= 32 hex chars) - * <li>Consist of only hex characters - * <li>Additionally, we allow an asterisk at the end, to indicate - * a prefix - * </ul> - */ - static boolean isValidAid(String aid) { - if (aid == null) - return false; - - // If a prefix AID, the total length must be odd (even # of AID chars + '*') - if (aid.endsWith("*") && ((aid.length() % 2) == 0)) { - Log.e(TAG, "AID " + aid + " is not a valid AID."); - return false; - } - - // If not a prefix AID, the total length must be even (even # of AID chars) - if (!aid.endsWith("*") && ((aid.length() % 2) != 0)) { - Log.e(TAG, "AID " + aid + " is not a valid AID."); - return false; - } - - // Verify hex characters - if (!aid.matches("[0-9A-Fa-f]{10,32}\\*?")) { - Log.e(TAG, "AID " + aid + " is not a valid AID."); - return false; - } - - return true; - } - @Override public String toString() { StringBuilder out = new StringBuilder("ApduService: "); diff --git a/core/java/android/nfc/cardemulation/CardEmulation.java b/core/java/android/nfc/cardemulation/CardEmulation.java index 4b9e890..bf248d2 100644 --- a/core/java/android/nfc/cardemulation/CardEmulation.java +++ b/core/java/android/nfc/cardemulation/CardEmulation.java @@ -571,8 +571,45 @@ public final class CardEmulation { } } + /** + * A valid AID according to ISO/IEC 7816-4: + * <ul> + * <li>Has >= 5 bytes and <=16 bytes (>=10 hex chars and <= 32 hex chars) + * <li>Consist of only hex characters + * <li>Additionally, we allow an asterisk at the end, to indicate + * a prefix + * </ul> + * + * @hide + */ + public static boolean isValidAid(String aid) { + if (aid == null) + return false; + + // If a prefix AID, the total length must be odd (even # of AID chars + '*') + if (aid.endsWith("*") && ((aid.length() % 2) == 0)) { + Log.e(TAG, "AID " + aid + " is not a valid AID."); + return false; + } + + // If not a prefix AID, the total length must be even (even # of AID chars) + if (!aid.endsWith("*") && ((aid.length() % 2) != 0)) { + Log.e(TAG, "AID " + aid + " is not a valid AID."); + return false; + } + + // Verify hex characters + if (!aid.matches("[0-9A-Fa-f]{10,32}\\*?")) { + Log.e(TAG, "AID " + aid + " is not a valid AID."); + return false; + } + + return true; + } + void recoverService() { NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mContext); sService = adapter.getCardEmulationService(); } + } |