• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

修订版9067003e1c7ae017e32fb6845295c47064a9a7fe (tree)
时间2016-12-09 16:22:09
作者Jaap Jan Meijer <jjmeijer88@gmai...>
CommiterChih-Wei Huang

Log Message

libsuspend: make sleep state configurable and add a fallback

This patch allows the user to set the sleep state target from
Android properties for both wakeup_count and earlysuspend methods.
It also includes a fallback state if the default state is not
available and the user didn't set the sleep.state property.

Signed-off-by: Jaap Jan Meijer <jjmeijer88@gmail.com>

更改概述

差异

--- a/libsuspend/autosuspend.c
+++ b/libsuspend/autosuspend.c
@@ -14,15 +14,22 @@
1414 * limitations under the License.
1515 */
1616
17+#include <errno.h>
18+#include <fcntl.h>
1719 #include <stdbool.h>
20+#include <string.h>
1821
1922 #define LOG_TAG "libsuspend"
2023 #include <cutils/log.h>
24+#include <cutils/properties.h>
2125
2226 #include <suspend/autosuspend.h>
2327
2428 #include "autosuspend_ops.h"
2529
30+static const char *default_sleep_state = "mem";
31+static const char *fallback_sleep_state = "freeze";
32+
2633 static struct autosuspend_ops *autosuspend_ops;
2734 static bool autosuspend_enabled;
2835 static bool autosuspend_inited;
@@ -110,3 +117,34 @@ int autosuspend_disable(void)
110117 autosuspend_enabled = false;
111118 return 0;
112119 }
120+
121+static bool sleep_state_available(const char *state)
122+{
123+ char buf[64];
124+ int fd = TEMP_FAILURE_RETRY(open(SYS_POWER_STATE, O_RDONLY));
125+ if (fd < 0) {
126+ ALOGE("Error reading power state: %s", SYS_POWER_STATE);
127+ return false;
128+ }
129+ TEMP_FAILURE_RETRY(read(fd, buf, 64));
130+ close(fd);
131+ return !!strstr(buf, state);
132+}
133+
134+const char *get_sleep_state()
135+{
136+ static char sleep_state[PROPERTY_VALUE_MAX] = "";
137+
138+ if (!sleep_state[0]) {
139+ if (property_get("sleep.state", sleep_state, NULL) > 0) {
140+ ALOGD("autosuspend using sleep.state property (%s)", sleep_state);
141+ } else if (sleep_state_available(default_sleep_state)) {
142+ ALOGD("autosuspend using default sleep_state (%s)", default_sleep_state);
143+ strncpy(sleep_state, default_sleep_state, PROPERTY_VALUE_MAX);
144+ } else {
145+ ALOGW("autosuspend \"%s\" unavailable, using fallback sleep.state (%s)", default_sleep_state, fallback_sleep_state);
146+ strncpy(sleep_state, fallback_sleep_state, PROPERTY_VALUE_MAX);
147+ }
148+ }
149+ return sleep_state;
150+}
--- a/libsuspend/autosuspend_earlysuspend.c
+++ b/libsuspend/autosuspend_earlysuspend.c
@@ -33,7 +33,6 @@
3333 #define EARLYSUSPEND_WAIT_FOR_FB_WAKE "/sys/power/wait_for_fb_wake"
3434
3535 static int sPowerStatefd;
36-static const char *pwr_state_mem = "mem";
3736 static const char *pwr_state_on = "on";
3837 static pthread_t earlysuspend_thread;
3938 static pthread_mutex_t earlysuspend_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -116,12 +115,13 @@ static void *earlysuspend_thread_func(void __unused *arg)
116115 static int autosuspend_earlysuspend_enable(void)
117116 {
118117 int ret;
118+ const char *sleep_state = get_sleep_state();
119119
120120 ALOGI("autosuspend_earlysuspend_enable");
121121
122- ret = TEMP_FAILURE_RETRY(write(sPowerStatefd, pwr_state_mem, strlen(pwr_state_mem)));
122+ ret = TEMP_FAILURE_RETRY(write(sPowerStatefd, sleep_state, strlen(sleep_state)));
123123 if (ret < 0) {
124- log_err("writing %s to %s", pwr_state_mem, SYS_POWER_STATE);
124+ log_err("writing %s to %s", sleep_state, SYS_POWER_STATE);
125125 return ret;
126126 }
127127
--- a/libsuspend/autosuspend_ops.h
+++ b/libsuspend/autosuspend_ops.h
@@ -28,4 +28,6 @@ struct autosuspend_ops *autosuspend_autosleep_init(void);
2828 struct autosuspend_ops *autosuspend_earlysuspend_init(void);
2929 struct autosuspend_ops *autosuspend_wakeup_count_init(void);
3030
31+const char *get_sleep_state();
32+
3133 #endif
--- a/libsuspend/autosuspend_wakeup_count.c
+++ b/libsuspend/autosuspend_wakeup_count.c
@@ -37,7 +37,6 @@ static int state_fd;
3737 static int wakeup_count_fd;
3838 static pthread_t suspend_thread;
3939 static sem_t suspend_lockout;
40-static const char *sleep_state = "mem";
4140 static void (*wakeup_func)(bool success) = NULL;
4241
4342 static void *suspend_thread_func(void *arg __attribute__((unused)))
@@ -80,6 +79,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
8079 strerror_r(errno, buf, sizeof(buf));
8180 ALOGE("Error writing to %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf);
8281 } else {
82+ const char *sleep_state = get_sleep_state();
8383 ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE);
8484 ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state)));
8585 if (ret < 0) {