Android-x86
Fork
Faire un don

  • R/O
  • HTTP
  • SSH
  • HTTPS

system-hardware-interfaces: Commit

system/hardware/interfaces


Commit MetaInfo

Révision4405fb0b202fdc1cd7b59c6d8348d0715b7bfd70 (tree)
l'heure2020-04-20 19:43:48
AuteurChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Message de Log

Make sleep state configurable and add a fallback

This patch allows the user to set the sleep state target from
Android properties for wakeup_count method.

It also includes a fallback state if the default state is not
available and the user didn't set the sleep.state property.

Change Summary

Modification

--- a/suspend/1.0/default/SystemSuspend.cpp
+++ b/suspend/1.0/default/SystemSuspend.cpp
@@ -18,6 +18,7 @@
1818
1919 #include <android-base/file.h>
2020 #include <android-base/logging.h>
21+#include <android-base/properties.h>
2122 #include <android-base/strings.h>
2223 #include <google/protobuf/text_format.h>
2324 #include <hidl/Status.h>
@@ -31,6 +32,7 @@
3132 #include <string>
3233 #include <thread>
3334
35+using ::android::base::GetProperty;
3436 using ::android::base::ReadFdToString;
3537 using ::android::base::WriteStringToFd;
3638 using ::android::hardware::Void;
@@ -139,7 +141,7 @@ bool SystemSuspend::forceSuspend() {
139141 // returns from suspend, the wakelocks and SuspendCounter will not have
140142 // changed.
141143 auto counterLock = std::unique_lock(mCounterLock);
142- bool success = WriteStringToFd(kSleepState, mStateFd);
144+ bool success = WriteStringToFd(getSleepState(), mStateFd);
143145 counterLock.unlock();
144146
145147 if (!success) {
@@ -252,7 +254,7 @@ void SystemSuspend::initAutosuspend() {
252254 PLOG(VERBOSE) << "error writing from /sys/power/wakeup_count";
253255 continue;
254256 }
255- bool success = WriteStringToFd(kSleepState, mStateFd);
257+ bool success = WriteStringToFd(getSleepState(), mStateFd);
256258 counterLock.unlock();
257259
258260 if (!success) {
@@ -268,6 +270,25 @@ void SystemSuspend::initAutosuspend() {
268270 LOG(INFO) << "automatic system suspend enabled";
269271 }
270272
273+const string &SystemSuspend::getSleepState() {
274+ if (mSleepState.empty()) {
275+ mSleepState = GetProperty("sleep.state", "");
276+ if (!mSleepState.empty()) {
277+ LOG(INFO) << "autosuspend using sleep.state property " << mSleepState;
278+ } else {
279+ string buf = readFd(mStateFd);
280+ if (buf.find(kSleepState) != std::string::npos) {
281+ mSleepState = kSleepState;
282+ LOG(INFO) << "autosuspend using default sleep_state " << mSleepState;
283+ } else {
284+ mSleepState = "freeze";
285+ LOG(WARNING) << "autosuspend using fallback state " << mSleepState;
286+ }
287+ }
288+ }
289+ return mSleepState;
290+}
291+
271292 void SystemSuspend::updateSleepTime(bool success) {
272293 static constexpr std::chrono::milliseconds kMaxSleepTime = 1min;
273294 if (success) {
--- a/suspend/1.0/default/SystemSuspend.h
+++ b/suspend/1.0/default/SystemSuspend.h
@@ -82,12 +82,14 @@ class SystemSuspend : public ISystemSuspend {
8282
8383 private:
8484 void initAutosuspend();
85+ const std::string &getSleepState();
8586
8687 std::mutex mCounterLock;
8788 std::condition_variable mCounterCondVar;
8889 uint32_t mSuspendCounter;
8990 unique_fd mWakeupCountFd;
9091 unique_fd mStateFd;
92+ std::string mSleepState;
9193
9294 // mStats can be inconsistent with with mSuspendCounter since we use two separate locks to
9395 // protect these. However, since mStats is only for debugging we prioritize performance.
Afficher sur ancien navigateur de dépôt.