Loading system/bta/csis/csis_client.cc +15 −2 Original line number Diff line number Diff line Loading @@ -658,7 +658,19 @@ class CsisClientImpl : public CsisClient { int group_id = csis_group->GetGroupId(); auto csis_instance = device->GetCsisInstanceByGroupId(group_id); LOG_ASSERT(csis_instance) << " csis_instance does not exist!"; LOG(ERROR) << __func__ << " group id " << group_id; if (!csis_instance) { /* This can happen when some other user added device to group in the * context which is not existing on the peer side. e.g. LeAudio added it * in the CAP context, but CSIS exist on the peer device without a * context. We will endup in having device in 2 groups. One in generic * context with valid csis_instance, and one in CAP context without csis * instance */ LOG(INFO) << __func__ << " csis_instance does not exist for group " << group_id; continue; } callbacks_->OnDeviceAvailable(device->addr, group_id, csis_group->GetDesiredSize(), Loading Loading @@ -1265,7 +1277,8 @@ class CsisClientImpl : public CsisClient { const bluetooth::Uuid& context_uuid, bool is_last_instance) { DLOG(INFO) << __func__ << " service handle: " << loghex(service->handle) << " end handle: " << loghex(service->end_handle); << " end handle: " << loghex(service->end_handle) << " uuid: " << context_uuid; auto csis_inst = std::make_shared<CsisInstance>( (uint16_t)service->handle, (uint16_t)service->end_handle, context_uuid); Loading system/bta/groups/groups.cc +16 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,10 @@ class DeviceGroupsImpl : public DeviceGroups { return group->GetGroupId(); } void RemoveDevice(const RawAddress& addr) override { void RemoveDevice(const RawAddress& addr, int group_id) override { int num_of_groups_dev_belongs = 0; /* Remove from all the groups. Usually happens on unbond */ for (auto it = groups_.begin(); it != groups_.end();) { auto& [id, g] = *it; if (!g.Contains(addr)) { Loading @@ -131,6 +134,15 @@ class DeviceGroupsImpl : public DeviceGroups { continue; } num_of_groups_dev_belongs++; if ((group_id != bluetooth::groups::kGroupUnknown) && (group_id != id)) { ++it; continue; } num_of_groups_dev_belongs--; g.Remove(addr); for (auto c : callbacks_) { c->OnGroupMemberRemoved(addr, id); Loading @@ -147,6 +159,9 @@ class DeviceGroupsImpl : public DeviceGroups { } btif_storage_remove_groups(addr); if (num_of_groups_dev_belongs > 0) { btif_storage_add_groups(addr); } } bool SerializeGroups(const RawAddress& addr, Loading system/bta/groups/groups_test.cc +21 −0 Original line number Diff line number Diff line Loading @@ -186,6 +186,27 @@ TEST_F(GroupsTest, test_remove_multiple_groups) { DeviceGroups::CleanUp(callbacks.get()); } TEST_F(GroupsTest, test_remove_device_fo_devices) { Uuid uuid1 = Uuid::GetRandom(); Uuid uuid2 = Uuid::GetRandom(); EXPECT_CALL(*callbacks, OnGroupAdded(_, _, _)).Times(2); DeviceGroups::Initialize(callbacks.get()); DeviceGroups::Get()->AddDevice(GetTestAddress(1), uuid1, 8); DeviceGroups::Get()->AddDevice(GetTestAddress(1), uuid2, 9); EXPECT_CALL(*callbacks, OnGroupRemoved(uuid1, 8)); EXPECT_CALL(*callbacks, OnGroupRemoved(uuid2, 9)).Times(0); DeviceGroups::Get()->RemoveDevice(GetTestAddress(1), 8); Mock::VerifyAndClearExpectations(&callbacks); EXPECT_CALL(*callbacks, OnGroupRemoved(uuid1, 8)).Times(0); EXPECT_CALL(*callbacks, OnGroupRemoved(uuid2, 9)); DeviceGroups::Get()->RemoveDevice(GetTestAddress(1), 9); } TEST_F(GroupsTest, test_add_devices_different_group_id) { DeviceGroups::Initialize(callbacks.get()); DeviceGroups::Get()->AddDevice(GetTestAddress(2), Uuid::kEmpty, 10); Loading system/bta/include/bta_groups.h +3 −1 Original line number Diff line number Diff line Loading @@ -70,7 +70,9 @@ class DeviceGroups { virtual int GetGroupId( const RawAddress& addr, bluetooth::Uuid uuid = bluetooth::groups::kGenericContextUuid) const = 0; virtual void RemoveDevice(const RawAddress& addr) = 0; virtual void RemoveDevice( const RawAddress& addr, int group_id = bluetooth::groups::kGroupUnknown) = 0; }; } // namespace groups Loading Loading
system/bta/csis/csis_client.cc +15 −2 Original line number Diff line number Diff line Loading @@ -658,7 +658,19 @@ class CsisClientImpl : public CsisClient { int group_id = csis_group->GetGroupId(); auto csis_instance = device->GetCsisInstanceByGroupId(group_id); LOG_ASSERT(csis_instance) << " csis_instance does not exist!"; LOG(ERROR) << __func__ << " group id " << group_id; if (!csis_instance) { /* This can happen when some other user added device to group in the * context which is not existing on the peer side. e.g. LeAudio added it * in the CAP context, but CSIS exist on the peer device without a * context. We will endup in having device in 2 groups. One in generic * context with valid csis_instance, and one in CAP context without csis * instance */ LOG(INFO) << __func__ << " csis_instance does not exist for group " << group_id; continue; } callbacks_->OnDeviceAvailable(device->addr, group_id, csis_group->GetDesiredSize(), Loading Loading @@ -1265,7 +1277,8 @@ class CsisClientImpl : public CsisClient { const bluetooth::Uuid& context_uuid, bool is_last_instance) { DLOG(INFO) << __func__ << " service handle: " << loghex(service->handle) << " end handle: " << loghex(service->end_handle); << " end handle: " << loghex(service->end_handle) << " uuid: " << context_uuid; auto csis_inst = std::make_shared<CsisInstance>( (uint16_t)service->handle, (uint16_t)service->end_handle, context_uuid); Loading
system/bta/groups/groups.cc +16 −1 Original line number Diff line number Diff line Loading @@ -123,7 +123,10 @@ class DeviceGroupsImpl : public DeviceGroups { return group->GetGroupId(); } void RemoveDevice(const RawAddress& addr) override { void RemoveDevice(const RawAddress& addr, int group_id) override { int num_of_groups_dev_belongs = 0; /* Remove from all the groups. Usually happens on unbond */ for (auto it = groups_.begin(); it != groups_.end();) { auto& [id, g] = *it; if (!g.Contains(addr)) { Loading @@ -131,6 +134,15 @@ class DeviceGroupsImpl : public DeviceGroups { continue; } num_of_groups_dev_belongs++; if ((group_id != bluetooth::groups::kGroupUnknown) && (group_id != id)) { ++it; continue; } num_of_groups_dev_belongs--; g.Remove(addr); for (auto c : callbacks_) { c->OnGroupMemberRemoved(addr, id); Loading @@ -147,6 +159,9 @@ class DeviceGroupsImpl : public DeviceGroups { } btif_storage_remove_groups(addr); if (num_of_groups_dev_belongs > 0) { btif_storage_add_groups(addr); } } bool SerializeGroups(const RawAddress& addr, Loading
system/bta/groups/groups_test.cc +21 −0 Original line number Diff line number Diff line Loading @@ -186,6 +186,27 @@ TEST_F(GroupsTest, test_remove_multiple_groups) { DeviceGroups::CleanUp(callbacks.get()); } TEST_F(GroupsTest, test_remove_device_fo_devices) { Uuid uuid1 = Uuid::GetRandom(); Uuid uuid2 = Uuid::GetRandom(); EXPECT_CALL(*callbacks, OnGroupAdded(_, _, _)).Times(2); DeviceGroups::Initialize(callbacks.get()); DeviceGroups::Get()->AddDevice(GetTestAddress(1), uuid1, 8); DeviceGroups::Get()->AddDevice(GetTestAddress(1), uuid2, 9); EXPECT_CALL(*callbacks, OnGroupRemoved(uuid1, 8)); EXPECT_CALL(*callbacks, OnGroupRemoved(uuid2, 9)).Times(0); DeviceGroups::Get()->RemoveDevice(GetTestAddress(1), 8); Mock::VerifyAndClearExpectations(&callbacks); EXPECT_CALL(*callbacks, OnGroupRemoved(uuid1, 8)).Times(0); EXPECT_CALL(*callbacks, OnGroupRemoved(uuid2, 9)); DeviceGroups::Get()->RemoveDevice(GetTestAddress(1), 9); } TEST_F(GroupsTest, test_add_devices_different_group_id) { DeviceGroups::Initialize(callbacks.get()); DeviceGroups::Get()->AddDevice(GetTestAddress(2), Uuid::kEmpty, 10); Loading
system/bta/include/bta_groups.h +3 −1 Original line number Diff line number Diff line Loading @@ -70,7 +70,9 @@ class DeviceGroups { virtual int GetGroupId( const RawAddress& addr, bluetooth::Uuid uuid = bluetooth::groups::kGenericContextUuid) const = 0; virtual void RemoveDevice(const RawAddress& addr) = 0; virtual void RemoveDevice( const RawAddress& addr, int group_id = bluetooth::groups::kGroupUnknown) = 0; }; } // namespace groups Loading