Loading system/types/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -67,6 +67,7 @@ cc_test { ], ], include_dirs: [ include_dirs: [ "packages/modules/Bluetooth/system", "packages/modules/Bluetooth/system", "packages/modules/Bluetooth/system/include", ], ], host_supported: true, host_supported: true, srcs: [ srcs: [ Loading system/types/ble_address_with_type.h +40 −0 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,8 @@ #include <cstdint> #include <cstdint> #include <string> #include <string> #include "types/bt_transport.h" #include "types/raw_address.h" #include "types/raw_address.h" #define BLE_ADDR_PUBLIC 0x00 #define BLE_ADDR_PUBLIC 0x00 Loading Loading @@ -149,4 +151,42 @@ struct std::hash<tBLE_BD_ADDR> { } } }; }; struct tTypedAddressTransport { tBLE_BD_ADDR addrt; tBT_TRANSPORT transport; bool operator==(const tTypedAddressTransport rhs) const { if (rhs.addrt != addrt) return false; if (rhs.transport == BT_TRANSPORT_AUTO || transport == BT_TRANSPORT_AUTO) { return true; } return rhs.transport == transport; } bool operator!=(const tTypedAddressTransport rhs) const { return !(*this == rhs); } bool StrictlyEquals(const tTypedAddressTransport rhs) const { return rhs.addrt == addrt && rhs.transport == transport; } std::string ToString() const { return std::string(addrt.ToString() + "[" + bt_transport_text(transport) + "]"); } std::string ToStringForLogging() const { return addrt.ToStringForLogging() + "[" + bt_transport_text(transport) + "]"; } std::string ToRedactedStringForLogging() const { return addrt.ToRedactedStringForLogging() + "[" + bt_transport_text(transport) + "]"; } }; #endif #endif system/types/test/ble_address_with_type_unittest.cc +19 −0 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,8 @@ #include "types/ble_address_with_type.h" #include "types/ble_address_with_type.h" #include <gtest/gtest.h> #include <gtest/gtest.h> static constexpr uint8_t RAW_ADDRESS_TEST1[6] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; TEST(BleAddressWithTypeTest, to_ble_addr_type) { TEST(BleAddressWithTypeTest, to_ble_addr_type) { for (unsigned i = 0; i < 0xff + 1; i++) { for (unsigned i = 0; i < 0xff + 1; i++) { Loading Loading @@ -97,6 +99,23 @@ TEST(BleAddressWithTypeTest, STREAM_TO_BLE_ADDR_TYPE) { } } } } TEST(BleAddressWithTypeTest, TYPED_ADDRESS_TRANSPORT) { tTypedAddressTransport typedAddressTransportA = { {BLE_ADDR_PUBLIC, RAW_ADDRESS_TEST1}, BT_TRANSPORT_AUTO}; tTypedAddressTransport typedAddressTransportB = { {BLE_ADDR_PUBLIC, RAW_ADDRESS_TEST1}, BT_TRANSPORT_BR_EDR}; tTypedAddressTransport typedAddressTransportC = { {BLE_ADDR_PUBLIC, RAW_ADDRESS_TEST1}, BT_TRANSPORT_LE}; ASSERT_EQ(typedAddressTransportA, typedAddressTransportB); ASSERT_EQ(typedAddressTransportA, typedAddressTransportC); ASSERT_NE(typedAddressTransportB, typedAddressTransportC); ASSERT_FALSE(typedAddressTransportA.StrictlyEquals(typedAddressTransportB)); ASSERT_FALSE(typedAddressTransportA.StrictlyEquals(typedAddressTransportC)); ASSERT_FALSE(typedAddressTransportB.StrictlyEquals(typedAddressTransportC)); } TEST(BleAddressWithTypeTest, BLE_ADDR_TYPE_TO_STREAM) { TEST(BleAddressWithTypeTest, BLE_ADDR_TYPE_TO_STREAM) { uint8_t buf[256] = {0}; uint8_t buf[256] = {0}; uint8_t* p = buf; uint8_t* p = buf; Loading Loading
system/types/Android.bp +1 −0 Original line number Original line Diff line number Diff line Loading @@ -67,6 +67,7 @@ cc_test { ], ], include_dirs: [ include_dirs: [ "packages/modules/Bluetooth/system", "packages/modules/Bluetooth/system", "packages/modules/Bluetooth/system/include", ], ], host_supported: true, host_supported: true, srcs: [ srcs: [ Loading
system/types/ble_address_with_type.h +40 −0 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,8 @@ #include <cstdint> #include <cstdint> #include <string> #include <string> #include "types/bt_transport.h" #include "types/raw_address.h" #include "types/raw_address.h" #define BLE_ADDR_PUBLIC 0x00 #define BLE_ADDR_PUBLIC 0x00 Loading Loading @@ -149,4 +151,42 @@ struct std::hash<tBLE_BD_ADDR> { } } }; }; struct tTypedAddressTransport { tBLE_BD_ADDR addrt; tBT_TRANSPORT transport; bool operator==(const tTypedAddressTransport rhs) const { if (rhs.addrt != addrt) return false; if (rhs.transport == BT_TRANSPORT_AUTO || transport == BT_TRANSPORT_AUTO) { return true; } return rhs.transport == transport; } bool operator!=(const tTypedAddressTransport rhs) const { return !(*this == rhs); } bool StrictlyEquals(const tTypedAddressTransport rhs) const { return rhs.addrt == addrt && rhs.transport == transport; } std::string ToString() const { return std::string(addrt.ToString() + "[" + bt_transport_text(transport) + "]"); } std::string ToStringForLogging() const { return addrt.ToStringForLogging() + "[" + bt_transport_text(transport) + "]"; } std::string ToRedactedStringForLogging() const { return addrt.ToRedactedStringForLogging() + "[" + bt_transport_text(transport) + "]"; } }; #endif #endif
system/types/test/ble_address_with_type_unittest.cc +19 −0 Original line number Original line Diff line number Diff line Loading @@ -17,6 +17,8 @@ #include "types/ble_address_with_type.h" #include "types/ble_address_with_type.h" #include <gtest/gtest.h> #include <gtest/gtest.h> static constexpr uint8_t RAW_ADDRESS_TEST1[6] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; TEST(BleAddressWithTypeTest, to_ble_addr_type) { TEST(BleAddressWithTypeTest, to_ble_addr_type) { for (unsigned i = 0; i < 0xff + 1; i++) { for (unsigned i = 0; i < 0xff + 1; i++) { Loading Loading @@ -97,6 +99,23 @@ TEST(BleAddressWithTypeTest, STREAM_TO_BLE_ADDR_TYPE) { } } } } TEST(BleAddressWithTypeTest, TYPED_ADDRESS_TRANSPORT) { tTypedAddressTransport typedAddressTransportA = { {BLE_ADDR_PUBLIC, RAW_ADDRESS_TEST1}, BT_TRANSPORT_AUTO}; tTypedAddressTransport typedAddressTransportB = { {BLE_ADDR_PUBLIC, RAW_ADDRESS_TEST1}, BT_TRANSPORT_BR_EDR}; tTypedAddressTransport typedAddressTransportC = { {BLE_ADDR_PUBLIC, RAW_ADDRESS_TEST1}, BT_TRANSPORT_LE}; ASSERT_EQ(typedAddressTransportA, typedAddressTransportB); ASSERT_EQ(typedAddressTransportA, typedAddressTransportC); ASSERT_NE(typedAddressTransportB, typedAddressTransportC); ASSERT_FALSE(typedAddressTransportA.StrictlyEquals(typedAddressTransportB)); ASSERT_FALSE(typedAddressTransportA.StrictlyEquals(typedAddressTransportC)); ASSERT_FALSE(typedAddressTransportB.StrictlyEquals(typedAddressTransportC)); } TEST(BleAddressWithTypeTest, BLE_ADDR_TYPE_TO_STREAM) { TEST(BleAddressWithTypeTest, BLE_ADDR_TYPE_TO_STREAM) { uint8_t buf[256] = {0}; uint8_t buf[256] = {0}; uint8_t* p = buf; uint8_t* p = buf; Loading