service.cpp revision cd0d29d4afd1910b584fb374265548adaf3f46ef
1#define LOG_TAG "android.hardware.boot@1.0-service" 2#include <utils/Log.h> 3 4#include <iostream> 5#include <unistd.h> 6 7#include <android/hardware/boot/1.0/IBootControl.h> 8 9#include <hidl/IServiceManager.h> 10#include <hwbinder/IPCThreadState.h> 11#include <hwbinder/ProcessState.h> 12#include <utils/Errors.h> 13#include <utils/StrongPointer.h> 14 15using android::sp; 16 17using android::hardware::IPCThreadState; 18using android::hardware::ProcessState; 19 20using ::android::hardware::boot::V1_0::IBootControl; 21 22int main (int /* argc */, char * /* argv */ []) { 23 ALOGI("Service is starting."); 24 const char instance[] = "bootctrl"; 25 ALOGI("Retrieving default implementation of instance %s.", 26 instance); 27 28 sp<IBootControl> service = IBootControl::getService(instance, true /* getStub */); 29 30 if (service.get() == nullptr) { 31 ALOGE("IBootControl::getService returned NULL, exiting"); 32 return -1; 33 } 34 35 LOG_FATAL_IF(service->isRemote(), "Implementation is REMOTE!"); 36 37 ALOGI("Registering instance %s.", instance); 38 service->registerAsService(instance); 39 ALOGI("Ready."); 40 41 ProcessState::self()->setThreadPoolMaxThreadCount(0); 42 ProcessState::self()->startThreadPool(); 43 IPCThreadState::self()->joinThreadPool(); 44} 45