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

Commit e347e590 authored by Bhasker Neti's avatar Bhasker Neti
Browse files

Bluetooth: Acquire wake lock to avoid power collapse

This ensures that target wont go into power save mode
when there is an acl is active and timer are running.

Change-Id: I9789c8ae0781a1ca4d33d364efd583ea16e9ee21
CRs-fixed: 576239
parent f53d911a
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ static jmethodID method_bondStateChangeCallback;
static jmethodID method_aclStateChangeCallback;
static jmethodID method_discoveryStateChangeCallback;
static jmethodID method_deviceMasInstancesFoundCallback;
static jmethodID method_wakeStateChangeCallback;

static const bt_interface_t *sBluetoothInterface = NULL;
static const btsock_interface_t *sBluetoothSocketInterface = NULL;
@@ -349,7 +350,20 @@ static void discovery_state_changed_callback(bt_discovery_state_t state) {

    checkAndClearExceptionFromCallback(callbackEnv, __FUNCTION__);
}
static void wake_state_changed_callback(bt_state_t state) {

    if (!checkCallbackThread()) {
       ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__);
       return;
    }

    ALOGV("%s: WakeState:%d ", __FUNCTION__, state);

    callbackEnv->CallVoidMethod(sJniCallbacksObj, method_wakeStateChangeCallback,
                                (jint)state);

    checkAndClearExceptionFromCallback(callbackEnv, __FUNCTION__);
}
static void pin_request_callback(bt_bdaddr_t *bd_addr, bt_bdname_t *bdname, uint32_t cod, uint8_t secure) {
    jbyteArray addr, devname;
    if (!checkCallbackThread()) {
@@ -451,6 +465,7 @@ bt_callbacks_t sBluetoothCallbacks = {
    remote_device_properties_callback,
    device_found_callback,
    discovery_state_changed_callback,
    wake_state_changed_callback,
    pin_request_callback,
    ssp_request_callback,
    bond_state_changed_callback,
@@ -554,7 +569,8 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
                                                             "([I[[B)V");
    method_discoveryStateChangeCallback = env->GetMethodID(jniCallbackClass,
                                                           "discoveryStateChangeCallback", "(I)V");

    method_wakeStateChangeCallback = env->GetMethodID(jniCallbackClass,
                                                           "wakeStateChangeCallback", "(I)V");
    method_devicePropertyChangedCallback = env->GetMethodID(jniCallbackClass,
                                                            "devicePropertyChangedCallback",
                                                            "([B[I[[B)V");
+1 −0
Original line number Diff line number Diff line
@@ -233,6 +233,7 @@ bt_callbacks_t sQBluetoothCallbacks = {
    NULL,
    NULL,
    NULL,
    NULL,
    le_extended_scan_result_callbacks,
    le_lpp_write_rssi_thresh_callbacks,
    le_lpp_read_rssi_thresh_callbacks,
+4 −2
Original line number Diff line number Diff line
@@ -70,7 +70,9 @@ final class JniCallbacks {
    void aclStateChangeCallback(int status, byte[] address, int newState) {
        mRemoteDevices.aclStateChangeCallback(status, address, newState);
    }

    void wakeStateChangeCallback(int state) {
        mRemoteDevices.wakeStateChangeCallback(state);
    }
    void stateChangeCallback(int status) {
        mAdapterStateMachine.stateChangeCallback(status);
    }
+25 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ final class RemoteDevices {
    /* The WakeLock is used for bringing up the LCD during a pairing request
     * from remote device when Android is in Suspend state.*/
    private PowerManager.WakeLock mWakeLock;
    private PowerManager.WakeLock mWakeLock_stack;
    private Object mObject = new Object();

    private static final int UUID_INTENT_DELAY = 6000;
@@ -70,6 +71,10 @@ final class RemoteDevices {
        mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                       | PowerManager.ON_AFTER_RELEASE, TAG);
        mWakeLock.setReferenceCounted(false);
        //WakeLock instantiation in RemoteDevices class
        mWakeLock_stack = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                       | PowerManager.ON_AFTER_RELEASE, TAG);
        mWakeLock_stack.setReferenceCounted(false);

    }

@@ -83,6 +88,13 @@ final class RemoteDevices {

        if (mDevices != null)
            mDevices.clear();

        if ((mWakeLock_stack != null) && // we have a WakeLock
           (mWakeLock_stack.isHeld() == true)) { // we hold it
            mWakeLock_stack.release ();
            mWakeLock_stack = null;
        }

    }

    public Object Clone() throws CloneNotSupportedException {
@@ -529,6 +541,19 @@ final class RemoteDevices {

        sendMasInstanceIntent(device, instances);
    }
    void wakeStateChangeCallback(int state) {
        if (state == 0x01) {
        // Acquire wakelock to not allow Device to go into power collapse
             mWakeLock_stack.acquire();
             debugLog("Wake lock Aquired");
        } else if (state == 0x00){
        // Release wakelock to allow Device to go into power collapse.
             mWakeLock_stack.release();
             debugLog("Wake lock released");
        } else
             errorLog("Wake lock WRONG STATE ***** ");

    }

    void fetchUuids(BluetoothDevice device) {
        if (mSdpTracker.contains(device)) return;