system/core
Revisión | 322112009d7098207802eb966081c6e0cd88e34b (tree) |
---|---|
Tiempo | 2019-03-12 17:21:42 |
Autor | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
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.
@@ -46,6 +46,7 @@ | ||
46 | 46 | |
47 | 47 | static const char *default_sleep_state = "mem"; |
48 | 48 | static const char *fallback_sleep_state = "freeze"; |
49 | +static char sleep_state[PROPERTY_VALUE_MAX] = ""; | |
49 | 50 | |
50 | 51 | static int uinput_fd = -1; |
51 | 52 | static int state_fd; |
@@ -221,12 +222,8 @@ static bool sleep_state_available(const char *state) | ||
221 | 222 | |
222 | 223 | static const char *get_sleep_state() |
223 | 224 | { |
224 | - static char sleep_state[PROPERTY_VALUE_MAX] = ""; | |
225 | - | |
226 | 225 | 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)) { | |
230 | 227 | ALOGD("autosuspend using default sleep_state (%s)", default_sleep_state); |
231 | 228 | strncpy(sleep_state, default_sleep_state, PROPERTY_VALUE_MAX); |
232 | 229 | } else { |
@@ -249,7 +246,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused))) | ||
249 | 246 | update_sleep_time(success); |
250 | 247 | usleep(sleep_time); |
251 | 248 | success = false; |
252 | - ALOGV("%s: read wakeup_count\n", __func__); | |
249 | + ALOGD("%s: read wakeup_count", __func__); | |
253 | 250 | lseek(wakeup_count_fd, 0, SEEK_SET); |
254 | 251 | wakeup_count_len = TEMP_FAILURE_RETRY(read(wakeup_count_fd, wakeup_count, |
255 | 252 | sizeof(wakeup_count))); |
@@ -264,7 +261,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused))) | ||
264 | 261 | continue; |
265 | 262 | } |
266 | 263 | |
267 | - ALOGV("%s: wait\n", __func__); | |
264 | + ALOGD("%s: wait wakeup_count=%s len=%d", __func__, wakeup_count, wakeup_count_len); | |
268 | 265 | ret = sem_wait(&suspend_lockout); |
269 | 266 | if (ret < 0) { |
270 | 267 | strerror_r(errno, buf, sizeof(buf)); |
@@ -272,14 +269,14 @@ static void *suspend_thread_func(void *arg __attribute__((unused))) | ||
272 | 269 | continue; |
273 | 270 | } |
274 | 271 | |
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); | |
276 | 273 | ret = TEMP_FAILURE_RETRY(write(wakeup_count_fd, wakeup_count, wakeup_count_len)); |
277 | 274 | if (ret < 0) { |
278 | 275 | strerror_r(errno, buf, sizeof(buf)); |
279 | 276 | ALOGE("Error writing to %s: %s\n", SYS_POWER_WAKEUP_COUNT, buf); |
280 | 277 | } else { |
281 | 278 | 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); | |
283 | 280 | ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state))); |
284 | 281 | if (ret >= 0) { |
285 | 282 | success = true; |
@@ -291,7 +288,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused))) | ||
291 | 288 | } |
292 | 289 | } |
293 | 290 | |
294 | - ALOGV("%s: release sem\n", __func__); | |
291 | + ALOGD("%s: release sem", __func__); | |
295 | 292 | ret = sem_post(&suspend_lockout); |
296 | 293 | if (ret < 0) { |
297 | 294 | strerror_r(errno, buf, sizeof(buf)); |
@@ -306,7 +303,7 @@ static int autosuspend_wakeup_count_enable(void) | ||
306 | 303 | char buf[80]; |
307 | 304 | int ret; |
308 | 305 | |
309 | - ALOGV("autosuspend_wakeup_count_enable\n"); | |
306 | + ALOGD("autosuspend_wakeup_count_enable"); | |
310 | 307 | |
311 | 308 | ret = sem_post(&suspend_lockout); |
312 | 309 |
@@ -315,7 +312,7 @@ static int autosuspend_wakeup_count_enable(void) | ||
315 | 312 | ALOGE("Error changing semaphore: %s\n", buf); |
316 | 313 | } |
317 | 314 | |
318 | - ALOGV("autosuspend_wakeup_count_enable done\n"); | |
315 | + ALOGD("autosuspend_wakeup_count_enable done"); | |
319 | 316 | |
320 | 317 | return ret; |
321 | 318 | } |
@@ -325,7 +322,7 @@ static int autosuspend_wakeup_count_disable(void) | ||
325 | 322 | char buf[80]; |
326 | 323 | int ret; |
327 | 324 | |
328 | - ALOGV("autosuspend_wakeup_count_disable\n"); | |
325 | + ALOGD("autosuspend_wakeup_count_disable"); | |
329 | 326 | |
330 | 327 | ret = sem_wait(&suspend_lockout); |
331 | 328 |
@@ -334,7 +331,7 @@ static int autosuspend_wakeup_count_disable(void) | ||
334 | 331 | ALOGE("Error changing semaphore: %s\n", buf); |
335 | 332 | } |
336 | 333 | |
337 | - ALOGV("autosuspend_wakeup_count_disable done\n"); | |
334 | + ALOGD("autosuspend_wakeup_count_disable done"); | |
338 | 335 | |
339 | 336 | return ret; |
340 | 337 | } |
@@ -357,9 +354,14 @@ struct autosuspend_ops *autosuspend_wakeup_count_init(void) | ||
357 | 354 | { |
358 | 355 | int ret; |
359 | 356 | char buf[80]; |
357 | + const char *wc_path = SYS_POWER_WAKEUP_COUNT; | |
360 | 358 | |
361 | 359 | init_android_power_button(); |
362 | 360 | |
361 | + if (property_get("sleep.state", sleep_state, NULL) > 0) { | |
362 | + ALOGD("autosuspend using sleep.state property (%s)", sleep_state); | |
363 | + } | |
364 | + | |
363 | 365 | state_fd = TEMP_FAILURE_RETRY(open(SYS_POWER_STATE, O_RDWR)); |
364 | 366 | if (state_fd < 0) { |
365 | 367 | strerror_r(errno, buf, sizeof(buf)); |
@@ -367,10 +369,14 @@ struct autosuspend_ops *autosuspend_wakeup_count_init(void) | ||
367 | 369 | goto err_open_state; |
368 | 370 | } |
369 | 371 | |
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)); | |
371 | 377 | if (wakeup_count_fd < 0) { |
372 | 378 | 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); | |
374 | 380 | goto err_open_wakeup_count; |
375 | 381 | } |
376 | 382 |