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

Commit 8a4d25c2 authored by zhoutengteng's avatar zhoutengteng Committed by Andre Eisenbach
Browse files

Fix deadlock of mObject and mDevices in RemoteDevices



In RemoteDevices.java, the object mObject and mDevices are used
for synchronized, but there are some cases that two threads come
into deadlock between mObject and mDevices. This solution makes
sure that the thread of devicePropertyChangedCallback does not
require two objects at a same time to avoid the deadlock.

Fixes: 78784797
Test: Compile; unable to trigger race condition reliably
Change-Id: I0987ca9cd29d363faa3b43b7844db675401ef354
Signed-off-by: default avatarzhoutengteng <zhoutengteng@xiaomi.com>
parent dddfc485
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -79,7 +79,8 @@ final class RemoteDevices {
                case MESSAGE_UUID_INTENT:
                    BluetoothDevice device = (BluetoothDevice) msg.obj;
                    if (device != null) {
                        sendUuidIntent(device);
                        DeviceProperties prop = getDeviceProperties(device);
                        sendUuidIntent(device, prop);
                    }
                    break;
            }
@@ -365,8 +366,7 @@ final class RemoteDevices {
        }
    }

    private void sendUuidIntent(BluetoothDevice device) {
        DeviceProperties prop = getDeviceProperties(device);
    private void sendUuidIntent(BluetoothDevice device, DeviceProperties prop) {
        Intent intent = new Intent(BluetoothDevice.ACTION_UUID);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        intent.putExtra(BluetoothDevice.EXTRA_UUID, prop == null ? null : prop.mUuids);
@@ -545,7 +545,7 @@ final class RemoteDevices {
                            }
                            device.mUuids = newUuids;
                            if (sAdapterService.getState() == BluetoothAdapter.STATE_ON) {
                                sendUuidIntent(bdDevice);
                                sendUuidIntent(bdDevice, device);
                            }
                            break;
                        case AbstractionLayer.BT_PROPERTY_TYPE_OF_DEVICE: