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

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

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

Merge "RemoteDevice: Fix for race condition on adding device properties" into main am: 809606a4 am: f6541bcd

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/3315146



Change-Id: I4b4b875ef7a8d8148095e59f5acccc7bc946ca00
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 305cd0f9 f6541bcd
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -293,10 +293,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