From edc09109a7146ac2671c0cfde2fe68f8e06be00c 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 | 40 ++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/services/core/jni/Android.bp b/services/core/jni/Android.bp index a0c96f0f19b8b..cc97dd884458d 100644 --- a/services/core/jni/Android.bp +++ b/services/core/jni/Android.bp @@ -176,7 +176,7 @@ cc_defaults { "android.frameworks.stats@1.0", "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 7a6d310c25204..4922b2cc9a801 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 @@ -33,6 +34,7 @@ #include #include +#include #include #include #include @@ -40,23 +42,23 @@ #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::Return; using android::hardware::Void; using android::hardware::power::Boost; using android::hardware::power::Mode; -using android::hardware::power::V1_0::PowerHint; using android::hardware::power::V1_0::Feature; -using android::String8; -using android::system::suspend::V1_0::ISystemSuspend; -using android::system::suspend::V1_0::IWakeLock; -using android::system::suspend::V1_0::WakeLockType; +using android::hardware::power::V1_0::PowerHint; using android::system::suspend::ISuspendControlService; using IPowerV1_1 = android::hardware::power::V1_1::IPower; using IPowerV1_0 = android::hardware::power::V1_0::IPower; @@ -352,20 +354,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; @@ -403,7 +406,7 @@ void enableAutoSuspend() { std::lock_guard lock(gSuspendMutex); if (gSuspendBlocker) { gSuspendBlocker->release(); - gSuspendBlocker.clear(); + gSuspendBlocker = nullptr; } } } @@ -411,9 +414,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); } }