Android-x86
Fork

  • R/O
  • HTTP
  • SSH
  • HTTPS

system-core: コミット

system/core


コミットメタ情報

リビジョン58340edf3a55c11ba0145ad10a8cb06ddf9bf8df (tree)
日時2015-12-22 12:24:42
作者Chih-Wei Huang <cwhuang@linu...>
コミッターChih-Wei Huang

ログメッセージ

libsuspend: enable earlysuspend for android-x86

変更サマリ

差分

--- a/libsuspend/autosuspend_earlysuspend.c
+++ b/libsuspend/autosuspend_earlysuspend.c
@@ -34,6 +34,7 @@
3434 #define EARLYSUSPEND_WAIT_FOR_FB_WAKE "/sys/power/wait_for_fb_wake"
3535
3636 static int sPowerStatefd;
37+static char pwr_states[128];
3738 static const char *pwr_state_mem = "mem";
3839 static const char *pwr_state_on = "on";
3940 static pthread_t earlysuspend_thread;
@@ -45,41 +46,56 @@ static enum {
4546 EARLYSUSPEND_MEM,
4647 } earlysuspend_state = EARLYSUSPEND_ON;
4748
48-int wait_for_fb_wake(void)
49+static void log_err(const char *fmt, ...)
4950 {
50- int err = 0;
51- char buf;
52- int fd = open(EARLYSUSPEND_WAIT_FOR_FB_WAKE, O_RDONLY, 0);
51+ char err[80];
52+ char buf[512];
53+
54+ strerror_r(errno, err, sizeof(err));
55+
56+ va_list ap;
57+ va_start(ap, fmt);
58+ vsnprintf(buf, sizeof(buf), fmt, ap);
59+ va_end(ap);
60+ ALOGE("Error %s: %s", buf, err);
61+}
62+
63+static int open_file(const char *file, char *buf, size_t sz)
64+{
65+ int err;
66+ int fd = open(file, O_RDONLY, 0);
5367 // if the file doesn't exist, the error will be caught in read() below
5468 do {
55- err = read(fd, &buf, 1);
69+ err = read(fd, buf, sz);
5670 } while (err < 0 && errno == EINTR);
57- ALOGE_IF(err < 0,
58- "*** ANDROID_WAIT_FOR_FB_WAKE failed (%s)", strerror(errno));
71+
72+ if (err < 0) {
73+ log_err("opening %s", file);
74+ } else {
75+ err = 0;
76+ }
77+
5978 close(fd);
60- return err < 0 ? err : 0;
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);
6186 }
6287
6388 static int wait_for_fb_sleep(void)
6489 {
65- int err = 0;
6690 char buf;
67- int fd = open(EARLYSUSPEND_WAIT_FOR_FB_SLEEP, O_RDONLY, 0);
68- // if the file doesn't exist, the error will be caught in read() below
69- do {
70- err = read(fd, &buf, 1);
71- } while (err < 0 && errno == EINTR);
72- ALOGE_IF(err < 0,
73- "*** ANDROID_WAIT_FOR_FB_SLEEP failed (%s)", strerror(errno));
74- close(fd);
75- return err < 0 ? err : 0;
91+ return open_file(EARLYSUSPEND_WAIT_FOR_FB_SLEEP, &buf, 1);
7692 }
7793
7894 static void *earlysuspend_thread_func(void __unused *arg)
7995 {
8096 while (1) {
8197 if (wait_for_fb_sleep()) {
82- ALOGE("Failed reading wait_for_fb_sleep, exiting earlysuspend thread\n");
98+ ALOGE("Failed reading wait_for_fb_sleep, exiting earlysuspend thread");
8399 return NULL;
84100 }
85101 pthread_mutex_lock(&earlysuspend_mutex);
@@ -88,7 +104,7 @@ static void *earlysuspend_thread_func(void __unused *arg)
88104 pthread_mutex_unlock(&earlysuspend_mutex);
89105
90106 if (wait_for_fb_wake()) {
91- ALOGE("Failed reading wait_for_fb_wake, exiting earlysuspend thread\n");
107+ ALOGE("Failed reading wait_for_fb_wake, exiting earlysuspend thread");
92108 return NULL;
93109 }
94110 pthread_mutex_lock(&earlysuspend_mutex);
@@ -99,16 +115,15 @@ static void *earlysuspend_thread_func(void __unused *arg)
99115 }
100116 static int autosuspend_earlysuspend_enable(void)
101117 {
102- char buf[80];
103118 int ret;
104119
105- ALOGV("autosuspend_earlysuspend_enable\n");
120+ ALOGI("autosuspend_earlysuspend_enable");
106121
107- ret = write(sPowerStatefd, pwr_state_mem, strlen(pwr_state_mem));
122+ int fd = open(EARLYSUSPEND_SYS_POWER_STATE, O_RDWR);
123+ ret = write(fd, pwr_state_mem, strlen(pwr_state_mem));
108124 if (ret < 0) {
109- strerror_r(errno, buf, sizeof(buf));
110- ALOGE("Error writing to %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
111- goto err;
125+ log_err("writing %s to %s", pwr_state_mem, EARLYSUSPEND_SYS_POWER_STATE);
126+ return ret;
112127 }
113128
114129 if (wait_for_earlysuspend) {
@@ -119,12 +134,9 @@ static int autosuspend_earlysuspend_enable(void)
119134 pthread_mutex_unlock(&earlysuspend_mutex);
120135 }
121136
122- ALOGV("autosuspend_earlysuspend_enable done\n");
137+ ALOGD("autosuspend_earlysuspend_enable done");
123138
124139 return 0;
125-
126-err:
127- return ret;
128140 }
129141
130142 static int autosuspend_earlysuspend_disable(void)
@@ -132,13 +144,12 @@ static int autosuspend_earlysuspend_disable(void)
132144 char buf[80];
133145 int ret;
134146
135- ALOGV("autosuspend_earlysuspend_disable\n");
147+ ALOGI("autosuspend_earlysuspend_disable");
136148
137149 ret = write(sPowerStatefd, pwr_state_on, strlen(pwr_state_on));
138150 if (ret < 0) {
139151 strerror_r(errno, buf, sizeof(buf));
140- ALOGE("Error writing to %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
141- goto err;
152+ ALOGE("Error writing %s to %s: %s\n", pwr_state_on, EARLYSUSPEND_SYS_POWER_STATE, buf);
142153 }
143154
144155 if (wait_for_earlysuspend) {
@@ -149,12 +160,9 @@ static int autosuspend_earlysuspend_disable(void)
149160 pthread_mutex_unlock(&earlysuspend_mutex);
150161 }
151162
152- ALOGV("autosuspend_earlysuspend_disable done\n");
163+ ALOGD("autosuspend_earlysuspend_disable done");
153164
154165 return 0;
155-
156-err:
157- return ret;
158166 }
159167
160168 struct autosuspend_ops autosuspend_earlysuspend_ops = {
@@ -164,26 +172,26 @@ struct autosuspend_ops autosuspend_earlysuspend_ops = {
164172
165173 void start_earlysuspend_thread(void)
166174 {
167- char buf[80];
168175 int ret;
169176
170177 ret = access(EARLYSUSPEND_WAIT_FOR_FB_SLEEP, F_OK);
171178 if (ret < 0) {
179+ log_err("accessing %s", EARLYSUSPEND_WAIT_FOR_FB_SLEEP);
172180 return;
173181 }
174182
175183 ret = access(EARLYSUSPEND_WAIT_FOR_FB_WAKE, F_OK);
176184 if (ret < 0) {
185+ log_err("accessing %s", EARLYSUSPEND_WAIT_FOR_FB_WAKE);
177186 return;
178187 }
179188
180189 wait_for_fb_wake();
181190
182- ALOGI("Starting early suspend unblocker thread\n");
191+ ALOGI("Starting early suspend unblocker thread");
183192 ret = pthread_create(&earlysuspend_thread, NULL, earlysuspend_thread_func, NULL);
184193 if (ret) {
185- strerror_r(errno, buf, sizeof(buf));
186- ALOGE("Error creating thread: %s\n", buf);
194+ log_err("creating thread");
187195 return;
188196 }
189197
@@ -192,31 +200,16 @@ void start_earlysuspend_thread(void)
192200
193201 struct autosuspend_ops *autosuspend_earlysuspend_init(void)
194202 {
195- char buf[80];
196203 int ret;
197204
198- sPowerStatefd = open(EARLYSUSPEND_SYS_POWER_STATE, O_RDWR);
199-
200- if (sPowerStatefd < 0) {
201- strerror_r(errno, buf, sizeof(buf));
202- ALOGW("Error opening %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
203- return NULL;
204- }
205-
206- ret = write(sPowerStatefd, "on", 2);
205+ ret = open_file(EARLYSUSPEND_SYS_POWER_STATE, pwr_states, sizeof(pwr_states));
207206 if (ret < 0) {
208- strerror_r(errno, buf, sizeof(buf));
209- ALOGW("Error writing 'on' to %s: %s\n", EARLYSUSPEND_SYS_POWER_STATE, buf);
210- goto err_write;
207+ return NULL;
211208 }
212209
213- ALOGI("Selected early suspend\n");
210+ ALOGI("Selected early suspend");
214211
215212 start_earlysuspend_thread();
216213
217214 return &autosuspend_earlysuspend_ops;
218-
219-err_write:
220- close(sPowerStatefd);
221- return NULL;
222215 }
--- a/libsuspend/autosuspend_wakeup_count.c
+++ b/libsuspend/autosuspend_wakeup_count.c
@@ -71,13 +71,13 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
7171 continue;
7272 }
7373
74- ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count);
74+ ALOGD("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count);
7575 ret = write(wakeup_count_fd, wakeup_count, wakeup_count_len);
7676 if (ret < 0) {
7777 strerror_r(errno, buf, sizeof(buf));
7878 ALOGE("Error writing to %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf);
7979 } else {
80- ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE);
80+ ALOGD("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE);
8181 ret = write(state_fd, sleep_state, strlen(sleep_state));
8282 if (ret < 0) {
8383 strerror_r(errno, buf, sizeof(buf));
@@ -105,7 +105,7 @@ static int autosuspend_wakeup_count_enable(void)
105105 char buf[80];
106106 int ret;
107107
108- ALOGV("autosuspend_wakeup_count_enable\n");
108+ ALOGD("autosuspend_wakeup_count_enable");
109109
110110 ret = sem_post(&suspend_lockout);
111111
@@ -114,7 +114,7 @@ static int autosuspend_wakeup_count_enable(void)
114114 ALOGE("Error changing semaphore: %s\n", buf);
115115 }
116116
117- ALOGV("autosuspend_wakeup_count_enable done\n");
117+ ALOGD("autosuspend_wakeup_count_enable done");
118118
119119 return ret;
120120 }
@@ -124,7 +124,7 @@ static int autosuspend_wakeup_count_disable(void)
124124 char buf[80];
125125 int ret;
126126
127- ALOGV("autosuspend_wakeup_count_disable\n");
127+ ALOGD("autosuspend_wakeup_count_disable");
128128
129129 ret = sem_wait(&suspend_lockout);
130130
@@ -133,7 +133,7 @@ static int autosuspend_wakeup_count_disable(void)
133133 ALOGE("Error changing semaphore: %s\n", buf);
134134 }
135135
136- ALOGV("autosuspend_wakeup_count_disable done\n");
136+ ALOGD("autosuspend_wakeup_count_disable done");
137137
138138 return ret;
139139 }
旧リポジトリブラウザで表示