sm6375-common: power-libperfmgr: Make HintManager a singleton class

HintManager is unique and widely used in many different components.
This is for making it easiler to be reloaded for debugging.

Bug: 172285365
Test: adb push \
      out/target/product/raven/data/nativetest64/libperfmgr_test/libperfmgr_test \
      /data/nativetest64/libperfmgr_test/libperfmgr_test && \
      adb shell /data/nativetest64/libperfmgr_test/libperfmgr_test
Change-Id: I3affdfe780073ebbc50fac7bfbdd1530ee9dc8c2
This commit is contained in:
Jimmy Shiu 2024-07-18 20:16:00 +05:30 committed by Anand S
commit 53f1fc4eee
No known key found for this signature in database
GPG key ID: 3B2983FA448B3D61
9 changed files with 68 additions and 96 deletions

View file

@ -16,12 +16,13 @@
#define LOG_TAG "powerhal-libperfmgr"
#include <thread>
#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <perfmgr/HintManager.h>
#include <thread>
#include "Power.h"
#include "PowerExt.h"
@ -34,37 +35,23 @@ using aidl::google::hardware::power::impl::pixel::PowerSessionManager;
using ::android::perfmgr::HintManager;
constexpr std::string_view kPowerHalInitProp("vendor.powerhal.init");
constexpr std::string_view kConfigDebugPathProperty("vendor.powerhal.config.debug");
constexpr std::string_view kConfigProperty("vendor.powerhal.config");
constexpr std::string_view kConfigDefaultFileName("powerhint.json");
int main() {
std::string config_path = "/vendor/etc/";
if (android::base::GetBoolProperty(kConfigDebugPathProperty.data(), false)) {
config_path = "/data/vendor/etc/";
LOG(WARNING) << "Power HAL AIDL Service for moto_sm6375 is using debug config from: " << config_path;
}
config_path.append(
android::base::GetProperty(kConfigProperty.data(), kConfigDefaultFileName.data()));
LOG(INFO) << "Power HAL AIDL Service for moto_sm6375 with Extension is starting with config: "
<< config_path;
// Parse config but do not start the looper
std::shared_ptr<HintManager> hm = HintManager::GetFromJSON(config_path, false);
std::shared_ptr<HintManager> hm = HintManager::GetInstance();
if (!hm) {
LOG(FATAL) << "Invalid config: " << config_path;
LOG(FATAL) << "HintManager Init failed";
}
// single thread
ABinderProcess_setThreadPoolMaxThreadCount(0);
// core service
std::shared_ptr<Power> pw = ndk::SharedRefBase::make<Power>(hm);
std::shared_ptr<Power> pw = ndk::SharedRefBase::make<Power>();
ndk::SpAIBinder pwBinder = pw->asBinder();
// extension service
std::shared_ptr<PowerExt> pwExt = ndk::SharedRefBase::make<PowerExt>(hm);
std::shared_ptr<PowerExt> pwExt = ndk::SharedRefBase::make<PowerExt>();
// attach the extension to the same binder we will be registering
CHECK(STATUS_OK == AIBinder_setExtension(pwBinder.get(), pwExt->asBinder().get()));
@ -76,12 +63,11 @@ int main() {
if (::android::base::GetIntProperty("vendor.powerhal.adpf.rate", -1) != -1) {
PowerHintMonitor::getInstance()->start();
PowerSessionManager::getInstance()->setHintManager(hm);
}
std::thread initThread([&]() {
::android::base::WaitForProperty(kPowerHalInitProp.data(), "1");
hm->Start();
HintManager::GetInstance()->Start();
});
initThread.detach();