Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34bd633f authored by Pavlin Radoslavov's avatar Pavlin Radoslavov
Browse files

Run the wakelock JNI callbacks on the JNI thread

All JNI callbacks must be on the JNI thread, otherwise this could
impact the threads' operation.

Bug: 111277984
Test: A2DP streaming
Change-Id: I94fa4500aea62a574c80749e904434e46eb4e942
parent 967a15bb
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -413,8 +413,32 @@ int le_test_mode(uint16_t opcode, uint8_t* buf, uint8_t len) {
  return btif_le_test_mode(opcode, buf, len);
}

static bt_os_callouts_t* wakelock_os_callouts_saved = nullptr;

static int acquire_wake_lock_cb(const char* lock_name) {
  return do_in_jni_thread(
      FROM_HERE, base::Bind(base::IgnoreResult(
                                wakelock_os_callouts_saved->acquire_wake_lock),
                            lock_name));
}

static int release_wake_lock_cb(const char* lock_name) {
  return do_in_jni_thread(
      FROM_HERE, base::Bind(base::IgnoreResult(
                                wakelock_os_callouts_saved->release_wake_lock),
                            lock_name));
}

static bt_os_callouts_t wakelock_os_callouts_jni = {
    sizeof(wakelock_os_callouts_jni),
    nullptr /* not used */,
    acquire_wake_lock_cb,
    release_wake_lock_cb,
};

static int set_os_callouts(bt_os_callouts_t* callouts) {
  wakelock_set_os_callouts(callouts);
  wakelock_os_callouts_saved = callouts;
  wakelock_set_os_callouts(&wakelock_os_callouts_jni);
  return BT_STATUS_SUCCESS;
}