Tag.java revision 590b73bc5b8e5f7b59bff1d9264a52388a5162e6
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/** 23590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Immutable data class, represents a 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> 30590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Tag objects are passed to applications via the NfcAdapter.EXTRA_TAG extra 31590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * in NfcAdapter.ACTION_TAG_DISCOVERED intents. The Tag object is immutable 32590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * and represents the state of the Tag at the time of discovery. It can be 33590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * directly queried for its UID and Type, or used to create a TagConnection 34590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * (NfcAdapter.createTagConnection()). 35590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * <p> 36590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * This Tag object can only be used to create a TagConnection while it is in 37590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * range. If it is removed and then returned to range then the most recent 38590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Tag object (in ACTION_TAG_DISCOVERED) should be used to create a 39590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * TagConnection. 40590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 41590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pellypublic class Tag implements Parcelable { 42590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 43590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 44590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 45590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 46590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_ISO14443_A = 1; /* phNfc_eISO14443_A_PICC */ 47590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 48590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 49590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 50590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 51590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_ISO14443_4A = 2; /* phNfc_eISO14443_4A_PICC */ 52590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 53590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 54590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 55590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 56590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_ISO14443_3A = 3; /* phNfc_eISO14443_3A_PICC */ 57590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 58590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 59590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 60590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 61590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_MIFARE = 4; /* phNfc_eMifare_PICC */ 62590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 63590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 64590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 65590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 66590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_ISO14443_B = 5; /* phNfc_eISO14443_B_PICC */ 67590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 68590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 69590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 70590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 71590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_ISO14443_4B = 6; /* phNfc_eISO14443_4B_PICC */ 72590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 73590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 74590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 75590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 76590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_ISO14443_B_PRIME = 7; /* phNfc_eISO14443_BPrime_PICC */ 77590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 78590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 79590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 80590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 81590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_FELICA = 8; /* phNfc_eFelica_PICC */ 82590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 83590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 84590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 85590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 86590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_JEWEL = 9; /* phNfc_eJewel_PICC */ 87590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 88590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 89590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 90590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 91590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_ISO15693 = 10; /* phNfc_eISO15693_PICC */ 92590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 93590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 94590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 95590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 96590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final int NFC_TAG_OTHER = 11; /* phNfc_ePICC_DevType */ 97590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 98590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 99590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_ISO_14443_3A = "iso14443_3a"; 100590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 101590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_ISO_14443_3B = "iso14443_3b"; 102590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 103590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_ISO_14443_3B_PRIME = "iso14443_3b"; 104590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 105590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_ISO_14443_4 = "iso14443_4"; 106590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 107590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_ISO_15693 = "iso15693"; 108590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 109590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_JIS_X_6319_4 = "jis_x_6319_4"; 110590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 111590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_TOPAZ = "topaz"; 112590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 113590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final String TARGET_OTHER = "other"; 114590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 115590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /*package*/ final int mType; 116590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /*package*/ final boolean mIsNdef; 117590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /*package*/ final byte[] mUid; 118590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /*package*/ final int mNativeHandle; 119590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 120590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 121590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Hidden constructor to be used by NFC service only. 122590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 123590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 124590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public Tag(int type, boolean isNdef, byte[] uid, int nativeHandle) { 125590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly mType = type; 126590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly mIsNdef = isNdef; 127590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly mUid = uid.clone(); 128590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly mNativeHandle = nativeHandle; 129590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 130590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 131590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 132590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * For use by NfcService only. 133590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 134590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 135590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public int getHandle() { 136590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly return mNativeHandle; 137590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 138590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 139590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 140590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Return the available targets that this NFC adapter can use to create 141590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * a RawTagConnection. 142590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * 143590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @return 144590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 145590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public String[] getRawTargets() { 146590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly //TODO 147590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly throw new UnsupportedOperationException(); 148590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 149590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 150590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 151590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Get the Tag type. 152590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * <p> 153590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * The Tag type is one of the NFC_TAG constants. It is read at discovery 154590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * time and this method does not cause any further RF activity and does not 155590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * block. 156590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * 157590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @return a NFC_TAG constant 158590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @hide 159590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 160590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public int getType() { 161590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly return mType; 162590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 163590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 164590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly /** 165590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Get the Tag Identifier (if it has one). 166590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * <p> 167590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Tag ID is usually a serial number for the tag. 168590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * <p> 169590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * The Tag ID is read at discovery time and this method does not cause any 170590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * further RF activity and does not block. 171590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * 172590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * @return ID, or null if it does not exist 173590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly */ 174590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public byte[] getId() { 175590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly if (mUid.length > 0) { 176590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly return mUid.clone(); 177590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } else { 178590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly return null; 179590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 180590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 181590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 182590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly @Override 183590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public int describeContents() { 184590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly return 0; 185590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 186590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 187590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly @Override 188590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public void writeToParcel(Parcel dest, int flags) { 189590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly boolean[] booleans = new boolean[] {mIsNdef}; 190590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly dest.writeInt(mType); 191590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly dest.writeBooleanArray(booleans); 192590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly dest.writeInt(mUid.length); 193590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly dest.writeByteArray(mUid); 194590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly dest.writeInt(mNativeHandle); 195590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 196590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 197590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public static final Parcelable.Creator<Tag> CREATOR = 198590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly new Parcelable.Creator<Tag>() { 199590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public Tag createFromParcel(Parcel in) { 200590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly boolean[] booleans = new boolean[1]; 201590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly int type = in.readInt(); 202590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly in.readBooleanArray(booleans); 203590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly boolean isNdef = booleans[0]; 204590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly int uidLength = in.readInt(); 205590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly byte[] uid = new byte[uidLength]; 206590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly in.readByteArray(uid); 207590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly int nativeHandle = in.readInt(); 208590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly 209590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly return new Tag(type, isNdef, uid, nativeHandle); 210590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 211590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly public Tag[] newArray(int size) { 212590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly return new Tag[size]; 213590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly } 214590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly }; 215590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly}