Android Q关机显示充电百分比
-
文件修改路径
-
android/system/core/healthd/animation.h
-
android/system/core/healthd/healthd_draw.cpp
-
android/system/core/healthd/healthd_draw.h
-
android/system/core/healthd/healthd_mode_charger.cpp
---
healthd/animation.h | 1 +
healthd/healthd_draw.cpp | 55 +++++++++++++--
healthd/healthd_draw.h | 6 +-
healthd/healthd_mode_charger.cpp | 140 +++++++++++++++++++++++++++++++++++++--
healthd/images/0_720p.png | Bin 0 -> 3196 bytes
healthd/images/1_720p.png | Bin 0 -> 2926 bytes
healthd/images/2_720p.png | Bin 0 -> 3093 bytes
healthd/images/3_720p.png | Bin 0 -> 3231 bytes
healthd/images/4_720p.png | Bin 0 -> 2994 bytes
healthd/images/5_720p.png | Bin 0 -> 3156 bytes
healthd/images/6_720p.png | Bin 0 -> 3259 bytes
healthd/images/7_720p.png | Bin 0 -> 3024 bytes
healthd/images/8_720p.png | Bin 0 -> 3246 bytes
healthd/images/9_720p.png | Bin 0 -> 3291 bytes
healthd/images/p_720p.png | Bin 0 -> 3267 bytes
15 files changed, 190 insertions(+), 12 deletions(-)
create mode 100644 healthd/images/0_720p.png
create mode 100644 healthd/images/1_720p.png
create mode 100644 healthd/images/2_720p.png
create mode 100644 healthd/images/3_720p.png
create mode 100644 healthd/images/4_720p.png
create mode 100644 healthd/images/5_720p.png
create mode 100644 healthd/images/6_720p.png
create mode 100644 healthd/images/7_720p.png
create mode 100644 healthd/images/8_720p.png
create mode 100644 healthd/images/9_720p.png
create mode 100644 healthd/images/p_720p.png
diff --git a/healthd/animation.h b/healthd/animation.h
index 9476c91..ddb55f8 100644
--- a/healthd/animation.h
+++ b/healthd/animation.h
@@ -29,6 +29,7 @@ namespace android {
struct animation {
struct frame {
+ const char *name; //Add by hhuiming for ID1058290
int disp_time;
int min_level;
int max_level;
diff --git a/healthd/healthd_draw.cpp b/healthd/healthd_draw.cpp
index 3da8bda..9baec65 100644
--- a/healthd/healthd_draw.cpp
+++ b/healthd/healthd_draw.cpp
@@ -59,7 +59,47 @@ HealthdDraw::HealthdDraw(animation* anim)
HealthdDraw::~HealthdDraw() {
}
-void HealthdDraw::redraw_screen(const animation* batt_anim, GRSurface* surf_unknown) {
+//Add by hhuiming for ID1058290
+void HealthdDraw::draw_capacity_by_pic_720p(const animation* batt_anim) {
+ LOGE("HHM draw_capacity_by_pic_720p ");
+ int w;
+ int h;
+ int x;
+ int y;
+ int m ,n;
+ animation::frame *frame_p = &batt_anim->frames[10];//percent
+ animation::frame *frame_t;//shi wei shu
+ animation::frame *frame_o;//geweishu
+ animation::frame *frame_h;//bai wei shu
+
+ m = (batt_anim->cur_level)/10;//shi wei shu
+ n = (batt_anim->cur_level)%10;//ge wei shu
+ frame_t = &batt_anim->frames[m];
+ frame_o = &batt_anim->frames[n];
+ w = gr_get_width(frame_p->surface);
+ h = gr_get_height(frame_p->surface);
+ x = (gr_fb_width()) / 2 ;
+ y = 260;
+ LOGE("drawing surface %dx%d+%d+%d\n", w, h, x, y);
+ if(batt_anim->cur_level >= 100)
+ {
+ frame_t = &batt_anim->frames[0];
+ frame_o = &batt_anim->frames[0];
+ frame_h = &batt_anim->frames[1];
+ gr_blit(frame_h->surface, 0, 0, w, h, x-32, y);//16*23
+ gr_blit(frame_t->surface, 0, 0, w, h, x-16, y);
+ gr_blit(frame_o->surface, 0, 0, w, h, x, y);
+ gr_blit(frame_p->surface, 0, 0, w, h, x+16, y);//24*23
+ } else {
+ if(m >= 1)//percent >= 10
+ gr_blit(frame_t->surface, 0, 0, w, h, x-24, y);
+ gr_blit(frame_o->surface, 0, 0, w, h, x-8, y);
+ gr_blit(frame_p->surface, 0, 0, w, h, x+8, y);
+ }
+}
+
+void HealthdDraw::redraw_screen(const animation* batt_percent_anim,const animation* batt_anim, GRSurface* surf_unknown){
+ LOGE("HHM redraw_screen graphics_available = %d",graphics_available);
if (!graphics_available) return;
clear_screen();
@@ -67,11 +107,13 @@ void HealthdDraw::redraw_screen(const animation* batt_anim, GRSurface* surf_unkn
if (batt_anim->cur_status == BATTERY_STATUS_UNKNOWN || batt_anim->cur_level < 0 ||
batt_anim->num_frames == 0)
draw_unknown(surf_unknown);
- else
- draw_battery(batt_anim);
+ else{
+ draw_battery(batt_anim);
+ draw_capacity_by_pic_720p(batt_percent_anim);
+ }
gr_flip();
}
-
+//add end by hhuiming
void HealthdDraw::blank_screen(bool blank) {
if (!graphics_available) return;
gr_fb_blank(blank);
@@ -168,6 +210,7 @@ void HealthdDraw::draw_clock(const animation* anim) {
}
void HealthdDraw::draw_percent(const animation* anim) {
+ LOGE("HHM draw_percent graphics_available = %d",graphics_available);
if (!graphics_available) return;
int cur_level = anim->cur_level;
if (anim->cur_status == BATTERY_STATUS_FULL) {
@@ -178,6 +221,9 @@ void HealthdDraw::draw_percent(const animation* anim) {
const animation::text_field& field = anim->text_percent;
if (field.font == nullptr || field.font->char_width == 0 || field.font->char_height == 0) {
+ std::string str_level = base::StringPrintf("%d%%", cur_level);
+ gr_color(0xa4, 0xc6, 0x39, 255);
+ draw_text(gr_sys_font(), -1, -1, str_level.c_str());
return;
}
@@ -192,6 +238,7 @@ void HealthdDraw::draw_percent(const animation* anim) {
}
void HealthdDraw::draw_battery(const animation* anim) {
+ LOGE("HHM draw_battery graphics_available = %d",graphics_available);
if (!graphics_available) return;
const animation::frame& frame = anim->frames[anim->cur_frame];
diff --git a/healthd/healthd_draw.h b/healthd/healthd_draw.h
index 7c847bd..3313d00 100644
--- a/healthd/healthd_draw.h
+++ b/healthd/healthd_draw.h
@@ -31,7 +31,7 @@ class HealthdDraw {
virtual ~HealthdDraw();
// Redraws screen.
- void redraw_screen(const animation* batt_anim, GRSurface* surf_unknown);
+ void redraw_screen(const animation* batt_percent_anim,const animation* batt_anim, GRSurface* surf_unknown); //modify begin by hhuiming
// Blanks screen if true, unblanks if false.
virtual void blank_screen(bool blank);
@@ -58,6 +58,10 @@ class HealthdDraw {
// Draws charger->surf_unknown or basic text.
virtual void draw_unknown(GRSurface* surf_unknown);
+ //modify begin by hhuiming
+ virtual void draw_capacity_by_pic_720p(const animation* anim);
+ //modify end by hhuiming
+
// Pixel sizes of characters for default font.
int char_width_;
int char_height_;
diff --git a/healthd/healthd_mode_charger.cpp b/healthd/healthd_mode_charger.cpp
index 60d9a8f..980313c 100644
--- a/healthd/healthd_mode_charger.cpp
+++ b/healthd/healthd_mode_charger.cpp
@@ -111,6 +111,7 @@ struct charger {
key_state keys[KEY_MAX + 1];
animation* batt_anim;
+ animation *batt_percent_anim; //Add by hhuiming
GRSurface* surf_unknown;
int boot_min_cap;
};
@@ -192,6 +193,100 @@ static animation::frame default_animation_frames[] = {
},
};
+//Add begin by HHM
+static animation::frame default_animation_percent_frames[] = {
+ {
+ .name = "charger/0_720p",
+ .disp_time = 750,
+ .min_level = 0,
+ .max_level = 100,
+ .surface = NULL,
+ },
+ {
+ .name = "charger/1_720p",
+ .disp_time = 750,
+ .min_level = 0,
+ .max_level = 100,
+ .surface = NULL,
+ },
+ {
+ .name = "charger/2_720p",
+ .disp_time = 750,
+ .min_level = 0,
+ .max_level = 100,
+ .surface = NULL,
+ },
+ {
+ .name = "charger/3_720p",
+ .disp_time = 750,
+ .min_level = 0,
+ .max_level = 100,
+ .surface = NULL,
+ },
+ {
+ .name = "charger/4_720p",
+ .disp_time = 750,
+ .min_level = 0,
+ .max_level = 100,
+ .surface = NULL,
+ },
+ {
+ .name = "charger/5_720p",
+ .disp_time = 750,
+ .min_level = 0,
+ .max_level = 100,
+ .surface = NULL,
+ },
+ {
+ .name = "charger/6_720p",
+ .disp_time = 750,
+ .min_level = 0,
+ .max_level = 100,
+ .surface = NULL,
+ },
+ {
+ .name = "charger/7_720p",
+ .disp_time = 750,
+ .min_level = 0,
+ .max_level = 100,
+ .surface = NULL,
+ },
+ {
+ .name = "charger/8_720p",
+ .disp_time = 750,
+ .min_level = 0,
+ .max_level = 100,
+ .surface = NULL,
+ },
+ {
+ .name = "charger/9_720p",
+ .disp_time = 750,
+ .min_level = 0,
+ .max_level = 100,
+ .surface = NULL,
+ },
+ {
+ .name = "charger/p_720p",
+ .disp_time = 750,
+ .min_level = 0,
+ .max_level = 100,
+ .surface = NULL,
+ },
+};
+
+static animation battery_percent_animation = {
+ .run = false,
+ .frames = default_animation_percent_frames,
+ .cur_frame = 0,
+ .num_frames = ARRAY_SIZE(default_animation_percent_frames),
+ .cur_cycle = 0,
+ .num_cycles = 2,//3
+ .cur_level = 0,
+ .first_frame_repeats = 2,
+ .cur_status = BATTERY_STATUS_UNKNOWN,
+};
+//Add by hhuiming for
+
static animation battery_animation = BASE_ANIMATION;
static charger charger_state;
@@ -288,6 +383,7 @@ static void reset_animation(animation* anim) {
static void update_screen_state(charger* charger, int64_t now) {
animation* batt_anim = charger->batt_anim;
+ animation *batt_percent_anim = charger->batt_percent_anim;
int disp_time;
if (!batt_anim->run || now < charger->next_screen_transition) return;
@@ -338,7 +434,12 @@ static void update_screen_state(charger* charger, int64_t now) {
}
disp_time = batt_anim->frames[batt_anim->cur_frame].disp_time;
-
+//Add begin HHM
if (batt_prop) {
+ batt_percent_anim->cur_level = batt_prop->batteryLevel;
+ batt_percent_anim->cur_status = batt_prop->batteryStatus;
+ }
+//Add end HHM
/* unblank the screen on first cycle and first frame */
if (batt_anim->cur_cycle == 0 && batt_anim->cur_frame == 0) healthd_draw->blank_screen(false);
@@ -375,10 +476,10 @@ static void update_screen_state(charger* charger, int64_t now) {
}
}
}
-
+ LOGE("HHM healthd_draw->redraw_screen before");
/* draw the new frame (@ cur_frame) */
- healthd_draw->redraw_screen(charger->batt_anim, charger->surf_unknown);
-
+ healthd_draw->redraw_screen(charger->batt_percent_anim,charger->batt_anim, charger->surf_unknown); //modify begin HHM
+ LOGE(" healthd_draw->redraw_screen end");
/* if we don't have anim frames, we only have one image, so just bump
* the cycle counter and exit
*/
@@ -493,15 +594,24 @@ static void process_key(charger* charger, int code, int64_t now) {
/* Turn on the display and kick animation on power-key press
* rather than on key release
*/
+ #if 0
kick_animation(charger->batt_anim);
request_suspend(false);
+ #endif
}
} else {
/* if the power key got released, force screen state cycle */
if (key->pending) {
- kick_animation(charger->batt_anim);
- request_suspend(false);
- }
+ if(!charger->batt_anim->run){
+ kick_animation(charger->batt_anim);
+ request_suspend(false);
+ } else {
+ reset_animation(charger->batt_anim);
+ charger->next_screen_transition = -1;
+ healthd_draw->blank_screen(true);
+ charger->screen_blanked = true;
+ }
+ }
}
}
@@ -693,6 +803,22 @@ void healthd_mode_charger_init(struct healthd_config* config) {
animation* anim = init_animation();
charger->batt_anim = anim;
+ charger->batt_percent_anim = &battery_percent_animation;//Add guzihao for ID1003037
+ //Add begin guzihao for ID1003037
+ LOGE("************ guzihao start ***********\n");
+ for (i = 0; i < charger->batt_percent_anim->num_frames; i++) {
+ animation::frame *frame = &charger->batt_percent_anim->frames[i];
+ ret = res_create_display_surface(frame->name, &frame->surface);
+ if (ret < 0) {
+ LOGE("Cannot load image %s\n", frame->name);
+ /* TODO: free the already allocated surfaces... */
+ charger->batt_percent_anim->num_frames = 0;
+ charger->batt_percent_anim->num_cycles = 1;
+ break;
+ }
+ }
+ LOGE("************ guzihao end ***********\n");
+ //Add end guzihao for ID1003037
ret = res_create_display_surface(anim->fail_file.c_str(), &charger->surf_unknown);
if (ret < 0) {
LOGE("Cannot load custom battery_fail image. Reverting to built in: %d\n", ret);