Tag.java revision c9f7890a203a013646650a695157277df81b6a17
1590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly/* 2590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Copyright (C) 2010 The Android Open Source Project 3590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * 4590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Licensed under the Apache License, Version 2.0 (the "License"); 5590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * you may not use this file except in compliance with the License. 6590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * You may obtain a copy of the License at 7590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * 8590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * http://www.apache.org/licenses/LICENSE-2.0 9590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * 10590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Unless required by applicable law or agreed to in writing, software 11590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * distributed under the License is distributed on an "AS IS" BASIS, 12590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * See the License for the specific language governing permissions and 14590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * limitations under the License. 15590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 16590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 17590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pellypackage android.nfc; 18590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 19590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pellyimport android.os.Parcel; 20590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pellyimport android.os.Parcelable; 21590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 22590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly/** 23c9f7890a203a013646650a695157277df81b6a17Scott Main * Represents a (generic) discovered tag. 24590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * <p> 25590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * A tag is a passive NFC element, such as NFC Forum Tag's, Mifare class Tags, 26590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Sony Felica Tags. 27590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * <p> 28590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Tag's have a type and usually have a UID. 29590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * <p> 30c9f7890a203a013646650a695157277df81b6a17Scott Main * {@link Tag} objects are passed to applications via the {@link NfcAdapter#EXTRA_TAG} extra 31c9f7890a203a013646650a695157277df81b6a17Scott Main * in {@link NfcAdapter#ACTION_TAG_DISCOVERED} intents. A {@link Tag} object is immutable 32c9f7890a203a013646650a695157277df81b6a17Scott Main * and represents the state of the tag at the time of discovery. It can be 33c9f7890a203a013646650a695157277df81b6a17Scott Main * directly queried for its UID and Type, or used to create a {@link RawTagConnection} 34c9f7890a203a013646650a695157277df81b6a17Scott Main * (with {@link NfcAdapter#createRawTagConnection createRawTagConnection()}). 35590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * <p> 36c9f7890a203a013646650a695157277df81b6a17Scott Main * A {@link Tag} can be used to create a {@link RawTagConnection} only while the tag is in 37c9f7890a203a013646650a695157277df81b6a17Scott Main * range. If it is removed and then returned to range, then the most recent 38c9f7890a203a013646650a695157277df81b6a17Scott Main * {@link Tag} object (in {@link NfcAdapter#ACTION_TAG_DISCOVERED}) should be used to create a 39c9f7890a203a013646650a695157277df81b6a17Scott Main * {@link RawTagConnection}. 40c9f7890a203a013646650a695157277df81b6a17Scott Main * <p>This is an immutable data class. 41590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 42590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pellypublic class Tag implements Parcelable { 43590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 44590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 45590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 46590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 47590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_ISO14443_A = 1; /* phNfc_eISO14443_A_PICC */ 48590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 49590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 50590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 51590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 52590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_ISO14443_4A = 2; /* phNfc_eISO14443_4A_PICC */ 53590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 54590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 55590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 56590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 57590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_ISO14443_3A = 3; /* phNfc_eISO14443_3A_PICC */ 58590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 59590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 60590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 61590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 62590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_MIFARE = 4; /* phNfc_eMifare_PICC */ 63590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 64590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 65590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 66590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 67590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_ISO14443_B = 5; /* phNfc_eISO14443_B_PICC */ 68590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 69590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 70590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 71590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 72590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_ISO14443_4B = 6; /* phNfc_eISO14443_4B_PICC */ 73590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 74590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 75590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 76590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 77590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_ISO14443_B_PRIME = 7; /* phNfc_eISO14443_BPrime_PICC */ 78590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 79590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 80590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 81590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 82590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_FELICA = 8; /* phNfc_eFelica_PICC */ 83590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 84590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 85590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 86590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 87590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_JEWEL = 9; /* phNfc_eJewel_PICC */ 88590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 89590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 90590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 91590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 92590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_ISO15693 = 10; /* phNfc_eISO15693_PICC */ 93590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 94590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 95590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 96590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 97590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_OTHER = 11; /* phNfc_ePICC_DevType */ 98590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 99590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 100590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_ISO_14443_3A = "iso14443_3a"; 101590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 102590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_ISO_14443_3B = "iso14443_3b"; 103590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 104590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_ISO_14443_3B_PRIME = "iso14443_3b"; 105590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 106590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_ISO_14443_4 = "iso14443_4"; 107590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 108590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_ISO_15693 = "iso15693"; 109590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 110590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_JIS_X_6319_4 = "jis_x_6319_4"; 111590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 112590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_TOPAZ = "topaz"; 113590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 114590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_OTHER = "other"; 115590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 116590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /*package*/ final int mType; 117590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /*package*/ final boolean mIsNdef; 118590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /*package*/ final byte[] mUid; 119590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /*package*/ final int mNativeHandle; 120590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 121590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 122590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Hidden constructor to be used by NFC service only. 123590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 124590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 125590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public Tag(int type, boolean isNdef, byte[] uid, int nativeHandle) { 126590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly mType = type; 127590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly mIsNdef = isNdef; 128590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly mUid = uid.clone(); 129590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly mNativeHandle = nativeHandle; 130590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 131590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 132590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 133590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * For use by NfcService only. 134590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 135590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 136590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public int getHandle() { 137590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly return mNativeHandle; 138590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 139590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 140590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 141590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Return the available targets that this NFC adapter can use to create 142590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * a RawTagConnection. 143590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * 144590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @return 145590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 146590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public String[] getRawTargets() { 147590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly //TODO 148590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly throw new UnsupportedOperationException(); 149590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 150590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 151590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 152590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Get the Tag type. 153590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * <p> 154590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * The Tag type is one of the NFC_TAG constants. It is read at discovery 155590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * time and this method does not cause any further RF activity and does not 156590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * block. 157590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * 158590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @return a NFC_TAG constant 159590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 160590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 161590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public int getType() { 162590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly return mType; 163590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 164590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 165590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 166590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Get the Tag Identifier (if it has one). 167590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * <p> 168590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Tag ID is usually a serial number for the tag. 169590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * <p> 170590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * The Tag ID is read at discovery time and this method does not cause any 171590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * further RF activity and does not block. 172590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * 173590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @return ID, or null if it does not exist 174590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 175590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public byte[] getId() { 176590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly if (mUid.length > 0) { 177590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly return mUid.clone(); 178590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } else { 179590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly return null; 180590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 181590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 182590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 183590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly @Override 184590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public int describeContents() { 185590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly return 0; 186590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 187590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 188590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly @Override 189590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public void writeToParcel(Parcel dest, int flags) { 190590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly boolean[] booleans = new boolean[] {mIsNdef}; 191590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly dest.writeInt(mType); 192590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly dest.writeBooleanArray(booleans); 193590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly dest.writeInt(mUid.length); 194590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly dest.writeByteArray(mUid); 195590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly dest.writeInt(mNativeHandle); 196590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 197590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 198590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final Parcelable.Creator<Tag> CREATOR = 199590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly new Parcelable.Creator<Tag>() { 200590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public Tag createFromParcel(Parcel in) { 201590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly boolean[] booleans = new boolean[1]; 202590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly int type = in.readInt(); 203590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly in.readBooleanArray(booleans); 204590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly boolean isNdef = booleans[0]; 205590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly int uidLength = in.readInt(); 206590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly byte[] uid = new byte[uidLength]; 207590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly in.readByteArray(uid); 208590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly int nativeHandle = in.readInt(); 209590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 210590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly return new Tag(type, isNdef, uid, nativeHandle); 211590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 212590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public Tag[] newArray(int size) { 213590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly return new Tag[size]; 214590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 215590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly }; 216590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly}