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
This commit is contained in:
committed by
Steven Moreland
parent
e0eaef7772
commit
ae77d25902
@@ -181,7 +181,7 @@ cc_defaults {
|
|||||||
"android.frameworks.stats-V1-ndk_platform",
|
"android.frameworks.stats-V1-ndk_platform",
|
||||||
"android.system.suspend.control-V1-cpp",
|
"android.system.suspend.control-V1-cpp",
|
||||||
"android.system.suspend.control.internal-cpp",
|
"android.system.suspend.control.internal-cpp",
|
||||||
"android.system.suspend@1.0",
|
"android.system.suspend-V1-ndk",
|
||||||
"service.incremental",
|
"service.incremental",
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|||||||
@@ -18,11 +18,12 @@
|
|||||||
|
|
||||||
//#define LOG_NDEBUG 0
|
//#define LOG_NDEBUG 0
|
||||||
|
|
||||||
|
#include <aidl/android/system/suspend/ISystemSuspend.h>
|
||||||
|
#include <aidl/android/system/suspend/IWakeLock.h>
|
||||||
#include <android/hardware/power/1.1/IPower.h>
|
#include <android/hardware/power/1.1/IPower.h>
|
||||||
#include <android/hardware/power/Boost.h>
|
#include <android/hardware/power/Boost.h>
|
||||||
#include <android/hardware/power/IPower.h>
|
#include <android/hardware/power/IPower.h>
|
||||||
#include <android/hardware/power/Mode.h>
|
#include <android/hardware/power/Mode.h>
|
||||||
#include <android/system/suspend/1.0/ISystemSuspend.h>
|
|
||||||
#include <android/system/suspend/ISuspendControlService.h>
|
#include <android/system/suspend/ISuspendControlService.h>
|
||||||
#include <android/system/suspend/internal/ISuspendControlServiceInternal.h>
|
#include <android/system/suspend/internal/ISuspendControlServiceInternal.h>
|
||||||
#include <nativehelper/JNIHelp.h>
|
#include <nativehelper/JNIHelp.h>
|
||||||
@@ -34,6 +35,7 @@
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include <android-base/chrono_utils.h>
|
#include <android-base/chrono_utils.h>
|
||||||
|
#include <android/binder_manager.h>
|
||||||
#include <android_runtime/AndroidRuntime.h>
|
#include <android_runtime/AndroidRuntime.h>
|
||||||
#include <android_runtime/Log.h>
|
#include <android_runtime/Log.h>
|
||||||
#include <binder/IServiceManager.h>
|
#include <binder/IServiceManager.h>
|
||||||
@@ -41,20 +43,20 @@
|
|||||||
#include <hardware/power.h>
|
#include <hardware/power.h>
|
||||||
#include <hardware_legacy/power.h>
|
#include <hardware_legacy/power.h>
|
||||||
#include <hidl/ServiceManagement.h>
|
#include <hidl/ServiceManagement.h>
|
||||||
|
#include <utils/Log.h>
|
||||||
|
#include <utils/String8.h>
|
||||||
#include <utils/Timers.h>
|
#include <utils/Timers.h>
|
||||||
#include <utils/misc.h>
|
#include <utils/misc.h>
|
||||||
#include <utils/String8.h>
|
|
||||||
#include <utils/Log.h>
|
|
||||||
|
|
||||||
#include "com_android_server_power_PowerManagerService.h"
|
#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::String8;
|
||||||
using android::hardware::power::Boost;
|
using android::hardware::power::Boost;
|
||||||
using android::hardware::power::Mode;
|
using android::hardware::power::Mode;
|
||||||
using android::system::suspend::ISuspendControlService;
|
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_1 = android::hardware::power::V1_1::IPower;
|
||||||
using IPowerV1_0 = android::hardware::power::V1_0::IPower;
|
using IPowerV1_0 = android::hardware::power::V1_0::IPower;
|
||||||
using IPowerAidl = android::hardware::power::IPower;
|
using IPowerAidl = android::hardware::power::IPower;
|
||||||
@@ -133,20 +135,21 @@ void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static sp<ISystemSuspend> gSuspendHal = nullptr;
|
static std::shared_ptr<ISystemSuspend> gSuspendHal = nullptr;
|
||||||
static sp<ISuspendControlService> gSuspendControl = nullptr;
|
static sp<ISuspendControlService> gSuspendControl = nullptr;
|
||||||
static sp<system::suspend::internal::ISuspendControlServiceInternal> gSuspendControlInternal =
|
static sp<system::suspend::internal::ISuspendControlServiceInternal> gSuspendControlInternal =
|
||||||
nullptr;
|
nullptr;
|
||||||
static sp<IWakeLock> gSuspendBlocker = nullptr;
|
static std::shared_ptr<IWakeLock> gSuspendBlocker = nullptr;
|
||||||
static std::mutex gSuspendMutex;
|
static std::mutex gSuspendMutex;
|
||||||
|
|
||||||
// Assume SystemSuspend HAL is always alive.
|
// Assume SystemSuspend HAL is always alive.
|
||||||
// TODO: Force device to restart if SystemSuspend HAL dies.
|
// TODO: Force device to restart if SystemSuspend HAL dies.
|
||||||
sp<ISystemSuspend> getSuspendHal() {
|
std::shared_ptr<ISystemSuspend> getSuspendHal() {
|
||||||
static std::once_flag suspendHalFlag;
|
static std::once_flag suspendHalFlag;
|
||||||
std::call_once(suspendHalFlag, []() {
|
std::call_once(suspendHalFlag, []() {
|
||||||
::android::hardware::details::waitForHwService(ISystemSuspend::descriptor, "default");
|
const std::string suspendInstance = std::string() + ISystemSuspend::descriptor + "/default";
|
||||||
gSuspendHal = ISystemSuspend::getService();
|
gSuspendHal = ISystemSuspend::fromBinder(
|
||||||
|
ndk::SpAIBinder(AServiceManager_waitForService(suspendInstance.c_str())));
|
||||||
assert(gSuspendHal != nullptr);
|
assert(gSuspendHal != nullptr);
|
||||||
});
|
});
|
||||||
return gSuspendHal;
|
return gSuspendHal;
|
||||||
@@ -184,7 +187,7 @@ void enableAutoSuspend() {
|
|||||||
std::lock_guard<std::mutex> lock(gSuspendMutex);
|
std::lock_guard<std::mutex> lock(gSuspendMutex);
|
||||||
if (gSuspendBlocker) {
|
if (gSuspendBlocker) {
|
||||||
gSuspendBlocker->release();
|
gSuspendBlocker->release();
|
||||||
gSuspendBlocker.clear();
|
gSuspendBlocker = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,9 +195,10 @@ void enableAutoSuspend() {
|
|||||||
void disableAutoSuspend() {
|
void disableAutoSuspend() {
|
||||||
std::lock_guard<std::mutex> lock(gSuspendMutex);
|
std::lock_guard<std::mutex> lock(gSuspendMutex);
|
||||||
if (!gSuspendBlocker) {
|
if (!gSuspendBlocker) {
|
||||||
sp<ISystemSuspend> suspendHal = getSuspendHal();
|
std::shared_ptr<ISystemSuspend> suspendHal = getSuspendHal();
|
||||||
gSuspendBlocker = suspendHal->acquireWakeLock(WakeLockType::PARTIAL,
|
suspendHal->acquireWakeLock(WakeLockType::PARTIAL, "PowerManager.SuspendLockout",
|
||||||
"PowerManager.SuspendLockout");
|
&gSuspendBlocker);
|
||||||
|
assert(gSuspendBlocker != nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user