diff options
-rw-r--r-- | Android.mk | 5 | ||||
-rw-r--r-- | CleanSpec.mk | 1 | ||||
-rw-r--r-- | core/java/android/nfc/ILlcpConnectionlessSocket.aidl | 30 | ||||
-rw-r--r-- | core/java/android/nfc/ILlcpServiceSocket.aidl | 26 | ||||
-rw-r--r-- | core/java/android/nfc/ILlcpSocket.aidl | 34 | ||||
-rw-r--r-- | core/java/android/nfc/INfcAdapter.aidl | 14 | ||||
-rw-r--r--[-rwxr-xr-x] | core/java/android/nfc/INfcAdapterExtras.aidl | 0 | ||||
-rw-r--r-- | core/java/android/nfc/IP2pInitiator.aidl | 28 | ||||
-rw-r--r-- | core/java/android/nfc/IP2pTarget.aidl | 29 | ||||
-rw-r--r-- | core/java/com/android/internal/nfc/LlcpConnectionlessSocket.java | 124 | ||||
-rw-r--r-- | core/java/com/android/internal/nfc/LlcpException.java | 33 | ||||
-rw-r--r-- | core/java/com/android/internal/nfc/LlcpServiceSocket.java | 134 | ||||
-rw-r--r-- | core/java/com/android/internal/nfc/LlcpSocket.java | 289 | ||||
-rw-r--r-- | core/java/com/android/internal/nfc/NfcException.java | 33 | ||||
-rw-r--r-- | core/java/com/android/internal/nfc/P2pDevice.java | 79 | ||||
-rw-r--r-- | core/java/com/android/internal/nfc/P2pInitiator.java | 104 | ||||
-rw-r--r-- | core/java/com/android/internal/nfc/P2pTarget.java | 170 |
17 files changed, 1 insertions, 1132 deletions
@@ -116,15 +116,10 @@ LOCAL_SRC_FILES += \ core/java/android/net/INetworkPolicyListener.aidl \ core/java/android/net/INetworkPolicyManager.aidl \ core/java/android/net/INetworkStatsService.aidl \ - core/java/android/nfc/ILlcpConnectionlessSocket.aidl \ - core/java/android/nfc/ILlcpServiceSocket.aidl \ - core/java/android/nfc/ILlcpSocket.aidl \ core/java/android/nfc/INdefPushCallback.aidl \ core/java/android/nfc/INfcAdapter.aidl \ core/java/android/nfc/INfcAdapterExtras.aidl \ core/java/android/nfc/INfcTag.aidl \ - core/java/android/nfc/IP2pInitiator.aidl \ - core/java/android/nfc/IP2pTarget.aidl \ core/java/android/os/IHardwareService.aidl \ core/java/android/os/IMessenger.aidl \ core/java/android/os/INetworkManagementService.aidl \ diff --git a/CleanSpec.mk b/CleanSpec.mk index f3eaeeb..a87293d 100644 --- a/CleanSpec.mk +++ b/CleanSpec.mk @@ -101,6 +101,7 @@ $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libstagefright $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/os) $(call add-clean-step, rm -rf $(OUT_DIR)target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/keystore/java/android/security/IKeyChainAliasResponse.java) $(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/vpn) +$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/core/java/android/nfc) # ************************************************ # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST # ************************************************ diff --git a/core/java/android/nfc/ILlcpConnectionlessSocket.aidl b/core/java/android/nfc/ILlcpConnectionlessSocket.aidl deleted file mode 100644 index c6d84e5..0000000 --- a/core/java/android/nfc/ILlcpConnectionlessSocket.aidl +++ /dev/null @@ -1,30 +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 android.nfc; - -import android.nfc.LlcpPacket; - -/** - * @hide - */ -interface ILlcpConnectionlessSocket -{ - void close(int nativeHandle); - int getSap(int nativeHandle); - LlcpPacket receiveFrom(int nativeHandle); - int sendTo(int nativeHandle, in LlcpPacket packet); -}
\ No newline at end of file diff --git a/core/java/android/nfc/ILlcpServiceSocket.aidl b/core/java/android/nfc/ILlcpServiceSocket.aidl deleted file mode 100644 index 581c21d..0000000 --- a/core/java/android/nfc/ILlcpServiceSocket.aidl +++ /dev/null @@ -1,26 +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 android.nfc; - -/** - * {@hide} - */ -interface ILlcpServiceSocket -{ - int accept(int nativeHandle); - void close(int nativeHandle); -} diff --git a/core/java/android/nfc/ILlcpSocket.aidl b/core/java/android/nfc/ILlcpSocket.aidl deleted file mode 100644 index 3166e72..0000000 --- a/core/java/android/nfc/ILlcpSocket.aidl +++ /dev/null @@ -1,34 +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 android.nfc; - -/** - * @hide - */ -interface ILlcpSocket -{ - int close(int nativeHandle); - int connect(int nativeHandle, int sap); - int connectByName(int nativeHandle, String sn); - 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); -}
\ No newline at end of file diff --git a/core/java/android/nfc/INfcAdapter.aidl b/core/java/android/nfc/INfcAdapter.aidl index 2ed6619..83a055c 100644 --- a/core/java/android/nfc/INfcAdapter.aidl +++ b/core/java/android/nfc/INfcAdapter.aidl @@ -22,13 +22,8 @@ import android.content.IntentFilter; import android.nfc.NdefMessage; import android.nfc.Tag; import android.nfc.TechListParcel; -import android.nfc.ILlcpSocket; -import android.nfc.ILlcpServiceSocket; -import android.nfc.ILlcpConnectionlessSocket; import android.nfc.INdefPushCallback; import android.nfc.INfcTag; -import android.nfc.IP2pTarget; -import android.nfc.IP2pInitiator; import android.nfc.INfcAdapterExtras; /** @@ -36,12 +31,7 @@ import android.nfc.INfcAdapterExtras; */ interface INfcAdapter { - ILlcpSocket getLlcpInterface(); - ILlcpConnectionlessSocket getLlcpConnectionlessInterface(); - ILlcpServiceSocket getLlcpServiceInterface(); INfcTag getNfcTagInterface(); - IP2pTarget getP2pTargetInterface(); - IP2pInitiator getP2pInitiatorInterface(); INfcAdapterExtras getNfcAdapterExtrasInterface(); // NfcAdapter-class related methods @@ -54,10 +44,6 @@ interface INfcAdapter void disableForegroundNdefPush(in ComponentName activity); // 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); boolean disable(); boolean enable(); boolean enableZeroClick(); diff --git a/core/java/android/nfc/INfcAdapterExtras.aidl b/core/java/android/nfc/INfcAdapterExtras.aidl index 0c2a2fd..0c2a2fd 100755..100644 --- a/core/java/android/nfc/INfcAdapterExtras.aidl +++ b/core/java/android/nfc/INfcAdapterExtras.aidl diff --git a/core/java/android/nfc/IP2pInitiator.aidl b/core/java/android/nfc/IP2pInitiator.aidl deleted file mode 100644 index 931f1f8..0000000 --- a/core/java/android/nfc/IP2pInitiator.aidl +++ /dev/null @@ -1,28 +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 android.nfc; - -/** - * @hide - */ -interface IP2pInitiator -{ - byte[] getGeneralBytes(int nativeHandle); - int getMode(int nativeHandle); - byte[] receive(int nativeHandle); - boolean send(int nativeHandle, in byte[] data); -}
\ No newline at end of file diff --git a/core/java/android/nfc/IP2pTarget.aidl b/core/java/android/nfc/IP2pTarget.aidl deleted file mode 100644 index ddaaed42..0000000 --- a/core/java/android/nfc/IP2pTarget.aidl +++ /dev/null @@ -1,29 +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 android.nfc; - -/** - * @hide - */ -interface IP2pTarget -{ - byte[] getGeneralBytes(int nativeHandle); - int getMode(int nativeHandle); - int connect(int nativeHandle); - boolean disconnect(int nativeHandle); - byte[] transceive(int nativeHandle, in byte[] data); -}
\ No newline at end of file diff --git a/core/java/com/android/internal/nfc/LlcpConnectionlessSocket.java b/core/java/com/android/internal/nfc/LlcpConnectionlessSocket.java deleted file mode 100644 index a9cf6b8..0000000 --- a/core/java/com/android/internal/nfc/LlcpConnectionlessSocket.java +++ /dev/null @@ -1,124 +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.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; - -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. - */ - protected int mHandle; - - - /** - * The entry point for LLCP Connectionless socket operations. - */ - protected ILlcpConnectionlessSocket mService; - - - /** - * Internal constructor for the LlcpConnectionlessSocket class. - * - * @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. - */ - LlcpConnectionlessSocket(ILlcpConnectionlessSocket service, int handle) { - this.mService = service; - this.mHandle = handle; - } - - /** - * Send data to a specific LLCP Connectionless client - * - * @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. - */ - public void sendTo(LlcpPacket packet) throws IOException { - try { - int result = mService.sendTo(mHandle, packet); - // Handle potential errors - if (ErrorCodes.isError(result)) { - throw new IOException(); - } - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in sendTo(): ", e); - } - } - - /** - * Receive data from a LLCP Connectionless client - * - * @return data data received from a specific LLCP Connectionless client - * @throws IOException if the LLCP link has been lost or deactivated. - * @see LlcpPacket - */ - public LlcpPacket receiveFrom() throws IOException { - try { - LlcpPacket packet = mService.receiveFrom(mHandle); - if (packet != null) { - return packet; - }else{ - // Handle potential errors - throw new IOException(); - } - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in receiveFrom(): ", e); - } - return null; - } - - /** - * Close the created Connectionless socket. - */ - public void close() { - try { - mService.close(mHandle); - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in close(): ", e); - } - } - - /** - * Returns the local Service Access Point number of the socket - * - * @return sap - */ - public int getSap() { - int sap = 0; - - try { - sap = mService.getSap(mHandle); - - } catch (RemoteException e) { - - e.printStackTrace(); - } - return sap; - } -} diff --git a/core/java/com/android/internal/nfc/LlcpException.java b/core/java/com/android/internal/nfc/LlcpException.java deleted file mode 100644 index da4e91e..0000000 --- a/core/java/com/android/internal/nfc/LlcpException.java +++ /dev/null @@ -1,33 +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.android.internal.nfc; - -/** - * Generic exception thrown in case something unexpected happened during a - * LLCP communication. - */ -public class LlcpException extends Exception { - /** - * Constructs a new LlcpException with the current stack trace and the - * specified detail message. - * - * @param s the detail message for this exception. - */ - public LlcpException(String s) { - super(s); - } -} diff --git a/core/java/com/android/internal/nfc/LlcpServiceSocket.java b/core/java/com/android/internal/nfc/LlcpServiceSocket.java deleted file mode 100644 index d616860..0000000 --- a/core/java/com/android/internal/nfc/LlcpServiceSocket.java +++ /dev/null @@ -1,134 +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.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 - */ -public class LlcpServiceSocket { - - private static final String TAG = "LlcpServiceSocket"; - - /** - * The handle returned by the NFC service and used to identify the LLCP - * Service socket in every call of this class. - */ - protected int mHandle; - - /** - * The entry point for LLCP Service socket operations. - */ - protected ILlcpServiceSocket mService; - - private final ILlcpSocket mLlcpSocketService; - - static LlcpException convertErrorToLlcpException(int errorCode) { - return convertErrorToLlcpException(errorCode, null); - } - - static LlcpException convertErrorToLlcpException(int errorCode, - String message) { - if (message == null) { - message = ""; - } else { - message = " (" + message + ")"; - } - - switch (errorCode) { - case ErrorCodes.ERROR_SOCKET_CREATION: - return new LlcpException( - "Error during the creation of an Llcp socket" + message); - case ErrorCodes.ERROR_INSUFFICIENT_RESOURCES: - return new LlcpException("Not enough ressources are available" - + message); - default: - return new LlcpException("Unkown error code " + errorCode + message); - } - } - - /** - * Internal constructor for the LlcpServiceSocket class. - * - * @param service - * The entry point to the Nfc Service for LlcpServiceSocket - * class. - * @param handle - * The handle returned by the NFC service and used to identify - * the socket in subsequent calls. - * @hide - */ - public LlcpServiceSocket(ILlcpServiceSocket service, ILlcpSocket socketService, int handle) { - this.mService = service; - this.mHandle = handle; - this.mLlcpSocketService = socketService; - } - - /** - * Wait for incomming connection request from a LLCP client and accept this - * request - * - * @return socket object to be used to communicate with a LLCP client - * - * @throws IOException - * if the llcp link is lost or deactivated - * @throws LlcpException - * if not enough ressources are available - * - * @see LlcpSocket - */ - public LlcpSocket accept() throws IOException, LlcpException { - - try { - int handle = mService.accept(mHandle); - // Handle potential errors - if (ErrorCodes.isError(handle)) { - if (handle == ErrorCodes.ERROR_IO) { - throw new IOException(); - } else { - throw convertErrorToLlcpException(handle); - } - } - - // Build the public LlcpSocket object - return new LlcpSocket(mLlcpSocketService, handle); - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in accept(): ", e); - return null; - } - - } - - /** - * Close the created Llcp Service socket - */ - public void close() { - try { - mService.close(mHandle); - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in close(): ", e); - } - } -} diff --git a/core/java/com/android/internal/nfc/LlcpSocket.java b/core/java/com/android/internal/nfc/LlcpSocket.java deleted file mode 100644 index 63888ae..0000000 --- a/core/java/com/android/internal/nfc/LlcpSocket.java +++ /dev/null @@ -1,289 +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.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 - */ -public class LlcpSocket { - - private static final String TAG = "LlcpSocket"; - - /** - * The handle returned by the NFC service and used to identify the LLCP - * socket in every call of this class. - */ - protected int mHandle; - - /** - * The entry point for LLCP socket operations. - */ - protected ILlcpSocket mService; - - static LlcpException convertErrorToLlcpException(int errorCode) { - return convertErrorToLlcpException(errorCode, null); - } - - static LlcpException convertErrorToLlcpException(int errorCode, - String message) { - if (message == null) { - message = ""; - } else { - message = " (" + message + ")"; - } - - switch (errorCode) { - case ErrorCodes.ERROR_SOCKET_CREATION: - return new LlcpException( - "Error during the creation of an Llcp socket" + message); - case ErrorCodes.ERROR_INSUFFICIENT_RESOURCES: - return new LlcpException("Not enough ressources are available" - + message); - case ErrorCodes.ERROR_SOCKET_NOT_CONNECTED: - return new LlcpException("Socket not connected to an Llcp Service" - + message); - default: - return new LlcpException("Unkown error code " + errorCode + message); - } - } - - /** - * Internal constructor for the LlcpSocket class. - * - * @param service - * The entry point to the Nfc Service for LlcpServiceSocket - * class. - * @param handle - * The handle returned by the NFC service and used to identify - * the socket in subsequent calls. - * @hide - */ - public LlcpSocket(ILlcpSocket service, int handle) { - this.mService = service; - this.mHandle = handle; - } - - /** - * Connect request to a specific LLCP Service by its SAP. - * - * @param sap - * Service Access Point number of the LLCP Service - * @throws IOException - * if the LLCP has been lost or deactivated. - * @throws LlcpException - * if the connection request is rejected by the remote LLCP - * Service - */ - public void connect(int sap) throws IOException, LlcpException { - try { - int result = mService.connect(mHandle, sap); - // Handle potential errors - if (ErrorCodes.isError(result)) { - if (result == ErrorCodes.ERROR_IO) { - throw new IOException(); - } else { - throw convertErrorToLlcpException(result); - } - } - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in accept(): ", e); - } - } - - /** - * Connect request to a specific LLCP Service by its Service Name. - * - * @param sn - * Service Name of the LLCP Service - * @throws IOException - * if the LLCP has been lost or deactivated. - * @throws LlcpException - * if the connection request is rejected by the remote LLCP - * Service - */ - public void connect(String sn) throws IOException, LlcpException { - try { - int result = mService.connectByName(mHandle, sn); - // Handle potential errors - if (ErrorCodes.isError(result)) { - if (result == ErrorCodes.ERROR_IO) { - throw new IOException(); - } else { - throw convertErrorToLlcpException(result); - } - } - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in accept(): ", e); - } - } - - /** - * Disconnect request to the connected LLCP socket and close the created - * socket. - * - * @throws IOException - * if the LLCP has been lost or deactivated. - */ - public void close() throws IOException { - try { - int result = mService.close(mHandle); - // Handle potential errors - if (ErrorCodes.isError(result)) { - throw new IOException(); - } - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in close(): ", e); - } - } - - /** - * Send data to the connected LLCP Socket. - * - * @throws IOException - * if the LLCP has been lost or deactivated. - */ - public void send(byte[] data) throws IOException { - try { - int result = mService.send(mHandle, data); - // Handle potential errors - if (ErrorCodes.isError(result)) { - throw new IOException(); - } - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in send(): ", e); - } - } - - /** - * Receive data from the connected LLCP socket - * - * @param receiveBuffer - * a buffer for the received data - * @return length length of the data received - * @throws IOException - * if the LLCP has been lost or deactivated. - */ - public int receive(byte[] receiveBuffer) throws IOException { - int receivedLength = 0; - try { - receivedLength = mService.receive(mHandle, receiveBuffer); - if(receivedLength == 0){ - throw new IOException(); - } - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in receive(): ", e); - } - - return receivedLength; - } - - /** - * Returns the local Service Access Point number of the socket - * - * @return localSap - */ - public int getLocalSap() { - try { - return mService.getLocalSap(mHandle); - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in getLocalSap(): ", e); - return 0; - } - } - - /** - * Returns the local Maximum Information Unit(MIU) of the socket - * - * @return miu - */ - public int getLocalSocketMiu() { - try { - return mService.getLocalSocketMiu(mHandle); - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in getLocalSocketMiu(): ", e); - return 0; - } - } - - /** - * Returns the local Receive Window(RW) of the socket - * - * @return rw - */ - public int getLocalSocketRw() { - try { - return mService.getLocalSocketRw(mHandle); - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in getLocalSocketRw(): ", e); - return 0; - } - } - - /** - * Returns the remote Maximum Information Unit(MIU) of the socket. - * <p> - * This method must be called when the socket is in CONNECTED_STATE - * - * @return remoteMiu - * @throws LlcpException - * if the LlcpClientSocket is not in a CONNECTED_STATE - */ - public int getRemoteSocketMiu() throws LlcpException { - try { - int result = mService.getRemoteSocketMiu(mHandle); - if(result != ErrorCodes.ERROR_SOCKET_NOT_CONNECTED){ - return result; - }else{ - throw convertErrorToLlcpException(result); - } - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in getRemoteSocketMiu(): ", e); - return 0; - } - } - - /** - * Returns the remote Receive Window(RW) of the connected remote socket. - * <p> - * This method must be called when the socket is in CONNECTED_STATE - * - * @return rw - * @throws LlcpException - * if the LlcpClientSocket is not in a CONNECTED_STATE - */ - public int getRemoteSocketRw() throws LlcpException { - try { - int result = mService.getRemoteSocketRw(mHandle); - if( result != ErrorCodes.ERROR_SOCKET_NOT_CONNECTED){ - return result; - }else{ - throw convertErrorToLlcpException(result); - } - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in getRemoteSocketRw(): ", e); - return 0; - } - } -} diff --git a/core/java/com/android/internal/nfc/NfcException.java b/core/java/com/android/internal/nfc/NfcException.java deleted file mode 100644 index 29a99c6..0000000 --- a/core/java/com/android/internal/nfc/NfcException.java +++ /dev/null @@ -1,33 +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.android.internal.nfc; - -/** - * Generic exception thrown in case something unexpected happened during the - * NFCManager operations. - */ -public class NfcException extends Exception { - /** - * Constructs a new NfcException with the current stack trace and the - * specified detail message. - * - * @param s the detail message for this exception. - */ - public NfcException(String s) { - super(s); - } -} diff --git a/core/java/com/android/internal/nfc/P2pDevice.java b/core/java/com/android/internal/nfc/P2pDevice.java deleted file mode 100644 index 8ab9aad..0000000 --- a/core/java/com/android/internal/nfc/P2pDevice.java +++ /dev/null @@ -1,79 +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.android.internal.nfc; - -import java.io.IOException; - -/** - * P2pDevice is the abstract base class for all supported P2P targets the - * NfcManager can handle. - */ -public abstract class P2pDevice { - - /** - * Peer-to-Peer Target. - */ - public static final short MODE_P2P_TARGET = 0x00; - - /** - * Peer-to-Peer Initiator. - */ - public static final short MODE_P2P_INITIATOR = 0x01; - - /** - * Invalid target type. - */ - public static final short MODE_INVALID = 0xff; - - /** - * Target handle, used by native calls. - */ - protected int mHandle; - - /** - * Flag set when the object is closed and thus not usable any more. - */ - protected boolean isClosed = false; - - /** - * Prevent default constructor to be public. - */ - protected P2pDevice() { - } - - /** - * Returns the remote NFC-IP1 General Bytes. - * - * @return remote general bytes - * @throws IOException - */ - public byte[] getGeneralBytes() throws IOException { - // Should not be called directly (use subclasses overridden method instead) - return null; - } - - /** - * Returns target type. The value returned can be one of the TYPE_* - * constants. - * - * @return target type. - */ - public int getMode() { - // Should not be called directly (use subclasses overridden method instead) - return MODE_INVALID; - } -} diff --git a/core/java/com/android/internal/nfc/P2pInitiator.java b/core/java/com/android/internal/nfc/P2pInitiator.java deleted file mode 100644 index 46ae9ab..0000000 --- a/core/java/com/android/internal/nfc/P2pInitiator.java +++ /dev/null @@ -1,104 +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.android.internal.nfc; - -import java.io.IOException; - -import android.nfc.IP2pInitiator; -import android.os.RemoteException; -import android.util.Log; - -/** - * P2pInitiator represents the initiator in an NFC-IP1 peer-to-peer - * communication. - * - * @see P2pTarget - */ -public class P2pInitiator extends P2pDevice { - - private static final String TAG = "P2pInitiator"; - - /** - * The entry point for P2P tag operations. - */ - private final IP2pInitiator mService; - - /** - * Internal constructor for the P2pInitiator class. - * - * @param handle The handle returned by the NFC service and used to identify - * the tag in subsequent calls. - */ - P2pInitiator(IP2pInitiator service, int handle) { - this.mService = service; - this.mHandle = handle; - } - - /** - * Receives data from a P2pInitiator. - * - * @return data sent by the P2pInitiator. - * @throws IOException if the target has been lost or if the connection has - * been closed. - */ - public byte[] receive() throws IOException { - try { - byte[] result = mService.receive(mHandle); - if (result == null) { - throw new IOException("Tag has been lost"); - } - return result; - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in receive(): ", e); - return null; - } - } - - /** - * Sends data to a P2pInitiator. - * - * @param data data to be sent to the P2pInitiator. - * @throws IOException if the target has been lost or if the connection has - * been closed. - */ - public void send(byte[] data) throws IOException { - try { - boolean isSuccess = mService.send(mHandle, data); - if (!isSuccess) { - throw new IOException("Tag has been lost"); - } - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in send(): ", e); - } - } - - @Override - public byte[] getGeneralBytes() { - try { - return mService.getGeneralBytes(mHandle); - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in getGeneralBytes(): ", e); - return null; - } - } - - @Override - public int getMode() { - return P2pDevice.MODE_P2P_INITIATOR; - } - -} diff --git a/core/java/com/android/internal/nfc/P2pTarget.java b/core/java/com/android/internal/nfc/P2pTarget.java deleted file mode 100644 index 7b59da3..0000000 --- a/core/java/com/android/internal/nfc/P2pTarget.java +++ /dev/null @@ -1,170 +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.android.internal.nfc; - -import java.io.IOException; - -import android.nfc.ErrorCodes; -import android.nfc.IP2pTarget; -import android.os.RemoteException; -import android.util.Log; - -/** - * P2pTarget represents the target in an NFC-IP1 peer-to-peer communication. - * - * @see P2pInitiator - */ -public class P2pTarget extends P2pDevice { - - private static final String TAG = "P2pTarget"; - - /** - * The entry point for P2P tag operations. - */ - private final IP2pTarget mService; - - /** - * Flag set when the object is closed and thus not usable any more. - */ - private final boolean isClosed = false; - - /** - * Flag set when the tag is connected. - */ - private boolean isConnected = false; - - /** - * Check if tag is still opened. - * - * @return data sent by the P2pInitiator. - * @throws NfcException if accessing a closed target. - */ - public void checkState() throws NfcException { - if(isClosed) { - throw new NfcException("Tag has been closed."); - } - } - - /** - * Internal constructor for the P2pTarget class. - * - * @param handle The handle returned by the NFC service and used to identify - * the tag in subsequent calls. - */ - P2pTarget(IP2pTarget service, int handle) { - this.mService = service; - this.mHandle = handle; - } - - /** - * Connects to the P2pTarget. This shall be called prior to any other - * operation on the P2pTarget. - * - * @throws NfcException - */ - public void connect() throws NfcException { - // Check state - checkState(); - 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 NfcException("Failed to connect"); - } - else { - // TODO(nxp) - // throw NfcAdapter.convertErrorToNfcException(result); - } - } - isConnected = true; - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in connect(): ", e); - } - } - - /** - * Disconnects from the P2p Target. This must be called so that other - * targets can be discovered. It restarts the NFC discovery loop. - * - * @throws NFCException - */ - public void disconnect() throws NfcException { - checkState(); - try { - mService.disconnect(mHandle); - isConnected = true; - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in disconnect(): ", e); - } - } - - /** - * Exchanges raw data with the P2pTarget. - * - * @param data data to be sent to the P2pTarget - * @return data sent in response by the P2pTarget - * @throws IOException if the target 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; - } - } - - /** - * Get the 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 - */ - @Override - public byte[] getGeneralBytes() throws IOException { - try { - if(isConnected){ - return mService.getGeneralBytes(mHandle); - }else{ - throw new IOException("Target not in connected state"); - } - } catch (RemoteException e) { - Log.e(TAG, "RemoteException in getGeneralBytes(): ", e); - return null; - } - } - - @Override - public int getMode() { - return P2pDevice.MODE_P2P_TARGET; - } -} |