sm6375-common: power-libperfmgr: add aidl extension server

Bug: 151896829
Test: boot flame
Change-Id: Ie951008cabe2a5680fbc546a21bdc9a428864ef9
This commit is contained in:
Wei Wang 2024-07-18 12:56:42 +05:30 committed by Anand S
commit a8c7e1fc54
No known key found for this signature in database
GPG key ID: 3B2983FA448B3D61
6 changed files with 238 additions and 55 deletions

View file

@ -16,24 +16,58 @@
#define LOG_TAG "android.hardware.power-service.moto_sm6375-libperfmgr"
#include "Power.h"
#include <thread>
#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include "Power.h"
#include "PowerExt.h"
using aidl::android::hardware::pixel::extension::power::impl::PowerExt;
using aidl::android::hardware::power::impl::pixel::Power;
using ::android::perfmgr::HintManager;
constexpr char kPowerHalConfigPath[] = "/vendor/etc/powerhint.json";
constexpr char kPowerHalInitProp[] = "vendor.powerhal.init";
int main() {
LOG(INFO) << "Power HAL AIDL Service for moto_sm6375 is starting.";
// Parse config but do not start the looper
std::shared_ptr<HintManager> hm = HintManager::GetFromJSON(kPowerHalConfigPath, false);
if (!hm) {
LOG(FATAL) << "Invalid config: " << kPowerHalConfigPath;
}
// single thread
ABinderProcess_setThreadPoolMaxThreadCount(0);
std::shared_ptr<Power> pw = ndk::SharedRefBase::make<Power>();
// power hal core service
std::shared_ptr<Power> pw = ndk::SharedRefBase::make<Power>(hm);
ndk::SpAIBinder pwBinder = pw->asBinder();
// making the extension service
std::shared_ptr<PowerExt> pwExt = ndk::SharedRefBase::make<PowerExt>(hm);
// need to attach the extension to the same binder we will be registering
CHECK(STATUS_OK == AIBinder_setExtension(pwBinder.get(), pwExt->asBinder().get()));
const std::string instance = std::string() + Power::descriptor + "/default";
binder_status_t status = AServiceManager_addService(pw->asBinder().get(), instance.c_str());
CHECK(status == STATUS_OK);
LOG(INFO) << "Power HAL AIDL Service for moto_sm6375 is started.";
std::thread initThread([&]() {
::android::base::WaitForProperty(kPowerHalInitProp, "1");
hm->Start();
pw->setReady();
pwExt->setReady();
});
initThread.detach();
ABinderProcess_joinThreadPool();
LOG(ERROR) << "Power HAL AIDL Service for moto_sm6375 died.";
return EXIT_FAILURE; // should not reach