Loading services/core/jni/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -120,6 +120,7 @@ cc_defaults { "android.frameworks.schedulerservice@1.0", "android.frameworks.sensorservice@1.0", "android.system.suspend@1.0", "suspend_control_aidl_interface-cpp", ], static_libs: [ Loading services/core/jni/com_android_server_am_BatteryStatsService.cpp +16 −13 Original line number Diff line number Diff line Loading @@ -30,8 +30,8 @@ #include <android/hardware/power/1.0/IPower.h> #include <android/hardware/power/1.1/IPower.h> #include <android/system/suspend/1.0/ISystemSuspend.h> #include <android/system/suspend/1.0/ISystemSuspendCallback.h> #include <android/system/suspend/BnSuspendCallback.h> #include <android/system/suspend/ISuspendControlService.h> #include <android_runtime/AndroidRuntime.h> #include <jni.h> Loading @@ -44,14 +44,14 @@ using android::hardware::Return; using android::hardware::Void; using android::system::suspend::BnSuspendCallback; using android::hardware::power::V1_0::PowerStatePlatformSleepState; using android::hardware::power::V1_0::PowerStateVoter; using android::hardware::power::V1_0::Status; using android::hardware::power::V1_1::PowerStateSubsystem; using android::hardware::power::V1_1::PowerStateSubsystemSleepState; using android::hardware::hidl_vec; using android::system::suspend::V1_0::ISystemSuspend; using android::system::suspend::V1_0::ISystemSuspendCallback; using android::system::suspend::ISuspendControlService; using IPowerV1_1 = android::hardware::power::V1_1::IPower; using IPowerV1_0 = android::hardware::power::V1_0::IPower; Loading @@ -66,7 +66,7 @@ static sem_t wakeup_sem; extern sp<IPowerV1_0> getPowerHalV1_0(); extern sp<IPowerV1_1> getPowerHalV1_1(); extern bool processPowerHalReturn(const Return<void> &ret, const char* functionName); extern sp<ISystemSuspend> getSuspendHal(); extern sp<ISuspendControlService> getSuspendControl(); // Java methods used in getLowPowerStats static jmethodID jgetAndUpdatePlatformState = NULL; Loading @@ -74,17 +74,17 @@ static jmethodID jgetSubsystem = NULL; static jmethodID jputVoter = NULL; static jmethodID jputState = NULL; class WakeupCallback : public ISystemSuspendCallback { class WakeupCallback : public BnSuspendCallback { public: Return<void> notifyWakeup(bool success) override { ALOGV("In wakeup_callback: %s", success ? "resumed from suspend" : "suspend aborted"); binder::Status notifyWakeup(bool success) override { ALOGI("In wakeup_callback: %s", success ? "resumed from suspend" : "suspend aborted"); int ret = sem_post(&wakeup_sem); if (ret < 0) { char buf[80]; strerror_r(errno, buf, sizeof(buf)); ALOGE("Error posting wakeup sem: %s\n", buf); } return Void(); return binder::Status::ok(); } }; Loading @@ -107,9 +107,12 @@ static jint nativeWaitWakeup(JNIEnv *env, jobject clazz, jobject outBuf) jniThrowException(env, "java/lang/IllegalStateException", buf); return -1; } ALOGV("Registering callback..."); sp<ISystemSuspend> suspendHal = getSuspendHal(); suspendHal->registerCallback(new WakeupCallback()); sp<ISuspendControlService> suspendControl = getSuspendControl(); bool isRegistered = false; suspendControl->registerCallback(new WakeupCallback(), &isRegistered); if (!isRegistered) { ALOGE("Failed to register wakeup callback"); } } // Wait for wakeup. Loading services/core/jni/com_android_server_power_PowerManagerService.cpp +30 −11 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <android/hardware/power/1.1/IPower.h> #include <android/system/suspend/1.0/ISystemSuspend.h> #include <android/system/suspend/ISuspendControlService.h> #include <nativehelper/JNIHelp.h> #include "jni.h" Loading @@ -30,13 +31,14 @@ #include <android-base/chrono_utils.h> #include <android_runtime/AndroidRuntime.h> #include <android_runtime/Log.h> #include <binder/IServiceManager.h> #include <hardware/power.h> #include <hardware_legacy/power.h> #include <hidl/ServiceManagement.h> #include <utils/Timers.h> #include <utils/misc.h> #include <utils/String8.h> #include <utils/Log.h> #include <hardware/power.h> #include <hardware_legacy/power.h> #include <hidl/ServiceManagement.h> #include "com_android_server_power_PowerManagerService.h" Loading @@ -48,6 +50,7 @@ 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::system::suspend::ISuspendControlService; using IPowerV1_1 = android::hardware::power::V1_1::IPower; using IPowerV1_0 = android::hardware::power::V1_0::IPower; Loading Loading @@ -176,6 +179,7 @@ void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t } static sp<ISystemSuspend> gSuspendHal = nullptr; static sp<ISuspendControlService> gSuspendControl = nullptr; static sp<IWakeLock> gSuspendBlocker = nullptr; static std::mutex gSuspendMutex; Loading @@ -191,20 +195,35 @@ sp<ISystemSuspend> getSuspendHal() { return gSuspendHal; } sp<ISuspendControlService> getSuspendControl() { static std::once_flag suspendControlFlag; std::call_once(suspendControlFlag, [](){ while(gSuspendControl == nullptr) { sp<IBinder> control = defaultServiceManager()->getService(String16("suspend_control")); if (control != nullptr) { gSuspendControl = interface_cast<ISuspendControlService>(control); } } }); return gSuspendControl; } void enableAutoSuspend() { static bool enabled = false; std::lock_guard<std::mutex> lock(gSuspendMutex); if (!enabled) { sp<ISystemSuspend> suspendHal = getSuspendHal(); suspendHal->enableAutosuspend(); enabled = true; sp<ISuspendControlService> suspendControl = getSuspendControl(); suspendControl->enableAutosuspend(&enabled); } { std::lock_guard<std::mutex> lock(gSuspendMutex); if (gSuspendBlocker) { gSuspendBlocker->release(); gSuspendBlocker.clear(); } } } void disableAutoSuspend() { std::lock_guard<std::mutex> lock(gSuspendMutex); Loading Loading
services/core/jni/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -120,6 +120,7 @@ cc_defaults { "android.frameworks.schedulerservice@1.0", "android.frameworks.sensorservice@1.0", "android.system.suspend@1.0", "suspend_control_aidl_interface-cpp", ], static_libs: [ Loading
services/core/jni/com_android_server_am_BatteryStatsService.cpp +16 −13 Original line number Diff line number Diff line Loading @@ -30,8 +30,8 @@ #include <android/hardware/power/1.0/IPower.h> #include <android/hardware/power/1.1/IPower.h> #include <android/system/suspend/1.0/ISystemSuspend.h> #include <android/system/suspend/1.0/ISystemSuspendCallback.h> #include <android/system/suspend/BnSuspendCallback.h> #include <android/system/suspend/ISuspendControlService.h> #include <android_runtime/AndroidRuntime.h> #include <jni.h> Loading @@ -44,14 +44,14 @@ using android::hardware::Return; using android::hardware::Void; using android::system::suspend::BnSuspendCallback; using android::hardware::power::V1_0::PowerStatePlatformSleepState; using android::hardware::power::V1_0::PowerStateVoter; using android::hardware::power::V1_0::Status; using android::hardware::power::V1_1::PowerStateSubsystem; using android::hardware::power::V1_1::PowerStateSubsystemSleepState; using android::hardware::hidl_vec; using android::system::suspend::V1_0::ISystemSuspend; using android::system::suspend::V1_0::ISystemSuspendCallback; using android::system::suspend::ISuspendControlService; using IPowerV1_1 = android::hardware::power::V1_1::IPower; using IPowerV1_0 = android::hardware::power::V1_0::IPower; Loading @@ -66,7 +66,7 @@ static sem_t wakeup_sem; extern sp<IPowerV1_0> getPowerHalV1_0(); extern sp<IPowerV1_1> getPowerHalV1_1(); extern bool processPowerHalReturn(const Return<void> &ret, const char* functionName); extern sp<ISystemSuspend> getSuspendHal(); extern sp<ISuspendControlService> getSuspendControl(); // Java methods used in getLowPowerStats static jmethodID jgetAndUpdatePlatformState = NULL; Loading @@ -74,17 +74,17 @@ static jmethodID jgetSubsystem = NULL; static jmethodID jputVoter = NULL; static jmethodID jputState = NULL; class WakeupCallback : public ISystemSuspendCallback { class WakeupCallback : public BnSuspendCallback { public: Return<void> notifyWakeup(bool success) override { ALOGV("In wakeup_callback: %s", success ? "resumed from suspend" : "suspend aborted"); binder::Status notifyWakeup(bool success) override { ALOGI("In wakeup_callback: %s", success ? "resumed from suspend" : "suspend aborted"); int ret = sem_post(&wakeup_sem); if (ret < 0) { char buf[80]; strerror_r(errno, buf, sizeof(buf)); ALOGE("Error posting wakeup sem: %s\n", buf); } return Void(); return binder::Status::ok(); } }; Loading @@ -107,9 +107,12 @@ static jint nativeWaitWakeup(JNIEnv *env, jobject clazz, jobject outBuf) jniThrowException(env, "java/lang/IllegalStateException", buf); return -1; } ALOGV("Registering callback..."); sp<ISystemSuspend> suspendHal = getSuspendHal(); suspendHal->registerCallback(new WakeupCallback()); sp<ISuspendControlService> suspendControl = getSuspendControl(); bool isRegistered = false; suspendControl->registerCallback(new WakeupCallback(), &isRegistered); if (!isRegistered) { ALOGE("Failed to register wakeup callback"); } } // Wait for wakeup. Loading
services/core/jni/com_android_server_power_PowerManagerService.cpp +30 −11 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <android/hardware/power/1.1/IPower.h> #include <android/system/suspend/1.0/ISystemSuspend.h> #include <android/system/suspend/ISuspendControlService.h> #include <nativehelper/JNIHelp.h> #include "jni.h" Loading @@ -30,13 +31,14 @@ #include <android-base/chrono_utils.h> #include <android_runtime/AndroidRuntime.h> #include <android_runtime/Log.h> #include <binder/IServiceManager.h> #include <hardware/power.h> #include <hardware_legacy/power.h> #include <hidl/ServiceManagement.h> #include <utils/Timers.h> #include <utils/misc.h> #include <utils/String8.h> #include <utils/Log.h> #include <hardware/power.h> #include <hardware_legacy/power.h> #include <hidl/ServiceManagement.h> #include "com_android_server_power_PowerManagerService.h" Loading @@ -48,6 +50,7 @@ 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::system::suspend::ISuspendControlService; using IPowerV1_1 = android::hardware::power::V1_1::IPower; using IPowerV1_0 = android::hardware::power::V1_0::IPower; Loading Loading @@ -176,6 +179,7 @@ void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t } static sp<ISystemSuspend> gSuspendHal = nullptr; static sp<ISuspendControlService> gSuspendControl = nullptr; static sp<IWakeLock> gSuspendBlocker = nullptr; static std::mutex gSuspendMutex; Loading @@ -191,20 +195,35 @@ sp<ISystemSuspend> getSuspendHal() { return gSuspendHal; } sp<ISuspendControlService> getSuspendControl() { static std::once_flag suspendControlFlag; std::call_once(suspendControlFlag, [](){ while(gSuspendControl == nullptr) { sp<IBinder> control = defaultServiceManager()->getService(String16("suspend_control")); if (control != nullptr) { gSuspendControl = interface_cast<ISuspendControlService>(control); } } }); return gSuspendControl; } void enableAutoSuspend() { static bool enabled = false; std::lock_guard<std::mutex> lock(gSuspendMutex); if (!enabled) { sp<ISystemSuspend> suspendHal = getSuspendHal(); suspendHal->enableAutosuspend(); enabled = true; sp<ISuspendControlService> suspendControl = getSuspendControl(); suspendControl->enableAutosuspend(&enabled); } { std::lock_guard<std::mutex> lock(gSuspendMutex); if (gSuspendBlocker) { gSuspendBlocker->release(); gSuspendBlocker.clear(); } } } void disableAutoSuspend() { std::lock_guard<std::mutex> lock(gSuspendMutex); Loading