blob: d11f609314a84daf5b7ba2b966f252c24b9ce2ad [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>
Riley Andrews6bd45882014-06-23 15:20:51 -070040#include <cutils/uevent.h>
41#include <cutils/properties.h>
Todd Poynorfea5b4d2013-09-09 12:09:08 -070042
43#ifdef CHARGER_ENABLE_SUSPEND
44#include <suspend/autosuspend.h>
45#endif
46
47#include "minui/minui.h"
48
49#include "healthd.h"
50
Colin Cross1c38f5d2014-02-13 13:34:37 -080051char *locale;
52
Todd Poynorfea5b4d2013-09-09 12:09:08 -070053#ifndef max
54#define max(a,b) ((a) > (b) ? (a) : (b))
55#endif
56
57#ifndef min
58#define min(a,b) ((a) < (b) ? (a) : (b))
59#endif
60
61#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
62
63#define MSEC_PER_SEC (1000LL)
64#define NSEC_PER_MSEC (1000000LL)
65
66#define BATTERY_UNKNOWN_TIME (2 * MSEC_PER_SEC)
67#define POWER_ON_KEY_TIME (2 * MSEC_PER_SEC)
68#define UNPLUGGED_SHUTDOWN_TIME (10 * MSEC_PER_SEC)
69
70#define BATTERY_FULL_THRESH 95
71
72#define LAST_KMSG_PATH "/proc/last_kmsg"
Todd Poynorcd7c1042013-11-22 17:52:59 -080073#define LAST_KMSG_PSTORE_PATH "/sys/fs/pstore/console-ramoops"
Todd Poynorfea5b4d2013-09-09 12:09:08 -070074#define LAST_KMSG_MAX_SZ (32 * 1024)
75
76#define LOGE(x...) do { KLOG_ERROR("charger", x); } while (0)
77#define LOGI(x...) do { KLOG_INFO("charger", x); } while (0)
78#define LOGV(x...) do { KLOG_DEBUG("charger", x); } while (0)
79
80struct key_state {
81 bool pending;
82 bool down;
83 int64_t timestamp;
84};
85
86struct frame {
Todd Poynorfea5b4d2013-09-09 12:09:08 -070087 int disp_time;
88 int min_capacity;
89 bool level_only;
90
91 gr_surface surface;
92};
93
94struct animation {
95 bool run;
96
97 struct frame *frames;
98 int cur_frame;
99 int num_frames;
100
101 int cur_cycle;
102 int num_cycles;
103
104 /* current capacity being animated */
105 int capacity;
106};
107
108struct charger {
109 bool have_battery_state;
110 bool charger_connected;
111 int capacity;
112 int64_t next_screen_transition;
113 int64_t next_key_check;
114 int64_t next_pwr_check;
115
116 struct key_state keys[KEY_MAX + 1];
117
118 struct animation *batt_anim;
119 gr_surface surf_unknown;
120};
121
122static struct frame batt_anim_frames[] = {
123 {
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700124 .disp_time = 750,
125 .min_capacity = 0,
126 .level_only = false,
127 .surface = NULL,
128 },
129 {
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700130 .disp_time = 750,
131 .min_capacity = 20,
132 .level_only = false,
133 .surface = NULL,
134 },
135 {
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700136 .disp_time = 750,
137 .min_capacity = 40,
138 .level_only = false,
139 .surface = NULL,
140 },
141 {
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700142 .disp_time = 750,
143 .min_capacity = 60,
144 .level_only = false,
145 .surface = NULL,
146 },
147 {
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700148 .disp_time = 750,
149 .min_capacity = 80,
150 .level_only = true,
151 .surface = NULL,
152 },
153 {
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700154 .disp_time = 750,
155 .min_capacity = BATTERY_FULL_THRESH,
156 .level_only = false,
157 .surface = NULL,
158 },
159};
160
161static struct animation battery_animation = {
162 .run = false,
163 .frames = batt_anim_frames,
164 .cur_frame = 0,
165 .num_frames = ARRAY_SIZE(batt_anim_frames),
166 .cur_cycle = 0,
167 .num_cycles = 3,
168 .capacity = 0,
169};
170
171static struct charger charger_state;
172
173static int char_width;
174static int char_height;
175
176/* current time in milliseconds */
177static int64_t curr_time_ms(void)
178{
179 struct timespec tm;
180 clock_gettime(CLOCK_MONOTONIC, &tm);
181 return tm.tv_sec * MSEC_PER_SEC + (tm.tv_nsec / NSEC_PER_MSEC);
182}
183
184static void clear_screen(void)
185{
186 gr_color(0, 0, 0, 255);
Doug Zongkeree6ef152014-03-11 08:42:09 -0700187 gr_clear();
188}
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700189
190#define MAX_KLOG_WRITE_BUF_SZ 256
191
192static void dump_last_kmsg(void)
193{
194 char *buf;
195 char *ptr;
196 unsigned sz = 0;
197 int len;
198
199 LOGI("\n");
200 LOGI("*************** LAST KMSG ***************\n");
201 LOGI("\n");
Todd Poynorcd7c1042013-11-22 17:52:59 -0800202 buf = (char *)load_file(LAST_KMSG_PSTORE_PATH, &sz);
203
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700204 if (!buf || !sz) {
Todd Poynorcd7c1042013-11-22 17:52:59 -0800205 buf = (char *)load_file(LAST_KMSG_PATH, &sz);
206 if (!buf || !sz) {
207 LOGI("last_kmsg not found. Cold reset?\n");
208 goto out;
209 }
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700210 }
211
212 len = min(sz, LAST_KMSG_MAX_SZ);
213 ptr = buf + (sz - len);
214
215 while (len > 0) {
216 int cnt = min(len, MAX_KLOG_WRITE_BUF_SZ);
217 char yoink;
218 char *nl;
219
220 nl = (char *)memrchr(ptr, '\n', cnt - 1);
221 if (nl)
222 cnt = nl - ptr + 1;
223
224 yoink = ptr[cnt];
225 ptr[cnt] = '\0';
226 klog_write(6, "<6>%s", ptr);
227 ptr[cnt] = yoink;
228
229 len -= cnt;
230 ptr += cnt;
231 }
232
233 free(buf);
234
235out:
236 LOGI("\n");
237 LOGI("************* END LAST KMSG *************\n");
238 LOGI("\n");
239}
240
241static int get_battery_capacity()
242{
243 return charger_state.capacity;
244}
245
246#ifdef CHARGER_ENABLE_SUSPEND
247static int request_suspend(bool enable)
248{
249 if (enable)
250 return autosuspend_enable();
251 else
252 return autosuspend_disable();
253}
254#else
Mark Salyzyn6f5b47f2014-05-15 15:00:59 -0700255static int request_suspend(bool /*enable*/)
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700256{
257 return 0;
258}
259#endif
260
261static int draw_text(const char *str, int x, int y)
262{
263 int str_len_px = gr_measure(str);
264
265 if (x < 0)
266 x = (gr_fb_width() - str_len_px) / 2;
267 if (y < 0)
268 y = (gr_fb_height() - char_height) / 2;
269 gr_text(x, y, str, 0);
270
271 return y + char_height;
272}
273
274static void android_green(void)
275{
276 gr_color(0xa4, 0xc6, 0x39, 255);
277}
278
279/* returns the last y-offset of where the surface ends */
Mark Salyzyn6f5b47f2014-05-15 15:00:59 -0700280static int draw_surface_centered(struct charger* /*charger*/, gr_surface surface)
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700281{
282 int w;
283 int h;
284 int x;
285 int y;
286
287 w = gr_get_width(surface);
288 h = gr_get_height(surface);
289 x = (gr_fb_width() - w) / 2 ;
290 y = (gr_fb_height() - h) / 2 ;
291
292 LOGV("drawing surface %dx%d+%d+%d\n", w, h, x, y);
293 gr_blit(surface, 0, 0, w, h, x, y);
294 return y + h;
295}
296
297static void draw_unknown(struct charger *charger)
298{
299 int y;
300 if (charger->surf_unknown) {
301 draw_surface_centered(charger, charger->surf_unknown);
302 } else {
303 android_green();
304 y = draw_text("Charging!", -1, -1);
305 draw_text("?\?/100", -1, y + 25);
306 }
307}
308
309static void draw_battery(struct charger *charger)
310{
311 struct animation *batt_anim = charger->batt_anim;
312 struct frame *frame = &batt_anim->frames[batt_anim->cur_frame];
313
314 if (batt_anim->num_frames != 0) {
315 draw_surface_centered(charger, frame->surface);
Doug Zongkeree6ef152014-03-11 08:42:09 -0700316 LOGV("drawing frame #%d min_cap=%d time=%d\n",
317 batt_anim->cur_frame, frame->min_capacity,
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700318 frame->disp_time);
319 }
320}
321
322static void redraw_screen(struct charger *charger)
323{
324 struct animation *batt_anim = charger->batt_anim;
325
326 clear_screen();
327
328 /* try to display *something* */
329 if (batt_anim->capacity < 0 || batt_anim->num_frames == 0)
330 draw_unknown(charger);
331 else
332 draw_battery(charger);
333 gr_flip();
334}
335
336static void kick_animation(struct animation *anim)
337{
338 anim->run = true;
339}
340
341static void reset_animation(struct animation *anim)
342{
343 anim->cur_cycle = 0;
344 anim->cur_frame = 0;
345 anim->run = false;
346}
347
348static void update_screen_state(struct charger *charger, int64_t now)
349{
350 struct animation *batt_anim = charger->batt_anim;
351 int cur_frame;
352 int disp_time;
353
354 if (!batt_anim->run || now < charger->next_screen_transition)
355 return;
356
357 /* animation is over, blank screen and leave */
358 if (batt_anim->cur_cycle == batt_anim->num_cycles) {
359 reset_animation(batt_anim);
360 charger->next_screen_transition = -1;
361 gr_fb_blank(true);
Colin Crosse1d52472014-05-15 17:49:06 -0700362 LOGV("[%" PRId64 "] animation done\n", now);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700363 if (!charger->charger_connected)
364 request_suspend(true);
365 return;
366 }
367
368 disp_time = batt_anim->frames[batt_anim->cur_frame].disp_time;
369
370 /* animation starting, set up the animation */
371 if (batt_anim->cur_frame == 0) {
372 int batt_cap;
373 int ret;
374
Colin Crosse1d52472014-05-15 17:49:06 -0700375 LOGV("[%" PRId64 "] animation starting\n", now);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700376 batt_cap = get_battery_capacity();
377 if (batt_cap >= 0 && batt_anim->num_frames != 0) {
378 int i;
379
380 /* find first frame given current capacity */
381 for (i = 1; i < batt_anim->num_frames; i++) {
382 if (batt_cap < batt_anim->frames[i].min_capacity)
383 break;
384 }
385 batt_anim->cur_frame = i - 1;
386
387 /* show the first frame for twice as long */
388 disp_time = batt_anim->frames[batt_anim->cur_frame].disp_time * 2;
389 }
390
391 batt_anim->capacity = batt_cap;
392 }
393
394 /* unblank the screen on first cycle */
395 if (batt_anim->cur_cycle == 0)
396 gr_fb_blank(false);
397
398 /* draw the new frame (@ cur_frame) */
399 redraw_screen(charger);
400
401 /* if we don't have anim frames, we only have one image, so just bump
402 * the cycle counter and exit
403 */
404 if (batt_anim->num_frames == 0 || batt_anim->capacity < 0) {
Colin Crosse1d52472014-05-15 17:49:06 -0700405 LOGV("[%" PRId64 "] animation missing or unknown battery status\n", now);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700406 charger->next_screen_transition = now + BATTERY_UNKNOWN_TIME;
407 batt_anim->cur_cycle++;
408 return;
409 }
410
411 /* schedule next screen transition */
412 charger->next_screen_transition = now + disp_time;
413
Ruchi Kandoi9015eaa2014-06-23 11:13:15 -0700414 /* advance frame cntr to the next valid frame only if we are charging
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700415 * if necessary, advance cycle cntr, and reset frame cntr
416 */
Ruchi Kandoi9015eaa2014-06-23 11:13:15 -0700417 if (charger->charger_connected) {
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700418 batt_anim->cur_frame++;
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700419
Ruchi Kandoi9015eaa2014-06-23 11:13:15 -0700420 /* if the frame is used for level-only, that is only show it when it's
421 * the current level, skip it during the animation.
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700422 */
Ruchi Kandoi9015eaa2014-06-23 11:13:15 -0700423 while (batt_anim->cur_frame < batt_anim->num_frames &&
424 batt_anim->frames[batt_anim->cur_frame].level_only)
425 batt_anim->cur_frame++;
426 if (batt_anim->cur_frame >= batt_anim->num_frames) {
427 batt_anim->cur_cycle++;
428 batt_anim->cur_frame = 0;
429
430 /* don't reset the cycle counter, since we use that as a signal
431 * in a test above to check if animation is over
432 */
433 }
434 } else {
435 /* Stop animating if we're not charging.
436 * If we stop it immediately instead of going through this loop, then
437 * the animation would stop somewhere in the middle.
438 */
439 batt_anim->cur_frame = 0;
440 batt_anim->cur_cycle++;
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700441 }
442}
443
444static int set_key_callback(int code, int value, void *data)
445{
446 struct charger *charger = (struct charger *)data;
447 int64_t now = curr_time_ms();
448 int down = !!value;
449
450 if (code > KEY_MAX)
451 return -1;
452
453 /* ignore events that don't modify our state */
454 if (charger->keys[code].down == down)
455 return 0;
456
457 /* only record the down even timestamp, as the amount
458 * of time the key spent not being pressed is not useful */
459 if (down)
460 charger->keys[code].timestamp = now;
461 charger->keys[code].down = down;
462 charger->keys[code].pending = true;
463 if (down) {
Colin Crosse1d52472014-05-15 17:49:06 -0700464 LOGV("[%" PRId64 "] key[%d] down\n", now, code);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700465 } else {
466 int64_t duration = now - charger->keys[code].timestamp;
467 int64_t secs = duration / 1000;
468 int64_t msecs = duration - secs * 1000;
Colin Crosse1d52472014-05-15 17:49:06 -0700469 LOGV("[%" PRId64 "] key[%d] up (was down for %" PRId64 ".%" PRId64 "sec)\n",
470 now, code, secs, msecs);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700471 }
472
473 return 0;
474}
475
476static void update_input_state(struct charger *charger,
477 struct input_event *ev)
478{
479 if (ev->type != EV_KEY)
480 return;
481 set_key_callback(ev->code, ev->value, charger);
482}
483
484static void set_next_key_check(struct charger *charger,
485 struct key_state *key,
486 int64_t timeout)
487{
488 int64_t then = key->timestamp + timeout;
489
490 if (charger->next_key_check == -1 || then < charger->next_key_check)
491 charger->next_key_check = then;
492}
493
494static void process_key(struct charger *charger, int code, int64_t now)
495{
496 struct key_state *key = &charger->keys[code];
497 int64_t next_key_check;
498
499 if (code == KEY_POWER) {
500 if (key->down) {
501 int64_t reboot_timeout = key->timestamp + POWER_ON_KEY_TIME;
502 if (now >= reboot_timeout) {
Riley Andrews6bd45882014-06-23 15:20:51 -0700503 /* We do not currently support booting from charger mode on
504 all devices. Check the property and continue booting or reboot
505 accordingly. */
506 if (property_get_bool("ro.enable_boot_charger_mode", false)) {
507 LOGI("[%" PRId64 "] booting from charger mode\n", now);
508 property_set("sys.boot_from_charger_mode", "1");
509 } else {
510 LOGI("[%" PRId64 "] rebooting\n", now);
511 android_reboot(ANDROID_RB_RESTART, 0, 0);
512 }
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700513 } else {
514 /* if the key is pressed but timeout hasn't expired,
515 * make sure we wake up at the right-ish time to check
516 */
517 set_next_key_check(charger, key, POWER_ON_KEY_TIME);
518 }
519 } else {
520 /* if the power key got released, force screen state cycle */
521 if (key->pending) {
522 request_suspend(false);
523 kick_animation(charger->batt_anim);
524 }
525 }
526 }
527
528 key->pending = false;
529}
530
531static void handle_input_state(struct charger *charger, int64_t now)
532{
533 process_key(charger, KEY_POWER, now);
534
535 if (charger->next_key_check != -1 && now > charger->next_key_check)
536 charger->next_key_check = -1;
537}
538
539static void handle_power_supply_state(struct charger *charger, int64_t now)
540{
541 if (!charger->have_battery_state)
542 return;
543
544 if (!charger->charger_connected) {
545 request_suspend(false);
546 if (charger->next_pwr_check == -1) {
547 charger->next_pwr_check = now + UNPLUGGED_SHUTDOWN_TIME;
Colin Crosse1d52472014-05-15 17:49:06 -0700548 LOGI("[%" PRId64 "] device unplugged: shutting down in %" PRId64 " (@ %" PRId64 ")\n",
549 now, (int64_t)UNPLUGGED_SHUTDOWN_TIME, charger->next_pwr_check);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700550 } else if (now >= charger->next_pwr_check) {
Colin Crosse1d52472014-05-15 17:49:06 -0700551 LOGI("[%" PRId64 "] shutting down\n", now);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700552 android_reboot(ANDROID_RB_POWEROFF, 0, 0);
553 } else {
554 /* otherwise we already have a shutdown timer scheduled */
555 }
556 } else {
557 /* online supply present, reset shutdown timer if set */
558 if (charger->next_pwr_check != -1) {
Colin Crosse1d52472014-05-15 17:49:06 -0700559 LOGI("[%" PRId64 "] device plugged in: shutdown cancelled\n", now);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700560 kick_animation(charger->batt_anim);
561 }
562 charger->next_pwr_check = -1;
563 }
564}
565
566void healthd_mode_charger_heartbeat()
567{
568 struct charger *charger = &charger_state;
569 int64_t now = curr_time_ms();
570 int ret;
571
572 handle_input_state(charger, now);
573 handle_power_supply_state(charger, now);
574
575 /* do screen update last in case any of the above want to start
576 * screen transitions (animations, etc)
577 */
578 update_screen_state(charger, now);
579}
580
581void healthd_mode_charger_battery_update(
582 struct android::BatteryProperties *props)
583{
584 struct charger *charger = &charger_state;
585
586 charger->charger_connected =
587 props->chargerAcOnline || props->chargerUsbOnline ||
588 props->chargerWirelessOnline;
589 charger->capacity = props->batteryLevel;
590
591 if (!charger->have_battery_state) {
592 charger->have_battery_state = true;
593 charger->next_screen_transition = curr_time_ms() - 1;
594 reset_animation(charger->batt_anim);
595 kick_animation(charger->batt_anim);
596 }
597}
598
599int healthd_mode_charger_preparetowait(void)
600{
601 struct charger *charger = &charger_state;
602 int64_t now = curr_time_ms();
603 int64_t next_event = INT64_MAX;
604 int64_t timeout;
605 struct input_event ev;
606 int ret;
607
Colin Crosse1d52472014-05-15 17:49:06 -0700608 LOGV("[%" PRId64 "] next screen: %" PRId64 " next key: %" PRId64 " next pwr: %" PRId64 "\n", now,
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700609 charger->next_screen_transition, charger->next_key_check,
610 charger->next_pwr_check);
611
612 if (charger->next_screen_transition != -1)
613 next_event = charger->next_screen_transition;
614 if (charger->next_key_check != -1 && charger->next_key_check < next_event)
615 next_event = charger->next_key_check;
616 if (charger->next_pwr_check != -1 && charger->next_pwr_check < next_event)
617 next_event = charger->next_pwr_check;
618
619 if (next_event != -1 && next_event != INT64_MAX)
620 timeout = max(0, next_event - now);
621 else
622 timeout = -1;
623
624 return (int)timeout;
625}
626
627static int input_callback(int fd, unsigned int epevents, void *data)
628{
629 struct charger *charger = (struct charger *)data;
630 struct input_event ev;
631 int ret;
632
633 ret = ev_get_input(fd, epevents, &ev);
634 if (ret)
635 return -1;
636 update_input_state(charger, &ev);
637 return 0;
638}
639
Mark Salyzyn6f5b47f2014-05-15 15:00:59 -0700640static void charger_event_handler(uint32_t /*epevents*/)
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700641{
642 int ret;
643
644 ret = ev_wait(-1);
645 if (!ret)
646 ev_dispatch();
647}
648
Mark Salyzyn6f5b47f2014-05-15 15:00:59 -0700649void healthd_mode_charger_init(struct healthd_config* /*config*/)
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700650{
651 int ret;
652 struct charger *charger = &charger_state;
653 int i;
654 int epollfd;
655
656 dump_last_kmsg();
657
658 LOGI("--------------- STARTING CHARGER MODE ---------------\n");
659
660 gr_init();
661 gr_font_size(&char_width, &char_height);
662
663 ret = ev_init(input_callback, charger);
664 if (!ret) {
665 epollfd = ev_get_epollfd();
666 healthd_register_event(epollfd, charger_event_handler);
667 }
668
Doug Zongker2f10b6b2014-03-18 00:15:27 +0000669 ret = res_create_display_surface("charger/battery_fail", &charger->surf_unknown);
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700670 if (ret < 0) {
Doug Zongkeree6ef152014-03-11 08:42:09 -0700671 LOGE("Cannot load battery_fail image\n");
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700672 charger->surf_unknown = NULL;
673 }
674
675 charger->batt_anim = &battery_animation;
676
Doug Zongkeree6ef152014-03-11 08:42:09 -0700677 gr_surface* scale_frames;
678 int scale_count;
Doug Zongker2f10b6b2014-03-18 00:15:27 +0000679 ret = res_create_multi_display_surface("charger/battery_scale", &scale_count, &scale_frames);
Doug Zongkeree6ef152014-03-11 08:42:09 -0700680 if (ret < 0) {
681 LOGE("Cannot load battery_scale image\n");
682 charger->batt_anim->num_frames = 0;
683 charger->batt_anim->num_cycles = 1;
684 } else if (scale_count != charger->batt_anim->num_frames) {
685 LOGE("battery_scale image has unexpected frame count (%d, expected %d)\n",
686 scale_count, charger->batt_anim->num_frames);
687 charger->batt_anim->num_frames = 0;
688 charger->batt_anim->num_cycles = 1;
689 } else {
690 for (i = 0; i < charger->batt_anim->num_frames; i++) {
691 charger->batt_anim->frames[i].surface = scale_frames[i];
Todd Poynorfea5b4d2013-09-09 12:09:08 -0700692 }
693 }
694
695 ev_sync_key_state(set_key_callback, charger);
696
697#ifndef CHARGER_DISABLE_INIT_BLANK
698 gr_fb_blank(true);
699#endif
700
701 charger->next_screen_transition = -1;
702 charger->next_key_check = -1;
703 charger->next_pwr_check = -1;
704}