Loading android/app/src/com/android/bluetooth/btservice/RemoteDevices.java +7 −1 Original line number Diff line number Diff line Loading @@ -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) { Loading android/app/tests/unit/src/com/android/bluetooth/btservice/RemoteDevicesTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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 Loading Loading
android/app/src/com/android/bluetooth/btservice/RemoteDevices.java +7 −1 Original line number Diff line number Diff line Loading @@ -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) { Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/RemoteDevicesTest.java +16 −0 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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 Loading