NFC API revision round 2.
- Add the second half of the new NFC API: NfcAdapter, Tag, NdefTag, RawTagConnection, NdefTagConnection. - Add implementations for all of the new NFC API. Change-Id: I8da9fd1d2971ed2c8b76f2a93f207fa9e305b0f6 Signed-off-by: Nick Pelly <npelly@google.com>
This commit is contained in:
12
Android.mk
12
Android.mk
@@ -159,14 +159,6 @@ LOCAL_SRC_FILES += \
|
|||||||
core/java/com/android/internal/view/IInputMethodClient.aidl \
|
core/java/com/android/internal/view/IInputMethodClient.aidl \
|
||||||
core/java/com/android/internal/view/IInputMethodManager.aidl \
|
core/java/com/android/internal/view/IInputMethodManager.aidl \
|
||||||
core/java/com/android/internal/view/IInputMethodSession.aidl \
|
core/java/com/android/internal/view/IInputMethodSession.aidl \
|
||||||
core/java/com/trustedlogic/trustednfc/android/ILlcpConnectionlessSocket.aidl \
|
|
||||||
core/java/com/trustedlogic/trustednfc/android/ILlcpServiceSocket.aidl \
|
|
||||||
core/java/com/trustedlogic/trustednfc/android/ILlcpSocket.aidl \
|
|
||||||
core/java/com/trustedlogic/trustednfc/android/INdefTag.aidl \
|
|
||||||
core/java/com/trustedlogic/trustednfc/android/INfcManager.aidl \
|
|
||||||
core/java/com/trustedlogic/trustednfc/android/INfcTag.aidl \
|
|
||||||
core/java/com/trustedlogic/trustednfc/android/IP2pInitiator.aidl \
|
|
||||||
core/java/com/trustedlogic/trustednfc/android/IP2pTarget.aidl \
|
|
||||||
location/java/android/location/IGeocodeProvider.aidl \
|
location/java/android/location/IGeocodeProvider.aidl \
|
||||||
location/java/android/location/IGpsStatusListener.aidl \
|
location/java/android/location/IGpsStatusListener.aidl \
|
||||||
location/java/android/location/IGpsStatusProvider.aidl \
|
location/java/android/location/IGpsStatusProvider.aidl \
|
||||||
@@ -249,6 +241,10 @@ aidl_files := \
|
|||||||
frameworks/base/core/java/android/content/res/Configuration.aidl \
|
frameworks/base/core/java/android/content/res/Configuration.aidl \
|
||||||
frameworks/base/core/java/android/appwidget/AppWidgetProviderInfo.aidl \
|
frameworks/base/core/java/android/appwidget/AppWidgetProviderInfo.aidl \
|
||||||
frameworks/base/core/java/android/net/Uri.aidl \
|
frameworks/base/core/java/android/net/Uri.aidl \
|
||||||
|
frameworks/base/core/java/android/nfc/NdefMessage.aidl \
|
||||||
|
frameworks/base/core/java/android/nfc/NdefRecord.aidl \
|
||||||
|
frameworks/base/core/java/android/nfc/Tag.aidl \
|
||||||
|
frameworks/base/core/java/android/nfc/NdefTag.aidl \
|
||||||
frameworks/base/core/java/android/os/Bundle.aidl \
|
frameworks/base/core/java/android/os/Bundle.aidl \
|
||||||
frameworks/base/core/java/android/os/DropBoxManager.aidl \
|
frameworks/base/core/java/android/os/DropBoxManager.aidl \
|
||||||
frameworks/base/core/java/android/os/ParcelFileDescriptor.aidl \
|
frameworks/base/core/java/android/os/ParcelFileDescriptor.aidl \
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libreverb_inte
|
|||||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libreverbtest_intermediates)
|
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libreverbtest_intermediates)
|
||||||
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/soundfx/)
|
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/lib/soundfx/)
|
||||||
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/os/storage/*)
|
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/os/storage/*)
|
||||||
|
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/com/trustedlogic)
|
||||||
|
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/com/trustedlogic)
|
||||||
|
|
||||||
# ************************************************
|
# ************************************************
|
||||||
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
|
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
|
||||||
|
|||||||
653
api/current.xml
653
api/current.xml
@@ -102984,6 +102984,33 @@
|
|||||||
</package>
|
</package>
|
||||||
<package name="android.nfc"
|
<package name="android.nfc"
|
||||||
>
|
>
|
||||||
|
<class name="FormatException"
|
||||||
|
extends="java.lang.Exception"
|
||||||
|
abstract="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<constructor name="FormatException"
|
||||||
|
type="android.nfc.FormatException"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</constructor>
|
||||||
|
<constructor name="FormatException"
|
||||||
|
type="android.nfc.FormatException"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<parameter name="message" type="java.lang.String">
|
||||||
|
</parameter>
|
||||||
|
</constructor>
|
||||||
|
</class>
|
||||||
<class name="NdefMessage"
|
<class name="NdefMessage"
|
||||||
extends="java.lang.Object"
|
extends="java.lang.Object"
|
||||||
abstract="false"
|
abstract="false"
|
||||||
@@ -103323,6 +103350,632 @@
|
|||||||
>
|
>
|
||||||
</field>
|
</field>
|
||||||
</class>
|
</class>
|
||||||
|
<class name="NdefTag"
|
||||||
|
extends="android.nfc.Tag"
|
||||||
|
abstract="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<implements name="android.os.Parcelable">
|
||||||
|
</implements>
|
||||||
|
<method name="getNdefMessages"
|
||||||
|
return="android.nfc.NdefMessage[]"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</method>
|
||||||
|
<method name="getNdefMessages"
|
||||||
|
return="android.nfc.NdefMessage[]"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<parameter name="target" type="java.lang.String">
|
||||||
|
</parameter>
|
||||||
|
</method>
|
||||||
|
<method name="getNdefTargets"
|
||||||
|
return="java.lang.String[]"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</method>
|
||||||
|
<field name="CREATOR"
|
||||||
|
type="android.os.Parcelable.Creator"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="TARGET_MIFARE_CLASSIC"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""type_mifare_classic""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="TARGET_OTHER"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""other""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="TARGET_TYPE_1"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""type_1""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="TARGET_TYPE_2"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""type_2""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="TARGET_TYPE_3"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""type_3""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="TARGET_TYPE_4"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""type_4""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
</class>
|
||||||
|
<class name="NdefTagConnection"
|
||||||
|
extends="android.nfc.RawTagConnection"
|
||||||
|
abstract="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<method name="getModeHint"
|
||||||
|
return="int"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<exception name="IOException" type="java.io.IOException">
|
||||||
|
</exception>
|
||||||
|
</method>
|
||||||
|
<method name="makeReadOnly"
|
||||||
|
return="boolean"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<exception name="IOException" type="java.io.IOException">
|
||||||
|
</exception>
|
||||||
|
</method>
|
||||||
|
<method name="readNdefMessages"
|
||||||
|
return="android.nfc.NdefMessage[]"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<exception name="FormatException" type="android.nfc.FormatException">
|
||||||
|
</exception>
|
||||||
|
<exception name="IOException" type="java.io.IOException">
|
||||||
|
</exception>
|
||||||
|
</method>
|
||||||
|
<method name="writeNdefMessage"
|
||||||
|
return="void"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<parameter name="message" type="android.nfc.NdefMessage">
|
||||||
|
</parameter>
|
||||||
|
<exception name="FormatException" type="android.nfc.FormatException">
|
||||||
|
</exception>
|
||||||
|
<exception name="IOException" type="java.io.IOException">
|
||||||
|
</exception>
|
||||||
|
</method>
|
||||||
|
<field name="NDEF_MODE_READ_ONCE"
|
||||||
|
type="int"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value="1"
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="NDEF_MODE_READ_ONLY"
|
||||||
|
type="int"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value="2"
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="NDEF_MODE_UNKNOWN"
|
||||||
|
type="int"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value="5"
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="NDEF_MODE_WRITE_MANY"
|
||||||
|
type="int"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value="4"
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="NDEF_MODE_WRITE_ONCE"
|
||||||
|
type="int"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value="3"
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
</class>
|
||||||
|
<class name="NfcAdapter"
|
||||||
|
extends="java.lang.Object"
|
||||||
|
abstract="false"
|
||||||
|
static="false"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<method name="createNdefTagConnection"
|
||||||
|
return="android.nfc.NdefTagConnection"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<parameter name="tag" type="android.nfc.NdefTag">
|
||||||
|
</parameter>
|
||||||
|
</method>
|
||||||
|
<method name="createNdefTagConnection"
|
||||||
|
return="android.nfc.NdefTagConnection"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<parameter name="tag" type="android.nfc.NdefTag">
|
||||||
|
</parameter>
|
||||||
|
<parameter name="target" type="java.lang.String">
|
||||||
|
</parameter>
|
||||||
|
</method>
|
||||||
|
<method name="createRawTagConnection"
|
||||||
|
return="android.nfc.RawTagConnection"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<parameter name="tag" type="android.nfc.Tag">
|
||||||
|
</parameter>
|
||||||
|
</method>
|
||||||
|
<method name="createRawTagConnection"
|
||||||
|
return="android.nfc.RawTagConnection"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<parameter name="tag" type="android.nfc.Tag">
|
||||||
|
</parameter>
|
||||||
|
<parameter name="target" type="java.lang.String">
|
||||||
|
</parameter>
|
||||||
|
</method>
|
||||||
|
<method name="getDefaultAdapter"
|
||||||
|
return="android.nfc.NfcAdapter"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="true"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</method>
|
||||||
|
<method name="getLocalNdefMessage"
|
||||||
|
return="android.nfc.NdefMessage"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</method>
|
||||||
|
<method name="isTagDiscoveryEnabled"
|
||||||
|
return="boolean"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</method>
|
||||||
|
<method name="setLocalNdefMessage"
|
||||||
|
return="void"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<parameter name="message" type="android.nfc.NdefMessage">
|
||||||
|
</parameter>
|
||||||
|
</method>
|
||||||
|
<field name="ACTION_NDEF_TAG_DISCOVERED"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""android.nfc.action.NDEF_TAG_DISCOVERED""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="ACTION_TAG_DISCOVERED"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""android.nfc.action.TAG_DISCOVERED""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="EXTRA_TAG"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""android.nfc.extra.TAG""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
</class>
|
||||||
|
<class name="RawTagConnection"
|
||||||
|
extends="java.lang.Object"
|
||||||
|
abstract="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<method name="close"
|
||||||
|
return="void"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</method>
|
||||||
|
<method name="connect"
|
||||||
|
return="void"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<exception name="IOException" type="java.io.IOException">
|
||||||
|
</exception>
|
||||||
|
</method>
|
||||||
|
<method name="getTag"
|
||||||
|
return="android.nfc.Tag"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</method>
|
||||||
|
<method name="getTagTarget"
|
||||||
|
return="java.lang.String"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</method>
|
||||||
|
<method name="isConnected"
|
||||||
|
return="boolean"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</method>
|
||||||
|
<method name="transceive"
|
||||||
|
return="byte[]"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<parameter name="data" type="byte[]">
|
||||||
|
</parameter>
|
||||||
|
<exception name="IOException" type="java.io.IOException">
|
||||||
|
</exception>
|
||||||
|
</method>
|
||||||
|
</class>
|
||||||
|
<class name="Tag"
|
||||||
|
extends="java.lang.Object"
|
||||||
|
abstract="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<implements name="android.os.Parcelable">
|
||||||
|
</implements>
|
||||||
|
<method name="describeContents"
|
||||||
|
return="int"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</method>
|
||||||
|
<method name="getId"
|
||||||
|
return="byte[]"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</method>
|
||||||
|
<method name="getRawTargets"
|
||||||
|
return="java.lang.String[]"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</method>
|
||||||
|
<method name="writeToParcel"
|
||||||
|
return="void"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
<parameter name="dest" type="android.os.Parcel">
|
||||||
|
</parameter>
|
||||||
|
<parameter name="flags" type="int">
|
||||||
|
</parameter>
|
||||||
|
</method>
|
||||||
|
<field name="CREATOR"
|
||||||
|
type="android.os.Parcelable.Creator"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="TARGET_ISO_14443_3A"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""iso14443_3a""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="TARGET_ISO_14443_3B"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""iso14443_3b""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="TARGET_ISO_14443_3B_PRIME"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""iso14443_3b""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="TARGET_ISO_14443_4"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""iso14443_4""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="TARGET_ISO_15693"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""iso15693""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="TARGET_JIS_X_6319_4"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""jis_x_6319_4""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="TARGET_OTHER"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""other""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
<field name="TARGET_TOPAZ"
|
||||||
|
type="java.lang.String"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
value=""topaz""
|
||||||
|
static="true"
|
||||||
|
final="true"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
|
</class>
|
||||||
</package>
|
</package>
|
||||||
<package name="android.opengl"
|
<package name="android.opengl"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -102,9 +102,6 @@ import android.view.inputmethod.InputMethodManager;
|
|||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.accounts.IAccountManager;
|
import android.accounts.IAccountManager;
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import com.trustedlogic.trustednfc.android.NfcManager;
|
|
||||||
import com.trustedlogic.trustednfc.android.INfcManager;
|
|
||||||
|
|
||||||
import com.android.internal.os.IDropBoxManagerService;
|
import com.android.internal.os.IDropBoxManagerService;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -173,7 +170,6 @@ class ContextImpl extends Context {
|
|||||||
private static ThrottleManager sThrottleManager;
|
private static ThrottleManager sThrottleManager;
|
||||||
private static WifiManager sWifiManager;
|
private static WifiManager sWifiManager;
|
||||||
private static LocationManager sLocationManager;
|
private static LocationManager sLocationManager;
|
||||||
private static NfcManager sNfcManager;
|
|
||||||
private static final HashMap<String, SharedPreferencesImpl> sSharedPrefs =
|
private static final HashMap<String, SharedPreferencesImpl> sSharedPrefs =
|
||||||
new HashMap<String, SharedPreferencesImpl>();
|
new HashMap<String, SharedPreferencesImpl>();
|
||||||
|
|
||||||
@@ -972,8 +968,6 @@ class ContextImpl extends Context {
|
|||||||
return getClipboardManager();
|
return getClipboardManager();
|
||||||
} else if (WALLPAPER_SERVICE.equals(name)) {
|
} else if (WALLPAPER_SERVICE.equals(name)) {
|
||||||
return getWallpaperManager();
|
return getWallpaperManager();
|
||||||
} else if (NFC_SERVICE.equals(name)) {
|
|
||||||
return getNfcManager();
|
|
||||||
} else if (DROPBOX_SERVICE.equals(name)) {
|
} else if (DROPBOX_SERVICE.equals(name)) {
|
||||||
return getDropBoxManager();
|
return getDropBoxManager();
|
||||||
} else if (DEVICE_POLICY_SERVICE.equals(name)) {
|
} else if (DEVICE_POLICY_SERVICE.equals(name)) {
|
||||||
@@ -1209,21 +1203,6 @@ class ContextImpl extends Context {
|
|||||||
return mDownloadManager;
|
return mDownloadManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
private NfcManager getNfcManager()
|
|
||||||
{
|
|
||||||
synchronized (sSync) {
|
|
||||||
if (sNfcManager == null) {
|
|
||||||
IBinder b = ServiceManager.getService(NFC_SERVICE);
|
|
||||||
if (b == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
INfcManager service = INfcManager.Stub.asInterface(b);
|
|
||||||
sNfcManager = new NfcManager(service, mMainThread.getHandler());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sNfcManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int checkPermission(String permission, int pid, int uid) {
|
public int checkPermission(String permission, int pid, int uid) {
|
||||||
if (permission == null) {
|
if (permission == null) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2010 The Android Open Source Project
|
* Copyright (C) 2010, The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,13 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
package android.nfc;
|
||||||
* File : ErrorCodes.java
|
|
||||||
* Original-Author : Trusted Logic S.A. (Sylvain Fonteneau)
|
|
||||||
* Created : 26-02-2010
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android.internal;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class defines all the error codes that can be returned by the service
|
* This class defines all the error codes that can be returned by the service
|
||||||
@@ -83,9 +77,4 @@ public class ErrorCodes {
|
|||||||
|
|
||||||
public static final int ERROR_NO_SE_CONNECTED = -20;
|
public static final int ERROR_NO_SE_CONNECTED = -20;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
28
core/java/android/nfc/FormatException.java
Normal file
28
core/java/android/nfc/FormatException.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
//TODO(npelly) javadoc or consider alternatives
|
||||||
|
public class FormatException extends Exception {
|
||||||
|
public FormatException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormatException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,21 +14,17 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android;
|
package android.nfc;
|
||||||
|
|
||||||
import com.trustedlogic.trustednfc.android.LlcpPacket;
|
import android.nfc.LlcpPacket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* @hide
|
||||||
*
|
|
||||||
* {@hide}
|
|
||||||
*/
|
*/
|
||||||
interface ILlcpConnectionlessSocket
|
interface ILlcpConnectionlessSocket
|
||||||
{
|
{
|
||||||
|
|
||||||
void close(int nativeHandle);
|
void close(int nativeHandle);
|
||||||
int getSap(int nativeHandle);
|
int getSap(int nativeHandle);
|
||||||
LlcpPacket receiveFrom(int nativeHandle);
|
LlcpPacket receiveFrom(int nativeHandle);
|
||||||
int sendTo(int nativeHandle, in LlcpPacket packet);
|
int sendTo(int nativeHandle, in LlcpPacket packet);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -14,19 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android;
|
package android.nfc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
|
||||||
*
|
|
||||||
* {@hide}
|
* {@hide}
|
||||||
*/
|
*/
|
||||||
interface ILlcpServiceSocket
|
interface ILlcpServiceSocket
|
||||||
{
|
{
|
||||||
|
|
||||||
int accept(int nativeHandle);
|
int accept(int nativeHandle);
|
||||||
void close(int nativeHandle);
|
void close(int nativeHandle);
|
||||||
int getAcceptTimeout(int nativeHandle);
|
int getAcceptTimeout(int nativeHandle);
|
||||||
void setAcceptTimeout(int nativeHandle, int timeout);
|
void setAcceptTimeout(int nativeHandle, int timeout);
|
||||||
|
|
||||||
}
|
}
|
||||||
36
core/java/android/nfc/ILlcpSocket.aidl
Normal file
36
core/java/android/nfc/ILlcpSocket.aidl
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
interface ILlcpSocket
|
||||||
|
{
|
||||||
|
int close(int nativeHandle);
|
||||||
|
int connect(int nativeHandle, int sap);
|
||||||
|
int connectByName(int nativeHandle, String sn);
|
||||||
|
int getConnectTimeout(int nativeHandle);
|
||||||
|
int getLocalSap(int nativeHandle);
|
||||||
|
int getLocalSocketMiu(int nativeHandle);
|
||||||
|
int getLocalSocketRw(int nativeHandle);
|
||||||
|
int getRemoteSocketMiu(int nativeHandle);
|
||||||
|
int getRemoteSocketRw(int nativeHandle);
|
||||||
|
int receive(int nativeHandle, out byte[] receiveBuffer);
|
||||||
|
int send(int nativeHandle, in byte[] data);
|
||||||
|
void setConnectTimeout(int nativeHandle, int timeout);
|
||||||
|
}
|
||||||
@@ -14,19 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android;
|
package android.nfc;
|
||||||
|
|
||||||
import com.trustedlogic.trustednfc.android.NdefMessage;
|
import android.nfc.NdefMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* @hide
|
||||||
*
|
|
||||||
* {@hide}
|
|
||||||
*/
|
*/
|
||||||
interface INdefTag
|
interface INdefTag
|
||||||
{
|
{
|
||||||
|
|
||||||
NdefMessage read(int nativeHandle);
|
NdefMessage read(int nativeHandle);
|
||||||
boolean write(int nativeHandle, in NdefMessage msg);
|
boolean write(int nativeHandle, in NdefMessage msg);
|
||||||
|
|
||||||
}
|
}
|
||||||
59
core/java/android/nfc/INfcAdapter.aidl
Normal file
59
core/java/android/nfc/INfcAdapter.aidl
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import android.nfc.NdefMessage;
|
||||||
|
import android.nfc.Tag;
|
||||||
|
import android.nfc.ILlcpSocket;
|
||||||
|
import android.nfc.ILlcpServiceSocket;
|
||||||
|
import android.nfc.ILlcpConnectionlessSocket;
|
||||||
|
import android.nfc.INfcTag;
|
||||||
|
import android.nfc.IP2pTarget;
|
||||||
|
import android.nfc.IP2pInitiator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
interface INfcAdapter
|
||||||
|
{
|
||||||
|
ILlcpSocket getLlcpInterface();
|
||||||
|
ILlcpConnectionlessSocket getLlcpConnectionlessInterface();
|
||||||
|
ILlcpServiceSocket getLlcpServiceInterface();
|
||||||
|
INfcTag getNfcTagInterface();
|
||||||
|
IP2pTarget getP2pTargetInterface();
|
||||||
|
IP2pInitiator getP2pInitiatorInterface();
|
||||||
|
|
||||||
|
// NfcAdapter-class related methods
|
||||||
|
boolean isEnabled();
|
||||||
|
NdefMessage localGet();
|
||||||
|
void localSet(in NdefMessage message);
|
||||||
|
void openTagConnection(in Tag tag);
|
||||||
|
|
||||||
|
// Non-public methods
|
||||||
|
// TODO: check and complete
|
||||||
|
int createLlcpConnectionlessSocket(int sap);
|
||||||
|
int createLlcpServiceSocket(int sap, String sn, int miu, int rw, int linearBufferLength);
|
||||||
|
int createLlcpSocket(int sap, int miu, int rw, int linearBufferLength);
|
||||||
|
int deselectSecureElement();
|
||||||
|
boolean disable();
|
||||||
|
boolean enable();
|
||||||
|
String getProperties(String param);
|
||||||
|
int[] getSecureElementList();
|
||||||
|
int getSelectedSecureElement();
|
||||||
|
int selectSecureElement(int seId);
|
||||||
|
int setProperties(String param, String value);
|
||||||
|
}
|
||||||
@@ -14,18 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android;
|
package android.nfc;
|
||||||
|
|
||||||
import com.trustedlogic.trustednfc.android.NdefMessage;
|
import android.nfc.NdefMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* @hide
|
||||||
*
|
|
||||||
* {@hide}
|
|
||||||
*/
|
*/
|
||||||
interface INfcTag
|
interface INfcTag
|
||||||
{
|
{
|
||||||
|
|
||||||
int close(int nativeHandle);
|
int close(int nativeHandle);
|
||||||
int connect(int nativeHandle);
|
int connect(int nativeHandle);
|
||||||
String getType(int nativeHandle);
|
String getType(int nativeHandle);
|
||||||
@@ -33,6 +30,10 @@ interface INfcTag
|
|||||||
boolean isNdef(int nativeHandle);
|
boolean isNdef(int nativeHandle);
|
||||||
byte[] transceive(int nativeHandle, in byte[] data);
|
byte[] transceive(int nativeHandle, in byte[] data);
|
||||||
|
|
||||||
|
int getLastError(int nativeHandle);
|
||||||
|
|
||||||
NdefMessage read(int nativeHandle);
|
NdefMessage read(int nativeHandle);
|
||||||
boolean write(int nativeHandle, in NdefMessage msg);
|
int write(int nativeHandle, in NdefMessage msg);
|
||||||
|
int makeReadOnly(int nativeHandle);
|
||||||
|
int getModeHint(int nativeHandle);
|
||||||
}
|
}
|
||||||
@@ -14,19 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android;
|
package android.nfc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* @hide
|
||||||
*
|
|
||||||
* {@hide}
|
|
||||||
*/
|
*/
|
||||||
interface IP2pInitiator
|
interface IP2pInitiator
|
||||||
{
|
{
|
||||||
|
|
||||||
byte[] getGeneralBytes(int nativeHandle);
|
byte[] getGeneralBytes(int nativeHandle);
|
||||||
int getMode(int nativeHandle);
|
int getMode(int nativeHandle);
|
||||||
byte[] receive(int nativeHandle);
|
byte[] receive(int nativeHandle);
|
||||||
boolean send(int nativeHandle, in byte[] data);
|
boolean send(int nativeHandle, in byte[] data);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -14,20 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android;
|
package android.nfc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* @hide
|
||||||
*
|
|
||||||
* {@hide}
|
|
||||||
*/
|
*/
|
||||||
interface IP2pTarget
|
interface IP2pTarget
|
||||||
{
|
{
|
||||||
|
|
||||||
byte[] getGeneralBytes(int nativeHandle);
|
byte[] getGeneralBytes(int nativeHandle);
|
||||||
int getMode(int nativeHandle);
|
int getMode(int nativeHandle);
|
||||||
int connect(int nativeHandle);
|
int connect(int nativeHandle);
|
||||||
boolean disconnect(int nativeHandle);
|
boolean disconnect(int nativeHandle);
|
||||||
byte[] transceive(int nativeHandle, in byte[] data);
|
byte[] transceive(int nativeHandle, in byte[] data);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android;
|
package android.nfc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
parcelable LlcpPacket;
|
parcelable LlcpPacket;
|
||||||
@@ -14,33 +14,57 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
package android.nfc;
|
||||||
* File : LLCPPacket.java
|
|
||||||
* Original-Author : Trusted Logic S.A. (Daniel Tomas)
|
|
||||||
* Created : 25-02-2010
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android;
|
|
||||||
|
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a LLCP packet received in a LLCP Connectionless communication;
|
* Represents a LLCP packet received in a LLCP Connectionless communication;
|
||||||
*
|
|
||||||
* @since AA02.01
|
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public class LlcpPacket implements Parcelable {
|
public class LlcpPacket implements Parcelable {
|
||||||
|
|
||||||
private int mRemoteSap;
|
private final int mRemoteSap;
|
||||||
|
|
||||||
private byte[] mDataBuffer;
|
private final byte[] mDataBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creator class, needed when implementing from Parcelable
|
* Creates a LlcpPacket to be sent to a remote Service Access Point number
|
||||||
* {@hide}
|
* (SAP)
|
||||||
|
*
|
||||||
|
* @param sap Remote Service Access Point number
|
||||||
|
* @param data Data buffer
|
||||||
*/
|
*/
|
||||||
|
public LlcpPacket(int sap, byte[] data) {
|
||||||
|
mRemoteSap = sap;
|
||||||
|
mDataBuffer = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the remote Service Access Point number
|
||||||
|
*/
|
||||||
|
public int getRemoteSap() {
|
||||||
|
return mRemoteSap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the data buffer
|
||||||
|
*/
|
||||||
|
public byte[] getDataBuffer() {
|
||||||
|
return mDataBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeInt(mRemoteSap);
|
||||||
|
dest.writeInt(mDataBuffer.length);
|
||||||
|
dest.writeByteArray(mDataBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
public static final Parcelable.Creator<LlcpPacket> CREATOR = new Parcelable.Creator<LlcpPacket>() {
|
public static final Parcelable.Creator<LlcpPacket> CREATOR = new Parcelable.Creator<LlcpPacket>() {
|
||||||
public LlcpPacket createFromParcel(Parcel in) {
|
public LlcpPacket createFromParcel(Parcel in) {
|
||||||
// Remote SAP
|
// Remote SAP
|
||||||
@@ -58,62 +82,4 @@ public class LlcpPacket implements Parcelable {
|
|||||||
return new LlcpPacket[size];
|
return new LlcpPacket[size];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a LlcpPacket to be sent to a remote Service Access Point number
|
|
||||||
* (SAP)
|
|
||||||
*
|
|
||||||
* @param sap Remote Service Access Point number
|
|
||||||
* @param data Data buffer
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public LlcpPacket(int sap, byte[] data) {
|
|
||||||
mRemoteSap = sap;
|
|
||||||
mDataBuffer = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public LlcpPacket() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the remote Service Access Point number
|
|
||||||
*
|
|
||||||
* @return remoteSap
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public int getRemoteSap() {
|
|
||||||
return mRemoteSap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the data buffer
|
|
||||||
*
|
|
||||||
* @return data
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public byte[] getDataBuffer() {
|
|
||||||
return mDataBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (Parcelable) Describe the parcel
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (Parcelable) Convert current object to a Parcel
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
dest.writeInt(mRemoteSap);
|
|
||||||
dest.writeInt(mDataBuffer.length);
|
|
||||||
dest.writeByteArray(mDataBuffer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android;
|
package android.nfc;
|
||||||
|
|
||||||
parcelable NdefMessage;
|
parcelable NdefMessage;
|
||||||
@@ -20,8 +20,6 @@ import android.nfc.NdefRecord;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
import java.lang.UnsupportedOperationException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NDEF Message data.
|
* NDEF Message data.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -29,23 +27,34 @@ import java.lang.UnsupportedOperationException;
|
|||||||
* records.
|
* records.
|
||||||
*/
|
*/
|
||||||
public class NdefMessage implements Parcelable {
|
public class NdefMessage implements Parcelable {
|
||||||
|
private static final byte FLAG_MB = (byte) 0x80;
|
||||||
|
private static final byte FLAG_ME = (byte) 0x40;
|
||||||
|
|
||||||
|
private final NdefRecord[] mRecords;
|
||||||
|
|
||||||
|
//TODO(npelly) FormatException
|
||||||
/**
|
/**
|
||||||
* Create an NDEF message from raw bytes.
|
* Create an NDEF message from raw bytes.
|
||||||
* <p>
|
* <p>
|
||||||
* Validation is performed to make sure the Record format headers are valid,
|
* Validation is performed to make sure the Record format headers are valid,
|
||||||
* and the ID + TYPE + PAYLOAD fields are of the correct size.
|
* and the ID + TYPE + PAYLOAD fields are of the correct size.
|
||||||
|
* @throws FormatException
|
||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public NdefMessage(byte[] data) {
|
public NdefMessage(byte[] data) throws FormatException {
|
||||||
throw new UnsupportedOperationException();
|
mRecords = null; // stop compiler complaints about final field
|
||||||
|
if (parseNdefMessage(data) == -1) {
|
||||||
|
throw new FormatException("Error while parsing NDEF message");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an NDEF message from NDEF records.
|
* Create an NDEF message from NDEF records.
|
||||||
*/
|
*/
|
||||||
public NdefMessage(NdefRecord[] records) {
|
public NdefMessage(NdefRecord[] records) {
|
||||||
throw new UnsupportedOperationException();
|
mRecords = new NdefRecord[records.length];
|
||||||
|
System.arraycopy(records, 0, mRecords, 0, records.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,7 +63,7 @@ public class NdefMessage implements Parcelable {
|
|||||||
* @return array of zero or more NDEF records.
|
* @return array of zero or more NDEF records.
|
||||||
*/
|
*/
|
||||||
public NdefRecord[] getRecords() {
|
public NdefRecord[] getRecords() {
|
||||||
throw new UnsupportedOperationException();
|
return mRecords.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,26 +73,62 @@ public class NdefMessage implements Parcelable {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public byte[] toByteArray() {
|
public byte[] toByteArray() {
|
||||||
throw new UnsupportedOperationException();
|
//TODO(nxp): do not return null
|
||||||
|
//TODO(nxp): allocate the byte array once, copy each record once
|
||||||
|
//TODO(nxp): process MB and ME flags outside loop
|
||||||
|
if ((mRecords == null) || (mRecords.length == 0))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
byte[] msg = {};
|
||||||
|
|
||||||
|
for (int i = 0; i < mRecords.length; i++) {
|
||||||
|
byte[] record = mRecords[i].toByteArray();
|
||||||
|
byte[] tmp = new byte[msg.length + record.length];
|
||||||
|
|
||||||
|
/* Make sure the Message Begin flag is set only for the first record */
|
||||||
|
if (i == 0) {
|
||||||
|
record[0] |= FLAG_MB;
|
||||||
|
} else {
|
||||||
|
record[0] &= ~FLAG_MB;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make sure the Message End flag is set only for the last record */
|
||||||
|
if (i == (mRecords.length - 1)) {
|
||||||
|
record[0] |= FLAG_ME;
|
||||||
|
} else {
|
||||||
|
record[0] &= ~FLAG_ME;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.arraycopy(msg, 0, tmp, 0, msg.length);
|
||||||
|
System.arraycopy(record, 0, tmp, msg.length, record.length);
|
||||||
|
|
||||||
|
msg = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
throw new UnsupportedOperationException();
|
dest.writeInt(mRecords.length);
|
||||||
|
dest.writeTypedArray(mRecords, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Parcelable.Creator<NdefMessage> CREATOR =
|
public static final Parcelable.Creator<NdefMessage> CREATOR =
|
||||||
new Parcelable.Creator<NdefMessage>() {
|
new Parcelable.Creator<NdefMessage>() {
|
||||||
public NdefMessage createFromParcel(Parcel in) {
|
public NdefMessage createFromParcel(Parcel in) {
|
||||||
throw new UnsupportedOperationException();
|
int recordsLength = in.readInt();
|
||||||
|
NdefRecord[] records = new NdefRecord[recordsLength];
|
||||||
|
in.readTypedArray(records, NdefRecord.CREATOR);
|
||||||
|
return new NdefMessage(records);
|
||||||
}
|
}
|
||||||
public NdefMessage[] newArray(int size) {
|
public NdefMessage[] newArray(int size) {
|
||||||
throw new UnsupportedOperationException();
|
return new NdefMessage[size];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private native int parseNdefMessage(byte[] data);
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android;
|
package android.nfc;
|
||||||
|
|
||||||
parcelable NdefRecord;
|
parcelable NdefRecord;
|
||||||
@@ -138,6 +138,18 @@ public class NdefRecord implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public static final byte[] RTD_HANDOVER_SELECT = {0x48, 0x73}; // "Hs"
|
public static final byte[] RTD_HANDOVER_SELECT = {0x48, 0x73}; // "Hs"
|
||||||
|
|
||||||
|
private static final byte FLAG_MB = (byte) 0x80;
|
||||||
|
private static final byte FLAG_ME = (byte) 0x40;
|
||||||
|
private static final byte FLAG_CF = (byte) 0x20;
|
||||||
|
private static final byte FLAG_SR = (byte) 0x10;
|
||||||
|
private static final byte FLAG_IL = (byte) 0x08;
|
||||||
|
|
||||||
|
private final byte mFlags;
|
||||||
|
private final short mTnf;
|
||||||
|
private final byte[] mType;
|
||||||
|
private final byte[] mId;
|
||||||
|
private final byte[] mPayload;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an NDEF Record.
|
* Construct an NDEF Record.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -153,7 +165,29 @@ public class NdefRecord implements Parcelable {
|
|||||||
* must not be null
|
* must not be null
|
||||||
*/
|
*/
|
||||||
public NdefRecord(short tnf, byte[] type, byte[] id, byte[] payload) {
|
public NdefRecord(short tnf, byte[] type, byte[] id, byte[] payload) {
|
||||||
throw new UnsupportedOperationException();
|
/* check arguments */
|
||||||
|
if ((type == null) || (id == null) || (payload == null)) {
|
||||||
|
throw new IllegalArgumentException("Illegal null argument");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* generate flag */
|
||||||
|
byte flags = FLAG_MB | FLAG_ME;
|
||||||
|
|
||||||
|
/* Determine if it is a short record */
|
||||||
|
if(payload.length < 0xFF) {
|
||||||
|
flags |= FLAG_SR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Determine if an id is present */
|
||||||
|
if(id.length != 0) {
|
||||||
|
flags |= FLAG_IL;
|
||||||
|
}
|
||||||
|
|
||||||
|
mFlags = flags;
|
||||||
|
mTnf = tnf;
|
||||||
|
mType = type.clone();
|
||||||
|
mId = id.clone();
|
||||||
|
mPayload = payload.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -174,7 +208,7 @@ public class NdefRecord implements Parcelable {
|
|||||||
* TNF is the top-level type.
|
* TNF is the top-level type.
|
||||||
*/
|
*/
|
||||||
public short getTnf() {
|
public short getTnf() {
|
||||||
throw new UnsupportedOperationException();
|
return mTnf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -184,21 +218,21 @@ public class NdefRecord implements Parcelable {
|
|||||||
* payload format.
|
* payload format.
|
||||||
*/
|
*/
|
||||||
public byte[] getType() {
|
public byte[] getType() {
|
||||||
throw new UnsupportedOperationException();
|
return mType.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the variable length ID.
|
* Returns the variable length ID.
|
||||||
*/
|
*/
|
||||||
public byte[] getId() {
|
public byte[] getId() {
|
||||||
throw new UnsupportedOperationException();
|
return mId.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the variable length payload.
|
* Returns the variable length payload.
|
||||||
*/
|
*/
|
||||||
public byte[] getPayload() {
|
public byte[] getPayload() {
|
||||||
throw new UnsupportedOperationException();
|
return mPayload.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,26 +240,43 @@ public class NdefRecord implements Parcelable {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public byte[] toByteArray() {
|
public byte[] toByteArray() {
|
||||||
throw new UnsupportedOperationException();
|
return generate(mFlags, mTnf, mType, mId, mPayload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
throw new UnsupportedOperationException();
|
dest.writeInt(mTnf);
|
||||||
|
dest.writeInt(mType.length);
|
||||||
|
dest.writeByteArray(mType);
|
||||||
|
dest.writeInt(mId.length);
|
||||||
|
dest.writeByteArray(mId);
|
||||||
|
dest.writeInt(mPayload.length);
|
||||||
|
dest.writeByteArray(mPayload);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Parcelable.Creator<NdefRecord> CREATOR =
|
public static final Parcelable.Creator<NdefRecord> CREATOR =
|
||||||
new Parcelable.Creator<NdefRecord>() {
|
new Parcelable.Creator<NdefRecord>() {
|
||||||
public NdefRecord createFromParcel(Parcel in) {
|
public NdefRecord createFromParcel(Parcel in) {
|
||||||
throw new UnsupportedOperationException();
|
short tnf = (short)in.readInt();
|
||||||
|
int typeLength = in.readInt();
|
||||||
|
byte[] type = new byte[typeLength];
|
||||||
|
in.readByteArray(type);
|
||||||
|
int idLength = in.readInt();
|
||||||
|
byte[] id = new byte[idLength];
|
||||||
|
in.readByteArray(id);
|
||||||
|
int payloadLength = in.readInt();
|
||||||
|
byte[] payload = new byte[payloadLength];
|
||||||
|
in.readByteArray(payload);
|
||||||
|
|
||||||
|
return new NdefRecord(tnf, type, id, payload);
|
||||||
}
|
}
|
||||||
public NdefRecord[] newArray(int size) {
|
public NdefRecord[] newArray(int size) {
|
||||||
throw new UnsupportedOperationException();
|
return new NdefRecord[size];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private native byte[] generate(short flags, short tnf, byte[] type, byte[] id, byte[] data);
|
||||||
}
|
}
|
||||||
19
core/java/android/nfc/NdefTag.aidl
Normal file
19
core/java/android/nfc/NdefTag.aidl
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
parcelable NdefTag;
|
||||||
118
core/java/android/nfc/NdefTag.java
Normal file
118
core/java/android/nfc/NdefTag.java
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NdefTag is a Tag that has NDEF messages or can store NDEF messages.
|
||||||
|
* <p>
|
||||||
|
* NDEF Tag's contain zero or more NDEF Messages in addition to the basic
|
||||||
|
* Tag properties of UID and Type.
|
||||||
|
* <p>
|
||||||
|
* NDEF Tag's that have been initialized will usually contain a single NDEF
|
||||||
|
* Message (and that Message can contain multiple NDEF Records). However it
|
||||||
|
* is possible for NDEF Tag's to contain multiple NDEF Messages.
|
||||||
|
* <p>
|
||||||
|
* This class is a immutable data class that contains the contents of the NDEF
|
||||||
|
* Message(s) as read at Tag discovery time.
|
||||||
|
* <p>
|
||||||
|
* NfcAdapter.createNdefTagConnection() can be used to modify the contents of
|
||||||
|
* some NDEF Tag's.
|
||||||
|
*/
|
||||||
|
public class NdefTag extends Tag implements Parcelable {
|
||||||
|
private final NdefMessage[] mMessages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hidden constructor to be used by NFC service when a
|
||||||
|
* tag is discovered and by Parcelable methods.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public NdefTag(int type, byte[] uid, int nativeHandle, NdefMessage[] messages) {
|
||||||
|
super(type, true, uid, nativeHandle);
|
||||||
|
mMessages = messages.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all NDEF Messages.
|
||||||
|
* <p>
|
||||||
|
* This retrieves the NDEF Messages that were found on the Tag at discovery
|
||||||
|
* time. It does not cause any further RF activity, and does not block.
|
||||||
|
* <p>
|
||||||
|
* Most tags only contain a single NDEF message.
|
||||||
|
*
|
||||||
|
* @return NDEF Messages found at Tag discovery
|
||||||
|
*/
|
||||||
|
public NdefMessage[] getNdefMessages() {
|
||||||
|
return mMessages.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get only the NDEF Messages from a single NDEF target on a tag.
|
||||||
|
*/
|
||||||
|
public NdefMessage[] getNdefMessages(String target) {
|
||||||
|
//TODO(nxp): new api method
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** TODO(npelly):
|
||||||
|
* - check that any single tag can only have one of each NDEF type
|
||||||
|
* - ok to include mifare_classic?
|
||||||
|
*/
|
||||||
|
public static final String TARGET_TYPE_1 = "type_1";
|
||||||
|
public static final String TARGET_TYPE_2 = "type_2";
|
||||||
|
public static final String TARGET_TYPE_3 = "type_3";
|
||||||
|
public static final String TARGET_TYPE_4 = "type_4";
|
||||||
|
public static final String TARGET_MIFARE_CLASSIC = "type_mifare_classic";
|
||||||
|
public static final String TARGET_OTHER = "other";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String[] getNdefTargets() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
super.writeToParcel(dest, flags);
|
||||||
|
dest.writeInt(mMessages.length);
|
||||||
|
dest.writeTypedArray(mMessages, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator<NdefTag> CREATOR =
|
||||||
|
new Parcelable.Creator<NdefTag>() {
|
||||||
|
public NdefTag createFromParcel(Parcel in) {
|
||||||
|
Tag tag = Tag.CREATOR.createFromParcel(in);
|
||||||
|
int messagesLength = in.readInt();
|
||||||
|
NdefMessage[] messages = new NdefMessage[messagesLength];
|
||||||
|
in.readTypedArray(messages, NdefMessage.CREATOR);
|
||||||
|
return new NdefTag(tag.mType, tag.mUid, tag.mNativeHandle, messages);
|
||||||
|
}
|
||||||
|
public NdefTag[] newArray(int size) {
|
||||||
|
return new NdefTag[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
167
core/java/android/nfc/NdefTagConnection.java
Normal file
167
core/java/android/nfc/NdefTagConnection.java
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import android.os.RemoteException;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NdefTagConnection is a connection to an NDEF target on an NDEF tag.
|
||||||
|
*/
|
||||||
|
public class NdefTagConnection extends RawTagConnection {
|
||||||
|
public static final int NDEF_MODE_READ_ONCE = 1;
|
||||||
|
public static final int NDEF_MODE_READ_ONLY = 2;
|
||||||
|
public static final int NDEF_MODE_WRITE_ONCE = 3;
|
||||||
|
public static final int NDEF_MODE_WRITE_MANY = 4;
|
||||||
|
public static final int NDEF_MODE_UNKNOWN = 5;
|
||||||
|
|
||||||
|
private static final String TAG = "NFC";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal constructor, to be used by NfcAdapter
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
NdefTagConnection(INfcAdapter service, NdefTag tag) throws RemoteException {
|
||||||
|
super(service, tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read NDEF message(s).
|
||||||
|
* This will always return the most up to date payload, and can block.
|
||||||
|
* It can be canceled with close().
|
||||||
|
* Most NDEF tags will contain just one NDEF message.
|
||||||
|
* <p>
|
||||||
|
* @throws FormatException if the tag is not NDEF formatted
|
||||||
|
* @throws IOException if the target is lost or connection closed
|
||||||
|
* @throws FormatException
|
||||||
|
*/
|
||||||
|
public NdefMessage[] readNdefMessages() throws IOException, FormatException {
|
||||||
|
//TODO(nxp): do not use getLastError(), it is racy
|
||||||
|
try {
|
||||||
|
NdefMessage[] msgArray = new NdefMessage[1];
|
||||||
|
NdefMessage msg = mTagService.read(mTag.mNativeHandle);
|
||||||
|
if (msg == null) {
|
||||||
|
int errorCode = mTagService.getLastError(mTag.mNativeHandle);
|
||||||
|
switch (errorCode) {
|
||||||
|
case ErrorCodes.ERROR_IO:
|
||||||
|
throw new IOException();
|
||||||
|
case ErrorCodes.ERROR_INVALID_PARAM:
|
||||||
|
throw new FormatException();
|
||||||
|
default:
|
||||||
|
// Should not happen
|
||||||
|
throw new IOException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msgArray[0] = msg;
|
||||||
|
return msgArray;
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "NFC service died");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to write an NDEF message to a tag.
|
||||||
|
* This method will block until the data is written. It can be canceled
|
||||||
|
* with close().
|
||||||
|
* Many tags are write-once, so use this method carefully.
|
||||||
|
* Specification allows for multiple NDEF messages per NDEF tag, but it is
|
||||||
|
* encourage to only write one message, this so API only takes a single
|
||||||
|
* message. Use NdefRecord to write several records to a single tag.
|
||||||
|
* For write-many tags, use makeReadOnly() after this method to attempt
|
||||||
|
* to prevent further modification. For write-once tags this is not
|
||||||
|
* neccesary.
|
||||||
|
* Requires NFC_WRITE permission.
|
||||||
|
* @throws FormatException if the tag is not suitable for NDEF messages
|
||||||
|
* @throws IOException if the target is lost or connection closed or the
|
||||||
|
* write failed
|
||||||
|
*/
|
||||||
|
public void writeNdefMessage(NdefMessage message) throws IOException, FormatException {
|
||||||
|
try {
|
||||||
|
int errorCode = mTagService.write(mTag.mNativeHandle, message);
|
||||||
|
switch (errorCode) {
|
||||||
|
case ErrorCodes.SUCCESS:
|
||||||
|
break;
|
||||||
|
case ErrorCodes.ERROR_IO:
|
||||||
|
throw new IOException();
|
||||||
|
case ErrorCodes.ERROR_INVALID_PARAM:
|
||||||
|
throw new FormatException();
|
||||||
|
default:
|
||||||
|
// Should not happen
|
||||||
|
throw new IOException();
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "NFC service died");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to make the NDEF data in this tag read-only.
|
||||||
|
* This method will block until the action is complete. It can be canceled
|
||||||
|
* with close().
|
||||||
|
* Requires NFC_WRITE permission.
|
||||||
|
* @return true if the tag is now read-only
|
||||||
|
* @throws IOException if the target is lost, or connection closed
|
||||||
|
*/
|
||||||
|
public boolean makeReadOnly() throws IOException {
|
||||||
|
try {
|
||||||
|
int errorCode = mTagService.makeReadOnly(mTag.mNativeHandle);
|
||||||
|
switch (errorCode) {
|
||||||
|
case ErrorCodes.SUCCESS:
|
||||||
|
return true;
|
||||||
|
case ErrorCodes.ERROR_IO:
|
||||||
|
throw new IOException();
|
||||||
|
case ErrorCodes.ERROR_INVALID_PARAM:
|
||||||
|
return false;
|
||||||
|
default:
|
||||||
|
// Should not happen
|
||||||
|
throw new IOException();
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "NFC service died");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read/Write mode hint.
|
||||||
|
* Provides a hint if further reads or writes are likely to suceed.
|
||||||
|
* @return one of NDEF_MODE
|
||||||
|
* @throws IOException if the target is lost or connection closed
|
||||||
|
*/
|
||||||
|
public int getModeHint() throws IOException {
|
||||||
|
try {
|
||||||
|
int result = mTagService.getModeHint(mTag.mNativeHandle);
|
||||||
|
if (ErrorCodes.isError(result)) {
|
||||||
|
switch (result) {
|
||||||
|
case ErrorCodes.ERROR_IO:
|
||||||
|
throw new IOException();
|
||||||
|
default:
|
||||||
|
// Should not happen
|
||||||
|
throw new IOException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "NFC service died");
|
||||||
|
return NDEF_MODE_UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
302
core/java/android/nfc/NfcAdapter.java
Normal file
302
core/java/android/nfc/NfcAdapter.java
Normal file
@@ -0,0 +1,302 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.lang.UnsupportedOperationException;
|
||||||
|
|
||||||
|
import android.annotation.SdkConstant;
|
||||||
|
import android.annotation.SdkConstant.SdkConstantType;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.nfc.INfcAdapter;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
import android.os.ServiceManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
//TODO(npelly) permission {@link android.Manifest.permission#NFC_MODIFY}
|
||||||
|
/**
|
||||||
|
* Represents a local NFC Adapter.
|
||||||
|
* <p>
|
||||||
|
* Use the static {@link #getDefaultAdapter} method to get the default NFC
|
||||||
|
* Adapter for this Android device. Most Android devices will have only one NFC
|
||||||
|
* Adapter, and {@link #getDefaultAdapter} returns the singleton object.
|
||||||
|
* <p>
|
||||||
|
* {@link NfcAdapter} can be used to create {@link RawTagConnection} or
|
||||||
|
* {@link NdefTagConnection} connections to modify or perform low level access
|
||||||
|
* to NFC Tags.
|
||||||
|
* <p class="note">
|
||||||
|
* <strong>Note:</strong> Some methods require the
|
||||||
|
* TODO permission.
|
||||||
|
*/
|
||||||
|
public final class NfcAdapter {
|
||||||
|
/**
|
||||||
|
* Intent to start an activity when a non-NDEF tag is discovered.
|
||||||
|
* TODO(npelly) finalize decision on using CATEGORY or DATA URI to provide a
|
||||||
|
* hint for applications to filter the tag type.
|
||||||
|
* TODO(npelly) probably combine these two intents since tags aren't that simple
|
||||||
|
*/
|
||||||
|
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
|
||||||
|
public static final String ACTION_TAG_DISCOVERED = "android.nfc.action.TAG_DISCOVERED";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Intent to start an activity when a NDEF tag is discovered. TODO(npelly)
|
||||||
|
* finalize decision on using CATEGORY or DATA URI to provide a hint for
|
||||||
|
* applications to filter the tag type.
|
||||||
|
*/
|
||||||
|
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
|
||||||
|
public static final String ACTION_NDEF_TAG_DISCOVERED =
|
||||||
|
"android.nfc.action.NDEF_TAG_DISCOVERED";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mandatory Tag extra for the ACTION_TAG and ACTION_NDEF_TAG intents.
|
||||||
|
*/
|
||||||
|
public static final String EXTRA_TAG = "android.nfc.extra.TAG";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Broadcast Action: a transaction with a secure element has been detected.
|
||||||
|
* <p>
|
||||||
|
* Always contains the extra field
|
||||||
|
* {@link android.nfc.NfcAdapter#EXTRA_AID}
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
||||||
|
public static final String ACTION_TRANSACTION_DETECTED =
|
||||||
|
"android.nfc.action.TRANSACTION_DETECTED";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mandatory byte array extra field in
|
||||||
|
* {@link android.nfc.NfcAdapter#ACTION_TRANSACTION_DETECTED}.
|
||||||
|
* <p>
|
||||||
|
* Contains the AID of the applet involved in the transaction.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final String EXTRA_AID = "android.nfc.extra.AID";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LLCP link status: The LLCP link is activated.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int LLCP_LINK_STATE_ACTIVATED = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LLCP link status: The LLCP link is deactivated.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int LLCP_LINK_STATE_DEACTIVATED = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Broadcast Action: the LLCP link state changed.
|
||||||
|
* <p>
|
||||||
|
* Always contains the extra field
|
||||||
|
* {@link android.nfc.NfcAdapter#EXTRA_LLCP_LINK_STATE_CHANGED}.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
||||||
|
public static final String ACTION_LLCP_LINK_STATE_CHANGED =
|
||||||
|
"android.nfc.action.LLCP_LINK_STATE_CHANGED";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used as int extra field in
|
||||||
|
* {@link android.nfc.NfcAdapter#ACTION_LLCP_LINK_STATE_CHANGED}.
|
||||||
|
* <p>
|
||||||
|
* It contains the new state of the LLCP link.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final String EXTRA_LLCP_LINK_STATE_CHANGED = "android.nfc.extra.LLCP_LINK_STATE";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tag Reader Discovery mode
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
private static final int DISCOVERY_MODE_TAG_READER = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NFC-IP1 Peer-to-Peer mode Enables the manager to act as a peer in an
|
||||||
|
* NFC-IP1 communication. Implementations should not assume that the
|
||||||
|
* controller will end up behaving as an NFC-IP1 target or initiator and
|
||||||
|
* should handle both cases, depending on the type of the remote peer type.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
private static final int DISCOVERY_MODE_NFCIP1 = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Card Emulation mode Enables the manager to act as an NFC tag. Provided
|
||||||
|
* that a Secure Element (an UICC for instance) is connected to the NFC
|
||||||
|
* controller through its SWP interface, it can be exposed to the outside
|
||||||
|
* NFC world and be addressed by external readers the same way they would
|
||||||
|
* with a tag.
|
||||||
|
* <p>
|
||||||
|
* Which Secure Element is exposed is implementation-dependent.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
private static final int DISCOVERY_MODE_CARD_EMULATION = 2;
|
||||||
|
|
||||||
|
private static final String TAG = "NFC";
|
||||||
|
|
||||||
|
private static boolean sIsInitialized = false;
|
||||||
|
private static NfcAdapter sAdapter;
|
||||||
|
|
||||||
|
private final INfcAdapter mService;
|
||||||
|
|
||||||
|
private NfcAdapter(INfcAdapter service) {
|
||||||
|
mService = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a handle to the default NFC Adapter on this Android device.
|
||||||
|
* <p>
|
||||||
|
* Most Android devices will only have one NFC Adapter (NFC Controller).
|
||||||
|
*
|
||||||
|
* @return the default NFC adapter, or null if no NFC adapter exists
|
||||||
|
*/
|
||||||
|
public static NfcAdapter getDefaultAdapter() {
|
||||||
|
synchronized (NfcAdapter.class) {
|
||||||
|
if (sIsInitialized) {
|
||||||
|
return sAdapter;
|
||||||
|
}
|
||||||
|
sIsInitialized = true;
|
||||||
|
|
||||||
|
// TODO(npelly): check which method to use here to get the service
|
||||||
|
IBinder b = ServiceManager.getService(Context.NFC_SERVICE);
|
||||||
|
if (b == null) {
|
||||||
|
return null; // This device does not have NFC
|
||||||
|
}
|
||||||
|
|
||||||
|
sAdapter = new NfcAdapter(INfcAdapter.Stub.asInterface(b));
|
||||||
|
return sAdapter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if this NFC Adapter is enabled to discover new tags.
|
||||||
|
* <p>
|
||||||
|
* If this method returns false, then applications should request the user
|
||||||
|
* turn on NFC tag discovery in Settings.
|
||||||
|
*
|
||||||
|
* @return true if this NFC Adapter is enabled to discover new tags
|
||||||
|
*/
|
||||||
|
public boolean isTagDiscoveryEnabled() {
|
||||||
|
try {
|
||||||
|
return mService.isEnabled();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "RemoteException in isEnabled()", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public boolean enableTagDiscovery() {
|
||||||
|
try {
|
||||||
|
return mService.enable();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "RemoteException in enable()", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public boolean disableTagDiscovery() {
|
||||||
|
try {
|
||||||
|
return mService.disable();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "RemoteException in disable()", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the NDEF Message that this NFC adapter should appear as to Tag
|
||||||
|
* readers.
|
||||||
|
* <p>
|
||||||
|
* Any Tag reader can read the contents of the local tag when it is in
|
||||||
|
* proximity, without any further user confirmation.
|
||||||
|
* <p>
|
||||||
|
* The implementation of this method must either
|
||||||
|
* <ul>
|
||||||
|
* <li>act as a passive tag containing this NDEF message
|
||||||
|
* <li>provide the NDEF message on over LLCP to peer NFC adapters
|
||||||
|
* </ul>
|
||||||
|
* The NDEF message is preserved across reboot.
|
||||||
|
* <p>
|
||||||
|
* Requires NFC_WRITE permission
|
||||||
|
*
|
||||||
|
* @param message NDEF message to make public
|
||||||
|
*/
|
||||||
|
public void setLocalNdefMessage(NdefMessage message) {
|
||||||
|
try {
|
||||||
|
mService.localSet(message);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "NFC service died", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the NDEF Message that this adapter appears as to Tag readers.
|
||||||
|
* <p>
|
||||||
|
* Requires NFC_WRITE permission
|
||||||
|
*
|
||||||
|
* @return NDEF Message that is publicly readable
|
||||||
|
*/
|
||||||
|
public NdefMessage getLocalNdefMessage() {
|
||||||
|
try {
|
||||||
|
return mService.localGet();
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "NFC service died", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a raw tag connection to the default Target
|
||||||
|
*/
|
||||||
|
public RawTagConnection createRawTagConnection(Tag tag) {
|
||||||
|
try {
|
||||||
|
return new RawTagConnection(mService, tag);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "NFC service died", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a raw tag connection to the specified Target
|
||||||
|
*/
|
||||||
|
public RawTagConnection createRawTagConnection(Tag tag, String target) {
|
||||||
|
//TODO
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an NDEF tag connection to the default Target
|
||||||
|
*/
|
||||||
|
public NdefTagConnection createNdefTagConnection(NdefTag tag) {
|
||||||
|
try {
|
||||||
|
return new NdefTagConnection(mService, tag);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "NFC service died", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an NDEF tag connection to the specified Target
|
||||||
|
*/
|
||||||
|
public NdefTagConnection createNdefTagConnection(NdefTag tag, String target) {
|
||||||
|
//TODO
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
139
core/java/android/nfc/RawTagConnection.java
Normal file
139
core/java/android/nfc/RawTagConnection.java
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import android.os.RemoteException;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RawTagConnection is a low-level connection to a Tag.
|
||||||
|
* <p>
|
||||||
|
* The only data transfer method that TagConnection offers is transceive().
|
||||||
|
* Applications must implement there own protocol stack on top of transceive().
|
||||||
|
* <p>
|
||||||
|
* Use NfcAdapter.createRawTagConnection() to create a RawTagConnection object.
|
||||||
|
*
|
||||||
|
* * <p class="note"><strong>Note:</strong>
|
||||||
|
* Most methods require the {@link android.Manifest.permission#BLUETOOTH}
|
||||||
|
* permission and some also require the
|
||||||
|
* {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
|
||||||
|
|
||||||
|
*/
|
||||||
|
public class RawTagConnection {
|
||||||
|
|
||||||
|
/*package*/ final INfcAdapter mService;
|
||||||
|
/*package*/ final INfcTag mTagService;
|
||||||
|
/*package*/ final Tag mTag;
|
||||||
|
/*package*/ boolean mIsConnected;
|
||||||
|
|
||||||
|
private static final String TAG = "NFC";
|
||||||
|
|
||||||
|
/* package private */ RawTagConnection(INfcAdapter service, Tag tag) throws RemoteException {
|
||||||
|
mService = service;
|
||||||
|
mTagService = service.getNfcTagInterface();
|
||||||
|
mService.openTagConnection(tag); // TODO(nxp): don't connect until connect()
|
||||||
|
mTag = tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Tag this connection is associated with.
|
||||||
|
*/
|
||||||
|
public Tag getTag() {
|
||||||
|
return mTag;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTagTarget() {
|
||||||
|
//TODO
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to indicate if transceive() calls might succeed.
|
||||||
|
* <p>
|
||||||
|
* Does not cause RF activity, and does not block.
|
||||||
|
* <p>
|
||||||
|
* Returns true if connect() has completed successfully, and the Tag is not
|
||||||
|
* yet known to be out of range. Applications must still handle IOException
|
||||||
|
* while using transceive().
|
||||||
|
*/
|
||||||
|
public boolean isConnected() {
|
||||||
|
// TODO(nxp): update mIsConnected when tag goes out of range -
|
||||||
|
// but do not do an active prescence check in
|
||||||
|
// isConnected()
|
||||||
|
return mIsConnected;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect to tag.
|
||||||
|
* <p>
|
||||||
|
* This method blocks until the connection is established.
|
||||||
|
* <p>
|
||||||
|
* close() can be called from another thread to cancel this connection
|
||||||
|
* attempt.
|
||||||
|
*
|
||||||
|
* @throws IOException if the target is lost, or connect canceled
|
||||||
|
*/
|
||||||
|
public void connect() throws IOException {
|
||||||
|
//TODO(nxp): enforce exclusivity
|
||||||
|
mIsConnected = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close tag connection.
|
||||||
|
* <p>
|
||||||
|
* Causes blocking operations such as transceive() or connect() to
|
||||||
|
* be canceled and immediately throw IOException.
|
||||||
|
* <p>
|
||||||
|
* This object cannot be re-used after calling close(). Further calls
|
||||||
|
* to transceive() or connect() will fail.
|
||||||
|
*/
|
||||||
|
public void close() {
|
||||||
|
mIsConnected = false;
|
||||||
|
try {
|
||||||
|
mTagService.close(mTag.mNativeHandle);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "NFC service died", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send data to a tag, and return the response.
|
||||||
|
* <p>
|
||||||
|
* This method will block until the response is received. It can be canceled
|
||||||
|
* with close().
|
||||||
|
* <p>
|
||||||
|
* Requires NFC_WRITE permission.
|
||||||
|
*
|
||||||
|
* @param data bytes to send
|
||||||
|
* @return bytes received in response
|
||||||
|
* @throws IOException if the target is lost or connection closed
|
||||||
|
*/
|
||||||
|
public byte[] transceive(byte[] data) throws IOException {
|
||||||
|
try {
|
||||||
|
byte[] response = mTagService.transceive(mTag.mNativeHandle, data);
|
||||||
|
if (response == null) {
|
||||||
|
throw new IOException("transcieve failed");
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "NFC service died", e);
|
||||||
|
throw new IOException("NFC service died");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
core/java/android/nfc/Tag.aidl
Normal file
19
core/java/android/nfc/Tag.aidl
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
parcelable Tag;
|
||||||
215
core/java/android/nfc/Tag.java
Normal file
215
core/java/android/nfc/Tag.java
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Immutable data class, represents a discovered tag.
|
||||||
|
* <p>
|
||||||
|
* A tag is a passive NFC element, such as NFC Forum Tag's, Mifare class Tags,
|
||||||
|
* Sony Felica Tags.
|
||||||
|
* <p>
|
||||||
|
* Tag's have a type and usually have a UID.
|
||||||
|
* <p>
|
||||||
|
* Tag objects are passed to applications via the NfcAdapter.EXTRA_TAG extra
|
||||||
|
* in NfcAdapter.ACTION_TAG_DISCOVERED intents. The Tag object is immutable
|
||||||
|
* and represents the state of the Tag at the time of discovery. It can be
|
||||||
|
* directly queried for its UID and Type, or used to create a TagConnection
|
||||||
|
* (NfcAdapter.createTagConnection()).
|
||||||
|
* <p>
|
||||||
|
* This Tag object can only be used to create a TagConnection while it is in
|
||||||
|
* range. If it is removed and then returned to range then the most recent
|
||||||
|
* Tag object (in ACTION_TAG_DISCOVERED) should be used to create a
|
||||||
|
* TagConnection.
|
||||||
|
*/
|
||||||
|
public class Tag implements Parcelable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int NFC_TAG_ISO14443_A = 1; /* phNfc_eISO14443_A_PICC */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int NFC_TAG_ISO14443_4A = 2; /* phNfc_eISO14443_4A_PICC */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int NFC_TAG_ISO14443_3A = 3; /* phNfc_eISO14443_3A_PICC */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int NFC_TAG_MIFARE = 4; /* phNfc_eMifare_PICC */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int NFC_TAG_ISO14443_B = 5; /* phNfc_eISO14443_B_PICC */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int NFC_TAG_ISO14443_4B = 6; /* phNfc_eISO14443_4B_PICC */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int NFC_TAG_ISO14443_B_PRIME = 7; /* phNfc_eISO14443_BPrime_PICC */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int NFC_TAG_FELICA = 8; /* phNfc_eFelica_PICC */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int NFC_TAG_JEWEL = 9; /* phNfc_eJewel_PICC */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int NFC_TAG_ISO15693 = 10; /* phNfc_eISO15693_PICC */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int NFC_TAG_OTHER = 11; /* phNfc_ePICC_DevType */
|
||||||
|
|
||||||
|
|
||||||
|
public static final String TARGET_ISO_14443_3A = "iso14443_3a";
|
||||||
|
|
||||||
|
public static final String TARGET_ISO_14443_3B = "iso14443_3b";
|
||||||
|
|
||||||
|
public static final String TARGET_ISO_14443_3B_PRIME = "iso14443_3b";
|
||||||
|
|
||||||
|
public static final String TARGET_ISO_14443_4 = "iso14443_4";
|
||||||
|
|
||||||
|
public static final String TARGET_ISO_15693 = "iso15693";
|
||||||
|
|
||||||
|
public static final String TARGET_JIS_X_6319_4 = "jis_x_6319_4";
|
||||||
|
|
||||||
|
public static final String TARGET_TOPAZ = "topaz";
|
||||||
|
|
||||||
|
public static final String TARGET_OTHER = "other";
|
||||||
|
|
||||||
|
/*package*/ final int mType;
|
||||||
|
/*package*/ final boolean mIsNdef;
|
||||||
|
/*package*/ final byte[] mUid;
|
||||||
|
/*package*/ final int mNativeHandle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hidden constructor to be used by NFC service only.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public Tag(int type, boolean isNdef, byte[] uid, int nativeHandle) {
|
||||||
|
mType = type;
|
||||||
|
mIsNdef = isNdef;
|
||||||
|
mUid = uid.clone();
|
||||||
|
mNativeHandle = nativeHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For use by NfcService only.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public int getHandle() {
|
||||||
|
return mNativeHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the available targets that this NFC adapter can use to create
|
||||||
|
* a RawTagConnection.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String[] getRawTargets() {
|
||||||
|
//TODO
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Tag type.
|
||||||
|
* <p>
|
||||||
|
* The Tag type is one of the NFC_TAG constants. It is read at discovery
|
||||||
|
* time and this method does not cause any further RF activity and does not
|
||||||
|
* block.
|
||||||
|
*
|
||||||
|
* @return a NFC_TAG constant
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public int getType() {
|
||||||
|
return mType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Tag Identifier (if it has one).
|
||||||
|
* <p>
|
||||||
|
* Tag ID is usually a serial number for the tag.
|
||||||
|
* <p>
|
||||||
|
* The Tag ID is read at discovery time and this method does not cause any
|
||||||
|
* further RF activity and does not block.
|
||||||
|
*
|
||||||
|
* @return ID, or null if it does not exist
|
||||||
|
*/
|
||||||
|
public byte[] getId() {
|
||||||
|
if (mUid.length > 0) {
|
||||||
|
return mUid.clone();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
boolean[] booleans = new boolean[] {mIsNdef};
|
||||||
|
dest.writeInt(mType);
|
||||||
|
dest.writeBooleanArray(booleans);
|
||||||
|
dest.writeInt(mUid.length);
|
||||||
|
dest.writeByteArray(mUid);
|
||||||
|
dest.writeInt(mNativeHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator<Tag> CREATOR =
|
||||||
|
new Parcelable.Creator<Tag>() {
|
||||||
|
public Tag createFromParcel(Parcel in) {
|
||||||
|
boolean[] booleans = new boolean[1];
|
||||||
|
int type = in.readInt();
|
||||||
|
in.readBooleanArray(booleans);
|
||||||
|
boolean isNdef = booleans[0];
|
||||||
|
int uidLength = in.readInt();
|
||||||
|
byte[] uid = new byte[uidLength];
|
||||||
|
in.readByteArray(uid);
|
||||||
|
int nativeHandle = in.readInt();
|
||||||
|
|
||||||
|
return new Tag(type, isNdef, uid, nativeHandle);
|
||||||
|
}
|
||||||
|
public Tag[] newArray(int size) {
|
||||||
|
return new Tag[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 com.trustedlogic.trustednfc.android;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO
|
|
||||||
*
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
interface ILlcpSocket
|
|
||||||
{
|
|
||||||
|
|
||||||
int close(int nativeHandle);
|
|
||||||
int connect(int nativeHandle, int sap);
|
|
||||||
int connectByName(int nativeHandle, String sn);
|
|
||||||
int getConnectTimeout(int nativeHandle);
|
|
||||||
int getLocalSap(int nativeHandle);
|
|
||||||
int getLocalSocketMiu(int nativeHandle);
|
|
||||||
int getLocalSocketRw(int nativeHandle);
|
|
||||||
int getRemoteSocketMiu(int nativeHandle);
|
|
||||||
int getRemoteSocketRw(int nativeHandle);
|
|
||||||
int receive(int nativeHandle, out byte[] receiveBuffer);
|
|
||||||
int send(int nativeHandle, in byte[] data);
|
|
||||||
void setConnectTimeout(int nativeHandle, int timeout);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 com.trustedlogic.trustednfc.android;
|
|
||||||
|
|
||||||
import com.trustedlogic.trustednfc.android.ILlcpSocket;
|
|
||||||
import com.trustedlogic.trustednfc.android.ILlcpServiceSocket;
|
|
||||||
import com.trustedlogic.trustednfc.android.ILlcpConnectionlessSocket;
|
|
||||||
import com.trustedlogic.trustednfc.android.INfcTag;
|
|
||||||
import com.trustedlogic.trustednfc.android.IP2pTarget;
|
|
||||||
import com.trustedlogic.trustednfc.android.IP2pInitiator;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface that allows controlling NFC activity.
|
|
||||||
*
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
interface INfcManager
|
|
||||||
{
|
|
||||||
|
|
||||||
ILlcpSocket getLlcpInterface();
|
|
||||||
ILlcpConnectionlessSocket getLlcpConnectionlessInterface();
|
|
||||||
ILlcpServiceSocket getLlcpServiceInterface();
|
|
||||||
INfcTag getNfcTagInterface();
|
|
||||||
IP2pTarget getP2pTargetInterface();
|
|
||||||
IP2pInitiator getP2pInitiatorInterface();
|
|
||||||
|
|
||||||
void cancel();
|
|
||||||
int createLlcpConnectionlessSocket(int sap);
|
|
||||||
int createLlcpServiceSocket(int sap, String sn, int miu, int rw, int linearBufferLength);
|
|
||||||
int createLlcpSocket(int sap, int miu, int rw, int linearBufferLength);
|
|
||||||
int deselectSecureElement();
|
|
||||||
boolean disable();
|
|
||||||
boolean enable();
|
|
||||||
int getOpenTimeout();
|
|
||||||
String getProperties(String param);
|
|
||||||
int[] getSecureElementList();
|
|
||||||
int getSelectedSecureElement();
|
|
||||||
boolean isEnabled();
|
|
||||||
int openP2pConnection();
|
|
||||||
int openTagConnection();
|
|
||||||
int selectSecureElement(int seId);
|
|
||||||
void setOpenTimeout(int timeout);
|
|
||||||
int setProperties(String param, String value);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -24,7 +24,9 @@ package com.trustedlogic.trustednfc.android;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.trustedlogic.trustednfc.android.internal.ErrorCodes;
|
import android.nfc.ErrorCodes;
|
||||||
|
import android.nfc.ILlcpConnectionlessSocket;
|
||||||
|
import android.nfc.LlcpPacket;
|
||||||
|
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ package com.trustedlogic.trustednfc.android;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.trustedlogic.trustednfc.android.internal.ErrorCodes;
|
import android.nfc.ErrorCodes;
|
||||||
|
import android.nfc.ILlcpSocket;
|
||||||
|
import android.nfc.ILlcpServiceSocket;
|
||||||
|
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -55,7 +57,7 @@ public class LlcpServiceSocket {
|
|||||||
*/
|
*/
|
||||||
protected ILlcpServiceSocket mService;
|
protected ILlcpServiceSocket mService;
|
||||||
|
|
||||||
private ILlcpSocket mLlcpSocketService;
|
private final ILlcpSocket mLlcpSocketService;
|
||||||
|
|
||||||
static LlcpException convertErrorToLlcpException(int errorCode) {
|
static LlcpException convertErrorToLlcpException(int errorCode) {
|
||||||
return convertErrorToLlcpException(errorCode, null);
|
return convertErrorToLlcpException(errorCode, null);
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ package com.trustedlogic.trustednfc.android;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.trustedlogic.trustednfc.android.internal.ErrorCodes;
|
import android.nfc.ErrorCodes;
|
||||||
|
import android.nfc.ILlcpSocket;
|
||||||
|
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|||||||
@@ -1,160 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* File : NDEFMessage.java
|
|
||||||
* Original-Author : Trusted Logic S.A. (Jeremie Corbier)
|
|
||||||
* Created : 05-10-2009
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.ListIterator;
|
|
||||||
|
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents an NDEF message as specified by the <a
|
|
||||||
* href="http://www.nfc-forum.org/">NFC Forum</a>.
|
|
||||||
*
|
|
||||||
* @see NdefRecord
|
|
||||||
*
|
|
||||||
* @since AA01.04
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public class NdefMessage implements Parcelable {
|
|
||||||
/* Flag values */
|
|
||||||
private static final int FLAG_MB = 0x80;
|
|
||||||
private static final int FLAG_ME = 0x40;
|
|
||||||
private static final int FLAG_CF = 0x20;
|
|
||||||
private static final int FLAG_SR = 0x10;
|
|
||||||
private static final int FLAG_IL = 0x08;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Array of {@link NdefRecord} composing this message.
|
|
||||||
*/
|
|
||||||
private NdefRecord[] mRecords;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds an NDEF message.
|
|
||||||
*
|
|
||||||
* @param data raw NDEF message data
|
|
||||||
*
|
|
||||||
* @throws NFCException
|
|
||||||
*/
|
|
||||||
public NdefMessage(byte[] data) throws NfcException {
|
|
||||||
if (parseNdefMessage(data) == -1)
|
|
||||||
throw new NfcException("Error while parsing NDEF message");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds an NDEF message.
|
|
||||||
*
|
|
||||||
* @param records
|
|
||||||
* an array of already created NDEF records
|
|
||||||
*/
|
|
||||||
public NdefMessage(NdefRecord[] records) {
|
|
||||||
mRecords = new NdefRecord[records.length];
|
|
||||||
|
|
||||||
System.arraycopy(records, 0, mRecords, 0, records.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the NDEF message as a byte array.
|
|
||||||
*
|
|
||||||
* @return the message as a byte array
|
|
||||||
*/
|
|
||||||
public byte[] toByteArray() {
|
|
||||||
if ((mRecords == null) || (mRecords.length == 0))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
byte[] msg = {};
|
|
||||||
|
|
||||||
for (int i = 0; i < mRecords.length; i++) {
|
|
||||||
byte[] record = mRecords[i].toByteArray();
|
|
||||||
byte[] tmp = new byte[msg.length + record.length];
|
|
||||||
|
|
||||||
/* Make sure the Message Begin flag is set only for the first record */
|
|
||||||
if (i == 0)
|
|
||||||
record[0] |= FLAG_MB;
|
|
||||||
else
|
|
||||||
record[0] &= ~FLAG_MB;
|
|
||||||
|
|
||||||
/* Make sure the Message End flag is set only for the last record */
|
|
||||||
if (i == (mRecords.length - 1))
|
|
||||||
record[0] |= FLAG_ME;
|
|
||||||
else
|
|
||||||
record[0] &= ~FLAG_ME;
|
|
||||||
|
|
||||||
System.arraycopy(msg, 0, tmp, 0, msg.length);
|
|
||||||
System.arraycopy(record, 0, tmp, msg.length, record.length);
|
|
||||||
|
|
||||||
msg = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an array of {@link NdefRecord} composing this message.
|
|
||||||
*
|
|
||||||
* @return mRecords
|
|
||||||
*
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public NdefRecord[] getRecords(){
|
|
||||||
return mRecords;
|
|
||||||
}
|
|
||||||
|
|
||||||
private native int parseNdefMessage(byte[] data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (Parcelable) Describe the parcel
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (Parcelable) Convert current object to a Parcel
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
dest.writeInt(mRecords.length);
|
|
||||||
dest.writeTypedArray(mRecords, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creator class, needed when implementing from Parcelable
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public static final Parcelable.Creator<NdefMessage> CREATOR = new Parcelable.Creator<NdefMessage>() {
|
|
||||||
public NdefMessage createFromParcel(Parcel in) {
|
|
||||||
int recordsLength = in.readInt();
|
|
||||||
NdefRecord[] records = new NdefRecord[recordsLength];
|
|
||||||
in.readTypedArray(records, NdefRecord.CREATOR);
|
|
||||||
return new NdefMessage(records);
|
|
||||||
}
|
|
||||||
|
|
||||||
public NdefMessage[] newArray(int size) {
|
|
||||||
return new NdefMessage[size];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,293 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* File : NdefRecord.java
|
|
||||||
* Original-Author : Trusted Logic S.A. (Jeremie Corbier)
|
|
||||||
* Created : 05-10-2009
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android;
|
|
||||||
|
|
||||||
import android.location.Location;
|
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An NDEF record as specified by the <a href="http://www.nfc-forum.org/">NFC
|
|
||||||
* Forum</a>.
|
|
||||||
*
|
|
||||||
* @see NdefMessage
|
|
||||||
*
|
|
||||||
* @since AA01.04
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public class NdefRecord implements Parcelable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type Name Format - Empty record
|
|
||||||
*/
|
|
||||||
public static final short TNF_EMPTY = 0x0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type Name Format - NFC Forum-defined type
|
|
||||||
*/
|
|
||||||
public static final short TNF_WELL_KNOWN_TYPE = 0x1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type Name Format - RFC2045 MIME type
|
|
||||||
*/
|
|
||||||
public static final short TNF_MIME_MEDIA_TYPE = 0x2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type Name Format - Absolute URI
|
|
||||||
*/
|
|
||||||
public static final short TNF_ABSOLUTE_URI = 0x3;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type Name Format - User-defined type
|
|
||||||
*/
|
|
||||||
public static final short TNF_EXTERNAL_TYPE = 0x4;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type Name Format - Unknown type
|
|
||||||
*/
|
|
||||||
public static final short TNF_UNKNOWN = 0x5;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type Name Format - Unchanged. This TNF is used for chunked records, so
|
|
||||||
* that middle records inherits from the first record's type.
|
|
||||||
*/
|
|
||||||
public static final short TNF_UNCHANGED = 0x6;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NFC Forum-defined Type - Smart Poster
|
|
||||||
*/
|
|
||||||
public static final byte[] TYPE_SMART_POSTER = { 0x53, 0x70 };
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NFC Forum-defined Type - Text
|
|
||||||
*/
|
|
||||||
public static final byte[] TYPE_TEXT = { 0x54 };
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NFC Forum-defined Type - URI
|
|
||||||
*/
|
|
||||||
public static final byte[] TYPE_URI = { 0x55 };
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NFC Forum-defined Global Type - Connection Handover Request
|
|
||||||
*/
|
|
||||||
public static final byte[] TYPE_HANDOVER_REQUEST = { 0x48, 0x72 };
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NFC Forum-defined Global Type - Connection Handover Select
|
|
||||||
*/
|
|
||||||
public static final byte[] TYPE_HANDOVER_SELECT = { 0x48, 0x73 };
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NFC Forum-defined Global Type - Connection Handover Carrier
|
|
||||||
*/
|
|
||||||
public static final byte[] TYPE_HANDOVER_CARRIER = { 0x48, 0x63 };
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NFC Forum-defined Local Type - Alternative Carrier
|
|
||||||
*/
|
|
||||||
public static final byte[] TYPE_ALTERNATIVE_CARRIER = { 0x61, 0x63 };
|
|
||||||
|
|
||||||
/* Flag values */
|
|
||||||
private static final int FLAG_MB = 0x80;
|
|
||||||
private static final int FLAG_ME = 0x40;
|
|
||||||
private static final int FLAG_CF = 0x20;
|
|
||||||
private static final int FLAG_SR = 0x10;
|
|
||||||
private static final int FLAG_IL = 0x08;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Record Flags
|
|
||||||
*/
|
|
||||||
private short mFlags = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Record Type Name Format
|
|
||||||
*/
|
|
||||||
private short mTnf = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Record Type
|
|
||||||
*/
|
|
||||||
private byte[] mType = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Record Identifier
|
|
||||||
*/
|
|
||||||
private byte[] mId = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Record Payload
|
|
||||||
*/
|
|
||||||
private byte[] mPayload = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an NdefRecord given its Type Name Format, its type, its id and
|
|
||||||
* its.
|
|
||||||
*
|
|
||||||
* @param tnf
|
|
||||||
* Type Name Format
|
|
||||||
* @param type
|
|
||||||
* record type
|
|
||||||
* @param id
|
|
||||||
* record id (optional, can be null)
|
|
||||||
* @param data
|
|
||||||
* record payload
|
|
||||||
*/
|
|
||||||
public NdefRecord(short tnf, byte[] type, byte[] id, byte[] data) {
|
|
||||||
|
|
||||||
/* generate flag */
|
|
||||||
mFlags = FLAG_MB | FLAG_ME;
|
|
||||||
|
|
||||||
/* Determine if it is a short record */
|
|
||||||
if(data.length < 0xFF)
|
|
||||||
{
|
|
||||||
mFlags |= FLAG_SR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Determine if an id is present */
|
|
||||||
if(id.length != 0)
|
|
||||||
{
|
|
||||||
mFlags |= FLAG_IL;
|
|
||||||
}
|
|
||||||
|
|
||||||
mTnf = tnf;
|
|
||||||
mType = (byte[]) type.clone();
|
|
||||||
mId = (byte[]) id.clone();
|
|
||||||
mPayload = (byte[]) data.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Appends data to the record's payload.
|
|
||||||
*
|
|
||||||
* @param data
|
|
||||||
* Data to be added to the record.
|
|
||||||
*/
|
|
||||||
public void appendPayload(byte[] data) {
|
|
||||||
byte[] newPayload = new byte[mPayload.length + data.length];
|
|
||||||
|
|
||||||
System.arraycopy(mPayload, 0, newPayload, 0, mPayload.length);
|
|
||||||
System.arraycopy(data, 0, newPayload, mPayload.length, data.length);
|
|
||||||
|
|
||||||
mPayload = newPayload;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns record as a byte array.
|
|
||||||
*
|
|
||||||
* @return record as a byte array.
|
|
||||||
*/
|
|
||||||
public byte[] toByteArray() {
|
|
||||||
return generate(mFlags, mTnf, mType, mId, mPayload);
|
|
||||||
}
|
|
||||||
|
|
||||||
private native byte[] generate(short flags, short tnf, byte[] type,
|
|
||||||
byte[] id, byte[] data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (Parcelable) Describe the parcel
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* (Parcelable) Convert current object to a Parcel
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
dest.writeInt(mTnf);
|
|
||||||
dest.writeInt(mType.length);
|
|
||||||
dest.writeByteArray(mType);
|
|
||||||
dest.writeInt(mId.length);
|
|
||||||
dest.writeByteArray(mId);
|
|
||||||
dest.writeInt(mPayload.length);
|
|
||||||
dest.writeByteArray(mPayload);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creator class, needed when implementing from Parcelable
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public static final Parcelable.Creator<NdefRecord> CREATOR = new Parcelable.Creator<NdefRecord>() {
|
|
||||||
public NdefRecord createFromParcel(Parcel in) {
|
|
||||||
// TNF
|
|
||||||
short tnf = (short)in.readInt();
|
|
||||||
// Type
|
|
||||||
int typeLength = in.readInt();
|
|
||||||
byte[] type = new byte[typeLength];
|
|
||||||
in.readByteArray(type);
|
|
||||||
// ID
|
|
||||||
int idLength = in.readInt();
|
|
||||||
byte[] id = new byte[idLength];
|
|
||||||
in.readByteArray(id);
|
|
||||||
// Payload
|
|
||||||
int payloadLength = in.readInt();
|
|
||||||
byte[] payload = new byte[payloadLength];
|
|
||||||
in.readByteArray(payload);
|
|
||||||
|
|
||||||
return new NdefRecord(tnf, type, id, payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
public NdefRecord[] newArray(int size) {
|
|
||||||
return new NdefRecord[size];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns record TNF
|
|
||||||
*
|
|
||||||
* @return mTnf
|
|
||||||
*/
|
|
||||||
public int getTnf(){
|
|
||||||
return mTnf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns record TYPE
|
|
||||||
*
|
|
||||||
* @return mType
|
|
||||||
*/
|
|
||||||
public byte[] getType(){
|
|
||||||
return mType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns record ID
|
|
||||||
*
|
|
||||||
* @return mId
|
|
||||||
*/
|
|
||||||
public byte[] getId(){
|
|
||||||
return mId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns record Payload
|
|
||||||
*
|
|
||||||
* @return mPayload
|
|
||||||
*/
|
|
||||||
public byte[] getPayload(){
|
|
||||||
return mPayload;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* File : NDEFTag.java
|
|
||||||
* Original-Author : Trusted Logic S.A. (Jeremie Corbier)
|
|
||||||
* Created : 04-12-2009
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NdefTag represents tags complying with the NFC Forum's NFC Data Exchange
|
|
||||||
* Format.
|
|
||||||
*
|
|
||||||
* @since AA01.04
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public class NdefTag extends NfcTag {
|
|
||||||
|
|
||||||
private static final String TAG = "NdefTag";
|
|
||||||
|
|
||||||
|
|
||||||
public NdefTag(NfcTag tag){
|
|
||||||
super(tag.mService,tag.mHandle);
|
|
||||||
this.isConnected = tag.isConnected;
|
|
||||||
this.isClosed = tag.isClosed;
|
|
||||||
tag.isClosed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal constructor for the NfcNdefTag class.
|
|
||||||
*
|
|
||||||
* @param service The entry point to the Nfc Service for NfcNdefTag class.
|
|
||||||
* @param handle The handle returned by the NFC service and used to identify
|
|
||||||
* the tag in subsequent calls.
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
NdefTag(INfcTag service, int handle) {
|
|
||||||
super(service, handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read NDEF data from an NDEF tag.
|
|
||||||
*
|
|
||||||
* @return the NDEF message read from the tag.
|
|
||||||
* @throws NfcException if the tag is not NDEF-formatted.
|
|
||||||
* @throws IOException if the target has been lost or the connection has
|
|
||||||
* been closed.
|
|
||||||
* @see NdefMessage
|
|
||||||
*/
|
|
||||||
public NdefMessage read() throws NfcException, IOException {
|
|
||||||
// Check state
|
|
||||||
checkState();
|
|
||||||
|
|
||||||
//Check if the tag is Ndef compliant
|
|
||||||
if(isNdef != true){
|
|
||||||
isNdef = isNdef();
|
|
||||||
if(isNdef != true) {
|
|
||||||
throw new NfcException("Tag is not NDEF compliant");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform transceive
|
|
||||||
try {
|
|
||||||
NdefMessage msg = mService.read(mHandle);
|
|
||||||
if (msg == null) {
|
|
||||||
throw new IOException("NDEF read failed");
|
|
||||||
}
|
|
||||||
return msg;
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in read(): ", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Write NDEF data to an NDEF-compliant tag.
|
|
||||||
*
|
|
||||||
* @param msg NDEF message to be written to the tag.
|
|
||||||
* @throws NfcException if the tag is not NDEF formatted.
|
|
||||||
* @throws IOException if the target has been lost or the connection has
|
|
||||||
* been closed.
|
|
||||||
* @see NdefMessage
|
|
||||||
*/
|
|
||||||
public void write(NdefMessage msg) throws NfcException, IOException {
|
|
||||||
// Check state
|
|
||||||
checkState();
|
|
||||||
|
|
||||||
//Check if the tag is Ndef compliant
|
|
||||||
if(isNdef != true){
|
|
||||||
isNdef = isNdef();
|
|
||||||
if(isNdef != true) {
|
|
||||||
throw new NfcException("Tag is not NDEF compliant");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform transceive
|
|
||||||
try {
|
|
||||||
boolean isSuccess = mService.write(mHandle, msg);
|
|
||||||
if (!isSuccess) {
|
|
||||||
throw new IOException("NDEF write failed");
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in write(): ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,656 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* File : NfcManager.java
|
|
||||||
* Original-Author : Trusted Logic S.A. (Jeremie Corbier)
|
|
||||||
* Created : 26-08-2009
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import com.trustedlogic.trustednfc.android.internal.ErrorCodes;
|
|
||||||
|
|
||||||
import android.annotation.SdkConstant;
|
|
||||||
import android.annotation.SdkConstant.SdkConstantType;
|
|
||||||
import android.media.MiniThumbFile;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
//import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides the primary API for managing all aspects of NFC. Get an
|
|
||||||
* instance of this class by calling
|
|
||||||
* Context.getSystemService(Context.NFC_SERVICE).
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public final class NfcManager {
|
|
||||||
/**
|
|
||||||
* Tag Reader Discovery mode
|
|
||||||
*/
|
|
||||||
private static final int DISCOVERY_MODE_TAG_READER = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NFC-IP1 Peer-to-Peer mode Enables the manager to act as a peer in an
|
|
||||||
* NFC-IP1 communication. Implementations should not assume that the
|
|
||||||
* controller will end up behaving as an NFC-IP1 target or initiator and
|
|
||||||
* should handle both cases, depending on the type of the remote peer type.
|
|
||||||
*/
|
|
||||||
private static final int DISCOVERY_MODE_NFCIP1 = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Card Emulation mode Enables the manager to act as an NFC tag. Provided
|
|
||||||
* that a Secure Element (an UICC for instance) is connected to the NFC
|
|
||||||
* controller through its SWP interface, it can be exposed to the outside
|
|
||||||
* NFC world and be addressed by external readers the same way they would
|
|
||||||
* with a tag.
|
|
||||||
* <p>
|
|
||||||
* Which Secure Element is exposed is implementation-dependent.
|
|
||||||
*
|
|
||||||
* @since AA01.04
|
|
||||||
*/
|
|
||||||
private static final int DISCOVERY_MODE_CARD_EMULATION = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used as Parcelable extra field in
|
|
||||||
* {@link com.trustedlogic.trustednfc.android.NfcManager#NDEF_TAG_DISCOVERED_ACTION}
|
|
||||||
* . It contains the NDEF message read from the NDEF tag discovered.
|
|
||||||
*/
|
|
||||||
public static final String NDEF_MESSAGE_EXTRA = "com.trustedlogic.trustednfc.android.extra.NDEF_MESSAGE";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Broadcast Action: a NDEF tag has been discovered.
|
|
||||||
* <p>
|
|
||||||
* Always contains the extra field
|
|
||||||
* {@link com.trustedlogic.trustednfc.android.NfcManager#NDEF_MESSAGE_EXTRA}.
|
|
||||||
* <p class="note">
|
|
||||||
* <strong>Note:</strong> Requires the NFC_NOTIFY permission.
|
|
||||||
*/
|
|
||||||
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
|
||||||
public static final String NDEF_TAG_DISCOVERED_ACTION = "com.trustedlogic.trustednfc.android.action.NDEF_TAG_DISCOVERED";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used as byte array extra field in
|
|
||||||
* {@link com.trustedlogic.trustednfc.android.NfcManager#TRANSACTION_DETECTED_ACTION}
|
|
||||||
* . It contains the AID of the applet concerned by the transaction.
|
|
||||||
*/
|
|
||||||
public static final String AID_EXTRA = "com.trustedlogic.trustednfc.android.extra.AID";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Broadcast Action: a transaction with a secure element has been detected.
|
|
||||||
* <p>
|
|
||||||
* Always contains the extra field
|
|
||||||
* {@link com.trustedlogic.trustednfc.android.NfcManager#AID_EXTRA}
|
|
||||||
* <p class="note">
|
|
||||||
* <strong>Note:</strong> Requires the NFC_NOTIFY permission
|
|
||||||
*/
|
|
||||||
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
|
||||||
public static final String TRANSACTION_DETECTED_ACTION = "com.trustedlogic.trustednfc.android.action.TRANSACTION_DETECTED";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LLCP link status: The LLCP link is activated.
|
|
||||||
*
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public static final int LLCP_LINK_STATE_ACTIVATED = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* LLCP link status: The LLCP link is deactivated.
|
|
||||||
*
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public static final int LLCP_LINK_STATE_DEACTIVATED = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used as int extra field in
|
|
||||||
* {@link com.trustedlogic.trustednfc.android.NfcManager#LLCP_LINK_STATE_CHANGED_ACTION}
|
|
||||||
* . It contains the new state of the LLCP link.
|
|
||||||
*/
|
|
||||||
public static final String LLCP_LINK_STATE_CHANGED_EXTRA = "com.trustedlogic.trustednfc.android.extra.LLCP_LINK_STATE";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Broadcast Action: the LLCP link state changed.
|
|
||||||
* <p>
|
|
||||||
* Always contains the extra field
|
|
||||||
* {@link com.trustedlogic.trustednfc.android.NfcManager#LLCP_LINK_STATE_CHANGED_EXTRA}.
|
|
||||||
* <p class="note">
|
|
||||||
* <strong>Note:</strong> Requires the NFC_LLCP permission.
|
|
||||||
*/
|
|
||||||
@SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
|
|
||||||
public static final String LLCP_LINK_STATE_CHANGED_ACTION = "com.trustedlogic.trustednfc.android.action.LLCP_LINK_STATE_CHANGED";
|
|
||||||
|
|
||||||
private static final String TAG = "NfcManager";
|
|
||||||
|
|
||||||
private Handler mHandler;
|
|
||||||
|
|
||||||
private INfcManager mService;
|
|
||||||
|
|
||||||
private INfcTag mNfcTagService;
|
|
||||||
|
|
||||||
private IP2pTarget mP2pTargetService;
|
|
||||||
|
|
||||||
private IP2pInitiator mP2pInitiatorService;
|
|
||||||
|
|
||||||
private ILlcpSocket mLlcpSocketService;
|
|
||||||
|
|
||||||
private ILlcpConnectionlessSocket mLlcpConnectionlessSocketService;
|
|
||||||
|
|
||||||
private ILlcpServiceSocket mLlcpServiceSocketService;
|
|
||||||
|
|
||||||
static NfcException convertErrorToNfcException(int errorCode) {
|
|
||||||
return convertErrorToNfcException(errorCode, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
static NfcException convertErrorToNfcException(int errorCode, String message) {
|
|
||||||
if (message == null) {
|
|
||||||
message = "";
|
|
||||||
} else {
|
|
||||||
message = " (" + message + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (errorCode) {
|
|
||||||
case ErrorCodes.ERROR_BUSY:
|
|
||||||
return new NfcException("Another operation is already pending" + message);
|
|
||||||
case ErrorCodes.ERROR_CANCELLED:
|
|
||||||
return new NfcException("Operation cancelled" + message);
|
|
||||||
case ErrorCodes.ERROR_TIMEOUT:
|
|
||||||
return new NfcException("Operation timed out" + message);
|
|
||||||
case ErrorCodes.ERROR_SOCKET_CREATION:
|
|
||||||
return new NfcException("Error during the creation of an Llcp socket:" + message);
|
|
||||||
case ErrorCodes.ERROR_SAP_USED:
|
|
||||||
return new NfcException("Error SAP already used:" + message);
|
|
||||||
case ErrorCodes.ERROR_SERVICE_NAME_USED:
|
|
||||||
return new NfcException("Error Service Name already used:" + message);
|
|
||||||
case ErrorCodes.ERROR_SOCKET_OPTIONS:
|
|
||||||
return new NfcException("Error Socket options:" + message);
|
|
||||||
case ErrorCodes.ERROR_INVALID_PARAM:
|
|
||||||
return new NfcException("Error Set Properties: invalid param" + message);
|
|
||||||
case ErrorCodes.ERROR_NFC_ON:
|
|
||||||
return new NfcException("Error Set Properties : NFC is ON" + message);
|
|
||||||
case ErrorCodes.ERROR_NOT_INITIALIZED:
|
|
||||||
return new NfcException("NFC is not running " + message);
|
|
||||||
case ErrorCodes.ERROR_SE_ALREADY_SELECTED:
|
|
||||||
return new NfcException("Secure Element already connected" + message);
|
|
||||||
case ErrorCodes.ERROR_NO_SE_CONNECTED:
|
|
||||||
return new NfcException("No Secure Element connected" + message);
|
|
||||||
case ErrorCodes.ERROR_SE_CONNECTED:
|
|
||||||
return new NfcException("A secure Element is already connected" + message);
|
|
||||||
default:
|
|
||||||
return new NfcException("Unkown error code " + errorCode + message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public NfcManager(INfcManager service, Handler handler) {
|
|
||||||
mService = service;
|
|
||||||
mHandler = handler;
|
|
||||||
try {
|
|
||||||
mNfcTagService = mService.getNfcTagInterface();
|
|
||||||
mP2pInitiatorService = mService.getP2pInitiatorInterface();
|
|
||||||
mP2pTargetService = mService.getP2pTargetInterface();
|
|
||||||
mLlcpServiceSocketService = mService.getLlcpServiceInterface();
|
|
||||||
mLlcpConnectionlessSocketService = mService.getLlcpConnectionlessInterface();
|
|
||||||
mLlcpSocketService = mService.getLlcpInterface();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
mLlcpSocketService = null;
|
|
||||||
mNfcTagService = null;
|
|
||||||
mP2pInitiatorService = null;
|
|
||||||
mP2pTargetService = null;
|
|
||||||
mLlcpConnectionlessSocketService = null;
|
|
||||||
mLlcpServiceSocketService = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the status of the NFC feature
|
|
||||||
*
|
|
||||||
* @return mIsNfcEnabled
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public boolean isEnabled() {
|
|
||||||
try {
|
|
||||||
return mService.isEnabled();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in isEnabled(): ", e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable the NFC Feature
|
|
||||||
* <p class="note">
|
|
||||||
* <strong>Note:</strong> Requires the NFC_ADMIN permission
|
|
||||||
*
|
|
||||||
* @throws NfcException if the enable failed
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public void enable() throws NfcException {
|
|
||||||
try {
|
|
||||||
boolean isSuccess = mService.enable();
|
|
||||||
if (isSuccess == false) {
|
|
||||||
throw new NfcException("NFC Service failed to enable");
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in enable(): ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disable the NFC feature
|
|
||||||
* <p class="note">
|
|
||||||
* <strong>Note:</strong> Requires the NFC_ADMIN permission
|
|
||||||
*
|
|
||||||
* @throws NfcException if the disable failed
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public void disable() throws NfcException {
|
|
||||||
try {
|
|
||||||
boolean isSuccess = mService.disable();
|
|
||||||
if (isSuccess == false) {
|
|
||||||
throw new NfcException("NFC Service failed to disable");
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in disable(): ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of the identifiers of the Secure Elements detected
|
|
||||||
* by the NFC controller.
|
|
||||||
*
|
|
||||||
* @return list a list of Secure Element identifiers.
|
|
||||||
* @see #getSelectedSecureElement
|
|
||||||
* @see #selectSecureElement(int)
|
|
||||||
* @see #deselectSecureElement
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public int[] getSecureElementList() {
|
|
||||||
try {
|
|
||||||
return mService.getSecureElementList();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in getSecureElementList(): ", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the identifier of the currently selected secure element.
|
|
||||||
*
|
|
||||||
* @return id identifier of the currently selected Secure Element. 0 if none.
|
|
||||||
* @see #getSecureElementList
|
|
||||||
* @see #selectSecureElement(int)
|
|
||||||
* @see #deselectSecureElement
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public int getSelectedSecureElement() {
|
|
||||||
try {
|
|
||||||
return mService.getSelectedSecureElement();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in getSelectedSecureElement(): ", e);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Select a specific Secure Element by its identifier.
|
|
||||||
* <p class="note">
|
|
||||||
* <strong>Note:</strong> Requires the NFC_ADMIN permission
|
|
||||||
*
|
|
||||||
* @throws NfcException if a or this secure element is already selected
|
|
||||||
* @see #getSecureElementList
|
|
||||||
* @see #getSelectedSecureElement
|
|
||||||
* @see #deselectSecureElement
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public void selectSecureElement(int seId) throws NfcException {
|
|
||||||
try {
|
|
||||||
int status = mService.selectSecureElement(seId);
|
|
||||||
if(status != ErrorCodes.SUCCESS){
|
|
||||||
throw convertErrorToNfcException(status);
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in selectSecureElement(): ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deselect the currently selected Secure Element
|
|
||||||
* <p class="note">
|
|
||||||
* <strong>Note:</strong> Requires the NFC_ADMIN permission
|
|
||||||
*
|
|
||||||
* @throws NfcException if no secure Element is selected
|
|
||||||
* @see #getSecureElementList
|
|
||||||
* @see #getSelectedSecureElement
|
|
||||||
* @see #selectSecureElement(int)
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public void deselectSecureElement() throws NfcException {
|
|
||||||
try {
|
|
||||||
int status = mService.deselectSecureElement();
|
|
||||||
if(status != ErrorCodes.SUCCESS){
|
|
||||||
throw convertErrorToNfcException(status);
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in deselectSecureElement(): ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open a connection with a remote NFC peer
|
|
||||||
*
|
|
||||||
* This method does not return while no remote NFC peer enters the field.
|
|
||||||
* <p class="note">
|
|
||||||
* <strong>Note:</strong> Requires the NFC_RAW permission
|
|
||||||
*
|
|
||||||
* @return P2pDevice object to be used to communicate with the detected
|
|
||||||
* peer.
|
|
||||||
* @throws IOException if the target has been lost or the connection has
|
|
||||||
* been closed.
|
|
||||||
* @throws NfcException if an open is already started
|
|
||||||
* @see P2pDevice
|
|
||||||
* @see #getOpenTimeout
|
|
||||||
* @see #setOpenTimeout(int)
|
|
||||||
* @see #cancel
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public P2pDevice openP2pConnection() throws IOException, NfcException {
|
|
||||||
try {
|
|
||||||
int handle = mService.openP2pConnection();
|
|
||||||
// Handle potential errors
|
|
||||||
if (ErrorCodes.isError(handle)) {
|
|
||||||
if (handle == ErrorCodes.ERROR_IO) {
|
|
||||||
throw new IOException();
|
|
||||||
} else {
|
|
||||||
throw convertErrorToNfcException(handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Build the public NfcTag object, depending on its type
|
|
||||||
if (mP2pTargetService.getMode(handle) == P2pDevice.MODE_P2P_TARGET) {
|
|
||||||
return new P2pTarget(mP2pTargetService, handle);
|
|
||||||
} else {
|
|
||||||
return new P2pInitiator(mP2pInitiatorService, handle);
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in openTagConnection(): ", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Open a connection with a tag
|
|
||||||
*
|
|
||||||
* This method does not return while no tag enters the field.
|
|
||||||
* <p class="note">
|
|
||||||
* <strong>Note:</strong> Requires the NFC_RAW permission
|
|
||||||
*
|
|
||||||
* @return tag object to be use to communicate with the detected NfcTag.
|
|
||||||
* @throws IOException if the target has been lost or the connection has
|
|
||||||
* been closed.
|
|
||||||
* @throws NfcException if an open is already started
|
|
||||||
* @see NfcTag
|
|
||||||
* @see #getOpenTimeout
|
|
||||||
* @see #setOpenTimeout(int)
|
|
||||||
* @see #cancel
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public NfcTag openTagConnection() throws IOException, NfcException {
|
|
||||||
try {
|
|
||||||
int handle = mService.openTagConnection();
|
|
||||||
// Handle potential errors
|
|
||||||
if (ErrorCodes.isError(handle)) {
|
|
||||||
if (handle == ErrorCodes.ERROR_IO) {
|
|
||||||
throw new IOException();
|
|
||||||
} else {
|
|
||||||
throw convertErrorToNfcException(handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Build the public NfcTag object
|
|
||||||
return new NfcTag(mNfcTagService, handle);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in openTagConnection(): ", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the timeout for open requests
|
|
||||||
* <p class="note">
|
|
||||||
* <strong>Note:</strong> Requires the NFC_RAW permission
|
|
||||||
*
|
|
||||||
* @param timeout value of the timeout for open request
|
|
||||||
* @see #openP2pConnection
|
|
||||||
* @see #openTagConnection
|
|
||||||
* @see #getOpenTimeout
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public void setOpenTimeout(int timeout) {
|
|
||||||
try {
|
|
||||||
mService.setOpenTimeout(timeout);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in setOpenTimeout(): ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the timeout value of open requests
|
|
||||||
*
|
|
||||||
* @return mTimeout
|
|
||||||
* @see #setOpenTimeout(int)
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public int getOpenTimeout() {
|
|
||||||
try {
|
|
||||||
return mService.getOpenTimeout();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in getOpenTimeout(): ", e);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cancel an openTagConnection or an openP2pConnection started
|
|
||||||
* <p class="note">
|
|
||||||
* <strong>Note:</strong> Requires the NFC_RAW permission
|
|
||||||
*
|
|
||||||
* @see #openP2pConnection
|
|
||||||
* @see #openTagConnection
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public void cancel() {
|
|
||||||
try {
|
|
||||||
mService.cancel();
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in cancel(): ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a connectionless socket for a LLCP link and set its Service
|
|
||||||
* Access Point number (SAP)
|
|
||||||
* <p class="note">
|
|
||||||
* <strong>Note:</strong> Requires the NFC_LLCP permission
|
|
||||||
*
|
|
||||||
* @param sap Service Access Point number related to the created
|
|
||||||
* Connectionless socket.
|
|
||||||
* @return LlcpConnectionlessSocket object to be used in a LLCP
|
|
||||||
* Connectionless communication.
|
|
||||||
* @throws IOException if the socket creation failed
|
|
||||||
* @throws NfcException if socket ressources are insufficicent
|
|
||||||
* @see LlcpConnectionlessSocket
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public LlcpConnectionlessSocket createLlcpConnectionlessSocket(int sap) throws IOException,
|
|
||||||
NfcException {
|
|
||||||
|
|
||||||
try {
|
|
||||||
int handle = mService.createLlcpConnectionlessSocket(sap);
|
|
||||||
// Handle potential errors
|
|
||||||
if (ErrorCodes.isError(handle)) {
|
|
||||||
if (handle == ErrorCodes.ERROR_IO) {
|
|
||||||
throw new IOException();
|
|
||||||
} else {
|
|
||||||
throw convertErrorToNfcException(handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build the public LlcpConnectionLess object
|
|
||||||
return new LlcpConnectionlessSocket(mLlcpConnectionlessSocketService, handle);
|
|
||||||
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in createLlcpConnectionlessSocket(): ", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a LlcpServiceSocket for a LLCP link, set its Service Access Point
|
|
||||||
* number (SAP).
|
|
||||||
* <p>
|
|
||||||
* During a LLCP communication, the LlcpServiceSocket will create LlcpSocket
|
|
||||||
* to communicate with incoming LLCP clients. For that, a server socket need
|
|
||||||
* to have some informations as a working buffer length in order to handle
|
|
||||||
* incoming data and some options to define the LLCP communication.
|
|
||||||
* <p class="note">
|
|
||||||
* <strong>Note:</strong> Requires the NFC_LLCP permission
|
|
||||||
*
|
|
||||||
* @param sap
|
|
||||||
* @param sn Service Name of the LlcpServiceSocket
|
|
||||||
* @param miu Maximum Information Unit (MIU) for a LlcpSocket created by the
|
|
||||||
* LlcpServiceSocket
|
|
||||||
* @param rw Receive Window (RW) for a LlcpSocket created by the
|
|
||||||
* LlcpServiceSocket
|
|
||||||
* @param linearBufferLength size of the memory space needed to handle
|
|
||||||
* incoming data for every LlcpSocket created.
|
|
||||||
* @return LlcpServiceSocket object to be used as a LLCP Service in a
|
|
||||||
* connection oriented communication.
|
|
||||||
* @throws IOException if the socket creation failed
|
|
||||||
* @throws NfcException if socket ressources are insufficicent
|
|
||||||
* @see LlcpServiceSocket
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public LlcpServiceSocket createLlcpServiceSocket(int sap, String sn, int miu, int rw,
|
|
||||||
int linearBufferLength) throws IOException, NfcException {
|
|
||||||
try {
|
|
||||||
int handle = mService.createLlcpServiceSocket(sap, sn, miu, rw, linearBufferLength);
|
|
||||||
// Handle potential errors
|
|
||||||
if (ErrorCodes.isError(handle)) {
|
|
||||||
if (handle == ErrorCodes.ERROR_IO) {
|
|
||||||
throw new IOException();
|
|
||||||
} else {
|
|
||||||
throw convertErrorToNfcException(handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build the public LlcpServiceSocket object
|
|
||||||
return new LlcpServiceSocket(mLlcpServiceSocketService, mLlcpSocketService, handle);
|
|
||||||
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in createLlcpServiceSocket(): ", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a LlcpSocket for a LLCP link with a specific Service Access Point
|
|
||||||
* number (SAP)
|
|
||||||
* <p>
|
|
||||||
* A LlcpSocket need to have a linear buffer in order to handle incoming
|
|
||||||
* data. This linear buffer will be used to store incoming data as a stream.
|
|
||||||
* Data will be readable later.
|
|
||||||
* <p class="note">
|
|
||||||
* <strong>Note:</strong> Requires the NFC_LLCP permission
|
|
||||||
*
|
|
||||||
* @param sap Service Access Point number for the created socket
|
|
||||||
* @param miu Maximum Information Unit (MIU) of the communication socket
|
|
||||||
* @param rw Receive Window (RW) of the communication socket
|
|
||||||
* @param linearBufferLength size of the memory space needed to handle
|
|
||||||
* incoming data with this socket
|
|
||||||
* @throws IOException if the socket creation failed
|
|
||||||
* @throws NfcException if socket ressources are insufficicent
|
|
||||||
* @see LlcpSocket
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public LlcpSocket createLlcpSocket(int sap, int miu, int rw, int linearBufferLength)
|
|
||||||
throws IOException, NfcException {
|
|
||||||
try {
|
|
||||||
int handle = mService.createLlcpSocket(sap, miu, rw, linearBufferLength);
|
|
||||||
// Handle potential errors
|
|
||||||
if (ErrorCodes.isError(handle)) {
|
|
||||||
if (handle == ErrorCodes.ERROR_IO) {
|
|
||||||
throw new IOException();
|
|
||||||
} else {
|
|
||||||
throw convertErrorToNfcException(handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Build the public LlcpSocket object
|
|
||||||
return new LlcpSocket(mLlcpSocketService, handle);
|
|
||||||
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in createLlcpSocket(): ", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set different parameters like the NCIP General bytes, the LLCP link
|
|
||||||
* parameters and all tag discovery parameters.
|
|
||||||
* <p class="note">
|
|
||||||
* <strong>Note:</strong> Requires the NFC_ADMIN permission
|
|
||||||
*
|
|
||||||
* @param param parameter to be updated with a new value
|
|
||||||
* @param value new value of the parameter
|
|
||||||
* @throws NfcException if incorrect parameters of NFC is ON
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public void setProperties(String param, String value) throws NfcException {
|
|
||||||
try {
|
|
||||||
int result = mService.setProperties(param, value);
|
|
||||||
// Handle potential errors
|
|
||||||
if (ErrorCodes.isError(result)) {
|
|
||||||
throw convertErrorToNfcException(result);
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in setProperties(): ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the value of different parameters like the NCFIP General bytes, the
|
|
||||||
* LLCP link parameters and all tag discovery parameters.
|
|
||||||
*
|
|
||||||
* @param param parameter to be updated
|
|
||||||
* @return String value of the requested parameter
|
|
||||||
* @throws RemoteException
|
|
||||||
* @since AA02.01
|
|
||||||
*/
|
|
||||||
public String getProperties(String param) {
|
|
||||||
String value;
|
|
||||||
try {
|
|
||||||
value = mService.getProperties(param);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in getProperties(): ", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,250 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* File : NFCTag.java
|
|
||||||
* Original-Author : Trusted Logic S.A. (Daniel Tomas)
|
|
||||||
* Created : 26-02-2010
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.trustedlogic.trustednfc.android;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import android.os.RemoteException;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.trustedlogic.trustednfc.android.internal.ErrorCodes;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class represents tags with no known formatting. One can use the method
|
|
||||||
* {@link #isNdef()} to determine if the tag can store NDEF-formatted messages.
|
|
||||||
* <p>
|
|
||||||
*
|
|
||||||
* <pre class="prettyprint">
|
|
||||||
* if (tag.isNdef()) {
|
|
||||||
* NdefTag ndefTag = (NdefTag) tag;
|
|
||||||
* NdefMessage msg = ndefTag.read();
|
|
||||||
* }
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* @since AA01.04
|
|
||||||
* @see NdefMessage
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public class NfcTag {
|
|
||||||
|
|
||||||
private static final String TAG = "NfcTag";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The handle returned by the NFC service and used to identify the tag in
|
|
||||||
* every call of this class.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
protected int mHandle;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The entry point for tag operations.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
protected INfcTag mService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag set when the object is closed and thus not usable any more.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
protected boolean isClosed = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag set when the tag is connected.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
protected boolean isConnected = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Flag set when a check NDEF is performed.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
protected boolean isNdef = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if tag is still opened.
|
|
||||||
*
|
|
||||||
* @return data sent by the P2pInitiator.
|
|
||||||
* @throws NfcException if accessing a closed target.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public void checkState() throws NfcException {
|
|
||||||
if (isClosed) {
|
|
||||||
throw new NfcException("Tag has been closed.");
|
|
||||||
}
|
|
||||||
if (!isConnected) {
|
|
||||||
throw new NfcException("Tag is not connected.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal constructor for the NfcTag class.
|
|
||||||
*
|
|
||||||
* @param service The entry point to the Nfc Service for NfcTag class.
|
|
||||||
* @param handle The handle returned by the NFC service and used to identify
|
|
||||||
* the tag in subsequent calls.
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
NfcTag(INfcTag service, int handle) {
|
|
||||||
this.mService = service;
|
|
||||||
this.mHandle = handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Connects to the tag. This shall be called prior to any other operation on
|
|
||||||
* the tag.
|
|
||||||
*
|
|
||||||
* @throws IOException if the tag has been lost or the connection has been
|
|
||||||
* closed.
|
|
||||||
* @throws nfcException if the tag is already in connected state.
|
|
||||||
*/
|
|
||||||
public void connect() throws NfcException, IOException {
|
|
||||||
// Check state
|
|
||||||
if (isClosed) {
|
|
||||||
throw new NfcException("Tag has been closed.");
|
|
||||||
}
|
|
||||||
if (isConnected) {
|
|
||||||
throw new NfcException("Already connected");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Perform connect
|
|
||||||
try {
|
|
||||||
int result = mService.connect(mHandle);
|
|
||||||
if (ErrorCodes.isError(result)) {
|
|
||||||
if (result == ErrorCodes.ERROR_IO) {
|
|
||||||
throw new IOException("Failed to connect");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw NfcManager.convertErrorToNfcException(result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isConnected = true;
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in connect(): ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disconnects from the tag. This must be called so that other targets can
|
|
||||||
* be discovered. It restarts the NFC discovery loop.
|
|
||||||
*
|
|
||||||
* @throws NfcException if the tag is already in disconnected state or not connected
|
|
||||||
*/
|
|
||||||
public void close() throws NfcException {
|
|
||||||
// Check state
|
|
||||||
checkState();
|
|
||||||
|
|
||||||
try {
|
|
||||||
mService.close(mHandle);
|
|
||||||
isClosed = true;
|
|
||||||
isConnected = false;
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in close(): ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exchanges raw data with the tag, whatever the tag type.
|
|
||||||
*
|
|
||||||
* To exchange APDUs with a ISO14443-4-compliant tag, the data parameter
|
|
||||||
* must be filled with the C-APDU (CLA, INS, P1, P2 [, ...]). The returned
|
|
||||||
* data consists of the R-APDU ([...,] SW1, SW2).
|
|
||||||
*
|
|
||||||
* @param data data to be sent to the tag
|
|
||||||
* @return data sent in response by the tag
|
|
||||||
* @throws IOException if the tag has been lost or the connection has been
|
|
||||||
* closed.
|
|
||||||
* @throws NfcException in case of failure within the stack
|
|
||||||
*/
|
|
||||||
public byte[] transceive(byte[] data) throws IOException, NfcException {
|
|
||||||
// Check state
|
|
||||||
checkState();
|
|
||||||
|
|
||||||
// Perform transceive
|
|
||||||
try {
|
|
||||||
byte[] response = mService.transceive(mHandle, data);
|
|
||||||
if (response == null) {
|
|
||||||
throw new IOException("Transceive failed");
|
|
||||||
}
|
|
||||||
return response;
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in transceive(): ", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether tag is NDEF-compliant or not.
|
|
||||||
*
|
|
||||||
* @return true if the tag is NDEF-compliant, false otherwise
|
|
||||||
* @throws NfcException in case an error occurred when trying to determine
|
|
||||||
* whether the tag is NDEF-compliant
|
|
||||||
*/
|
|
||||||
public boolean isNdef() throws NfcException {
|
|
||||||
// Check state
|
|
||||||
checkState();
|
|
||||||
|
|
||||||
// Perform Check Ndef
|
|
||||||
try {
|
|
||||||
isNdef = mService.isNdef(mHandle);
|
|
||||||
return isNdef;
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in isNdef(): ", e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns target type. constants.
|
|
||||||
*
|
|
||||||
* @return tag type.
|
|
||||||
*/
|
|
||||||
public String getType() {
|
|
||||||
try {
|
|
||||||
return mService.getType(mHandle);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in getType(): ", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns target UID.
|
|
||||||
*
|
|
||||||
* @return tag UID.
|
|
||||||
*/
|
|
||||||
public byte[] getUid() {
|
|
||||||
try {
|
|
||||||
return mService.getUid(mHandle);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "RemoteException in getType(): ", e);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -23,8 +23,7 @@ package com.trustedlogic.trustednfc.android;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.trustedlogic.trustednfc.android.internal.ErrorCodes;
|
import android.nfc.IP2pInitiator;
|
||||||
|
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -44,7 +43,7 @@ public class P2pInitiator extends P2pDevice {
|
|||||||
* The entry point for P2P tag operations.
|
* The entry point for P2P tag operations.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
private IP2pInitiator mService;
|
private final IP2pInitiator mService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal constructor for the P2pInitiator class.
|
* Internal constructor for the P2pInitiator class.
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ package com.trustedlogic.trustednfc.android;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.trustedlogic.trustednfc.android.internal.ErrorCodes;
|
import android.nfc.ErrorCodes;
|
||||||
|
import android.nfc.IP2pTarget;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -43,13 +43,13 @@ public class P2pTarget extends P2pDevice {
|
|||||||
* The entry point for P2P tag operations.
|
* The entry point for P2P tag operations.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
private IP2pTarget mService;
|
private final IP2pTarget mService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag set when the object is closed and thus not usable any more.
|
* Flag set when the object is closed and thus not usable any more.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
private boolean isClosed = false;
|
private final boolean isClosed = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag set when the tag is connected.
|
* Flag set when the tag is connected.
|
||||||
@@ -105,7 +105,8 @@ public class P2pTarget extends P2pDevice {
|
|||||||
throw new NfcException("Failed to connect");
|
throw new NfcException("Failed to connect");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw NfcManager.convertErrorToNfcException(result);
|
// TODO(nxp)
|
||||||
|
// throw NfcAdapter.convertErrorToNfcException(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
@@ -162,6 +163,7 @@ public class P2pTarget extends P2pDevice {
|
|||||||
* @return general bytes of the connected P2P Target
|
* @return general bytes of the connected P2P Target
|
||||||
* @throws IOException if the target in not in connected state
|
* @throws IOException if the target in not in connected state
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public byte[] getGeneralBytes() throws IOException {
|
public byte[] getGeneralBytes() throws IOException {
|
||||||
try {
|
try {
|
||||||
if(isConnected){
|
if(isConnected){
|
||||||
|
|||||||
@@ -22,14 +22,14 @@
|
|||||||
|
|
||||||
package com.trustedlogic.trustednfc.android.internal;
|
package com.trustedlogic.trustednfc.android.internal;
|
||||||
|
|
||||||
import com.trustedlogic.trustednfc.android.LlcpPacket;
|
import android.nfc.LlcpPacket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LlcpConnectionlessSocket represents a LLCP Connectionless object to be used
|
* LlcpConnectionlessSocket represents a LLCP Connectionless object to be used
|
||||||
* in a connectionless communication
|
* in a connectionless communication
|
||||||
*
|
*
|
||||||
* @since AA02.01
|
* @since AA02.01
|
||||||
* {@hide}
|
* @hide
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class NativeLlcpConnectionlessSocket {
|
public class NativeLlcpConnectionlessSocket {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ package com.trustedlogic.trustednfc.android.internal;
|
|||||||
/**
|
/**
|
||||||
* LlcpClientSocket represents a LLCP Connection-Oriented client to be used in a
|
* LlcpClientSocket represents a LLCP Connection-Oriented client to be used in a
|
||||||
* connection-oriented communication
|
* connection-oriented communication
|
||||||
* {@hide}
|
* @hide
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class NativeLlcpSocket {
|
public class NativeLlcpSocket {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ package com.trustedlogic.trustednfc.android.internal;
|
|||||||
/**
|
/**
|
||||||
* Native interface to the NDEF tag functions
|
* Native interface to the NDEF tag functions
|
||||||
*
|
*
|
||||||
* {@hide}
|
* @hide
|
||||||
*/
|
*/
|
||||||
public class NativeNdefTag {
|
public class NativeNdefTag {
|
||||||
private int mHandle;
|
private int mHandle;
|
||||||
|
|||||||
@@ -24,18 +24,22 @@ package com.trustedlogic.trustednfc.android.internal;
|
|||||||
|
|
||||||
import android.annotation.SdkConstant;
|
import android.annotation.SdkConstant;
|
||||||
import android.annotation.SdkConstant.SdkConstantType;
|
import android.annotation.SdkConstant.SdkConstantType;
|
||||||
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.trustedlogic.trustednfc.android.NfcManager;
|
import android.nfc.FormatException;
|
||||||
import com.trustedlogic.trustednfc.android.NdefMessage;
|
import android.nfc.NdefTag;
|
||||||
import com.trustedlogic.trustednfc.android.NfcTag;
|
import android.nfc.NfcAdapter;
|
||||||
|
import android.nfc.NdefMessage;
|
||||||
|
import android.nfc.Tag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Native interface to the NFC Manager functions {@hide}
|
* Native interface to the NFC Manager functions
|
||||||
|
* @hide
|
||||||
*/
|
*/
|
||||||
public class NativeNfcManager {
|
public class NativeNfcManager {
|
||||||
|
|
||||||
@@ -51,9 +55,9 @@ public class NativeNfcManager {
|
|||||||
/* Native structure */
|
/* Native structure */
|
||||||
private int mNative;
|
private int mNative;
|
||||||
|
|
||||||
private Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
private Handler mNfcHandler;
|
private final Handler mNfcHandler;
|
||||||
|
|
||||||
private static final String TAG = "NativeNfcManager";
|
private static final String TAG = "NativeNfcManager";
|
||||||
|
|
||||||
@@ -130,45 +134,81 @@ public class NativeNfcManager {
|
|||||||
public native boolean doActivateLlcp();
|
public native boolean doActivateLlcp();
|
||||||
|
|
||||||
private class NfcHandler extends Handler {
|
private class NfcHandler extends Handler {
|
||||||
|
|
||||||
|
private int convertType(String typeName) {
|
||||||
|
if (typeName.equals("Iso14443")) {
|
||||||
|
return Tag.NFC_TAG_ISO14443_4B;
|
||||||
|
} else if (typeName.equals("MifareUL")) {
|
||||||
|
return Tag.NFC_TAG_MIFARE;
|
||||||
|
} else if (typeName.equals("Mifare1K")) {
|
||||||
|
return Tag.NFC_TAG_MIFARE;
|
||||||
|
} else if (typeName.equals("Mifare4K")) {
|
||||||
|
return Tag.NFC_TAG_MIFARE;
|
||||||
|
} else if (typeName.equals("MifareDESFIRE")) {
|
||||||
|
return Tag.NFC_TAG_MIFARE;
|
||||||
|
} else if (typeName.equals("Unknown Mifare")) {
|
||||||
|
return Tag.NFC_TAG_MIFARE;
|
||||||
|
} else if (typeName.equals("Felica")) {
|
||||||
|
return Tag.NFC_TAG_FELICA;
|
||||||
|
} else if (typeName.equals("Jewel")) {
|
||||||
|
return Tag.NFC_TAG_JEWEL;
|
||||||
|
} else {
|
||||||
|
return Tag.NFC_TAG_OTHER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case MSG_NDEF_TAG:
|
case MSG_NDEF_TAG:
|
||||||
Log.d(TAG, "Checking for NDEF tag message");
|
Log.d(TAG, "Tag detected, notifying applications");
|
||||||
NativeNfcTag tag = (NativeNfcTag) msg.obj;
|
NativeNfcTag nativeTag = (NativeNfcTag) msg.obj;
|
||||||
if (tag.doConnect()) {
|
if (nativeTag.doConnect()) {
|
||||||
if (tag.checkNDEF()) {
|
if (nativeTag.checkNDEF()) {
|
||||||
byte[] buff = tag.doRead();
|
byte[] buff = nativeTag.doRead();
|
||||||
if (buff != null) {
|
if (buff != null) {
|
||||||
NdefMessage msgNdef = new NdefMessage(buff);
|
NdefMessage[] msgNdef = new NdefMessage[1];
|
||||||
if (msgNdef != null) {
|
try {
|
||||||
/* Send broadcast ordered */
|
msgNdef[0] = new NdefMessage(buff);
|
||||||
Intent NdefMessageIntent = new Intent();
|
NdefTag tag = new NdefTag(convertType(nativeTag.getType()), nativeTag.getUid(), nativeTag.getHandle(), msgNdef);
|
||||||
NdefMessageIntent
|
Intent intent = new Intent();
|
||||||
.setAction(NfcManager.NDEF_TAG_DISCOVERED_ACTION);
|
intent.setAction(NfcAdapter.ACTION_NDEF_TAG_DISCOVERED);
|
||||||
NdefMessageIntent.putExtra(NfcManager.NDEF_MESSAGE_EXTRA,
|
intent.putExtra(NfcAdapter.EXTRA_TAG, tag);
|
||||||
msgNdef);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
Log.d(TAG, "NDEF message found, broadcasting to applications");
|
Log.d(TAG, "NDEF tag found, starting corresponding activity");
|
||||||
mContext.sendOrderedBroadcast(NdefMessageIntent,
|
try {
|
||||||
android.Manifest.permission.NFC_NOTIFY);
|
mContext.startActivity(intent);
|
||||||
/* Disconnect tag */
|
} catch (ActivityNotFoundException e) {
|
||||||
tag.doAsyncDisconnect();
|
Log.w(TAG, "No activity found, disconnecting");
|
||||||
|
nativeTag.doAsyncDisconnect();
|
||||||
|
}
|
||||||
|
} catch (FormatException e) {
|
||||||
|
Log.w(TAG, "Unable to create NDEF message object (tag empty or not well formated)");
|
||||||
|
nativeTag.doAsyncDisconnect();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "Unable to read NDEF message (tag empty or not well formated)");
|
Log.w(TAG, "Unable to read NDEF message (tag empty or not well formated)");
|
||||||
/* Disconnect tag */
|
nativeTag.doAsyncDisconnect();
|
||||||
tag.doAsyncDisconnect();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Tag is *not* NDEF compliant");
|
Intent intent = new Intent();
|
||||||
/* Disconnect tag */
|
Tag tag = new Tag(convertType(nativeTag.getType()), false, nativeTag.getUid(), nativeTag.getHandle());
|
||||||
tag.doAsyncDisconnect();
|
intent.setAction(NfcAdapter.ACTION_TAG_DISCOVERED);
|
||||||
|
intent.putExtra(NfcAdapter.EXTRA_TAG, tag);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
Log.d(TAG, "Non-NDEF tag found, starting corresponding activity");
|
||||||
|
try {
|
||||||
|
mContext.startActivity(intent);
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
Log.w(TAG, "No activity found, disconnecting");
|
||||||
|
nativeTag.doAsyncDisconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Disconnect tag */
|
Log.w(TAG, "Failed to connect to tag");
|
||||||
tag.doAsyncDisconnect();
|
nativeTag.doAsyncDisconnect();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MSG_CARD_EMULATION:
|
case MSG_CARD_EMULATION:
|
||||||
@@ -176,8 +216,8 @@ public class NativeNfcManager {
|
|||||||
byte[] aid = (byte[]) msg.obj;
|
byte[] aid = (byte[]) msg.obj;
|
||||||
/* Send broadcast ordered */
|
/* Send broadcast ordered */
|
||||||
Intent TransactionIntent = new Intent();
|
Intent TransactionIntent = new Intent();
|
||||||
TransactionIntent.setAction(NfcManager.TRANSACTION_DETECTED_ACTION);
|
TransactionIntent.setAction(NfcAdapter.ACTION_TRANSACTION_DETECTED);
|
||||||
TransactionIntent.putExtra(NfcManager.AID_EXTRA, aid);
|
TransactionIntent.putExtra(NfcAdapter.EXTRA_AID, aid);
|
||||||
Log.d(TAG, "Broadcasting Card Emulation event");
|
Log.d(TAG, "Broadcasting Card Emulation event");
|
||||||
mContext.sendOrderedBroadcast(TransactionIntent,
|
mContext.sendOrderedBroadcast(TransactionIntent,
|
||||||
android.Manifest.permission.NFC_NOTIFY);
|
android.Manifest.permission.NFC_NOTIFY);
|
||||||
@@ -201,7 +241,7 @@ public class NativeNfcManager {
|
|||||||
.setAction(INTERNAL_LLCP_LINK_STATE_CHANGED_ACTION);
|
.setAction(INTERNAL_LLCP_LINK_STATE_CHANGED_ACTION);
|
||||||
LlcpLinkIntent.putExtra(
|
LlcpLinkIntent.putExtra(
|
||||||
INTERNAL_LLCP_LINK_STATE_CHANGED_EXTRA,
|
INTERNAL_LLCP_LINK_STATE_CHANGED_EXTRA,
|
||||||
NfcManager.LLCP_LINK_STATE_ACTIVATED);
|
NfcAdapter.LLCP_LINK_STATE_ACTIVATED);
|
||||||
Log.d(TAG, "Broadcasting internal LLCP activation");
|
Log.d(TAG, "Broadcasting internal LLCP activation");
|
||||||
mContext.sendBroadcast(LlcpLinkIntent);
|
mContext.sendBroadcast(LlcpLinkIntent);
|
||||||
}
|
}
|
||||||
@@ -223,7 +263,7 @@ public class NativeNfcManager {
|
|||||||
LlcpLinkIntent
|
LlcpLinkIntent
|
||||||
.setAction(INTERNAL_LLCP_LINK_STATE_CHANGED_ACTION);
|
.setAction(INTERNAL_LLCP_LINK_STATE_CHANGED_ACTION);
|
||||||
LlcpLinkIntent.putExtra(INTERNAL_LLCP_LINK_STATE_CHANGED_EXTRA,
|
LlcpLinkIntent.putExtra(INTERNAL_LLCP_LINK_STATE_CHANGED_EXTRA,
|
||||||
NfcManager.LLCP_LINK_STATE_ACTIVATED);
|
NfcAdapter.LLCP_LINK_STATE_ACTIVATED);
|
||||||
Log.d(TAG, "Broadcasting internal LLCP activation");
|
Log.d(TAG, "Broadcasting internal LLCP activation");
|
||||||
mContext.sendBroadcast(LlcpLinkIntent);
|
mContext.sendBroadcast(LlcpLinkIntent);
|
||||||
}
|
}
|
||||||
@@ -235,9 +275,9 @@ public class NativeNfcManager {
|
|||||||
/* Broadcast Intent Link LLCP activated */
|
/* Broadcast Intent Link LLCP activated */
|
||||||
Log.d(TAG, "LLCP Link Deactivated message");
|
Log.d(TAG, "LLCP Link Deactivated message");
|
||||||
Intent LlcpLinkIntent = new Intent();
|
Intent LlcpLinkIntent = new Intent();
|
||||||
LlcpLinkIntent.setAction(NfcManager.LLCP_LINK_STATE_CHANGED_ACTION);
|
LlcpLinkIntent.setAction(NfcAdapter.ACTION_LLCP_LINK_STATE_CHANGED);
|
||||||
LlcpLinkIntent.putExtra(NfcManager.LLCP_LINK_STATE_CHANGED_EXTRA,
|
LlcpLinkIntent.putExtra(NfcAdapter.EXTRA_LLCP_LINK_STATE_CHANGED,
|
||||||
NfcManager.LLCP_LINK_STATE_DEACTIVATED);
|
NfcAdapter.LLCP_LINK_STATE_DEACTIVATED);
|
||||||
Log.d(TAG, "Broadcasting LLCP deactivation");
|
Log.d(TAG, "Broadcasting LLCP deactivation");
|
||||||
mContext.sendOrderedBroadcast(LlcpLinkIntent,
|
mContext.sendOrderedBroadcast(LlcpLinkIntent,
|
||||||
android.Manifest.permission.NFC_LLCP);
|
android.Manifest.permission.NFC_LLCP);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ package com.trustedlogic.trustednfc.android.internal;
|
|||||||
/**
|
/**
|
||||||
* Native interface to the NFC tag functions
|
* Native interface to the NFC tag functions
|
||||||
*
|
*
|
||||||
* {@hide}
|
* @hide
|
||||||
*/
|
*/
|
||||||
public class NativeNfcTag {
|
public class NativeNfcTag {
|
||||||
private int mHandle;
|
private int mHandle;
|
||||||
@@ -48,6 +48,15 @@ public class NativeNfcTag {
|
|||||||
|
|
||||||
public native boolean doWrite(byte[] buf);
|
public native boolean doWrite(byte[] buf);
|
||||||
|
|
||||||
|
private NativeNfcTag() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public NativeNfcTag(int handle, String type, byte[] uid) {
|
||||||
|
mHandle = handle;
|
||||||
|
mType = type;
|
||||||
|
mUid = uid.clone();
|
||||||
|
}
|
||||||
|
|
||||||
public int getHandle() {
|
public int getHandle() {
|
||||||
return mHandle;
|
return mHandle;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ package com.trustedlogic.trustednfc.android.internal;
|
|||||||
/**
|
/**
|
||||||
* Native interface to the P2P Initiator functions
|
* Native interface to the P2P Initiator functions
|
||||||
*
|
*
|
||||||
* {@hide}
|
* @hide
|
||||||
*/
|
*/
|
||||||
public class NativeP2pDevice {
|
public class NativeP2pDevice {
|
||||||
|
|
||||||
|
|||||||
@@ -86,9 +86,10 @@
|
|||||||
<protected-broadcast android:name="android.hardware.action.USB_DISCONNECTED" />
|
<protected-broadcast android:name="android.hardware.action.USB_DISCONNECTED" />
|
||||||
<protected-broadcast android:name="android.hardware.action.USB_STATE" />
|
<protected-broadcast android:name="android.hardware.action.USB_STATE" />
|
||||||
|
|
||||||
<protected-broadcast android:name="com.trustedlogic.trustednfc.android.action.NDEF_TAG_DISCOVERED" />
|
<protected-broadcast android:name="android.nfc.action.NDEF_TAG_DISCOVERED" />
|
||||||
<protected-broadcast android:name="com.trustedlogic.trustednfc.android.action.TRANSACTION_DETECTED" />
|
<protected-broadcast android:name="android.nfc.action.TAG_DISCOVERED" />
|
||||||
<protected-broadcast android:name="com.trustedlogic.trustednfc.android.action.LLCP_LINK_STATE_CHANGED" />
|
<protected-broadcast android:name="android.nfc.action.LLCP_LINK_STATE_CHANGED" />
|
||||||
|
<protected-broadcast android:name="android.nfc.action.TRANSACTION_DETECTED" />
|
||||||
|
|
||||||
<!-- ====================================== -->
|
<!-- ====================================== -->
|
||||||
<!-- Permissions for things that cost money -->
|
<!-- Permissions for things that cost money -->
|
||||||
|
|||||||
@@ -17,44 +17,43 @@
|
|||||||
package com.trustedlogic.trustednfc.android.server;
|
package com.trustedlogic.trustednfc.android.server;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.trustedlogic.trustednfc.android.ILlcpConnectionlessSocket;
|
import android.nfc.ErrorCodes;
|
||||||
import com.trustedlogic.trustednfc.android.ILlcpServiceSocket;
|
import android.nfc.FormatException;
|
||||||
import com.trustedlogic.trustednfc.android.INfcManager;
|
import android.nfc.ILlcpConnectionlessSocket;
|
||||||
import com.trustedlogic.trustednfc.android.ILlcpSocket;
|
import android.nfc.ILlcpServiceSocket;
|
||||||
import com.trustedlogic.trustednfc.android.INfcTag;
|
import android.nfc.INfcAdapter;
|
||||||
import com.trustedlogic.trustednfc.android.IP2pInitiator;
|
import android.nfc.ILlcpSocket;
|
||||||
import com.trustedlogic.trustednfc.android.IP2pTarget;
|
import android.nfc.INfcTag;
|
||||||
import com.trustedlogic.trustednfc.android.LlcpPacket;
|
import android.nfc.IP2pInitiator;
|
||||||
import com.trustedlogic.trustednfc.android.NdefMessage;
|
import android.nfc.IP2pTarget;
|
||||||
import com.trustedlogic.trustednfc.android.NfcException;
|
import android.nfc.LlcpPacket;
|
||||||
import com.trustedlogic.trustednfc.android.NfcManager;
|
import android.nfc.NdefMessage;
|
||||||
|
import android.nfc.Tag;
|
||||||
|
//import android.nfc.NfcException;
|
||||||
|
//import android.nfc.NfcManager;
|
||||||
|
import android.nfc.NfcAdapter;
|
||||||
import com.trustedlogic.trustednfc.android.internal.NativeLlcpConnectionlessSocket;
|
import com.trustedlogic.trustednfc.android.internal.NativeLlcpConnectionlessSocket;
|
||||||
import com.trustedlogic.trustednfc.android.internal.NativeLlcpServiceSocket;
|
import com.trustedlogic.trustednfc.android.internal.NativeLlcpServiceSocket;
|
||||||
import com.trustedlogic.trustednfc.android.internal.NativeLlcpSocket;
|
import com.trustedlogic.trustednfc.android.internal.NativeLlcpSocket;
|
||||||
import com.trustedlogic.trustednfc.android.internal.NativeNfcManager;
|
import com.trustedlogic.trustednfc.android.internal.NativeNfcManager;
|
||||||
import com.trustedlogic.trustednfc.android.internal.NativeNfcTag;
|
import com.trustedlogic.trustednfc.android.internal.NativeNfcTag;
|
||||||
import com.trustedlogic.trustednfc.android.internal.NativeP2pDevice;
|
import com.trustedlogic.trustednfc.android.internal.NativeP2pDevice;
|
||||||
import com.trustedlogic.trustednfc.android.internal.ErrorCodes;
|
|
||||||
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.provider.Settings.SettingNotFoundException;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
|
||||||
public class NfcService extends INfcManager.Stub implements Runnable {
|
public class NfcService extends INfcAdapter.Stub implements Runnable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NFC Service tag
|
* NFC Service tag
|
||||||
@@ -188,15 +187,15 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
|
|
||||||
private static final String PROPERTY_NFC_DISCOVERY_NFCIP_VALUE = "discovery.nfcip";
|
private static final String PROPERTY_NFC_DISCOVERY_NFCIP_VALUE = "discovery.nfcip";
|
||||||
|
|
||||||
private Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
private HashMap<Integer, Object> mObjectMap = new HashMap<Integer, Object>();
|
private final HashMap<Integer, Object> mObjectMap = new HashMap<Integer, Object>();
|
||||||
|
|
||||||
private HashMap<Integer, Object> mSocketMap = new HashMap<Integer, Object>();
|
private final HashMap<Integer, Object> mSocketMap = new HashMap<Integer, Object>();
|
||||||
|
|
||||||
private LinkedList<RegisteredSocket> mRegisteredSocketList = new LinkedList<RegisteredSocket>();
|
private final LinkedList<RegisteredSocket> mRegisteredSocketList = new LinkedList<RegisteredSocket>();
|
||||||
|
|
||||||
private int mLlcpLinkState = NfcManager.LLCP_LINK_STATE_DEACTIVATED;
|
private int mLlcpLinkState = NfcAdapter.LLCP_LINK_STATE_DEACTIVATED;
|
||||||
|
|
||||||
private int mGeneratedSocketHandle = 0;
|
private int mGeneratedSocketHandle = 0;
|
||||||
|
|
||||||
@@ -216,9 +215,42 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
|
|
||||||
private boolean mOpenPending = false;
|
private boolean mOpenPending = false;
|
||||||
|
|
||||||
private NativeNfcManager mManager;
|
private final NativeNfcManager mManager;
|
||||||
|
|
||||||
private ILlcpSocket mLlcpSocket = new ILlcpSocket.Stub() {
|
private final ILlcpSocket mLlcpSocket = new ILlcpSocket.Stub() {
|
||||||
|
|
||||||
|
private final int CONNECT_FLAG = 0x01;
|
||||||
|
private final int CLOSE_FLAG = 0x02;
|
||||||
|
private final int RECV_FLAG = 0x04;
|
||||||
|
private final int SEND_FLAG = 0x08;
|
||||||
|
|
||||||
|
private int concurrencyFlags;
|
||||||
|
private Object sync;
|
||||||
|
|
||||||
|
private void enterCritical(int mask, int current) {
|
||||||
|
int result = -1;
|
||||||
|
try {
|
||||||
|
while (result != 0) {
|
||||||
|
synchronized(this) {
|
||||||
|
result = concurrencyFlags & mask;
|
||||||
|
}
|
||||||
|
sync.wait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(InterruptedException e) {
|
||||||
|
}
|
||||||
|
// Set flag
|
||||||
|
concurrencyFlags |= current;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void leaveCritical(int current) {
|
||||||
|
synchronized(this) {
|
||||||
|
// Clear flag
|
||||||
|
concurrencyFlags &= ~current;
|
||||||
|
}
|
||||||
|
// Release waiting threads
|
||||||
|
sync.notifyAll();
|
||||||
|
}
|
||||||
|
|
||||||
public int close(int nativeHandle) throws RemoteException {
|
public int close(int nativeHandle) throws RemoteException {
|
||||||
NativeLlcpSocket socket = null;
|
NativeLlcpSocket socket = null;
|
||||||
@@ -232,7 +264,7 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
/* find the socket in the hmap */
|
/* find the socket in the hmap */
|
||||||
socket = (NativeLlcpSocket) findSocket(nativeHandle);
|
socket = (NativeLlcpSocket) findSocket(nativeHandle);
|
||||||
if (socket != null) {
|
if (socket != null) {
|
||||||
if (mLlcpLinkState == NfcManager.LLCP_LINK_STATE_ACTIVATED) {
|
if (mLlcpLinkState == NfcAdapter.LLCP_LINK_STATE_ACTIVATED) {
|
||||||
isSuccess = socket.doClose();
|
isSuccess = socket.doClose();
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
/* Remove the socket closed from the hmap */
|
/* Remove the socket closed from the hmap */
|
||||||
@@ -476,7 +508,7 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private ILlcpServiceSocket mLlcpServerSocketService = new ILlcpServiceSocket.Stub() {
|
private final ILlcpServiceSocket mLlcpServerSocketService = new ILlcpServiceSocket.Stub() {
|
||||||
|
|
||||||
public int accept(int nativeHandle) throws RemoteException {
|
public int accept(int nativeHandle) throws RemoteException {
|
||||||
NativeLlcpServiceSocket socket = null;
|
NativeLlcpServiceSocket socket = null;
|
||||||
@@ -522,7 +554,7 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
/* find the socket in the hmap */
|
/* find the socket in the hmap */
|
||||||
socket = (NativeLlcpServiceSocket) findSocket(nativeHandle);
|
socket = (NativeLlcpServiceSocket) findSocket(nativeHandle);
|
||||||
if (socket != null) {
|
if (socket != null) {
|
||||||
if (mLlcpLinkState == NfcManager.LLCP_LINK_STATE_ACTIVATED) {
|
if (mLlcpLinkState == NfcAdapter.LLCP_LINK_STATE_ACTIVATED) {
|
||||||
isSuccess = socket.doClose();
|
isSuccess = socket.doClose();
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
/* Remove the socket closed from the hmap */
|
/* Remove the socket closed from the hmap */
|
||||||
@@ -571,7 +603,7 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private ILlcpConnectionlessSocket mLlcpConnectionlessSocketService = new ILlcpConnectionlessSocket.Stub() {
|
private final ILlcpConnectionlessSocket mLlcpConnectionlessSocketService = new ILlcpConnectionlessSocket.Stub() {
|
||||||
|
|
||||||
public void close(int nativeHandle) throws RemoteException {
|
public void close(int nativeHandle) throws RemoteException {
|
||||||
NativeLlcpConnectionlessSocket socket = null;
|
NativeLlcpConnectionlessSocket socket = null;
|
||||||
@@ -585,7 +617,7 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
/* find the socket in the hmap */
|
/* find the socket in the hmap */
|
||||||
socket = (NativeLlcpConnectionlessSocket) findSocket(nativeHandle);
|
socket = (NativeLlcpConnectionlessSocket) findSocket(nativeHandle);
|
||||||
if (socket != null) {
|
if (socket != null) {
|
||||||
if (mLlcpLinkState == NfcManager.LLCP_LINK_STATE_ACTIVATED) {
|
if (mLlcpLinkState == NfcAdapter.LLCP_LINK_STATE_ACTIVATED) {
|
||||||
isSuccess = socket.doClose();
|
isSuccess = socket.doClose();
|
||||||
if (isSuccess) {
|
if (isSuccess) {
|
||||||
/* Remove the socket closed from the hmap */
|
/* Remove the socket closed from the hmap */
|
||||||
@@ -669,7 +701,7 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private INfcTag mNfcTagService = new INfcTag.Stub() {
|
private final INfcTag mNfcTagService = new INfcTag.Stub() {
|
||||||
|
|
||||||
public int close(int nativeHandle) throws RemoteException {
|
public int close(int nativeHandle) throws RemoteException {
|
||||||
NativeNfcTag tag = null;
|
NativeNfcTag tag = null;
|
||||||
@@ -807,34 +839,55 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
/* Create an NdefMessage */
|
/* Create an NdefMessage */
|
||||||
try {
|
try {
|
||||||
return new NdefMessage(buf);
|
return new NdefMessage(buf);
|
||||||
} catch (NfcException e) {
|
} catch (FormatException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean write(int nativeHandle, NdefMessage msg) throws RemoteException {
|
public int write(int nativeHandle, NdefMessage msg) throws RemoteException {
|
||||||
NativeNfcTag tag;
|
NativeNfcTag tag;
|
||||||
boolean isSuccess = false;
|
|
||||||
|
|
||||||
// Check if NFC is enabled
|
// Check if NFC is enabled
|
||||||
if (!mIsNfcEnabled) {
|
if (!mIsNfcEnabled) {
|
||||||
return isSuccess;
|
return ErrorCodes.ERROR_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find the tag in the hmap */
|
/* find the tag in the hmap */
|
||||||
tag = (NativeNfcTag) findObject(nativeHandle);
|
tag = (NativeNfcTag) findObject(nativeHandle);
|
||||||
if (tag != null) {
|
if (tag == null) {
|
||||||
isSuccess = tag.doWrite(msg.toByteArray());
|
return ErrorCodes.ERROR_IO;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag.doWrite(msg.toByteArray())) {
|
||||||
|
return ErrorCodes.SUCCESS;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return ErrorCodes.ERROR_IO;
|
||||||
}
|
}
|
||||||
return isSuccess;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getLastError(int nativeHandle) throws RemoteException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getModeHint(int nativeHandle) throws RemoteException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int makeReadOnly(int nativeHandle) throws RemoteException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private IP2pInitiator mP2pInitiatorService = new IP2pInitiator.Stub() {
|
private final IP2pInitiator mP2pInitiatorService = new IP2pInitiator.Stub() {
|
||||||
|
|
||||||
public byte[] getGeneralBytes(int nativeHandle) throws RemoteException {
|
public byte[] getGeneralBytes(int nativeHandle) throws RemoteException {
|
||||||
NativeP2pDevice device;
|
NativeP2pDevice device;
|
||||||
@@ -911,7 +964,7 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private IP2pTarget mP2pTargetService = new IP2pTarget.Stub() {
|
private final IP2pTarget mP2pTargetService = new IP2pTarget.Stub() {
|
||||||
|
|
||||||
public int connect(int nativeHandle) throws RemoteException {
|
public int connect(int nativeHandle) throws RemoteException {
|
||||||
NativeP2pDevice device;
|
NativeP2pDevice device;
|
||||||
@@ -1033,7 +1086,7 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
NativeNfcManager.INTERNAL_LLCP_LINK_STATE_CHANGED_ACTION));
|
NativeNfcManager.INTERNAL_LLCP_LINK_STATE_CHANGED_ACTION));
|
||||||
|
|
||||||
mContext.registerReceiver(mNfcServiceReceiver, new IntentFilter(
|
mContext.registerReceiver(mNfcServiceReceiver, new IntentFilter(
|
||||||
NfcManager.LLCP_LINK_STATE_CHANGED_ACTION));
|
NfcAdapter.ACTION_LLCP_LINK_STATE_CHANGED));
|
||||||
|
|
||||||
mContext.registerReceiver(mNfcServiceReceiver, new IntentFilter(
|
mContext.registerReceiver(mNfcServiceReceiver, new IntentFilter(
|
||||||
NativeNfcManager.INTERNAL_TARGET_DESELECTED_ACTION));
|
NativeNfcManager.INTERNAL_TARGET_DESELECTED_ACTION));
|
||||||
@@ -1088,7 +1141,7 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
/* Store the socket handle */
|
/* Store the socket handle */
|
||||||
int sockeHandle = mGeneratedSocketHandle;
|
int sockeHandle = mGeneratedSocketHandle;
|
||||||
|
|
||||||
if (mLlcpLinkState == NfcManager.LLCP_LINK_STATE_ACTIVATED) {
|
if (mLlcpLinkState == NfcAdapter.LLCP_LINK_STATE_ACTIVATED) {
|
||||||
NativeLlcpConnectionlessSocket socket;
|
NativeLlcpConnectionlessSocket socket;
|
||||||
|
|
||||||
socket = mManager.doCreateLlcpConnectionlessSocket(sap);
|
socket = mManager.doCreateLlcpConnectionlessSocket(sap);
|
||||||
@@ -1167,7 +1220,7 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
if (mNbSocketCreated < LLCP_SOCKET_NB_MAX) {
|
if (mNbSocketCreated < LLCP_SOCKET_NB_MAX) {
|
||||||
int sockeHandle = mGeneratedSocketHandle;
|
int sockeHandle = mGeneratedSocketHandle;
|
||||||
|
|
||||||
if (mLlcpLinkState == NfcManager.LLCP_LINK_STATE_ACTIVATED) {
|
if (mLlcpLinkState == NfcAdapter.LLCP_LINK_STATE_ACTIVATED) {
|
||||||
NativeLlcpServiceSocket socket;
|
NativeLlcpServiceSocket socket;
|
||||||
|
|
||||||
socket = mManager.doCreateLlcpServiceSocket(sap, sn, miu, rw, linearBufferLength);
|
socket = mManager.doCreateLlcpServiceSocket(sap, sn, miu, rw, linearBufferLength);
|
||||||
@@ -1251,7 +1304,7 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
|
|
||||||
int sockeHandle = mGeneratedSocketHandle;
|
int sockeHandle = mGeneratedSocketHandle;
|
||||||
|
|
||||||
if (mLlcpLinkState == NfcManager.LLCP_LINK_STATE_ACTIVATED) {
|
if (mLlcpLinkState == NfcAdapter.LLCP_LINK_STATE_ACTIVATED) {
|
||||||
NativeLlcpSocket socket;
|
NativeLlcpSocket socket;
|
||||||
|
|
||||||
socket = mManager.doCreateLlcpSocket(sap, miu, rw, linearBufferLength);
|
socket = mManager.doCreateLlcpSocket(sap, miu, rw, linearBufferLength);
|
||||||
@@ -1615,30 +1668,10 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int openTagConnection() throws RemoteException {
|
public void openTagConnection(Tag tag) throws RemoteException {
|
||||||
NativeNfcTag tag;
|
NativeNfcTag nativeTag = new NativeNfcTag(tag.getHandle(), "", tag.getId());
|
||||||
// Check if NFC is enabled
|
|
||||||
if (!mIsNfcEnabled) {
|
|
||||||
return ErrorCodes.ERROR_NOT_INITIALIZED;
|
|
||||||
}
|
|
||||||
|
|
||||||
mContext.enforceCallingPermission(android.Manifest.permission.NFC_RAW,
|
mObjectMap.put(nativeTag.getHandle(), nativeTag);
|
||||||
"NFC_RAW permission required to open NFC Tag connection");
|
|
||||||
if (!mOpenPending) {
|
|
||||||
mOpenPending = true;
|
|
||||||
tag = mManager.doOpenTagConnection(mTimeout);
|
|
||||||
if (tag != null) {
|
|
||||||
mObjectMap.put(tag.getHandle(), tag);
|
|
||||||
return tag.getHandle();
|
|
||||||
} else {
|
|
||||||
mOpenPending = false;
|
|
||||||
/* Restart polling loop for notification */
|
|
||||||
mManager.enableDiscovery(DISCOVERY_MODE_READER);
|
|
||||||
return ErrorCodes.ERROR_IO;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return ErrorCodes.ERROR_BUSY;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int selectSecureElement(int seId) throws RemoteException {
|
public int selectSecureElement(int seId) throws RemoteException {
|
||||||
@@ -1847,6 +1880,16 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
return ErrorCodes.SUCCESS;
|
return ErrorCodes.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NdefMessage localGet() throws RemoteException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void localSet(NdefMessage message) throws RemoteException {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Reset all internals
|
// Reset all internals
|
||||||
private void reset() {
|
private void reset() {
|
||||||
|
|
||||||
@@ -1856,7 +1899,7 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
mRegisteredSocketList.clear();
|
mRegisteredSocketList.clear();
|
||||||
|
|
||||||
// Reset variables
|
// Reset variables
|
||||||
mLlcpLinkState = NfcManager.LLCP_LINK_STATE_DEACTIVATED;
|
mLlcpLinkState = NfcAdapter.LLCP_LINK_STATE_DEACTIVATED;
|
||||||
mNbSocketCreated = 0;
|
mNbSocketCreated = 0;
|
||||||
mIsNfcEnabled = false;
|
mIsNfcEnabled = false;
|
||||||
mSelectedSeId = 0;
|
mSelectedSeId = 0;
|
||||||
@@ -1869,6 +1912,9 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
Object device = null;
|
Object device = null;
|
||||||
|
|
||||||
device = mObjectMap.get(key);
|
device = mObjectMap.get(key);
|
||||||
|
if (device == null) {
|
||||||
|
Log.w(TAG, "Handle not found !");
|
||||||
|
}
|
||||||
|
|
||||||
return device;
|
return device;
|
||||||
}
|
}
|
||||||
@@ -1947,11 +1993,11 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
* LLCP link in not activated
|
* LLCP link in not activated
|
||||||
*/
|
*/
|
||||||
private class RegisteredSocket {
|
private class RegisteredSocket {
|
||||||
private int mType;
|
private final int mType;
|
||||||
|
|
||||||
private int mHandle;
|
private final int mHandle;
|
||||||
|
|
||||||
private int mSap;
|
private final int mSap;
|
||||||
|
|
||||||
private int mMiu;
|
private int mMiu;
|
||||||
|
|
||||||
@@ -1988,17 +2034,17 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BroadcastReceiver mNfcServiceReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mNfcServiceReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Log.d(TAG, "Internal NFC Intent received");
|
Log.d(TAG, "Internal NFC Intent received");
|
||||||
|
|
||||||
/* LLCP Link deactivation */
|
/* LLCP Link deactivation */
|
||||||
if (intent.getAction().equals(NfcManager.LLCP_LINK_STATE_CHANGED_ACTION)) {
|
if (intent.getAction().equals(NfcAdapter.ACTION_LLCP_LINK_STATE_CHANGED)) {
|
||||||
mLlcpLinkState = intent.getIntExtra(NfcManager.LLCP_LINK_STATE_CHANGED_EXTRA,
|
mLlcpLinkState = intent.getIntExtra(NfcAdapter.EXTRA_LLCP_LINK_STATE_CHANGED,
|
||||||
NfcManager.LLCP_LINK_STATE_DEACTIVATED);
|
NfcAdapter.LLCP_LINK_STATE_DEACTIVATED);
|
||||||
|
|
||||||
if (mLlcpLinkState == NfcManager.LLCP_LINK_STATE_DEACTIVATED) {
|
if (mLlcpLinkState == NfcAdapter.LLCP_LINK_STATE_DEACTIVATED) {
|
||||||
/* restart polling loop */
|
/* restart polling loop */
|
||||||
mManager.enableDiscovery(DISCOVERY_MODE_READER);
|
mManager.enableDiscovery(DISCOVERY_MODE_READER);
|
||||||
}
|
}
|
||||||
@@ -2010,9 +2056,9 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
|
|
||||||
mLlcpLinkState = intent.getIntExtra(
|
mLlcpLinkState = intent.getIntExtra(
|
||||||
NativeNfcManager.INTERNAL_LLCP_LINK_STATE_CHANGED_EXTRA,
|
NativeNfcManager.INTERNAL_LLCP_LINK_STATE_CHANGED_EXTRA,
|
||||||
NfcManager.LLCP_LINK_STATE_DEACTIVATED);
|
NfcAdapter.LLCP_LINK_STATE_DEACTIVATED);
|
||||||
|
|
||||||
if (mLlcpLinkState == NfcManager.LLCP_LINK_STATE_ACTIVATED) {
|
if (mLlcpLinkState == NfcAdapter.LLCP_LINK_STATE_ACTIVATED) {
|
||||||
/* check if sockets are registered */
|
/* check if sockets are registered */
|
||||||
ListIterator<RegisteredSocket> it = mRegisteredSocketList.listIterator();
|
ListIterator<RegisteredSocket> it = mRegisteredSocketList.listIterator();
|
||||||
|
|
||||||
@@ -2086,10 +2132,10 @@ public class NfcService extends INfcManager.Stub implements Runnable {
|
|||||||
|
|
||||||
/* Broadcast Intent Link LLCP activated */
|
/* Broadcast Intent Link LLCP activated */
|
||||||
Intent LlcpLinkIntent = new Intent();
|
Intent LlcpLinkIntent = new Intent();
|
||||||
LlcpLinkIntent.setAction(NfcManager.LLCP_LINK_STATE_CHANGED_ACTION);
|
LlcpLinkIntent.setAction(NfcAdapter.ACTION_LLCP_LINK_STATE_CHANGED);
|
||||||
|
|
||||||
LlcpLinkIntent.putExtra(NfcManager.LLCP_LINK_STATE_CHANGED_EXTRA,
|
LlcpLinkIntent.putExtra(NfcAdapter.EXTRA_LLCP_LINK_STATE_CHANGED,
|
||||||
NfcManager.LLCP_LINK_STATE_ACTIVATED);
|
NfcAdapter.LLCP_LINK_STATE_ACTIVATED);
|
||||||
|
|
||||||
Log.d(TAG, "Broadcasting LLCP activation");
|
Log.d(TAG, "Broadcasting LLCP activation");
|
||||||
mContext.sendOrderedBroadcast(LlcpLinkIntent,
|
mContext.sendOrderedBroadcast(LlcpLinkIntent,
|
||||||
|
|||||||
Reference in New Issue
Block a user