Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

system-core: Commit

system/core


Commit MetaInfo

Revisión322112009d7098207802eb966081c6e0cd88e34b (tree)
Tiempo2019-03-12 17:21:42
AutorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

libsuspend: add sleep.state=force

Some devices have bad wakeup_count that prevents them from sleeping.
To workaround that, add sleep.state=force to ignore the wakeup_count
interface to put the devices into deep sleep forcibly.

Cambiar Resumen

Diferencia incremental

--- a/libsuspend/autosuspend_wakeup_count.c
+++ b/libsuspend/autosuspend_wakeup_count.c
@@ -46,6 +46,7 @@
4646
4747 static const char *default_sleep_state = "mem";
4848 static const char *fallback_sleep_state = "freeze";
49+static char sleep_state[PROPERTY_VALUE_MAX] = "";
4950
5051 static int uinput_fd = -1;
5152 static int state_fd;
@@ -221,12 +222,8 @@ static bool sleep_state_available(const char *state)
221222
222223 static const char *get_sleep_state()
223224 {
224- static char sleep_state[PROPERTY_VALUE_MAX] = "";
225-
226225 if (!sleep_state[0]) {
227- if (property_get("sleep.state", sleep_state, NULL) > 0) {
228- ALOGD("autosuspend using sleep.state property (%s)", sleep_state);
229- } else if (sleep_state_available(default_sleep_state)) {
226+ if (sleep_state_available(default_sleep_state)) {
230227 ALOGD("autosuspend using default sleep_state (%s)", default_sleep_state);
231228 strncpy(sleep_state, default_sleep_state, PROPERTY_VALUE_MAX);
232229 } else {
@@ -249,7 +246,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
249246 update_sleep_time(success);
250247 usleep(sleep_time);
251248 success = false;
252- ALOGV("%s: read wakeup_count\n", __func__);
249+ ALOGD("%s: read wakeup_count", __func__);
253250 lseek(wakeup_count_fd, 0, SEEK_SET);
254251 wakeup_count_len = TEMP_FAILURE_RETRY(read(wakeup_count_fd, wakeup_count,
255252 sizeof(wakeup_count)));
@@ -264,7 +261,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
264261 continue;
265262 }
266263
267- ALOGV("%s: wait\n", __func__);
264+ ALOGD("%s: wait wakeup_count=%s len=%d", __func__, wakeup_count, wakeup_count_len);
268265 ret = sem_wait(&suspend_lockout);
269266 if (ret < 0) {
270267 strerror_r(errno, buf, sizeof(buf));
@@ -272,14 +269,14 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
272269 continue;
273270 }
274271
275- ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count);
272+ ALOGD("%s: write %*s to wakeup_count", __func__, wakeup_count_len, wakeup_count);
276273 ret = TEMP_FAILURE_RETRY(write(wakeup_count_fd, wakeup_count, wakeup_count_len));
277274 if (ret < 0) {
278275 strerror_r(errno, buf, sizeof(buf));
279276 ALOGE("Error writing to %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf);
280277 } else {
281278 const char *sleep_state = get_sleep_state();
282- ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE);
279+ ALOGI("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE);
283280 ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state)));
284281 if (ret >= 0) {
285282 success = true;
@@ -291,7 +288,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
291288 }
292289 }
293290
294- ALOGV("%s: release sem\n", __func__);
291+ ALOGD("%s: release sem", __func__);
295292 ret = sem_post(&suspend_lockout);
296293 if (ret < 0) {
297294 strerror_r(errno, buf, sizeof(buf));
@@ -306,7 +303,7 @@ static int autosuspend_wakeup_count_enable(void)
306303 char buf[80];
307304 int ret;
308305
309- ALOGV("autosuspend_wakeup_count_enable\n");
306+ ALOGD("autosuspend_wakeup_count_enable");
310307
311308 ret = sem_post(&suspend_lockout);
312309
@@ -315,7 +312,7 @@ static int autosuspend_wakeup_count_enable(void)
315312 ALOGE("Error changing semaphore: %s\n", buf);
316313 }
317314
318- ALOGV("autosuspend_wakeup_count_enable done\n");
315+ ALOGD("autosuspend_wakeup_count_enable done");
319316
320317 return ret;
321318 }
@@ -325,7 +322,7 @@ static int autosuspend_wakeup_count_disable(void)
325322 char buf[80];
326323 int ret;
327324
328- ALOGV("autosuspend_wakeup_count_disable\n");
325+ ALOGD("autosuspend_wakeup_count_disable");
329326
330327 ret = sem_wait(&suspend_lockout);
331328
@@ -334,7 +331,7 @@ static int autosuspend_wakeup_count_disable(void)
334331 ALOGE("Error changing semaphore: %s\n", buf);
335332 }
336333
337- ALOGV("autosuspend_wakeup_count_disable done\n");
334+ ALOGD("autosuspend_wakeup_count_disable done");
338335
339336 return ret;
340337 }
@@ -357,9 +354,14 @@ struct autosuspend_ops *autosuspend_wakeup_count_init(void)
357354 {
358355 int ret;
359356 char buf[80];
357+ const char *wc_path = SYS_POWER_WAKEUP_COUNT;
360358
361359 init_android_power_button();
362360
361+ if (property_get("sleep.state", sleep_state, NULL) > 0) {
362+ ALOGD("autosuspend using sleep.state property (%s)", sleep_state);
363+ }
364+
363365 state_fd = TEMP_FAILURE_RETRY(open(SYS_POWER_STATE, O_RDWR));
364366 if (state_fd < 0) {
365367 strerror_r(errno, buf, sizeof(buf));
@@ -367,10 +369,14 @@ struct autosuspend_ops *autosuspend_wakeup_count_init(void)
367369 goto err_open_state;
368370 }
369371
370- wakeup_count_fd = TEMP_FAILURE_RETRY(open(SYS_POWER_WAKEUP_COUNT, O_RDWR));
372+ if (!strcmp(sleep_state, "force")) {
373+ wc_path = "/dev/zero";
374+ sleep_state[0] = '\0';
375+ }
376+ wakeup_count_fd = TEMP_FAILURE_RETRY(open(wc_path, O_RDWR));
371377 if (wakeup_count_fd < 0) {
372378 strerror_r(errno, buf, sizeof(buf));
373- ALOGE("Error opening %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf);
379+ ALOGE("Error opening %s: %s", wc_path, buf);
374380 goto err_open_wakeup_count;
375381 }
376382
Show on old repository browser