blob: 4f772c37909842a8588b62ab59210b0fbc7aae73 [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
Jason parksbd9a08d2011-01-31 15:04:34 -060032#include <cutils/properties.h>
33
Mathias Agopianb13b9bd2012-02-17 18:27:36 -080034#include <androidfw/AssetManager.h>
Mathias Agopianac31a3b2009-05-21 19:59:24 -070035#include <binder/IPCThreadState.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036#include <utils/Atomic.h>
37#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"
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -070065#include "audioplay.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066
67namespace android {
68
Damien Bargiacchi97480862016-03-29 14:55:55 -070069static const char OEM_BOOTANIMATION_FILE[] = "/oem/media/bootanimation.zip";
70static const char SYSTEM_BOOTANIMATION_FILE[] = "/system/media/bootanimation.zip";
71static const char SYSTEM_ENCRYPTED_BOOTANIMATION_FILE[] = "/system/media/bootanimation-encrypted.zip";
Keun-young Parkb5938422017-03-23 13:46:24 -070072static const char OEM_SHUTDOWNANIMATION_FILE[] = "/oem/media/shutdownanimation.zip";
73static const char SYSTEM_SHUTDOWNANIMATION_FILE[] = "/system/media/shutdownanimation.zip";
74
Damien Bargiacchi97480862016-03-29 14:55:55 -070075static const char SYSTEM_DATA_DIR_PATH[] = "/data/system";
76static const char SYSTEM_TIME_DIR_NAME[] = "time";
77static const char SYSTEM_TIME_DIR_PATH[] = "/data/system/time";
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070078static const char CLOCK_FONT_ASSET[] = "images/clock_font.png";
79static const char CLOCK_FONT_ZIP_NAME[] = "clock_font.png";
Damien Bargiacchi97480862016-03-29 14:55:55 -070080static const char LAST_TIME_CHANGED_FILE_NAME[] = "last_time_change";
81static const char LAST_TIME_CHANGED_FILE_PATH[] = "/data/system/time/last_time_change";
82static const char ACCURATE_TIME_FLAG_FILE_NAME[] = "time_is_accurate";
83static const char ACCURATE_TIME_FLAG_FILE_PATH[] = "/data/system/time/time_is_accurate";
Damien Bargiacchi9071db12016-10-28 17:38:22 -070084static const char TIME_FORMAT_12_HOUR_FLAG_FILE_PATH[] = "/data/system/time/time_format_12_hour";
Damien Bargiacchi96762812016-07-12 15:53:40 -070085// Java timestamp format. Don't show the clock if the date is before 2000-01-01 00:00:00.
86static const long long ACCURATE_TIME_EPOCH = 946684800000;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070087static constexpr char FONT_BEGIN_CHAR = ' ';
88static constexpr char FONT_END_CHAR = '~' + 1;
89static constexpr size_t FONT_NUM_CHARS = FONT_END_CHAR - FONT_BEGIN_CHAR + 1;
90static constexpr size_t FONT_NUM_COLS = 16;
91static constexpr size_t FONT_NUM_ROWS = FONT_NUM_CHARS / FONT_NUM_COLS;
92static const int TEXT_CENTER_VALUE = INT_MAX;
93static const int TEXT_MISSING_VALUE = INT_MIN;
Damien Bargiacchi97480862016-03-29 14:55:55 -070094static const char EXIT_PROP_NAME[] = "service.bootanim.exit";
Geoffrey Pitsch30508792016-07-22 17:04:21 -040095static const char PLAY_SOUND_PROP_NAME[] = "persist.sys.bootanim.play_sound";
Narayan Kamathafd31e02013-12-03 13:16:03 +000096static const int ANIM_ENTRY_NAME_MAX = 256;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -070097static constexpr size_t TEXT_POS_LEN_MAX = 16;
Geoffrey Pitsch290c4352016-08-09 14:35:10 -040098static const char BOOT_COMPLETED_PROP_NAME[] = "sys.boot_completed";
99static const char BOOTREASON_PROP_NAME[] = "ro.boot.bootreason";
100// bootreasons list in "system/core/bootstat/bootstat.cpp".
101static const std::vector<std::string> PLAY_SOUND_BOOTREASON_BLACKLIST {
102 "kernel_panic",
103 "Panic",
104 "Watchdog",
105};
Narayan Kamathafd31e02013-12-03 13:16:03 +0000106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107// ---------------------------------------------------------------------------
108
Damien Bargiacchi97480862016-03-29 14:55:55 -0700109BootAnimation::BootAnimation() : Thread(false), mClockEnabled(true), mTimeIsAccurate(false),
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700110 mTimeFormat12Hour(false), mTimeCheckThread(NULL) {
Mathias Agopian627e7b52009-05-21 19:21:59 -0700111 mSession = new SurfaceComposerClient();
Geoffrey Pitsch290c4352016-08-09 14:35:10 -0400112
113 // If the system has already booted, the animation is not being used for a boot.
Keun-young Parkb5938422017-03-23 13:46:24 -0700114 mSystemBoot = !android::base::GetBoolProperty(BOOT_COMPLETED_PROP_NAME, false);
115 std::string powerCtl = android::base::GetProperty("sys.powerctl", "");
116 if (powerCtl.empty()) {
117 mShuttingDown = false;
118 } else {
119 mShuttingDown = true;
120 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121}
122
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123void BootAnimation::onFirstRef() {
Mathias Agopianbc726112009-09-23 15:44:05 -0700124 status_t err = mSession->linkToComposerDeath(this);
Steve Block3762c312012-01-06 19:20:56 +0000125 ALOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err));
Mathias Agopian8434c532009-09-23 18:52:49 -0700126 if (err == NO_ERROR) {
Mathias Agopianbc726112009-09-23 15:44:05 -0700127 run("BootAnimation", PRIORITY_DISPLAY);
128 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800129}
130
Mathias Agopianbc726112009-09-23 15:44:05 -0700131sp<SurfaceComposerClient> BootAnimation::session() const {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132 return mSession;
133}
134
Mathias Agopianbc726112009-09-23 15:44:05 -0700135
Narayan Kamathafd31e02013-12-03 13:16:03 +0000136void BootAnimation::binderDied(const wp<IBinder>&)
Mathias Agopianbc726112009-09-23 15:44:05 -0700137{
138 // woah, surfaceflinger died!
Steve Block5baa3a62011-12-20 16:23:08 +0000139 ALOGD("SurfaceFlinger died, exiting...");
Mathias Agopianbc726112009-09-23 15:44:05 -0700140
141 // calling requestExit() is not enough here because the Surface code
142 // might be blocked on a condition variable that will never be updated.
143 kill( getpid(), SIGKILL );
144 requestExit();
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -0700145 audioplay::destroy();
Mathias Agopianbc726112009-09-23 15:44:05 -0700146}
147
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets,
149 const char* name) {
150 Asset* asset = assets.open(name, Asset::ACCESS_BUFFER);
Andreas Gampecfedceb2014-09-30 21:48:18 -0700151 if (asset == NULL)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800152 return NO_INIT;
153 SkBitmap bitmap;
Matt Sarett8898c162016-03-24 16:11:01 -0400154 sk_sp<SkData> data = SkData::MakeWithoutCopy(asset->getBuffer(false),
155 asset->getLength());
156 sk_sp<SkImage> image = SkImage::MakeFromEncoded(data);
157 image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 asset->close();
159 delete asset;
160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 const int w = bitmap.width();
162 const int h = bitmap.height();
163 const void* p = bitmap.getPixels();
164
165 GLint crop[4] = { 0, h, w, -h };
166 texture->w = w;
167 texture->h = h;
168
169 glGenTextures(1, &texture->name);
170 glBindTexture(GL_TEXTURE_2D, texture->name);
171
Mike Reed42a1d082014-07-07 18:06:18 -0400172 switch (bitmap.colorType()) {
173 case kAlpha_8_SkColorType:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA,
175 GL_UNSIGNED_BYTE, p);
176 break;
Mike Reed42a1d082014-07-07 18:06:18 -0400177 case kARGB_4444_SkColorType:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
179 GL_UNSIGNED_SHORT_4_4_4_4, p);
180 break;
Mike Reed42a1d082014-07-07 18:06:18 -0400181 case kN32_SkColorType:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
183 GL_UNSIGNED_BYTE, p);
184 break;
Mike Reed42a1d082014-07-07 18:06:18 -0400185 case kRGB_565_SkColorType:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB,
187 GL_UNSIGNED_SHORT_5_6_5, p);
188 break;
189 default:
190 break;
191 }
192
193 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
194 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
195 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
196 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
197 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 return NO_ERROR;
200}
201
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700202status_t BootAnimation::initTexture(FileMap* map, int* width, int* height)
Mathias Agopiana8826d62009-10-01 03:10:14 -0700203{
Mathias Agopiana8826d62009-10-01 03:10:14 -0700204 SkBitmap bitmap;
Damien Bargiacchif67b3172016-09-07 20:17:14 -0700205 sk_sp<SkData> data = SkData::MakeWithoutCopy(map->getDataPtr(),
206 map->getDataLength());
Matt Sarett8898c162016-03-24 16:11:01 -0400207 sk_sp<SkImage> image = SkImage::MakeFromEncoded(data);
208 image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700209
Mykola Kondratenko0c1eeb32014-04-15 09:35:44 +0200210 // FileMap memory is never released until application exit.
211 // Release it now as the texture is already loaded and the memory used for
212 // the packed resource can be released.
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700213 delete map;
Mykola Kondratenko0c1eeb32014-04-15 09:35:44 +0200214
Mathias Agopiana8826d62009-10-01 03:10:14 -0700215 const int w = bitmap.width();
216 const int h = bitmap.height();
217 const void* p = bitmap.getPixels();
218
219 GLint crop[4] = { 0, h, w, -h };
220 int tw = 1 << (31 - __builtin_clz(w));
221 int th = 1 << (31 - __builtin_clz(h));
222 if (tw < w) tw <<= 1;
223 if (th < h) th <<= 1;
224
Mike Reed42a1d082014-07-07 18:06:18 -0400225 switch (bitmap.colorType()) {
226 case kN32_SkColorType:
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530227 if (!mUseNpotTextures && (tw != w || th != h)) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700228 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA,
229 GL_UNSIGNED_BYTE, 0);
230 glTexSubImage2D(GL_TEXTURE_2D, 0,
231 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p);
232 } else {
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530233 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA,
Mathias Agopiana8826d62009-10-01 03:10:14 -0700234 GL_UNSIGNED_BYTE, p);
235 }
236 break;
237
Mike Reed42a1d082014-07-07 18:06:18 -0400238 case kRGB_565_SkColorType:
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530239 if (!mUseNpotTextures && (tw != w || th != h)) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700240 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB,
241 GL_UNSIGNED_SHORT_5_6_5, 0);
242 glTexSubImage2D(GL_TEXTURE_2D, 0,
243 0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p);
244 } else {
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530245 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB,
Mathias Agopiana8826d62009-10-01 03:10:14 -0700246 GL_UNSIGNED_SHORT_5_6_5, p);
247 }
248 break;
249 default:
250 break;
251 }
252
253 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
254
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700255 *width = w;
256 *height = h;
257
Mathias Agopiana8826d62009-10-01 03:10:14 -0700258 return NO_ERROR;
259}
260
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800261status_t BootAnimation::readyToRun() {
262 mAssets.addDefaultAssets();
263
Jeff Brown0b722fe2012-08-24 22:40:14 -0700264 sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay(
265 ISurfaceComposer::eDisplayIdMain));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 DisplayInfo dinfo;
Jeff Brown0b722fe2012-08-24 22:40:14 -0700267 status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800268 if (status)
269 return -1;
270
271 // create the native surface
Jeff Brown0b722fe2012-08-24 22:40:14 -0700272 sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"),
273 dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565);
Mathias Agopian439863f2011-06-28 19:09:31 -0700274
275 SurfaceComposerClient::openGlobalTransaction();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700276 control->setLayer(0x40000000);
Mathias Agopian439863f2011-06-28 19:09:31 -0700277 SurfaceComposerClient::closeGlobalTransaction();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278
Mathias Agopian17f638b2009-04-16 20:04:08 -0700279 sp<Surface> s = control->getSurface();
280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 // initialize opengl and egl
Mathias Agopian738b9a42009-08-06 16:41:02 -0700282 const EGLint attribs[] = {
Mathias Agopian1b253b72011-08-15 15:20:22 -0700283 EGL_RED_SIZE, 8,
284 EGL_GREEN_SIZE, 8,
285 EGL_BLUE_SIZE, 8,
Mathias Agopiana8826d62009-10-01 03:10:14 -0700286 EGL_DEPTH_SIZE, 0,
287 EGL_NONE
Mathias Agopian738b9a42009-08-06 16:41:02 -0700288 };
Andreas Gampecfedceb2014-09-30 21:48:18 -0700289 EGLint w, h;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290 EGLint numConfigs;
291 EGLConfig config;
292 EGLSurface surface;
293 EGLContext context;
Mathias Agopian627e7b52009-05-21 19:21:59 -0700294
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800295 EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
Mathias Agopian627e7b52009-05-21 19:21:59 -0700296
297 eglInitialize(display, 0, 0);
Mathias Agopian1b253b72011-08-15 15:20:22 -0700298 eglChooseConfig(display, attribs, &config, 1, &numConfigs);
Mathias Agopian1473f462009-04-10 14:24:30 -0700299 surface = eglCreateWindowSurface(display, config, s.get(), NULL);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800300 context = eglCreateContext(display, config, NULL, NULL);
301 eglQuerySurface(display, surface, EGL_WIDTH, &w);
302 eglQuerySurface(display, surface, EGL_HEIGHT, &h);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700303
Mathias Agopianabac0102009-07-31 14:47:00 -0700304 if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE)
305 return NO_INIT;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700306
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800307 mDisplay = display;
308 mContext = context;
309 mSurface = surface;
310 mWidth = w;
311 mHeight = h;
Mathias Agopian17f638b2009-04-16 20:04:08 -0700312 mFlingerSurfaceControl = control;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 mFlingerSurface = s;
314
Elliott Hughesc367d482013-10-29 13:12:55 -0700315 // If the device has encryption turned on or is in process
Jason parksbd9a08d2011-01-31 15:04:34 -0600316 // of being encrypted we show the encrypted boot animation.
317 char decrypt[PROPERTY_VALUE_MAX];
318 property_get("vold.decrypt", decrypt, "");
319
Keun-young Parkb5938422017-03-23 13:46:24 -0700320 bool encryptedAnimation = atoi(decrypt) != 0 ||
321 !strcmp("trigger_restart_min_framework", decrypt);
Jason parksbd9a08d2011-01-31 15:04:34 -0600322
Keun-young Parkb5938422017-03-23 13:46:24 -0700323 if (!mShuttingDown && encryptedAnimation &&
324 (access(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, R_OK) == 0)) {
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700325 mZipFileName = SYSTEM_ENCRYPTED_BOOTANIMATION_FILE;
Keun-young Parkb5938422017-03-23 13:46:24 -0700326 return NO_ERROR;
Jason parksbd9a08d2011-01-31 15:04:34 -0600327 }
Keun-young Parkb5938422017-03-23 13:46:24 -0700328 static const char* bootFiles[] = {OEM_BOOTANIMATION_FILE, SYSTEM_BOOTANIMATION_FILE};
329 static const char* shutdownFiles[] =
330 {OEM_SHUTDOWNANIMATION_FILE, SYSTEM_SHUTDOWNANIMATION_FILE};
331
332 for (const char* f : (!mShuttingDown ? bootFiles : shutdownFiles)) {
333 if (access(f, R_OK) == 0) {
334 mZipFileName = f;
335 return NO_ERROR;
336 }
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700337 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 return NO_ERROR;
339}
340
Mathias Agopiana8826d62009-10-01 03:10:14 -0700341bool BootAnimation::threadLoop()
342{
343 bool r;
Narayan Kamathafd31e02013-12-03 13:16:03 +0000344 // We have no bootanimation file, so we use the stock android logo
345 // animation.
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700346 if (mZipFileName.isEmpty()) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700347 r = android();
348 } else {
349 r = movie();
350 }
351
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800352 eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
353 eglDestroyContext(mDisplay, mContext);
354 eglDestroySurface(mDisplay, mSurface);
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700355 mFlingerSurface.clear();
Mathias Agopian17f638b2009-04-16 20:04:08 -0700356 mFlingerSurfaceControl.clear();
Mathias Agopian627e7b52009-05-21 19:21:59 -0700357 eglTerminate(mDisplay);
Sai Kiran Korwar3eee9fb2015-06-16 17:13:35 +0530358 eglReleaseThread();
Mathias Agopian627e7b52009-05-21 19:21:59 -0700359 IPCThreadState::self()->stopProcess();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 return r;
361}
362
Mathias Agopiana8826d62009-10-01 03:10:14 -0700363bool BootAnimation::android()
364{
Keun-young Parkd1794cd2017-04-04 12:21:19 -0700365 ALOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
366 elapsedRealtime());
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700367 initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png");
368 initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369
370 // clear screen
Mathias Agopiana8826d62009-10-01 03:10:14 -0700371 glShadeModel(GL_FLAT);
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700372 glDisable(GL_DITHER);
373 glDisable(GL_SCISSOR_TEST);
Mathias Agopian59f19e42011-05-06 19:22:12 -0700374 glClearColor(0,0,0,1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375 glClear(GL_COLOR_BUFFER_BIT);
376 eglSwapBuffers(mDisplay, mSurface);
377
Mathias Agopiana8826d62009-10-01 03:10:14 -0700378 glEnable(GL_TEXTURE_2D);
379 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
380
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700381 const GLint xc = (mWidth - mAndroid[0].w) / 2;
382 const GLint yc = (mHeight - mAndroid[0].h) / 2;
383 const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800385 glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(),
386 updateRect.height());
387
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700388 // Blend state
389 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
390 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
391
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 const nsecs_t startTime = systemTime();
393 do {
Mathias Agopian13796652009-03-24 22:49:21 -0700394 nsecs_t now = systemTime();
395 double time = now - startTime;
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700396 float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w;
397 GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w;
398 GLint x = xc - offset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399
Mathias Agopian81668642009-07-28 11:41:30 -0700400 glDisable(GL_SCISSOR_TEST);
401 glClear(GL_COLOR_BUFFER_BIT);
402
403 glEnable(GL_SCISSOR_TEST);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800404 glDisable(GL_BLEND);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 glBindTexture(GL_TEXTURE_2D, mAndroid[1].name);
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700406 glDrawTexiOES(x, yc, 0, mAndroid[1].w, mAndroid[1].h);
407 glDrawTexiOES(x + mAndroid[1].w, yc, 0, mAndroid[1].w, mAndroid[1].h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800408
Mathias Agopianb2cf9542009-03-24 18:34:16 -0700409 glEnable(GL_BLEND);
410 glBindTexture(GL_TEXTURE_2D, mAndroid[0].name);
411 glDrawTexiOES(xc, yc, 0, mAndroid[0].w, mAndroid[0].h);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800412
Mathias Agopian627e7b52009-05-21 19:21:59 -0700413 EGLBoolean res = eglSwapBuffers(mDisplay, mSurface);
414 if (res == EGL_FALSE)
415 break;
416
Mathias Agopian13796652009-03-24 22:49:21 -0700417 // 12fps: don't animate too fast to preserve CPU
418 const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now);
419 if (sleepTime > 0)
Mathias Agopiana8826d62009-10-01 03:10:14 -0700420 usleep(sleepTime);
Kevin Hesterd3782b22012-04-26 10:38:55 -0700421
422 checkExit();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 } while (!exitPending());
424
425 glDeleteTextures(1, &mAndroid[0].name);
426 glDeleteTextures(1, &mAndroid[1].name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 return false;
428}
429
Kevin Hesterd3782b22012-04-26 10:38:55 -0700430void BootAnimation::checkExit() {
431 // Allow surface flinger to gracefully request shutdown
432 char value[PROPERTY_VALUE_MAX];
433 property_get(EXIT_PROP_NAME, value, "0");
434 int exitnow = atoi(value);
435 if (exitnow) {
436 requestExit();
437 }
438}
439
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700440bool BootAnimation::validClock(const Animation::Part& part) {
441 return part.clockPosX != TEXT_MISSING_VALUE && part.clockPosY != TEXT_MISSING_VALUE;
442}
443
444bool parseTextCoord(const char* str, int* dest) {
445 if (strcmp("c", str) == 0) {
446 *dest = TEXT_CENTER_VALUE;
447 return true;
448 }
449
450 char* end;
451 int val = (int) strtol(str, &end, 0);
452 if (end == str || *end != '\0' || val == INT_MAX || val == INT_MIN) {
453 return false;
454 }
455 *dest = val;
456 return true;
457}
458
459// Parse two position coordinates. If only string is non-empty, treat it as the y value.
460void parsePosition(const char* str1, const char* str2, int* x, int* y) {
461 bool success = false;
462 if (strlen(str1) == 0) { // No values were specified
463 // success = false
464 } else if (strlen(str2) == 0) { // we have only one value
465 if (parseTextCoord(str1, y)) {
466 *x = TEXT_CENTER_VALUE;
467 success = true;
468 }
469 } else {
470 if (parseTextCoord(str1, x) && parseTextCoord(str2, y)) {
471 success = true;
472 }
473 }
474
475 if (!success) {
476 *x = TEXT_MISSING_VALUE;
477 *y = TEXT_MISSING_VALUE;
478 }
479}
480
Jesse Hall083b84c2014-09-22 10:51:09 -0700481// Parse a color represented as an HTML-style 'RRGGBB' string: each pair of
482// characters in str is a hex number in [0, 255], which are converted to
483// floating point values in the range [0.0, 1.0] and placed in the
484// corresponding elements of color.
485//
486// If the input string isn't valid, parseColor returns false and color is
487// left unchanged.
488static bool parseColor(const char str[7], float color[3]) {
489 float tmpColor[3];
490 for (int i = 0; i < 3; i++) {
491 int val = 0;
492 for (int j = 0; j < 2; j++) {
493 val *= 16;
494 char c = str[2*i + j];
495 if (c >= '0' && c <= '9') val += c - '0';
496 else if (c >= 'A' && c <= 'F') val += (c - 'A') + 10;
497 else if (c >= 'a' && c <= 'f') val += (c - 'a') + 10;
498 else return false;
499 }
500 tmpColor[i] = static_cast<float>(val) / 255.0f;
501 }
502 memcpy(color, tmpColor, sizeof(tmpColor));
503 return true;
504}
505
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700506
507static bool readFile(ZipFileRO* zip, const char* name, String8& outString)
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700508{
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700509 ZipEntryRO entry = zip->findEntryByName(name);
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700510 ALOGE_IF(!entry, "couldn't find %s", name);
511 if (!entry) {
512 return false;
513 }
514
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700515 FileMap* entryMap = zip->createEntryFileMap(entry);
516 zip->releaseEntry(entry);
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700517 ALOGE_IF(!entryMap, "entryMap is null");
518 if (!entryMap) {
519 return false;
520 }
521
522 outString.setTo((char const*)entryMap->getDataPtr(), entryMap->getDataLength());
Narayan Kamath688ff4c2015-02-23 15:47:54 +0000523 delete entryMap;
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700524 return true;
525}
526
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700527// The font image should be a 96x2 array of character images. The
528// columns are the printable ASCII characters 0x20 - 0x7f. The
529// top row is regular text; the bottom row is bold.
530status_t BootAnimation::initFont(Font* font, const char* fallback) {
531 status_t status = NO_ERROR;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800532
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700533 if (font->map != nullptr) {
534 glGenTextures(1, &font->texture.name);
535 glBindTexture(GL_TEXTURE_2D, font->texture.name);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800536
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700537 status = initTexture(font->map, &font->texture.w, &font->texture.h);
538
539 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
540 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
541 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
542 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
543 } else if (fallback != nullptr) {
544 status = initTexture(&font->texture, mAssets, fallback);
545 } else {
546 return NO_INIT;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800547 }
548
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700549 if (status == NO_ERROR) {
550 font->char_width = font->texture.w / FONT_NUM_COLS;
551 font->char_height = font->texture.h / FONT_NUM_ROWS / 2; // There are bold and regular rows
552 }
553
554 return status;
555}
556
557void BootAnimation::drawText(const char* str, const Font& font, bool bold, int* x, int* y) {
558 glEnable(GL_BLEND); // Allow us to draw on top of the animation
559 glBindTexture(GL_TEXTURE_2D, font.texture.name);
560
561 const int len = strlen(str);
562 const int strWidth = font.char_width * len;
563
564 if (*x == TEXT_CENTER_VALUE) {
565 *x = (mWidth - strWidth) / 2;
566 } else if (*x < 0) {
567 *x = mWidth + *x - strWidth;
568 }
569 if (*y == TEXT_CENTER_VALUE) {
570 *y = (mHeight - font.char_height) / 2;
571 } else if (*y < 0) {
572 *y = mHeight + *y - font.char_height;
573 }
574
575 int cropRect[4] = { 0, 0, font.char_width, -font.char_height };
576
577 for (int i = 0; i < len; i++) {
578 char c = str[i];
579
580 if (c < FONT_BEGIN_CHAR || c > FONT_END_CHAR) {
581 c = '?';
582 }
583
584 // Crop the texture to only the pixels in the current glyph
585 const int charPos = (c - FONT_BEGIN_CHAR); // Position in the list of valid characters
586 const int row = charPos / FONT_NUM_COLS;
587 const int col = charPos % FONT_NUM_COLS;
588 cropRect[0] = col * font.char_width; // Left of column
589 cropRect[1] = row * font.char_height * 2; // Top of row
590 // Move down to bottom of regular (one char_heigh) or bold (two char_heigh) line
591 cropRect[1] += bold ? 2 * font.char_height : font.char_height;
592 glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect);
593
594 glDrawTexiOES(*x, *y, 0, font.char_width, font.char_height);
595
596 *x += font.char_width;
597 }
598
599 glDisable(GL_BLEND); // Return to the animation's default behaviour
600 glBindTexture(GL_TEXTURE_2D, 0);
601}
602
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700603// We render 12 or 24 hour time.
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700604void BootAnimation::drawClock(const Font& font, const int xPos, const int yPos) {
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700605 static constexpr char TIME_FORMAT_12[] = "%l:%M";
606 static constexpr char TIME_FORMAT_24[] = "%H:%M";
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700607 static constexpr int TIME_LENGTH = 6;
608
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800609 time_t rawtime;
610 time(&rawtime);
611 struct tm* timeInfo = localtime(&rawtime);
612
613 char timeBuff[TIME_LENGTH];
Damien Bargiacchi9071db12016-10-28 17:38:22 -0700614 const char* timeFormat = mTimeFormat12Hour ? TIME_FORMAT_12 : TIME_FORMAT_24;
615 size_t length = strftime(timeBuff, TIME_LENGTH, timeFormat, timeInfo);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800616
617 if (length != TIME_LENGTH - 1) {
618 ALOGE("Couldn't format time; abandoning boot animation clock");
619 mClockEnabled = false;
620 return;
621 }
622
Damien Bargiacchi45a76442016-12-05 18:02:18 -0800623 char* out = timeBuff[0] == ' ' ? &timeBuff[1] : &timeBuff[0];
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700624 int x = xPos;
625 int y = yPos;
Damien Bargiacchi45a76442016-12-05 18:02:18 -0800626 drawText(out, font, false, &x, &y);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800627}
628
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700629bool BootAnimation::parseAnimationDesc(Animation& animation)
Mathias Agopiana8826d62009-10-01 03:10:14 -0700630{
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700631 String8 desString;
632
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700633 if (!readFile(animation.zip, "desc.txt", desString)) {
Narayan Kamathafd31e02013-12-03 13:16:03 +0000634 return false;
635 }
Mathias Agopiana8826d62009-10-01 03:10:14 -0700636 char const* s = desString.string();
637
Mathias Agopiana8826d62009-10-01 03:10:14 -0700638 // Parse the description file
639 for (;;) {
640 const char* endl = strstr(s, "\n");
Andreas Gampecfedceb2014-09-30 21:48:18 -0700641 if (endl == NULL) break;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700642 String8 line(s, endl - s);
643 const char* l = line.string();
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800644 int fps = 0;
645 int width = 0;
646 int height = 0;
647 int count = 0;
648 int pause = 0;
Narayan Kamathafd31e02013-12-03 13:16:03 +0000649 char path[ANIM_ENTRY_NAME_MAX];
Jesse Hall083b84c2014-09-22 10:51:09 -0700650 char color[7] = "000000"; // default to black if unspecified
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700651 char clockPos1[TEXT_POS_LEN_MAX + 1] = "";
652 char clockPos2[TEXT_POS_LEN_MAX + 1] = "";
Jesse Hall083b84c2014-09-22 10:51:09 -0700653
Kevin Hesterd3782b22012-04-26 10:38:55 -0700654 char pathType;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700655 if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) {
Jesse Hall083b84c2014-09-22 10:51:09 -0700656 // ALOGD("> w=%d, h=%d, fps=%d", width, height, fps);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700657 animation.width = width;
658 animation.height = height;
659 animation.fps = fps;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700660 } else if (sscanf(l, " %c %d %d %s #%6s %16s %16s",
661 &pathType, &count, &pause, path, color, clockPos1, clockPos2) >= 4) {
662 //ALOGD("> type=%c, count=%d, pause=%d, path=%s, color=%s, clockPos1=%s, clockPos2=%s",
663 // pathType, count, pause, path, color, clockPos1, clockPos2);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700664 Animation::Part part;
Kevin Hesterd3782b22012-04-26 10:38:55 -0700665 part.playUntilComplete = pathType == 'c';
Mathias Agopiana8826d62009-10-01 03:10:14 -0700666 part.count = count;
667 part.pause = pause;
668 part.path = path;
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -0700669 part.audioData = NULL;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700670 part.animation = NULL;
Jesse Hall083b84c2014-09-22 10:51:09 -0700671 if (!parseColor(color, part.backgroundColor)) {
672 ALOGE("> invalid color '#%s'", color);
673 part.backgroundColor[0] = 0.0f;
674 part.backgroundColor[1] = 0.0f;
675 part.backgroundColor[2] = 0.0f;
676 }
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700677 parsePosition(clockPos1, clockPos2, &part.clockPosX, &part.clockPosY);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700678 animation.parts.add(part);
679 }
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700680 else if (strcmp(l, "$SYSTEM") == 0) {
681 // ALOGD("> SYSTEM");
682 Animation::Part part;
683 part.playUntilComplete = false;
684 part.count = 1;
685 part.pause = 0;
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -0700686 part.audioData = NULL;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700687 part.animation = loadAnimation(String8(SYSTEM_BOOTANIMATION_FILE));
688 if (part.animation != NULL)
689 animation.parts.add(part);
690 }
Mathias Agopiana8826d62009-10-01 03:10:14 -0700691 s = ++endl;
692 }
693
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700694 return true;
695}
696
697bool BootAnimation::preloadZip(Animation& animation)
698{
Mathias Agopiana8826d62009-10-01 03:10:14 -0700699 // read all the data structures
700 const size_t pcount = animation.parts.size();
Narayan Kamathafd31e02013-12-03 13:16:03 +0000701 void *cookie = NULL;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400702 ZipFileRO* zip = animation.zip;
703 if (!zip->startIteration(&cookie)) {
Narayan Kamathafd31e02013-12-03 13:16:03 +0000704 return false;
705 }
706
Geoffrey Pitscha91a2d72016-07-12 14:46:19 -0400707 Animation::Part* partWithAudio = NULL;
Narayan Kamathafd31e02013-12-03 13:16:03 +0000708 ZipEntryRO entry;
709 char name[ANIM_ENTRY_NAME_MAX];
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400710 while ((entry = zip->nextEntry(cookie)) != NULL) {
711 const int foundEntryName = zip->getEntryFileName(entry, name, ANIM_ENTRY_NAME_MAX);
Narayan Kamathafd31e02013-12-03 13:16:03 +0000712 if (foundEntryName > ANIM_ENTRY_NAME_MAX || foundEntryName == -1) {
713 ALOGE("Error fetching entry file name");
714 continue;
715 }
716
717 const String8 entryName(name);
718 const String8 path(entryName.getPathDir());
719 const String8 leaf(entryName.getPathLeaf());
720 if (leaf.size() > 0) {
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700721 if (entryName == CLOCK_FONT_ZIP_NAME) {
722 FileMap* map = zip->createEntryFileMap(entry);
723 if (map) {
724 animation.clockFont.map = map;
725 }
726 continue;
727 }
728
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400729 for (size_t j = 0; j < pcount; j++) {
Narayan Kamathafd31e02013-12-03 13:16:03 +0000730 if (path == animation.parts[j].path) {
Narayan Kamath4600dd02015-06-16 12:02:57 +0100731 uint16_t method;
Narayan Kamathafd31e02013-12-03 13:16:03 +0000732 // supports only stored png files
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400733 if (zip->getEntryInfo(entry, &method, NULL, NULL, NULL, NULL, NULL)) {
Narayan Kamathafd31e02013-12-03 13:16:03 +0000734 if (method == ZipFileRO::kCompressStored) {
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400735 FileMap* map = zip->createEntryFileMap(entry);
Narayan Kamathafd31e02013-12-03 13:16:03 +0000736 if (map) {
Narayan Kamathafd31e02013-12-03 13:16:03 +0000737 Animation::Part& part(animation.parts.editItemAt(j));
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700738 if (leaf == "audio.wav") {
739 // a part may have at most one audio file
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -0700740 part.audioData = (uint8_t *)map->getDataPtr();
741 part.audioLength = map->getDataLength();
Geoffrey Pitscha91a2d72016-07-12 14:46:19 -0400742 partWithAudio = &part;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400743 } else if (leaf == "trim.txt") {
744 part.trimData.setTo((char const*)map->getDataPtr(),
745 map->getDataLength());
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700746 } else {
747 Animation::Frame frame;
748 frame.name = leaf;
749 frame.map = map;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400750 frame.trimWidth = animation.width;
751 frame.trimHeight = animation.height;
752 frame.trimX = 0;
753 frame.trimY = 0;
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700754 part.frames.add(frame);
755 }
Mathias Agopiana8826d62009-10-01 03:10:14 -0700756 }
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -0700757 } else {
758 ALOGE("bootanimation.zip is compressed; must be only stored");
Mathias Agopiana8826d62009-10-01 03:10:14 -0700759 }
760 }
761 }
762 }
763 }
764 }
765
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400766 // If there is trimData present, override the positioning defaults.
767 for (Animation::Part& part : animation.parts) {
768 const char* trimDataStr = part.trimData.string();
769 for (size_t frameIdx = 0; frameIdx < part.frames.size(); frameIdx++) {
770 const char* endl = strstr(trimDataStr, "\n");
771 // No more trimData for this part.
772 if (endl == NULL) {
773 break;
774 }
775 String8 line(trimDataStr, endl - trimDataStr);
776 const char* lineStr = line.string();
777 trimDataStr = ++endl;
778 int width = 0, height = 0, x = 0, y = 0;
779 if (sscanf(lineStr, "%dx%d+%d+%d", &width, &height, &x, &y) == 4) {
780 Animation::Frame& frame(part.frames.editItemAt(frameIdx));
781 frame.trimWidth = width;
782 frame.trimHeight = height;
783 frame.trimX = x;
784 frame.trimY = y;
785 } else {
786 ALOGE("Error parsing trim.txt, line: %s", lineStr);
787 break;
788 }
789 }
790 }
791
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -0700792 // Create and initialize audioplay if there is a wav file in any of the animations.
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400793 // Do it on a separate thread so we don't hold up the animation intro.
Geoffrey Pitscha91a2d72016-07-12 14:46:19 -0400794 if (partWithAudio != NULL) {
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -0700795 ALOGD("found audio.wav, creating playback engine");
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400796 mInitAudioThread = new InitAudioThread(partWithAudio->audioData,
797 partWithAudio->audioLength);
798 mInitAudioThread->run("BootAnimation::InitAudioThread", PRIORITY_NORMAL);
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -0700799 }
800
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400801 zip->endIteration(cookie);
Narayan Kamathafd31e02013-12-03 13:16:03 +0000802
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700803 return true;
804}
805
806bool BootAnimation::movie()
807{
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700808 Animation* animation = loadAnimation(mZipFileName);
809 if (animation == NULL)
810 return false;
811
Damien Bargiacchi97480862016-03-29 14:55:55 -0700812 bool anyPartHasClock = false;
813 for (size_t i=0; i < animation->parts.size(); i++) {
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700814 if(validClock(animation->parts[i])) {
Damien Bargiacchi97480862016-03-29 14:55:55 -0700815 anyPartHasClock = true;
816 break;
817 }
818 }
819 if (!anyPartHasClock) {
820 mClockEnabled = false;
821 }
822
Sai Kiran Korwar27167492015-07-07 20:00:06 +0530823 // Check if npot textures are supported
824 mUseNpotTextures = false;
825 String8 gl_extensions;
826 const char* exts = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
827 if (!exts) {
828 glGetError();
829 } else {
830 gl_extensions.setTo(exts);
831 if ((gl_extensions.find("GL_ARB_texture_non_power_of_two") != -1) ||
832 (gl_extensions.find("GL_OES_texture_npot") != -1)) {
833 mUseNpotTextures = true;
834 }
835 }
836
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800837 // Blend required to draw time on top of animation frames.
838 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700839 glShadeModel(GL_FLAT);
840 glDisable(GL_DITHER);
841 glDisable(GL_SCISSOR_TEST);
842 glDisable(GL_BLEND);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700843
844 glBindTexture(GL_TEXTURE_2D, 0);
845 glEnable(GL_TEXTURE_2D);
846 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
847 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
848 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
849 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
850 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
851
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700852 bool clockFontInitialized = false;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800853 if (mClockEnabled) {
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700854 clockFontInitialized =
855 (initFont(&animation->clockFont, CLOCK_FONT_ASSET) == NO_ERROR);
856 mClockEnabled = clockFontInitialized;
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800857 }
858
Damien Bargiacchi97480862016-03-29 14:55:55 -0700859 if (mClockEnabled && !updateIsTimeAccurate()) {
860 mTimeCheckThread = new TimeCheckThread(this);
861 mTimeCheckThread->run("BootAnimation::TimeCheckThread", PRIORITY_NORMAL);
862 }
863
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700864 playAnimation(*animation);
Damien Bargiacchi97480862016-03-29 14:55:55 -0700865
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400866 if (mTimeCheckThread != nullptr) {
Damien Bargiacchi97480862016-03-29 14:55:55 -0700867 mTimeCheckThread->requestExit();
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400868 mTimeCheckThread = nullptr;
869 }
870
Wei Wanga90c54c2017-02-02 11:35:21 -0800871 // We should have joined mInitAudioThread thread in playAnimation
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400872 if (mInitAudioThread != nullptr) {
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400873 mInitAudioThread = nullptr;
Damien Bargiacchi97480862016-03-29 14:55:55 -0700874 }
875
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700876 releaseAnimation(animation);
877
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700878 if (clockFontInitialized) {
879 glDeleteTextures(1, &animation->clockFont.texture.name);
Andriy Naborskyy815e51d2016-03-24 16:43:34 -0700880 }
881
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700882 return false;
883}
884
885bool BootAnimation::playAnimation(const Animation& animation)
886{
887 const size_t pcount = animation.parts.size();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700888 nsecs_t frameDuration = s2ns(1) / animation.fps;
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400889 const int animationX = (mWidth - animation.width) / 2;
890 const int animationY = (mHeight - animation.height) / 2;
Mathias Agopian9f3020d2009-11-06 16:30:18 -0800891
Keun-young Parkd1794cd2017-04-04 12:21:19 -0700892 ALOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot",
893 elapsedRealtime());
Narayan Kamathafd31e02013-12-03 13:16:03 +0000894 for (size_t i=0 ; i<pcount ; i++) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700895 const Animation::Part& part(animation.parts[i]);
896 const size_t fcount = part.frames.size();
897 glBindTexture(GL_TEXTURE_2D, 0);
898
Andriy Naborskyy39218ba2015-08-16 21:32:50 -0700899 // Handle animation package
900 if (part.animation != NULL) {
901 playAnimation(*part.animation);
902 if (exitPending())
903 break;
904 continue; //to next part
905 }
906
Mathias Agopiana8826d62009-10-01 03:10:14 -0700907 for (int r=0 ; !part.count || r<part.count ; r++) {
Kevin Hesterd3782b22012-04-26 10:38:55 -0700908 // Exit any non playuntil complete parts immediately
909 if(exitPending() && !part.playUntilComplete)
910 break;
911
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700912 // only play audio file the first time we animate the part
Geoffrey Pitsch290c4352016-08-09 14:35:10 -0400913 if (r == 0 && part.audioData && playSoundsAllowed()) {
914 ALOGD("playing clip for part%d, size=%d", (int) i, part.audioLength);
Geoffrey Pitscha9173532016-07-19 14:56:39 -0400915 // Block until the audio engine is finished initializing.
916 if (mInitAudioThread != nullptr) {
917 mInitAudioThread->join();
918 }
Geoffrey Pitsch290c4352016-08-09 14:35:10 -0400919 audioplay::playClip(part.audioData, part.audioLength);
Mike Lockwoodebf9a0d2014-10-02 16:08:47 -0700920 }
921
Jesse Hall083b84c2014-09-22 10:51:09 -0700922 glClearColor(
923 part.backgroundColor[0],
924 part.backgroundColor[1],
925 part.backgroundColor[2],
926 1.0f);
927
Narayan Kamathafd31e02013-12-03 13:16:03 +0000928 for (size_t j=0 ; j<fcount && (!exitPending() || part.playUntilComplete) ; j++) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700929 const Animation::Frame& frame(part.frames[j]);
Mathias Agopiandb7dd2a2012-05-12 15:08:21 -0700930 nsecs_t lastFrame = systemTime();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700931
932 if (r > 0) {
933 glBindTexture(GL_TEXTURE_2D, frame.tid);
934 } else {
935 if (part.count != 1) {
936 glGenTextures(1, &frame.tid);
937 glBindTexture(GL_TEXTURE_2D, frame.tid);
938 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
939 glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
940 }
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700941 int w, h;
942 initTexture(frame.map, &w, &h);
Mathias Agopiana8826d62009-10-01 03:10:14 -0700943 }
944
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400945 const int xc = animationX + frame.trimX;
946 const int yc = animationY + frame.trimY;
947 Region clearReg(Rect(mWidth, mHeight));
948 clearReg.subtractSelf(Rect(xc, yc, xc+frame.trimWidth, yc+frame.trimHeight));
Mathias Agopian9f3020d2009-11-06 16:30:18 -0800949 if (!clearReg.isEmpty()) {
950 Region::const_iterator head(clearReg.begin());
951 Region::const_iterator tail(clearReg.end());
952 glEnable(GL_SCISSOR_TEST);
953 while (head != tail) {
Andreas Gampecfedceb2014-09-30 21:48:18 -0700954 const Rect& r2(*head++);
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400955 glScissor(r2.left, mHeight - r2.bottom, r2.width(), r2.height());
Mathias Agopian9f3020d2009-11-06 16:30:18 -0800956 glClear(GL_COLOR_BUFFER_BIT);
957 }
958 glDisable(GL_SCISSOR_TEST);
959 }
Geoffrey Pitschdd214a72016-06-27 17:14:30 -0400960 // specify the y center as ceiling((mHeight - frame.trimHeight) / 2)
961 // which is equivalent to mHeight - (yc + frame.trimHeight)
962 glDrawTexiOES(xc, mHeight - (yc + frame.trimHeight),
963 0, frame.trimWidth, frame.trimHeight);
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -0700964 if (mClockEnabled && mTimeIsAccurate && validClock(part)) {
965 drawClock(animation.clockFont, part.clockPosX, part.clockPosY);
Damien Bargiacchia704b7d2016-02-16 16:55:49 -0800966 }
967
Mathias Agopiana8826d62009-10-01 03:10:14 -0700968 eglSwapBuffers(mDisplay, mSurface);
969
970 nsecs_t now = systemTime();
971 nsecs_t delay = frameDuration - (now - lastFrame);
Mathias Agopiandb7dd2a2012-05-12 15:08:21 -0700972 //ALOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay));
Mathias Agopiana8826d62009-10-01 03:10:14 -0700973 lastFrame = now;
Mathias Agopiandb7dd2a2012-05-12 15:08:21 -0700974
975 if (delay > 0) {
976 struct timespec spec;
977 spec.tv_sec = (now + delay) / 1000000000;
978 spec.tv_nsec = (now + delay) % 1000000000;
979 int err;
980 do {
981 err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, NULL);
982 } while (err<0 && errno == EINTR);
983 }
Kevin Hesterd3782b22012-04-26 10:38:55 -0700984
985 checkExit();
Mathias Agopiana8826d62009-10-01 03:10:14 -0700986 }
Kevin Hesterd3782b22012-04-26 10:38:55 -0700987
Mathias Agopiana8826d62009-10-01 03:10:14 -0700988 usleep(part.pause * ns2us(frameDuration));
Kevin Hesterd3782b22012-04-26 10:38:55 -0700989
990 // For infinite parts, we've now played them at least once, so perhaps exit
991 if(exitPending() && !part.count)
992 break;
Mathias Agopiana8826d62009-10-01 03:10:14 -0700993 }
994
Geoffrey Pitsch2fb30fb2016-07-06 16:16:20 -0400995 }
996
997 // Free textures created for looping parts now that the animation is done.
998 for (const Animation::Part& part : animation.parts) {
Mathias Agopiana8826d62009-10-01 03:10:14 -0700999 if (part.count != 1) {
Geoffrey Pitsch2fb30fb2016-07-06 16:16:20 -04001000 const size_t fcount = part.frames.size();
1001 for (size_t j = 0; j < fcount; j++) {
Mathias Agopiana8826d62009-10-01 03:10:14 -07001002 const Animation::Frame& frame(part.frames[j]);
1003 glDeleteTextures(1, &frame.tid);
1004 }
1005 }
1006 }
Geoffrey Pitschd6d9a1d2016-06-08 00:38:58 -07001007
1008 // we've finally played everything we're going to play
1009 audioplay::setPlaying(false);
1010 audioplay::destroy();
1011
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001012 return true;
Mathias Agopiana8826d62009-10-01 03:10:14 -07001013}
1014
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001015void BootAnimation::releaseAnimation(Animation* animation) const
1016{
1017 for (Vector<Animation::Part>::iterator it = animation->parts.begin(),
1018 e = animation->parts.end(); it != e; ++it) {
1019 if (it->animation)
1020 releaseAnimation(it->animation);
1021 }
1022 if (animation->zip)
1023 delete animation->zip;
1024 delete animation;
1025}
1026
1027BootAnimation::Animation* BootAnimation::loadAnimation(const String8& fn)
1028{
1029 if (mLoadedFiles.indexOf(fn) >= 0) {
1030 ALOGE("File \"%s\" is already loaded. Cyclic ref is not allowed",
1031 fn.string());
1032 return NULL;
1033 }
1034 ZipFileRO *zip = ZipFileRO::open(fn);
1035 if (zip == NULL) {
1036 ALOGE("Failed to open animation zip \"%s\": %s",
1037 fn.string(), strerror(errno));
1038 return NULL;
1039 }
1040
1041 Animation *animation = new Animation;
1042 animation->fileName = fn;
1043 animation->zip = zip;
Damien Bargiacchi0e3d2ab2016-08-29 04:11:19 -07001044 animation->clockFont.map = nullptr;
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001045 mLoadedFiles.add(animation->fileName);
1046
1047 parseAnimationDesc(*animation);
Geoffrey Pitscha91a2d72016-07-12 14:46:19 -04001048 if (!preloadZip(*animation)) {
1049 return NULL;
1050 }
1051
Andriy Naborskyy39218ba2015-08-16 21:32:50 -07001052
1053 mLoadedFiles.remove(fn);
1054 return animation;
1055}
Damien Bargiacchi97480862016-03-29 14:55:55 -07001056
Geoffrey Pitsch290c4352016-08-09 14:35:10 -04001057bool BootAnimation::playSoundsAllowed() const {
1058 // Only play sounds for system boots, not runtime restarts.
1059 if (!mSystemBoot) {
1060 return false;
1061 }
Keun-young Parkb5938422017-03-23 13:46:24 -07001062 if (mShuttingDown) { // no audio while shutting down
1063 return false;
1064 }
Geoffrey Pitsch290c4352016-08-09 14:35:10 -04001065 // Read the system property to see if we should play the sound.
1066 // If it's not present, default to allowed.
1067 if (!property_get_bool(PLAY_SOUND_PROP_NAME, 1)) {
1068 return false;
1069 }
1070
1071 // Don't play sounds if this is a reboot due to an error.
1072 char bootreason[PROPERTY_VALUE_MAX];
1073 if (property_get(BOOTREASON_PROP_NAME, bootreason, nullptr) > 0) {
1074 for (const auto& str : PLAY_SOUND_BOOTREASON_BLACKLIST) {
1075 if (strcasecmp(str.c_str(), bootreason) == 0) {
1076 return false;
1077 }
1078 }
1079 }
1080 return true;
1081}
1082
Damien Bargiacchi97480862016-03-29 14:55:55 -07001083bool BootAnimation::updateIsTimeAccurate() {
1084 static constexpr long long MAX_TIME_IN_PAST = 60000LL * 60LL * 24LL * 30LL; // 30 days
1085 static constexpr long long MAX_TIME_IN_FUTURE = 60000LL * 90LL; // 90 minutes
1086
1087 if (mTimeIsAccurate) {
1088 return true;
1089 }
Keun-young Parkb5938422017-03-23 13:46:24 -07001090 if (mShuttingDown) return true;
Damien Bargiacchi97480862016-03-29 14:55:55 -07001091 struct stat statResult;
Damien Bargiacchi9071db12016-10-28 17:38:22 -07001092
1093 if(stat(TIME_FORMAT_12_HOUR_FLAG_FILE_PATH, &statResult) == 0) {
1094 mTimeFormat12Hour = true;
1095 }
1096
Damien Bargiacchi97480862016-03-29 14:55:55 -07001097 if(stat(ACCURATE_TIME_FLAG_FILE_PATH, &statResult) == 0) {
1098 mTimeIsAccurate = true;
1099 return true;
1100 }
1101
1102 FILE* file = fopen(LAST_TIME_CHANGED_FILE_PATH, "r");
1103 if (file != NULL) {
1104 long long lastChangedTime = 0;
1105 fscanf(file, "%lld", &lastChangedTime);
1106 fclose(file);
1107 if (lastChangedTime > 0) {
1108 struct timespec now;
1109 clock_gettime(CLOCK_REALTIME, &now);
1110 // Match the Java timestamp format
1111 long long rtcNow = (now.tv_sec * 1000LL) + (now.tv_nsec / 1000000LL);
Damien Bargiacchi96762812016-07-12 15:53:40 -07001112 if (ACCURATE_TIME_EPOCH < rtcNow
1113 && lastChangedTime > (rtcNow - MAX_TIME_IN_PAST)
1114 && lastChangedTime < (rtcNow + MAX_TIME_IN_FUTURE)) {
Damien Bargiacchi97480862016-03-29 14:55:55 -07001115 mTimeIsAccurate = true;
1116 }
1117 }
1118 }
1119
1120 return mTimeIsAccurate;
1121}
1122
1123BootAnimation::TimeCheckThread::TimeCheckThread(BootAnimation* bootAnimation) : Thread(false),
1124 mInotifyFd(-1), mSystemWd(-1), mTimeWd(-1), mBootAnimation(bootAnimation) {}
1125
1126BootAnimation::TimeCheckThread::~TimeCheckThread() {
1127 // mInotifyFd may be -1 but that's ok since we're not at risk of attempting to close a valid FD.
1128 close(mInotifyFd);
1129}
1130
1131bool BootAnimation::TimeCheckThread::threadLoop() {
1132 bool shouldLoop = doThreadLoop() && !mBootAnimation->mTimeIsAccurate
1133 && mBootAnimation->mClockEnabled;
1134 if (!shouldLoop) {
1135 close(mInotifyFd);
1136 mInotifyFd = -1;
1137 }
1138 return shouldLoop;
1139}
1140
1141bool BootAnimation::TimeCheckThread::doThreadLoop() {
1142 static constexpr int BUFF_LEN (10 * (sizeof(struct inotify_event) + NAME_MAX + 1));
1143
1144 // Poll instead of doing a blocking read so the Thread can exit if requested.
1145 struct pollfd pfd = { mInotifyFd, POLLIN, 0 };
1146 ssize_t pollResult = poll(&pfd, 1, 1000);
1147
1148 if (pollResult == 0) {
1149 return true;
1150 } else if (pollResult < 0) {
1151 ALOGE("Could not poll inotify events");
1152 return false;
1153 }
1154
1155 char buff[BUFF_LEN] __attribute__ ((aligned(__alignof__(struct inotify_event))));;
1156 ssize_t length = read(mInotifyFd, buff, BUFF_LEN);
1157 if (length == 0) {
1158 return true;
1159 } else if (length < 0) {
1160 ALOGE("Could not read inotify events");
1161 return false;
1162 }
1163
1164 const struct inotify_event *event;
1165 for (char* ptr = buff; ptr < buff + length; ptr += sizeof(struct inotify_event) + event->len) {
1166 event = (const struct inotify_event *) ptr;
1167 if (event->wd == mSystemWd && strcmp(SYSTEM_TIME_DIR_NAME, event->name) == 0) {
1168 addTimeDirWatch();
1169 } else if (event->wd == mTimeWd && (strcmp(LAST_TIME_CHANGED_FILE_NAME, event->name) == 0
1170 || strcmp(ACCURATE_TIME_FLAG_FILE_NAME, event->name) == 0)) {
1171 return !mBootAnimation->updateIsTimeAccurate();
1172 }
1173 }
1174
1175 return true;
1176}
1177
1178void BootAnimation::TimeCheckThread::addTimeDirWatch() {
1179 mTimeWd = inotify_add_watch(mInotifyFd, SYSTEM_TIME_DIR_PATH,
1180 IN_CLOSE_WRITE | IN_MOVED_TO | IN_ATTRIB);
1181 if (mTimeWd > 0) {
1182 // No need to watch for the time directory to be created if it already exists
1183 inotify_rm_watch(mInotifyFd, mSystemWd);
1184 mSystemWd = -1;
1185 }
1186}
1187
1188status_t BootAnimation::TimeCheckThread::readyToRun() {
1189 mInotifyFd = inotify_init();
1190 if (mInotifyFd < 0) {
1191 ALOGE("Could not initialize inotify fd");
1192 return NO_INIT;
1193 }
1194
1195 mSystemWd = inotify_add_watch(mInotifyFd, SYSTEM_DATA_DIR_PATH, IN_CREATE | IN_ATTRIB);
1196 if (mSystemWd < 0) {
1197 close(mInotifyFd);
1198 mInotifyFd = -1;
1199 ALOGE("Could not add watch for %s", SYSTEM_DATA_DIR_PATH);
1200 return NO_INIT;
1201 }
1202
1203 addTimeDirWatch();
1204
1205 if (mBootAnimation->updateIsTimeAccurate()) {
1206 close(mInotifyFd);
1207 mInotifyFd = -1;
1208 return ALREADY_EXISTS;
1209 }
1210
1211 return NO_ERROR;
1212}
1213
Geoffrey Pitscha9173532016-07-19 14:56:39 -04001214BootAnimation::InitAudioThread::InitAudioThread(uint8_t* exampleAudioData, int exampleAudioLength)
1215 : Thread(false),
1216 mExampleAudioData(exampleAudioData),
1217 mExampleAudioLength(exampleAudioLength) {}
1218
1219bool BootAnimation::InitAudioThread::threadLoop() {
1220 audioplay::create(mExampleAudioData, mExampleAudioLength);
1221 // Exit immediately
1222 return false;
1223}
1224
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001225// ---------------------------------------------------------------------------
1226
1227}
1228; // namespace android