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

Commit 4faa7f5b authored by Martijn Coenen's avatar Martijn Coenen
Browse files

Fix wifi/bluetooth threadpool usage.

Bug: 31226656
Test: mma, hidl_test
Change-Id: I3f30f32392714ed653498828172165e511f847e7
parent 6a7d6222
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@
#include <android/hardware/bluetooth/1.0/IBluetoothHciCallbacks.h>
#include <android/hardware/bluetooth/1.0/types.h>
#include <hardware/bluetooth.h>
#include <hwbinder/ProcessState.h>
#include <utils/Log.h>

#include <gtest/gtest.h>
@@ -128,14 +127,6 @@ class BluetoothHidlTest : public ::testing::Test {
          bluetooth->isRemote() ? "remote" : "local");
    ASSERT_NE(bluetooth, nullptr);

    // TODO(b/31748996) A client must be completely unaware of the
    // implementation details of its HAL: whether the HAL is passthrough, or
    // whether it uses HWbinder or some other transport.
    if (bluetooth->isRemote()) {
      ::android::hardware::ProcessState::self()->setThreadPoolMaxThreadCount(1);
      ::android::hardware::ProcessState::self()->startThreadPool();
    }

    bluetooth_cb = new BluetoothHciCallbacks(*this);
    ASSERT_NE(bluetooth_cb, nullptr);

+5 −29
Original line number Diff line number Diff line
@@ -15,42 +15,21 @@
 */

#include <android-base/logging.h>
#include <hwbinder/IPCThreadState.h>
#include <hwbinder/ProcessState.h>
#include <hidl/HidlTransportSupport.h>
#include <utils/Looper.h>
#include <utils/StrongPointer.h>

#include "wifi.h"

using android::hardware::hidl_version;
using android::hardware::IPCThreadState;
using android::hardware::ProcessState;
using android::Looper;

namespace {
int OnBinderReadReady(int /*fd*/, int /*events*/, void* /*data*/) {
  IPCThreadState::self()->handlePolledCommands();
  return 1;  // continue receiving events
}
}
using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;

int main(int /*argc*/, char** argv) {
  android::base::InitLogging(argv,
                             android::base::LogdLogger(android::base::SYSTEM));
  LOG(INFO) << "wifi_hal_legacy is starting up...";

  // Setup binder
  int binder_fd = -1;
  ProcessState::self()->setThreadPoolMaxThreadCount(0);
  CHECK_EQ(IPCThreadState::self()->setupPolling(&binder_fd), android::NO_ERROR)
      << "Failed to initialize binder polling";
  CHECK_GE(binder_fd, 0) << "Invalid binder FD: " << binder_fd;

  // Setup looper
  android::sp<Looper> looper = Looper::prepare(0 /* no options */);
  CHECK(looper->addFd(
      binder_fd, 0, Looper::EVENT_INPUT, OnBinderReadReady, nullptr))
      << "Failed to watch binder FD";
  configureRpcThreadpool(1, true /* callerWillJoin */);

  // Setup hwbinder service
  android::sp<android::hardware::wifi::V1_0::IWifi> service =
@@ -58,10 +37,7 @@ int main(int /*argc*/, char** argv) {
  CHECK_EQ(service->registerAsService("wifi"), android::NO_ERROR)
      << "Failed to register wifi HAL";

  // Loop
  while (looper->pollAll(-1) != Looper::POLL_ERROR) {
    // Keep polling until failure.
  }
  joinRpcThreadpool();

  LOG(INFO) << "wifi_hal_legacy is terminating...";
  return 0;