Loading api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -4130,6 +4130,7 @@ package android.bluetooth { method public java.io.InputStream getInputStream() throws java.io.IOException; method public java.io.OutputStream getOutputStream() throws java.io.IOException; method public android.bluetooth.BluetoothDevice getRemoteDevice(); method public boolean isConnected(); } } core/java/android/bluetooth/BluetoothSocket.java +32 −12 Original line number Diff line number Diff line Loading @@ -94,10 +94,16 @@ public final class BluetoothSocket implements Closeable { private int mPort; /* RFCOMM channel or L2CAP psm */ private enum SocketState { INIT, CONNECTED, CLOSED } /** prevents all native calls after destroyNative() */ private boolean mClosed; private SocketState mSocketState; /** protects mClosed */ /** protects mSocketState */ private final ReentrantReadWriteLock mLock; /** used by native code only */ Loading Loading @@ -145,7 +151,7 @@ public final class BluetoothSocket implements Closeable { } mInputStream = new BluetoothInputStream(this); mOutputStream = new BluetoothOutputStream(this); mClosed = false; mSocketState = SocketState.INIT; mLock = new ReentrantReadWriteLock(); } Loading Loading @@ -195,13 +201,14 @@ public final class BluetoothSocket implements Closeable { public void connect() throws IOException { mLock.readLock().lock(); try { if (mClosed) throw new IOException("socket closed"); if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed"); if (mSdp != null) { mPort = mSdp.doSdp(); // blocks } connectNative(); // blocks mSocketState = SocketState.CONNECTED; } finally { mLock.readLock().unlock(); } Loading @@ -216,7 +223,7 @@ public final class BluetoothSocket implements Closeable { // abort blocking operations on the socket mLock.readLock().lock(); try { if (mClosed) return; if (mSocketState == SocketState.CLOSED) return; if (mSdp != null) { mSdp.cancel(); } Loading @@ -229,7 +236,7 @@ public final class BluetoothSocket implements Closeable { // abortNative(), so this lock should immediately acquire mLock.writeLock().lock(); try { mClosed = true; mSocketState = SocketState.CLOSED; destroyNative(); } finally { mLock.writeLock().unlock(); Loading Loading @@ -266,6 +273,16 @@ public final class BluetoothSocket implements Closeable { return mOutputStream; } /** * Get the connection status of this socket, ie, whether there is an active connection with * remote device. * @return true if connected * false if not connected */ public boolean isConnected() { return (mSocketState == SocketState.CONNECTED); } /** * Currently returns unix errno instead of throwing IOException, * so that BluetoothAdapter can check the error code for EADDRINUSE Loading @@ -273,7 +290,7 @@ public final class BluetoothSocket implements Closeable { /*package*/ int bindListen() { mLock.readLock().lock(); try { if (mClosed) return EBADFD; if (mSocketState == SocketState.CLOSED) return EBADFD; return bindListenNative(); } finally { mLock.readLock().unlock(); Loading @@ -283,8 +300,11 @@ public final class BluetoothSocket implements Closeable { /*package*/ BluetoothSocket accept(int timeout) throws IOException { mLock.readLock().lock(); try { if (mClosed) throw new IOException("socket closed"); return acceptNative(timeout); if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed"); BluetoothSocket acceptedSocket = acceptNative(timeout); mSocketState = SocketState.CONNECTED; return acceptedSocket; } finally { mLock.readLock().unlock(); } Loading @@ -293,7 +313,7 @@ public final class BluetoothSocket implements Closeable { /*package*/ int available() throws IOException { mLock.readLock().lock(); try { if (mClosed) throw new IOException("socket closed"); if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed"); return availableNative(); } finally { mLock.readLock().unlock(); Loading @@ -303,7 +323,7 @@ public final class BluetoothSocket implements Closeable { /*package*/ int read(byte[] b, int offset, int length) throws IOException { mLock.readLock().lock(); try { if (mClosed) throw new IOException("socket closed"); if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed"); return readNative(b, offset, length); } finally { mLock.readLock().unlock(); Loading @@ -313,7 +333,7 @@ public final class BluetoothSocket implements Closeable { /*package*/ int write(byte[] b, int offset, int length) throws IOException { mLock.readLock().lock(); try { if (mClosed) throw new IOException("socket closed"); if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed"); return writeNative(b, offset, length); } finally { mLock.readLock().unlock(); Loading Loading
api/current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -4130,6 +4130,7 @@ package android.bluetooth { method public java.io.InputStream getInputStream() throws java.io.IOException; method public java.io.OutputStream getOutputStream() throws java.io.IOException; method public android.bluetooth.BluetoothDevice getRemoteDevice(); method public boolean isConnected(); } }
core/java/android/bluetooth/BluetoothSocket.java +32 −12 Original line number Diff line number Diff line Loading @@ -94,10 +94,16 @@ public final class BluetoothSocket implements Closeable { private int mPort; /* RFCOMM channel or L2CAP psm */ private enum SocketState { INIT, CONNECTED, CLOSED } /** prevents all native calls after destroyNative() */ private boolean mClosed; private SocketState mSocketState; /** protects mClosed */ /** protects mSocketState */ private final ReentrantReadWriteLock mLock; /** used by native code only */ Loading Loading @@ -145,7 +151,7 @@ public final class BluetoothSocket implements Closeable { } mInputStream = new BluetoothInputStream(this); mOutputStream = new BluetoothOutputStream(this); mClosed = false; mSocketState = SocketState.INIT; mLock = new ReentrantReadWriteLock(); } Loading Loading @@ -195,13 +201,14 @@ public final class BluetoothSocket implements Closeable { public void connect() throws IOException { mLock.readLock().lock(); try { if (mClosed) throw new IOException("socket closed"); if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed"); if (mSdp != null) { mPort = mSdp.doSdp(); // blocks } connectNative(); // blocks mSocketState = SocketState.CONNECTED; } finally { mLock.readLock().unlock(); } Loading @@ -216,7 +223,7 @@ public final class BluetoothSocket implements Closeable { // abort blocking operations on the socket mLock.readLock().lock(); try { if (mClosed) return; if (mSocketState == SocketState.CLOSED) return; if (mSdp != null) { mSdp.cancel(); } Loading @@ -229,7 +236,7 @@ public final class BluetoothSocket implements Closeable { // abortNative(), so this lock should immediately acquire mLock.writeLock().lock(); try { mClosed = true; mSocketState = SocketState.CLOSED; destroyNative(); } finally { mLock.writeLock().unlock(); Loading Loading @@ -266,6 +273,16 @@ public final class BluetoothSocket implements Closeable { return mOutputStream; } /** * Get the connection status of this socket, ie, whether there is an active connection with * remote device. * @return true if connected * false if not connected */ public boolean isConnected() { return (mSocketState == SocketState.CONNECTED); } /** * Currently returns unix errno instead of throwing IOException, * so that BluetoothAdapter can check the error code for EADDRINUSE Loading @@ -273,7 +290,7 @@ public final class BluetoothSocket implements Closeable { /*package*/ int bindListen() { mLock.readLock().lock(); try { if (mClosed) return EBADFD; if (mSocketState == SocketState.CLOSED) return EBADFD; return bindListenNative(); } finally { mLock.readLock().unlock(); Loading @@ -283,8 +300,11 @@ public final class BluetoothSocket implements Closeable { /*package*/ BluetoothSocket accept(int timeout) throws IOException { mLock.readLock().lock(); try { if (mClosed) throw new IOException("socket closed"); return acceptNative(timeout); if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed"); BluetoothSocket acceptedSocket = acceptNative(timeout); mSocketState = SocketState.CONNECTED; return acceptedSocket; } finally { mLock.readLock().unlock(); } Loading @@ -293,7 +313,7 @@ public final class BluetoothSocket implements Closeable { /*package*/ int available() throws IOException { mLock.readLock().lock(); try { if (mClosed) throw new IOException("socket closed"); if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed"); return availableNative(); } finally { mLock.readLock().unlock(); Loading @@ -303,7 +323,7 @@ public final class BluetoothSocket implements Closeable { /*package*/ int read(byte[] b, int offset, int length) throws IOException { mLock.readLock().lock(); try { if (mClosed) throw new IOException("socket closed"); if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed"); return readNative(b, offset, length); } finally { mLock.readLock().unlock(); Loading @@ -313,7 +333,7 @@ public final class BluetoothSocket implements Closeable { /*package*/ int write(byte[] b, int offset, int length) throws IOException { mLock.readLock().lock(); try { if (mClosed) throw new IOException("socket closed"); if (mSocketState == SocketState.CLOSED) throw new IOException("socket closed"); return writeNative(b, offset, length); } finally { mLock.readLock().unlock(); Loading