blob: 95bdc4a79af98031984eeb7d55b89c58332e7739 [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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020#include <stdint.h>
Wei Wanga90c54c2017-02-02 11:35:21 -080021#include <inttypes.h>
Damien Bargiacchi97480862016-03-29 14:55:55 -070022#include <sys/inotify.h>
23#include <sys/poll.h>
24#include <sys/stat.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025#include <sys/types.h>
26#include <math.h>
27#include <fcntl.h>
28#include <utils/misc.h>
Mathias Agopianb4d5a722009-09-23 17:05:19 -070029#include <signal.h>
Elliott Hughesbb94f312014-10-21 10:41:33 -070030#include <time.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031
Steven Morelandfb7952f2018-02-23 14:58:50 -080032#include <cutils/atomic.h>
Jason parksbd9a08d2011-01-31 15:04:34 -060033#include <cutils/properties.h>
34
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080035#include <androidfw/AssetManager.h>
Mathias Agopianac31a3b2009-05-21 19:59:24 -070036#include <binder/IPCThreadState.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037#include <utils/Errors.h>
38#include <utils/Log.h>
Wei Wanga90c54c2017-02-02 11:35:21 -080039#include <utils/SystemClock.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
Keun-young Parkb5938422017-03-23 13:46:24 -070041#include <android-base/properties.h>
42
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043#include <ui/PixelFormat.h>
44#include <ui/Rect.h>
45#include <ui/Region.h>
46#include <ui/DisplayInfo.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047
Jeff Brown0b722fe2012-08-24 22:40:14 -070048#include <gui/ISurfaceComposer.h>
Mathias Agopian8335f1c2012-02-25 18:48:35 -080049#include <gui/Surface.h>
50#include <gui/SurfaceComposerClient.h>
Mathias Agopian000479f2010-02-09 17:46:37 -080051
Andreas Gampecfedceb2014-09-30 21:48:18 -070052// TODO: Fix Skia.
53#pragma GCC diagnostic push
54#pragma GCC diagnostic ignored "-Wunused-parameter"
Derek Sollenbergereece0dd2014-02-27 14:31:29 -050055#include <SkBitmap.h>
Matt Sarett8898c162016-03-24 16:11:01 -040056#include <SkImage.h>
Derek Sollenbergereece0dd2014-02-27 14:31:29 -050057#include <SkStream.h>
Andreas Gampecfedceb2014-09-30 21:48:18 -070058#pragma GCC diagnostic pop
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059
60#include <GLES/gl.h>
61#include <GLES/glext.h>
62#include <EGL/eglext.h>
63
64#include "BootAnimation.h"
65
Kyeongkab.Nam35a8a112019-07-17 16:41:48 +090066#define ANIM_PATH_MAX 255
67#define STR(x) #x
68#define STRTO(x) STR(x)
69
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070namespace android {
71
Damien Bargiacchi97480862016-03-29 14:55:55 -070072static const char OEM_BOOTANIMATION_FILE[] = "/oem/media/bootanimation.zip";
Jaekyun Seokc521bb32018-01-30 11:52:47 +090073static const char PRODUCT_BOOTANIMATION_FILE[] = "/product/media/bootanimation.zip";
Damien Bargiacchi97480862016-03-29 14:55:55 -070074static const char SYSTEM_BOOTANIMATION_FILE[] = "/system/media/bootanimation.zip";
Jaekyun Seokc521bb32018-01-30 11:52:47 +090075static const char PRODUCT_ENCRYPTED_BOOTANIMATION_FILE[] = "/product/media/bootanimation-encrypted.zip";
Damien Bargiacchi97480862016-03-29 14:55:55 -070076static const char SYSTEM_ENCRYPTED_BOOTANIMATION_FILE[] = "/system/media/bootanimation-encrypted.zip";
Keun-young Parkb5938422017-03-23 13:46:24 -070077static const char OEM_SHUTDOWNANIMATION_FILE[] = "/oem/media/shutdownanimation.zip";
Jaekyun Seokc521bb32018-01-30 11:52:47 +090078static const char PRODUCT_SHUTDOWNANIMATION_FILE[] = "/product/media/shutdownanimation.zip";
Keun-young Parkb5938422017-03-23 13:46:24 -070079static const char SYSTEM_SHUTDOWNANIMATION_FILE[] = "/system/media/shutdownanimation.zip";
80
Damien Bargiacchi97480862016-03-29 14:55:55 -070081static const char SYSTEM_DATA_DIR_PATH[] = "/data/system";
82static const char SYSTEM_TIME_DIR_NAME[] = "time";
83static const char SYSTEM_TIME_DIR_PATH[] = "/data/system/time";
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070084static const char CLOCK_FONT_ASSET[] = "images/clock_font.png";
85static const char CLOCK_FONT_ZIP_NAME[] = "clock_font.png";
Damien Bargiacchi97480862016-03-29 14:55:55 -070086static const char LAST_TIME_CHANGED_FILE_NAME[] = "last_time_change";
87static const char LAST_TIME_CHANGED_FILE_PATH[] = "/data/system/time/last_time_change";
88static const char ACCURATE_TIME_FLAG_FILE_NAME[] = "time_is_accurate";
89static const char ACCURATE_TIME_FLAG_FILE_PATH[] = "/data/system/time/time_is_accurate";
Damien Bargiacchi9071db12016-10-28 17:38:22 -070090static const char TIME_FORMAT_12_HOUR_FLAG_FILE_PATH[] = "/data/system/time/time_format_12_hour";
Damien Bargiacchi96762812016-07-12 15:53:40 -070091// Java timestamp format. Don't show the clock if the date is before 2000-01-01 00:00:00.
92static const long long ACCURATE_TIME_EPOCH = 946684800000;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070093static constexpr char FONT_BEGIN_CHAR = ' ';
94static constexpr char FONT_END_CHAR = '~' + 1;
95static constexpr size_t FONT_NUM_CHARS = FONT_END_CHAR - FONT_BEGIN_CHAR + 1;
96static constexpr size_t FONT_NUM_COLS = 16;
97static constexpr size_t FONT_NUM_ROWS = FONT_NUM_CHARS / FONT_NUM_COLS;
98static const int TEXT_CENTER_VALUE = INT_MAX;
99static const int TEXT_MISSING_VALUE = INT_MIN;
Damien Bargiacchi97480862016-03-29 14:55:55 -0700100static const char EXIT_PROP_NAME[] = "service.bootanim.exit";
Kyeongkab.Nam35a8a112019-07-17 16:41:48 +0900101static const int ANIM_ENTRY_NAME_MAX = ANIM_PATH_MAX + 1;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700102static constexpr size_t TEXT_POS_LEN_MAX = 16;
Narayan Kamathafd31e02013-12-03 13:16:03 +0000103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104// ---------------------------------------------------------------------------
105
Ed Coyne7464ac92017-06-08 12:26:48 -0700106BootAnimation::BootAnimation(sp<Callbacks> callbacks)
Ed Coyne2c9e94a2017-05-31 10:08:28 -0700107 : Thread(false), mClockEnabled(true), mTimeIsAccurate(false),
Ed Coyne7464ac92017-06-08 12:26:48 -0700108 mTimeFormat12Hour(false), mTimeCheckThread(NULL), mCallbacks(callbacks) {
Mathias Agopian627e7b52009-05-21 19:21:59 -0700109 mSession = new SurfaceComposerClient();
Geoffrey Pitsch290c4352016-08-09 14:35:10 -0400110
Keun-young Parkb5938422017-03-23 13:46:24 -0700111 std::string powerCtl = android::base::GetProperty("sys.powerctl", "");
112 if (powerCtl.empty()) {
113 mShuttingDown = false;
114 } else {
115 mShuttingDown = true;
116 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117}
118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119void BootAnimation::onFirstRef() {
Mathias Agopianbc726112009-09-23 15:44:05 -0700120 status_t err = mSession->linkToComposerDeath(this);
Steve Block3762c312012-01-06 19:20:56 +0000121 ALOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err));
Mathias Agopian8434c532009-09-23 18:52:49 -0700122 if (err == NO_ERROR) {
Mathias Agopianbc726112009-09-23 15:44:05 -0700123 run("BootAnimation", PRIORITY_DISPLAY);
124 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125}
126
Mathias Agopianbc726112009-09-23 15:44:05 -0700127sp<SurfaceComposerClient> BootAnimation::session() const {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 return mSession;
129}
130
Mathias Agopianbc726112009-09-23 15:44:05 -0700131
Narayan Kamathafd31e02013-12-03 13:16:03 +0000132void BootAnimation::binderDied(const wp<IBinder>&)
Mathias Agopianbc726112009-09-23 15:44:05 -0700133{
134 // woah, surfaceflinger died!
Steve Block5baa3a62011-12-20 16:23:08 +0000135 ALOGD("SurfaceFlinger died, exiting...");
Mathias Agopianbc726112009-09-23 15:44:05 -0700136
137 // calling requestExit() is not enough here because the Surface code
138 // might be blocked on a condition variable that will never be updated.
139 kill( getpid(), SIGKILL );
140 requestExit();
141}
142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets,
144 const char* name) {
145 Asset* asset = assets.open(name, Asset::ACCESS_BUFFER);
Andreas Gampecfedceb2014-09-30 21:48:18 -0700146 if (asset == NULL)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800147 return NO_INIT;
148 SkBitmap bitmap;
Matt Sarett8898c162016-03-24 16:11:01 -0400149 sk_sp<SkData> data = SkData::MakeWithoutCopy(asset->getBuffer(false),
150 asset->getLength());
151 sk_sp<SkImage> image = SkImage::MakeFromEncoded(data);
152 image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800153 asset->close();
154 delete asset;
155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 const int w = bitmap.width();
157 const int h = bitmap.height();
158 const void* p = bitmap.getPixels();
159
160 GLint crop[4] = { 0, h, w, -h };
161 texture->w = w;
162 texture->h = h;
163
164 glGenTextures(1, &texture->name);
165 glBindTexture(GL_TEXTURE_2D, texture->name);
166
Mike Reed42a1d082014-07-07 18:06:18 -0400167 switch (bitmap.colorType()) {
168 case kAlpha_8_SkColorType:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA,
170 GL_UNSIGNED_BYTE, p);
171 break;
Mike Reed42a1d082014-07-07 18:06:18 -0400172 case kARGB_4444_SkColorType:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
174 GL_UNSIGNED_SHORT_4_4_4_4, p);
175 break;
Mike Reed42a1d082014-07-07 18:06:18 -0400176 case kN32_SkColorType:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
178 GL_UNSIGNED_BYTE, p);
179 break;
Mike Reed42a1d082014-07-07 18:06:18 -0400180 case kRGB_565_SkColorType:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB,
182 GL_UNSIGNED_SHORT_5_6_5, p);
183 break;
184 default:
185 break;
186 }
187
188 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
189 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
190 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
191 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
192 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 return NO_ERROR;
195}
196
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700197status_t BootAnimation::initTexture(FileMap* map, int* width, int* height)
Mathias Agopiana8826d62009-10-01 03:10:14 -0700198{
Mathias Agopiana8826d62009-10-01 03:10:14 -0700199 SkBitmap bitmap;
Damien Bargiacchif67b3172016-09-07 20:17:14 -0700200 sk_sp<SkData> data = SkData::MakeWithoutCopy(map->getDataPtr(),
201 map->getDataLength());
Matt Sarett8898c162016-03-24 16:11:01 -0400202 sk_sp<SkImage> image = SkImage::MakeFromEncoded(data);
203 image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700204
Mykola Kondratenko0c1eeb32014-04-15 09:35:44 +0200205 // FileMap memory is never released until application exit.
206 // Release it now as the texture is already loaded and the memory used for
207 // the packed resource can be released.
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700208 delete map;
Mykola Kondratenko0c1eeb32014-04-15 09:35:44 +0200209
Mathias Agopiana8826d62009-10-01 03:10:14 -0700210 const int w = bitmap.width();
211 const int h = bitmap.height();
212 const void* p = bitmap.getPixels();
213
214 GLint crop[4] = { 0, h, w, -h };
215 int tw = 1 << (31 - __builtin_clz(w));
216 int th = 1 << (31 - __builtin_clz(h));
217 if (tw < w) tw <<= 1;
218 if (th < h) th <<= 1;
219
Mike Reed42a1d082014-07-07 18:06:18 -0400220 switch (bitmap.colorType()) {
221 case kN32_SkColorType:
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530222 if (!mUseNpotTextures && (tw != w || th != h)) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700223 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA,
224 GL_UNSIGNED_BYTE, 0);
225 glTexSubImage2D(GL_TEXTURE_2D, 0,
226 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p);
227 } else {
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530228 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
Mathias Agopiana8826d62009-10-01 03:10:14 -0700229 GL_UNSIGNED_BYTE, p);
230 }
231 break;
232
Mike Reed42a1d082014-07-07 18:06:18 -0400233 case kRGB_565_SkColorType:
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530234 if (!mUseNpotTextures && (tw != w || th != h)) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700235 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB,
236 GL_UNSIGNED_SHORT_5_6_5, 0);
237 glTexSubImage2D(GL_TEXTURE_2D, 0,
238 0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p);
239 } else {
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530240 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB,
Mathias Agopiana8826d62009-10-01 03:10:14 -0700241 GL_UNSIGNED_SHORT_5_6_5, p);
242 }
243 break;
244 default:
245 break;
246 }
247
248 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
249
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700250 *width = w;
251 *height = h;
252
Mathias Agopiana8826d62009-10-01 03:10:14 -0700253 return NO_ERROR;
254}
255
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256status_t BootAnimation::readyToRun() {
257 mAssets.addDefaultAssets();
258
Jeff Brown0b722fe2012-08-24 22:40:14 -0700259 sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
260 ISurfaceComposer::eDisplayIdMain));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261 DisplayInfo dinfo;
Jeff Brown0b722fe2012-08-24 22:40:14 -0700262 status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 if (status)
264 return -1;
265
266 // create the native surface
Jeff Brown0b722fe2012-08-24 22:40:14 -0700267 sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
268 dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565);
Mathias Agopian439863f2011-06-28 19:09:31 -0700269
Robert Carre13b58e2017-08-31 14:50:44 -0700270 SurfaceComposerClient::Transaction t;
271 t.setLayer(control, 0x40000000)
272 .apply();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273
Mathias Agopian17f638b2009-04-16 20:04:08 -0700274 sp<Surface> s = control->getSurface();
275
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 // initialize opengl and egl
Mathias Agopian738b9a42009-08-06 16:41:02 -0700277 const EGLint attribs[] = {
Mathias Agopian1b253b72011-08-15 15:20:22 -0700278 EGL_RED_SIZE, 8,
279 EGL_GREEN_SIZE, 8,
280 EGL_BLUE_SIZE, 8,
Mathias Agopiana8826d62009-10-01 03:10:14 -0700281 EGL_DEPTH_SIZE, 0,
282 EGL_NONE
Mathias Agopian738b9a42009-08-06 16:41:02 -0700283 };
Andreas Gampecfedceb2014-09-30 21:48:18 -0700284 EGLint w, h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 EGLint numConfigs;
286 EGLConfig config;
287 EGLSurface surface;
288 EGLContext context;
Mathias Agopian627e7b52009-05-21 19:21:59 -0700289
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
Mathias Agopian627e7b52009-05-21 19:21:59 -0700291
292 eglInitialize(display, 0, 0);
Mathias Agopian1b253b72011-08-15 15:20:22 -0700293 eglChooseConfig(display, attribs, &config, 1, &numConfigs);
Mathias Agopian1473f462009-04-10 14:24:30 -0700294 surface = eglCreateWindowSurface(display, config, s.get(), NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 context = eglCreateContext(display, config, NULL, NULL);
296 eglQuerySurface(display, surface, EGL_WIDTH, &w);
297 eglQuerySurface(display, surface, EGL_HEIGHT, &h);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700298
Mathias Agopianabac0102009-07-31 14:47:00 -0700299 if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE)
300 return NO_INIT;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700301
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800302 mDisplay = display;
303 mContext = context;
304 mSurface = surface;
305 mWidth = w;
306 mHeight = h;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700307 mFlingerSurfaceControl = control;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800308 mFlingerSurface = s;
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200309 mTargetInset = -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310
Elliott Hughesc367d482013-10-29 13:12:55 -0700311 // If the device has encryption turned on or is in process
Jason parksbd9a08d2011-01-31 15:04:34 -0600312 // of being encrypted we show the encrypted boot animation.
313 char decrypt[PROPERTY_VALUE_MAX];
314 property_get("vold.decrypt", decrypt, "");
315
Keun-young Parkb5938422017-03-23 13:46:24 -0700316 bool encryptedAnimation = atoi(decrypt) != 0 ||
317 !strcmp("trigger_restart_min_framework", decrypt);
Jason parksbd9a08d2011-01-31 15:04:34 -0600318
Jaekyun Seokc521bb32018-01-30 11:52:47 +0900319 if (!mShuttingDown && encryptedAnimation) {
320 static const char* encryptedBootFiles[] =
321 {PRODUCT_ENCRYPTED_BOOTANIMATION_FILE, SYSTEM_ENCRYPTED_BOOTANIMATION_FILE};
322 for (const char* f : encryptedBootFiles) {
323 if (access(f, R_OK) == 0) {
324 mZipFileName = f;
325 return NO_ERROR;
326 }
327 }
Jason parksbd9a08d2011-01-31 15:04:34 -0600328 }
Jaekyun Seokc521bb32018-01-30 11:52:47 +0900329 static const char* bootFiles[] =
330 {PRODUCT_BOOTANIMATION_FILE, OEM_BOOTANIMATION_FILE, SYSTEM_BOOTANIMATION_FILE};
Keun-young Parkb5938422017-03-23 13:46:24 -0700331 static const char* shutdownFiles[] =
Jaekyun Seokc521bb32018-01-30 11:52:47 +0900332 {PRODUCT_SHUTDOWNANIMATION_FILE, OEM_SHUTDOWNANIMATION_FILE, SYSTEM_SHUTDOWNANIMATION_FILE};
Keun-young Parkb5938422017-03-23 13:46:24 -0700333
334 for (const char* f : (!mShuttingDown ? bootFiles : shutdownFiles)) {
335 if (access(f, R_OK) == 0) {
336 mZipFileName = f;
337 return NO_ERROR;
338 }
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700339 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 return NO_ERROR;
341}
342
Mathias Agopiana8826d62009-10-01 03:10:14 -0700343bool BootAnimation::threadLoop()
344{
345 bool r;
Narayan Kamathafd31e02013-12-03 13:16:03 +0000346 // We have no bootanimation file, so we use the stock android logo
347 // animation.
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700348 if (mZipFileName.isEmpty()) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700349 r = android();
350 } else {
351 r = movie();
352 }
353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800354 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
355 eglDestroyContext(mDisplay, mContext);
356 eglDestroySurface(mDisplay, mSurface);
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700357 mFlingerSurface.clear();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700358 mFlingerSurfaceControl.clear();
Mathias Agopian627e7b52009-05-21 19:21:59 -0700359 eglTerminate(mDisplay);
Sai Kiran Korwar3eee9fb2015-06-16 17:13:35 +0530360 eglReleaseThread();
Mathias Agopian627e7b52009-05-21 19:21:59 -0700361 IPCThreadState::self()->stopProcess();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362 return r;
363}
364
Mathias Agopiana8826d62009-10-01 03:10:14 -0700365bool BootAnimation::android()
366{
Keun-young Parkd1794cd2017-04-04 12:21:19 -0700367 ALOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
368 elapsedRealtime());
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700369 initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png");
370 initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371
Ed Coyne7464ac92017-06-08 12:26:48 -0700372 mCallbacks->init({});
373
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800374 // clear screen
Mathias Agopiana8826d62009-10-01 03:10:14 -0700375 glShadeModel(GL_FLAT);
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700376 glDisable(GL_DITHER);
377 glDisable(GL_SCISSOR_TEST);
Mathias Agopian59f19e42011-05-06 19:22:12 -0700378 glClearColor(0,0,0,1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 glClear(GL_COLOR_BUFFER_BIT);
380 eglSwapBuffers(mDisplay, mSurface);
381
Mathias Agopiana8826d62009-10-01 03:10:14 -0700382 glEnable(GL_TEXTURE_2D);
383 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
384
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700385 const GLint xc = (mWidth - mAndroid[0].w) / 2;
386 const GLint yc = (mHeight - mAndroid[0].h) / 2;
387 const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800389 glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(),
390 updateRect.height());
391
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700392 // Blend state
393 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
394 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 const nsecs_t startTime = systemTime();
397 do {
Mathias Agopian13796652009-03-24 22:49:21 -0700398 nsecs_t now = systemTime();
399 double time = now - startTime;
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700400 float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w;
401 GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w;
402 GLint x = xc - offset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800403
Mathias Agopian81668642009-07-28 11:41:30 -0700404 glDisable(GL_SCISSOR_TEST);
405 glClear(GL_COLOR_BUFFER_BIT);
406
407 glEnable(GL_SCISSOR_TEST);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408 glDisable(GL_BLEND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800409 glBindTexture(GL_TEXTURE_2D, mAndroid[1].name);
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700410 glDrawTexiOES(x, yc, 0, mAndroid[1].w, mAndroid[1].h);
411 glDrawTexiOES(x + mAndroid[1].w, yc, 0, mAndroid[1].w, mAndroid[1].h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700413 glEnable(GL_BLEND);
414 glBindTexture(GL_TEXTURE_2D, mAndroid[0].name);
415 glDrawTexiOES(xc, yc, 0, mAndroid[0].w, mAndroid[0].h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416
Mathias Agopian627e7b52009-05-21 19:21:59 -0700417 EGLBoolean res = eglSwapBuffers(mDisplay, mSurface);
418 if (res == EGL_FALSE)
419 break;
420
Mathias Agopian13796652009-03-24 22:49:21 -0700421 // 12fps: don't animate too fast to preserve CPU
422 const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now);
423 if (sleepTime > 0)
Mathias Agopiana8826d62009-10-01 03:10:14 -0700424 usleep(sleepTime);
Kevin Hesterd3782b22012-04-26 10:38:55 -0700425
426 checkExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 } while (!exitPending());
428
429 glDeleteTextures(1, &mAndroid[0].name);
430 glDeleteTextures(1, &mAndroid[1].name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431 return false;
432}
433
Kevin Hesterd3782b22012-04-26 10:38:55 -0700434void BootAnimation::checkExit() {
435 // Allow surface flinger to gracefully request shutdown
436 char value[PROPERTY_VALUE_MAX];
437 property_get(EXIT_PROP_NAME, value, "0");
438 int exitnow = atoi(value);
439 if (exitnow) {
440 requestExit();
Ed Coyne7464ac92017-06-08 12:26:48 -0700441 mCallbacks->shutdown();
Kevin Hesterd3782b22012-04-26 10:38:55 -0700442 }
443}
444
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700445bool BootAnimation::validClock(const Animation::Part& part) {
446 return part.clockPosX != TEXT_MISSING_VALUE && part.clockPosY != TEXT_MISSING_VALUE;
447}
448
449bool parseTextCoord(const char* str, int* dest) {
450 if (strcmp("c", str) == 0) {
451 *dest = TEXT_CENTER_VALUE;
452 return true;
453 }
454
455 char* end;
456 int val = (int) strtol(str, &end, 0);
457 if (end == str || *end != '\0' || val == INT_MAX || val == INT_MIN) {
458 return false;
459 }
460 *dest = val;
461 return true;
462}
463
464// Parse two position coordinates. If only string is non-empty, treat it as the y value.
465void parsePosition(const char* str1, const char* str2, int* x, int* y) {
466 bool success = false;
467 if (strlen(str1) == 0) { // No values were specified
468 // success = false
469 } else if (strlen(str2) == 0) { // we have only one value
470 if (parseTextCoord(str1, y)) {
471 *x = TEXT_CENTER_VALUE;
472 success = true;
473 }
474 } else {
475 if (parseTextCoord(str1, x) && parseTextCoord(str2, y)) {
476 success = true;
477 }
478 }
479
480 if (!success) {
481 *x = TEXT_MISSING_VALUE;
482 *y = TEXT_MISSING_VALUE;
483 }
484}
485
Jesse Hall083b84c2014-09-22 10:51:09 -0700486// Parse a color represented as an HTML-style 'RRGGBB' string: each pair of
487// characters in str is a hex number in [0, 255], which are converted to
488// floating point values in the range [0.0, 1.0] and placed in the
489// corresponding elements of color.
490//
491// If the input string isn't valid, parseColor returns false and color is
492// left unchanged.
493static bool parseColor(const char str[7], float color[3]) {
494 float tmpColor[3];
495 for (int i = 0; i < 3; i++) {
496 int val = 0;
497 for (int j = 0; j < 2; j++) {
498 val *= 16;
499 char c = str[2*i + j];
500 if (c >= '0' && c <= '9') val += c - '0';
501 else if (c >= 'A' && c <= 'F') val += (c - 'A') + 10;
502 else if (c >= 'a' && c <= 'f') val += (c - 'a') + 10;
503 else return false;
504 }
505 tmpColor[i] = static_cast<float>(val) / 255.0f;
506 }
507 memcpy(color, tmpColor, sizeof(tmpColor));
508 return true;
509}
510
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700511
512static bool readFile(ZipFileRO* zip, const char* name, String8& outString)
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700513{
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700514 ZipEntryRO entry = zip->findEntryByName(name);
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700515 ALOGE_IF(!entry, "couldn't find %s", name);
516 if (!entry) {
517 return false;
518 }
519
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700520 FileMap* entryMap = zip->createEntryFileMap(entry);
521 zip->releaseEntry(entry);
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700522 ALOGE_IF(!entryMap, "entryMap is null");
523 if (!entryMap) {
524 return false;
525 }
526
527 outString.setTo((char const*)entryMap->getDataPtr(), entryMap->getDataLength());
Narayan Kamath688ff4c2015-02-23 15:47:54 +0000528 delete entryMap;
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700529 return true;
530}
531
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700532// The font image should be a 96x2 array of character images. The
533// columns are the printable ASCII characters 0x20 - 0x7f. The
534// top row is regular text; the bottom row is bold.
535status_t BootAnimation::initFont(Font* font, const char* fallback) {
536 status_t status = NO_ERROR;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800537
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700538 if (font->map != nullptr) {
539 glGenTextures(1, &font->texture.name);
540 glBindTexture(GL_TEXTURE_2D, font->texture.name);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800541
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700542 status = initTexture(font->map, &font->texture.w, &font->texture.h);
543
544 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
545 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
546 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
547 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
548 } else if (fallback != nullptr) {
549 status = initTexture(&font->texture, mAssets, fallback);
550 } else {
551 return NO_INIT;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800552 }
553
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700554 if (status == NO_ERROR) {
555 font->char_width = font->texture.w / FONT_NUM_COLS;
556 font->char_height = font->texture.h / FONT_NUM_ROWS / 2; // There are bold and regular rows
557 }
558
559 return status;
560}
561
562void BootAnimation::drawText(const char* str, const Font& font, bool bold, int* x, int* y) {
563 glEnable(GL_BLEND); // Allow us to draw on top of the animation
564 glBindTexture(GL_TEXTURE_2D, font.texture.name);
565
566 const int len = strlen(str);
567 const int strWidth = font.char_width * len;
568
569 if (*x == TEXT_CENTER_VALUE) {
570 *x = (mWidth - strWidth) / 2;
571 } else if (*x < 0) {
572 *x = mWidth + *x - strWidth;
573 }
574 if (*y == TEXT_CENTER_VALUE) {
575 *y = (mHeight - font.char_height) / 2;
576 } else if (*y < 0) {
577 *y = mHeight + *y - font.char_height;
578 }
579
580 int cropRect[4] = { 0, 0, font.char_width, -font.char_height };
581
582 for (int i = 0; i < len; i++) {
583 char c = str[i];
584
585 if (c < FONT_BEGIN_CHAR || c > FONT_END_CHAR) {
586 c = '?';
587 }
588
589 // Crop the texture to only the pixels in the current glyph
590 const int charPos = (c - FONT_BEGIN_CHAR); // Position in the list of valid characters
591 const int row = charPos / FONT_NUM_COLS;
592 const int col = charPos % FONT_NUM_COLS;
593 cropRect[0] = col * font.char_width; // Left of column
594 cropRect[1] = row * font.char_height * 2; // Top of row
595 // Move down to bottom of regular (one char_heigh) or bold (two char_heigh) line
596 cropRect[1] += bold ? 2 * font.char_height : font.char_height;
597 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect);
598
599 glDrawTexiOES(*x, *y, 0, font.char_width, font.char_height);
600
601 *x += font.char_width;
602 }
603
604 glDisable(GL_BLEND); // Return to the animation's default behaviour
605 glBindTexture(GL_TEXTURE_2D, 0);
606}
607
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700608// We render 12 or 24 hour time.
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700609void BootAnimation::drawClock(const Font& font, const int xPos, const int yPos) {
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700610 static constexpr char TIME_FORMAT_12[] = "%l:%M";
611 static constexpr char TIME_FORMAT_24[] = "%H:%M";
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700612 static constexpr int TIME_LENGTH = 6;
613
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800614 time_t rawtime;
615 time(&rawtime);
616 struct tm* timeInfo = localtime(&rawtime);
617
618 char timeBuff[TIME_LENGTH];
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700619 const char* timeFormat = mTimeFormat12Hour ? TIME_FORMAT_12 : TIME_FORMAT_24;
620 size_t length = strftime(timeBuff, TIME_LENGTH, timeFormat, timeInfo);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800621
622 if (length != TIME_LENGTH - 1) {
623 ALOGE("Couldn't format time; abandoning boot animation clock");
624 mClockEnabled = false;
625 return;
626 }
627
Damien Bargiacchi45a76442016-12-05 18:02:18 -0800628 char* out = timeBuff[0] == ' ' ? &timeBuff[1] : &timeBuff[0];
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700629 int x = xPos;
630 int y = yPos;
Damien Bargiacchi45a76442016-12-05 18:02:18 -0800631 drawText(out, font, false, &x, &y);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800632}
633
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700634bool BootAnimation::parseAnimationDesc(Animation& animation)
Mathias Agopiana8826d62009-10-01 03:10:14 -0700635{
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700636 String8 desString;
637
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700638 if (!readFile(animation.zip, "desc.txt", desString)) {
Narayan Kamathafd31e02013-12-03 13:16:03 +0000639 return false;
640 }
Mathias Agopiana8826d62009-10-01 03:10:14 -0700641 char const* s = desString.string();
642
Mathias Agopiana8826d62009-10-01 03:10:14 -0700643 // Parse the description file
644 for (;;) {
645 const char* endl = strstr(s, "\n");
Andreas Gampecfedceb2014-09-30 21:48:18 -0700646 if (endl == NULL) break;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700647 String8 line(s, endl - s);
648 const char* l = line.string();
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800649 int fps = 0;
650 int width = 0;
651 int height = 0;
652 int count = 0;
653 int pause = 0;
Narayan Kamathafd31e02013-12-03 13:16:03 +0000654 char path[ANIM_ENTRY_NAME_MAX];
Jesse Hall083b84c2014-09-22 10:51:09 -0700655 char color[7] = "000000"; // default to black if unspecified
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700656 char clockPos1[TEXT_POS_LEN_MAX + 1] = "";
657 char clockPos2[TEXT_POS_LEN_MAX + 1] = "";
Jesse Hall083b84c2014-09-22 10:51:09 -0700658
Kevin Hesterd3782b22012-04-26 10:38:55 -0700659 char pathType;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700660 if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) {
Jesse Hall083b84c2014-09-22 10:51:09 -0700661 // ALOGD("> w=%d, h=%d, fps=%d", width, height, fps);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700662 animation.width = width;
663 animation.height = height;
664 animation.fps = fps;
Kyeongkab.Nam35a8a112019-07-17 16:41:48 +0900665 } else if (sscanf(l, " %c %d %d %" STRTO(ANIM_PATH_MAX) "s #%6s %16s %16s",
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700666 &pathType, &count, &pause, path, color, clockPos1, clockPos2) >= 4) {
667 //ALOGD("> type=%c, count=%d, pause=%d, path=%s, color=%s, clockPos1=%s, clockPos2=%s",
668 // pathType, count, pause, path, color, clockPos1, clockPos2);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700669 Animation::Part part;
Kevin Hesterd3782b22012-04-26 10:38:55 -0700670 part.playUntilComplete = pathType == 'c';
Mathias Agopiana8826d62009-10-01 03:10:14 -0700671 part.count = count;
672 part.pause = pause;
673 part.path = path;
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -0700674 part.audioData = NULL;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700675 part.animation = NULL;
Jesse Hall083b84c2014-09-22 10:51:09 -0700676 if (!parseColor(color, part.backgroundColor)) {
677 ALOGE("> invalid color '#%s'", color);
678 part.backgroundColor[0] = 0.0f;
679 part.backgroundColor[1] = 0.0f;
680 part.backgroundColor[2] = 0.0f;
681 }
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700682 parsePosition(clockPos1, clockPos2, &part.clockPosX, &part.clockPosY);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700683 animation.parts.add(part);
684 }
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700685 else if (strcmp(l, "$SYSTEM") == 0) {
686 // ALOGD("> SYSTEM");
687 Animation::Part part;
688 part.playUntilComplete = false;
689 part.count = 1;
690 part.pause = 0;
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -0700691 part.audioData = NULL;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700692 part.animation = loadAnimation(String8(SYSTEM_BOOTANIMATION_FILE));
693 if (part.animation != NULL)
694 animation.parts.add(part);
695 }
Mathias Agopiana8826d62009-10-01 03:10:14 -0700696 s = ++endl;
697 }
698
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700699 return true;
700}
701
702bool BootAnimation::preloadZip(Animation& animation)
703{
Mathias Agopiana8826d62009-10-01 03:10:14 -0700704 // read all the data structures
705 const size_t pcount = animation.parts.size();
Narayan Kamathafd31e02013-12-03 13:16:03 +0000706 void *cookie = NULL;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400707 ZipFileRO* zip = animation.zip;
708 if (!zip->startIteration(&cookie)) {
Narayan Kamathafd31e02013-12-03 13:16:03 +0000709 return false;
710 }
711
712 ZipEntryRO entry;
713 char name[ANIM_ENTRY_NAME_MAX];
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400714 while ((entry = zip->nextEntry(cookie)) != NULL) {
715 const int foundEntryName = zip->getEntryFileName(entry, name, ANIM_ENTRY_NAME_MAX);
Narayan Kamathafd31e02013-12-03 13:16:03 +0000716 if (foundEntryName > ANIM_ENTRY_NAME_MAX || foundEntryName == -1) {
717 ALOGE("Error fetching entry file name");
718 continue;
719 }
720
721 const String8 entryName(name);
722 const String8 path(entryName.getPathDir());
723 const String8 leaf(entryName.getPathLeaf());
724 if (leaf.size() > 0) {
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700725 if (entryName == CLOCK_FONT_ZIP_NAME) {
726 FileMap* map = zip->createEntryFileMap(entry);
727 if (map) {
728 animation.clockFont.map = map;
729 }
730 continue;
731 }
732
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400733 for (size_t j = 0; j < pcount; j++) {
Narayan Kamathafd31e02013-12-03 13:16:03 +0000734 if (path == animation.parts[j].path) {
Narayan Kamath4600dd02015-06-16 12:02:57 +0100735 uint16_t method;
Narayan Kamathafd31e02013-12-03 13:16:03 +0000736 // supports only stored png files
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400737 if (zip->getEntryInfo(entry, &method, NULL, NULL, NULL, NULL, NULL)) {
Narayan Kamathafd31e02013-12-03 13:16:03 +0000738 if (method == ZipFileRO::kCompressStored) {
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400739 FileMap* map = zip->createEntryFileMap(entry);
Narayan Kamathafd31e02013-12-03 13:16:03 +0000740 if (map) {
Narayan Kamathafd31e02013-12-03 13:16:03 +0000741 Animation::Part& part(animation.parts.editItemAt(j));
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700742 if (leaf == "audio.wav") {
743 // a part may have at most one audio file
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -0700744 part.audioData = (uint8_t *)map->getDataPtr();
745 part.audioLength = map->getDataLength();
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400746 } else if (leaf == "trim.txt") {
747 part.trimData.setTo((char const*)map->getDataPtr(),
748 map->getDataLength());
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700749 } else {
750 Animation::Frame frame;
751 frame.name = leaf;
752 frame.map = map;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400753 frame.trimWidth = animation.width;
754 frame.trimHeight = animation.height;
755 frame.trimX = 0;
756 frame.trimY = 0;
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700757 part.frames.add(frame);
758 }
Mathias Agopiana8826d62009-10-01 03:10:14 -0700759 }
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -0700760 } else {
761 ALOGE("bootanimation.zip is compressed; must be only stored");
Mathias Agopiana8826d62009-10-01 03:10:14 -0700762 }
763 }
764 }
765 }
766 }
767 }
768
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400769 // If there is trimData present, override the positioning defaults.
770 for (Animation::Part& part : animation.parts) {
771 const char* trimDataStr = part.trimData.string();
772 for (size_t frameIdx = 0; frameIdx < part.frames.size(); frameIdx++) {
773 const char* endl = strstr(trimDataStr, "\n");
774 // No more trimData for this part.
775 if (endl == NULL) {
776 break;
777 }
778 String8 line(trimDataStr, endl - trimDataStr);
779 const char* lineStr = line.string();
780 trimDataStr = ++endl;
781 int width = 0, height = 0, x = 0, y = 0;
782 if (sscanf(lineStr, "%dx%d+%d+%d", &width, &height, &x, &y) == 4) {
783 Animation::Frame& frame(part.frames.editItemAt(frameIdx));
784 frame.trimWidth = width;
785 frame.trimHeight = height;
786 frame.trimX = x;
787 frame.trimY = y;
788 } else {
789 ALOGE("Error parsing trim.txt, line: %s", lineStr);
790 break;
791 }
792 }
793 }
794
Ed Coyne7464ac92017-06-08 12:26:48 -0700795 mCallbacks->init(animation.parts);
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -0700796
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400797 zip->endIteration(cookie);
Narayan Kamathafd31e02013-12-03 13:16:03 +0000798
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700799 return true;
800}
801
802bool BootAnimation::movie()
803{
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700804 Animation* animation = loadAnimation(mZipFileName);
805 if (animation == NULL)
806 return false;
807
Damien Bargiacchi97480862016-03-29 14:55:55 -0700808 bool anyPartHasClock = false;
809 for (size_t i=0; i < animation->parts.size(); i++) {
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700810 if(validClock(animation->parts[i])) {
Damien Bargiacchi97480862016-03-29 14:55:55 -0700811 anyPartHasClock = true;
812 break;
813 }
814 }
815 if (!anyPartHasClock) {
816 mClockEnabled = false;
817 }
818
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530819 // Check if npot textures are supported
820 mUseNpotTextures = false;
821 String8 gl_extensions;
822 const char* exts = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
823 if (!exts) {
824 glGetError();
825 } else {
826 gl_extensions.setTo(exts);
827 if ((gl_extensions.find("GL_ARB_texture_non_power_of_two") != -1) ||
828 (gl_extensions.find("GL_OES_texture_npot") != -1)) {
829 mUseNpotTextures = true;
830 }
831 }
832
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800833 // Blend required to draw time on top of animation frames.
834 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700835 glShadeModel(GL_FLAT);
836 glDisable(GL_DITHER);
837 glDisable(GL_SCISSOR_TEST);
838 glDisable(GL_BLEND);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700839
840 glBindTexture(GL_TEXTURE_2D, 0);
841 glEnable(GL_TEXTURE_2D);
842 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
843 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
844 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
845 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
846 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
847
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700848 bool clockFontInitialized = false;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800849 if (mClockEnabled) {
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700850 clockFontInitialized =
851 (initFont(&animation->clockFont, CLOCK_FONT_ASSET) == NO_ERROR);
852 mClockEnabled = clockFontInitialized;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800853 }
854
Damien Bargiacchi97480862016-03-29 14:55:55 -0700855 if (mClockEnabled && !updateIsTimeAccurate()) {
856 mTimeCheckThread = new TimeCheckThread(this);
857 mTimeCheckThread->run("BootAnimation::TimeCheckThread", PRIORITY_NORMAL);
858 }
859
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700860 playAnimation(*animation);
Damien Bargiacchi97480862016-03-29 14:55:55 -0700861
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400862 if (mTimeCheckThread != nullptr) {
Damien Bargiacchi97480862016-03-29 14:55:55 -0700863 mTimeCheckThread->requestExit();
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400864 mTimeCheckThread = nullptr;
865 }
866
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700867 releaseAnimation(animation);
868
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700869 if (clockFontInitialized) {
870 glDeleteTextures(1, &animation->clockFont.texture.name);
Andriy Naborskyy815e51d2016-03-24 16:43:34 -0700871 }
872
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700873 return false;
874}
875
876bool BootAnimation::playAnimation(const Animation& animation)
877{
878 const size_t pcount = animation.parts.size();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700879 nsecs_t frameDuration = s2ns(1) / animation.fps;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400880 const int animationX = (mWidth - animation.width) / 2;
881 const int animationY = (mHeight - animation.height) / 2;
Mathias Agopian9f3020d2009-11-06 16:30:18 -0800882
Keun-young Parkd1794cd2017-04-04 12:21:19 -0700883 ALOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
884 elapsedRealtime());
Narayan Kamathafd31e02013-12-03 13:16:03 +0000885 for (size_t i=0 ; i<pcount ; i++) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700886 const Animation::Part& part(animation.parts[i]);
887 const size_t fcount = part.frames.size();
888 glBindTexture(GL_TEXTURE_2D, 0);
889
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700890 // Handle animation package
891 if (part.animation != NULL) {
892 playAnimation(*part.animation);
893 if (exitPending())
894 break;
895 continue; //to next part
896 }
897
Mathias Agopiana8826d62009-10-01 03:10:14 -0700898 for (int r=0 ; !part.count || r<part.count ; r++) {
Kevin Hesterd3782b22012-04-26 10:38:55 -0700899 // Exit any non playuntil complete parts immediately
900 if(exitPending() && !part.playUntilComplete)
901 break;
902
Ed Coyne7464ac92017-06-08 12:26:48 -0700903 mCallbacks->playPart(i, part, r);
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700904
Jesse Hall083b84c2014-09-22 10:51:09 -0700905 glClearColor(
906 part.backgroundColor[0],
907 part.backgroundColor[1],
908 part.backgroundColor[2],
909 1.0f);
910
Narayan Kamathafd31e02013-12-03 13:16:03 +0000911 for (size_t j=0 ; j<fcount && (!exitPending() || part.playUntilComplete) ; j++) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700912 const Animation::Frame& frame(part.frames[j]);
Mathias Agopiandb7dd2a2012-05-12 15:08:21 -0700913 nsecs_t lastFrame = systemTime();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700914
915 if (r > 0) {
916 glBindTexture(GL_TEXTURE_2D, frame.tid);
917 } else {
918 if (part.count != 1) {
919 glGenTextures(1, &frame.tid);
920 glBindTexture(GL_TEXTURE_2D, frame.tid);
921 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
922 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
923 }
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700924 int w, h;
925 initTexture(frame.map, &w, &h);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700926 }
927
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400928 const int xc = animationX + frame.trimX;
929 const int yc = animationY + frame.trimY;
930 Region clearReg(Rect(mWidth, mHeight));
931 clearReg.subtractSelf(Rect(xc, yc, xc+frame.trimWidth, yc+frame.trimHeight));
Mathias Agopian9f3020d2009-11-06 16:30:18 -0800932 if (!clearReg.isEmpty()) {
933 Region::const_iterator head(clearReg.begin());
934 Region::const_iterator tail(clearReg.end());
935 glEnable(GL_SCISSOR_TEST);
936 while (head != tail) {
Andreas Gampecfedceb2014-09-30 21:48:18 -0700937 const Rect& r2(*head++);
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400938 glScissor(r2.left, mHeight - r2.bottom, r2.width(), r2.height());
Mathias Agopian9f3020d2009-11-06 16:30:18 -0800939 glClear(GL_COLOR_BUFFER_BIT);
940 }
941 glDisable(GL_SCISSOR_TEST);
942 }
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400943 // specify the y center as ceiling((mHeight - frame.trimHeight) / 2)
944 // which is equivalent to mHeight - (yc + frame.trimHeight)
945 glDrawTexiOES(xc, mHeight - (yc + frame.trimHeight),
946 0, frame.trimWidth, frame.trimHeight);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700947 if (mClockEnabled && mTimeIsAccurate && validClock(part)) {
948 drawClock(animation.clockFont, part.clockPosX, part.clockPosY);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800949 }
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200950 handleViewport(frameDuration);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800951
Mathias Agopiana8826d62009-10-01 03:10:14 -0700952 eglSwapBuffers(mDisplay, mSurface);
953
954 nsecs_t now = systemTime();
955 nsecs_t delay = frameDuration - (now - lastFrame);
Mathias Agopiandb7dd2a2012-05-12 15:08:21 -0700956 //ALOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay));
Mathias Agopiana8826d62009-10-01 03:10:14 -0700957 lastFrame = now;
Mathias Agopiandb7dd2a2012-05-12 15:08:21 -0700958
959 if (delay > 0) {
960 struct timespec spec;
961 spec.tv_sec = (now + delay) / 1000000000;
962 spec.tv_nsec = (now + delay) % 1000000000;
963 int err;
964 do {
965 err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, NULL);
966 } while (err<0 && errno == EINTR);
967 }
Kevin Hesterd3782b22012-04-26 10:38:55 -0700968
969 checkExit();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700970 }
Kevin Hesterd3782b22012-04-26 10:38:55 -0700971
Mathias Agopiana8826d62009-10-01 03:10:14 -0700972 usleep(part.pause * ns2us(frameDuration));
Kevin Hesterd3782b22012-04-26 10:38:55 -0700973
974 // For infinite parts, we've now played them at least once, so perhaps exit
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200975 if(exitPending() && !part.count && mCurrentInset >= mTargetInset)
Kevin Hesterd3782b22012-04-26 10:38:55 -0700976 break;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700977 }
978
Geoffrey Pitsch2fb30fb2016-07-06 16:16:20 -0400979 }
980
981 // Free textures created for looping parts now that the animation is done.
982 for (const Animation::Part& part : animation.parts) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700983 if (part.count != 1) {
Geoffrey Pitsch2fb30fb2016-07-06 16:16:20 -0400984 const size_t fcount = part.frames.size();
985 for (size_t j = 0; j < fcount; j++) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700986 const Animation::Frame& frame(part.frames[j]);
987 glDeleteTextures(1, &frame.tid);
988 }
989 }
990 }
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -0700991
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700992 return true;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700993}
994
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200995void BootAnimation::handleViewport(nsecs_t timestep) {
996 if (mShuttingDown || !mFlingerSurfaceControl || mTargetInset == 0) {
997 return;
998 }
999 if (mTargetInset < 0) {
1000 // Poll the amount for the top display inset. This will return -1 until persistent properties
1001 // have been loaded.
1002 mTargetInset = android::base::GetIntProperty("persist.sys.displayinset.top",
1003 -1 /* default */, -1 /* min */, mHeight / 2 /* max */);
1004 }
1005 if (mTargetInset <= 0) {
1006 return;
1007 }
1008
1009 if (mCurrentInset < mTargetInset) {
1010 // After the device boots, the inset will effectively be cropped away. We animate this here.
1011 float fraction = static_cast<float>(mCurrentInset) / mTargetInset;
1012 int interpolatedInset = (cosf((fraction + 1) * M_PI) / 2.0f + 0.5f) * mTargetInset;
1013
1014 SurfaceComposerClient::Transaction()
1015 .setCrop(mFlingerSurfaceControl, Rect(0, interpolatedInset, mWidth, mHeight))
1016 .apply();
1017 } else {
1018 // At the end of the animation, we switch to the viewport that DisplayManager will apply
1019 // later. This changes the coordinate system, and means we must move the surface up by
1020 // the inset amount.
1021 sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
1022 ISurfaceComposer::eDisplayIdMain));
1023
1024 Rect layerStackRect(0, 0, mWidth, mHeight - mTargetInset);
1025 Rect displayRect(0, mTargetInset, mWidth, mHeight);
1026
1027 SurfaceComposerClient::Transaction t;
1028 t.setPosition(mFlingerSurfaceControl, 0, -mTargetInset)
1029 .setCrop(mFlingerSurfaceControl, Rect(0, mTargetInset, mWidth, mHeight));
1030 t.setDisplayProjection(dtoken, 0 /* orientation */, layerStackRect, displayRect);
1031 t.apply();
1032
1033 mTargetInset = mCurrentInset = 0;
1034 }
1035
1036 int delta = timestep * mTargetInset / ms2ns(200);
1037 mCurrentInset += delta;
1038}
1039
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001040void BootAnimation::releaseAnimation(Animation* animation) const
1041{
1042 for (Vector<Animation::Part>::iterator it = animation->parts.begin(),
1043 e = animation->parts.end(); it != e; ++it) {
1044 if (it->animation)
1045 releaseAnimation(it->animation);
1046 }
1047 if (animation->zip)
1048 delete animation->zip;
1049 delete animation;
1050}
1051
1052BootAnimation::Animation* BootAnimation::loadAnimation(const String8& fn)
1053{
1054 if (mLoadedFiles.indexOf(fn) >= 0) {
1055 ALOGE("File \"%s\" is already loaded. Cyclic ref is not allowed",
1056 fn.string());
1057 return NULL;
1058 }
1059 ZipFileRO *zip = ZipFileRO::open(fn);
1060 if (zip == NULL) {
1061 ALOGE("Failed to open animation zip \"%s\": %s",
1062 fn.string(), strerror(errno));
1063 return NULL;
1064 }
1065
1066 Animation *animation = new Animation;
1067 animation->fileName = fn;
1068 animation->zip = zip;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001069 animation->clockFont.map = nullptr;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001070 mLoadedFiles.add(animation->fileName);
1071
1072 parseAnimationDesc(*animation);
Geoffrey Pitscha91a2d72016-07-12 14:46:19 -04001073 if (!preloadZip(*animation)) {
1074 return NULL;
1075 }
1076
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001077
1078 mLoadedFiles.remove(fn);
1079 return animation;
1080}
Damien Bargiacchi97480862016-03-29 14:55:55 -07001081
1082bool BootAnimation::updateIsTimeAccurate() {
1083 static constexpr long long MAX_TIME_IN_PAST = 60000LL * 60LL * 24LL * 30LL; // 30 days
1084 static constexpr long long MAX_TIME_IN_FUTURE = 60000LL * 90LL; // 90 minutes
1085
1086 if (mTimeIsAccurate) {
1087 return true;
1088 }
Keun-young Parkb5938422017-03-23 13:46:24 -07001089 if (mShuttingDown) return true;
Damien Bargiacchi97480862016-03-29 14:55:55 -07001090 struct stat statResult;
Damien Bargiacchi9071db12016-10-28 17:38:22 -07001091
1092 if(stat(TIME_FORMAT_12_HOUR_FLAG_FILE_PATH, &statResult) == 0) {
1093 mTimeFormat12Hour = true;
1094 }
1095
Damien Bargiacchi97480862016-03-29 14:55:55 -07001096 if(stat(ACCURATE_TIME_FLAG_FILE_PATH, &statResult) == 0) {
1097 mTimeIsAccurate = true;
1098 return true;
1099 }
1100
1101 FILE* file = fopen(LAST_TIME_CHANGED_FILE_PATH, "r");
1102 if (file != NULL) {
1103 long long lastChangedTime = 0;
1104 fscanf(file, "%lld", &lastChangedTime);
1105 fclose(file);
1106 if (lastChangedTime > 0) {
1107 struct timespec now;
1108 clock_gettime(CLOCK_REALTIME, &now);
1109 // Match the Java timestamp format
1110 long long rtcNow = (now.tv_sec * 1000LL) + (now.tv_nsec / 1000000LL);
Damien Bargiacchi96762812016-07-12 15:53:40 -07001111 if (ACCURATE_TIME_EPOCH < rtcNow
1112 && lastChangedTime > (rtcNow - MAX_TIME_IN_PAST)
1113 && lastChangedTime < (rtcNow + MAX_TIME_IN_FUTURE)) {
Damien Bargiacchi97480862016-03-29 14:55:55 -07001114 mTimeIsAccurate = true;
1115 }
1116 }
1117 }
1118
1119 return mTimeIsAccurate;
1120}
1121
1122BootAnimation::TimeCheckThread::TimeCheckThread(BootAnimation* bootAnimation) : Thread(false),
1123 mInotifyFd(-1), mSystemWd(-1), mTimeWd(-1), mBootAnimation(bootAnimation) {}
1124
1125BootAnimation::TimeCheckThread::~TimeCheckThread() {
1126 // mInotifyFd may be -1 but that's ok since we're not at risk of attempting to close a valid FD.
1127 close(mInotifyFd);
1128}
1129
1130bool BootAnimation::TimeCheckThread::threadLoop() {
1131 bool shouldLoop = doThreadLoop() && !mBootAnimation->mTimeIsAccurate
1132 && mBootAnimation->mClockEnabled;
1133 if (!shouldLoop) {
1134 close(mInotifyFd);
1135 mInotifyFd = -1;
1136 }
1137 return shouldLoop;
1138}
1139
1140bool BootAnimation::TimeCheckThread::doThreadLoop() {
1141 static constexpr int BUFF_LEN (10 * (sizeof(struct inotify_event) + NAME_MAX + 1));
1142
1143 // Poll instead of doing a blocking read so the Thread can exit if requested.
1144 struct pollfd pfd = { mInotifyFd, POLLIN, 0 };
1145 ssize_t pollResult = poll(&pfd, 1, 1000);
1146
1147 if (pollResult == 0) {
1148 return true;
1149 } else if (pollResult < 0) {
1150 ALOGE("Could not poll inotify events");
1151 return false;
1152 }
1153
1154 char buff[BUFF_LEN] __attribute__ ((aligned(__alignof__(struct inotify_event))));;
1155 ssize_t length = read(mInotifyFd, buff, BUFF_LEN);
1156 if (length == 0) {
1157 return true;
1158 } else if (length < 0) {
1159 ALOGE("Could not read inotify events");
1160 return false;
1161 }
1162
1163 const struct inotify_event *event;
1164 for (char* ptr = buff; ptr < buff + length; ptr += sizeof(struct inotify_event) + event->len) {
1165 event = (const struct inotify_event *) ptr;
1166 if (event->wd == mSystemWd && strcmp(SYSTEM_TIME_DIR_NAME, event->name) == 0) {
1167 addTimeDirWatch();
1168 } else if (event->wd == mTimeWd && (strcmp(LAST_TIME_CHANGED_FILE_NAME, event->name) == 0
1169 || strcmp(ACCURATE_TIME_FLAG_FILE_NAME, event->name) == 0)) {
1170 return !mBootAnimation->updateIsTimeAccurate();
1171 }
1172 }
1173
1174 return true;
1175}
1176
1177void BootAnimation::TimeCheckThread::addTimeDirWatch() {
1178 mTimeWd = inotify_add_watch(mInotifyFd, SYSTEM_TIME_DIR_PATH,
1179 IN_CLOSE_WRITE | IN_MOVED_TO | IN_ATTRIB);
1180 if (mTimeWd > 0) {
1181 // No need to watch for the time directory to be created if it already exists
1182 inotify_rm_watch(mInotifyFd, mSystemWd);
1183 mSystemWd = -1;
1184 }
1185}
1186
1187status_t BootAnimation::TimeCheckThread::readyToRun() {
1188 mInotifyFd = inotify_init();
1189 if (mInotifyFd < 0) {
1190 ALOGE("Could not initialize inotify fd");
1191 return NO_INIT;
1192 }
1193
1194 mSystemWd = inotify_add_watch(mInotifyFd, SYSTEM_DATA_DIR_PATH, IN_CREATE | IN_ATTRIB);
1195 if (mSystemWd < 0) {
1196 close(mInotifyFd);
1197 mInotifyFd = -1;
1198 ALOGE("Could not add watch for %s", SYSTEM_DATA_DIR_PATH);
1199 return NO_INIT;
1200 }
1201
1202 addTimeDirWatch();
1203
1204 if (mBootAnimation->updateIsTimeAccurate()) {
1205 close(mInotifyFd);
1206 mInotifyFd = -1;
1207 return ALREADY_EXISTS;
1208 }
1209
1210 return NO_ERROR;
1211}
1212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001213// ---------------------------------------------------------------------------
1214
1215}
1216; // namespace android