Merge gingerbread-nfc into gingerbread

This commit is contained in:
Nick Pelly
2010-12-05 18:08:16 -08:00
3 changed files with 86 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ package android.nfc;
import android.nfc.technology.IsoDep;
import android.nfc.technology.MifareClassic;
import android.nfc.technology.MifareUltralight;
import android.nfc.technology.NfcV;
import android.nfc.technology.Ndef;
import android.nfc.technology.NfcA;
@@ -160,6 +161,9 @@ public class Tag implements Parcelable {
case TagTechnology.MIFARE_CLASSIC: {
return new MifareClassic(adapter, this, extras);
}
case TagTechnology.MIFARE_ULTRALIGHT: {
return new MifareUltralight(adapter, this, extras);
}
default: {
throw new UnsupportedOperationException("Tech " + tech + " not supported");

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.nfc.technology;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.os.Bundle;
import android.os.RemoteException;
import java.io.IOException;
/**
* Concrete class for TagTechnology.MIFARE_ULTRALIGHT
*
* Mifare classic has n sectors, with varying sizes, although
* they are at least the same pattern for any one mifare classic
* product. Each sector has two keys. Authentication with the correct
* key is needed before access to any sector.
*
* Each sector has k blocks.
* Block size is constant across the whole mifare classic family.
*/
public final class MifareUltralight extends BasicTagTechnology {
public static final int TYPE_ULTRALIGHT = 1;
public static final int TYPE_ULTRALIGHT_C = 2;
public static final int TYPE_UNKNOWN = 10;
private static final int NXP_MANUFACTURER_ID = 0x04;
private int mType;
public MifareUltralight(NfcAdapter adapter, Tag tag, Bundle extras) throws RemoteException {
super(adapter, tag, TagTechnology.MIFARE_ULTRALIGHT);
// Check if this could actually be a Mifare
NfcA a = (NfcA) tag.getTechnology(TagTechnology.NFC_A);
mType = TYPE_UNKNOWN;
if( a.getSak() == 0x00 && tag.getId()[0] == NXP_MANUFACTURER_ID ) {
// could be UL or UL-C
mType = TYPE_ULTRALIGHT;
}
}
public int getType() {
return mType;
}
// Methods that require connect()
/**
* @throws IOException
*/
public byte[] readBlock(int block) throws IOException {
byte[] blockread_cmd = { 0x30, (byte)block }; // phHal_eMifareRead
return transceive(blockread_cmd);
}
/**
* @throws IOException
*/
/*
public byte[] readOTP();
public void writePage(int block, byte[] data);
public void writeBlock(int block, byte[] data);
*/
}

View File

@@ -77,7 +77,7 @@ public interface TagTechnology {
public static final int MIFARE_CLASSIC_NDEF = 201;
/**
* A Mifare Ultralight tag
* This object is an instance of {@link MifareUltralight}
*/
public static final int MIFARE_ULTRALIGHT = 202;