OSDN Git Service

Bluetooth: Add additional BluetoothSocket logging to root cause errors
authorAjay Panicker <apanicke@google.com>
Tue, 28 Mar 2017 21:28:27 +0000 (14:28 -0700)
committerAjay Panicker <apanicke@google.com>
Fri, 31 Mar 2017 21:22:59 +0000 (21:22 +0000)
Bug: 34780400
Test: Code still compiles
Change-Id: I166842ecc6889f9ea403e7aa3678ed818cd80968

core/java/android/bluetooth/BluetoothSocket.java

index 98a5341..6bf6aa0 100644 (file)
@@ -416,6 +416,11 @@ public final class BluetoothSocket implements Closeable {
                 if(mSocketState != SocketState.INIT) return EBADFD;
                 if(mPfd == null) return -1;
                 FileDescriptor fd = mPfd.getFileDescriptor();
+                if (fd == null) {
+                    Log.e(TAG, "bindListen(), null file descriptor");
+                    return -1;
+                }
+
                 if (DBG) Log.d(TAG, "bindListen(), Create LocalSocket");
                 mSocket = LocalSocket.createConnectedLocalSocket(fd);
                 if (DBG) Log.d(TAG, "bindListen(), new LocalSocket.getInputStream()");
@@ -556,8 +561,9 @@ public final class BluetoothSocket implements Closeable {
 
     @Override
     public void close() throws IOException {
-        if (DBG) Log.d(TAG, "close() in, this: " + this + ", channel: " + mPort + ", state: "
-                + mSocketState);
+        Log.d(TAG, "close() this: " + this + ", channel: " + mPort +
+            ", mSocketIS: " + mSocketIS + ", mSocketOS: " + mSocketOS +
+            "mSocket: " + mSocket + ", mSocketState: " + mSocketState);
         if(mSocketState == SocketState.CLOSED)
             return;
         else
@@ -567,9 +573,6 @@ public final class BluetoothSocket implements Closeable {
                  if(mSocketState == SocketState.CLOSED)
                     return;
                  mSocketState = SocketState.CLOSED;
-                 if (DBG) Log.d(TAG, "close() this: " + this + ", channel: " + mPort +
-                         ", mSocketIS: " + mSocketIS + ", mSocketOS: " + mSocketOS +
-                         "mSocket: " + mSocket);
                  if(mSocket != null) {
                     if (DBG) Log.d(TAG, "Closing mSocket: " + mSocket);
                     mSocket.shutdownInput();