Remove obsolete references to IPCThreadState/ProcessState.
Threadpool can now be configured/joined if needed with
configureRpcThreadpool() / joinRpcThreadpool().
Bug: 31226656
Test: mma
Change-Id: I0d7d9924cc8c8851cc2b61ebdae906204909890e
diff --git a/audio/2.0/default/service.cpp b/audio/2.0/default/service.cpp
index 28ef660..646d898 100644
--- a/audio/2.0/default/service.cpp
+++ b/audio/2.0/default/service.cpp
@@ -16,14 +16,17 @@
#define LOG_TAG "audiohalservice"
+#include <hidl/HidlTransportSupport.h>
#include <hidl/LegacySupport.h>
#include <android/hardware/audio/2.0/IDevicesFactory.h>
#include <android/hardware/audio/effect/2.0/IEffectsFactory.h>
#include <android/hardware/soundtrigger/2.0/ISoundTriggerHw.h>
#include <android/hardware/broadcastradio/1.0/IBroadcastRadioFactory.h>
-using android::hardware::IPCThreadState;
-using android::hardware::ProcessState;
+using android::hardware::configureRpcThreadpool;
+using android::hardware::joinRpcThreadpool;
+using android::hardware::registerPassthroughServiceImplementation;
+
using android::hardware::audio::effect::V2_0::IEffectsFactory;
using android::hardware::audio::V2_0::IDevicesFactory;
using android::hardware::soundtrigger::V2_0::ISoundTriggerHw;
@@ -31,9 +34,10 @@
using android::hardware::broadcastradio::V1_0::IBroadcastRadioFactory;
int main(int /* argc */, char* /* argv */ []) {
+ configureRpcThreadpool(16, true /*callerWillJoin*/);
registerPassthroughServiceImplementation<IDevicesFactory>("audio_devices_factory");
registerPassthroughServiceImplementation<IEffectsFactory>("audio_effects_factory");
registerPassthroughServiceImplementation<ISoundTriggerHw>("sound_trigger.primary");
registerPassthroughServiceImplementation<IBroadcastRadioFactory>("broadcastradio");
- return android::hardware::launchRpcServer(16);
+ joinRpcThreadpool();
}
diff --git a/broadcastradio/1.0/vts/functional/broadcastradio_hidl_hal_test.cpp b/broadcastradio/1.0/vts/functional/broadcastradio_hidl_hal_test.cpp
index 26666d6..6802c3c 100644
--- a/broadcastradio/1.0/vts/functional/broadcastradio_hidl_hal_test.cpp
+++ b/broadcastradio/1.0/vts/functional/broadcastradio_hidl_hal_test.cpp
@@ -19,9 +19,8 @@
#include <android-base/logging.h>
#include <cutils/native_handle.h>
#include <cutils/properties.h>
+#include <hidl/HidlTransportSupport.h>
#include <utils/threads.h>
-#include <hwbinder/IPCThreadState.h>
-#include <hwbinder/ProcessState.h>
#include <android/hardware/broadcastradio/1.0/IBroadcastRadioFactory.h>
#include <android/hardware/broadcastradio/1.0/IBroadcastRadio.h>
@@ -33,7 +32,6 @@
using ::android::sp;
using ::android::Mutex;
using ::android::Condition;
-using ::android::hardware::ProcessState;
using ::android::hardware::Return;
using ::android::hardware::Status;
using ::android::hardware::Void;
@@ -461,8 +459,6 @@
int main(int argc, char** argv) {
- sp<ProcessState> proc(ProcessState::self());
- ProcessState::self()->startThreadPool();
::testing::AddGlobalTestEnvironment(new BroadcastRadioHidlEnvironment);
::testing::InitGoogleTest(&argc, argv);
int status = RUN_ALL_TESTS();
diff --git a/evs/1.0/default/service.cpp b/evs/1.0/default/service.cpp
index 6ab2975..112c879 100644
--- a/evs/1.0/default/service.cpp
+++ b/evs/1.0/default/service.cpp
@@ -18,8 +18,7 @@
#include <unistd.h>
-#include <hwbinder/IPCThreadState.h>
-#include <hwbinder/ProcessState.h>
+#include <hidl/HidlTransportSupport.h>
#include <utils/Errors.h>
#include <utils/StrongPointer.h>
#include <utils/Log.h>
@@ -29,9 +28,9 @@
#include "EvsDisplay.h"
-// libhwbinder:
-using android::hardware::IPCThreadState;
-using android::hardware::ProcessState;
+// libhidl:
+using android::hardware::configureRpcThreadpool;
+using android::hardware::joinRpcThreadpool;
// Generated HIDL files
using android::hardware::evs::V1_0::IEvsEnumerator;
@@ -46,25 +45,14 @@
ALOGI("EVS Hardware Enumerator service is starting");
android::sp<IEvsEnumerator> service = new EvsEnumerator();
+ configureRpcThreadpool(1, true /* callerWillJoin */);
+
// Register our service -- if somebody is already registered by our name,
// they will be killed (their thread pool will throw an exception).
status_t status = service->registerAsService(kEnumeratorServiceName);
if (status == OK) {
ALOGD("%s is ready.", kEnumeratorServiceName);
-
- // Set thread pool size to ensure the API is not called in parallel.
- // By setting the size to zero, the main thread will be the only one
- // serving requests once we "joinThreadPool".
- ProcessState::self()->setThreadPoolMaxThreadCount(0);
-
- // Note: We don't start the thread pool because it'll add at least one (default)
- // thread to it, which we don't want. See b/31226656
- // ProcessState::self()->startThreadPool();
-
- // Send this main thread to become a permanent part of the thread pool.
- // This bumps up the thread count by 1 (from zero in this case).
- // This is not expected to return.
- IPCThreadState::self()->joinThreadPool();
+ joinRpcThreadpool();
} else {
ALOGE("Could not register service %s (%d).", kEnumeratorServiceName, status);
}
diff --git a/example/extension/light/2.0/default/service.cpp b/example/extension/light/2.0/default/service.cpp
index 3eb7bdf..d3fb4de 100644
--- a/example/extension/light/2.0/default/service.cpp
+++ b/example/extension/light/2.0/default/service.cpp
@@ -16,15 +16,14 @@
#define LOG_TAG "android.hardware.light@2.0-service"
#include <android/log.h>
+#include <hidl/HidlTransportSupport.h>
#include "Light.h"
+using android::hardware::configureRpcThreadpool;
+using android::hardware::joinRpcThreadpool;
using android::sp;
-// libhwbinder:
-using android::hardware::IPCThreadState;
-using android::hardware::ProcessState;
-
// Generated HIDL files
using android::hardware::light::V2_0::ILight;
@@ -32,10 +31,7 @@
const char instance[] = "light";
android::sp<ILight> service = new Light();
-
+ configureRpcThreadpool(1, true /*callerWillJoin*/);
service->registerAsService(instance);
-
- ProcessState::self()->setThreadPoolMaxThreadCount(0);
- ProcessState::self()->startThreadPool();
- IPCThreadState::self()->joinThreadPool();
+ joinRpcThreadpool();
}
diff --git a/graphics/composer/2.1/default/service.cpp b/graphics/composer/2.1/default/service.cpp
index 0384a53..c2a2b19 100644
--- a/graphics/composer/2.1/default/service.cpp
+++ b/graphics/composer/2.1/default/service.cpp
@@ -17,14 +17,13 @@
#define LOG_TAG "HWComposerService"
#include <binder/ProcessState.h>
-#include <hwbinder/IPCThreadState.h>
-#include <hwbinder/ProcessState.h>
+#include <hidl/HidlTransportSupport.h>
#include <utils/StrongPointer.h>
#include "Hwc.h"
+using android::hardware::configureRpcThreadpool;
+using android::hardware::joinRpcThreadpool;
using android::sp;
-using android::hardware::IPCThreadState;
-using android::hardware::ProcessState;
using android::hardware::graphics::composer::V2_1::IComposer;
using android::hardware::graphics::composer::V2_1::implementation::HIDL_FETCH_IComposer;
@@ -34,6 +33,7 @@
ALOGI("Service is starting.");
+ configureRpcThreadpool(1, true /* callerWillJoin */);
sp<IComposer> service = HIDL_FETCH_IComposer(instance);
if (service == nullptr) {
ALOGI("getService returned NULL");
@@ -48,9 +48,7 @@
android::ProcessState::self()->setThreadPoolMaxThreadCount(4);
android::ProcessState::self()->startThreadPool();
- ProcessState::self()->setThreadPoolMaxThreadCount(0);
- ProcessState::self()->startThreadPool();
- IPCThreadState::self()->joinThreadPool();
+ joinRpcThreadpool();
return 0;
}
diff --git a/keymaster/3.0/default/service.cpp b/keymaster/3.0/default/service.cpp
index 038bf31..dd8c0b2 100644
--- a/keymaster/3.0/default/service.cpp
+++ b/keymaster/3.0/default/service.cpp
@@ -19,15 +19,17 @@
#include <android/hardware/keymaster/3.0/IKeymasterDevice.h>
+#include <hidl/HidlTransportSupport.h>
#include <hidl/LegacySupport.h>
-using android::sp;
+using android::hardware::configureRpcThreadpool;
+using android::hardware::joinRpcThreadpool;
using android::hardware::keymaster::V3_0::IKeymasterDevice;
using android::hardware::registerPassthroughServiceImplementation;
-using android::hardware::launchRpcServer;
int main() {
+ configureRpcThreadpool(1, true /*callerWillJoin*/);
registerPassthroughServiceImplementation<IKeymasterDevice>("keymaster");
- return launchRpcServer(1);
+ joinRpcThreadpool();
}
diff --git a/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp b/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp
index 3e40a9c..f5ed4d7 100644
--- a/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp
+++ b/nfc/1.0/vts/functional/nfc_hidl_hal_test.cpp
@@ -21,14 +21,12 @@
#include <android/hardware/nfc/1.0/INfcClientCallback.h>
#include <android/hardware/nfc/1.0/types.h>
#include <hardware/nfc.h>
-#include <hwbinder/ProcessState.h>
#include <gtest/gtest.h>
#include <chrono>
#include <condition_variable>
#include <mutex>
-using ::android::hardware::ProcessState;
using ::android::hardware::nfc::V1_0::INfc;
using ::android::hardware::nfc::V1_0::INfcClientCallback;
using ::android::hardware::nfc::V1_0::NfcEvent;
@@ -66,12 +64,6 @@
nfc_ = INfc::getService(NFC_NCI_SERVICE_NAME, passthrough);
ASSERT_NE(nfc_, nullptr);
- // TODO:b/31748996
- if (nfc_->isRemote()) {
- ProcessState::self()->setThreadPoolMaxThreadCount(1);
- ProcessState::self()->startThreadPool();
- }
-
nfc_cb_ = new NfcClientCallback(*this);
ASSERT_NE(nfc_cb_, nullptr);
diff --git a/vehicle/2.0/default/VehicleService.cpp b/vehicle/2.0/default/VehicleService.cpp
index 651a2ad..493df74 100644
--- a/vehicle/2.0/default/VehicleService.cpp
+++ b/vehicle/2.0/default/VehicleService.cpp
@@ -16,10 +16,10 @@
#define LOG_TAG "android.hardware.vehicle@2.0-service"
#include <android/log.h>
+#include <hidl/HidlTransportSupport.h>
#include <iostream>
-#include <hwbinder/IPCThreadState.h>
#include <vehicle_hal_manager/VehicleHalManager.h>
#include <impl/DefaultVehicleHal.h>
@@ -32,11 +32,11 @@
auto hal = std::make_unique<impl::DefaultVehicleHal>();
auto service = std::make_unique<VehicleHalManager>(hal.get());
+ configureRpcThreadpool(1, true /* callerWillJoin */);
+
ALOGI("Registering as service...");
service->registerAsService("Vehicle");
ALOGI("Ready");
- ProcessState::self()->setThreadPoolMaxThreadCount(0);
- ProcessState::self()->startThreadPool();
- IPCThreadState::self()->joinThreadPool();
+ joinRpcThreadpool();
}