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

Commit 776e330c authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Gerrit Code Review
Browse files

Merge changes I97317d23,I19a54e44,Id95b18a9

* changes:
  groups: Extend RemoveDevice with group id
  csis: Minor log extension
  csis: Fix for assert on missing csis instance
parents 58d124df 06d538bc
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -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(),
@@ -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);
+16 −1
Original line number Diff line number Diff line
@@ -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)) {
@@ -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);
@@ -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,
+21 −0
Original line number Diff line number Diff line
@@ -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);
+3 −1
Original line number Diff line number Diff line
@@ -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