summaryrefslogtreecommitdiffstats
path: root/core/java/android/bluetooth/BluetoothSocket.java
diff options
context:
space:
mode:
authorzzy <zhenye@broadcom.com>2012-11-22 11:52:44 -0800
committerMatthew Xie <mattx@google.com>2012-11-28 22:12:27 -0800
commit652678af4d18b9a6c18ce6a860de01d958bc82fe (patch)
tree324d5679f1b04d6f09e15af35b17d02b477bc63d /core/java/android/bluetooth/BluetoothSocket.java
parentcdc6d5cf88e8eb73a557052679c436e864cb1853 (diff)
downloadframeworks_base-652678af4d18b9a6c18ce6a860de01d958bc82fe.zip
frameworks_base-652678af4d18b9a6c18ce6a860de01d958bc82fe.tar.gz
frameworks_base-652678af4d18b9a6c18ce6a860de01d958bc82fe.tar.bz2
timeout support for accept() and added check for signal size
bug 7592240 Change-Id: Ide1868da669c190cdfed90f7af3f739ec9da690b
Diffstat (limited to 'core/java/android/bluetooth/BluetoothSocket.java')
-rw-r--r--core/java/android/bluetooth/BluetoothSocket.java16
1 files changed, 9 insertions, 7 deletions
diff --git a/core/java/android/bluetooth/BluetoothSocket.java b/core/java/android/bluetooth/BluetoothSocket.java
index 26bde19..d7a214d 100644
--- a/core/java/android/bluetooth/BluetoothSocket.java
+++ b/core/java/android/bluetooth/BluetoothSocket.java
@@ -300,7 +300,6 @@ public final class BluetoothSocket implements Closeable {
if (mDevice == null) throw new IOException("Connect is called on null device");
try {
- // TODO(BT) derive flag from auth and encrypt
if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed");
IBluetooth bluetoothProxy = BluetoothAdapter.getDefaultAdapter().getBluetoothService(null);
if (bluetoothProxy == null) throw new IOException("Bluetooth is off");
@@ -349,7 +348,6 @@ public final class BluetoothSocket implements Closeable {
mUuid, mPort, getSecurityFlags());
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(new Throwable()));
- // TODO(BT) right error code?
return -1;
}
@@ -388,8 +386,13 @@ public final class BluetoothSocket implements Closeable {
/*package*/ BluetoothSocket accept(int timeout) throws IOException {
BluetoothSocket acceptedSocket;
if (mSocketState != SocketState.LISTENING) throw new IOException("bt socket is not in listen state");
- // TODO(BT) wait on an incoming connection
+ if(timeout > 0) {
+ Log.d(TAG, "accept() set timeout (ms):" + timeout);
+ mSocket.setSoTimeout(timeout);
+ }
String RemoteAddr = waitSocketSignal(mSocketIS);
+ if(timeout > 0)
+ mSocket.setSoTimeout(0);
synchronized(this)
{
if (mSocketState != SocketState.LISTENING)
@@ -397,8 +400,6 @@ public final class BluetoothSocket implements Closeable {
acceptedSocket = acceptSocket(RemoteAddr);
//quick drop the reference of the file handle
}
- // TODO(BT) rfcomm socket only supports one connection, return this?
- // return this;
return acceptedSocket;
}
@@ -451,7 +452,6 @@ public final class BluetoothSocket implements Closeable {
mPfd.detachFd();
}
}
- // TODO(BT) unbind proxy,
}
/*package */ void removeChannel() {
@@ -471,6 +471,8 @@ public final class BluetoothSocket implements Closeable {
ByteBuffer bb = ByteBuffer.wrap(sig);
bb.order(ByteOrder.nativeOrder());
int size = bb.getShort();
+ if(size != SOCK_SIGNAL_SIZE)
+ throw new IOException("Connection failure, wrong signal size: " + size);
byte [] addr = new byte[6];
bb.get(addr);
int channel = bb.getInt();
@@ -487,7 +489,7 @@ public final class BluetoothSocket implements Closeable {
while(left > 0) {
int ret = is.read(b, b.length - left, left);
if(ret <= 0)
- throw new IOException("read failed, socket might closed, read ret: " + ret);
+ throw new IOException("read failed, socket might closed or timeout, read ret: " + ret);
left -= ret;
if(left != 0)
Log.w(TAG, "readAll() looping, read partial size: " + (b.length - left) +