From bbb00e78ef87e45ffb25b9347c648a04fac00b6e Mon Sep 17 00:00:00 2001 From: Nicolas Geoffray Date: Tue, 15 Dec 2020 10:50:29 +0000 Subject: Support for showing percent progress in boot animation. Bug: 175686819 Test: boot with manual changes updating the progress Change-Id: I2d936e3391f56796308c90deb39ecacc58797721 Merged-In: I2d936e3391f56796308c90deb39ecacc58797721 --- cmds/bootanimation/BootAnimation.cpp | 60 ++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) (limited to 'cmds/bootanimation/BootAnimation.cpp') diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp index 2c7ee212b7b5..854982f825dc 100644 --- a/cmds/bootanimation/BootAnimation.cpp +++ b/cmds/bootanimation/BootAnimation.cpp @@ -92,6 +92,8 @@ static const char SYSTEM_TIME_DIR_NAME[] = "time"; static const char SYSTEM_TIME_DIR_PATH[] = "/data/system/time"; static const char CLOCK_FONT_ASSET[] = "images/clock_font.png"; static const char CLOCK_FONT_ZIP_NAME[] = "clock_font.png"; +static const char PROGRESS_FONT_ASSET[] = "images/progress_font.png"; +static const char PROGRESS_FONT_ZIP_NAME[] = "progress_font.png"; static const char LAST_TIME_CHANGED_FILE_NAME[] = "last_time_change"; static const char LAST_TIME_CHANGED_FILE_PATH[] = "/data/system/time/last_time_change"; static const char ACCURATE_TIME_FLAG_FILE_NAME[] = "time_is_accurate"; @@ -107,6 +109,7 @@ static constexpr size_t FONT_NUM_ROWS = FONT_NUM_CHARS / FONT_NUM_COLS; static const int TEXT_CENTER_VALUE = INT_MAX; static const int TEXT_MISSING_VALUE = INT_MIN; static const char EXIT_PROP_NAME[] = "service.bootanim.exit"; +static const char PROGRESS_PROP_NAME[] = "service.bootanim.progress"; static const char DISPLAYS_PROP_NAME[] = "persist.service.bootanim.displays"; static const int ANIM_ENTRY_NAME_MAX = ANIM_PATH_MAX + 1; static constexpr size_t TEXT_POS_LEN_MAX = 16; @@ -891,6 +894,18 @@ void BootAnimation::drawClock(const Font& font, const int xPos, const int yPos) drawText(out, font, false, &x, &y); } +void BootAnimation::drawProgress(int percent, const Font& font, const int xPos, const int yPos) { + static constexpr int PERCENT_LENGTH = 5; + + char percentBuff[PERCENT_LENGTH]; + // ';' has the ascii code just after ':', and the font resource contains '%' + // for that ascii code. + sprintf(percentBuff, "%d;", percent); + int x = xPos; + int y = yPos; + drawText(percentBuff, font, false, &x, &y); +} + bool BootAnimation::parseAnimationDesc(Animation& animation) { String8 desString; @@ -910,6 +925,7 @@ bool BootAnimation::parseAnimationDesc(Animation& animation) { int height = 0; int count = 0; int pause = 0; + int progress = 0; int framesToFadeCount = 0; char path[ANIM_ENTRY_NAME_MAX]; char color[7] = "000000"; // default to black if unspecified @@ -919,11 +935,17 @@ bool BootAnimation::parseAnimationDesc(Animation& animation) { int nextReadPos; - if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) { - // SLOGD("> w=%d, h=%d, fps=%d", width, height, fps); + int topLineNumbers = sscanf(l, "%d %d %d %d", &width, &height, &fps, &progress); + if (topLineNumbers == 3 || topLineNumbers == 4) { + // SLOGD("> w=%d, h=%d, fps=%d, progress=%d", width, height, fps, progress); animation.width = width; animation.height = height; animation.fps = fps; + if (topLineNumbers == 4) { + animation.progressEnabled = (progress != 0); + } else { + animation.progressEnabled = false; + } } else if (sscanf(l, "%c %d %d %" STRTO(ANIM_PATH_MAX) "s%n", &pathType, &count, &pause, path, &nextReadPos) >= 4) { if (pathType == 'f') { @@ -1000,6 +1022,14 @@ bool BootAnimation::preloadZip(Animation& animation) { continue; } + if (entryName == PROGRESS_FONT_ZIP_NAME) { + FileMap* map = zip->createEntryFileMap(entry); + if (map) { + animation.progressFont.map = map; + } + continue; + } + for (size_t j = 0; j < pcount; j++) { if (path == animation.parts[j].path) { uint16_t method; @@ -1131,6 +1161,8 @@ bool BootAnimation::movie() { mClockEnabled = clockFontInitialized; } + initFont(&mAnimation->progressFont, PROGRESS_FONT_ASSET); + if (mClockEnabled && !updateIsTimeAccurate()) { mTimeCheckThread = new TimeCheckThread(this); mTimeCheckThread->run("BootAnimation::TimeCheckThread", PRIORITY_NORMAL); @@ -1166,6 +1198,7 @@ bool BootAnimation::playAnimation(const Animation& animation) { elapsedRealtime()); int fadedFramesCount = 0; + int lastDisplayedProgress = 0; for (size_t i=0 ; i