system/hardware/interfaces
Révision | 4405fb0b202fdc1cd7b59c6d8348d0715b7bfd70 (tree) |
---|---|
l'heure | 2020-04-20 19:43:48 |
Auteur | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
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.
@@ -18,6 +18,7 @@ | ||
18 | 18 | |
19 | 19 | #include <android-base/file.h> |
20 | 20 | #include <android-base/logging.h> |
21 | +#include <android-base/properties.h> | |
21 | 22 | #include <android-base/strings.h> |
22 | 23 | #include <google/protobuf/text_format.h> |
23 | 24 | #include <hidl/Status.h> |
@@ -31,6 +32,7 @@ | ||
31 | 32 | #include <string> |
32 | 33 | #include <thread> |
33 | 34 | |
35 | +using ::android::base::GetProperty; | |
34 | 36 | using ::android::base::ReadFdToString; |
35 | 37 | using ::android::base::WriteStringToFd; |
36 | 38 | using ::android::hardware::Void; |
@@ -139,7 +141,7 @@ bool SystemSuspend::forceSuspend() { | ||
139 | 141 | // returns from suspend, the wakelocks and SuspendCounter will not have |
140 | 142 | // changed. |
141 | 143 | auto counterLock = std::unique_lock(mCounterLock); |
142 | - bool success = WriteStringToFd(kSleepState, mStateFd); | |
144 | + bool success = WriteStringToFd(getSleepState(), mStateFd); | |
143 | 145 | counterLock.unlock(); |
144 | 146 | |
145 | 147 | if (!success) { |
@@ -252,7 +254,7 @@ void SystemSuspend::initAutosuspend() { | ||
252 | 254 | PLOG(VERBOSE) << "error writing from /sys/power/wakeup_count"; |
253 | 255 | continue; |
254 | 256 | } |
255 | - bool success = WriteStringToFd(kSleepState, mStateFd); | |
257 | + bool success = WriteStringToFd(getSleepState(), mStateFd); | |
256 | 258 | counterLock.unlock(); |
257 | 259 | |
258 | 260 | if (!success) { |
@@ -268,6 +270,25 @@ void SystemSuspend::initAutosuspend() { | ||
268 | 270 | LOG(INFO) << "automatic system suspend enabled"; |
269 | 271 | } |
270 | 272 | |
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 | + | |
271 | 292 | void SystemSuspend::updateSleepTime(bool success) { |
272 | 293 | static constexpr std::chrono::milliseconds kMaxSleepTime = 1min; |
273 | 294 | if (success) { |
@@ -82,12 +82,14 @@ class SystemSuspend : public ISystemSuspend { | ||
82 | 82 | |
83 | 83 | private: |
84 | 84 | void initAutosuspend(); |
85 | + const std::string &getSleepState(); | |
85 | 86 | |
86 | 87 | std::mutex mCounterLock; |
87 | 88 | std::condition_variable mCounterCondVar; |
88 | 89 | uint32_t mSuspendCounter; |
89 | 90 | unique_fd mWakeupCountFd; |
90 | 91 | unique_fd mStateFd; |
92 | + std::string mSleepState; | |
91 | 93 | |
92 | 94 | // mStats can be inconsistent with with mSuspendCounter since we use two separate locks to |
93 | 95 | // protect these. However, since mStats is only for debugging we prioritize performance. |