OSDN Git Service

Fix a deadlock in service discovery callbacks
authorJakub Pawlowski <jpawlowski@google.com>
Fri, 19 Aug 2016 11:08:18 +0000 (04:08 -0700)
committerJakub Pawlowski <jpawlowski@google.com>
Mon, 22 Aug 2016 11:17:21 +0000 (11:17 +0000)
onSearchCompleted calling gattClientGetGattDbNative directly, might
cause deadlock if the jni_workqueue is full.

Bug: 30835367
Change-Id: I05de735aa189dd2d250f2c5816d38c2ddcabb864

src/com/android/bluetooth/gatt/GattService.java

index 0ef6079..c4a0807 100644 (file)
@@ -650,7 +650,15 @@ public class GattService extends ProfileService {
     void onSearchCompleted(int connId, int status) throws RemoteException {
         if (DBG) Log.d(TAG, "onSearchCompleted() - connId=" + connId+ ", status=" + status);
         // Gatt DB is ready!
-        gattClientGetGattDbNative(connId);
+
+        // This callback was called from the jni_workqueue thread. If we make request to the stack
+        // on the same thread, it might cause deadlock. Schedule request on a new thread instead.
+        Thread t = new Thread(new Runnable() {
+            public void run() {
+                gattClientGetGattDbNative(connId);
+            }
+        });
+        t.start();
     }
 
     GattDbElement GetSampleGattDbElement() {