blob: 86610b2228ae76cc9d8434da7c2beee81727f2a6 [file] [log] [blame]
Todd Poynorfea5b4d2013-09-09 12:09:08 -07001/*
2 * Copyright (C) 2011-2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <dirent.h>
18#include <errno.h>
19#include <fcntl.h>
Colin Crosse1d52472014-05-15 17:49:06 -070020#include <inttypes.h>
Todd Poynorfea5b4d2013-09-09 12:09:08 -070021#include <linux/input.h>
22#include <stdbool.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <sys/epoll.h>
27#include <sys/stat.h>
28#include <sys/types.h>
29#include <sys/un.h>
30#include <time.h>
31#include <unistd.h>
32
33#include <sys/socket.h>
34#include <linux/netlink.h>
35
36#include <batteryservice/BatteryService.h>
37#include <cutils/android_reboot.h>
38#include <cutils/klog.h>
39#include <cutils/misc.h>
40
41#ifdef CHARGER_ENABLE_SUSPEND
42#include <suspend/autosuspend.h>
43#endif
44
45#include "minui/minui.h"
46
47#include "healthd.h"
48
Colin Cross1c38f5d2014-02-13 13:34:37 -080049char *locale;
50
Todd Poynorfea5b4d2013-09-09 12:09:08 -070051#ifndef max
52#define max(a,b) ((a) > (b) ? (a) : (b))
53#endif
54
55#ifndef min
56#define min(a,b) ((a) < (b) ? (a) : (b))
57#endif
58
59#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
60
61#define MSEC_PER_SEC (1000LL)
62#define NSEC_PER_MSEC (1000000LL)
63
64#define BATTERY_UNKNOWN_TIME (2 * MSEC_PER_SEC)
65#define POWER_ON_KEY_TIME (2 * MSEC_PER_SEC)
66#define UNPLUGGED_SHUTDOWN_TIME (10 * MSEC_PER_SEC)
67
68#define BATTERY_FULL_THRESH 95
69
70#define LAST_KMSG_PATH "/proc/last_kmsg"
Todd Poynorcd7c1042013-11-22 17:52:59 -080071#define LAST_KMSG_PSTORE_PATH "/sys/fs/pstore/console-ramoops"
Todd Poynorfea5b4d2013-09-09 12:09:08 -070072#define LAST_KMSG_MAX_SZ (32 * 1024)
73
74#define LOGE(x...) do { KLOG_ERROR("charger", x); } while (0)
75#define LOGI(x...) do { KLOG_INFO("charger", x); } while (0)
76#define LOGV(x...) do { KLOG_DEBUG("charger", x); } while (0)
77
78struct key_state {
79 bool pending;
80 bool down;
81 int64_t timestamp;
82};
83
84struct frame {
Todd Poynorfea5b4d2013-09-09 12:09:08 -070085 int disp_time;
86 int min_capacity;
87 bool level_only;
88
89 gr_surface surface;
90};
91
92struct animation {
93 bool run;
94
95 struct frame *frames;
96 int cur_frame;
97 int num_frames;
98
99 int cur_cycle;
100 int num_cycles;
101
102 /* current capacity being animated */
103 int capacity;
104};
105
106struct charger {
107 bool have_battery_state;
108 bool charger_connected;
109 int capacity;
110 int64_t next_screen_transition;
111 int64_t next_key_check;
112 int64_t next_pwr_check;
113
114 struct key_state keys[KEY_MAX + 1];
115
116 struct animation *batt_anim;
117 gr_surface surf_unknown;
118};
119
120static struct frame batt_anim_frames[] = {
121 {
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700122 .disp_time = 750,
123 .min_capacity = 0,
124 .level_only = false,
125 .surface = NULL,
126 },
127 {
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700128 .disp_time = 750,
129 .min_capacity = 20,
130 .level_only = false,
131 .surface = NULL,
132 },
133 {
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700134 .disp_time = 750,
135 .min_capacity = 40,
136 .level_only = false,
137 .surface = NULL,
138 },
139 {
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700140 .disp_time = 750,
141 .min_capacity = 60,
142 .level_only = false,
143 .surface = NULL,
144 },
145 {
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700146 .disp_time = 750,
147 .min_capacity = 80,
148 .level_only = true,
149 .surface = NULL,
150 },
151 {
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700152 .disp_time = 750,
153 .min_capacity = BATTERY_FULL_THRESH,
154 .level_only = false,
155 .surface = NULL,
156 },
157};
158
159static struct animation battery_animation = {
160 .run = false,
161 .frames = batt_anim_frames,
162 .cur_frame = 0,
163 .num_frames = ARRAY_SIZE(batt_anim_frames),
164 .cur_cycle = 0,
165 .num_cycles = 3,
166 .capacity = 0,
167};
168
169static struct charger charger_state;
170
171static int char_width;
172static int char_height;
173
174/* current time in milliseconds */
175static int64_t curr_time_ms(void)
176{
177 struct timespec tm;
178 clock_gettime(CLOCK_MONOTONIC, &tm);
179 return tm.tv_sec * MSEC_PER_SEC + (tm.tv_nsec / NSEC_PER_MSEC);
180}
181
182static void clear_screen(void)
183{
184 gr_color(0, 0, 0, 255);
Doug Zongkeree6ef152014-03-11 08:42:09 -0700185 gr_clear();
186}
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700187
188#define MAX_KLOG_WRITE_BUF_SZ 256
189
190static void dump_last_kmsg(void)
191{
192 char *buf;
193 char *ptr;
194 unsigned sz = 0;
195 int len;
196
197 LOGI("\n");
198 LOGI("*************** LAST KMSG ***************\n");
199 LOGI("\n");
Todd Poynorcd7c1042013-11-22 17:52:59 -0800200 buf = (char *)load_file(LAST_KMSG_PSTORE_PATH, &sz);
201
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700202 if (!buf || !sz) {
Todd Poynorcd7c1042013-11-22 17:52:59 -0800203 buf = (char *)load_file(LAST_KMSG_PATH, &sz);
204 if (!buf || !sz) {
205 LOGI("last_kmsg not found. Cold reset?\n");
206 goto out;
207 }
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700208 }
209
210 len = min(sz, LAST_KMSG_MAX_SZ);
211 ptr = buf + (sz - len);
212
213 while (len > 0) {
214 int cnt = min(len, MAX_KLOG_WRITE_BUF_SZ);
215 char yoink;
216 char *nl;
217
218 nl = (char *)memrchr(ptr, '\n', cnt - 1);
219 if (nl)
220 cnt = nl - ptr + 1;
221
222 yoink = ptr[cnt];
223 ptr[cnt] = '\0';
224 klog_write(6, "<6>%s", ptr);
225 ptr[cnt] = yoink;
226
227 len -= cnt;
228 ptr += cnt;
229 }
230
231 free(buf);
232
233out:
234 LOGI("\n");
235 LOGI("************* END LAST KMSG *************\n");
236 LOGI("\n");
237}
238
239static int get_battery_capacity()
240{
241 return charger_state.capacity;
242}
243
244#ifdef CHARGER_ENABLE_SUSPEND
245static int request_suspend(bool enable)
246{
247 if (enable)
248 return autosuspend_enable();
249 else
250 return autosuspend_disable();
251}
252#else
Mark Salyzyn6f5b47f2014-05-15 15:00:59 -0700253static int request_suspend(bool /*enable*/)
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700254{
255 return 0;
256}
257#endif
258
259static int draw_text(const char *str, int x, int y)
260{
261 int str_len_px = gr_measure(str);
262
263 if (x < 0)
264 x = (gr_fb_width() - str_len_px) / 2;
265 if (y < 0)
266 y = (gr_fb_height() - char_height) / 2;
267 gr_text(x, y, str, 0);
268
269 return y + char_height;
270}
271
272static void android_green(void)
273{
274 gr_color(0xa4, 0xc6, 0x39, 255);
275}
276
277/* returns the last y-offset of where the surface ends */
Mark Salyzyn6f5b47f2014-05-15 15:00:59 -0700278static int draw_surface_centered(struct charger* /*charger*/, gr_surface surface)
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700279{
280 int w;
281 int h;
282 int x;
283 int y;
284
285 w = gr_get_width(surface);
286 h = gr_get_height(surface);
287 x = (gr_fb_width() - w) / 2 ;
288 y = (gr_fb_height() - h) / 2 ;
289
290 LOGV("drawing surface %dx%d+%d+%d\n", w, h, x, y);
291 gr_blit(surface, 0, 0, w, h, x, y);
292 return y + h;
293}
294
295static void draw_unknown(struct charger *charger)
296{
297 int y;
298 if (charger->surf_unknown) {
299 draw_surface_centered(charger, charger->surf_unknown);
300 } else {
301 android_green();
302 y = draw_text("Charging!", -1, -1);
303 draw_text("?\?/100", -1, y + 25);
304 }
305}
306
307static void draw_battery(struct charger *charger)
308{
309 struct animation *batt_anim = charger->batt_anim;
310 struct frame *frame = &batt_anim->frames[batt_anim->cur_frame];
311
312 if (batt_anim->num_frames != 0) {
313 draw_surface_centered(charger, frame->surface);
Doug Zongkeree6ef152014-03-11 08:42:09 -0700314 LOGV("drawing frame #%d min_cap=%d time=%d\n",
315 batt_anim->cur_frame, frame->min_capacity,
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700316 frame->disp_time);
317 }
318}
319
320static void redraw_screen(struct charger *charger)
321{
322 struct animation *batt_anim = charger->batt_anim;
323
324 clear_screen();
325
326 /* try to display *something* */
327 if (batt_anim->capacity < 0 || batt_anim->num_frames == 0)
328 draw_unknown(charger);
329 else
330 draw_battery(charger);
331 gr_flip();
332}
333
334static void kick_animation(struct animation *anim)
335{
336 anim->run = true;
337}
338
339static void reset_animation(struct animation *anim)
340{
341 anim->cur_cycle = 0;
342 anim->cur_frame = 0;
343 anim->run = false;
344}
345
346static void update_screen_state(struct charger *charger, int64_t now)
347{
348 struct animation *batt_anim = charger->batt_anim;
349 int cur_frame;
350 int disp_time;
351
352 if (!batt_anim->run || now < charger->next_screen_transition)
353 return;
354
355 /* animation is over, blank screen and leave */
356 if (batt_anim->cur_cycle == batt_anim->num_cycles) {
357 reset_animation(batt_anim);
358 charger->next_screen_transition = -1;
359 gr_fb_blank(true);
Colin Crosse1d52472014-05-15 17:49:06 -0700360 LOGV("[%" PRId64 "] animation done\n", now);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700361 if (!charger->charger_connected)
362 request_suspend(true);
363 return;
364 }
365
366 disp_time = batt_anim->frames[batt_anim->cur_frame].disp_time;
367
368 /* animation starting, set up the animation */
369 if (batt_anim->cur_frame == 0) {
370 int batt_cap;
371 int ret;
372
Colin Crosse1d52472014-05-15 17:49:06 -0700373 LOGV("[%" PRId64 "] animation starting\n", now);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700374 batt_cap = get_battery_capacity();
375 if (batt_cap >= 0 && batt_anim->num_frames != 0) {
376 int i;
377
378 /* find first frame given current capacity */
379 for (i = 1; i < batt_anim->num_frames; i++) {
380 if (batt_cap < batt_anim->frames[i].min_capacity)
381 break;
382 }
383 batt_anim->cur_frame = i - 1;
384
385 /* show the first frame for twice as long */
386 disp_time = batt_anim->frames[batt_anim->cur_frame].disp_time * 2;
387 }
388
389 batt_anim->capacity = batt_cap;
390 }
391
392 /* unblank the screen on first cycle */
393 if (batt_anim->cur_cycle == 0)
394 gr_fb_blank(false);
395
396 /* draw the new frame (@ cur_frame) */
397 redraw_screen(charger);
398
399 /* if we don't have anim frames, we only have one image, so just bump
400 * the cycle counter and exit
401 */
402 if (batt_anim->num_frames == 0 || batt_anim->capacity < 0) {
Colin Crosse1d52472014-05-15 17:49:06 -0700403 LOGV("[%" PRId64 "] animation missing or unknown battery status\n", now);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700404 charger->next_screen_transition = now + BATTERY_UNKNOWN_TIME;
405 batt_anim->cur_cycle++;
406 return;
407 }
408
409 /* schedule next screen transition */
410 charger->next_screen_transition = now + disp_time;
411
Ruchi Kandoi9015eaa2014-06-23 11:13:15 -0700412 /* advance frame cntr to the next valid frame only if we are charging
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700413 * if necessary, advance cycle cntr, and reset frame cntr
414 */
Ruchi Kandoi9015eaa2014-06-23 11:13:15 -0700415 if (charger->charger_connected) {
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700416 batt_anim->cur_frame++;
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700417
Ruchi Kandoi9015eaa2014-06-23 11:13:15 -0700418 /* if the frame is used for level-only, that is only show it when it's
419 * the current level, skip it during the animation.
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700420 */
Ruchi Kandoi9015eaa2014-06-23 11:13:15 -0700421 while (batt_anim->cur_frame < batt_anim->num_frames &&
422 batt_anim->frames[batt_anim->cur_frame].level_only)
423 batt_anim->cur_frame++;
424 if (batt_anim->cur_frame >= batt_anim->num_frames) {
425 batt_anim->cur_cycle++;
426 batt_anim->cur_frame = 0;
427
428 /* don't reset the cycle counter, since we use that as a signal
429 * in a test above to check if animation is over
430 */
431 }
432 } else {
433 /* Stop animating if we're not charging.
434 * If we stop it immediately instead of going through this loop, then
435 * the animation would stop somewhere in the middle.
436 */
437 batt_anim->cur_frame = 0;
438 batt_anim->cur_cycle++;
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700439 }
440}
441
442static int set_key_callback(int code, int value, void *data)
443{
444 struct charger *charger = (struct charger *)data;
445 int64_t now = curr_time_ms();
446 int down = !!value;
447
448 if (code > KEY_MAX)
449 return -1;
450
451 /* ignore events that don't modify our state */
452 if (charger->keys[code].down == down)
453 return 0;
454
455 /* only record the down even timestamp, as the amount
456 * of time the key spent not being pressed is not useful */
457 if (down)
458 charger->keys[code].timestamp = now;
459 charger->keys[code].down = down;
460 charger->keys[code].pending = true;
461 if (down) {
Colin Crosse1d52472014-05-15 17:49:06 -0700462 LOGV("[%" PRId64 "] key[%d] down\n", now, code);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700463 } else {
464 int64_t duration = now - charger->keys[code].timestamp;
465 int64_t secs = duration / 1000;
466 int64_t msecs = duration - secs * 1000;
Colin Crosse1d52472014-05-15 17:49:06 -0700467 LOGV("[%" PRId64 "] key[%d] up (was down for %" PRId64 ".%" PRId64 "sec)\n",
468 now, code, secs, msecs);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700469 }
470
471 return 0;
472}
473
474static void update_input_state(struct charger *charger,
475 struct input_event *ev)
476{
477 if (ev->type != EV_KEY)
478 return;
479 set_key_callback(ev->code, ev->value, charger);
480}
481
482static void set_next_key_check(struct charger *charger,
483 struct key_state *key,
484 int64_t timeout)
485{
486 int64_t then = key->timestamp + timeout;
487
488 if (charger->next_key_check == -1 || then < charger->next_key_check)
489 charger->next_key_check = then;
490}
491
492static void process_key(struct charger *charger, int code, int64_t now)
493{
494 struct key_state *key = &charger->keys[code];
495 int64_t next_key_check;
496
497 if (code == KEY_POWER) {
498 if (key->down) {
499 int64_t reboot_timeout = key->timestamp + POWER_ON_KEY_TIME;
500 if (now >= reboot_timeout) {
Colin Crosse1d52472014-05-15 17:49:06 -0700501 LOGI("[%" PRId64 "] rebooting\n", now);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700502 android_reboot(ANDROID_RB_RESTART, 0, 0);
503 } else {
504 /* if the key is pressed but timeout hasn't expired,
505 * make sure we wake up at the right-ish time to check
506 */
507 set_next_key_check(charger, key, POWER_ON_KEY_TIME);
508 }
509 } else {
510 /* if the power key got released, force screen state cycle */
511 if (key->pending) {
512 request_suspend(false);
513 kick_animation(charger->batt_anim);
514 }
515 }
516 }
517
518 key->pending = false;
519}
520
521static void handle_input_state(struct charger *charger, int64_t now)
522{
523 process_key(charger, KEY_POWER, now);
524
525 if (charger->next_key_check != -1 && now > charger->next_key_check)
526 charger->next_key_check = -1;
527}
528
529static void handle_power_supply_state(struct charger *charger, int64_t now)
530{
531 if (!charger->have_battery_state)
532 return;
533
534 if (!charger->charger_connected) {
535 request_suspend(false);
536 if (charger->next_pwr_check == -1) {
537 charger->next_pwr_check = now + UNPLUGGED_SHUTDOWN_TIME;
Colin Crosse1d52472014-05-15 17:49:06 -0700538 LOGI("[%" PRId64 "] device unplugged: shutting down in %" PRId64 " (@ %" PRId64 ")\n",
539 now, (int64_t)UNPLUGGED_SHUTDOWN_TIME, charger->next_pwr_check);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700540 } else if (now >= charger->next_pwr_check) {
Colin Crosse1d52472014-05-15 17:49:06 -0700541 LOGI("[%" PRId64 "] shutting down\n", now);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700542 android_reboot(ANDROID_RB_POWEROFF, 0, 0);
543 } else {
544 /* otherwise we already have a shutdown timer scheduled */
545 }
546 } else {
547 /* online supply present, reset shutdown timer if set */
548 if (charger->next_pwr_check != -1) {
Colin Crosse1d52472014-05-15 17:49:06 -0700549 LOGI("[%" PRId64 "] device plugged in: shutdown cancelled\n", now);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700550 kick_animation(charger->batt_anim);
551 }
552 charger->next_pwr_check = -1;
553 }
554}
555
556void healthd_mode_charger_heartbeat()
557{
558 struct charger *charger = &charger_state;
559 int64_t now = curr_time_ms();
560 int ret;
561
562 handle_input_state(charger, now);
563 handle_power_supply_state(charger, now);
564
565 /* do screen update last in case any of the above want to start
566 * screen transitions (animations, etc)
567 */
568 update_screen_state(charger, now);
569}
570
571void healthd_mode_charger_battery_update(
572 struct android::BatteryProperties *props)
573{
574 struct charger *charger = &charger_state;
575
576 charger->charger_connected =
577 props->chargerAcOnline || props->chargerUsbOnline ||
578 props->chargerWirelessOnline;
579 charger->capacity = props->batteryLevel;
580
581 if (!charger->have_battery_state) {
582 charger->have_battery_state = true;
583 charger->next_screen_transition = curr_time_ms() - 1;
584 reset_animation(charger->batt_anim);
585 kick_animation(charger->batt_anim);
586 }
587}
588
589int healthd_mode_charger_preparetowait(void)
590{
591 struct charger *charger = &charger_state;
592 int64_t now = curr_time_ms();
593 int64_t next_event = INT64_MAX;
594 int64_t timeout;
595 struct input_event ev;
596 int ret;
597
Colin Crosse1d52472014-05-15 17:49:06 -0700598 LOGV("[%" PRId64 "] next screen: %" PRId64 " next key: %" PRId64 " next pwr: %" PRId64 "\n", now,
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700599 charger->next_screen_transition, charger->next_key_check,
600 charger->next_pwr_check);
601
602 if (charger->next_screen_transition != -1)
603 next_event = charger->next_screen_transition;
604 if (charger->next_key_check != -1 && charger->next_key_check < next_event)
605 next_event = charger->next_key_check;
606 if (charger->next_pwr_check != -1 && charger->next_pwr_check < next_event)
607 next_event = charger->next_pwr_check;
608
609 if (next_event != -1 && next_event != INT64_MAX)
610 timeout = max(0, next_event - now);
611 else
612 timeout = -1;
613
614 return (int)timeout;
615}
616
617static int input_callback(int fd, unsigned int epevents, void *data)
618{
619 struct charger *charger = (struct charger *)data;
620 struct input_event ev;
621 int ret;
622
623 ret = ev_get_input(fd, epevents, &ev);
624 if (ret)
625 return -1;
626 update_input_state(charger, &ev);
627 return 0;
628}
629
Mark Salyzyn6f5b47f2014-05-15 15:00:59 -0700630static void charger_event_handler(uint32_t /*epevents*/)
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700631{
632 int ret;
633
634 ret = ev_wait(-1);
635 if (!ret)
636 ev_dispatch();
637}
638
Mark Salyzyn6f5b47f2014-05-15 15:00:59 -0700639void healthd_mode_charger_init(struct healthd_config* /*config*/)
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700640{
641 int ret;
642 struct charger *charger = &charger_state;
643 int i;
644 int epollfd;
645
646 dump_last_kmsg();
647
648 LOGI("--------------- STARTING CHARGER MODE ---------------\n");
649
650 gr_init();
651 gr_font_size(&char_width, &char_height);
652
653 ret = ev_init(input_callback, charger);
654 if (!ret) {
655 epollfd = ev_get_epollfd();
656 healthd_register_event(epollfd, charger_event_handler);
657 }
658
Doug Zongker2f10b6b2014-03-18 00:15:27 +0000659 ret = res_create_display_surface("charger/battery_fail", &charger->surf_unknown);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700660 if (ret < 0) {
Doug Zongkeree6ef152014-03-11 08:42:09 -0700661 LOGE("Cannot load battery_fail image\n");
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700662 charger->surf_unknown = NULL;
663 }
664
665 charger->batt_anim = &battery_animation;
666
Doug Zongkeree6ef152014-03-11 08:42:09 -0700667 gr_surface* scale_frames;
668 int scale_count;
Doug Zongker2f10b6b2014-03-18 00:15:27 +0000669 ret = res_create_multi_display_surface("charger/battery_scale", &scale_count, &scale_frames);
Doug Zongkeree6ef152014-03-11 08:42:09 -0700670 if (ret < 0) {
671 LOGE("Cannot load battery_scale image\n");
672 charger->batt_anim->num_frames = 0;
673 charger->batt_anim->num_cycles = 1;
674 } else if (scale_count != charger->batt_anim->num_frames) {
675 LOGE("battery_scale image has unexpected frame count (%d, expected %d)\n",
676 scale_count, charger->batt_anim->num_frames);
677 charger->batt_anim->num_frames = 0;
678 charger->batt_anim->num_cycles = 1;
679 } else {
680 for (i = 0; i < charger->batt_anim->num_frames; i++) {
681 charger->batt_anim->frames[i].surface = scale_frames[i];
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700682 }
683 }
684
685 ev_sync_key_state(set_key_callback, charger);
686
687#ifndef CHARGER_DISABLE_INIT_BLANK
688 gr_fb_blank(true);
689#endif
690
691 charger->next_screen_transition = -1;
692 charger->next_key_check = -1;
693 charger->next_pwr_check = -1;
694}