• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

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

system/corennnnn


Commit MetaInfo

修訂3ac1162a06f284d7ea1f9a6f48b2057dcddd7d73 (tree)
時間2016-12-09 16:22:09
作者Chih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

libsuspend: enable earlysuspend for android-x86

Change Summary

差異

--- a/libsuspend/autosuspend_earlysuspend.c
+++ b/libsuspend/autosuspend_earlysuspend.c
@@ -29,7 +29,6 @@
2929
3030 #include "autosuspend_ops.h"
3131
32-#define EARLYSUSPEND_SYS_POWER_STATE "/sys/power/state"
3332 #define EARLYSUSPEND_WAIT_FOR_FB_SLEEP "/sys/power/wait_for_fb_sleep"
3433 #define EARLYSUSPEND_WAIT_FOR_FB_WAKE "/sys/power/wait_for_fb_wake"
3534
@@ -45,37 +44,58 @@ static enum {
4544 EARLYSUSPEND_MEM,
4645 } earlysuspend_state = EARLYSUSPEND_ON;
4746
48-int wait_for_fb_wake(void)
47+static void log_err(const char *fmt, ...)
4948 {
50- int err = 0;
51- char buf;
52- int fd = TEMP_FAILURE_RETRY(open(EARLYSUSPEND_WAIT_FOR_FB_WAKE, O_RDONLY, 0));
49+ char err[80];
50+ char buf[512];
51+
52+ strerror_r(errno, err, sizeof(err));
53+
54+ va_list ap;
55+ va_start(ap, fmt);
56+ vsnprintf(buf, sizeof(buf), fmt, ap);
57+ va_end(ap);
58+ ALOGE("Error %s: %s", buf, err);
59+}
60+
61+static int open_file(const char *file, char *buf, size_t sz, int *fd)
62+{
63+ int err;
64+ int f = TEMP_FAILURE_RETRY(open(file, fd ? O_RDWR : O_RDONLY, 0));
5365 // if the file doesn't exist, the error will be caught in read() below
54- err = TEMP_FAILURE_RETRY(read(fd, &buf, 1));
55- ALOGE_IF(err < 0,
56- "*** ANDROID_WAIT_FOR_FB_WAKE failed (%s)", strerror(errno));
57- close(fd);
58- return err < 0 ? err : 0;
66+ err = TEMP_FAILURE_RETRY(read(f, buf, sz));
67+
68+ if (err < 0) {
69+ log_err("opening %s", file);
70+ } else {
71+ err = 0;
72+ }
73+
74+ if (fd == NULL) {
75+ close(f);
76+ } else {
77+ *fd = f;
78+ }
79+ return err;
80+}
81+
82+static int wait_for_fb_wake(void)
83+{
84+ char buf;
85+ return open_file(EARLYSUSPEND_WAIT_FOR_FB_WAKE, &buf, 1, NULL);
5986 }
6087
6188 static int wait_for_fb_sleep(void)
6289 {
63- int err = 0;
6490 char buf;
65- int fd = TEMP_FAILURE_RETRY(open(EARLYSUSPEND_WAIT_FOR_FB_SLEEP, O_RDONLY, 0));
66- // if the file doesn't exist, the error will be caught in read() below
67- err = TEMP_FAILURE_RETRY(read(fd, &buf, 1));
68- ALOGE_IF(err < 0,
69- "*** ANDROID_WAIT_FOR_FB_SLEEP failed (%s)", strerror(errno));
70- close(fd);
71- return err < 0 ? err : 0;
91+ return open_file(EARLYSUSPEND_WAIT_FOR_FB_SLEEP, &buf, 1, NULL);
7292 }
7393
7494 static void *earlysuspend_thread_func(void __unused *arg)
7595 {
7696 while (1) {
7797 if (wait_for_fb_sleep()) {
78- ALOGE("Failed reading wait_for_fb_sleep, exiting earlysuspend thread\n");
98+ ALOGE("Failed reading wait_for_fb_sleep, exiting earlysuspend thread");
7999 return NULL;
80100 }
81101 pthread_mutex_lock(&earlysuspend_mutex);
@@ -84,7 +104,7 @@ static void *earlysuspend_thread_func(void __unused *arg)
84104 pthread_mutex_unlock(&earlysuspend_mutex);
85105
86106 if (wait_for_fb_wake()) {
87- ALOGE("Failed reading wait_for_fb_wake, exiting earlysuspend thread\n");
107+ ALOGE("Failed reading wait_for_fb_wake, exiting earlysuspend thread");
88108 return NULL;
89109 }
90110 pthread_mutex_lock(&earlysuspend_mutex);
@@ -95,16 +115,14 @@ static void *earlysuspend_thread_func(void __unused *arg)
95115 }
96116 static int autosuspend_earlysuspend_enable(void)
97117 {
98- char buf[80];
99118 int ret;
100119
101- ALOGV("autosuspend_earlysuspend_enable\n");
120+ ALOGI("autosuspend_earlysuspend_enable");
102121
103- ret = write(sPowerStatefd, pwr_state_mem, strlen(pwr_state_mem));
122+ ret = TEMP_FAILURE_RETRY(write(sPowerStatefd, pwr_state_mem, strlen(pwr_state_mem)));
104123 if (ret < 0) {
105- strerror_r(errno, buf, sizeof(buf));
106- ALOGE("Error writing to %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
107- goto err;
124+ log_err("writing %s to %s", pwr_state_mem, SYS_POWER_STATE);
125+ return ret;
108126 }
109127
110128 if (wait_for_earlysuspend) {
@@ -115,26 +133,22 @@ static int autosuspend_earlysuspend_enable(void)
115133 pthread_mutex_unlock(&earlysuspend_mutex);
116134 }
117135
118- ALOGV("autosuspend_earlysuspend_enable done\n");
136+ ALOGD("autosuspend_earlysuspend_enable done");
119137
120138 return 0;
121-
122-err:
123- return ret;
124139 }
125140
126141 static int autosuspend_earlysuspend_disable(void)
127142 {
128- char buf[80];
129143 int ret;
130144
131- ALOGV("autosuspend_earlysuspend_disable\n");
145+ ALOGI("autosuspend_earlysuspend_disable");
132146
133147 ret = TEMP_FAILURE_RETRY(write(sPowerStatefd, pwr_state_on, strlen(pwr_state_on)));
134148 if (ret < 0) {
135- strerror_r(errno, buf, sizeof(buf));
136- ALOGE("Error writing to %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
137- goto err;
149+#if DEBUG
150+ log_err("writing %s to %s", pwr_state_on, SYS_POWER_STATE);
151+#endif
138152 }
139153
140154 if (wait_for_earlysuspend) {
@@ -145,12 +159,9 @@ static int autosuspend_earlysuspend_disable(void)
145159 pthread_mutex_unlock(&earlysuspend_mutex);
146160 }
147161
148- ALOGV("autosuspend_earlysuspend_disable done\n");
162+ ALOGD("autosuspend_earlysuspend_disable done");
149163
150164 return 0;
151-
152-err:
153- return ret;
154165 }
155166
156167 struct autosuspend_ops autosuspend_earlysuspend_ops = {
@@ -160,26 +171,26 @@ struct autosuspend_ops autosuspend_earlysuspend_ops = {
160171
161172 void start_earlysuspend_thread(void)
162173 {
163- char buf[80];
164174 int ret;
165175
166176 ret = access(EARLYSUSPEND_WAIT_FOR_FB_SLEEP, F_OK);
167177 if (ret < 0) {
178+ log_err("accessing %s", EARLYSUSPEND_WAIT_FOR_FB_SLEEP);
168179 return;
169180 }
170181
171182 ret = access(EARLYSUSPEND_WAIT_FOR_FB_WAKE, F_OK);
172183 if (ret < 0) {
184+ log_err("accessing %s", EARLYSUSPEND_WAIT_FOR_FB_WAKE);
173185 return;
174186 }
175187
176188 wait_for_fb_wake();
177189
178- ALOGI("Starting early suspend unblocker thread\n");
190+ ALOGI("Starting early suspend unblocker thread");
179191 ret = pthread_create(&earlysuspend_thread, NULL, earlysuspend_thread_func, NULL);
180192 if (ret) {
181- strerror_r(errno, buf, sizeof(buf));
182- ALOGE("Error creating thread: %s\n", buf);
193+ log_err("creating thread");
183194 return;
184195 }
185196
@@ -188,31 +199,18 @@ void start_earlysuspend_thread(void)
188199
189200 struct autosuspend_ops *autosuspend_earlysuspend_init(void)
190201 {
191- char buf[80];
192202 int ret;
203+ char pwr_st[128];
193204
194- sPowerStatefd = TEMP_FAILURE_RETRY(open(EARLYSUSPEND_SYS_POWER_STATE, O_RDWR));
195-
196- if (sPowerStatefd < 0) {
197- strerror_r(errno, buf, sizeof(buf));
198- ALOGW("Error opening %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
199- return NULL;
200- }
201-
202- ret = TEMP_FAILURE_RETRY(write(sPowerStatefd, "on", 2));
205+ ret = open_file(SYS_POWER_STATE, pwr_st, sizeof(pwr_st), &sPowerStatefd);
203206 if (ret < 0) {
204- strerror_r(errno, buf, sizeof(buf));
205- ALOGW("Error writing 'on' to %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
206- goto err_write;
207+ close(sPowerStatefd);
208+ return NULL;
207209 }
208210
209- ALOGI("Selected early suspend\n");
211+ ALOGI("Selected early suspend");
210212
211213 start_earlysuspend_thread();
212214
213215 return &autosuspend_earlysuspend_ops;
214-
215-err_write:
216- close(sPowerStatefd);
217- return NULL;
218216 }
--- a/libsuspend/autosuspend_ops.h
+++ b/libsuspend/autosuspend_ops.h
@@ -17,6 +17,8 @@
1717 #ifndef _LIBSUSPEND_AUTOSUSPEND_OPS_H_
1818 #define _LIBSUSPEND_AUTOSUSPEND_OPS_H_
1919
20+#define SYS_POWER_STATE "/sys/power/state"
21+
2022 struct autosuspend_ops {
2123 int (*enable)(void);
2224 int (*disable)(void);
--- a/libsuspend/autosuspend_wakeup_count.c
+++ b/libsuspend/autosuspend_wakeup_count.c
@@ -31,7 +31,6 @@
3131
3232 #include "autosuspend_ops.h"
3333
34-#define SYS_POWER_STATE "/sys/power/state"
3534 #define SYS_POWER_WAKEUP_COUNT "/sys/power/wakeup_count"
3635
3736 static int state_fd;