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 19:07:39 +0000 (12:07 -0700)
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 854e9ae..d231f0f 100644 (file)
@@ -727,7 +727,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() {