diff options
author | Jeff Hamilton <jham@android.com> | 2011-06-29 22:01:44 -0500 |
---|---|---|
committer | Jeff Hamilton <jham@android.com> | 2011-08-01 23:26:58 -0500 |
commit | 4a61d3b45e81c0070538f94747a70a49c78f12fa (patch) | |
tree | 4939ec54a0e6527b942126023a393f9c0f85ad35 /src/com/android/nfc/nxp | |
parent | 5ce39aec169a275e814286372256277819593829 (diff) | |
download | packages_apps_nfc-4a61d3b45e81c0070538f94747a70a49c78f12fa.zip packages_apps_nfc-4a61d3b45e81c0070538f94747a70a49c78f12fa.tar.gz packages_apps_nfc-4a61d3b45e81c0070538f94747a70a49c78f12fa.tar.bz2 |
Remove the binder interface for LLCP.
Change-Id: I8d5fd546ecb07f005322eb5f173975dff7820439
Diffstat (limited to 'src/com/android/nfc/nxp')
-rwxr-xr-x | src/com/android/nfc/nxp/NativeLlcpServiceSocket.java | 35 | ||||
-rwxr-xr-x | src/com/android/nfc/nxp/NativeLlcpSocket.java | 65 | ||||
-rwxr-xr-x | src/com/android/nfc/nxp/NativeNfcManager.java | 57 |
3 files changed, 119 insertions, 38 deletions
diff --git a/src/com/android/nfc/nxp/NativeLlcpServiceSocket.java b/src/com/android/nfc/nxp/NativeLlcpServiceSocket.java index 2eb8ab7..531afd8 100755 --- a/src/com/android/nfc/nxp/NativeLlcpServiceSocket.java +++ b/src/com/android/nfc/nxp/NativeLlcpServiceSocket.java @@ -16,11 +16,16 @@ package com.android.nfc.nxp; +import com.android.nfc.DeviceHost; +import com.android.nfc.DeviceHost.LlcpSocket; + +import java.io.IOException; + /** * LlcpServiceSocket represents a LLCP Service to be used in a * Connection-oriented communication */ -public class NativeLlcpServiceSocket { +public class NativeLlcpServiceSocket implements DeviceHost.LlcpServerSocket { private int mHandle; private int mLocalMiu; private int mLocalRw; @@ -30,23 +35,19 @@ public class NativeLlcpServiceSocket { public NativeLlcpServiceSocket(){ } - public native NativeLlcpSocket doAccept(int miu, int rw, int linearBufferLength); - - public native boolean doClose(); - - public int getHandle(){ - return mHandle; - } - - public int getRw(){ - return mLocalRw; - } - - public int getMiu(){ - return mLocalMiu; + private native NativeLlcpSocket doAccept(int miu, int rw, int linearBufferLength); + @Override + public LlcpSocket accept() throws IOException { + LlcpSocket socket = doAccept(mLocalMiu, mLocalRw, mLocalLinearBufferLength); + if (socket == null) throw new IOException(); + return socket; } - public int getLinearBufferLength(){ - return mLocalLinearBufferLength; + private native boolean doClose(); + @Override + public void close() throws IOException { + if (!doClose()) { + throw new IOException(); + } } } diff --git a/src/com/android/nfc/nxp/NativeLlcpSocket.java b/src/com/android/nfc/nxp/NativeLlcpSocket.java index 4132c3a..84d9dd3 100755 --- a/src/com/android/nfc/nxp/NativeLlcpSocket.java +++ b/src/com/android/nfc/nxp/NativeLlcpSocket.java @@ -16,11 +16,15 @@ package com.android.nfc.nxp; +import com.android.nfc.DeviceHost; + +import java.io.IOException; + /** * LlcpClientSocket represents a LLCP Connection-Oriented client to be used in a * connection-oriented communication */ -public class NativeLlcpSocket { +public class NativeLlcpSocket implements DeviceHost.LlcpSocket { private int mHandle; private int mSap; private int mLocalMiu; @@ -28,33 +32,64 @@ public class NativeLlcpSocket { public NativeLlcpSocket(){ } - public native boolean doConnect(int nSap); + private native boolean doConnect(int nSap); + @Override + public void connectToSap(int sap) throws IOException { + if (!doConnect(sap)) { + throw new IOException(); + } + } - public native boolean doConnectBy(String sn); + private native boolean doConnectBy(String sn); + @Override + public void connectToService(String serviceName) throws IOException { + if (!doConnectBy(serviceName)) { + throw new IOException(); + } + } - public native boolean doClose(); + private native boolean doClose(); + @Override + public void close() throws IOException { + if (!doClose()) { + throw new IOException(); + } + } - public native boolean doSend(byte[] data); + private native boolean doSend(byte[] data); + @Override + public void send(byte[] data) throws IOException { + if (!doSend(data)) { + throw new IOException(); + } + } - public native int doReceive(byte[] recvBuff); + private native int doReceive(byte[] recvBuff); + @Override + public int receive(byte[] recvBuff) throws IOException { + return doReceive(recvBuff); + } - public native int doGetRemoteSocketMiu(); + private native int doGetRemoteSocketMiu(); + @Override + public int getRemoteMiu() { return doGetRemoteSocketMiu(); } - public native int doGetRemoteSocketRw(); + private native int doGetRemoteSocketRw(); + @Override + public int getRemoteRw() { return doGetRemoteSocketRw(); } - public int getSap(){ + @Override + public int getLocalSap(){ return mSap; } - public int getMiu(){ + @Override + public int getLocalMiu(){ return mLocalMiu; } - public int getRw(){ + @Override + public int getLocalRw(){ return mLocalRw; } - - public int getHandle(){ - return mHandle; - } } diff --git a/src/com/android/nfc/nxp/NativeNfcManager.java b/src/com/android/nfc/nxp/NativeNfcManager.java index 8a59370..bce9fa9 100755 --- a/src/com/android/nfc/nxp/NativeNfcManager.java +++ b/src/com/android/nfc/nxp/NativeNfcManager.java @@ -17,15 +17,20 @@ package com.android.nfc.nxp; import com.android.nfc.DeviceHost; +import com.android.nfc.LlcpException; import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; import android.content.Context; +import android.nfc.ErrorCodes; +import android.util.Log; /** * Native interface to the NFC Manager functions */ public class NativeNfcManager implements DeviceHost { + private static final String TAG = "NativeNfcManager"; + static { System.loadLibrary("nfc_jni"); } @@ -40,6 +45,7 @@ public class NativeNfcManager implements DeviceHost { public NativeNfcManager(Context context, DeviceHostListener listener) { mListener = listener; + initializeNativeStructure(); } public native boolean initializeNativeStructure(); @@ -68,16 +74,55 @@ public class NativeNfcManager implements DeviceHost { @Override public native int doGetLastError(); - @Override - public native NativeLlcpConnectionlessSocket doCreateLlcpConnectionlessSocket(int nSap); + private native NativeLlcpConnectionlessSocket doCreateLlcpConnectionlessSocket(int nSap); - @Override - public native NativeLlcpServiceSocket doCreateLlcpServiceSocket(int nSap, String sn, int miu, + private native NativeLlcpServiceSocket doCreateLlcpServiceSocket(int nSap, String sn, int miu, int rw, int linearBufferLength); - @Override - public native NativeLlcpSocket doCreateLlcpSocket(int sap, int miu, int rw, + public LlcpServerSocket createLlcpServerSocket(int nSap, String sn, int miu, + int rw, int linearBufferLength) throws LlcpException { + LlcpServerSocket socket = doCreateLlcpServiceSocket(nSap, sn, miu, rw, linearBufferLength); + if (socket != null) { + return socket; + } else { + /* Get Error Status */ + int error = doGetLastError(); + + Log.d(TAG, "failed to create llcp socket: " + ErrorCodes.asString(error)); + + switch (error) { + case ErrorCodes.ERROR_BUFFER_TO_SMALL: + case ErrorCodes.ERROR_INSUFFICIENT_RESOURCES: + throw new LlcpException(error); + default: + throw new LlcpException(ErrorCodes.ERROR_SOCKET_CREATION); + } + } + } + + private native NativeLlcpSocket doCreateLlcpSocket(int sap, int miu, int rw, int linearBufferLength); + @Override + public LlcpSocket createLlcpSocket(int sap, int miu, int rw, + int linearBufferLength) throws LlcpException { + LlcpSocket socket = doCreateLlcpSocket(sap, miu, rw, linearBufferLength); + if (socket != null) { + return socket; + } else { + /* Get Error Status */ + int error = doGetLastError(); + + Log.d(TAG, "failed to create llcp socket: " + ErrorCodes.asString(error)); + + switch (error) { + case ErrorCodes.ERROR_BUFFER_TO_SMALL: + case ErrorCodes.ERROR_INSUFFICIENT_RESOURCES: + throw new LlcpException(error); + default: + throw new LlcpException(ErrorCodes.ERROR_SOCKET_CREATION); + } + } + } @Override public native boolean doCheckLlcp(); |