blob: 814800bcd9e5dbd33b63df3ca6bda040e9056ce5 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -070017#define LOG_NDEBUG 0
Mathias Agopianbc726112009-09-23 15:44:05 -070018#define LOG_TAG "BootAnimation"
19
Nikita Ioffe06c986e2020-01-27 17:16:03 +000020#include <vector>
21
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022#include <stdint.h>
Wei Wanga90c54c2017-02-02 11:35:21 -080023#include <inttypes.h>
Damien Bargiacchi97480862016-03-29 14:55:55 -070024#include <sys/inotify.h>
25#include <sys/poll.h>
26#include <sys/stat.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027#include <sys/types.h>
28#include <math.h>
29#include <fcntl.h>
30#include <utils/misc.h>
Mathias Agopianb4d5a722009-09-23 17:05:19 -070031#include <signal.h>
Elliott Hughesbb94f312014-10-21 10:41:33 -070032#include <time.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
Steven Morelandfb7952f2018-02-23 14:58:50 -080034#include <cutils/atomic.h>
Jason parksbd9a08d2011-01-31 15:04:34 -060035#include <cutils/properties.h>
36
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -040037#include <android/imagedecoder.h>
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080038#include <androidfw/AssetManager.h>
Mathias Agopianac31a3b2009-05-21 19:59:24 -070039#include <binder/IPCThreadState.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040#include <utils/Errors.h>
41#include <utils/Log.h>
Wei Wanga90c54c2017-02-02 11:35:21 -080042#include <utils/SystemClock.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043
Keun-young Parkb5938422017-03-23 13:46:24 -070044#include <android-base/properties.h>
45
Marin Shalamanovcb783ca2021-01-29 21:26:07 +010046#include <ui/DisplayMode.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047#include <ui/PixelFormat.h>
48#include <ui/Rect.h>
49#include <ui/Region.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050
Jeff Brown0b722fe2012-08-24 22:40:14 -070051#include <gui/ISurfaceComposer.h>
Marin Shalamanov9070c052020-05-18 19:05:17 +020052#include <gui/DisplayEventReceiver.h>
Mathias Agopian8335f1c2012-02-25 18:48:35 -080053#include <gui/Surface.h>
54#include <gui/SurfaceComposerClient.h>
Lucas Dupin8eedc022021-07-29 21:49:07 +000055#include <GLES2/gl2.h>
56#include <GLES2/gl2ext.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057#include <EGL/eglext.h>
58
59#include "BootAnimation.h"
60
Kyeongkab.Nam35a8a112019-07-17 16:41:48 +090061#define ANIM_PATH_MAX 255
62#define STR(x) #x
63#define STRTO(x) STR(x)
64
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065namespace android {
66
Marin Shalamanovcb783ca2021-01-29 21:26:07 +010067using ui::DisplayMode;
68
Damien Bargiacchi97480862016-03-29 14:55:55 -070069static const char OEM_BOOTANIMATION_FILE[] = "/oem/media/bootanimation.zip";
Beverly34ffe252019-05-17 11:03:54 -040070static const char PRODUCT_BOOTANIMATION_DARK_FILE[] = "/product/media/bootanimation-dark.zip";
Jaekyun Seokc521bb32018-01-30 11:52:47 +090071static const char PRODUCT_BOOTANIMATION_FILE[] = "/product/media/bootanimation.zip";
Damien Bargiacchi97480862016-03-29 14:55:55 -070072static const char SYSTEM_BOOTANIMATION_FILE[] = "/system/media/bootanimation.zip";
Anders Fridlunde0b4d232018-11-06 14:23:25 +010073static const char APEX_BOOTANIMATION_FILE[] = "/apex/com.android.bootanimation/etc/bootanimation.zip";
Keun-young Parkb5938422017-03-23 13:46:24 -070074static const char OEM_SHUTDOWNANIMATION_FILE[] = "/oem/media/shutdownanimation.zip";
Jaekyun Seokc521bb32018-01-30 11:52:47 +090075static const char PRODUCT_SHUTDOWNANIMATION_FILE[] = "/product/media/shutdownanimation.zip";
Keun-young Parkb5938422017-03-23 13:46:24 -070076static const char SYSTEM_SHUTDOWNANIMATION_FILE[] = "/system/media/shutdownanimation.zip";
77
Nikita Ioffe06c986e2020-01-27 17:16:03 +000078static constexpr const char* PRODUCT_USERSPACE_REBOOT_ANIMATION_FILE = "/product/media/userspace-reboot.zip";
79static constexpr const char* OEM_USERSPACE_REBOOT_ANIMATION_FILE = "/oem/media/userspace-reboot.zip";
80static constexpr const char* SYSTEM_USERSPACE_REBOOT_ANIMATION_FILE = "/system/media/userspace-reboot.zip";
81
Josh Yangf95b2002021-12-23 14:32:28 -080082static const char BOOTANIM_DATA_DIR_PATH[] = "/data/bootanim";
83static const char BOOTANIM_TIME_DIR_NAME[] = "time";
84static const char BOOTANIM_TIME_DIR_PATH[] = "/data/bootanim/time";
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070085static const char CLOCK_FONT_ASSET[] = "images/clock_font.png";
86static const char CLOCK_FONT_ZIP_NAME[] = "clock_font.png";
Nicolas Geoffray41fffb42020-12-15 10:50:29 +000087static const char PROGRESS_FONT_ASSET[] = "images/progress_font.png";
88static const char PROGRESS_FONT_ZIP_NAME[] = "progress_font.png";
Damien Bargiacchi97480862016-03-29 14:55:55 -070089static const char LAST_TIME_CHANGED_FILE_NAME[] = "last_time_change";
Josh Yangf95b2002021-12-23 14:32:28 -080090static const char LAST_TIME_CHANGED_FILE_PATH[] = "/data/bootanim/time/last_time_change";
Damien Bargiacchi97480862016-03-29 14:55:55 -070091static const char ACCURATE_TIME_FLAG_FILE_NAME[] = "time_is_accurate";
Josh Yangf95b2002021-12-23 14:32:28 -080092static const char ACCURATE_TIME_FLAG_FILE_PATH[] = "/data/bootanim/time/time_is_accurate";
93static const char TIME_FORMAT_12_HOUR_FLAG_FILE_PATH[] = "/data/bootanim/time/time_format_12_hour";
Damien Bargiacchi96762812016-07-12 15:53:40 -070094// Java timestamp format. Don't show the clock if the date is before 2000-01-01 00:00:00.
95static const long long ACCURATE_TIME_EPOCH = 946684800000;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070096static constexpr char FONT_BEGIN_CHAR = ' ';
97static constexpr char FONT_END_CHAR = '~' + 1;
98static constexpr size_t FONT_NUM_CHARS = FONT_END_CHAR - FONT_BEGIN_CHAR + 1;
99static constexpr size_t FONT_NUM_COLS = 16;
100static constexpr size_t FONT_NUM_ROWS = FONT_NUM_CHARS / FONT_NUM_COLS;
101static const int TEXT_CENTER_VALUE = INT_MAX;
102static const int TEXT_MISSING_VALUE = INT_MIN;
Damien Bargiacchi97480862016-03-29 14:55:55 -0700103static const char EXIT_PROP_NAME[] = "service.bootanim.exit";
Nicolas Geoffray41fffb42020-12-15 10:50:29 +0000104static const char PROGRESS_PROP_NAME[] = "service.bootanim.progress";
Huihong Luod4a217e2020-01-16 15:56:33 -0800105static const char DISPLAYS_PROP_NAME[] = "persist.service.bootanim.displays";
Thiébaud Weksteen08de4432021-11-18 13:25:59 +1100106static const char CLOCK_ENABLED_PROP_NAME[] = "persist.sys.bootanim.clock.enabled";
Kyeongkab.Nam35a8a112019-07-17 16:41:48 +0900107static const int ANIM_ENTRY_NAME_MAX = ANIM_PATH_MAX + 1;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700108static constexpr size_t TEXT_POS_LEN_MAX = 16;
Shan Huang2b31a362021-08-16 16:45:39 +0000109static const int DYNAMIC_COLOR_COUNT = 4;
Lucas Dupin8eedc022021-07-29 21:49:07 +0000110static const char U_TEXTURE[] = "uTexture";
111static const char U_FADE[] = "uFade";
112static const char U_CROP_AREA[] = "uCropArea";
Shan Huang2b31a362021-08-16 16:45:39 +0000113static const char U_START_COLOR_PREFIX[] = "uStartColor";
114static const char U_END_COLOR_PREFIX[] = "uEndColor";
115static const char U_COLOR_PROGRESS[] = "uColorProgress";
Lucas Dupin8eedc022021-07-29 21:49:07 +0000116static const char A_UV[] = "aUv";
117static const char A_POSITION[] = "aPosition";
118static const char VERTEX_SHADER_SOURCE[] = R"(
119 precision mediump float;
120 attribute vec4 aPosition;
121 attribute highp vec2 aUv;
122 varying highp vec2 vUv;
123 void main() {
124 gl_Position = aPosition;
125 vUv = aUv;
126 })";
Shan Huang2b31a362021-08-16 16:45:39 +0000127static const char IMAGE_FRAG_DYNAMIC_COLORING_SHADER_SOURCE[] = R"(
128 precision mediump float;
Shan Huang81846ba2021-09-07 19:07:47 +0000129 const float cWhiteMaskThreshold = 0.05;
Shan Huang2b31a362021-08-16 16:45:39 +0000130 uniform sampler2D uTexture;
131 uniform float uFade;
132 uniform float uColorProgress;
133 uniform vec4 uStartColor0;
134 uniform vec4 uStartColor1;
135 uniform vec4 uStartColor2;
136 uniform vec4 uStartColor3;
137 uniform vec4 uEndColor0;
138 uniform vec4 uEndColor1;
139 uniform vec4 uEndColor2;
140 uniform vec4 uEndColor3;
141 varying highp vec2 vUv;
142 void main() {
143 vec4 mask = texture2D(uTexture, vUv);
Shan Huang488ff742021-08-25 20:10:46 +0000144 float r = mask.r;
145 float g = mask.g;
146 float b = mask.b;
147 float a = mask.a;
148 // If all channels have values, render pixel as a shade of white.
149 float useWhiteMask = step(cWhiteMaskThreshold, r)
150 * step(cWhiteMaskThreshold, g)
151 * step(cWhiteMaskThreshold, b)
152 * step(cWhiteMaskThreshold, a);
153 vec4 color = r * mix(uStartColor0, uEndColor0, uColorProgress)
154 + g * mix(uStartColor1, uEndColor1, uColorProgress)
155 + b * mix(uStartColor2, uEndColor2, uColorProgress)
156 + a * mix(uStartColor3, uEndColor3, uColorProgress);
Shan Huang81846ba2021-09-07 19:07:47 +0000157 color = mix(color, vec4(vec3((r + g + b + a) * 0.25), 1.0), useWhiteMask);
Shan Huang2b31a362021-08-16 16:45:39 +0000158 gl_FragColor = vec4(color.x, color.y, color.z, (1.0 - uFade)) * color.a;
159 })";
Lucas Dupin8eedc022021-07-29 21:49:07 +0000160static const char IMAGE_FRAG_SHADER_SOURCE[] = R"(
161 precision mediump float;
162 uniform sampler2D uTexture;
163 uniform float uFade;
164 varying highp vec2 vUv;
165 void main() {
166 vec4 color = texture2D(uTexture, vUv);
Shan Huang2b31a362021-08-16 16:45:39 +0000167 gl_FragColor = vec4(color.x, color.y, color.z, (1.0 - uFade)) * color.a;
Lucas Dupin8eedc022021-07-29 21:49:07 +0000168 })";
169static const char TEXT_FRAG_SHADER_SOURCE[] = R"(
170 precision mediump float;
171 uniform sampler2D uTexture;
172 uniform vec4 uCropArea;
173 varying highp vec2 vUv;
174 void main() {
175 vec2 uv = vec2(mix(uCropArea.x, uCropArea.z, vUv.x),
176 mix(uCropArea.y, uCropArea.w, vUv.y));
177 gl_FragColor = texture2D(uTexture, uv);
178 })";
179
180static GLfloat quadPositions[] = {
181 -0.5f, -0.5f,
182 +0.5f, -0.5f,
183 +0.5f, +0.5f,
184 +0.5f, +0.5f,
185 -0.5f, +0.5f,
186 -0.5f, -0.5f
187};
188static GLfloat quadUVs[] = {
189 0.0f, 1.0f,
190 1.0f, 1.0f,
191 1.0f, 0.0f,
192 1.0f, 0.0f,
193 0.0f, 0.0f,
194 0.0f, 1.0f
195};
Narayan Kamathafd31e02013-12-03 13:16:03 +0000196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197// ---------------------------------------------------------------------------
198
Ed Coyne7464ac92017-06-08 12:26:48 -0700199BootAnimation::BootAnimation(sp<Callbacks> callbacks)
Marin Shalamanov9070c052020-05-18 19:05:17 +0200200 : Thread(false), mLooper(new Looper(false)), mClockEnabled(true), mTimeIsAccurate(false),
Yi Kong911ac232019-03-24 01:49:02 -0700201 mTimeFormat12Hour(false), mTimeCheckThread(nullptr), mCallbacks(callbacks) {
Mathias Agopian627e7b52009-05-21 19:21:59 -0700202 mSession = new SurfaceComposerClient();
Geoffrey Pitsch290c4352016-08-09 14:35:10 -0400203
Keun-young Parkb5938422017-03-23 13:46:24 -0700204 std::string powerCtl = android::base::GetProperty("sys.powerctl", "");
205 if (powerCtl.empty()) {
206 mShuttingDown = false;
207 } else {
208 mShuttingDown = true;
209 }
Huihong Luo50a2f362018-08-11 09:27:57 -0700210 ALOGD("%sAnimationStartTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
211 elapsedRealtime());
212}
213
214BootAnimation::~BootAnimation() {
215 if (mAnimation != nullptr) {
216 releaseAnimation(mAnimation);
217 mAnimation = nullptr;
218 }
219 ALOGD("%sAnimationStopTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
220 elapsedRealtime());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221}
222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223void BootAnimation::onFirstRef() {
Mathias Agopianbc726112009-09-23 15:44:05 -0700224 status_t err = mSession->linkToComposerDeath(this);
Wei Wang159a4102018-10-23 23:15:58 -0700225 SLOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err));
Mathias Agopian8434c532009-09-23 18:52:49 -0700226 if (err == NO_ERROR) {
Huihong Luo50a2f362018-08-11 09:27:57 -0700227 // Load the animation content -- this can be slow (eg 200ms)
228 // called before waitForSurfaceFlinger() in main() to avoid wait
229 ALOGD("%sAnimationPreloadTiming start time: %" PRId64 "ms",
230 mShuttingDown ? "Shutdown" : "Boot", elapsedRealtime());
231 preloadAnimation();
232 ALOGD("%sAnimationPreloadStopTiming start time: %" PRId64 "ms",
233 mShuttingDown ? "Shutdown" : "Boot", elapsedRealtime());
Mathias Agopianbc726112009-09-23 15:44:05 -0700234 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235}
236
Mathias Agopianbc726112009-09-23 15:44:05 -0700237sp<SurfaceComposerClient> BootAnimation::session() const {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 return mSession;
239}
240
Marin Shalamanov9070c052020-05-18 19:05:17 +0200241void BootAnimation::binderDied(const wp<IBinder>&) {
Mathias Agopianbc726112009-09-23 15:44:05 -0700242 // woah, surfaceflinger died!
Wei Wang159a4102018-10-23 23:15:58 -0700243 SLOGD("SurfaceFlinger died, exiting...");
Mathias Agopianbc726112009-09-23 15:44:05 -0700244
245 // calling requestExit() is not enough here because the Surface code
246 // might be blocked on a condition variable that will never be updated.
247 kill( getpid(), SIGKILL );
248 requestExit();
249}
250
Shan Huang2b31a362021-08-16 16:45:39 +0000251static void* decodeImage(const void* encodedData, size_t dataLength, AndroidBitmapInfo* outInfo,
252 bool premultiplyAlpha) {
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400253 AImageDecoder* decoder = nullptr;
254 AImageDecoder_createFromBuffer(encodedData, dataLength, &decoder);
255 if (!decoder) {
256 return nullptr;
257 }
258
259 const AImageDecoderHeaderInfo* info = AImageDecoder_getHeaderInfo(decoder);
260 outInfo->width = AImageDecoderHeaderInfo_getWidth(info);
261 outInfo->height = AImageDecoderHeaderInfo_getHeight(info);
262 outInfo->format = AImageDecoderHeaderInfo_getAndroidBitmapFormat(info);
263 outInfo->stride = AImageDecoder_getMinimumStride(decoder);
264 outInfo->flags = 0;
265
Shan Huang2b31a362021-08-16 16:45:39 +0000266 if (!premultiplyAlpha) {
267 AImageDecoder_setUnpremultipliedRequired(decoder, true);
268 }
269
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400270 const size_t size = outInfo->stride * outInfo->height;
271 void* pixels = malloc(size);
272 int result = AImageDecoder_decodeImage(decoder, pixels, outInfo->stride, size);
273 AImageDecoder_delete(decoder);
274
275 if (result != ANDROID_IMAGE_DECODER_SUCCESS) {
276 free(pixels);
277 return nullptr;
278 }
279 return pixels;
280}
281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets,
Shan Huang2b31a362021-08-16 16:45:39 +0000283 const char* name, bool premultiplyAlpha) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800284 Asset* asset = assets.open(name, Asset::ACCESS_BUFFER);
Yi Kong911ac232019-03-24 01:49:02 -0700285 if (asset == nullptr)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 return NO_INIT;
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400287
288 AndroidBitmapInfo bitmapInfo;
Shan Huang2b31a362021-08-16 16:45:39 +0000289 void* pixels = decodeImage(asset->getBuffer(false), asset->getLength(), &bitmapInfo,
290 premultiplyAlpha);
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400291 auto pixelDeleter = std::unique_ptr<void, decltype(free)*>{ pixels, free };
292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800293 asset->close();
294 delete asset;
295
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400296 if (!pixels) {
297 return NO_INIT;
298 }
299
300 const int w = bitmapInfo.width;
301 const int h = bitmapInfo.height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800303 texture->w = w;
304 texture->h = h;
305
306 glGenTextures(1, &texture->name);
307 glBindTexture(GL_TEXTURE_2D, texture->name);
308
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400309 switch (bitmapInfo.format) {
310 case ANDROID_BITMAP_FORMAT_A_8:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800311 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400312 GL_UNSIGNED_BYTE, pixels);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 break;
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400314 case ANDROID_BITMAP_FORMAT_RGBA_4444:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800315 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400316 GL_UNSIGNED_SHORT_4_4_4_4, pixels);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 break;
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400318 case ANDROID_BITMAP_FORMAT_RGBA_8888:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800319 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400320 GL_UNSIGNED_BYTE, pixels);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 break;
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400322 case ANDROID_BITMAP_FORMAT_RGB_565:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400324 GL_UNSIGNED_SHORT_5_6_5, pixels);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800325 break;
326 default:
327 break;
328 }
329
Lucas Dupin8eedc022021-07-29 21:49:07 +0000330 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
331 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
332 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
333 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700334
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800335 return NO_ERROR;
336}
337
Shan Huang2b31a362021-08-16 16:45:39 +0000338status_t BootAnimation::initTexture(FileMap* map, int* width, int* height,
339 bool premultiplyAlpha) {
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400340 AndroidBitmapInfo bitmapInfo;
Shan Huang2b31a362021-08-16 16:45:39 +0000341 void* pixels = decodeImage(map->getDataPtr(), map->getDataLength(), &bitmapInfo,
342 premultiplyAlpha);
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400343 auto pixelDeleter = std::unique_ptr<void, decltype(free)*>{ pixels, free };
Mathias Agopiana8826d62009-10-01 03:10:14 -0700344
Mykola Kondratenko0c1eeb32014-04-15 09:35:44 +0200345 // FileMap memory is never released until application exit.
346 // Release it now as the texture is already loaded and the memory used for
347 // the packed resource can be released.
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700348 delete map;
Mykola Kondratenko0c1eeb32014-04-15 09:35:44 +0200349
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400350 if (!pixels) {
351 return NO_INIT;
352 }
353
354 const int w = bitmapInfo.width;
355 const int h = bitmapInfo.height;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700356
Mathias Agopiana8826d62009-10-01 03:10:14 -0700357 int tw = 1 << (31 - __builtin_clz(w));
358 int th = 1 << (31 - __builtin_clz(h));
359 if (tw < w) tw <<= 1;
360 if (th < h) th <<= 1;
361
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400362 switch (bitmapInfo.format) {
363 case ANDROID_BITMAP_FORMAT_RGBA_8888:
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530364 if (!mUseNpotTextures && (tw != w || th != h)) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700365 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA,
Yi Kong911ac232019-03-24 01:49:02 -0700366 GL_UNSIGNED_BYTE, nullptr);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700367 glTexSubImage2D(GL_TEXTURE_2D, 0,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400368 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700369 } else {
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530370 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400371 GL_UNSIGNED_BYTE, pixels);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700372 }
373 break;
374
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400375 case ANDROID_BITMAP_FORMAT_RGB_565:
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530376 if (!mUseNpotTextures && (tw != w || th != h)) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700377 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB,
Yi Kong911ac232019-03-24 01:49:02 -0700378 GL_UNSIGNED_SHORT_5_6_5, nullptr);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700379 glTexSubImage2D(GL_TEXTURE_2D, 0,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400380 0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, pixels);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700381 } else {
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530382 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400383 GL_UNSIGNED_SHORT_5_6_5, pixels);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700384 }
385 break;
386 default:
387 break;
388 }
389
Lucas Dupin8eedc022021-07-29 21:49:07 +0000390 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
391 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
392 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
393 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700394
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700395 *width = w;
396 *height = h;
397
Mathias Agopiana8826d62009-10-01 03:10:14 -0700398 return NO_ERROR;
399}
400
Marin Shalamanov9070c052020-05-18 19:05:17 +0200401class BootAnimation::DisplayEventCallback : public LooperCallback {
402 BootAnimation* mBootAnimation;
403
404public:
405 DisplayEventCallback(BootAnimation* bootAnimation) {
406 mBootAnimation = bootAnimation;
407 }
408
409 int handleEvent(int /* fd */, int events, void* /* data */) {
410 if (events & (Looper::EVENT_ERROR | Looper::EVENT_HANGUP)) {
411 ALOGE("Display event receiver pipe was closed or an error occurred. events=0x%x",
412 events);
413 return 0; // remove the callback
414 }
415
416 if (!(events & Looper::EVENT_INPUT)) {
417 ALOGW("Received spurious callback for unhandled poll event. events=0x%x", events);
418 return 1; // keep the callback
419 }
420
421 constexpr int kBufferSize = 100;
422 DisplayEventReceiver::Event buffer[kBufferSize];
423 ssize_t numEvents;
424 do {
425 numEvents = mBootAnimation->mDisplayEventReceiver->getEvents(buffer, kBufferSize);
426 for (size_t i = 0; i < static_cast<size_t>(numEvents); i++) {
427 const auto& event = buffer[i];
428 if (event.header.type == DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG) {
429 SLOGV("Hotplug received");
430
431 if (!event.hotplug.connected) {
432 // ignore hotplug disconnect
433 continue;
434 }
435 auto token = SurfaceComposerClient::getPhysicalDisplayToken(
436 event.header.displayId);
437
438 if (token != mBootAnimation->mDisplayToken) {
439 // ignore hotplug of a secondary display
440 continue;
441 }
442
Marin Shalamanovcb783ca2021-01-29 21:26:07 +0100443 DisplayMode displayMode;
444 const status_t error = SurfaceComposerClient::getActiveDisplayMode(
445 mBootAnimation->mDisplayToken, &displayMode);
Marin Shalamanov9070c052020-05-18 19:05:17 +0200446 if (error != NO_ERROR) {
Marin Shalamanovcb783ca2021-01-29 21:26:07 +0100447 SLOGE("Can't get active display mode.");
Marin Shalamanov9070c052020-05-18 19:05:17 +0200448 }
Marin Shalamanovcb783ca2021-01-29 21:26:07 +0100449 mBootAnimation->resizeSurface(displayMode.resolution.getWidth(),
450 displayMode.resolution.getHeight());
Marin Shalamanov9070c052020-05-18 19:05:17 +0200451 }
452 }
453 } while (numEvents > 0);
454
455 return 1; // keep the callback
456 }
457};
458
459EGLConfig BootAnimation::getEglConfig(const EGLDisplay& display) {
460 const EGLint attribs[] = {
461 EGL_RED_SIZE, 8,
462 EGL_GREEN_SIZE, 8,
463 EGL_BLUE_SIZE, 8,
464 EGL_DEPTH_SIZE, 0,
465 EGL_NONE
466 };
467 EGLint numConfigs;
468 EGLConfig config;
469 eglChooseConfig(display, attribs, &config, 1, &numConfigs);
470 return config;
471}
472
Marin Shalamanov047802d2020-05-19 23:55:12 +0200473ui::Size BootAnimation::limitSurfaceSize(int width, int height) const {
474 ui::Size limited(width, height);
475 bool wasLimited = false;
476 const float aspectRatio = float(width) / float(height);
477 if (mMaxWidth != 0 && width > mMaxWidth) {
478 limited.height = mMaxWidth / aspectRatio;
479 limited.width = mMaxWidth;
480 wasLimited = true;
481 }
482 if (mMaxHeight != 0 && limited.height > mMaxHeight) {
483 limited.height = mMaxHeight;
484 limited.width = mMaxHeight * aspectRatio;
485 wasLimited = true;
486 }
487 SLOGV_IF(wasLimited, "Surface size has been limited to [%dx%d] from [%dx%d]",
488 limited.width, limited.height, width, height);
489 return limited;
490}
491
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492status_t BootAnimation::readyToRun() {
493 mAssets.addDefaultAssets();
494
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800495 mDisplayToken = SurfaceComposerClient::getInternalDisplayToken();
496 if (mDisplayToken == nullptr)
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800497 return NAME_NOT_FOUND;
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800498
Marin Shalamanovcb783ca2021-01-29 21:26:07 +0100499 DisplayMode displayMode;
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800500 const status_t error =
Marin Shalamanovcb783ca2021-01-29 21:26:07 +0100501 SurfaceComposerClient::getActiveDisplayMode(mDisplayToken, &displayMode);
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800502 if (error != NO_ERROR)
503 return error;
504
Marin Shalamanov047802d2020-05-19 23:55:12 +0200505 mMaxWidth = android::base::GetIntProperty("ro.surface_flinger.max_graphics_width", 0);
506 mMaxHeight = android::base::GetIntProperty("ro.surface_flinger.max_graphics_height", 0);
Marin Shalamanovcb783ca2021-01-29 21:26:07 +0100507 ui::Size resolution = displayMode.resolution;
Marin Shalamanov047802d2020-05-19 23:55:12 +0200508 resolution = limitSurfaceSize(resolution.width, resolution.height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 // create the native surface
Jeff Brown0b722fe2012-08-24 22:40:14 -0700510 sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
xi yuc3415442022-05-09 08:58:02 +0000511 resolution.getWidth(), resolution.getHeight(), PIXEL_FORMAT_RGB_565,
512 ISurfaceComposerClient::eOpaque);
Mathias Agopian439863f2011-06-28 19:09:31 -0700513
Robert Carre13b58e2017-08-31 14:50:44 -0700514 SurfaceComposerClient::Transaction t;
Huihong Luof97c9e22019-05-29 11:08:01 -0700515
516 // this guest property specifies multi-display IDs to show the boot animation
517 // multiple ids can be set with comma (,) as separator, for example:
Huihong Luod4a217e2020-01-16 15:56:33 -0800518 // setprop persist.boot.animation.displays 19260422155234049,19261083906282754
Marin Shalamanov11599ee2020-07-27 21:31:48 +0200519 Vector<PhysicalDisplayId> physicalDisplayIds;
Huihong Luof97c9e22019-05-29 11:08:01 -0700520 char displayValue[PROPERTY_VALUE_MAX] = "";
Huihong Luod4a217e2020-01-16 15:56:33 -0800521 property_get(DISPLAYS_PROP_NAME, displayValue, "");
Huihong Luof97c9e22019-05-29 11:08:01 -0700522 bool isValid = displayValue[0] != '\0';
523 if (isValid) {
524 char *p = displayValue;
525 while (*p) {
526 if (!isdigit(*p) && *p != ',') {
527 isValid = false;
528 break;
529 }
530 p ++;
531 }
532 if (!isValid)
Huihong Luod4a217e2020-01-16 15:56:33 -0800533 SLOGE("Invalid syntax for the value of system prop: %s", DISPLAYS_PROP_NAME);
Huihong Luof97c9e22019-05-29 11:08:01 -0700534 }
535 if (isValid) {
536 std::istringstream stream(displayValue);
Marin Shalamanov11599ee2020-07-27 21:31:48 +0200537 for (PhysicalDisplayId id; stream >> id.value; ) {
Huihong Luof97c9e22019-05-29 11:08:01 -0700538 physicalDisplayIds.add(id);
539 if (stream.peek() == ',')
540 stream.ignore();
541 }
542
543 // In the case of multi-display, boot animation shows on the specified displays
544 // in addition to the primary display
Dominik Laskowski989de3d2021-07-27 21:09:34 -0700545 const auto ids = SurfaceComposerClient::getPhysicalDisplayIds();
546 for (const auto id : physicalDisplayIds) {
Huihong Luof97c9e22019-05-29 11:08:01 -0700547 if (std::find(ids.begin(), ids.end(), id) != ids.end()) {
Dominik Laskowski989de3d2021-07-27 21:09:34 -0700548 if (const auto token = SurfaceComposerClient::getPhysicalDisplayToken(id)) {
549 t.setDisplayLayerStack(token, ui::DEFAULT_LAYER_STACK);
550 }
Huihong Luof97c9e22019-05-29 11:08:01 -0700551 }
552 }
Dominik Laskowski989de3d2021-07-27 21:09:34 -0700553 t.setLayerStack(control, ui::DEFAULT_LAYER_STACK);
Huihong Luof97c9e22019-05-29 11:08:01 -0700554 }
555
Robert Carre13b58e2017-08-31 14:50:44 -0700556 t.setLayer(control, 0x40000000)
557 .apply();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558
Mathias Agopian17f638b2009-04-16 20:04:08 -0700559 sp<Surface> s = control->getSurface();
560
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800561 // initialize opengl and egl
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
Yi Kong911ac232019-03-24 01:49:02 -0700563 eglInitialize(display, nullptr, nullptr);
Marin Shalamanov9070c052020-05-18 19:05:17 +0200564 EGLConfig config = getEglConfig(display);
565 EGLSurface surface = eglCreateWindowSurface(display, config, s.get(), nullptr);
Lucas Dupin8eedc022021-07-29 21:49:07 +0000566 // Initialize egl context with client version number 2.0.
567 EGLint contextAttributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
568 EGLContext context = eglCreateContext(display, config, nullptr, contextAttributes);
Marin Shalamanov9070c052020-05-18 19:05:17 +0200569 EGLint w, h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 eglQuerySurface(display, surface, EGL_WIDTH, &w);
571 eglQuerySurface(display, surface, EGL_HEIGHT, &h);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700572
Mathias Agopianabac0102009-07-31 14:47:00 -0700573 if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE)
574 return NO_INIT;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700575
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 mDisplay = display;
577 mContext = context;
578 mSurface = surface;
joenchen764ea042022-04-11 23:58:34 +0800579 mInitWidth = mWidth = w;
580 mInitHeight = mHeight = h;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700581 mFlingerSurfaceControl = control;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800582 mFlingerSurface = s;
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200583 mTargetInset = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800584
Yegor Malyshev6925e1b2020-09-10 16:42:20 +0200585 projectSceneToWindow();
586
Marin Shalamanov9070c052020-05-18 19:05:17 +0200587 // Register a display event receiver
588 mDisplayEventReceiver = std::make_unique<DisplayEventReceiver>();
589 status_t status = mDisplayEventReceiver->initCheck();
590 SLOGE_IF(status != NO_ERROR, "Initialization of DisplayEventReceiver failed with status: %d",
591 status);
592 mLooper->addFd(mDisplayEventReceiver->getFd(), 0, Looper::EVENT_INPUT,
593 new DisplayEventCallback(this), nullptr);
594
Huihong Luo50a2f362018-08-11 09:27:57 -0700595 return NO_ERROR;
596}
597
Yegor Malyshev6925e1b2020-09-10 16:42:20 +0200598void BootAnimation::projectSceneToWindow() {
599 glViewport(0, 0, mWidth, mHeight);
600 glScissor(0, 0, mWidth, mHeight);
Yegor Malyshev6925e1b2020-09-10 16:42:20 +0200601}
602
Marin Shalamanov9070c052020-05-18 19:05:17 +0200603void BootAnimation::resizeSurface(int newWidth, int newHeight) {
604 // We assume this function is called on the animation thread.
605 if (newWidth == mWidth && newHeight == mHeight) {
606 return;
607 }
608 SLOGV("Resizing the boot animation surface to %d %d", newWidth, newHeight);
609
610 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
611 eglDestroySurface(mDisplay, mSurface);
612
joenchen764ea042022-04-11 23:58:34 +0800613 mFlingerSurfaceControl->updateDefaultBufferSize(newWidth, newHeight);
Marin Shalamanov047802d2020-05-19 23:55:12 +0200614 const auto limitedSize = limitSurfaceSize(newWidth, newHeight);
615 mWidth = limitedSize.width;
616 mHeight = limitedSize.height;
Marin Shalamanov9070c052020-05-18 19:05:17 +0200617
Marin Shalamanov9070c052020-05-18 19:05:17 +0200618 EGLConfig config = getEglConfig(mDisplay);
619 EGLSurface surface = eglCreateWindowSurface(mDisplay, config, mFlingerSurface.get(), nullptr);
620 if (eglMakeCurrent(mDisplay, surface, surface, mContext) == EGL_FALSE) {
621 SLOGE("Can't make the new surface current. Error %d", eglGetError());
622 return;
623 }
Yegor Malyshev6925e1b2020-09-10 16:42:20 +0200624
625 projectSceneToWindow();
Marin Shalamanov9070c052020-05-18 19:05:17 +0200626
627 mSurface = surface;
628}
629
Huihong Luo50a2f362018-08-11 09:27:57 -0700630bool BootAnimation::preloadAnimation() {
631 findBootAnimationFile();
632 if (!mZipFileName.isEmpty()) {
633 mAnimation = loadAnimation(mZipFileName);
634 return (mAnimation != nullptr);
635 }
636
637 return false;
638}
639
Nikita Ioffe06c986e2020-01-27 17:16:03 +0000640bool BootAnimation::findBootAnimationFileInternal(const std::vector<std::string> &files) {
641 for (const std::string& f : files) {
642 if (access(f.c_str(), R_OK) == 0) {
643 mZipFileName = f.c_str();
644 return true;
645 }
646 }
647 return false;
648}
649
Huihong Luo50a2f362018-08-11 09:27:57 -0700650void BootAnimation::findBootAnimationFile() {
Beverly34ffe252019-05-17 11:03:54 -0400651 const bool playDarkAnim = android::base::GetIntProperty("ro.boot.theme", 0) == 1;
Nikita Ioffe06c986e2020-01-27 17:16:03 +0000652 static const std::vector<std::string> bootFiles = {
653 APEX_BOOTANIMATION_FILE, playDarkAnim ? PRODUCT_BOOTANIMATION_DARK_FILE : PRODUCT_BOOTANIMATION_FILE,
654 OEM_BOOTANIMATION_FILE, SYSTEM_BOOTANIMATION_FILE
655 };
656 static const std::vector<std::string> shutdownFiles = {
657 PRODUCT_SHUTDOWNANIMATION_FILE, OEM_SHUTDOWNANIMATION_FILE, SYSTEM_SHUTDOWNANIMATION_FILE, ""
658 };
659 static const std::vector<std::string> userspaceRebootFiles = {
660 PRODUCT_USERSPACE_REBOOT_ANIMATION_FILE, OEM_USERSPACE_REBOOT_ANIMATION_FILE,
661 SYSTEM_USERSPACE_REBOOT_ANIMATION_FILE,
662 };
Keun-young Parkb5938422017-03-23 13:46:24 -0700663
Nikita Ioffe06c986e2020-01-27 17:16:03 +0000664 if (android::base::GetBoolProperty("sys.init.userspace_reboot.in_progress", false)) {
665 findBootAnimationFileInternal(userspaceRebootFiles);
666 } else if (mShuttingDown) {
667 findBootAnimationFileInternal(shutdownFiles);
668 } else {
669 findBootAnimationFileInternal(bootFiles);
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700670 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800671}
672
Lucas Dupin8eedc022021-07-29 21:49:07 +0000673GLuint compileShader(GLenum shaderType, const GLchar *source) {
674 GLuint shader = glCreateShader(shaderType);
675 glShaderSource(shader, 1, &source, 0);
676 glCompileShader(shader);
677 GLint isCompiled = 0;
678 glGetShaderiv(shader, GL_COMPILE_STATUS, &isCompiled);
679 if (isCompiled == GL_FALSE) {
680 SLOGE("Compile shader failed. Shader type: %d", shaderType);
Shan Huang81846ba2021-09-07 19:07:47 +0000681 GLint maxLength = 0;
682 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength);
683 std::vector<GLchar> errorLog(maxLength);
684 glGetShaderInfoLog(shader, maxLength, &maxLength, &errorLog[0]);
685 SLOGE("Shader compilation error: %s", &errorLog[0]);
Lucas Dupin8eedc022021-07-29 21:49:07 +0000686 return 0;
687 }
688 return shader;
689}
690
691GLuint linkShader(GLuint vertexShader, GLuint fragmentShader) {
692 GLuint program = glCreateProgram();
693 glAttachShader(program, vertexShader);
694 glAttachShader(program, fragmentShader);
695 glLinkProgram(program);
696 GLint isLinked = 0;
697 glGetProgramiv(program, GL_LINK_STATUS, (int *)&isLinked);
698 if (isLinked == GL_FALSE) {
699 SLOGE("Linking shader failed. Shader handles: vert %d, frag %d",
700 vertexShader, fragmentShader);
701 return 0;
702 }
703 return program;
704}
705
706void BootAnimation::initShaders() {
Shan Huang2b31a362021-08-16 16:45:39 +0000707 bool dynamicColoringEnabled = mAnimation != nullptr && mAnimation->dynamicColoringEnabled;
Lucas Dupin8eedc022021-07-29 21:49:07 +0000708 GLuint vertexShader = compileShader(GL_VERTEX_SHADER, (const GLchar *)VERTEX_SHADER_SOURCE);
709 GLuint imageFragmentShader =
Shan Huang2b31a362021-08-16 16:45:39 +0000710 compileShader(GL_FRAGMENT_SHADER, dynamicColoringEnabled
711 ? (const GLchar *)IMAGE_FRAG_DYNAMIC_COLORING_SHADER_SOURCE
712 : (const GLchar *)IMAGE_FRAG_SHADER_SOURCE);
Lucas Dupin8eedc022021-07-29 21:49:07 +0000713 GLuint textFragmentShader =
714 compileShader(GL_FRAGMENT_SHADER, (const GLchar *)TEXT_FRAG_SHADER_SOURCE);
715
716 // Initialize image shader.
717 mImageShader = linkShader(vertexShader, imageFragmentShader);
718 GLint positionLocation = glGetAttribLocation(mImageShader, A_POSITION);
719 GLint uvLocation = glGetAttribLocation(mImageShader, A_UV);
720 mImageTextureLocation = glGetUniformLocation(mImageShader, U_TEXTURE);
721 mImageFadeLocation = glGetUniformLocation(mImageShader, U_FADE);
722 glEnableVertexAttribArray(positionLocation);
723 glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, quadPositions);
724 glVertexAttribPointer(uvLocation, 2, GL_FLOAT, GL_FALSE, 0, quadUVs);
725 glEnableVertexAttribArray(uvLocation);
726
727 // Initialize text shader.
728 mTextShader = linkShader(vertexShader, textFragmentShader);
729 positionLocation = glGetAttribLocation(mTextShader, A_POSITION);
730 uvLocation = glGetAttribLocation(mTextShader, A_UV);
731 mTextTextureLocation = glGetUniformLocation(mTextShader, U_TEXTURE);
732 mTextCropAreaLocation = glGetUniformLocation(mTextShader, U_CROP_AREA);
733 glEnableVertexAttribArray(positionLocation);
734 glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, quadPositions);
735 glVertexAttribPointer(uvLocation, 2, GL_FLOAT, GL_FALSE, 0, quadUVs);
736 glEnableVertexAttribArray(uvLocation);
737}
738
Marin Shalamanov9070c052020-05-18 19:05:17 +0200739bool BootAnimation::threadLoop() {
740 bool result;
Lucas Dupin8eedc022021-07-29 21:49:07 +0000741 initShaders();
742
Narayan Kamathafd31e02013-12-03 13:16:03 +0000743 // We have no bootanimation file, so we use the stock android logo
744 // animation.
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700745 if (mZipFileName.isEmpty()) {
Yoshiaki Maruoka9ef19b82017-10-25 13:55:49 +0900746 ALOGD("No animation file");
Marin Shalamanov9070c052020-05-18 19:05:17 +0200747 result = android();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700748 } else {
Marin Shalamanov9070c052020-05-18 19:05:17 +0200749 result = movie();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700750 }
751
Philip Junker60600562020-11-25 18:16:16 +0100752 mCallbacks->shutdown();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800753 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
754 eglDestroyContext(mDisplay, mContext);
755 eglDestroySurface(mDisplay, mSurface);
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700756 mFlingerSurface.clear();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700757 mFlingerSurfaceControl.clear();
Mathias Agopian627e7b52009-05-21 19:21:59 -0700758 eglTerminate(mDisplay);
Sai Kiran Korwar3eee9fb2015-06-16 17:13:35 +0530759 eglReleaseThread();
Mathias Agopian627e7b52009-05-21 19:21:59 -0700760 IPCThreadState::self()->stopProcess();
Marin Shalamanov9070c052020-05-18 19:05:17 +0200761 return result;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800762}
763
Marin Shalamanov9070c052020-05-18 19:05:17 +0200764bool BootAnimation::android() {
Lucas Dupin8eedc022021-07-29 21:49:07 +0000765 glActiveTexture(GL_TEXTURE0);
766
Wei Wang159a4102018-10-23 23:15:58 -0700767 SLOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
Keun-young Parkd1794cd2017-04-04 12:21:19 -0700768 elapsedRealtime());
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700769 initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png");
770 initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800771
Ed Coyne7464ac92017-06-08 12:26:48 -0700772 mCallbacks->init({});
773
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800774 // clear screen
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700775 glDisable(GL_DITHER);
776 glDisable(GL_SCISSOR_TEST);
Shan Huangbfd2d3c2021-09-09 23:19:04 +0000777 glUseProgram(mImageShader);
778
Mathias Agopian59f19e42011-05-06 19:22:12 -0700779 glClearColor(0,0,0,1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800780 glClear(GL_COLOR_BUFFER_BIT);
781 eglSwapBuffers(mDisplay, mSurface);
782
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700783 // Blend state
784 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800786 const nsecs_t startTime = systemTime();
787 do {
Marin Shalamanov9070c052020-05-18 19:05:17 +0200788 processDisplayEvents();
789 const GLint xc = (mWidth - mAndroid[0].w) / 2;
790 const GLint yc = (mHeight - mAndroid[0].h) / 2;
791 const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h);
792 glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(),
793 updateRect.height());
794
Mathias Agopian13796652009-03-24 22:49:21 -0700795 nsecs_t now = systemTime();
796 double time = now - startTime;
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700797 float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w;
798 GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w;
799 GLint x = xc - offset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800800
Mathias Agopian81668642009-07-28 11:41:30 -0700801 glDisable(GL_SCISSOR_TEST);
802 glClear(GL_COLOR_BUFFER_BIT);
803
804 glEnable(GL_SCISSOR_TEST);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800805 glDisable(GL_BLEND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 glBindTexture(GL_TEXTURE_2D, mAndroid[1].name);
Lucas Dupin8eedc022021-07-29 21:49:07 +0000807 drawTexturedQuad(x, yc, mAndroid[1].w, mAndroid[1].h);
808 drawTexturedQuad(x + mAndroid[1].w, yc, mAndroid[1].w, mAndroid[1].h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800809
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700810 glEnable(GL_BLEND);
811 glBindTexture(GL_TEXTURE_2D, mAndroid[0].name);
Lucas Dupin8eedc022021-07-29 21:49:07 +0000812 drawTexturedQuad(xc, yc, mAndroid[0].w, mAndroid[0].h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800813
Mathias Agopian627e7b52009-05-21 19:21:59 -0700814 EGLBoolean res = eglSwapBuffers(mDisplay, mSurface);
815 if (res == EGL_FALSE)
816 break;
817
Mathias Agopian13796652009-03-24 22:49:21 -0700818 // 12fps: don't animate too fast to preserve CPU
819 const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now);
820 if (sleepTime > 0)
Mathias Agopiana8826d62009-10-01 03:10:14 -0700821 usleep(sleepTime);
Kevin Hesterd3782b22012-04-26 10:38:55 -0700822
823 checkExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 } while (!exitPending());
825
826 glDeleteTextures(1, &mAndroid[0].name);
827 glDeleteTextures(1, &mAndroid[1].name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 return false;
829}
830
Kevin Hesterd3782b22012-04-26 10:38:55 -0700831void BootAnimation::checkExit() {
832 // Allow surface flinger to gracefully request shutdown
833 char value[PROPERTY_VALUE_MAX];
834 property_get(EXIT_PROP_NAME, value, "0");
835 int exitnow = atoi(value);
836 if (exitnow) {
837 requestExit();
838 }
839}
840
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700841bool BootAnimation::validClock(const Animation::Part& part) {
842 return part.clockPosX != TEXT_MISSING_VALUE && part.clockPosY != TEXT_MISSING_VALUE;
843}
844
845bool parseTextCoord(const char* str, int* dest) {
846 if (strcmp("c", str) == 0) {
847 *dest = TEXT_CENTER_VALUE;
848 return true;
849 }
850
851 char* end;
852 int val = (int) strtol(str, &end, 0);
853 if (end == str || *end != '\0' || val == INT_MAX || val == INT_MIN) {
854 return false;
855 }
856 *dest = val;
857 return true;
858}
859
860// Parse two position coordinates. If only string is non-empty, treat it as the y value.
861void parsePosition(const char* str1, const char* str2, int* x, int* y) {
862 bool success = false;
863 if (strlen(str1) == 0) { // No values were specified
864 // success = false
865 } else if (strlen(str2) == 0) { // we have only one value
866 if (parseTextCoord(str1, y)) {
867 *x = TEXT_CENTER_VALUE;
868 success = true;
869 }
870 } else {
871 if (parseTextCoord(str1, x) && parseTextCoord(str2, y)) {
872 success = true;
873 }
874 }
875
876 if (!success) {
877 *x = TEXT_MISSING_VALUE;
878 *y = TEXT_MISSING_VALUE;
879 }
880}
881
Jesse Hall083b84c2014-09-22 10:51:09 -0700882// Parse a color represented as an HTML-style 'RRGGBB' string: each pair of
883// characters in str is a hex number in [0, 255], which are converted to
884// floating point values in the range [0.0, 1.0] and placed in the
885// corresponding elements of color.
886//
887// If the input string isn't valid, parseColor returns false and color is
888// left unchanged.
889static bool parseColor(const char str[7], float color[3]) {
890 float tmpColor[3];
891 for (int i = 0; i < 3; i++) {
892 int val = 0;
893 for (int j = 0; j < 2; j++) {
894 val *= 16;
895 char c = str[2*i + j];
896 if (c >= '0' && c <= '9') val += c - '0';
897 else if (c >= 'A' && c <= 'F') val += (c - 'A') + 10;
898 else if (c >= 'a' && c <= 'f') val += (c - 'a') + 10;
899 else return false;
900 }
901 tmpColor[i] = static_cast<float>(val) / 255.0f;
902 }
903 memcpy(color, tmpColor, sizeof(tmpColor));
904 return true;
905}
906
Shan Huang2b31a362021-08-16 16:45:39 +0000907// Parse a color represented as a signed decimal int string.
908// E.g. "-2757722" (whose hex 2's complement is 0xFFD5EBA6).
909// If the input color string is empty, set color with values in defaultColor.
910static void parseColorDecimalString(const std::string& colorString,
911 float color[3], float defaultColor[3]) {
912 if (colorString == "") {
913 memcpy(color, defaultColor, sizeof(float) * 3);
914 return;
915 }
916 int colorInt = atoi(colorString.c_str());
917 color[0] = ((float)((colorInt >> 16) & 0xFF)) / 0xFF; // r
918 color[1] = ((float)((colorInt >> 8) & 0xFF)) / 0xFF; // g
919 color[2] = ((float)(colorInt & 0xFF)) / 0xFF; // b
920}
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700921
Marin Shalamanov9070c052020-05-18 19:05:17 +0200922static bool readFile(ZipFileRO* zip, const char* name, String8& outString) {
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700923 ZipEntryRO entry = zip->findEntryByName(name);
Wei Wang159a4102018-10-23 23:15:58 -0700924 SLOGE_IF(!entry, "couldn't find %s", name);
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700925 if (!entry) {
926 return false;
927 }
928
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700929 FileMap* entryMap = zip->createEntryFileMap(entry);
930 zip->releaseEntry(entry);
Wei Wang159a4102018-10-23 23:15:58 -0700931 SLOGE_IF(!entryMap, "entryMap is null");
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700932 if (!entryMap) {
933 return false;
934 }
935
936 outString.setTo((char const*)entryMap->getDataPtr(), entryMap->getDataLength());
Narayan Kamath688ff4c2015-02-23 15:47:54 +0000937 delete entryMap;
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700938 return true;
939}
940
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700941// The font image should be a 96x2 array of character images. The
942// columns are the printable ASCII characters 0x20 - 0x7f. The
943// top row is regular text; the bottom row is bold.
944status_t BootAnimation::initFont(Font* font, const char* fallback) {
945 status_t status = NO_ERROR;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800946
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700947 if (font->map != nullptr) {
948 glGenTextures(1, &font->texture.name);
949 glBindTexture(GL_TEXTURE_2D, font->texture.name);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800950
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700951 status = initTexture(font->map, &font->texture.w, &font->texture.h);
952
Lucas Dupin8eedc022021-07-29 21:49:07 +0000953 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
954 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
955 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
956 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700957 } else if (fallback != nullptr) {
958 status = initTexture(&font->texture, mAssets, fallback);
959 } else {
960 return NO_INIT;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800961 }
962
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700963 if (status == NO_ERROR) {
964 font->char_width = font->texture.w / FONT_NUM_COLS;
965 font->char_height = font->texture.h / FONT_NUM_ROWS / 2; // There are bold and regular rows
966 }
967
968 return status;
969}
970
971void BootAnimation::drawText(const char* str, const Font& font, bool bold, int* x, int* y) {
972 glEnable(GL_BLEND); // Allow us to draw on top of the animation
973 glBindTexture(GL_TEXTURE_2D, font.texture.name);
Lucas Dupin8eedc022021-07-29 21:49:07 +0000974 glUseProgram(mTextShader);
975 glUniform1i(mTextTextureLocation, 0);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700976
977 const int len = strlen(str);
978 const int strWidth = font.char_width * len;
979
980 if (*x == TEXT_CENTER_VALUE) {
981 *x = (mWidth - strWidth) / 2;
982 } else if (*x < 0) {
983 *x = mWidth + *x - strWidth;
984 }
985 if (*y == TEXT_CENTER_VALUE) {
986 *y = (mHeight - font.char_height) / 2;
987 } else if (*y < 0) {
988 *y = mHeight + *y - font.char_height;
989 }
990
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700991 for (int i = 0; i < len; i++) {
992 char c = str[i];
993
994 if (c < FONT_BEGIN_CHAR || c > FONT_END_CHAR) {
995 c = '?';
996 }
997
998 // Crop the texture to only the pixels in the current glyph
999 const int charPos = (c - FONT_BEGIN_CHAR); // Position in the list of valid characters
1000 const int row = charPos / FONT_NUM_COLS;
1001 const int col = charPos % FONT_NUM_COLS;
Lucas Dupin8eedc022021-07-29 21:49:07 +00001002 // Bold fonts are expected in the second half of each row.
1003 float v0 = (row + (bold ? 0.5f : 0.0f)) / FONT_NUM_ROWS;
1004 float u0 = ((float)col) / FONT_NUM_COLS;
1005 float v1 = v0 + 1.0f / FONT_NUM_ROWS / 2;
1006 float u1 = u0 + 1.0f / FONT_NUM_COLS;
1007 glUniform4f(mTextCropAreaLocation, u0, v0, u1, v1);
1008 drawTexturedQuad(*x, *y, font.char_width, font.char_height);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001009
1010 *x += font.char_width;
1011 }
1012
1013 glDisable(GL_BLEND); // Return to the animation's default behaviour
1014 glBindTexture(GL_TEXTURE_2D, 0);
1015}
1016
Damien Bargiacchi9071db12016-10-28 17:38:22 -07001017// We render 12 or 24 hour time.
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001018void BootAnimation::drawClock(const Font& font, const int xPos, const int yPos) {
Damien Bargiacchi9071db12016-10-28 17:38:22 -07001019 static constexpr char TIME_FORMAT_12[] = "%l:%M";
1020 static constexpr char TIME_FORMAT_24[] = "%H:%M";
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001021 static constexpr int TIME_LENGTH = 6;
1022
Damien Bargiacchia704b7d2016-02-16 16:55:49 -08001023 time_t rawtime;
1024 time(&rawtime);
1025 struct tm* timeInfo = localtime(&rawtime);
1026
1027 char timeBuff[TIME_LENGTH];
Damien Bargiacchi9071db12016-10-28 17:38:22 -07001028 const char* timeFormat = mTimeFormat12Hour ? TIME_FORMAT_12 : TIME_FORMAT_24;
1029 size_t length = strftime(timeBuff, TIME_LENGTH, timeFormat, timeInfo);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -08001030
1031 if (length != TIME_LENGTH - 1) {
Wei Wang159a4102018-10-23 23:15:58 -07001032 SLOGE("Couldn't format time; abandoning boot animation clock");
Damien Bargiacchia704b7d2016-02-16 16:55:49 -08001033 mClockEnabled = false;
1034 return;
1035 }
1036
Damien Bargiacchi45a76442016-12-05 18:02:18 -08001037 char* out = timeBuff[0] == ' ' ? &timeBuff[1] : &timeBuff[0];
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001038 int x = xPos;
1039 int y = yPos;
Damien Bargiacchi45a76442016-12-05 18:02:18 -08001040 drawText(out, font, false, &x, &y);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -08001041}
1042
Nicolas Geoffray41fffb42020-12-15 10:50:29 +00001043void BootAnimation::drawProgress(int percent, const Font& font, const int xPos, const int yPos) {
1044 static constexpr int PERCENT_LENGTH = 5;
1045
1046 char percentBuff[PERCENT_LENGTH];
1047 // ';' has the ascii code just after ':', and the font resource contains '%'
1048 // for that ascii code.
1049 sprintf(percentBuff, "%d;", percent);
1050 int x = xPos;
1051 int y = yPos;
1052 drawText(percentBuff, font, false, &x, &y);
1053}
1054
Marin Shalamanov9070c052020-05-18 19:05:17 +02001055bool BootAnimation::parseAnimationDesc(Animation& animation) {
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -07001056 String8 desString;
1057
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001058 if (!readFile(animation.zip, "desc.txt", desString)) {
Narayan Kamathafd31e02013-12-03 13:16:03 +00001059 return false;
1060 }
Mathias Agopiana8826d62009-10-01 03:10:14 -07001061 char const* s = desString.string();
Shan Huang2b31a362021-08-16 16:45:39 +00001062 std::string dynamicColoringPartName = "";
1063 bool postDynamicColoring = false;
Mathias Agopiana8826d62009-10-01 03:10:14 -07001064
Mathias Agopiana8826d62009-10-01 03:10:14 -07001065 // Parse the description file
1066 for (;;) {
1067 const char* endl = strstr(s, "\n");
Yi Kong911ac232019-03-24 01:49:02 -07001068 if (endl == nullptr) break;
Mathias Agopiana8826d62009-10-01 03:10:14 -07001069 String8 line(s, endl - s);
1070 const char* l = line.string();
Damien Bargiacchia704b7d2016-02-16 16:55:49 -08001071 int fps = 0;
1072 int width = 0;
1073 int height = 0;
1074 int count = 0;
1075 int pause = 0;
Nicolas Geoffray41fffb42020-12-15 10:50:29 +00001076 int progress = 0;
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001077 int framesToFadeCount = 0;
Shan Huang488ff742021-08-25 20:10:46 +00001078 int colorTransitionStart = 0;
1079 int colorTransitionEnd = 0;
Narayan Kamathafd31e02013-12-03 13:16:03 +00001080 char path[ANIM_ENTRY_NAME_MAX];
Jesse Hall083b84c2014-09-22 10:51:09 -07001081 char color[7] = "000000"; // default to black if unspecified
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001082 char clockPos1[TEXT_POS_LEN_MAX + 1] = "";
1083 char clockPos2[TEXT_POS_LEN_MAX + 1] = "";
Shan Huang2b31a362021-08-16 16:45:39 +00001084 char dynamicColoringPartNameBuffer[ANIM_ENTRY_NAME_MAX];
Kevin Hesterd3782b22012-04-26 10:38:55 -07001085 char pathType;
Shan Huang2b31a362021-08-16 16:45:39 +00001086 // start colors default to black if unspecified
1087 char start_color_0[7] = "000000";
1088 char start_color_1[7] = "000000";
1089 char start_color_2[7] = "000000";
1090 char start_color_3[7] = "000000";
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001091
1092 int nextReadPos;
1093
Nicolas Geoffray41fffb42020-12-15 10:50:29 +00001094 int topLineNumbers = sscanf(l, "%d %d %d %d", &width, &height, &fps, &progress);
1095 if (topLineNumbers == 3 || topLineNumbers == 4) {
1096 // SLOGD("> w=%d, h=%d, fps=%d, progress=%d", width, height, fps, progress);
Mathias Agopiana8826d62009-10-01 03:10:14 -07001097 animation.width = width;
1098 animation.height = height;
1099 animation.fps = fps;
Nicolas Geoffray41fffb42020-12-15 10:50:29 +00001100 if (topLineNumbers == 4) {
1101 animation.progressEnabled = (progress != 0);
1102 } else {
1103 animation.progressEnabled = false;
1104 }
Shan Huang488ff742021-08-25 20:10:46 +00001105 } else if (sscanf(l, "dynamic_colors %" STRTO(ANIM_PATH_MAX) "s #%6s #%6s #%6s #%6s %d %d",
Shan Huang2b31a362021-08-16 16:45:39 +00001106 dynamicColoringPartNameBuffer,
Shan Huang488ff742021-08-25 20:10:46 +00001107 start_color_0, start_color_1, start_color_2, start_color_3,
1108 &colorTransitionStart, &colorTransitionEnd)) {
Shan Huang2b31a362021-08-16 16:45:39 +00001109 animation.dynamicColoringEnabled = true;
1110 parseColor(start_color_0, animation.startColors[0]);
1111 parseColor(start_color_1, animation.startColors[1]);
1112 parseColor(start_color_2, animation.startColors[2]);
1113 parseColor(start_color_3, animation.startColors[3]);
Shan Huang488ff742021-08-25 20:10:46 +00001114 animation.colorTransitionStart = colorTransitionStart;
1115 animation.colorTransitionEnd = colorTransitionEnd;
Shan Huang2b31a362021-08-16 16:45:39 +00001116 dynamicColoringPartName = std::string(dynamicColoringPartNameBuffer);
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001117 } else if (sscanf(l, "%c %d %d %" STRTO(ANIM_PATH_MAX) "s%n",
1118 &pathType, &count, &pause, path, &nextReadPos) >= 4) {
1119 if (pathType == 'f') {
1120 sscanf(l + nextReadPos, " %d #%6s %16s %16s", &framesToFadeCount, color, clockPos1,
1121 clockPos2);
1122 } else {
1123 sscanf(l + nextReadPos, " #%6s %16s %16s", color, clockPos1, clockPos2);
1124 }
1125 // SLOGD("> type=%c, count=%d, pause=%d, path=%s, framesToFadeCount=%d, color=%s, "
1126 // "clockPos1=%s, clockPos2=%s",
1127 // pathType, count, pause, path, framesToFadeCount, color, clockPos1, clockPos2);
Mathias Agopiana8826d62009-10-01 03:10:14 -07001128 Animation::Part part;
Shan Huang2b31a362021-08-16 16:45:39 +00001129 if (path == dynamicColoringPartName) {
1130 // Part is specified to use dynamic coloring.
1131 part.useDynamicColoring = true;
1132 part.postDynamicColoring = false;
1133 postDynamicColoring = true;
1134 } else {
1135 // Part does not use dynamic coloring.
1136 part.useDynamicColoring = false;
1137 part.postDynamicColoring = postDynamicColoring;
1138 }
Kevin Hesterd3782b22012-04-26 10:38:55 -07001139 part.playUntilComplete = pathType == 'c';
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001140 part.framesToFadeCount = framesToFadeCount;
Mathias Agopiana8826d62009-10-01 03:10:14 -07001141 part.count = count;
1142 part.pause = pause;
1143 part.path = path;
Yi Kong911ac232019-03-24 01:49:02 -07001144 part.audioData = nullptr;
1145 part.animation = nullptr;
Jesse Hall083b84c2014-09-22 10:51:09 -07001146 if (!parseColor(color, part.backgroundColor)) {
Wei Wang159a4102018-10-23 23:15:58 -07001147 SLOGE("> invalid color '#%s'", color);
Jesse Hall083b84c2014-09-22 10:51:09 -07001148 part.backgroundColor[0] = 0.0f;
1149 part.backgroundColor[1] = 0.0f;
1150 part.backgroundColor[2] = 0.0f;
1151 }
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001152 parsePosition(clockPos1, clockPos2, &part.clockPosX, &part.clockPosY);
Mathias Agopiana8826d62009-10-01 03:10:14 -07001153 animation.parts.add(part);
1154 }
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001155 else if (strcmp(l, "$SYSTEM") == 0) {
Wei Wang159a4102018-10-23 23:15:58 -07001156 // SLOGD("> SYSTEM");
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001157 Animation::Part part;
1158 part.playUntilComplete = false;
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001159 part.framesToFadeCount = 0;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001160 part.count = 1;
1161 part.pause = 0;
Yi Kong911ac232019-03-24 01:49:02 -07001162 part.audioData = nullptr;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001163 part.animation = loadAnimation(String8(SYSTEM_BOOTANIMATION_FILE));
Yi Kong911ac232019-03-24 01:49:02 -07001164 if (part.animation != nullptr)
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001165 animation.parts.add(part);
1166 }
Mathias Agopiana8826d62009-10-01 03:10:14 -07001167 s = ++endl;
1168 }
1169
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001170 return true;
1171}
1172
Marin Shalamanov9070c052020-05-18 19:05:17 +02001173bool BootAnimation::preloadZip(Animation& animation) {
Mathias Agopiana8826d62009-10-01 03:10:14 -07001174 // read all the data structures
1175 const size_t pcount = animation.parts.size();
Yi Kong911ac232019-03-24 01:49:02 -07001176 void *cookie = nullptr;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001177 ZipFileRO* zip = animation.zip;
1178 if (!zip->startIteration(&cookie)) {
Narayan Kamathafd31e02013-12-03 13:16:03 +00001179 return false;
1180 }
1181
1182 ZipEntryRO entry;
1183 char name[ANIM_ENTRY_NAME_MAX];
Yi Kong911ac232019-03-24 01:49:02 -07001184 while ((entry = zip->nextEntry(cookie)) != nullptr) {
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001185 const int foundEntryName = zip->getEntryFileName(entry, name, ANIM_ENTRY_NAME_MAX);
Narayan Kamathafd31e02013-12-03 13:16:03 +00001186 if (foundEntryName > ANIM_ENTRY_NAME_MAX || foundEntryName == -1) {
Wei Wang159a4102018-10-23 23:15:58 -07001187 SLOGE("Error fetching entry file name");
Narayan Kamathafd31e02013-12-03 13:16:03 +00001188 continue;
1189 }
1190
1191 const String8 entryName(name);
1192 const String8 path(entryName.getPathDir());
1193 const String8 leaf(entryName.getPathLeaf());
1194 if (leaf.size() > 0) {
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001195 if (entryName == CLOCK_FONT_ZIP_NAME) {
1196 FileMap* map = zip->createEntryFileMap(entry);
1197 if (map) {
1198 animation.clockFont.map = map;
1199 }
1200 continue;
1201 }
1202
Nicolas Geoffray41fffb42020-12-15 10:50:29 +00001203 if (entryName == PROGRESS_FONT_ZIP_NAME) {
1204 FileMap* map = zip->createEntryFileMap(entry);
1205 if (map) {
1206 animation.progressFont.map = map;
1207 }
1208 continue;
1209 }
1210
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001211 for (size_t j = 0; j < pcount; j++) {
Narayan Kamathafd31e02013-12-03 13:16:03 +00001212 if (path == animation.parts[j].path) {
Narayan Kamath4600dd02015-06-16 12:02:57 +01001213 uint16_t method;
Narayan Kamathafd31e02013-12-03 13:16:03 +00001214 // supports only stored png files
Yi Kong911ac232019-03-24 01:49:02 -07001215 if (zip->getEntryInfo(entry, &method, nullptr, nullptr, nullptr, nullptr, nullptr)) {
Narayan Kamathafd31e02013-12-03 13:16:03 +00001216 if (method == ZipFileRO::kCompressStored) {
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001217 FileMap* map = zip->createEntryFileMap(entry);
Narayan Kamathafd31e02013-12-03 13:16:03 +00001218 if (map) {
Narayan Kamathafd31e02013-12-03 13:16:03 +00001219 Animation::Part& part(animation.parts.editItemAt(j));
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -07001220 if (leaf == "audio.wav") {
1221 // a part may have at most one audio file
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -07001222 part.audioData = (uint8_t *)map->getDataPtr();
1223 part.audioLength = map->getDataLength();
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001224 } else if (leaf == "trim.txt") {
1225 part.trimData.setTo((char const*)map->getDataPtr(),
1226 map->getDataLength());
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -07001227 } else {
1228 Animation::Frame frame;
1229 frame.name = leaf;
1230 frame.map = map;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001231 frame.trimWidth = animation.width;
1232 frame.trimHeight = animation.height;
1233 frame.trimX = 0;
1234 frame.trimY = 0;
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -07001235 part.frames.add(frame);
1236 }
Mathias Agopiana8826d62009-10-01 03:10:14 -07001237 }
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -07001238 } else {
Wei Wang159a4102018-10-23 23:15:58 -07001239 SLOGE("bootanimation.zip is compressed; must be only stored");
Mathias Agopiana8826d62009-10-01 03:10:14 -07001240 }
1241 }
1242 }
1243 }
1244 }
1245 }
1246
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001247 // If there is trimData present, override the positioning defaults.
1248 for (Animation::Part& part : animation.parts) {
1249 const char* trimDataStr = part.trimData.string();
1250 for (size_t frameIdx = 0; frameIdx < part.frames.size(); frameIdx++) {
1251 const char* endl = strstr(trimDataStr, "\n");
1252 // No more trimData for this part.
Yi Kong911ac232019-03-24 01:49:02 -07001253 if (endl == nullptr) {
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001254 break;
1255 }
1256 String8 line(trimDataStr, endl - trimDataStr);
1257 const char* lineStr = line.string();
1258 trimDataStr = ++endl;
1259 int width = 0, height = 0, x = 0, y = 0;
1260 if (sscanf(lineStr, "%dx%d+%d+%d", &width, &height, &x, &y) == 4) {
1261 Animation::Frame& frame(part.frames.editItemAt(frameIdx));
1262 frame.trimWidth = width;
1263 frame.trimHeight = height;
1264 frame.trimX = x;
1265 frame.trimY = y;
1266 } else {
Wei Wang159a4102018-10-23 23:15:58 -07001267 SLOGE("Error parsing trim.txt, line: %s", lineStr);
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001268 break;
1269 }
1270 }
1271 }
1272
1273 zip->endIteration(cookie);
Narayan Kamathafd31e02013-12-03 13:16:03 +00001274
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001275 return true;
1276}
1277
Marin Shalamanov9070c052020-05-18 19:05:17 +02001278bool BootAnimation::movie() {
Huihong Luo50a2f362018-08-11 09:27:57 -07001279 if (mAnimation == nullptr) {
1280 mAnimation = loadAnimation(mZipFileName);
1281 }
1282
1283 if (mAnimation == nullptr)
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001284 return false;
1285
Huihong Luo50a2f362018-08-11 09:27:57 -07001286 // mCallbacks->init() may get called recursively,
1287 // this loop is needed to get the same results
1288 for (const Animation::Part& part : mAnimation->parts) {
1289 if (part.animation != nullptr) {
1290 mCallbacks->init(part.animation->parts);
1291 }
1292 }
1293 mCallbacks->init(mAnimation->parts);
1294
Damien Bargiacchi97480862016-03-29 14:55:55 -07001295 bool anyPartHasClock = false;
Huihong Luo50a2f362018-08-11 09:27:57 -07001296 for (size_t i=0; i < mAnimation->parts.size(); i++) {
1297 if(validClock(mAnimation->parts[i])) {
Damien Bargiacchi97480862016-03-29 14:55:55 -07001298 anyPartHasClock = true;
1299 break;
1300 }
1301 }
1302 if (!anyPartHasClock) {
1303 mClockEnabled = false;
Thiébaud Weksteen08de4432021-11-18 13:25:59 +11001304 } else if (!android::base::GetBoolProperty(CLOCK_ENABLED_PROP_NAME, false)) {
1305 mClockEnabled = false;
Damien Bargiacchi97480862016-03-29 14:55:55 -07001306 }
1307
Sai Kiran Korwar27167492015-07-07 20:00:06 +05301308 // Check if npot textures are supported
1309 mUseNpotTextures = false;
1310 String8 gl_extensions;
1311 const char* exts = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
1312 if (!exts) {
1313 glGetError();
1314 } else {
1315 gl_extensions.setTo(exts);
1316 if ((gl_extensions.find("GL_ARB_texture_non_power_of_two") != -1) ||
1317 (gl_extensions.find("GL_OES_texture_npot") != -1)) {
1318 mUseNpotTextures = true;
1319 }
1320 }
1321
Damien Bargiacchia704b7d2016-02-16 16:55:49 -08001322 // Blend required to draw time on top of animation frames.
1323 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopiana8826d62009-10-01 03:10:14 -07001324 glDisable(GL_DITHER);
1325 glDisable(GL_SCISSOR_TEST);
1326 glDisable(GL_BLEND);
Mathias Agopiana8826d62009-10-01 03:10:14 -07001327
Greg Kaiser2ded8002021-07-19 17:03:27 +00001328 glEnable(GL_TEXTURE_2D);
Lucas Dupin8eedc022021-07-29 21:49:07 +00001329 glBindTexture(GL_TEXTURE_2D, 0);
1330 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1331 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1332 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1333 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001334 bool clockFontInitialized = false;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -08001335 if (mClockEnabled) {
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001336 clockFontInitialized =
Huihong Luo50a2f362018-08-11 09:27:57 -07001337 (initFont(&mAnimation->clockFont, CLOCK_FONT_ASSET) == NO_ERROR);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001338 mClockEnabled = clockFontInitialized;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -08001339 }
1340
Nicolas Geoffray41fffb42020-12-15 10:50:29 +00001341 initFont(&mAnimation->progressFont, PROGRESS_FONT_ASSET);
1342
Damien Bargiacchi97480862016-03-29 14:55:55 -07001343 if (mClockEnabled && !updateIsTimeAccurate()) {
1344 mTimeCheckThread = new TimeCheckThread(this);
1345 mTimeCheckThread->run("BootAnimation::TimeCheckThread", PRIORITY_NORMAL);
1346 }
1347
George Burgess IV0f8e8112021-08-23 17:32:23 -07001348 if (mAnimation->dynamicColoringEnabled) {
Shan Huang7fee3522021-08-18 00:56:08 +00001349 initDynamicColors();
1350 }
1351
Huihong Luo50a2f362018-08-11 09:27:57 -07001352 playAnimation(*mAnimation);
Damien Bargiacchi97480862016-03-29 14:55:55 -07001353
Geoffrey Pitscha9173532016-07-19 14:56:39 -04001354 if (mTimeCheckThread != nullptr) {
Damien Bargiacchi97480862016-03-29 14:55:55 -07001355 mTimeCheckThread->requestExit();
Geoffrey Pitscha9173532016-07-19 14:56:39 -04001356 mTimeCheckThread = nullptr;
1357 }
1358
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001359 if (clockFontInitialized) {
Huihong Luo50a2f362018-08-11 09:27:57 -07001360 glDeleteTextures(1, &mAnimation->clockFont.texture.name);
Andriy Naborskyy815e51d2016-03-24 16:43:34 -07001361 }
1362
Huihong Luo50a2f362018-08-11 09:27:57 -07001363 releaseAnimation(mAnimation);
1364 mAnimation = nullptr;
Damien Bargiacchi1a8a2132018-07-24 15:20:26 -07001365
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001366 return false;
1367}
1368
Nicolas Geoffraya1298752021-04-20 15:15:06 +01001369bool BootAnimation::shouldStopPlayingPart(const Animation::Part& part,
1370 const int fadedFramesCount,
1371 const int lastDisplayedProgress) {
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001372 // stop playing only if it is time to exit and it's a partial part which has been faded out
Nicolas Geoffraya1298752021-04-20 15:15:06 +01001373 return exitPending() && !part.playUntilComplete && fadedFramesCount >= part.framesToFadeCount &&
1374 (lastDisplayedProgress == 0 || lastDisplayedProgress == 100);
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001375}
1376
Lucas Dupin8eedc022021-07-29 21:49:07 +00001377// Linear mapping from range <a1, a2> to range <b1, b2>
1378float mapLinear(float x, float a1, float a2, float b1, float b2) {
1379 return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
1380}
1381
1382void BootAnimation::drawTexturedQuad(float xStart, float yStart, float width, float height) {
1383 // Map coordinates from screen space to world space.
1384 float x0 = mapLinear(xStart, 0, mWidth, -1, 1);
1385 float y0 = mapLinear(yStart, 0, mHeight, -1, 1);
1386 float x1 = mapLinear(xStart + width, 0, mWidth, -1, 1);
1387 float y1 = mapLinear(yStart + height, 0, mHeight, -1, 1);
1388 // Update quad vertex positions.
1389 quadPositions[0] = x0;
1390 quadPositions[1] = y0;
1391 quadPositions[2] = x1;
1392 quadPositions[3] = y0;
1393 quadPositions[4] = x1;
1394 quadPositions[5] = y1;
1395 quadPositions[6] = x1;
1396 quadPositions[7] = y1;
1397 quadPositions[8] = x0;
1398 quadPositions[9] = y1;
1399 quadPositions[10] = x0;
1400 quadPositions[11] = y0;
1401 glDrawArrays(GL_TRIANGLES, 0,
1402 sizeof(quadPositions) / sizeof(quadPositions[0]) / 2);
1403}
1404
Shan Huang7fee3522021-08-18 00:56:08 +00001405void BootAnimation::initDynamicColors() {
1406 for (int i = 0; i < DYNAMIC_COLOR_COUNT; i++) {
Lucas Dupincd256842022-03-29 15:46:36 -07001407 const auto syspropName = "persist.bootanim.color" + std::to_string(i + 1);
1408 const auto syspropValue = android::base::GetProperty(syspropName, "");
1409 if (syspropValue != "") {
1410 SLOGI("Loaded dynamic color: %s -> %s", syspropName.c_str(), syspropValue.c_str());
1411 mDynamicColorsApplied = true;
1412 }
1413 parseColorDecimalString(syspropValue,
Shan Huang7fee3522021-08-18 00:56:08 +00001414 mAnimation->endColors[i], mAnimation->startColors[i]);
1415 }
1416 glUseProgram(mImageShader);
Lucas Dupincd256842022-03-29 15:46:36 -07001417 SLOGI("Dynamically coloring boot animation. Sysprops loaded? %i", mDynamicColorsApplied);
Shan Huang7fee3522021-08-18 00:56:08 +00001418 for (int i = 0; i < DYNAMIC_COLOR_COUNT; i++) {
1419 float *startColor = mAnimation->startColors[i];
1420 float *endColor = mAnimation->endColors[i];
1421 glUniform4f(glGetUniformLocation(mImageShader,
1422 (U_START_COLOR_PREFIX + std::to_string(i)).c_str()),
1423 startColor[0], startColor[1], startColor[2], 1 /* alpha */);
1424 glUniform4f(glGetUniformLocation(mImageShader,
1425 (U_END_COLOR_PREFIX + std::to_string(i)).c_str()),
1426 endColor[0], endColor[1], endColor[2], 1 /* alpha */);
1427 }
1428 mImageColorProgressLocation = glGetUniformLocation(mImageShader, U_COLOR_PROGRESS);
1429}
1430
Marin Shalamanov9070c052020-05-18 19:05:17 +02001431bool BootAnimation::playAnimation(const Animation& animation) {
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001432 const size_t pcount = animation.parts.size();
Mathias Agopiana8826d62009-10-01 03:10:14 -07001433 nsecs_t frameDuration = s2ns(1) / animation.fps;
Mathias Agopian9f3020d2009-11-06 16:30:18 -08001434
Wei Wang159a4102018-10-23 23:15:58 -07001435 SLOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
Keun-young Parkd1794cd2017-04-04 12:21:19 -07001436 elapsedRealtime());
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001437
1438 int fadedFramesCount = 0;
Nicolas Geoffray41fffb42020-12-15 10:50:29 +00001439 int lastDisplayedProgress = 0;
Lucas Dupinbfd18122022-04-25 11:26:08 -07001440 int colorTransitionStart = animation.colorTransitionStart;
1441 int colorTransitionEnd = animation.colorTransitionEnd;
Narayan Kamathafd31e02013-12-03 13:16:03 +00001442 for (size_t i=0 ; i<pcount ; i++) {
Mathias Agopiana8826d62009-10-01 03:10:14 -07001443 const Animation::Part& part(animation.parts[i]);
1444 const size_t fcount = part.frames.size();
Mathias Agopiana8826d62009-10-01 03:10:14 -07001445
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001446 // Handle animation package
Yi Kong911ac232019-03-24 01:49:02 -07001447 if (part.animation != nullptr) {
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001448 playAnimation(*part.animation);
1449 if (exitPending())
1450 break;
1451 continue; //to next part
1452 }
1453
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001454 // process the part not only while the count allows but also if already fading
1455 for (int r=0 ; !part.count || r<part.count || fadedFramesCount > 0 ; r++) {
Nicolas Geoffraya1298752021-04-20 15:15:06 +01001456 if (shouldStopPlayingPart(part, fadedFramesCount, lastDisplayedProgress)) break;
Kevin Hesterd3782b22012-04-26 10:38:55 -07001457
Lucas Dupinbfd18122022-04-25 11:26:08 -07001458 // It's possible that the sysprops were not loaded yet at this boot phase.
1459 // If that's the case, then we should keep trying until they are available.
1460 if (animation.dynamicColoringEnabled && !mDynamicColorsApplied
1461 && (part.useDynamicColoring || part.postDynamicColoring)) {
1462 SLOGD("Trying to load dynamic color sysprops.");
1463 initDynamicColors();
1464 if (mDynamicColorsApplied) {
1465 // Sysprops were loaded. Next step is to adjust the animation if we loaded
1466 // the colors after the animation should have started.
1467 const int transitionLength = colorTransitionEnd - colorTransitionStart;
1468 if (part.postDynamicColoring) {
1469 colorTransitionStart = 0;
1470 colorTransitionEnd = fmin(transitionLength, fcount - 1);
1471 }
1472 }
1473 }
1474
Ed Coyne7464ac92017-06-08 12:26:48 -07001475 mCallbacks->playPart(i, part, r);
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -07001476
Jesse Hall083b84c2014-09-22 10:51:09 -07001477 glClearColor(
1478 part.backgroundColor[0],
1479 part.backgroundColor[1],
1480 part.backgroundColor[2],
1481 1.0f);
1482
Yoshiaki Maruoka9ef19b82017-10-25 13:55:49 +09001483 ALOGD("Playing files = %s/%s, Requested repeat = %d, playUntilComplete = %s",
1484 animation.fileName.string(), part.path.string(), part.count,
1485 part.playUntilComplete ? "true" : "false");
1486
Nicolas Geoffray41fffb42020-12-15 10:50:29 +00001487 // For the last animation, if we have progress indicator from
1488 // the system, display it.
1489 int currentProgress = android::base::GetIntProperty(PROGRESS_PROP_NAME, 0);
1490 bool displayProgress = animation.progressEnabled &&
1491 (i == (pcount -1)) && currentProgress != 0;
1492
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001493 for (size_t j=0 ; j<fcount ; j++) {
Nicolas Geoffraya1298752021-04-20 15:15:06 +01001494 if (shouldStopPlayingPart(part, fadedFramesCount, lastDisplayedProgress)) break;
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001495
Shan Huang2b31a362021-08-16 16:45:39 +00001496 // Color progress is
Shan Huang488ff742021-08-25 20:10:46 +00001497 // - the animation progress, normalized from
1498 // [colorTransitionStart,colorTransitionEnd] to [0, 1] for the dynamic coloring
1499 // part.
Shan Huang2b31a362021-08-16 16:45:39 +00001500 // - 0 for parts that come before,
1501 // - 1 for parts that come after.
1502 float colorProgress = part.useDynamicColoring
Shan Huang488ff742021-08-25 20:10:46 +00001503 ? fmin(fmax(
Lucas Dupinbfd18122022-04-25 11:26:08 -07001504 ((float)j - colorTransitionStart) /
1505 fmax(colorTransitionEnd - colorTransitionStart, 1.0f), 0.0f), 1.0f)
Shan Huang2b31a362021-08-16 16:45:39 +00001506 : (part.postDynamicColoring ? 1 : 0);
1507
Marin Shalamanov9070c052020-05-18 19:05:17 +02001508 processDisplayEvents();
1509
joenchen764ea042022-04-11 23:58:34 +08001510 const double ratio_w = static_cast<double>(mWidth) / mInitWidth;
1511 const double ratio_h = static_cast<double>(mHeight) / mInitHeight;
1512 const int animationX = (mWidth - animation.width * ratio_w) / 2;
1513 const int animationY = (mHeight - animation.height * ratio_h) / 2;
Marin Shalamanov9070c052020-05-18 19:05:17 +02001514
Mathias Agopiana8826d62009-10-01 03:10:14 -07001515 const Animation::Frame& frame(part.frames[j]);
Mathias Agopiandb7dd2a2012-05-12 15:08:21 -07001516 nsecs_t lastFrame = systemTime();
Mathias Agopiana8826d62009-10-01 03:10:14 -07001517
1518 if (r > 0) {
1519 glBindTexture(GL_TEXTURE_2D, frame.tid);
1520 } else {
Lucas Dupin8eedc022021-07-29 21:49:07 +00001521 glGenTextures(1, &frame.tid);
1522 glBindTexture(GL_TEXTURE_2D, frame.tid);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001523 int w, h;
Shan Huang2b31a362021-08-16 16:45:39 +00001524 // Set decoding option to alpha unpremultiplied so that the R, G, B channels
1525 // of transparent pixels are preserved.
1526 initTexture(frame.map, &w, &h, false /* don't premultiply alpha */);
Mathias Agopiana8826d62009-10-01 03:10:14 -07001527 }
1528
joenchen764ea042022-04-11 23:58:34 +08001529 const int trimWidth = frame.trimWidth * ratio_w;
1530 const int trimHeight = frame.trimHeight * ratio_h;
1531 const int trimX = frame.trimX * ratio_w;
1532 const int trimY = frame.trimY * ratio_h;
1533 const int xc = animationX + trimX;
1534 const int yc = animationY + trimY;
Shan Huang2b31a362021-08-16 16:45:39 +00001535 glClear(GL_COLOR_BUFFER_BIT);
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001536 // specify the y center as ceiling((mHeight - frame.trimHeight) / 2)
1537 // which is equivalent to mHeight - (yc + frame.trimHeight)
joenchen764ea042022-04-11 23:58:34 +08001538 const int frameDrawY = mHeight - (yc + trimHeight);
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001539
Lucas Dupin8eedc022021-07-29 21:49:07 +00001540 float fade = 0;
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001541 // if the part hasn't been stopped yet then continue fading if necessary
1542 if (exitPending() && part.hasFadingPhase()) {
Lucas Dupin8eedc022021-07-29 21:49:07 +00001543 fade = static_cast<float>(++fadedFramesCount) / part.framesToFadeCount;
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001544 if (fadedFramesCount >= part.framesToFadeCount) {
1545 fadedFramesCount = MAX_FADED_FRAMES_COUNT; // no more fading
1546 }
1547 }
Lucas Dupin8eedc022021-07-29 21:49:07 +00001548 glUseProgram(mImageShader);
1549 glUniform1i(mImageTextureLocation, 0);
1550 glUniform1f(mImageFadeLocation, fade);
Shan Huang2b31a362021-08-16 16:45:39 +00001551 if (animation.dynamicColoringEnabled) {
1552 glUniform1f(mImageColorProgressLocation, colorProgress);
1553 }
Lucas Dupin8eedc022021-07-29 21:49:07 +00001554 glEnable(GL_BLEND);
joenchen764ea042022-04-11 23:58:34 +08001555 drawTexturedQuad(xc, frameDrawY, trimWidth, trimHeight);
Lucas Dupin8eedc022021-07-29 21:49:07 +00001556 glDisable(GL_BLEND);
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001557
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001558 if (mClockEnabled && mTimeIsAccurate && validClock(part)) {
1559 drawClock(animation.clockFont, part.clockPosX, part.clockPosY);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -08001560 }
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001561
Nicolas Geoffray41fffb42020-12-15 10:50:29 +00001562 if (displayProgress) {
1563 int newProgress = android::base::GetIntProperty(PROGRESS_PROP_NAME, 0);
1564 // In case the new progress jumped suddenly, still show an
1565 // increment of 1.
1566 if (lastDisplayedProgress != 100) {
1567 // Artificially sleep 1/10th a second to slow down the animation.
1568 usleep(100000);
1569 if (lastDisplayedProgress < newProgress) {
1570 lastDisplayedProgress++;
1571 }
1572 }
1573 // Put the progress percentage right below the animation.
1574 int posY = animation.height / 3;
1575 int posX = TEXT_CENTER_VALUE;
1576 drawProgress(lastDisplayedProgress, animation.progressFont, posX, posY);
1577 }
1578
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001579 handleViewport(frameDuration);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -08001580
Mathias Agopiana8826d62009-10-01 03:10:14 -07001581 eglSwapBuffers(mDisplay, mSurface);
1582
1583 nsecs_t now = systemTime();
1584 nsecs_t delay = frameDuration - (now - lastFrame);
Wei Wang159a4102018-10-23 23:15:58 -07001585 //SLOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay));
Mathias Agopiana8826d62009-10-01 03:10:14 -07001586 lastFrame = now;
Mathias Agopiandb7dd2a2012-05-12 15:08:21 -07001587
1588 if (delay > 0) {
1589 struct timespec spec;
1590 spec.tv_sec = (now + delay) / 1000000000;
1591 spec.tv_nsec = (now + delay) % 1000000000;
1592 int err;
1593 do {
Yi Kong911ac232019-03-24 01:49:02 -07001594 err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, nullptr);
Keith Mok0f2e6682021-11-15 05:50:32 +00001595 } while (err == EINTR);
Mathias Agopiandb7dd2a2012-05-12 15:08:21 -07001596 }
Kevin Hesterd3782b22012-04-26 10:38:55 -07001597
1598 checkExit();
Mathias Agopiana8826d62009-10-01 03:10:14 -07001599 }
Kevin Hesterd3782b22012-04-26 10:38:55 -07001600
Mathias Agopiana8826d62009-10-01 03:10:14 -07001601 usleep(part.pause * ns2us(frameDuration));
Kevin Hesterd3782b22012-04-26 10:38:55 -07001602
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001603 if (exitPending() && !part.count && mCurrentInset >= mTargetInset &&
1604 !part.hasFadingPhase()) {
Nicolas Geoffraya1298752021-04-20 15:15:06 +01001605 if (lastDisplayedProgress != 0 && lastDisplayedProgress != 100) {
1606 android::base::SetProperty(PROGRESS_PROP_NAME, "100");
1607 continue;
1608 }
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001609 break; // exit the infinite non-fading part when it has been played at least once
1610 }
Mathias Agopiana8826d62009-10-01 03:10:14 -07001611 }
Geoffrey Pitsch2fb30fb2016-07-06 16:16:20 -04001612 }
1613
1614 // Free textures created for looping parts now that the animation is done.
1615 for (const Animation::Part& part : animation.parts) {
Mathias Agopiana8826d62009-10-01 03:10:14 -07001616 if (part.count != 1) {
Geoffrey Pitsch2fb30fb2016-07-06 16:16:20 -04001617 const size_t fcount = part.frames.size();
1618 for (size_t j = 0; j < fcount; j++) {
Mathias Agopiana8826d62009-10-01 03:10:14 -07001619 const Animation::Frame& frame(part.frames[j]);
1620 glDeleteTextures(1, &frame.tid);
1621 }
1622 }
1623 }
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -07001624
Yoshiaki Maruoka9ef19b82017-10-25 13:55:49 +09001625 ALOGD("%sAnimationShownTiming End time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
1626 elapsedRealtime());
1627
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001628 return true;
Mathias Agopiana8826d62009-10-01 03:10:14 -07001629}
1630
Marin Shalamanov9070c052020-05-18 19:05:17 +02001631void BootAnimation::processDisplayEvents() {
1632 // This will poll mDisplayEventReceiver and if there are new events it'll call
1633 // displayEventCallback synchronously.
1634 mLooper->pollOnce(0);
1635}
1636
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001637void BootAnimation::handleViewport(nsecs_t timestep) {
1638 if (mShuttingDown || !mFlingerSurfaceControl || mTargetInset == 0) {
1639 return;
1640 }
1641 if (mTargetInset < 0) {
1642 // Poll the amount for the top display inset. This will return -1 until persistent properties
1643 // have been loaded.
1644 mTargetInset = android::base::GetIntProperty("persist.sys.displayinset.top",
1645 -1 /* default */, -1 /* min */, mHeight / 2 /* max */);
1646 }
1647 if (mTargetInset <= 0) {
1648 return;
1649 }
1650
1651 if (mCurrentInset < mTargetInset) {
1652 // After the device boots, the inset will effectively be cropped away. We animate this here.
1653 float fraction = static_cast<float>(mCurrentInset) / mTargetInset;
1654 int interpolatedInset = (cosf((fraction + 1) * M_PI) / 2.0f + 0.5f) * mTargetInset;
1655
1656 SurfaceComposerClient::Transaction()
1657 .setCrop(mFlingerSurfaceControl, Rect(0, interpolatedInset, mWidth, mHeight))
1658 .apply();
1659 } else {
1660 // At the end of the animation, we switch to the viewport that DisplayManager will apply
1661 // later. This changes the coordinate system, and means we must move the surface up by
1662 // the inset amount.
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001663 Rect layerStackRect(0, 0, mWidth, mHeight - mTargetInset);
1664 Rect displayRect(0, mTargetInset, mWidth, mHeight);
1665
1666 SurfaceComposerClient::Transaction t;
1667 t.setPosition(mFlingerSurfaceControl, 0, -mTargetInset)
1668 .setCrop(mFlingerSurfaceControl, Rect(0, mTargetInset, mWidth, mHeight));
Dominik Laskowski2a3d9aa2019-11-18 20:26:39 -08001669 t.setDisplayProjection(mDisplayToken, ui::ROTATION_0, layerStackRect, displayRect);
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001670 t.apply();
1671
1672 mTargetInset = mCurrentInset = 0;
1673 }
1674
1675 int delta = timestep * mTargetInset / ms2ns(200);
1676 mCurrentInset += delta;
1677}
1678
Marin Shalamanov9070c052020-05-18 19:05:17 +02001679void BootAnimation::releaseAnimation(Animation* animation) const {
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001680 for (Vector<Animation::Part>::iterator it = animation->parts.begin(),
1681 e = animation->parts.end(); it != e; ++it) {
1682 if (it->animation)
1683 releaseAnimation(it->animation);
1684 }
1685 if (animation->zip)
1686 delete animation->zip;
1687 delete animation;
1688}
1689
Marin Shalamanov9070c052020-05-18 19:05:17 +02001690BootAnimation::Animation* BootAnimation::loadAnimation(const String8& fn) {
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001691 if (mLoadedFiles.indexOf(fn) >= 0) {
Wei Wang159a4102018-10-23 23:15:58 -07001692 SLOGE("File \"%s\" is already loaded. Cyclic ref is not allowed",
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001693 fn.string());
Yi Kong911ac232019-03-24 01:49:02 -07001694 return nullptr;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001695 }
1696 ZipFileRO *zip = ZipFileRO::open(fn);
Yi Kong911ac232019-03-24 01:49:02 -07001697 if (zip == nullptr) {
Wei Wang159a4102018-10-23 23:15:58 -07001698 SLOGE("Failed to open animation zip \"%s\": %s",
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001699 fn.string(), strerror(errno));
Yi Kong911ac232019-03-24 01:49:02 -07001700 return nullptr;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001701 }
1702
Yoshiaki Maruoka9ef19b82017-10-25 13:55:49 +09001703 ALOGD("%s is loaded successfully", fn.string());
1704
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001705 Animation *animation = new Animation;
1706 animation->fileName = fn;
1707 animation->zip = zip;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001708 animation->clockFont.map = nullptr;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001709 mLoadedFiles.add(animation->fileName);
1710
1711 parseAnimationDesc(*animation);
Geoffrey Pitscha91a2d72016-07-12 14:46:19 -04001712 if (!preloadZip(*animation)) {
Greg Kaiser7426ec82019-09-11 14:34:27 -07001713 releaseAnimation(animation);
Yi Kong911ac232019-03-24 01:49:02 -07001714 return nullptr;
Geoffrey Pitscha91a2d72016-07-12 14:46:19 -04001715 }
1716
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001717 mLoadedFiles.remove(fn);
1718 return animation;
1719}
Damien Bargiacchi97480862016-03-29 14:55:55 -07001720
1721bool BootAnimation::updateIsTimeAccurate() {
1722 static constexpr long long MAX_TIME_IN_PAST = 60000LL * 60LL * 24LL * 30LL; // 30 days
1723 static constexpr long long MAX_TIME_IN_FUTURE = 60000LL * 90LL; // 90 minutes
1724
1725 if (mTimeIsAccurate) {
1726 return true;
1727 }
Keun-young Parkb5938422017-03-23 13:46:24 -07001728 if (mShuttingDown) return true;
Damien Bargiacchi97480862016-03-29 14:55:55 -07001729 struct stat statResult;
Damien Bargiacchi9071db12016-10-28 17:38:22 -07001730
1731 if(stat(TIME_FORMAT_12_HOUR_FLAG_FILE_PATH, &statResult) == 0) {
1732 mTimeFormat12Hour = true;
1733 }
1734
Damien Bargiacchi97480862016-03-29 14:55:55 -07001735 if(stat(ACCURATE_TIME_FLAG_FILE_PATH, &statResult) == 0) {
1736 mTimeIsAccurate = true;
1737 return true;
1738 }
1739
1740 FILE* file = fopen(LAST_TIME_CHANGED_FILE_PATH, "r");
Yi Kong911ac232019-03-24 01:49:02 -07001741 if (file != nullptr) {
Damien Bargiacchi97480862016-03-29 14:55:55 -07001742 long long lastChangedTime = 0;
1743 fscanf(file, "%lld", &lastChangedTime);
1744 fclose(file);
1745 if (lastChangedTime > 0) {
1746 struct timespec now;
1747 clock_gettime(CLOCK_REALTIME, &now);
1748 // Match the Java timestamp format
1749 long long rtcNow = (now.tv_sec * 1000LL) + (now.tv_nsec / 1000000LL);
Damien Bargiacchi96762812016-07-12 15:53:40 -07001750 if (ACCURATE_TIME_EPOCH < rtcNow
1751 && lastChangedTime > (rtcNow - MAX_TIME_IN_PAST)
1752 && lastChangedTime < (rtcNow + MAX_TIME_IN_FUTURE)) {
Damien Bargiacchi97480862016-03-29 14:55:55 -07001753 mTimeIsAccurate = true;
1754 }
1755 }
1756 }
1757
1758 return mTimeIsAccurate;
1759}
1760
1761BootAnimation::TimeCheckThread::TimeCheckThread(BootAnimation* bootAnimation) : Thread(false),
Josh Yangf95b2002021-12-23 14:32:28 -08001762 mInotifyFd(-1), mBootAnimWd(-1), mTimeWd(-1), mBootAnimation(bootAnimation) {}
Damien Bargiacchi97480862016-03-29 14:55:55 -07001763
1764BootAnimation::TimeCheckThread::~TimeCheckThread() {
1765 // mInotifyFd may be -1 but that's ok since we're not at risk of attempting to close a valid FD.
1766 close(mInotifyFd);
1767}
1768
1769bool BootAnimation::TimeCheckThread::threadLoop() {
1770 bool shouldLoop = doThreadLoop() && !mBootAnimation->mTimeIsAccurate
1771 && mBootAnimation->mClockEnabled;
1772 if (!shouldLoop) {
1773 close(mInotifyFd);
1774 mInotifyFd = -1;
1775 }
1776 return shouldLoop;
1777}
1778
1779bool BootAnimation::TimeCheckThread::doThreadLoop() {
1780 static constexpr int BUFF_LEN (10 * (sizeof(struct inotify_event) + NAME_MAX + 1));
1781
1782 // Poll instead of doing a blocking read so the Thread can exit if requested.
1783 struct pollfd pfd = { mInotifyFd, POLLIN, 0 };
1784 ssize_t pollResult = poll(&pfd, 1, 1000);
1785
1786 if (pollResult == 0) {
1787 return true;
1788 } else if (pollResult < 0) {
Wei Wang159a4102018-10-23 23:15:58 -07001789 SLOGE("Could not poll inotify events");
Damien Bargiacchi97480862016-03-29 14:55:55 -07001790 return false;
1791 }
1792
1793 char buff[BUFF_LEN] __attribute__ ((aligned(__alignof__(struct inotify_event))));;
1794 ssize_t length = read(mInotifyFd, buff, BUFF_LEN);
1795 if (length == 0) {
1796 return true;
1797 } else if (length < 0) {
Wei Wang159a4102018-10-23 23:15:58 -07001798 SLOGE("Could not read inotify events");
Damien Bargiacchi97480862016-03-29 14:55:55 -07001799 return false;
1800 }
1801
1802 const struct inotify_event *event;
1803 for (char* ptr = buff; ptr < buff + length; ptr += sizeof(struct inotify_event) + event->len) {
1804 event = (const struct inotify_event *) ptr;
Josh Yangf95b2002021-12-23 14:32:28 -08001805 if (event->wd == mBootAnimWd && strcmp(BOOTANIM_TIME_DIR_NAME, event->name) == 0) {
Damien Bargiacchi97480862016-03-29 14:55:55 -07001806 addTimeDirWatch();
1807 } else if (event->wd == mTimeWd && (strcmp(LAST_TIME_CHANGED_FILE_NAME, event->name) == 0
1808 || strcmp(ACCURATE_TIME_FLAG_FILE_NAME, event->name) == 0)) {
1809 return !mBootAnimation->updateIsTimeAccurate();
1810 }
1811 }
1812
1813 return true;
1814}
1815
1816void BootAnimation::TimeCheckThread::addTimeDirWatch() {
Josh Yangf95b2002021-12-23 14:32:28 -08001817 mTimeWd = inotify_add_watch(mInotifyFd, BOOTANIM_TIME_DIR_PATH,
Damien Bargiacchi97480862016-03-29 14:55:55 -07001818 IN_CLOSE_WRITE | IN_MOVED_TO | IN_ATTRIB);
1819 if (mTimeWd > 0) {
1820 // No need to watch for the time directory to be created if it already exists
Josh Yangf95b2002021-12-23 14:32:28 -08001821 inotify_rm_watch(mInotifyFd, mBootAnimWd);
1822 mBootAnimWd = -1;
Damien Bargiacchi97480862016-03-29 14:55:55 -07001823 }
1824}
1825
1826status_t BootAnimation::TimeCheckThread::readyToRun() {
1827 mInotifyFd = inotify_init();
1828 if (mInotifyFd < 0) {
Wei Wang159a4102018-10-23 23:15:58 -07001829 SLOGE("Could not initialize inotify fd");
Damien Bargiacchi97480862016-03-29 14:55:55 -07001830 return NO_INIT;
1831 }
1832
Josh Yangf95b2002021-12-23 14:32:28 -08001833 mBootAnimWd = inotify_add_watch(mInotifyFd, BOOTANIM_DATA_DIR_PATH, IN_CREATE | IN_ATTRIB);
1834 if (mBootAnimWd < 0) {
Damien Bargiacchi97480862016-03-29 14:55:55 -07001835 close(mInotifyFd);
1836 mInotifyFd = -1;
Josh Yangf95b2002021-12-23 14:32:28 -08001837 SLOGE("Could not add watch for %s: %s", BOOTANIM_DATA_DIR_PATH, strerror(errno));
Damien Bargiacchi97480862016-03-29 14:55:55 -07001838 return NO_INIT;
1839 }
1840
1841 addTimeDirWatch();
1842
1843 if (mBootAnimation->updateIsTimeAccurate()) {
1844 close(mInotifyFd);
1845 mInotifyFd = -1;
1846 return ALREADY_EXISTS;
1847 }
1848
1849 return NO_ERROR;
1850}
1851
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001852// ---------------------------------------------------------------------------
1853
Marin Shalamanov9070c052020-05-18 19:05:17 +02001854} // namespace android