am d1f7f4a6: Move hidden API\'s Llcp* and P2p* to f/b/c/j/com/android/internal/nfc.
Merge commit 'd1f7f4a68375f879671d300510f23d3ee78a500e' into gingerbread-plus-aosp * commit 'd1f7f4a68375f879671d300510f23d3ee78a500e': Move hidden API's Llcp* and P2p* to f/b/c/j/com/android/internal/nfc.
This commit is contained in:
@@ -14,48 +14,28 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* File : LlcpConnectionLessSocket.java
|
||||
* Original-Author : Trusted Logic S.A. (Daniel Tomas)
|
||||
* Created : 18-02-2010
|
||||
*/
|
||||
|
||||
package com.trustedlogic.trustednfc.android;
|
||||
package com.android.internal.nfc;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import android.nfc.ErrorCodes;
|
||||
import android.nfc.ILlcpConnectionlessSocket;
|
||||
import android.nfc.LlcpPacket;
|
||||
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* LlcpConnectionlessSocket represents a LLCP Connectionless object to be used
|
||||
* in a connectionless communication
|
||||
*
|
||||
* @since AA02.01
|
||||
* @hide
|
||||
*/
|
||||
public class LlcpConnectionlessSocket {
|
||||
|
||||
|
||||
private static final String TAG = "LlcpConnectionlessSocket";
|
||||
|
||||
/**
|
||||
* The handle returned by the NFC service and used to identify the LLCP connectionless socket in
|
||||
* every call of this class.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
protected int mHandle;
|
||||
|
||||
|
||||
/**
|
||||
* The entry point for LLCP Connectionless socket operations.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
protected ILlcpConnectionlessSocket mService;
|
||||
|
||||
@@ -66,7 +46,6 @@ public class LlcpConnectionlessSocket {
|
||||
* @param service The entry point to the Nfc Service for LLCP Connectionless socket class.
|
||||
* @param handle The handle returned by the NFC service and used to identify
|
||||
* the socket in subsequent calls.
|
||||
* @hide
|
||||
*/
|
||||
LlcpConnectionlessSocket(ILlcpConnectionlessSocket service, int handle) {
|
||||
this.mService = service;
|
||||
@@ -79,7 +58,6 @@ public class LlcpConnectionlessSocket {
|
||||
* @param packet Service Access Point number related to a LLCP
|
||||
* Connectionless client and a data buffer to send
|
||||
* @throws IOException if the LLCP link has been lost or deactivated.
|
||||
* @since AA02.01
|
||||
*/
|
||||
public void sendTo(LlcpPacket packet) throws IOException {
|
||||
try {
|
||||
@@ -99,7 +77,6 @@ public class LlcpConnectionlessSocket {
|
||||
* @return data data received from a specific LLCP Connectionless client
|
||||
* @throws IOException if the LLCP link has been lost or deactivated.
|
||||
* @see LlcpPacket
|
||||
* @since AA02.01
|
||||
*/
|
||||
public LlcpPacket receiveFrom() throws IOException {
|
||||
try {
|
||||
@@ -118,8 +95,6 @@ public class LlcpConnectionlessSocket {
|
||||
|
||||
/**
|
||||
* Close the created Connectionless socket.
|
||||
*
|
||||
* @since AA02.01
|
||||
*/
|
||||
public void close() {
|
||||
try {
|
||||
@@ -133,7 +108,6 @@ public class LlcpConnectionlessSocket {
|
||||
* Returns the local Service Access Point number of the socket
|
||||
*
|
||||
* @return sap
|
||||
* @since AA02.01
|
||||
*/
|
||||
public int getSap() {
|
||||
int sap = 0;
|
||||
@@ -14,20 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* File : LLCPException.java
|
||||
* Original-Author : Trusted Logic S.A. (Daniel Tomas)
|
||||
* Created : 24-02-2010
|
||||
*/
|
||||
|
||||
package com.trustedlogic.trustednfc.android;
|
||||
package com.android.internal.nfc;
|
||||
|
||||
/**
|
||||
* Generic exception thrown in case something unexpected happened during a
|
||||
* LLCP communication.
|
||||
*
|
||||
* @since AA02.01
|
||||
* @hide
|
||||
*/
|
||||
public class LlcpException extends Exception {
|
||||
/**
|
||||
@@ -14,29 +14,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* File : LLCPServerSocket.java
|
||||
* Original-Author : Trusted Logic S.A. (Daniel Tomas)
|
||||
* Created : 18-02-2010
|
||||
*/
|
||||
|
||||
package com.trustedlogic.trustednfc.android;
|
||||
package com.android.internal.nfc;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import android.nfc.ErrorCodes;
|
||||
import android.nfc.ILlcpSocket;
|
||||
import android.nfc.ILlcpServiceSocket;
|
||||
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* LlcpServiceSocket represents a LLCP Service to be used in a
|
||||
* Connection-oriented communication
|
||||
*
|
||||
* @since AA02.01
|
||||
* @hide
|
||||
*/
|
||||
public class LlcpServiceSocket {
|
||||
|
||||
@@ -45,15 +35,11 @@ public class LlcpServiceSocket {
|
||||
/**
|
||||
* The handle returned by the NFC service and used to identify the LLCP
|
||||
* Service socket in every call of this class.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
protected int mHandle;
|
||||
|
||||
/**
|
||||
* The entry point for LLCP Service socket operations.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
protected ILlcpServiceSocket mService;
|
||||
|
||||
@@ -92,7 +78,6 @@ public class LlcpServiceSocket {
|
||||
* @param handle
|
||||
* The handle returned by the NFC service and used to identify
|
||||
* the socket in subsequent calls.
|
||||
* @hide
|
||||
*/
|
||||
LlcpServiceSocket(ILlcpServiceSocket service, ILlcpSocket socketService, int handle) {
|
||||
this.mService = service;
|
||||
@@ -112,7 +97,6 @@ public class LlcpServiceSocket {
|
||||
* if not enough ressources are available
|
||||
*
|
||||
* @see LlcpSocket
|
||||
* @since AA02.01
|
||||
*/
|
||||
public LlcpSocket accept() throws IOException, LlcpException {
|
||||
|
||||
@@ -141,7 +125,6 @@ public class LlcpServiceSocket {
|
||||
*
|
||||
* @param timeout
|
||||
* value of the timeout for the accept request
|
||||
* @since AA02.01
|
||||
*/
|
||||
public void setAcceptTimeout(int timeout) {
|
||||
try {
|
||||
@@ -155,7 +138,6 @@ public class LlcpServiceSocket {
|
||||
* Get the timeout value of the accept request
|
||||
*
|
||||
* @return mTimeout
|
||||
* @since AA02.01
|
||||
*/
|
||||
public int getAcceptTimeout() {
|
||||
try {
|
||||
@@ -168,8 +150,6 @@ public class LlcpServiceSocket {
|
||||
|
||||
/**
|
||||
* Close the created Llcp Service socket
|
||||
*
|
||||
* @since AA02.01
|
||||
*/
|
||||
public void close() {
|
||||
try {
|
||||
@@ -178,5 +158,4 @@ public class LlcpServiceSocket {
|
||||
Log.e(TAG, "RemoteException in close(): ", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,28 +14,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* File : LlcpClientSocket.java
|
||||
* Original-Author : Trusted Logic S.A. (Daniel Tomas)
|
||||
* Created : 18-02-2010
|
||||
*/
|
||||
|
||||
package com.trustedlogic.trustednfc.android;
|
||||
package com.android.internal.nfc;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import android.nfc.ErrorCodes;
|
||||
import android.nfc.ILlcpSocket;
|
||||
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* LlcpClientSocket represents a LLCP Connection-Oriented client to be used in a
|
||||
* connection-oriented communication
|
||||
*
|
||||
* @since AA02.01
|
||||
* @hide
|
||||
*/
|
||||
public class LlcpSocket {
|
||||
|
||||
@@ -44,15 +34,11 @@ public class LlcpSocket {
|
||||
/**
|
||||
* The handle returned by the NFC service and used to identify the LLCP
|
||||
* socket in every call of this class.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
protected int mHandle;
|
||||
|
||||
/**
|
||||
* The entry point for LLCP socket operations.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
protected ILlcpSocket mService;
|
||||
|
||||
@@ -92,7 +78,6 @@ public class LlcpSocket {
|
||||
* @param handle
|
||||
* The handle returned by the NFC service and used to identify
|
||||
* the socket in subsequent calls.
|
||||
* @hide
|
||||
*/
|
||||
LlcpSocket(ILlcpSocket service, int handle) {
|
||||
this.mService = service;
|
||||
@@ -109,7 +94,6 @@ public class LlcpSocket {
|
||||
* @throws LlcpException
|
||||
* if the connection request is rejected by the remote LLCP
|
||||
* Service
|
||||
* @since AA02.01
|
||||
*/
|
||||
public void connect(int sap) throws IOException, LlcpException {
|
||||
try {
|
||||
@@ -137,7 +121,6 @@ public class LlcpSocket {
|
||||
* @throws LlcpException
|
||||
* if the connection request is rejected by the remote LLCP
|
||||
* Service
|
||||
* @since AA02.01
|
||||
*/
|
||||
public void connect(String sn) throws IOException, LlcpException {
|
||||
try {
|
||||
@@ -160,7 +143,6 @@ public class LlcpSocket {
|
||||
*
|
||||
* @param timeout
|
||||
* timeout value for the connect request
|
||||
* @since AA02.01
|
||||
*/
|
||||
public void setConnectTimeout(int timeout) {
|
||||
try {
|
||||
@@ -174,7 +156,6 @@ public class LlcpSocket {
|
||||
* Get the timeout value of the connect request
|
||||
*
|
||||
* @return mTimeout
|
||||
* @since AA02.01
|
||||
*/
|
||||
public int getConnectTimeout() {
|
||||
try {
|
||||
@@ -191,7 +172,6 @@ public class LlcpSocket {
|
||||
*
|
||||
* @throws IOException
|
||||
* if the LLCP has been lost or deactivated.
|
||||
* @since AA02.01
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
try {
|
||||
@@ -210,7 +190,6 @@ public class LlcpSocket {
|
||||
*
|
||||
* @throws IOException
|
||||
* if the LLCP has been lost or deactivated.
|
||||
* @since AA02.01
|
||||
*/
|
||||
public void send(byte[] data) throws IOException {
|
||||
try {
|
||||
@@ -232,7 +211,6 @@ public class LlcpSocket {
|
||||
* @return length length of the data received
|
||||
* @throws IOException
|
||||
* if the LLCP has been lost or deactivated.
|
||||
* @since AA02.01
|
||||
*/
|
||||
public int receive(byte[] receiveBuffer) throws IOException {
|
||||
int receivedLength = 0;
|
||||
@@ -252,7 +230,6 @@ public class LlcpSocket {
|
||||
* Returns the local Service Access Point number of the socket
|
||||
*
|
||||
* @return localSap
|
||||
* @since AA02.01
|
||||
*/
|
||||
public int getLocalSap() {
|
||||
try {
|
||||
@@ -267,7 +244,6 @@ public class LlcpSocket {
|
||||
* Returns the local Maximum Information Unit(MIU) of the socket
|
||||
*
|
||||
* @return miu
|
||||
* @since AA02.01
|
||||
*/
|
||||
public int getLocalSocketMiu() {
|
||||
try {
|
||||
@@ -282,7 +258,6 @@ public class LlcpSocket {
|
||||
* Returns the local Receive Window(RW) of the socket
|
||||
*
|
||||
* @return rw
|
||||
* @since AA02.01
|
||||
*/
|
||||
public int getLocalSocketRw() {
|
||||
try {
|
||||
@@ -301,7 +276,6 @@ public class LlcpSocket {
|
||||
* @return remoteMiu
|
||||
* @throws LlcpException
|
||||
* if the LlcpClientSocket is not in a CONNECTED_STATE
|
||||
* @since AA02.01
|
||||
*/
|
||||
public int getRemoteSocketMiu() throws LlcpException {
|
||||
try {
|
||||
@@ -325,7 +299,6 @@ public class LlcpSocket {
|
||||
* @return rw
|
||||
* @throws LlcpException
|
||||
* if the LlcpClientSocket is not in a CONNECTED_STATE
|
||||
* @since AA02.01
|
||||
*/
|
||||
public int getRemoteSocketRw() throws LlcpException {
|
||||
try {
|
||||
@@ -340,6 +313,4 @@ public class LlcpSocket {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -14,20 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* File : NFCException.java
|
||||
* Original-Author : Trusted Logic S.A. (Jeremie Corbier)
|
||||
* Created : 26-08-2009
|
||||
*/
|
||||
|
||||
package com.trustedlogic.trustednfc.android;
|
||||
package com.android.internal.nfc;
|
||||
|
||||
/**
|
||||
* Generic exception thrown in case something unexpected happened during the
|
||||
* NFCManager operations.
|
||||
*
|
||||
* @since AA01.04
|
||||
* @hide
|
||||
*/
|
||||
public class NfcException extends Exception {
|
||||
/**
|
||||
@@ -14,20 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* File : P2PDevice.java
|
||||
* Original-Author : Trusted Logic S.A. (Daniel Tomas)
|
||||
* Created : 26-02-2010
|
||||
*/
|
||||
|
||||
package com.trustedlogic.trustednfc.android;
|
||||
package com.android.internal.nfc;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* P2pDevice is the abstract base class for all supported P2P targets the
|
||||
* NfcManager can handle.
|
||||
* @hide
|
||||
*/
|
||||
public abstract class P2pDevice {
|
||||
|
||||
@@ -48,19 +41,16 @@ public abstract class P2pDevice {
|
||||
|
||||
/**
|
||||
* Target handle, used by native calls.
|
||||
* @hide
|
||||
*/
|
||||
protected int mHandle;
|
||||
|
||||
/**
|
||||
* Flag set when the object is closed and thus not usable any more.
|
||||
* @hide
|
||||
*/
|
||||
protected boolean isClosed = false;
|
||||
|
||||
/**
|
||||
* Prevent default constructor to be public.
|
||||
* @hide
|
||||
*/
|
||||
protected P2pDevice() {
|
||||
}
|
||||
@@ -14,12 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* File : P2PInitiator.java
|
||||
* Original-Author : Trusted Logic S.A. (Daniel Tomas)
|
||||
*/
|
||||
|
||||
package com.trustedlogic.trustednfc.android;
|
||||
package com.android.internal.nfc;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -32,8 +27,6 @@ import android.util.Log;
|
||||
* communication.
|
||||
*
|
||||
* @see P2pTarget
|
||||
* @since AA02.01
|
||||
* @hide
|
||||
*/
|
||||
public class P2pInitiator extends P2pDevice {
|
||||
|
||||
@@ -41,7 +34,6 @@ public class P2pInitiator extends P2pDevice {
|
||||
|
||||
/**
|
||||
* The entry point for P2P tag operations.
|
||||
* @hide
|
||||
*/
|
||||
private final IP2pInitiator mService;
|
||||
|
||||
@@ -50,8 +42,6 @@ public class P2pInitiator extends P2pDevice {
|
||||
*
|
||||
* @param handle The handle returned by the NFC service and used to identify
|
||||
* the tag in subsequent calls.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
P2pInitiator(IP2pInitiator service, int handle) {
|
||||
this.mService = service;
|
||||
@@ -14,12 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* File : P2PTarget.java
|
||||
* Original-Author : Trusted Logic S.A. (Daniel Tomas)
|
||||
*/
|
||||
|
||||
package com.trustedlogic.trustednfc.android;
|
||||
package com.android.internal.nfc;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -32,8 +27,6 @@ import android.util.Log;
|
||||
* P2pTarget represents the target in an NFC-IP1 peer-to-peer communication.
|
||||
*
|
||||
* @see P2pInitiator
|
||||
* @since AA02.01
|
||||
* @hide
|
||||
*/
|
||||
public class P2pTarget extends P2pDevice {
|
||||
|
||||
@@ -41,19 +34,16 @@ public class P2pTarget extends P2pDevice {
|
||||
|
||||
/**
|
||||
* The entry point for P2P tag operations.
|
||||
* @hide
|
||||
*/
|
||||
private final IP2pTarget mService;
|
||||
|
||||
/**
|
||||
* Flag set when the object is closed and thus not usable any more.
|
||||
* @hide
|
||||
*/
|
||||
private final boolean isClosed = false;
|
||||
|
||||
/**
|
||||
* Flag set when the tag is connected.
|
||||
* @hide
|
||||
*/
|
||||
private boolean isConnected = false;
|
||||
|
||||
@@ -62,8 +52,6 @@ public class P2pTarget extends P2pDevice {
|
||||
*
|
||||
* @return data sent by the P2pInitiator.
|
||||
* @throws NfcException if accessing a closed target.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public void checkState() throws NfcException {
|
||||
if(isClosed) {
|
||||
@@ -76,8 +64,6 @@ public class P2pTarget extends P2pDevice {
|
||||
*
|
||||
* @param handle The handle returned by the NFC service and used to identify
|
||||
* the tag in subsequent calls.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
P2pTarget(IP2pTarget service, int handle) {
|
||||
this.mService = service;
|
||||
@@ -181,5 +167,4 @@ public class P2pTarget extends P2pDevice {
|
||||
public int getMode() {
|
||||
return P2pDevice.MODE_P2P_TARGET;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,473 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
|
||||
<p>Provides classes that manage the NFC functionality.</p>
|
||||
|
||||
<p>The NFC functionality is related to Near Field Communication.</p>
|
||||
|
||||
<p>The NFC APIs let applications:</p>
|
||||
<ul>
|
||||
<li>Scan for remote NFC targets (NFC Tag or NFC Peer)</li>
|
||||
<li>Transfer raw data to and from remote NFC targets (NFC Tags or NFC Peer)</li>
|
||||
<li>Read/Write NDEF data from/to remote NFC targets (NFC Tags)</li>
|
||||
<li>Establish LLCP connection with a remote NFC target (NFC Peer with LLCP support)</li>
|
||||
<li>Exchange data with a remote NFC target through LLCP services (NFC Peer with LLCP support)</li>
|
||||
<li>Be notified of transactions on the local Secure Element by an external NFC reader</li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h1>Setting Up NFC</h1>
|
||||
|
||||
<p>
|
||||
Before an application can use the NFC feature, it needs to check if NFC is
|
||||
supported on the device by getting an instance of the
|
||||
{@link com.trustedlogic.trustednfc.android.NfcManager} class.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
NfcManager mNfcManager = (NfcManager) getSystemService(Context.NFC_SERVICE);
|
||||
if (mNfcManager == null) {
|
||||
// Device does not support NFC
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
An application can ensure that NFC is enabled.
|
||||
If not, an application with the needed permission can request that NFC be
|
||||
enabled.
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
if (!mNfcManager.isEnabled) {
|
||||
// NFC is currently disabled.
|
||||
// Enable NFC.
|
||||
mNfcManager.enable();
|
||||
}
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Before using the card emulation mode, an application can ensure that a secure
|
||||
element is selected ({@link com.trustedlogic.trustednfc.android.NfcManager#getSelectedSecureElement}).
|
||||
If not, an application with the needed permission can recover the list of
|
||||
available secure elements on the device
|
||||
({@link com.trustedlogic.trustednfc.android.NfcManager#getSecureElementList}) and select one
|
||||
({@link com.trustedlogic.trustednfc.android.NfcManager#selectSecureElement}).
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Before using the NFC feature, an application can configure the NFC device by
|
||||
calling {@link com.trustedlogic.trustednfc.android.NfcManager#setProperties}. This function allows:
|
||||
</p>
|
||||
<ul>
|
||||
<li>Enabling/disabling the NFC device capabilities (RF types, baudrates,
|
||||
NFCIP-1 mode and role...)</li>
|
||||
<li>Settings the NFCIP-1 general bytes and the LLCP link parameters</li>
|
||||
</ul>
|
||||
<p>
|
||||
The setting properties can be customized according to the Device capabilities.
|
||||
The next table give the minimal set of properties supported by the Device.
|
||||
Depending on the implementation, the table may be completed.
|
||||
</p>
|
||||
<table>
|
||||
<TR><TH> Property Name </TH><TH> Property Values </TH></TR>
|
||||
<TR><TD> discovery.felica </TD><TD> <b>true</b>|false </TD></TR>
|
||||
<TR><TD> discovery.iso14443A </TD><TD> <b>true</b>|false </TD></TR>
|
||||
<TR><TD> discovery.iso14443B </TD><TD> <b>true</b>|false </TD></TR>
|
||||
<TR><TD> discovery.iso15693 </TD><TD> <b>true</b>|false </TD></TR>
|
||||
<TR><TD> discovery.nfcip </TD><TD> <b>true</b>|false </TD></TR>
|
||||
<TR><TD> nfcip.baudrate </TD><TD> 106|212|424 </TD></TR>
|
||||
<TR><TD> nfcip.generalbytes </TD><TD> </TD></TR>
|
||||
<TR><TD> nfcip.mode </TD><TD> active|passive|<b>all</b> </TD></TR>
|
||||
<TR><TD> nfcip.role </TD><TD> initiator|target|<b>both</b> </TD></TR>
|
||||
<TR><TD> llcp.lto </TD><TD> <b>150</b> (0 to 255) </TD></TR>
|
||||
<TR><TD> llcp.opt </TD><TD> <b>0</b> (0 to 3) </TD></TR>
|
||||
<TR><TD> llcp.miu </TD><TD> <b>128</b> (128 to 2176) </TD></TR>
|
||||
<TR><TD> llcp.wks </TD><TD> <b>1</b> (0 to 15) </TD></TR>
|
||||
</table>
|
||||
<p>(default values in bold)</p>
|
||||
|
||||
|
||||
<h1>NFC Permissions</h1>
|
||||
|
||||
<p>
|
||||
To change the NFC service settings such as enabling the NFC targets
|
||||
discovery or activating the secure element, an application must declare the
|
||||
NFC_ADMIN permission.
|
||||
</p>
|
||||
<p>
|
||||
To perform NFC raw communication with a remote NFC target in
|
||||
Reader/Write Mode or Peer-to-Peer Mode, an application must declare the NFC_RAW
|
||||
permission.
|
||||
</p>
|
||||
<p>
|
||||
To receive NDEF message or Secure Element intents, an application must declare
|
||||
the NFC_NOTIFY permission.
|
||||
</p>
|
||||
<p>
|
||||
To receive the LLCP link intent and perform an LLCP communication with a remote NFC target, an application must
|
||||
declare the NFC_LLCP permission.
|
||||
</p>
|
||||
|
||||
|
||||
<h1>NFC Usage</h1>
|
||||
|
||||
<p>
|
||||
The following code samples illustrate the APIs usage regarding the NFC service
|
||||
use cases.
|
||||
</p>
|
||||
|
||||
<h2>Reader/Writer Mode NDEF message notification</h2>
|
||||
|
||||
<p>
|
||||
This code sample illustrates the NDEF message notification through an Intent declared in the manifest and a receiver implemented in the application.
|
||||
</p>
|
||||
<p>Main involved classes/methods:</p>
|
||||
|
||||
<p>Manifest Example:</p>
|
||||
<pre>
|
||||
<receiver android:name=".NfcReaderDemoReceiver">
|
||||
<intent-filter>
|
||||
<action android:name= "com.trustedlogic.trustednfc.android.action.NDEF_TAG_DISCOVERED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</pre>
|
||||
|
||||
<p>Receiver Example:</p>
|
||||
<ul>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.NdefMessage}</li>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.NfcManager#NDEF_TAG_DISCOVERED_ACTION}</li>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.NfcManager#NDEF_MESSAGE_EXTRA}</li>
|
||||
</ul>
|
||||
<pre>
|
||||
public class NdefMessageReceiverSample extends BroadcastReceiver {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(NfcManager.NDEF_TAG_DISCOVERERD_ACTION)) {
|
||||
NdefMessage msg = intent.getParcelableExtra(NfcManager.NDEF_MESSAGE_EXTRA);
|
||||
|
||||
/* Manage the NdefMessage received */
|
||||
}
|
||||
</pre>
|
||||
|
||||
<h2>Reader/Writer Mode raw exchange</h2>
|
||||
|
||||
<p>
|
||||
This code sample illustrates raw exchanges with a NFC target in Reader/Writer
|
||||
mode.
|
||||
</p>
|
||||
<p>Main involved classes/methods:</p>
|
||||
<ul>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.NfcManager#openTagConnection}</li>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.NfcTag}</li>
|
||||
</ul>
|
||||
|
||||
<pre>
|
||||
public class TagReaderSample {
|
||||
|
||||
/** The NFC manager to access NFC features */
|
||||
private NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE);
|
||||
|
||||
private void runTagReader() {
|
||||
NfcTag tag = null;
|
||||
String type;
|
||||
byte[] cmd = { 0x01, 0x02, 0x03 };
|
||||
byte[] res;
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
Log.i("NFC example", "Please wave in front of the tag");
|
||||
// Open a connection on next available tag
|
||||
try {
|
||||
tag = manager.openTagConnection();
|
||||
} catch (NfcException e) {
|
||||
// TODO: Handle open failure
|
||||
}
|
||||
|
||||
// Look for a mifare 4k
|
||||
type = tag.getType();
|
||||
if (type.equals("Mifare4K")) {
|
||||
Log.i("NFC example", "Tag detected");
|
||||
tag.connect();
|
||||
// Ready to communicate, we can send transceive !
|
||||
res = tag.transceive(cmd);
|
||||
} else {
|
||||
Log.i("NFC example", "Unknown tag");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO: Handle broken connection
|
||||
} finally {
|
||||
if (tag != null) {
|
||||
tag.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
|
||||
<h2>Peer-to-Peer Mode raw exchange</h2>
|
||||
|
||||
<p>
|
||||
This code sample illustrates raw exchanges with a NFC target in Peer-to-Peer
|
||||
mode.
|
||||
</p>
|
||||
<p>Main involved classes/methods:</p>
|
||||
<ul>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.NfcManager#openP2pConnection}</li>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.P2pDevice}</li>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.P2pInitiator}</li>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.P2pTarget}</li>
|
||||
</ul>
|
||||
|
||||
<pre>
|
||||
public class P2pSample {
|
||||
|
||||
/** The NFC manager to access NFC features */
|
||||
private NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE);
|
||||
|
||||
private void runP2p() {
|
||||
P2pDevice deviceP2p;
|
||||
P2pInitiator initiator;
|
||||
P2pTarget target;
|
||||
byte[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
byte[] echo = new byte[data.length * 10];
|
||||
|
||||
try {
|
||||
deviceP2p = manager.openP2pConnection();
|
||||
|
||||
if (deviceP2p.getMode() == P2pDevice.MODE_P2P_INITIATOR) {
|
||||
target = new P2pTarget(deviceP2p);
|
||||
// Connect to the detected P2P target
|
||||
target.connect();
|
||||
// send data to the target
|
||||
target.transceive(data);
|
||||
// disconnect the connected target
|
||||
target.disconnect();
|
||||
} else if (deviceP2p.getMode() == P2pDevice.MODE_P2P_TARGET) {
|
||||
initiator = new P2pInitiator(deviceP2p);
|
||||
//target in receive state
|
||||
echo = initiator.receive();
|
||||
// send back the data received
|
||||
initiator.send(echo);
|
||||
}
|
||||
} catch (IOException e0) {
|
||||
|
||||
} catch (NfcException e1) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
|
||||
<h2>Peer-to-Peer Mode LLCP exchange</h2>
|
||||
|
||||
<p>
|
||||
This code sample illustrates how to get LLCP link state notification with the declaration of a Receiver in the manifest of the application and the implementation
|
||||
of the receiver in the application.
|
||||
</p>
|
||||
<p>Manifest Example:</p>
|
||||
<pre>
|
||||
<receiver android:name=".LlcpModeReceiverSample">
|
||||
<intent-filter>
|
||||
<action android:name= "com.trustedlogic.trustednfc.android.action.LLCP_LINK_STATE_CHANGED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</pre>
|
||||
|
||||
<p>Receiver Example:</p>
|
||||
<ul>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.NfcManager#LLCP_LINK_STATE_CHANGED_ACTION}</li>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.NfcManager#LLCP_LINK_STATE_CHANGED_EXTRA}</li>
|
||||
</ul>
|
||||
<pre>
|
||||
public class LlcpModeReceiverSample extends BroadcastReceiver {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
if (intent.getAction().equals(NfcManager.LLCP_LINK_STATE_CHANGED_ACTION)){
|
||||
byte[] aid = intent.getByteArrayExtra(NfcManager.LLCP_LINK_STATE_CHANGED_EXTRA);
|
||||
/* Create an LLCP service or client and start an LLCP communication */
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
|
||||
|
||||
<p>
|
||||
This code samples illustrate LLCP exchanges with a NFC Peer.
|
||||
</p>
|
||||
<p>Main involved classes/methods:</p>
|
||||
<ul>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.NfcManager#createLlcpSocket}</li>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.NfcManager#createLlcpConnectionlessSocket}</li>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.NfcManager#createLlcpServiceSocket}</li>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.LlcpSocket}</li>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.LlcpConnectionlessSocket}</li>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.LlcpPacket}</li>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.LlcpServiceSocket}</li>
|
||||
</ul>
|
||||
|
||||
<pre>
|
||||
public class LlcpServerSample {
|
||||
|
||||
/** The NFC manager to access NFC features */
|
||||
private NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE);
|
||||
|
||||
private void runLlcpClient() {
|
||||
LlcpSocket sock;
|
||||
byte[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
byte[] echo = new byte[data.length * 10];
|
||||
int length = 0;
|
||||
|
||||
sock = manager.createLlcpSocket((short) 128, (byte) 2, 1024);
|
||||
|
||||
// set a timeout in ms for connect request
|
||||
sock.setConnectTimeout(10);
|
||||
|
||||
try {
|
||||
// Connect to remote service
|
||||
// NOTE: could be sock.connect("com.trusted-logic.tnfc.testapp");
|
||||
sock.connect((byte) 0x10);
|
||||
|
||||
// Send data
|
||||
for (int i = 0; i < 10; i++) {
|
||||
sock.send(data);
|
||||
}
|
||||
|
||||
// Receive echo
|
||||
while (length < 10 * data.length) {
|
||||
length += sock.receive(echo);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO: Handle broken connection broken (link down, remote closure
|
||||
// or connect rejected) or Timeout expired
|
||||
}
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
|
||||
<pre>
|
||||
public class LlcpClientSample {
|
||||
|
||||
/** The NFC manager to access NFC features */
|
||||
private NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE);
|
||||
|
||||
private void runLlcpClient() {
|
||||
LlcpSocket sock;
|
||||
byte[] data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
byte[] echo = new byte[data.length * 10];
|
||||
int length = 0;
|
||||
|
||||
sock = manager.createLlcpSocket((short) 128, (byte) 2, 1024);
|
||||
try {
|
||||
// Connect to remote service
|
||||
// NOTE: could be sock.connect("com.trusted-logic.tnfc.testapp");
|
||||
sock.connect((byte) 0x10);
|
||||
|
||||
// Send data
|
||||
for (int i = 0; i < 10; i++) {
|
||||
sock.send(data);
|
||||
}
|
||||
|
||||
// Receive echo
|
||||
while (length < 10 * data.length) {
|
||||
length += sock.receive(echo);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO: Handle broken connection broken (link down, remote closure
|
||||
// or connect rejected)
|
||||
}
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
|
||||
<h2>Card Emulation Mode transaction notification</h2>
|
||||
|
||||
<p>
|
||||
This code sample illustrates how to get the card emulation notification with the declaration of a Receiver in the manifest of the application and the implementation
|
||||
of the receiver in the application.
|
||||
</p>
|
||||
<p>Manifest Example:</p>
|
||||
<pre>
|
||||
<receiver android:name=".NfcReaderDemoReceiver">
|
||||
<intent-filter>
|
||||
<action android:name= "com.trustedlogic.trustednfc.android.action.TRANSACTION_DETECTED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</pre>
|
||||
|
||||
<p>Receiver Example:</p>
|
||||
<ul>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.NfcManager#TRANSACTION_DETECTED_ACTION}</li>
|
||||
<li>{@link com.trustedlogic.trustednfc.android.NfcManager#AID_EXTRA}</li>
|
||||
</ul>
|
||||
<pre>
|
||||
public class CardEmulationReceiverSample extends BroadcastReceiver {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
if (intent.getAction().equals(NfcManager.TRANSACTION_DETECTED_ACTION)){
|
||||
byte[] aid = intent.getByteArrayExtra(NfcManager.AID_EXTRA);
|
||||
/* Manage the AID: */
|
||||
/* For example start an activity related to this AID value or display a popup with the AID */
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
|
||||
|
||||
|
||||
<h1>Multiple Applications rules</h1>
|
||||
|
||||
<p>
|
||||
Several LLCP sockets can be created by a single application or by multiple
|
||||
applications by calling {@link com.trustedlogic.trustednfc.android.NfcManager#createLlcpSocket},
|
||||
{@link com.trustedlogic.trustednfc.android.NfcManager#createLlcpConnectionlessSocket} or
|
||||
{@link com.trustedlogic.trustednfc.android.NfcManager#createLlcpServiceSocket}, provided the local SAP
|
||||
numbers are differents.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Only one application can open a raw connection by calling
|
||||
{@link com.trustedlogic.trustednfc.android.NfcManager#openTagConnection} or
|
||||
{@link com.trustedlogic.trustednfc.android.NfcManager#openP2pConnection}.
|
||||
While this application has not closed or cancelled its connection, any other
|
||||
application that attempts to open another raw connection will raise an
|
||||
exception.
|
||||
During an open connnection, the card emulation mode is always enabled and
|
||||
applications are able to receive card emulation intents.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
When an application opens a tag connection by calling
|
||||
{@link com.trustedlogic.trustednfc.android.NfcManager#openTagConnection}, this operation is exclusive, no NDEF message intent are
|
||||
broadcast while the connection is not closed or canceled.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
When an application opens a peer-to-peer connection by calling
|
||||
{@link com.trustedlogic.trustednfc.android.NfcManager#openP2pConnection}, this operation is exclusive, no LLCP intent are broadcast and LLCP sockets are
|
||||
disabled while the connection is not closed or canceled.
|
||||
</p>
|
||||
|
||||
|
||||
<h1>NFC Tag types</h1>
|
||||
|
||||
<p>
|
||||
The {@link com.trustedlogic.trustednfc.android.NfcTag} type returned by
|
||||
{@link com.trustedlogic.trustednfc.android.NfcTag#getType} indicates the set of
|
||||
commands supported by the tag. These commands can be used in
|
||||
{@link com.trustedlogic.trustednfc.android.NfcTag#transceive}.
|
||||
</p>
|
||||
|
||||
<TABLE BORDER="1">
|
||||
<TR><TH> Tag Type </TH><TH> Returned string </TH></TR>
|
||||
<TR><TD> Jewel/Topaz </TD><TD> Jewel </TD></TR>
|
||||
<TR><TD> Mifare UltraLight </TD><TD> MifareUL </TD></TR>
|
||||
<TR><TD> Mifare Standard 1K </TD><TD> Mifare1K </TD></TR>
|
||||
<TR><TD> Mifare Standard 4K </TD><TD> Mifare4K </TD></TR>
|
||||
<TR><TD> Mifare DESFIRE </TD><TD> MifareDESFIRE </TD></TR>
|
||||
<TR><TD> Felica </TD><TD> Felica </TD></TR>
|
||||
<TR><TD> ISO14443-4 A or B </TD><TD> Iso14443 </TD></TR>
|
||||
<TR><TD> ISO15693 </TD><TD> Iso15693 </TD></TR>
|
||||
</TABLE>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user