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

Commit 411205f0 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

SecurityManagerImpl remove special handling for first callback insertion/deletion

Also, crash if callback is re-used. Attempt to register callback twice
is a sign of serious stack misconfiguration.

Bug: 142341141
Change-Id: I596acb1cff1cbf2a52382ff346e5a00995908da1
parent 12dad709
Loading
Loading
Loading
Loading
+10 −24
Original line number Diff line number Diff line
@@ -101,38 +101,24 @@ void SecurityManagerImpl::RemoveBond(std::shared_ptr<hci::ClassicDevice> device)
}

void SecurityManagerImpl::RegisterCallbackListener(ISecurityManagerListener* listener, os::Handler* handler) {
  if (listeners_.size() < 1) {
    listeners_.push_back({listener, handler});
  } else {
    bool found = false;
  for (auto it = listeners_.begin(); it != listeners_.end(); ++it) {
      found = it->first == listener;
      if (found) break;
    if (it->first == listener) {
      LOG_ALWAYS_FATAL("Listener has already been registered!");
    }
  }

    if (found) {
      LOG_ERROR("Listener has already been registered!");
    } else {
  listeners_.push_back({listener, handler});
}
  }
}

void SecurityManagerImpl::UnregisterCallbackListener(ISecurityManagerListener* listener) {
  if (listeners_.size() < 1) {
    LOG_ERROR("Listener has not been registered!");
  } else {
    bool found = false;
    auto it = listeners_.begin();
    while (it != listeners_.end()) {
      found = it->first == listener;
      if (found) break;
      ++it;
    }
    if (found) {
  for (auto it = listeners_.begin(); it != listeners_.end(); ++it) {
    if (it->first == listener) {
      listeners_.erase(it);
      return;
    }
  }

  LOG_ALWAYS_FATAL("Listener has not been registered!");
}

void SecurityManagerImpl::FireDeviceBondedCallbacks(std::shared_ptr<Device> device) {