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

Commit 24be1bb1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Bluetooth: Fix gatt can't writeCharacteristic" am: 8dea13fc

parents 3f0925bc 8dea13fc
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -258,9 +258,9 @@ public class GattService extends ProfileService {

    /**
     * HashMap used to synchronize writeCharacteristic calls mapping remote device address to
     * available permit (either 1 or 0).
     * available permit (connectId or -1).
     */
    private final HashMap<String, AtomicBoolean> mPermits = new HashMap<>();
    private final HashMap<String, Integer> mPermits = new HashMap<>();

    private AdapterService mAdapterService;
    private BluetoothAdapterProxy mBluetoothAdapterProxy;
@@ -2020,7 +2020,7 @@ public class GattService extends ProfileService {
            synchronized (mPermits) {
                Log.d(TAG, "onConnected() - adding permit for address="
                    + address);
                mPermits.putIfAbsent(address, new AtomicBoolean(true));
                mPermits.putIfAbsent(address, -1);
            }
            connectionState = BluetoothProtoEnums.CONNECTION_STATE_CONNECTED;

@@ -2052,6 +2052,13 @@ public class GattService extends ProfileService {
                    + address);
                mPermits.remove(address);
            }
        } else {
            synchronized (mPermits) {
                if (mPermits.get(address) == connId) {
                    Log.d(TAG, "onDisconnected() - set permit -1 for address=" + address);
                    mPermits.put(address, -1);
                }
            }
        }

        if (app != null) {
@@ -2357,7 +2364,7 @@ public class GattService extends ProfileService {
        synchronized (mPermits) {
            Log.d(TAG, "onWriteCharacteristic() - increasing permit for address="
                    + address);
            mPermits.get(address).set(true);
            mPermits.put(address, -1);
        }

        if (VDBG) {
@@ -3653,18 +3660,18 @@ public class GattService extends ProfileService {
        Log.d(TAG, "writeCharacteristic() - trying to acquire permit.");
        // Lock the thread until onCharacteristicWrite callback comes back.
        synchronized (mPermits) {
            AtomicBoolean atomicBoolean = mPermits.get(address);
            if (atomicBoolean == null) {
            Integer permit = mPermits.get(address);
            if (permit == null) {
                Log.d(TAG, "writeCharacteristic() -  atomicBoolean uninitialized!");
                return BluetoothStatusCodes.ERROR_DEVICE_NOT_CONNECTED;
            }

            boolean success = atomicBoolean.get();
            boolean success = (permit == -1);
            if (!success) {
                Log.d(TAG, "writeCharacteristic() - no permit available.");
                return BluetoothStatusCodes.ERROR_GATT_WRITE_REQUEST_BUSY;
            }
            atomicBoolean.set(false);
            mPermits.put(address, connId);
        }

        mNativeInterface.gattClientWriteCharacteristic(connId, handle, writeType, authReq, value);