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

Commit 809606a4 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "RemoteDevice: Fix for race condition on adding device properties" into main

parents edef9b9c 636011df
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -290,10 +290,16 @@ public class RemoteDevices {
    @VisibleForTesting
    DeviceProperties addDeviceProperties(byte[] address) {
        synchronized (mDevices) {
            String key = Utils.getAddressStringFromByte(address);
            if (Flags.fixAddDeviceProperties() && mDevices.containsKey(key)) {
                debugLog("Properties for device " + key + " are already added");
                return mDevices.get(key);
            }

            DeviceProperties prop = new DeviceProperties();
            prop.setDevice(mAdapter.getRemoteDevice(Utils.getAddressStringFromByte(address)));
            prop.setAddress(address);
            String key = Utils.getAddressStringFromByte(address);

            DeviceProperties pv = mDevices.put(key, prop);

            if (pv == null) {
+16 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@ import android.os.Bundle;
import android.os.HandlerThread;
import android.os.Message;
import android.os.TestLooperManager;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;

import androidx.test.filters.MediumTest;
import androidx.test.platform.app.InstrumentationRegistry;
@@ -25,6 +27,7 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.bluetooth.Utils;
import com.android.bluetooth.bas.BatteryService;
import com.android.bluetooth.btservice.RemoteDevices.DeviceProperties;
import com.android.bluetooth.flags.Flags;
import com.android.bluetooth.hfp.HeadsetHalConstants;

import org.junit.After;
@@ -55,6 +58,7 @@ public class RemoteDevicesTest {

    private Context mTargetContext;
    private BluetoothManager mBluetoothManager;
    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();

@@ -760,6 +764,18 @@ public class RemoteDevicesTest {
        Assert.assertEquals(BLUETOOTH_CONNECT, mStringArgument.getValue());
    }

    @Test
    @EnableFlags(Flags.FLAG_FIX_ADD_DEVICE_PROPERTIES)
    public void testMultipleAddDeviceProperties() {
        // Verify that device property is null initially
        Assert.assertNull(mRemoteDevices.getDeviceProperties(mDevice1));
        DeviceProperties prop1 =
                mRemoteDevices.addDeviceProperties(Utils.getBytesFromAddress(TEST_BT_ADDR_1));
        DeviceProperties prop2 =
                mRemoteDevices.addDeviceProperties(Utils.getBytesFromAddress(TEST_BT_ADDR_1));
        Assert.assertEquals(prop2, prop1);
    }

    @Test
    public void testSetgetHfAudioPolicyForRemoteAg() {
        // Verify that device property is null initially