summaryrefslogtreecommitdiff
path: root/cmds/bootanimation/BootAnimation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cmds/bootanimation/BootAnimation.cpp')
-rw-r--r--cmds/bootanimation/BootAnimation.cpp60
1 files changed, 58 insertions, 2 deletions
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp
index 0bddf3d9c7ad..f51d1233eb95 100644
--- a/cmds/bootanimation/BootAnimation.cpp
+++ b/cmds/bootanimation/BootAnimation.cpp
@@ -85,6 +85,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";
@@ -100,6 +102,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;
@@ -925,6 +928,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;
@@ -944,6 +959,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
@@ -953,11 +969,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') {
@@ -1034,6 +1056,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;
@@ -1165,6 +1195,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);
@@ -1200,6 +1232,7 @@ bool BootAnimation::playAnimation(const Animation& animation) {
elapsedRealtime());
int fadedFramesCount = 0;
+ int lastDisplayedProgress = 0;
for (size_t i=0 ; i<pcount ; i++) {
const Animation::Part& part(animation.parts[i]);
const size_t fcount = part.frames.size();
@@ -1225,6 +1258,12 @@ bool BootAnimation::playAnimation(const Animation& animation) {
part.backgroundColor[2],
1.0f);
+ // For the last animation, if we have progress indicator from
+ // the system, display it.
+ int currentProgress = android::base::GetIntProperty(PROGRESS_PROP_NAME, 0);
+ bool displayProgress = animation.progressEnabled &&
+ (i == (pcount -1)) && currentProgress != 0;
+
for (size_t j=0 ; j<fcount ; j++) {
if (shouldStopPlayingPart(part, fadedFramesCount)) break;
@@ -1282,6 +1321,23 @@ bool BootAnimation::playAnimation(const Animation& animation) {
drawClock(animation.clockFont, part.clockPosX, part.clockPosY);
}
+ if (displayProgress) {
+ int newProgress = android::base::GetIntProperty(PROGRESS_PROP_NAME, 0);
+ // In case the new progress jumped suddenly, still show an
+ // increment of 1.
+ if (lastDisplayedProgress != 100) {
+ // Artificially sleep 1/10th a second to slow down the animation.
+ usleep(100000);
+ if (lastDisplayedProgress < newProgress) {
+ lastDisplayedProgress++;
+ }
+ }
+ // Put the progress percentage right below the animation.
+ int posY = animation.height / 3;
+ int posX = TEXT_CENTER_VALUE;
+ drawProgress(lastDisplayedProgress, animation.progressFont, posX, posY);
+ }
+
handleViewport(frameDuration);
eglSwapBuffers(mDisplay, mSurface);