Merge "PowerManagerService: Use AIDL Suspend HAL" into sc-dev-plus-aosp
This commit is contained in:
@@ -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",
|
||||
],
|
||||
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
|
||||
//#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/Boost.h>
|
||||
#include <android/hardware/power/IPower.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/internal/ISuspendControlServiceInternal.h>
|
||||
#include <nativehelper/JNIHelp.h>
|
||||
@@ -34,6 +35,7 @@
|
||||
#include <limits.h>
|
||||
|
||||
#include <android-base/chrono_utils.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <android_runtime/AndroidRuntime.h>
|
||||
#include <android_runtime/Log.h>
|
||||
#include <binder/IServiceManager.h>
|
||||
@@ -41,20 +43,20 @@
|
||||
#include <hardware/power.h>
|
||||
#include <hardware_legacy/power.h>
|
||||
#include <hidl/ServiceManagement.h>
|
||||
#include <utils/Log.h>
|
||||
#include <utils/String8.h>
|
||||
#include <utils/Timers.h>
|
||||
#include <utils/misc.h>
|
||||
#include <utils/String8.h>
|
||||
#include <utils/Log.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::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<ISystemSuspend> gSuspendHal = nullptr;
|
||||
static std::shared_ptr<ISystemSuspend> gSuspendHal = nullptr;
|
||||
static sp<ISuspendControlService> gSuspendControl = nullptr;
|
||||
static sp<system::suspend::internal::ISuspendControlServiceInternal> gSuspendControlInternal =
|
||||
nullptr;
|
||||
static sp<IWakeLock> gSuspendBlocker = nullptr;
|
||||
static std::shared_ptr<IWakeLock> gSuspendBlocker = nullptr;
|
||||
static std::mutex gSuspendMutex;
|
||||
|
||||
// Assume SystemSuspend HAL is always alive.
|
||||
// TODO: Force device to restart if SystemSuspend HAL dies.
|
||||
sp<ISystemSuspend> getSuspendHal() {
|
||||
std::shared_ptr<ISystemSuspend> 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<std::mutex> lock(gSuspendMutex);
|
||||
if (gSuspendBlocker) {
|
||||
gSuspendBlocker->release();
|
||||
gSuspendBlocker.clear();
|
||||
gSuspendBlocker = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,9 +195,10 @@ void enableAutoSuspend() {
|
||||
void disableAutoSuspend() {
|
||||
std::lock_guard<std::mutex> lock(gSuspendMutex);
|
||||
if (!gSuspendBlocker) {
|
||||
sp<ISystemSuspend> suspendHal = getSuspendHal();
|
||||
gSuspendBlocker = suspendHal->acquireWakeLock(WakeLockType::PARTIAL,
|
||||
"PowerManager.SuspendLockout");
|
||||
std::shared_ptr<ISystemSuspend> suspendHal = getSuspendHal();
|
||||
suspendHal->acquireWakeLock(WakeLockType::PARTIAL, "PowerManager.SuspendLockout",
|
||||
&gSuspendBlocker);
|
||||
assert(gSuspendBlocker != nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user