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

Commit d33c1168 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "Bluetooth: Fix PXP LPP app link loss reconnection"

parents 0b9db08e 987cbcf0
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ public final class BluetoothLwPwrProximityMonitor implements QBluetoothAdapter.
    /* This timer is triggered in case that BluetoothGatt does not callback when we perform connect/disconnect */
    private Timer     mTimer = null;
    private final int mTimeOutValue = 30*1000;
    public boolean isWriteThresholdNeedToBeCalled = false;
    private final class ConnectTimeOutTask extends TimerTask {
        public void run() {
            if (DBG) Log.d(TAG, "connect timer triggered!");
@@ -139,8 +140,9 @@ public final class BluetoothLwPwrProximityMonitor implements QBluetoothAdapter.
                        stop = true;
                    }
                } else if (newState == BluetoothProfile.STATE_CONNECTED) {
                    if (mState == MONITOR_STATE_STARTING) {
                    if (mState == MONITOR_STATE_STARTING && isWriteThresholdNeedToBeCalled) {
                        if (status == BluetoothGatt.GATT_SUCCESS) {
                            isWriteThresholdNeedToBeCalled = false;
                            if(!mQAdapter.writeRssiThreshold(BluetoothLwPwrProximityMonitor.this, mLowerLimit, mUpperLimit)) {
                                mGattProfile.disconnect();
                                mState = MONITOR_STATE_STOPPING;
@@ -151,6 +153,10 @@ public final class BluetoothLwPwrProximityMonitor implements QBluetoothAdapter.
                            stop = true;
                        }
                    }
                    if (status != BluetoothGatt.GATT_SUCCESS) {
                        mState = MONITOR_STATE_IDLE;
                        stop = true;
                    }
                }
            }
            if (stop && mMonitorCbk != null){
@@ -206,6 +212,7 @@ public final class BluetoothLwPwrProximityMonitor implements QBluetoothAdapter.
    /** @hide */
    public boolean start (int thresh_min, int thresh_max) {
        if (DBG) Log.d(TAG, "start() low=" + thresh_min + ", upper=" + thresh_max);
        isWriteThresholdNeedToBeCalled = true;
        synchronized(mStateLock){
            if (mState != MONITOR_STATE_IDLE) {
                if (DBG) Log.d(TAG, "start() invalid state, monitor is not idle");
@@ -233,6 +240,16 @@ public final class BluetoothLwPwrProximityMonitor implements QBluetoothAdapter.
                        mState = MONITOR_STATE_IDLE;
                        return false;
                    }
                    else {
                        if (mState == MONITOR_STATE_STARTING && isWriteThresholdNeedToBeCalled) {
                            isWriteThresholdNeedToBeCalled = false;
                            if(!mQAdapter.writeRssiThreshold(BluetoothLwPwrProximityMonitor.this, mLowerLimit, mUpperLimit)) {
                                mGattProfile.disconnect();
                                mState = MONITOR_STATE_STOPPING;
                                setTimer(BluetoothLwPwrProximityMonitor.this.new DisconnectTimeOutTask(), mTimeOutValue);
                            }
                        }
                    }
                }
            } catch (IllegalStateException e) {
                mQAdapter.registerLppClient(this, mDevice.getAddress(), false);