blob: 046145f90808a2ab1c1e924ea6c9f399e2c43214 [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
Dominik Laskowski69b281d2019-11-22 14:13:12 -080046#include <ui/DisplayConfig.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>
Mathias Agopian000479f2010-02-09 17:46:37 -080055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080056#include <GLES/gl.h>
57#include <GLES/glext.h>
58#include <EGL/eglext.h>
59
60#include "BootAnimation.h"
61
Kyeongkab.Nam35a8a112019-07-17 16:41:48 +090062#define ANIM_PATH_MAX 255
63#define STR(x) #x
64#define STRTO(x) STR(x)
65
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066namespace android {
67
Damien Bargiacchi97480862016-03-29 14:55:55 -070068static const char OEM_BOOTANIMATION_FILE[] = "/oem/media/bootanimation.zip";
Beverly34ffe252019-05-17 11:03:54 -040069static const char PRODUCT_BOOTANIMATION_DARK_FILE[] = "/product/media/bootanimation-dark.zip";
Jaekyun Seokc521bb32018-01-30 11:52:47 +090070static const char PRODUCT_BOOTANIMATION_FILE[] = "/product/media/bootanimation.zip";
Damien Bargiacchi97480862016-03-29 14:55:55 -070071static const char SYSTEM_BOOTANIMATION_FILE[] = "/system/media/bootanimation.zip";
Anders Fridlunde0b4d232018-11-06 14:23:25 +010072static const char APEX_BOOTANIMATION_FILE[] = "/apex/com.android.bootanimation/etc/bootanimation.zip";
Jaekyun Seokc521bb32018-01-30 11:52:47 +090073static const char PRODUCT_ENCRYPTED_BOOTANIMATION_FILE[] = "/product/media/bootanimation-encrypted.zip";
Damien Bargiacchi97480862016-03-29 14:55:55 -070074static const char SYSTEM_ENCRYPTED_BOOTANIMATION_FILE[] = "/system/media/bootanimation-encrypted.zip";
Keun-young Parkb5938422017-03-23 13:46:24 -070075static const char OEM_SHUTDOWNANIMATION_FILE[] = "/oem/media/shutdownanimation.zip";
Jaekyun Seokc521bb32018-01-30 11:52:47 +090076static const char PRODUCT_SHUTDOWNANIMATION_FILE[] = "/product/media/shutdownanimation.zip";
Keun-young Parkb5938422017-03-23 13:46:24 -070077static const char SYSTEM_SHUTDOWNANIMATION_FILE[] = "/system/media/shutdownanimation.zip";
78
Nikita Ioffe06c986e2020-01-27 17:16:03 +000079static constexpr const char* PRODUCT_USERSPACE_REBOOT_ANIMATION_FILE = "/product/media/userspace-reboot.zip";
80static constexpr const char* OEM_USERSPACE_REBOOT_ANIMATION_FILE = "/oem/media/userspace-reboot.zip";
81static constexpr const char* SYSTEM_USERSPACE_REBOOT_ANIMATION_FILE = "/system/media/userspace-reboot.zip";
82
Damien Bargiacchi97480862016-03-29 14:55:55 -070083static const char SYSTEM_DATA_DIR_PATH[] = "/data/system";
84static const char SYSTEM_TIME_DIR_NAME[] = "time";
85static const char SYSTEM_TIME_DIR_PATH[] = "/data/system/time";
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070086static const char CLOCK_FONT_ASSET[] = "images/clock_font.png";
87static const char CLOCK_FONT_ZIP_NAME[] = "clock_font.png";
Damien Bargiacchi97480862016-03-29 14:55:55 -070088static const char LAST_TIME_CHANGED_FILE_NAME[] = "last_time_change";
89static const char LAST_TIME_CHANGED_FILE_PATH[] = "/data/system/time/last_time_change";
90static const char ACCURATE_TIME_FLAG_FILE_NAME[] = "time_is_accurate";
91static const char ACCURATE_TIME_FLAG_FILE_PATH[] = "/data/system/time/time_is_accurate";
Damien Bargiacchi9071db12016-10-28 17:38:22 -070092static const char TIME_FORMAT_12_HOUR_FLAG_FILE_PATH[] = "/data/system/time/time_format_12_hour";
Damien Bargiacchi96762812016-07-12 15:53:40 -070093// Java timestamp format. Don't show the clock if the date is before 2000-01-01 00:00:00.
94static const long long ACCURATE_TIME_EPOCH = 946684800000;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070095static constexpr char FONT_BEGIN_CHAR = ' ';
96static constexpr char FONT_END_CHAR = '~' + 1;
97static constexpr size_t FONT_NUM_CHARS = FONT_END_CHAR - FONT_BEGIN_CHAR + 1;
98static constexpr size_t FONT_NUM_COLS = 16;
99static constexpr size_t FONT_NUM_ROWS = FONT_NUM_CHARS / FONT_NUM_COLS;
100static const int TEXT_CENTER_VALUE = INT_MAX;
101static const int TEXT_MISSING_VALUE = INT_MIN;
Damien Bargiacchi97480862016-03-29 14:55:55 -0700102static const char EXIT_PROP_NAME[] = "service.bootanim.exit";
Huihong Luod4a217e2020-01-16 15:56:33 -0800103static const char DISPLAYS_PROP_NAME[] = "persist.service.bootanim.displays";
Kyeongkab.Nam35a8a112019-07-17 16:41:48 +0900104static const int ANIM_ENTRY_NAME_MAX = ANIM_PATH_MAX + 1;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700105static constexpr size_t TEXT_POS_LEN_MAX = 16;
Narayan Kamathafd31e02013-12-03 13:16:03 +0000106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107// ---------------------------------------------------------------------------
108
Ed Coyne7464ac92017-06-08 12:26:48 -0700109BootAnimation::BootAnimation(sp<Callbacks> callbacks)
Marin Shalamanov9070c052020-05-18 19:05:17 +0200110 : Thread(false), mLooper(new Looper(false)), mClockEnabled(true), mTimeIsAccurate(false),
Yi Kong911ac232019-03-24 01:49:02 -0700111 mTimeFormat12Hour(false), mTimeCheckThread(nullptr), mCallbacks(callbacks) {
Mathias Agopian627e7b52009-05-21 19:21:59 -0700112 mSession = new SurfaceComposerClient();
Geoffrey Pitsch290c4352016-08-09 14:35:10 -0400113
Keun-young Parkb5938422017-03-23 13:46:24 -0700114 std::string powerCtl = android::base::GetProperty("sys.powerctl", "");
115 if (powerCtl.empty()) {
116 mShuttingDown = false;
117 } else {
118 mShuttingDown = true;
119 }
Huihong Luo50a2f362018-08-11 09:27:57 -0700120 ALOGD("%sAnimationStartTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
121 elapsedRealtime());
122}
123
124BootAnimation::~BootAnimation() {
125 if (mAnimation != nullptr) {
126 releaseAnimation(mAnimation);
127 mAnimation = nullptr;
128 }
129 ALOGD("%sAnimationStopTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
130 elapsedRealtime());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131}
132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133void BootAnimation::onFirstRef() {
Mathias Agopianbc726112009-09-23 15:44:05 -0700134 status_t err = mSession->linkToComposerDeath(this);
Wei Wang159a4102018-10-23 23:15:58 -0700135 SLOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err));
Mathias Agopian8434c532009-09-23 18:52:49 -0700136 if (err == NO_ERROR) {
Huihong Luo50a2f362018-08-11 09:27:57 -0700137 // Load the animation content -- this can be slow (eg 200ms)
138 // called before waitForSurfaceFlinger() in main() to avoid wait
139 ALOGD("%sAnimationPreloadTiming start time: %" PRId64 "ms",
140 mShuttingDown ? "Shutdown" : "Boot", elapsedRealtime());
141 preloadAnimation();
142 ALOGD("%sAnimationPreloadStopTiming start time: %" PRId64 "ms",
143 mShuttingDown ? "Shutdown" : "Boot", elapsedRealtime());
Mathias Agopianbc726112009-09-23 15:44:05 -0700144 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145}
146
Mathias Agopianbc726112009-09-23 15:44:05 -0700147sp<SurfaceComposerClient> BootAnimation::session() const {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 return mSession;
149}
150
Marin Shalamanov9070c052020-05-18 19:05:17 +0200151void BootAnimation::binderDied(const wp<IBinder>&) {
Mathias Agopianbc726112009-09-23 15:44:05 -0700152 // woah, surfaceflinger died!
Wei Wang159a4102018-10-23 23:15:58 -0700153 SLOGD("SurfaceFlinger died, exiting...");
Mathias Agopianbc726112009-09-23 15:44:05 -0700154
155 // calling requestExit() is not enough here because the Surface code
156 // might be blocked on a condition variable that will never be updated.
157 kill( getpid(), SIGKILL );
158 requestExit();
159}
160
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400161static void* decodeImage(const void* encodedData, size_t dataLength, AndroidBitmapInfo* outInfo) {
162 AImageDecoder* decoder = nullptr;
163 AImageDecoder_createFromBuffer(encodedData, dataLength, &decoder);
164 if (!decoder) {
165 return nullptr;
166 }
167
168 const AImageDecoderHeaderInfo* info = AImageDecoder_getHeaderInfo(decoder);
169 outInfo->width = AImageDecoderHeaderInfo_getWidth(info);
170 outInfo->height = AImageDecoderHeaderInfo_getHeight(info);
171 outInfo->format = AImageDecoderHeaderInfo_getAndroidBitmapFormat(info);
172 outInfo->stride = AImageDecoder_getMinimumStride(decoder);
173 outInfo->flags = 0;
174
175 const size_t size = outInfo->stride * outInfo->height;
176 void* pixels = malloc(size);
177 int result = AImageDecoder_decodeImage(decoder, pixels, outInfo->stride, size);
178 AImageDecoder_delete(decoder);
179
180 if (result != ANDROID_IMAGE_DECODER_SUCCESS) {
181 free(pixels);
182 return nullptr;
183 }
184 return pixels;
185}
186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets,
188 const char* name) {
189 Asset* asset = assets.open(name, Asset::ACCESS_BUFFER);
Yi Kong911ac232019-03-24 01:49:02 -0700190 if (asset == nullptr)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 return NO_INIT;
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400192
193 AndroidBitmapInfo bitmapInfo;
194 void* pixels = decodeImage(asset->getBuffer(false), asset->getLength(), &bitmapInfo);
195 auto pixelDeleter = std::unique_ptr<void, decltype(free)*>{ pixels, free };
196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 asset->close();
198 delete asset;
199
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400200 if (!pixels) {
201 return NO_INIT;
202 }
203
204 const int w = bitmapInfo.width;
205 const int h = bitmapInfo.height;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206
207 GLint crop[4] = { 0, h, w, -h };
208 texture->w = w;
209 texture->h = h;
210
211 glGenTextures(1, &texture->name);
212 glBindTexture(GL_TEXTURE_2D, texture->name);
213
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400214 switch (bitmapInfo.format) {
215 case ANDROID_BITMAP_FORMAT_A_8:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400217 GL_UNSIGNED_BYTE, pixels);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 break;
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400219 case ANDROID_BITMAP_FORMAT_RGBA_4444:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400221 GL_UNSIGNED_SHORT_4_4_4_4, pixels);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 break;
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400223 case ANDROID_BITMAP_FORMAT_RGBA_8888:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400225 GL_UNSIGNED_BYTE, pixels);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 break;
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400227 case ANDROID_BITMAP_FORMAT_RGB_565:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400229 GL_UNSIGNED_SHORT_5_6_5, pixels);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 break;
231 default:
232 break;
233 }
234
235 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
236 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
237 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
238 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
239 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 return NO_ERROR;
242}
243
Marin Shalamanov9070c052020-05-18 19:05:17 +0200244status_t BootAnimation::initTexture(FileMap* map, int* width, int* height) {
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400245 AndroidBitmapInfo bitmapInfo;
246 void* pixels = decodeImage(map->getDataPtr(), map->getDataLength(), &bitmapInfo);
247 auto pixelDeleter = std::unique_ptr<void, decltype(free)*>{ pixels, free };
Mathias Agopiana8826d62009-10-01 03:10:14 -0700248
Mykola Kondratenko0c1eeb32014-04-15 09:35:44 +0200249 // FileMap memory is never released until application exit.
250 // Release it now as the texture is already loaded and the memory used for
251 // the packed resource can be released.
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700252 delete map;
Mykola Kondratenko0c1eeb32014-04-15 09:35:44 +0200253
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400254 if (!pixels) {
255 return NO_INIT;
256 }
257
258 const int w = bitmapInfo.width;
259 const int h = bitmapInfo.height;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700260
261 GLint crop[4] = { 0, h, w, -h };
262 int tw = 1 << (31 - __builtin_clz(w));
263 int th = 1 << (31 - __builtin_clz(h));
264 if (tw < w) tw <<= 1;
265 if (th < h) th <<= 1;
266
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400267 switch (bitmapInfo.format) {
268 case ANDROID_BITMAP_FORMAT_RGBA_8888:
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530269 if (!mUseNpotTextures && (tw != w || th != h)) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700270 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA,
Yi Kong911ac232019-03-24 01:49:02 -0700271 GL_UNSIGNED_BYTE, nullptr);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700272 glTexSubImage2D(GL_TEXTURE_2D, 0,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400273 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700274 } else {
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530275 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400276 GL_UNSIGNED_BYTE, pixels);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700277 }
278 break;
279
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400280 case ANDROID_BITMAP_FORMAT_RGB_565:
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530281 if (!mUseNpotTextures && (tw != w || th != h)) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700282 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB,
Yi Kong911ac232019-03-24 01:49:02 -0700283 GL_UNSIGNED_SHORT_5_6_5, nullptr);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700284 glTexSubImage2D(GL_TEXTURE_2D, 0,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400285 0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, pixels);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700286 } else {
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530287 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB,
Derek Sollenberger22d0d4c72020-04-08 10:53:46 -0400288 GL_UNSIGNED_SHORT_5_6_5, pixels);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700289 }
290 break;
291 default:
292 break;
293 }
294
295 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
296
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700297 *width = w;
298 *height = h;
299
Mathias Agopiana8826d62009-10-01 03:10:14 -0700300 return NO_ERROR;
301}
302
Marin Shalamanov9070c052020-05-18 19:05:17 +0200303class BootAnimation::DisplayEventCallback : public LooperCallback {
304 BootAnimation* mBootAnimation;
305
306public:
307 DisplayEventCallback(BootAnimation* bootAnimation) {
308 mBootAnimation = bootAnimation;
309 }
310
311 int handleEvent(int /* fd */, int events, void* /* data */) {
312 if (events & (Looper::EVENT_ERROR | Looper::EVENT_HANGUP)) {
313 ALOGE("Display event receiver pipe was closed or an error occurred. events=0x%x",
314 events);
315 return 0; // remove the callback
316 }
317
318 if (!(events & Looper::EVENT_INPUT)) {
319 ALOGW("Received spurious callback for unhandled poll event. events=0x%x", events);
320 return 1; // keep the callback
321 }
322
323 constexpr int kBufferSize = 100;
324 DisplayEventReceiver::Event buffer[kBufferSize];
325 ssize_t numEvents;
326 do {
327 numEvents = mBootAnimation->mDisplayEventReceiver->getEvents(buffer, kBufferSize);
328 for (size_t i = 0; i < static_cast<size_t>(numEvents); i++) {
329 const auto& event = buffer[i];
330 if (event.header.type == DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG) {
331 SLOGV("Hotplug received");
332
333 if (!event.hotplug.connected) {
334 // ignore hotplug disconnect
335 continue;
336 }
337 auto token = SurfaceComposerClient::getPhysicalDisplayToken(
338 event.header.displayId);
339
340 if (token != mBootAnimation->mDisplayToken) {
341 // ignore hotplug of a secondary display
342 continue;
343 }
344
345 DisplayConfig displayConfig;
346 const status_t error = SurfaceComposerClient::getActiveDisplayConfig(
347 mBootAnimation->mDisplayToken, &displayConfig);
348 if (error != NO_ERROR) {
349 SLOGE("Can't get active display configuration.");
350 }
351 mBootAnimation->resizeSurface(displayConfig.resolution.getWidth(),
352 displayConfig.resolution.getHeight());
353 }
354 }
355 } while (numEvents > 0);
356
357 return 1; // keep the callback
358 }
359};
360
361EGLConfig BootAnimation::getEglConfig(const EGLDisplay& display) {
362 const EGLint attribs[] = {
363 EGL_RED_SIZE, 8,
364 EGL_GREEN_SIZE, 8,
365 EGL_BLUE_SIZE, 8,
366 EGL_DEPTH_SIZE, 0,
367 EGL_NONE
368 };
369 EGLint numConfigs;
370 EGLConfig config;
371 eglChooseConfig(display, attribs, &config, 1, &numConfigs);
372 return config;
373}
374
Marin Shalamanov047802d2020-05-19 23:55:12 +0200375ui::Size BootAnimation::limitSurfaceSize(int width, int height) const {
376 ui::Size limited(width, height);
377 bool wasLimited = false;
378 const float aspectRatio = float(width) / float(height);
379 if (mMaxWidth != 0 && width > mMaxWidth) {
380 limited.height = mMaxWidth / aspectRatio;
381 limited.width = mMaxWidth;
382 wasLimited = true;
383 }
384 if (mMaxHeight != 0 && limited.height > mMaxHeight) {
385 limited.height = mMaxHeight;
386 limited.width = mMaxHeight * aspectRatio;
387 wasLimited = true;
388 }
389 SLOGV_IF(wasLimited, "Surface size has been limited to [%dx%d] from [%dx%d]",
390 limited.width, limited.height, width, height);
391 return limited;
392}
393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800394status_t BootAnimation::readyToRun() {
395 mAssets.addDefaultAssets();
396
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800397 mDisplayToken = SurfaceComposerClient::getInternalDisplayToken();
398 if (mDisplayToken == nullptr)
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800399 return NAME_NOT_FOUND;
Dominik Laskowski3316a0a2019-01-25 02:56:41 -0800400
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800401 DisplayConfig displayConfig;
402 const status_t error =
403 SurfaceComposerClient::getActiveDisplayConfig(mDisplayToken, &displayConfig);
404 if (error != NO_ERROR)
405 return error;
406
Marin Shalamanov047802d2020-05-19 23:55:12 +0200407 mMaxWidth = android::base::GetIntProperty("ro.surface_flinger.max_graphics_width", 0);
408 mMaxHeight = android::base::GetIntProperty("ro.surface_flinger.max_graphics_height", 0);
409 ui::Size resolution = displayConfig.resolution;
410 resolution = limitSurfaceSize(resolution.width, resolution.height);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 // create the native surface
Jeff Brown0b722fe2012-08-24 22:40:14 -0700412 sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
Dominik Laskowski69b281d2019-11-22 14:13:12 -0800413 resolution.getWidth(), resolution.getHeight(), PIXEL_FORMAT_RGB_565);
Mathias Agopian439863f2011-06-28 19:09:31 -0700414
Robert Carre13b58e2017-08-31 14:50:44 -0700415 SurfaceComposerClient::Transaction t;
Huihong Luof97c9e22019-05-29 11:08:01 -0700416
417 // this guest property specifies multi-display IDs to show the boot animation
418 // multiple ids can be set with comma (,) as separator, for example:
Huihong Luod4a217e2020-01-16 15:56:33 -0800419 // setprop persist.boot.animation.displays 19260422155234049,19261083906282754
Marin Shalamanov11599ee2020-07-27 21:31:48 +0200420 Vector<PhysicalDisplayId> physicalDisplayIds;
Huihong Luof97c9e22019-05-29 11:08:01 -0700421 char displayValue[PROPERTY_VALUE_MAX] = "";
Huihong Luod4a217e2020-01-16 15:56:33 -0800422 property_get(DISPLAYS_PROP_NAME, displayValue, "");
Huihong Luof97c9e22019-05-29 11:08:01 -0700423 bool isValid = displayValue[0] != '\0';
424 if (isValid) {
425 char *p = displayValue;
426 while (*p) {
427 if (!isdigit(*p) && *p != ',') {
428 isValid = false;
429 break;
430 }
431 p ++;
432 }
433 if (!isValid)
Huihong Luod4a217e2020-01-16 15:56:33 -0800434 SLOGE("Invalid syntax for the value of system prop: %s", DISPLAYS_PROP_NAME);
Huihong Luof97c9e22019-05-29 11:08:01 -0700435 }
436 if (isValid) {
437 std::istringstream stream(displayValue);
Marin Shalamanov11599ee2020-07-27 21:31:48 +0200438 for (PhysicalDisplayId id; stream >> id.value; ) {
Huihong Luof97c9e22019-05-29 11:08:01 -0700439 physicalDisplayIds.add(id);
440 if (stream.peek() == ',')
441 stream.ignore();
442 }
443
444 // In the case of multi-display, boot animation shows on the specified displays
445 // in addition to the primary display
446 auto ids = SurfaceComposerClient::getPhysicalDisplayIds();
447 constexpr uint32_t LAYER_STACK = 0;
448 for (auto id : physicalDisplayIds) {
449 if (std::find(ids.begin(), ids.end(), id) != ids.end()) {
450 sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(id);
451 if (token != nullptr)
452 t.setDisplayLayerStack(token, LAYER_STACK);
453 }
454 }
455 t.setLayerStack(control, LAYER_STACK);
456 }
457
Robert Carre13b58e2017-08-31 14:50:44 -0700458 t.setLayer(control, 0x40000000)
459 .apply();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800460
Mathias Agopian17f638b2009-04-16 20:04:08 -0700461 sp<Surface> s = control->getSurface();
462
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800463 // initialize opengl and egl
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
Yi Kong911ac232019-03-24 01:49:02 -0700465 eglInitialize(display, nullptr, nullptr);
Marin Shalamanov9070c052020-05-18 19:05:17 +0200466 EGLConfig config = getEglConfig(display);
467 EGLSurface surface = eglCreateWindowSurface(display, config, s.get(), nullptr);
468 EGLContext context = eglCreateContext(display, config, nullptr, nullptr);
469 EGLint w, h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800470 eglQuerySurface(display, surface, EGL_WIDTH, &w);
471 eglQuerySurface(display, surface, EGL_HEIGHT, &h);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700472
Mathias Agopianabac0102009-07-31 14:47:00 -0700473 if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE)
474 return NO_INIT;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700475
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 mDisplay = display;
477 mContext = context;
478 mSurface = surface;
479 mWidth = w;
480 mHeight = h;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700481 mFlingerSurfaceControl = control;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 mFlingerSurface = s;
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200483 mTargetInset = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484
Yegor Malyshev6925e1b2020-09-10 16:42:20 +0200485 projectSceneToWindow();
486
Marin Shalamanov9070c052020-05-18 19:05:17 +0200487 // Register a display event receiver
488 mDisplayEventReceiver = std::make_unique<DisplayEventReceiver>();
489 status_t status = mDisplayEventReceiver->initCheck();
490 SLOGE_IF(status != NO_ERROR, "Initialization of DisplayEventReceiver failed with status: %d",
491 status);
492 mLooper->addFd(mDisplayEventReceiver->getFd(), 0, Looper::EVENT_INPUT,
493 new DisplayEventCallback(this), nullptr);
494
Huihong Luo50a2f362018-08-11 09:27:57 -0700495 return NO_ERROR;
496}
497
Yegor Malyshev6925e1b2020-09-10 16:42:20 +0200498void BootAnimation::projectSceneToWindow() {
499 glViewport(0, 0, mWidth, mHeight);
500 glScissor(0, 0, mWidth, mHeight);
501 glMatrixMode(GL_PROJECTION);
502 glLoadIdentity();
503 glOrthof(0, static_cast<float>(mWidth), 0, static_cast<float>(mHeight), -1, 1);
504 glMatrixMode(GL_MODELVIEW);
505 glLoadIdentity();
506}
507
Marin Shalamanov9070c052020-05-18 19:05:17 +0200508void BootAnimation::resizeSurface(int newWidth, int newHeight) {
509 // We assume this function is called on the animation thread.
510 if (newWidth == mWidth && newHeight == mHeight) {
511 return;
512 }
513 SLOGV("Resizing the boot animation surface to %d %d", newWidth, newHeight);
514
515 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
516 eglDestroySurface(mDisplay, mSurface);
517
Marin Shalamanov047802d2020-05-19 23:55:12 +0200518 const auto limitedSize = limitSurfaceSize(newWidth, newHeight);
519 mWidth = limitedSize.width;
520 mHeight = limitedSize.height;
Marin Shalamanov9070c052020-05-18 19:05:17 +0200521
522 SurfaceComposerClient::Transaction t;
523 t.setSize(mFlingerSurfaceControl, mWidth, mHeight);
524 t.apply();
525
526 EGLConfig config = getEglConfig(mDisplay);
527 EGLSurface surface = eglCreateWindowSurface(mDisplay, config, mFlingerSurface.get(), nullptr);
528 if (eglMakeCurrent(mDisplay, surface, surface, mContext) == EGL_FALSE) {
529 SLOGE("Can't make the new surface current. Error %d", eglGetError());
530 return;
531 }
Yegor Malyshev6925e1b2020-09-10 16:42:20 +0200532
533 projectSceneToWindow();
Marin Shalamanov9070c052020-05-18 19:05:17 +0200534
535 mSurface = surface;
536}
537
Huihong Luo50a2f362018-08-11 09:27:57 -0700538bool BootAnimation::preloadAnimation() {
539 findBootAnimationFile();
540 if (!mZipFileName.isEmpty()) {
541 mAnimation = loadAnimation(mZipFileName);
542 return (mAnimation != nullptr);
543 }
544
545 return false;
546}
547
Nikita Ioffe06c986e2020-01-27 17:16:03 +0000548bool BootAnimation::findBootAnimationFileInternal(const std::vector<std::string> &files) {
549 for (const std::string& f : files) {
550 if (access(f.c_str(), R_OK) == 0) {
551 mZipFileName = f.c_str();
552 return true;
553 }
554 }
555 return false;
556}
557
Huihong Luo50a2f362018-08-11 09:27:57 -0700558void BootAnimation::findBootAnimationFile() {
Elliott Hughesc367d482013-10-29 13:12:55 -0700559 // If the device has encryption turned on or is in process
Jason parksbd9a08d2011-01-31 15:04:34 -0600560 // of being encrypted we show the encrypted boot animation.
561 char decrypt[PROPERTY_VALUE_MAX];
562 property_get("vold.decrypt", decrypt, "");
563
Keun-young Parkb5938422017-03-23 13:46:24 -0700564 bool encryptedAnimation = atoi(decrypt) != 0 ||
565 !strcmp("trigger_restart_min_framework", decrypt);
Jason parksbd9a08d2011-01-31 15:04:34 -0600566
Jaekyun Seokc521bb32018-01-30 11:52:47 +0900567 if (!mShuttingDown && encryptedAnimation) {
Nikita Ioffe06c986e2020-01-27 17:16:03 +0000568 static const std::vector<std::string> encryptedBootFiles = {
569 PRODUCT_ENCRYPTED_BOOTANIMATION_FILE, SYSTEM_ENCRYPTED_BOOTANIMATION_FILE,
570 };
571 if (findBootAnimationFileInternal(encryptedBootFiles)) {
572 return;
Jaekyun Seokc521bb32018-01-30 11:52:47 +0900573 }
Jason parksbd9a08d2011-01-31 15:04:34 -0600574 }
Beverly34ffe252019-05-17 11:03:54 -0400575
576 const bool playDarkAnim = android::base::GetIntProperty("ro.boot.theme", 0) == 1;
Nikita Ioffe06c986e2020-01-27 17:16:03 +0000577 static const std::vector<std::string> bootFiles = {
578 APEX_BOOTANIMATION_FILE, playDarkAnim ? PRODUCT_BOOTANIMATION_DARK_FILE : PRODUCT_BOOTANIMATION_FILE,
579 OEM_BOOTANIMATION_FILE, SYSTEM_BOOTANIMATION_FILE
580 };
581 static const std::vector<std::string> shutdownFiles = {
582 PRODUCT_SHUTDOWNANIMATION_FILE, OEM_SHUTDOWNANIMATION_FILE, SYSTEM_SHUTDOWNANIMATION_FILE, ""
583 };
584 static const std::vector<std::string> userspaceRebootFiles = {
585 PRODUCT_USERSPACE_REBOOT_ANIMATION_FILE, OEM_USERSPACE_REBOOT_ANIMATION_FILE,
586 SYSTEM_USERSPACE_REBOOT_ANIMATION_FILE,
587 };
Keun-young Parkb5938422017-03-23 13:46:24 -0700588
Nikita Ioffe06c986e2020-01-27 17:16:03 +0000589 if (android::base::GetBoolProperty("sys.init.userspace_reboot.in_progress", false)) {
590 findBootAnimationFileInternal(userspaceRebootFiles);
591 } else if (mShuttingDown) {
592 findBootAnimationFileInternal(shutdownFiles);
593 } else {
594 findBootAnimationFileInternal(bootFiles);
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700595 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800596}
597
Marin Shalamanov9070c052020-05-18 19:05:17 +0200598bool BootAnimation::threadLoop() {
599 bool result;
Narayan Kamathafd31e02013-12-03 13:16:03 +0000600 // We have no bootanimation file, so we use the stock android logo
601 // animation.
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700602 if (mZipFileName.isEmpty()) {
Marin Shalamanov9070c052020-05-18 19:05:17 +0200603 result = android();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700604 } else {
Marin Shalamanov9070c052020-05-18 19:05:17 +0200605 result = movie();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700606 }
607
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
609 eglDestroyContext(mDisplay, mContext);
610 eglDestroySurface(mDisplay, mSurface);
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700611 mFlingerSurface.clear();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700612 mFlingerSurfaceControl.clear();
Mathias Agopian627e7b52009-05-21 19:21:59 -0700613 eglTerminate(mDisplay);
Sai Kiran Korwar3eee9fb2015-06-16 17:13:35 +0530614 eglReleaseThread();
Mathias Agopian627e7b52009-05-21 19:21:59 -0700615 IPCThreadState::self()->stopProcess();
Marin Shalamanov9070c052020-05-18 19:05:17 +0200616 return result;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617}
618
Marin Shalamanov9070c052020-05-18 19:05:17 +0200619bool BootAnimation::android() {
Wei Wang159a4102018-10-23 23:15:58 -0700620 SLOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
Keun-young Parkd1794cd2017-04-04 12:21:19 -0700621 elapsedRealtime());
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700622 initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png");
623 initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624
Ed Coyne7464ac92017-06-08 12:26:48 -0700625 mCallbacks->init({});
626
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800627 // clear screen
Mathias Agopiana8826d62009-10-01 03:10:14 -0700628 glShadeModel(GL_FLAT);
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700629 glDisable(GL_DITHER);
630 glDisable(GL_SCISSOR_TEST);
Mathias Agopian59f19e42011-05-06 19:22:12 -0700631 glClearColor(0,0,0,1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 glClear(GL_COLOR_BUFFER_BIT);
633 eglSwapBuffers(mDisplay, mSurface);
634
Mathias Agopiana8826d62009-10-01 03:10:14 -0700635 glEnable(GL_TEXTURE_2D);
636 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
637
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700638 // Blend state
639 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
640 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
641
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800642 const nsecs_t startTime = systemTime();
643 do {
Marin Shalamanov9070c052020-05-18 19:05:17 +0200644 processDisplayEvents();
645 const GLint xc = (mWidth - mAndroid[0].w) / 2;
646 const GLint yc = (mHeight - mAndroid[0].h) / 2;
647 const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h);
648 glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(),
649 updateRect.height());
650
Mathias Agopian13796652009-03-24 22:49:21 -0700651 nsecs_t now = systemTime();
652 double time = now - startTime;
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700653 float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w;
654 GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w;
655 GLint x = xc - offset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656
Mathias Agopian81668642009-07-28 11:41:30 -0700657 glDisable(GL_SCISSOR_TEST);
658 glClear(GL_COLOR_BUFFER_BIT);
659
660 glEnable(GL_SCISSOR_TEST);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800661 glDisable(GL_BLEND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800662 glBindTexture(GL_TEXTURE_2D, mAndroid[1].name);
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700663 glDrawTexiOES(x, yc, 0, mAndroid[1].w, mAndroid[1].h);
664 glDrawTexiOES(x + mAndroid[1].w, yc, 0, mAndroid[1].w, mAndroid[1].h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700666 glEnable(GL_BLEND);
667 glBindTexture(GL_TEXTURE_2D, mAndroid[0].name);
668 glDrawTexiOES(xc, yc, 0, mAndroid[0].w, mAndroid[0].h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800669
Mathias Agopian627e7b52009-05-21 19:21:59 -0700670 EGLBoolean res = eglSwapBuffers(mDisplay, mSurface);
671 if (res == EGL_FALSE)
672 break;
673
Mathias Agopian13796652009-03-24 22:49:21 -0700674 // 12fps: don't animate too fast to preserve CPU
675 const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now);
676 if (sleepTime > 0)
Mathias Agopiana8826d62009-10-01 03:10:14 -0700677 usleep(sleepTime);
Kevin Hesterd3782b22012-04-26 10:38:55 -0700678
679 checkExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800680 } while (!exitPending());
681
682 glDeleteTextures(1, &mAndroid[0].name);
683 glDeleteTextures(1, &mAndroid[1].name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800684 return false;
685}
686
Kevin Hesterd3782b22012-04-26 10:38:55 -0700687void BootAnimation::checkExit() {
688 // Allow surface flinger to gracefully request shutdown
689 char value[PROPERTY_VALUE_MAX];
690 property_get(EXIT_PROP_NAME, value, "0");
691 int exitnow = atoi(value);
692 if (exitnow) {
693 requestExit();
Ed Coyne7464ac92017-06-08 12:26:48 -0700694 mCallbacks->shutdown();
Kevin Hesterd3782b22012-04-26 10:38:55 -0700695 }
696}
697
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700698bool BootAnimation::validClock(const Animation::Part& part) {
699 return part.clockPosX != TEXT_MISSING_VALUE && part.clockPosY != TEXT_MISSING_VALUE;
700}
701
702bool parseTextCoord(const char* str, int* dest) {
703 if (strcmp("c", str) == 0) {
704 *dest = TEXT_CENTER_VALUE;
705 return true;
706 }
707
708 char* end;
709 int val = (int) strtol(str, &end, 0);
710 if (end == str || *end != '\0' || val == INT_MAX || val == INT_MIN) {
711 return false;
712 }
713 *dest = val;
714 return true;
715}
716
717// Parse two position coordinates. If only string is non-empty, treat it as the y value.
718void parsePosition(const char* str1, const char* str2, int* x, int* y) {
719 bool success = false;
720 if (strlen(str1) == 0) { // No values were specified
721 // success = false
722 } else if (strlen(str2) == 0) { // we have only one value
723 if (parseTextCoord(str1, y)) {
724 *x = TEXT_CENTER_VALUE;
725 success = true;
726 }
727 } else {
728 if (parseTextCoord(str1, x) && parseTextCoord(str2, y)) {
729 success = true;
730 }
731 }
732
733 if (!success) {
734 *x = TEXT_MISSING_VALUE;
735 *y = TEXT_MISSING_VALUE;
736 }
737}
738
Jesse Hall083b84c2014-09-22 10:51:09 -0700739// Parse a color represented as an HTML-style 'RRGGBB' string: each pair of
740// characters in str is a hex number in [0, 255], which are converted to
741// floating point values in the range [0.0, 1.0] and placed in the
742// corresponding elements of color.
743//
744// If the input string isn't valid, parseColor returns false and color is
745// left unchanged.
746static bool parseColor(const char str[7], float color[3]) {
747 float tmpColor[3];
748 for (int i = 0; i < 3; i++) {
749 int val = 0;
750 for (int j = 0; j < 2; j++) {
751 val *= 16;
752 char c = str[2*i + j];
753 if (c >= '0' && c <= '9') val += c - '0';
754 else if (c >= 'A' && c <= 'F') val += (c - 'A') + 10;
755 else if (c >= 'a' && c <= 'f') val += (c - 'a') + 10;
756 else return false;
757 }
758 tmpColor[i] = static_cast<float>(val) / 255.0f;
759 }
760 memcpy(color, tmpColor, sizeof(tmpColor));
761 return true;
762}
763
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700764
Marin Shalamanov9070c052020-05-18 19:05:17 +0200765static bool readFile(ZipFileRO* zip, const char* name, String8& outString) {
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700766 ZipEntryRO entry = zip->findEntryByName(name);
Wei Wang159a4102018-10-23 23:15:58 -0700767 SLOGE_IF(!entry, "couldn't find %s", name);
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700768 if (!entry) {
769 return false;
770 }
771
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700772 FileMap* entryMap = zip->createEntryFileMap(entry);
773 zip->releaseEntry(entry);
Wei Wang159a4102018-10-23 23:15:58 -0700774 SLOGE_IF(!entryMap, "entryMap is null");
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700775 if (!entryMap) {
776 return false;
777 }
778
779 outString.setTo((char const*)entryMap->getDataPtr(), entryMap->getDataLength());
Narayan Kamath688ff4c2015-02-23 15:47:54 +0000780 delete entryMap;
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700781 return true;
782}
783
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700784// The font image should be a 96x2 array of character images. The
785// columns are the printable ASCII characters 0x20 - 0x7f. The
786// top row is regular text; the bottom row is bold.
787status_t BootAnimation::initFont(Font* font, const char* fallback) {
788 status_t status = NO_ERROR;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800789
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700790 if (font->map != nullptr) {
791 glGenTextures(1, &font->texture.name);
792 glBindTexture(GL_TEXTURE_2D, font->texture.name);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800793
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700794 status = initTexture(font->map, &font->texture.w, &font->texture.h);
795
796 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
797 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
798 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
799 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
800 } else if (fallback != nullptr) {
801 status = initTexture(&font->texture, mAssets, fallback);
802 } else {
803 return NO_INIT;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800804 }
805
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700806 if (status == NO_ERROR) {
807 font->char_width = font->texture.w / FONT_NUM_COLS;
808 font->char_height = font->texture.h / FONT_NUM_ROWS / 2; // There are bold and regular rows
809 }
810
811 return status;
812}
813
Yegor Malyshev6925e1b2020-09-10 16:42:20 +0200814void BootAnimation::fadeFrame(const int frameLeft, const int frameBottom, const int frameWidth,
815 const int frameHeight, const Animation::Part& part,
816 const int fadedFramesCount) {
817 glEnable(GL_BLEND);
818 glEnableClientState(GL_VERTEX_ARRAY);
819 glDisable(GL_TEXTURE_2D);
820 // avoid creating a hole due to mixing result alpha with GL_REPLACE texture
821 glBlendFuncSeparateOES(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE);
822
823 const float alpha = static_cast<float>(fadedFramesCount) / part.framesToFadeCount;
824 glColor4f(part.backgroundColor[0], part.backgroundColor[1], part.backgroundColor[2], alpha);
825
826 const float frameStartX = static_cast<float>(frameLeft);
827 const float frameStartY = static_cast<float>(frameBottom);
828 const float frameEndX = frameStartX + frameWidth;
829 const float frameEndY = frameStartY + frameHeight;
830 const GLfloat frameRect[] = {
831 frameStartX, frameStartY,
832 frameEndX, frameStartY,
833 frameEndX, frameEndY,
834 frameStartX, frameEndY
835 };
836 glVertexPointer(2, GL_FLOAT, 0, frameRect);
837 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
838
839 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
840 glEnable(GL_TEXTURE_2D);
841 glDisableClientState(GL_VERTEX_ARRAY);
842 glDisable(GL_BLEND);
843}
844
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700845void BootAnimation::drawText(const char* str, const Font& font, bool bold, int* x, int* y) {
846 glEnable(GL_BLEND); // Allow us to draw on top of the animation
847 glBindTexture(GL_TEXTURE_2D, font.texture.name);
848
849 const int len = strlen(str);
850 const int strWidth = font.char_width * len;
851
852 if (*x == TEXT_CENTER_VALUE) {
853 *x = (mWidth - strWidth) / 2;
854 } else if (*x < 0) {
855 *x = mWidth + *x - strWidth;
856 }
857 if (*y == TEXT_CENTER_VALUE) {
858 *y = (mHeight - font.char_height) / 2;
859 } else if (*y < 0) {
860 *y = mHeight + *y - font.char_height;
861 }
862
863 int cropRect[4] = { 0, 0, font.char_width, -font.char_height };
864
865 for (int i = 0; i < len; i++) {
866 char c = str[i];
867
868 if (c < FONT_BEGIN_CHAR || c > FONT_END_CHAR) {
869 c = '?';
870 }
871
872 // Crop the texture to only the pixels in the current glyph
873 const int charPos = (c - FONT_BEGIN_CHAR); // Position in the list of valid characters
874 const int row = charPos / FONT_NUM_COLS;
875 const int col = charPos % FONT_NUM_COLS;
876 cropRect[0] = col * font.char_width; // Left of column
877 cropRect[1] = row * font.char_height * 2; // Top of row
878 // Move down to bottom of regular (one char_heigh) or bold (two char_heigh) line
879 cropRect[1] += bold ? 2 * font.char_height : font.char_height;
880 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect);
881
882 glDrawTexiOES(*x, *y, 0, font.char_width, font.char_height);
883
884 *x += font.char_width;
885 }
886
887 glDisable(GL_BLEND); // Return to the animation's default behaviour
888 glBindTexture(GL_TEXTURE_2D, 0);
889}
890
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700891// We render 12 or 24 hour time.
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700892void BootAnimation::drawClock(const Font& font, const int xPos, const int yPos) {
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700893 static constexpr char TIME_FORMAT_12[] = "%l:%M";
894 static constexpr char TIME_FORMAT_24[] = "%H:%M";
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700895 static constexpr int TIME_LENGTH = 6;
896
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800897 time_t rawtime;
898 time(&rawtime);
899 struct tm* timeInfo = localtime(&rawtime);
900
901 char timeBuff[TIME_LENGTH];
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700902 const char* timeFormat = mTimeFormat12Hour ? TIME_FORMAT_12 : TIME_FORMAT_24;
903 size_t length = strftime(timeBuff, TIME_LENGTH, timeFormat, timeInfo);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800904
905 if (length != TIME_LENGTH - 1) {
Wei Wang159a4102018-10-23 23:15:58 -0700906 SLOGE("Couldn't format time; abandoning boot animation clock");
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800907 mClockEnabled = false;
908 return;
909 }
910
Damien Bargiacchi45a76442016-12-05 18:02:18 -0800911 char* out = timeBuff[0] == ' ' ? &timeBuff[1] : &timeBuff[0];
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700912 int x = xPos;
913 int y = yPos;
Damien Bargiacchi45a76442016-12-05 18:02:18 -0800914 drawText(out, font, false, &x, &y);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800915}
916
Marin Shalamanov9070c052020-05-18 19:05:17 +0200917bool BootAnimation::parseAnimationDesc(Animation& animation) {
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700918 String8 desString;
919
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700920 if (!readFile(animation.zip, "desc.txt", desString)) {
Narayan Kamathafd31e02013-12-03 13:16:03 +0000921 return false;
922 }
Mathias Agopiana8826d62009-10-01 03:10:14 -0700923 char const* s = desString.string();
924
Mathias Agopiana8826d62009-10-01 03:10:14 -0700925 // Parse the description file
926 for (;;) {
927 const char* endl = strstr(s, "\n");
Yi Kong911ac232019-03-24 01:49:02 -0700928 if (endl == nullptr) break;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700929 String8 line(s, endl - s);
930 const char* l = line.string();
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800931 int fps = 0;
932 int width = 0;
933 int height = 0;
934 int count = 0;
935 int pause = 0;
Yegor Malyshev6925e1b2020-09-10 16:42:20 +0200936 int framesToFadeCount = 0;
Narayan Kamathafd31e02013-12-03 13:16:03 +0000937 char path[ANIM_ENTRY_NAME_MAX];
Jesse Hall083b84c2014-09-22 10:51:09 -0700938 char color[7] = "000000"; // default to black if unspecified
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700939 char clockPos1[TEXT_POS_LEN_MAX + 1] = "";
940 char clockPos2[TEXT_POS_LEN_MAX + 1] = "";
Kevin Hesterd3782b22012-04-26 10:38:55 -0700941 char pathType;
Yegor Malyshev6925e1b2020-09-10 16:42:20 +0200942
943 int nextReadPos;
944
Mathias Agopiana8826d62009-10-01 03:10:14 -0700945 if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) {
Wei Wang159a4102018-10-23 23:15:58 -0700946 // SLOGD("> w=%d, h=%d, fps=%d", width, height, fps);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700947 animation.width = width;
948 animation.height = height;
949 animation.fps = fps;
Yegor Malyshev6925e1b2020-09-10 16:42:20 +0200950 } else if (sscanf(l, "%c %d %d %" STRTO(ANIM_PATH_MAX) "s%n",
951 &pathType, &count, &pause, path, &nextReadPos) >= 4) {
952 if (pathType == 'f') {
953 sscanf(l + nextReadPos, " %d #%6s %16s %16s", &framesToFadeCount, color, clockPos1,
954 clockPos2);
955 } else {
956 sscanf(l + nextReadPos, " #%6s %16s %16s", color, clockPos1, clockPos2);
957 }
958 // SLOGD("> type=%c, count=%d, pause=%d, path=%s, framesToFadeCount=%d, color=%s, "
959 // "clockPos1=%s, clockPos2=%s",
960 // pathType, count, pause, path, framesToFadeCount, color, clockPos1, clockPos2);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700961 Animation::Part part;
Kevin Hesterd3782b22012-04-26 10:38:55 -0700962 part.playUntilComplete = pathType == 'c';
Yegor Malyshev6925e1b2020-09-10 16:42:20 +0200963 part.framesToFadeCount = framesToFadeCount;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700964 part.count = count;
965 part.pause = pause;
966 part.path = path;
Yi Kong911ac232019-03-24 01:49:02 -0700967 part.audioData = nullptr;
968 part.animation = nullptr;
Jesse Hall083b84c2014-09-22 10:51:09 -0700969 if (!parseColor(color, part.backgroundColor)) {
Wei Wang159a4102018-10-23 23:15:58 -0700970 SLOGE("> invalid color '#%s'", color);
Jesse Hall083b84c2014-09-22 10:51:09 -0700971 part.backgroundColor[0] = 0.0f;
972 part.backgroundColor[1] = 0.0f;
973 part.backgroundColor[2] = 0.0f;
974 }
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700975 parsePosition(clockPos1, clockPos2, &part.clockPosX, &part.clockPosY);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700976 animation.parts.add(part);
977 }
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700978 else if (strcmp(l, "$SYSTEM") == 0) {
Wei Wang159a4102018-10-23 23:15:58 -0700979 // SLOGD("> SYSTEM");
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700980 Animation::Part part;
981 part.playUntilComplete = false;
Yegor Malyshev6925e1b2020-09-10 16:42:20 +0200982 part.framesToFadeCount = 0;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700983 part.count = 1;
984 part.pause = 0;
Yi Kong911ac232019-03-24 01:49:02 -0700985 part.audioData = nullptr;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700986 part.animation = loadAnimation(String8(SYSTEM_BOOTANIMATION_FILE));
Yi Kong911ac232019-03-24 01:49:02 -0700987 if (part.animation != nullptr)
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700988 animation.parts.add(part);
989 }
Mathias Agopiana8826d62009-10-01 03:10:14 -0700990 s = ++endl;
991 }
992
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700993 return true;
994}
995
Marin Shalamanov9070c052020-05-18 19:05:17 +0200996bool BootAnimation::preloadZip(Animation& animation) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700997 // read all the data structures
998 const size_t pcount = animation.parts.size();
Yi Kong911ac232019-03-24 01:49:02 -0700999 void *cookie = nullptr;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001000 ZipFileRO* zip = animation.zip;
1001 if (!zip->startIteration(&cookie)) {
Narayan Kamathafd31e02013-12-03 13:16:03 +00001002 return false;
1003 }
1004
1005 ZipEntryRO entry;
1006 char name[ANIM_ENTRY_NAME_MAX];
Yi Kong911ac232019-03-24 01:49:02 -07001007 while ((entry = zip->nextEntry(cookie)) != nullptr) {
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001008 const int foundEntryName = zip->getEntryFileName(entry, name, ANIM_ENTRY_NAME_MAX);
Narayan Kamathafd31e02013-12-03 13:16:03 +00001009 if (foundEntryName > ANIM_ENTRY_NAME_MAX || foundEntryName == -1) {
Wei Wang159a4102018-10-23 23:15:58 -07001010 SLOGE("Error fetching entry file name");
Narayan Kamathafd31e02013-12-03 13:16:03 +00001011 continue;
1012 }
1013
1014 const String8 entryName(name);
1015 const String8 path(entryName.getPathDir());
1016 const String8 leaf(entryName.getPathLeaf());
1017 if (leaf.size() > 0) {
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001018 if (entryName == CLOCK_FONT_ZIP_NAME) {
1019 FileMap* map = zip->createEntryFileMap(entry);
1020 if (map) {
1021 animation.clockFont.map = map;
1022 }
1023 continue;
1024 }
1025
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001026 for (size_t j = 0; j < pcount; j++) {
Narayan Kamathafd31e02013-12-03 13:16:03 +00001027 if (path == animation.parts[j].path) {
Narayan Kamath4600dd02015-06-16 12:02:57 +01001028 uint16_t method;
Narayan Kamathafd31e02013-12-03 13:16:03 +00001029 // supports only stored png files
Yi Kong911ac232019-03-24 01:49:02 -07001030 if (zip->getEntryInfo(entry, &method, nullptr, nullptr, nullptr, nullptr, nullptr)) {
Narayan Kamathafd31e02013-12-03 13:16:03 +00001031 if (method == ZipFileRO::kCompressStored) {
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001032 FileMap* map = zip->createEntryFileMap(entry);
Narayan Kamathafd31e02013-12-03 13:16:03 +00001033 if (map) {
Narayan Kamathafd31e02013-12-03 13:16:03 +00001034 Animation::Part& part(animation.parts.editItemAt(j));
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -07001035 if (leaf == "audio.wav") {
1036 // a part may have at most one audio file
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -07001037 part.audioData = (uint8_t *)map->getDataPtr();
1038 part.audioLength = map->getDataLength();
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001039 } else if (leaf == "trim.txt") {
1040 part.trimData.setTo((char const*)map->getDataPtr(),
1041 map->getDataLength());
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -07001042 } else {
1043 Animation::Frame frame;
1044 frame.name = leaf;
1045 frame.map = map;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001046 frame.trimWidth = animation.width;
1047 frame.trimHeight = animation.height;
1048 frame.trimX = 0;
1049 frame.trimY = 0;
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -07001050 part.frames.add(frame);
1051 }
Mathias Agopiana8826d62009-10-01 03:10:14 -07001052 }
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -07001053 } else {
Wei Wang159a4102018-10-23 23:15:58 -07001054 SLOGE("bootanimation.zip is compressed; must be only stored");
Mathias Agopiana8826d62009-10-01 03:10:14 -07001055 }
1056 }
1057 }
1058 }
1059 }
1060 }
1061
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001062 // If there is trimData present, override the positioning defaults.
1063 for (Animation::Part& part : animation.parts) {
1064 const char* trimDataStr = part.trimData.string();
1065 for (size_t frameIdx = 0; frameIdx < part.frames.size(); frameIdx++) {
1066 const char* endl = strstr(trimDataStr, "\n");
1067 // No more trimData for this part.
Yi Kong911ac232019-03-24 01:49:02 -07001068 if (endl == nullptr) {
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001069 break;
1070 }
1071 String8 line(trimDataStr, endl - trimDataStr);
1072 const char* lineStr = line.string();
1073 trimDataStr = ++endl;
1074 int width = 0, height = 0, x = 0, y = 0;
1075 if (sscanf(lineStr, "%dx%d+%d+%d", &width, &height, &x, &y) == 4) {
1076 Animation::Frame& frame(part.frames.editItemAt(frameIdx));
1077 frame.trimWidth = width;
1078 frame.trimHeight = height;
1079 frame.trimX = x;
1080 frame.trimY = y;
1081 } else {
Wei Wang159a4102018-10-23 23:15:58 -07001082 SLOGE("Error parsing trim.txt, line: %s", lineStr);
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001083 break;
1084 }
1085 }
1086 }
1087
1088 zip->endIteration(cookie);
Narayan Kamathafd31e02013-12-03 13:16:03 +00001089
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001090 return true;
1091}
1092
Marin Shalamanov9070c052020-05-18 19:05:17 +02001093bool BootAnimation::movie() {
Huihong Luo50a2f362018-08-11 09:27:57 -07001094 if (mAnimation == nullptr) {
1095 mAnimation = loadAnimation(mZipFileName);
1096 }
1097
1098 if (mAnimation == nullptr)
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001099 return false;
1100
Huihong Luo50a2f362018-08-11 09:27:57 -07001101 // mCallbacks->init() may get called recursively,
1102 // this loop is needed to get the same results
1103 for (const Animation::Part& part : mAnimation->parts) {
1104 if (part.animation != nullptr) {
1105 mCallbacks->init(part.animation->parts);
1106 }
1107 }
1108 mCallbacks->init(mAnimation->parts);
1109
Damien Bargiacchi97480862016-03-29 14:55:55 -07001110 bool anyPartHasClock = false;
Huihong Luo50a2f362018-08-11 09:27:57 -07001111 for (size_t i=0; i < mAnimation->parts.size(); i++) {
1112 if(validClock(mAnimation->parts[i])) {
Damien Bargiacchi97480862016-03-29 14:55:55 -07001113 anyPartHasClock = true;
1114 break;
1115 }
1116 }
1117 if (!anyPartHasClock) {
1118 mClockEnabled = false;
1119 }
1120
Sai Kiran Korwar27167492015-07-07 20:00:06 +05301121 // Check if npot textures are supported
1122 mUseNpotTextures = false;
1123 String8 gl_extensions;
1124 const char* exts = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
1125 if (!exts) {
1126 glGetError();
1127 } else {
1128 gl_extensions.setTo(exts);
1129 if ((gl_extensions.find("GL_ARB_texture_non_power_of_two") != -1) ||
1130 (gl_extensions.find("GL_OES_texture_npot") != -1)) {
1131 mUseNpotTextures = true;
1132 }
1133 }
1134
Damien Bargiacchia704b7d2016-02-16 16:55:49 -08001135 // Blend required to draw time on top of animation frames.
1136 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopiana8826d62009-10-01 03:10:14 -07001137 glShadeModel(GL_FLAT);
1138 glDisable(GL_DITHER);
1139 glDisable(GL_SCISSOR_TEST);
1140 glDisable(GL_BLEND);
Mathias Agopiana8826d62009-10-01 03:10:14 -07001141
1142 glBindTexture(GL_TEXTURE_2D, 0);
1143 glEnable(GL_TEXTURE_2D);
1144 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1145 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
1146 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
1147 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1148 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1149
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001150 bool clockFontInitialized = false;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -08001151 if (mClockEnabled) {
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001152 clockFontInitialized =
Huihong Luo50a2f362018-08-11 09:27:57 -07001153 (initFont(&mAnimation->clockFont, CLOCK_FONT_ASSET) == NO_ERROR);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001154 mClockEnabled = clockFontInitialized;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -08001155 }
1156
Damien Bargiacchi97480862016-03-29 14:55:55 -07001157 if (mClockEnabled && !updateIsTimeAccurate()) {
1158 mTimeCheckThread = new TimeCheckThread(this);
1159 mTimeCheckThread->run("BootAnimation::TimeCheckThread", PRIORITY_NORMAL);
1160 }
1161
Huihong Luo50a2f362018-08-11 09:27:57 -07001162 playAnimation(*mAnimation);
Damien Bargiacchi97480862016-03-29 14:55:55 -07001163
Geoffrey Pitscha9173532016-07-19 14:56:39 -04001164 if (mTimeCheckThread != nullptr) {
Damien Bargiacchi97480862016-03-29 14:55:55 -07001165 mTimeCheckThread->requestExit();
Geoffrey Pitscha9173532016-07-19 14:56:39 -04001166 mTimeCheckThread = nullptr;
1167 }
1168
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001169 if (clockFontInitialized) {
Huihong Luo50a2f362018-08-11 09:27:57 -07001170 glDeleteTextures(1, &mAnimation->clockFont.texture.name);
Andriy Naborskyy815e51d2016-03-24 16:43:34 -07001171 }
1172
Huihong Luo50a2f362018-08-11 09:27:57 -07001173 releaseAnimation(mAnimation);
1174 mAnimation = nullptr;
Damien Bargiacchi1a8a2132018-07-24 15:20:26 -07001175
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001176 return false;
1177}
1178
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001179bool BootAnimation::shouldStopPlayingPart(const Animation::Part& part, const int fadedFramesCount) {
1180 // stop playing only if it is time to exit and it's a partial part which has been faded out
1181 return exitPending() && !part.playUntilComplete && fadedFramesCount >= part.framesToFadeCount;
1182}
1183
Marin Shalamanov9070c052020-05-18 19:05:17 +02001184bool BootAnimation::playAnimation(const Animation& animation) {
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001185 const size_t pcount = animation.parts.size();
Mathias Agopiana8826d62009-10-01 03:10:14 -07001186 nsecs_t frameDuration = s2ns(1) / animation.fps;
Mathias Agopian9f3020d2009-11-06 16:30:18 -08001187
Wei Wang159a4102018-10-23 23:15:58 -07001188 SLOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
Keun-young Parkd1794cd2017-04-04 12:21:19 -07001189 elapsedRealtime());
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001190
1191 int fadedFramesCount = 0;
Narayan Kamathafd31e02013-12-03 13:16:03 +00001192 for (size_t i=0 ; i<pcount ; i++) {
Mathias Agopiana8826d62009-10-01 03:10:14 -07001193 const Animation::Part& part(animation.parts[i]);
1194 const size_t fcount = part.frames.size();
1195 glBindTexture(GL_TEXTURE_2D, 0);
1196
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001197 // Handle animation package
Yi Kong911ac232019-03-24 01:49:02 -07001198 if (part.animation != nullptr) {
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001199 playAnimation(*part.animation);
1200 if (exitPending())
1201 break;
1202 continue; //to next part
1203 }
1204
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001205 // process the part not only while the count allows but also if already fading
1206 for (int r=0 ; !part.count || r<part.count || fadedFramesCount > 0 ; r++) {
1207 if (shouldStopPlayingPart(part, fadedFramesCount)) break;
Kevin Hesterd3782b22012-04-26 10:38:55 -07001208
Ed Coyne7464ac92017-06-08 12:26:48 -07001209 mCallbacks->playPart(i, part, r);
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -07001210
Jesse Hall083b84c2014-09-22 10:51:09 -07001211 glClearColor(
1212 part.backgroundColor[0],
1213 part.backgroundColor[1],
1214 part.backgroundColor[2],
1215 1.0f);
1216
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001217 for (size_t j=0 ; j<fcount ; j++) {
1218 if (shouldStopPlayingPart(part, fadedFramesCount)) break;
1219
Marin Shalamanov9070c052020-05-18 19:05:17 +02001220 processDisplayEvents();
1221
1222 const int animationX = (mWidth - animation.width) / 2;
1223 const int animationY = (mHeight - animation.height) / 2;
1224
Mathias Agopiana8826d62009-10-01 03:10:14 -07001225 const Animation::Frame& frame(part.frames[j]);
Mathias Agopiandb7dd2a2012-05-12 15:08:21 -07001226 nsecs_t lastFrame = systemTime();
Mathias Agopiana8826d62009-10-01 03:10:14 -07001227
1228 if (r > 0) {
1229 glBindTexture(GL_TEXTURE_2D, frame.tid);
1230 } else {
1231 if (part.count != 1) {
1232 glGenTextures(1, &frame.tid);
1233 glBindTexture(GL_TEXTURE_2D, frame.tid);
1234 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1235 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1236 }
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001237 int w, h;
1238 initTexture(frame.map, &w, &h);
Mathias Agopiana8826d62009-10-01 03:10:14 -07001239 }
1240
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001241 const int xc = animationX + frame.trimX;
1242 const int yc = animationY + frame.trimY;
1243 Region clearReg(Rect(mWidth, mHeight));
1244 clearReg.subtractSelf(Rect(xc, yc, xc+frame.trimWidth, yc+frame.trimHeight));
Mathias Agopian9f3020d2009-11-06 16:30:18 -08001245 if (!clearReg.isEmpty()) {
1246 Region::const_iterator head(clearReg.begin());
1247 Region::const_iterator tail(clearReg.end());
1248 glEnable(GL_SCISSOR_TEST);
1249 while (head != tail) {
Andreas Gampecfedceb2014-09-30 21:48:18 -07001250 const Rect& r2(*head++);
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001251 glScissor(r2.left, mHeight - r2.bottom, r2.width(), r2.height());
Mathias Agopian9f3020d2009-11-06 16:30:18 -08001252 glClear(GL_COLOR_BUFFER_BIT);
1253 }
1254 glDisable(GL_SCISSOR_TEST);
1255 }
Geoffrey Pitschdd214a72016-06-27 17:14:30 -04001256 // specify the y center as ceiling((mHeight - frame.trimHeight) / 2)
1257 // which is equivalent to mHeight - (yc + frame.trimHeight)
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001258 const int frameDrawY = mHeight - (yc + frame.trimHeight);
1259 glDrawTexiOES(xc, frameDrawY, 0, frame.trimWidth, frame.trimHeight);
1260
1261 // if the part hasn't been stopped yet then continue fading if necessary
1262 if (exitPending() && part.hasFadingPhase()) {
1263 fadeFrame(xc, frameDrawY, frame.trimWidth, frame.trimHeight, part,
1264 ++fadedFramesCount);
1265 if (fadedFramesCount >= part.framesToFadeCount) {
1266 fadedFramesCount = MAX_FADED_FRAMES_COUNT; // no more fading
1267 }
1268 }
1269
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001270 if (mClockEnabled && mTimeIsAccurate && validClock(part)) {
1271 drawClock(animation.clockFont, part.clockPosX, part.clockPosY);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -08001272 }
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001273
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001274 handleViewport(frameDuration);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -08001275
Mathias Agopiana8826d62009-10-01 03:10:14 -07001276 eglSwapBuffers(mDisplay, mSurface);
1277
1278 nsecs_t now = systemTime();
1279 nsecs_t delay = frameDuration - (now - lastFrame);
Wei Wang159a4102018-10-23 23:15:58 -07001280 //SLOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay));
Mathias Agopiana8826d62009-10-01 03:10:14 -07001281 lastFrame = now;
Mathias Agopiandb7dd2a2012-05-12 15:08:21 -07001282
1283 if (delay > 0) {
1284 struct timespec spec;
1285 spec.tv_sec = (now + delay) / 1000000000;
1286 spec.tv_nsec = (now + delay) % 1000000000;
1287 int err;
1288 do {
Yi Kong911ac232019-03-24 01:49:02 -07001289 err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, nullptr);
Mathias Agopiandb7dd2a2012-05-12 15:08:21 -07001290 } while (err<0 && errno == EINTR);
1291 }
Kevin Hesterd3782b22012-04-26 10:38:55 -07001292
1293 checkExit();
Mathias Agopiana8826d62009-10-01 03:10:14 -07001294 }
Kevin Hesterd3782b22012-04-26 10:38:55 -07001295
Mathias Agopiana8826d62009-10-01 03:10:14 -07001296 usleep(part.pause * ns2us(frameDuration));
Kevin Hesterd3782b22012-04-26 10:38:55 -07001297
Yegor Malyshev6925e1b2020-09-10 16:42:20 +02001298 if (exitPending() && !part.count && mCurrentInset >= mTargetInset &&
1299 !part.hasFadingPhase()) {
1300 break; // exit the infinite non-fading part when it has been played at least once
1301 }
Mathias Agopiana8826d62009-10-01 03:10:14 -07001302 }
Geoffrey Pitsch2fb30fb2016-07-06 16:16:20 -04001303 }
1304
1305 // Free textures created for looping parts now that the animation is done.
1306 for (const Animation::Part& part : animation.parts) {
Mathias Agopiana8826d62009-10-01 03:10:14 -07001307 if (part.count != 1) {
Geoffrey Pitsch2fb30fb2016-07-06 16:16:20 -04001308 const size_t fcount = part.frames.size();
1309 for (size_t j = 0; j < fcount; j++) {
Mathias Agopiana8826d62009-10-01 03:10:14 -07001310 const Animation::Frame& frame(part.frames[j]);
1311 glDeleteTextures(1, &frame.tid);
1312 }
1313 }
1314 }
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -07001315
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001316 return true;
Mathias Agopiana8826d62009-10-01 03:10:14 -07001317}
1318
Marin Shalamanov9070c052020-05-18 19:05:17 +02001319void BootAnimation::processDisplayEvents() {
1320 // This will poll mDisplayEventReceiver and if there are new events it'll call
1321 // displayEventCallback synchronously.
1322 mLooper->pollOnce(0);
1323}
1324
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001325void BootAnimation::handleViewport(nsecs_t timestep) {
1326 if (mShuttingDown || !mFlingerSurfaceControl || mTargetInset == 0) {
1327 return;
1328 }
1329 if (mTargetInset < 0) {
1330 // Poll the amount for the top display inset. This will return -1 until persistent properties
1331 // have been loaded.
1332 mTargetInset = android::base::GetIntProperty("persist.sys.displayinset.top",
1333 -1 /* default */, -1 /* min */, mHeight / 2 /* max */);
1334 }
1335 if (mTargetInset <= 0) {
1336 return;
1337 }
1338
1339 if (mCurrentInset < mTargetInset) {
1340 // After the device boots, the inset will effectively be cropped away. We animate this here.
1341 float fraction = static_cast<float>(mCurrentInset) / mTargetInset;
1342 int interpolatedInset = (cosf((fraction + 1) * M_PI) / 2.0f + 0.5f) * mTargetInset;
1343
1344 SurfaceComposerClient::Transaction()
1345 .setCrop(mFlingerSurfaceControl, Rect(0, interpolatedInset, mWidth, mHeight))
1346 .apply();
1347 } else {
1348 // At the end of the animation, we switch to the viewport that DisplayManager will apply
1349 // later. This changes the coordinate system, and means we must move the surface up by
1350 // the inset amount.
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001351 Rect layerStackRect(0, 0, mWidth, mHeight - mTargetInset);
1352 Rect displayRect(0, mTargetInset, mWidth, mHeight);
1353
1354 SurfaceComposerClient::Transaction t;
1355 t.setPosition(mFlingerSurfaceControl, 0, -mTargetInset)
1356 .setCrop(mFlingerSurfaceControl, Rect(0, mTargetInset, mWidth, mHeight));
Dominik Laskowski2a3d9aa2019-11-18 20:26:39 -08001357 t.setDisplayProjection(mDisplayToken, ui::ROTATION_0, layerStackRect, displayRect);
Adrian Roos9ee5dff2018-08-22 20:19:49 +02001358 t.apply();
1359
1360 mTargetInset = mCurrentInset = 0;
1361 }
1362
1363 int delta = timestep * mTargetInset / ms2ns(200);
1364 mCurrentInset += delta;
1365}
1366
Marin Shalamanov9070c052020-05-18 19:05:17 +02001367void BootAnimation::releaseAnimation(Animation* animation) const {
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001368 for (Vector<Animation::Part>::iterator it = animation->parts.begin(),
1369 e = animation->parts.end(); it != e; ++it) {
1370 if (it->animation)
1371 releaseAnimation(it->animation);
1372 }
1373 if (animation->zip)
1374 delete animation->zip;
1375 delete animation;
1376}
1377
Marin Shalamanov9070c052020-05-18 19:05:17 +02001378BootAnimation::Animation* BootAnimation::loadAnimation(const String8& fn) {
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001379 if (mLoadedFiles.indexOf(fn) >= 0) {
Wei Wang159a4102018-10-23 23:15:58 -07001380 SLOGE("File \"%s\" is already loaded. Cyclic ref is not allowed",
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001381 fn.string());
Yi Kong911ac232019-03-24 01:49:02 -07001382 return nullptr;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001383 }
1384 ZipFileRO *zip = ZipFileRO::open(fn);
Yi Kong911ac232019-03-24 01:49:02 -07001385 if (zip == nullptr) {
Wei Wang159a4102018-10-23 23:15:58 -07001386 SLOGE("Failed to open animation zip \"%s\": %s",
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001387 fn.string(), strerror(errno));
Yi Kong911ac232019-03-24 01:49:02 -07001388 return nullptr;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001389 }
1390
1391 Animation *animation = new Animation;
1392 animation->fileName = fn;
1393 animation->zip = zip;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001394 animation->clockFont.map = nullptr;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001395 mLoadedFiles.add(animation->fileName);
1396
1397 parseAnimationDesc(*animation);
Geoffrey Pitscha91a2d72016-07-12 14:46:19 -04001398 if (!preloadZip(*animation)) {
Greg Kaiser7426ec82019-09-11 14:34:27 -07001399 releaseAnimation(animation);
Yi Kong911ac232019-03-24 01:49:02 -07001400 return nullptr;
Geoffrey Pitscha91a2d72016-07-12 14:46:19 -04001401 }
1402
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001403 mLoadedFiles.remove(fn);
1404 return animation;
1405}
Damien Bargiacchi97480862016-03-29 14:55:55 -07001406
1407bool BootAnimation::updateIsTimeAccurate() {
1408 static constexpr long long MAX_TIME_IN_PAST = 60000LL * 60LL * 24LL * 30LL; // 30 days
1409 static constexpr long long MAX_TIME_IN_FUTURE = 60000LL * 90LL; // 90 minutes
1410
1411 if (mTimeIsAccurate) {
1412 return true;
1413 }
Keun-young Parkb5938422017-03-23 13:46:24 -07001414 if (mShuttingDown) return true;
Damien Bargiacchi97480862016-03-29 14:55:55 -07001415 struct stat statResult;
Damien Bargiacchi9071db12016-10-28 17:38:22 -07001416
1417 if(stat(TIME_FORMAT_12_HOUR_FLAG_FILE_PATH, &statResult) == 0) {
1418 mTimeFormat12Hour = true;
1419 }
1420
Damien Bargiacchi97480862016-03-29 14:55:55 -07001421 if(stat(ACCURATE_TIME_FLAG_FILE_PATH, &statResult) == 0) {
1422 mTimeIsAccurate = true;
1423 return true;
1424 }
1425
1426 FILE* file = fopen(LAST_TIME_CHANGED_FILE_PATH, "r");
Yi Kong911ac232019-03-24 01:49:02 -07001427 if (file != nullptr) {
Damien Bargiacchi97480862016-03-29 14:55:55 -07001428 long long lastChangedTime = 0;
1429 fscanf(file, "%lld", &lastChangedTime);
1430 fclose(file);
1431 if (lastChangedTime > 0) {
1432 struct timespec now;
1433 clock_gettime(CLOCK_REALTIME, &now);
1434 // Match the Java timestamp format
1435 long long rtcNow = (now.tv_sec * 1000LL) + (now.tv_nsec / 1000000LL);
Damien Bargiacchi96762812016-07-12 15:53:40 -07001436 if (ACCURATE_TIME_EPOCH < rtcNow
1437 && lastChangedTime > (rtcNow - MAX_TIME_IN_PAST)
1438 && lastChangedTime < (rtcNow + MAX_TIME_IN_FUTURE)) {
Damien Bargiacchi97480862016-03-29 14:55:55 -07001439 mTimeIsAccurate = true;
1440 }
1441 }
1442 }
1443
1444 return mTimeIsAccurate;
1445}
1446
1447BootAnimation::TimeCheckThread::TimeCheckThread(BootAnimation* bootAnimation) : Thread(false),
1448 mInotifyFd(-1), mSystemWd(-1), mTimeWd(-1), mBootAnimation(bootAnimation) {}
1449
1450BootAnimation::TimeCheckThread::~TimeCheckThread() {
1451 // mInotifyFd may be -1 but that's ok since we're not at risk of attempting to close a valid FD.
1452 close(mInotifyFd);
1453}
1454
1455bool BootAnimation::TimeCheckThread::threadLoop() {
1456 bool shouldLoop = doThreadLoop() && !mBootAnimation->mTimeIsAccurate
1457 && mBootAnimation->mClockEnabled;
1458 if (!shouldLoop) {
1459 close(mInotifyFd);
1460 mInotifyFd = -1;
1461 }
1462 return shouldLoop;
1463}
1464
1465bool BootAnimation::TimeCheckThread::doThreadLoop() {
1466 static constexpr int BUFF_LEN (10 * (sizeof(struct inotify_event) + NAME_MAX + 1));
1467
1468 // Poll instead of doing a blocking read so the Thread can exit if requested.
1469 struct pollfd pfd = { mInotifyFd, POLLIN, 0 };
1470 ssize_t pollResult = poll(&pfd, 1, 1000);
1471
1472 if (pollResult == 0) {
1473 return true;
1474 } else if (pollResult < 0) {
Wei Wang159a4102018-10-23 23:15:58 -07001475 SLOGE("Could not poll inotify events");
Damien Bargiacchi97480862016-03-29 14:55:55 -07001476 return false;
1477 }
1478
1479 char buff[BUFF_LEN] __attribute__ ((aligned(__alignof__(struct inotify_event))));;
1480 ssize_t length = read(mInotifyFd, buff, BUFF_LEN);
1481 if (length == 0) {
1482 return true;
1483 } else if (length < 0) {
Wei Wang159a4102018-10-23 23:15:58 -07001484 SLOGE("Could not read inotify events");
Damien Bargiacchi97480862016-03-29 14:55:55 -07001485 return false;
1486 }
1487
1488 const struct inotify_event *event;
1489 for (char* ptr = buff; ptr < buff + length; ptr += sizeof(struct inotify_event) + event->len) {
1490 event = (const struct inotify_event *) ptr;
1491 if (event->wd == mSystemWd && strcmp(SYSTEM_TIME_DIR_NAME, event->name) == 0) {
1492 addTimeDirWatch();
1493 } else if (event->wd == mTimeWd && (strcmp(LAST_TIME_CHANGED_FILE_NAME, event->name) == 0
1494 || strcmp(ACCURATE_TIME_FLAG_FILE_NAME, event->name) == 0)) {
1495 return !mBootAnimation->updateIsTimeAccurate();
1496 }
1497 }
1498
1499 return true;
1500}
1501
1502void BootAnimation::TimeCheckThread::addTimeDirWatch() {
1503 mTimeWd = inotify_add_watch(mInotifyFd, SYSTEM_TIME_DIR_PATH,
1504 IN_CLOSE_WRITE | IN_MOVED_TO | IN_ATTRIB);
1505 if (mTimeWd > 0) {
1506 // No need to watch for the time directory to be created if it already exists
1507 inotify_rm_watch(mInotifyFd, mSystemWd);
1508 mSystemWd = -1;
1509 }
1510}
1511
1512status_t BootAnimation::TimeCheckThread::readyToRun() {
1513 mInotifyFd = inotify_init();
1514 if (mInotifyFd < 0) {
Wei Wang159a4102018-10-23 23:15:58 -07001515 SLOGE("Could not initialize inotify fd");
Damien Bargiacchi97480862016-03-29 14:55:55 -07001516 return NO_INIT;
1517 }
1518
1519 mSystemWd = inotify_add_watch(mInotifyFd, SYSTEM_DATA_DIR_PATH, IN_CREATE | IN_ATTRIB);
1520 if (mSystemWd < 0) {
1521 close(mInotifyFd);
1522 mInotifyFd = -1;
Dan Sandler562d46d2020-05-11 17:09:22 -04001523 SLOGE("Could not add watch for %s: %s", SYSTEM_DATA_DIR_PATH, strerror(errno));
Damien Bargiacchi97480862016-03-29 14:55:55 -07001524 return NO_INIT;
1525 }
1526
1527 addTimeDirWatch();
1528
1529 if (mBootAnimation->updateIsTimeAccurate()) {
1530 close(mInotifyFd);
1531 mInotifyFd = -1;
1532 return ALREADY_EXISTS;
1533 }
1534
1535 return NO_ERROR;
1536}
1537
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001538// ---------------------------------------------------------------------------
1539
Marin Shalamanov9070c052020-05-18 19:05:17 +02001540} // namespace android