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

Commit ddfaa805 authored by Dmitry Grinberg's avatar Dmitry Grinberg
Browse files

DO NOT MERGE: Fix concurrency issues with wakelock support

Bluedroid seems to have paths through it that lead us to here in many
ways. Add a lock to prevent confusing ourselves.

Bug: 15532889
Change-Id: Idaa828d9c49fbca5d52bfeeb6e6109df20170e0b
parent 58adcf54
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -447,6 +447,9 @@ static void le_test_mode_recv_callback (bt_status_t status, uint16_t packet_coun
static void bt_wakelock_control_callback(int acquire) {
    static sp<IPowerManager> sPm = NULL;
    static sp<IBinder> sWakelock = NULL;
    static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

    pthread_mutex_lock(&mutex);

    if (sPm == NULL) {
        sp<IBinder> binder = defaultServiceManager()->checkService(String16("power"));
@@ -454,7 +457,7 @@ static void bt_wakelock_control_callback(int acquire) {

        if (sPm == NULL) {
            ALOGE("Unable to get a hold of PowerManager. Bluetooth wakelocks will not function");
            return;
            goto out;
        }
    }
    if (acquire) {
@@ -474,6 +477,8 @@ static void bt_wakelock_control_callback(int acquire) {
            sWakelock.clear();
        }
    }
out:
    pthread_mutex_unlock(&mutex);
}

bt_callbacks_t sBluetoothCallbacks = {