From 9ce1be0f0387a4df8e5372bcd257d7ce76116e5a Mon Sep 17 00:00:00 2001 From: Kalesh Singh Date: Wed, 21 Jul 2021 01:51:30 +0000 Subject: [PATCH] PowerManagerService: Use AIDL Suspend HAL Use the aidl suspend hal for getting suspend blocker in power manager service. Bug: 170260236 Test: boot; Verify no failure to get suspend service in logs Change-Id: I338804d98fea32bf5481a335a77484c1418e1b82 Merged-In: I338804d98fea32bf5481a335a77484c1418e1b82 --- services/core/jni/Android.bp | 2 +- ...droid_server_power_PowerManagerService.cpp | 36 ++++++++++--------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/services/core/jni/Android.bp b/services/core/jni/Android.bp index 062f232728a66..2722b8d043705 100644 --- a/services/core/jni/Android.bp +++ b/services/core/jni/Android.bp @@ -181,7 +181,7 @@ cc_defaults { "android.frameworks.stats-V1-ndk_platform", "android.system.suspend.control-V1-cpp", "android.system.suspend.control.internal-cpp", - "android.system.suspend@1.0", + "android.system.suspend-V1-ndk", "service.incremental", ], diff --git a/services/core/jni/com_android_server_power_PowerManagerService.cpp b/services/core/jni/com_android_server_power_PowerManagerService.cpp index ae7ea3cd90e8a..7fea547459bcb 100644 --- a/services/core/jni/com_android_server_power_PowerManagerService.cpp +++ b/services/core/jni/com_android_server_power_PowerManagerService.cpp @@ -18,11 +18,12 @@ //#define LOG_NDEBUG 0 +#include +#include #include #include #include #include -#include #include #include #include @@ -34,6 +35,7 @@ #include #include +#include #include #include #include @@ -41,20 +43,20 @@ #include #include #include +#include +#include #include #include -#include -#include #include "com_android_server_power_PowerManagerService.h" +using aidl::android::system::suspend::ISystemSuspend; +using aidl::android::system::suspend::IWakeLock; +using aidl::android::system::suspend::WakeLockType; using android::String8; using android::hardware::power::Boost; using android::hardware::power::Mode; using android::system::suspend::ISuspendControlService; -using android::system::suspend::V1_0::ISystemSuspend; -using android::system::suspend::V1_0::IWakeLock; -using android::system::suspend::V1_0::WakeLockType; using IPowerV1_1 = android::hardware::power::V1_1::IPower; using IPowerV1_0 = android::hardware::power::V1_0::IPower; using IPowerAidl = android::hardware::power::IPower; @@ -133,20 +135,21 @@ void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t } } -static sp gSuspendHal = nullptr; +static std::shared_ptr gSuspendHal = nullptr; static sp gSuspendControl = nullptr; static sp gSuspendControlInternal = nullptr; -static sp gSuspendBlocker = nullptr; +static std::shared_ptr gSuspendBlocker = nullptr; static std::mutex gSuspendMutex; // Assume SystemSuspend HAL is always alive. // TODO: Force device to restart if SystemSuspend HAL dies. -sp getSuspendHal() { +std::shared_ptr getSuspendHal() { static std::once_flag suspendHalFlag; - std::call_once(suspendHalFlag, [](){ - ::android::hardware::details::waitForHwService(ISystemSuspend::descriptor, "default"); - gSuspendHal = ISystemSuspend::getService(); + std::call_once(suspendHalFlag, []() { + const std::string suspendInstance = std::string() + ISystemSuspend::descriptor + "/default"; + gSuspendHal = ISystemSuspend::fromBinder( + ndk::SpAIBinder(AServiceManager_waitForService(suspendInstance.c_str()))); assert(gSuspendHal != nullptr); }); return gSuspendHal; @@ -184,7 +187,7 @@ void enableAutoSuspend() { std::lock_guard lock(gSuspendMutex); if (gSuspendBlocker) { gSuspendBlocker->release(); - gSuspendBlocker.clear(); + gSuspendBlocker = nullptr; } } } @@ -192,9 +195,10 @@ void enableAutoSuspend() { void disableAutoSuspend() { std::lock_guard lock(gSuspendMutex); if (!gSuspendBlocker) { - sp suspendHal = getSuspendHal(); - gSuspendBlocker = suspendHal->acquireWakeLock(WakeLockType::PARTIAL, - "PowerManager.SuspendLockout"); + std::shared_ptr suspendHal = getSuspendHal(); + suspendHal->acquireWakeLock(WakeLockType::PARTIAL, "PowerManager.SuspendLockout", + &gSuspendBlocker); + assert(gSuspendBlocker != nullptr); } }