Loading core/java/android/nfc/cardemulation/AidGroup.java +1 −1 Original line number Diff line number Diff line Loading @@ -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."); } } Loading core/java/android/nfc/cardemulation/ApduServiceInfo.java +1 −35 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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: "); Loading core/java/android/nfc/cardemulation/CardEmulation.java +37 −0 Original line number Diff line number Diff line Loading @@ -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(); } } Loading
core/java/android/nfc/cardemulation/AidGroup.java +1 −1 Original line number Diff line number Diff line Loading @@ -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."); } } Loading
core/java/android/nfc/cardemulation/ApduServiceInfo.java +1 −35 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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: "); Loading
core/java/android/nfc/cardemulation/CardEmulation.java +37 −0 Original line number Diff line number Diff line Loading @@ -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(); } }