The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 17 | #define LOG_NDEBUG 0 |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 18 | #define LOG_TAG "BootAnimation" |
| 19 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | #include <stdint.h> |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 21 | #include <sys/inotify.h> |
| 22 | #include <sys/poll.h> |
| 23 | #include <sys/stat.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <sys/types.h> |
| 25 | #include <math.h> |
| 26 | #include <fcntl.h> |
| 27 | #include <utils/misc.h> |
Mathias Agopian | b4d5a72 | 2009-09-23 17:05:19 -0700 | [diff] [blame] | 28 | #include <signal.h> |
Elliott Hughes | bb94f31 | 2014-10-21 10:41:33 -0700 | [diff] [blame] | 29 | #include <time.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 31 | #include <cutils/properties.h> |
| 32 | |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 33 | #include <androidfw/AssetManager.h> |
Mathias Agopian | ac31a3b | 2009-05-21 19:59:24 -0700 | [diff] [blame] | 34 | #include <binder/IPCThreadState.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | #include <utils/Atomic.h> |
| 36 | #include <utils/Errors.h> |
| 37 | #include <utils/Log.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
| 39 | #include <ui/PixelFormat.h> |
| 40 | #include <ui/Rect.h> |
| 41 | #include <ui/Region.h> |
| 42 | #include <ui/DisplayInfo.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 44 | #include <gui/ISurfaceComposer.h> |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 45 | #include <gui/Surface.h> |
| 46 | #include <gui/SurfaceComposerClient.h> |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 47 | |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 48 | // TODO: Fix Skia. |
| 49 | #pragma GCC diagnostic push |
| 50 | #pragma GCC diagnostic ignored "-Wunused-parameter" |
Derek Sollenberger | eece0dd | 2014-02-27 14:31:29 -0500 | [diff] [blame] | 51 | #include <SkBitmap.h> |
Matt Sarett | 8898c16 | 2016-03-24 16:11:01 -0400 | [diff] [blame] | 52 | #include <SkImage.h> |
Derek Sollenberger | eece0dd | 2014-02-27 14:31:29 -0500 | [diff] [blame] | 53 | #include <SkStream.h> |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 54 | #pragma GCC diagnostic pop |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | |
| 56 | #include <GLES/gl.h> |
| 57 | #include <GLES/glext.h> |
| 58 | #include <EGL/eglext.h> |
| 59 | |
| 60 | #include "BootAnimation.h" |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 61 | #include "audioplay.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | |
| 63 | namespace android { |
| 64 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 65 | static const char OEM_BOOTANIMATION_FILE[] = "/oem/media/bootanimation.zip"; |
| 66 | static const char SYSTEM_BOOTANIMATION_FILE[] = "/system/media/bootanimation.zip"; |
| 67 | static const char SYSTEM_ENCRYPTED_BOOTANIMATION_FILE[] = "/system/media/bootanimation-encrypted.zip"; |
| 68 | static const char SYSTEM_DATA_DIR_PATH[] = "/data/system"; |
| 69 | static const char SYSTEM_TIME_DIR_NAME[] = "time"; |
| 70 | static const char SYSTEM_TIME_DIR_PATH[] = "/data/system/time"; |
| 71 | static const char LAST_TIME_CHANGED_FILE_NAME[] = "last_time_change"; |
| 72 | static const char LAST_TIME_CHANGED_FILE_PATH[] = "/data/system/time/last_time_change"; |
| 73 | static const char ACCURATE_TIME_FLAG_FILE_NAME[] = "time_is_accurate"; |
| 74 | static const char ACCURATE_TIME_FLAG_FILE_PATH[] = "/data/system/time/time_is_accurate"; |
Damien Bargiacchi | 9676281 | 2016-07-12 15:53:40 -0700 | [diff] [blame] | 75 | // Java timestamp format. Don't show the clock if the date is before 2000-01-01 00:00:00. |
| 76 | static const long long ACCURATE_TIME_EPOCH = 946684800000; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 77 | static const char EXIT_PROP_NAME[] = "service.bootanim.exit"; |
Geoffrey Pitsch | 3050879 | 2016-07-22 17:04:21 -0400 | [diff] [blame] | 78 | static const char PLAY_SOUND_PROP_NAME[] = "persist.sys.bootanim.play_sound"; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 79 | static const int ANIM_ENTRY_NAME_MAX = 256; |
Geoffrey Pitsch | 290c435 | 2016-08-09 14:35:10 -0400 | [diff] [blame] | 80 | static const char BOOT_COMPLETED_PROP_NAME[] = "sys.boot_completed"; |
| 81 | static const char BOOTREASON_PROP_NAME[] = "ro.boot.bootreason"; |
| 82 | // bootreasons list in "system/core/bootstat/bootstat.cpp". |
| 83 | static const std::vector<std::string> PLAY_SOUND_BOOTREASON_BLACKLIST { |
| 84 | "kernel_panic", |
| 85 | "Panic", |
| 86 | "Watchdog", |
| 87 | }; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 88 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | // --------------------------------------------------------------------------- |
| 90 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 91 | BootAnimation::BootAnimation() : Thread(false), mClockEnabled(true), mTimeIsAccurate(false), |
| 92 | mTimeCheckThread(NULL) { |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 93 | mSession = new SurfaceComposerClient(); |
Geoffrey Pitsch | 290c435 | 2016-08-09 14:35:10 -0400 | [diff] [blame] | 94 | |
| 95 | // If the system has already booted, the animation is not being used for a boot. |
| 96 | mSystemBoot = !property_get_bool(BOOT_COMPLETED_PROP_NAME, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 99 | BootAnimation::~BootAnimation() {} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | |
| 101 | void BootAnimation::onFirstRef() { |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 102 | status_t err = mSession->linkToComposerDeath(this); |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 103 | ALOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err)); |
Mathias Agopian | 8434c53 | 2009-09-23 18:52:49 -0700 | [diff] [blame] | 104 | if (err == NO_ERROR) { |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 105 | run("BootAnimation", PRIORITY_DISPLAY); |
| 106 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 109 | sp<SurfaceComposerClient> BootAnimation::session() const { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | return mSession; |
| 111 | } |
| 112 | |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 113 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 114 | void BootAnimation::binderDied(const wp<IBinder>&) |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 115 | { |
| 116 | // woah, surfaceflinger died! |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 117 | ALOGD("SurfaceFlinger died, exiting..."); |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 118 | |
| 119 | // calling requestExit() is not enough here because the Surface code |
| 120 | // might be blocked on a condition variable that will never be updated. |
| 121 | kill( getpid(), SIGKILL ); |
| 122 | requestExit(); |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 123 | audioplay::destroy(); |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 124 | } |
| 125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets, |
| 127 | const char* name) { |
| 128 | Asset* asset = assets.open(name, Asset::ACCESS_BUFFER); |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 129 | if (asset == NULL) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | return NO_INIT; |
| 131 | SkBitmap bitmap; |
Matt Sarett | 8898c16 | 2016-03-24 16:11:01 -0400 | [diff] [blame] | 132 | sk_sp<SkData> data = SkData::MakeWithoutCopy(asset->getBuffer(false), |
| 133 | asset->getLength()); |
| 134 | sk_sp<SkImage> image = SkImage::MakeFromEncoded(data); |
| 135 | image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | asset->close(); |
| 137 | delete asset; |
| 138 | |
| 139 | // ensure we can call getPixels(). No need to call unlock, since the |
| 140 | // bitmap will go out of scope when we return from this method. |
| 141 | bitmap.lockPixels(); |
| 142 | |
| 143 | const int w = bitmap.width(); |
| 144 | const int h = bitmap.height(); |
| 145 | const void* p = bitmap.getPixels(); |
| 146 | |
| 147 | GLint crop[4] = { 0, h, w, -h }; |
| 148 | texture->w = w; |
| 149 | texture->h = h; |
| 150 | |
| 151 | glGenTextures(1, &texture->name); |
| 152 | glBindTexture(GL_TEXTURE_2D, texture->name); |
| 153 | |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 154 | switch (bitmap.colorType()) { |
| 155 | case kAlpha_8_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, |
| 157 | GL_UNSIGNED_BYTE, p); |
| 158 | break; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 159 | case kARGB_4444_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
| 161 | GL_UNSIGNED_SHORT_4_4_4_4, p); |
| 162 | break; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 163 | case kN32_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
| 165 | GL_UNSIGNED_BYTE, p); |
| 166 | break; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 167 | case kRGB_565_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, |
| 169 | GL_UNSIGNED_SHORT_5_6_5, p); |
| 170 | break; |
| 171 | default: |
| 172 | break; |
| 173 | } |
| 174 | |
| 175 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 176 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 177 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 178 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 179 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 180 | return NO_ERROR; |
| 181 | } |
| 182 | |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 183 | status_t BootAnimation::initTexture(const Animation::Frame& frame) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 184 | { |
| 185 | //StopWatch watch("blah"); |
| 186 | |
| 187 | SkBitmap bitmap; |
Matt Sarett | 8898c16 | 2016-03-24 16:11:01 -0400 | [diff] [blame] | 188 | sk_sp<SkData> data = SkData::MakeWithoutCopy(frame.map->getDataPtr(), |
| 189 | frame.map->getDataLength()); |
| 190 | sk_sp<SkImage> image = SkImage::MakeFromEncoded(data); |
| 191 | image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 192 | |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 193 | // FileMap memory is never released until application exit. |
| 194 | // Release it now as the texture is already loaded and the memory used for |
| 195 | // the packed resource can be released. |
Narayan Kamath | 688ff4c | 2015-02-23 15:47:54 +0000 | [diff] [blame] | 196 | delete frame.map; |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 197 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 198 | // ensure we can call getPixels(). No need to call unlock, since the |
| 199 | // bitmap will go out of scope when we return from this method. |
| 200 | bitmap.lockPixels(); |
| 201 | |
| 202 | const int w = bitmap.width(); |
| 203 | const int h = bitmap.height(); |
| 204 | const void* p = bitmap.getPixels(); |
| 205 | |
| 206 | GLint crop[4] = { 0, h, w, -h }; |
| 207 | int tw = 1 << (31 - __builtin_clz(w)); |
| 208 | int th = 1 << (31 - __builtin_clz(h)); |
| 209 | if (tw < w) tw <<= 1; |
| 210 | if (th < h) th <<= 1; |
| 211 | |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 212 | switch (bitmap.colorType()) { |
| 213 | case kN32_SkColorType: |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 214 | if (!mUseNpotTextures && (tw != w || th != h)) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 215 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, |
| 216 | GL_UNSIGNED_BYTE, 0); |
| 217 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
| 218 | 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p); |
| 219 | } else { |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 220 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 221 | GL_UNSIGNED_BYTE, p); |
| 222 | } |
| 223 | break; |
| 224 | |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 225 | case kRGB_565_SkColorType: |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 226 | if (!mUseNpotTextures && (tw != w || th != h)) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 227 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB, |
| 228 | GL_UNSIGNED_SHORT_5_6_5, 0); |
| 229 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
| 230 | 0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p); |
| 231 | } else { |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 232 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 233 | GL_UNSIGNED_SHORT_5_6_5, p); |
| 234 | } |
| 235 | break; |
| 236 | default: |
| 237 | break; |
| 238 | } |
| 239 | |
| 240 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); |
| 241 | |
| 242 | return NO_ERROR; |
| 243 | } |
| 244 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | status_t BootAnimation::readyToRun() { |
| 246 | mAssets.addDefaultAssets(); |
| 247 | |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 248 | sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay( |
| 249 | ISurfaceComposer::eDisplayIdMain)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | DisplayInfo dinfo; |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 251 | status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | if (status) |
| 253 | return -1; |
| 254 | |
| 255 | // create the native surface |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 256 | sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"), |
| 257 | dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565); |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 258 | |
| 259 | SurfaceComposerClient::openGlobalTransaction(); |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 260 | control->setLayer(0x40000000); |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 261 | SurfaceComposerClient::closeGlobalTransaction(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 263 | sp<Surface> s = control->getSurface(); |
| 264 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | // initialize opengl and egl |
Mathias Agopian | 738b9a4 | 2009-08-06 16:41:02 -0700 | [diff] [blame] | 266 | const EGLint attribs[] = { |
Mathias Agopian | 1b253b7 | 2011-08-15 15:20:22 -0700 | [diff] [blame] | 267 | EGL_RED_SIZE, 8, |
| 268 | EGL_GREEN_SIZE, 8, |
| 269 | EGL_BLUE_SIZE, 8, |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 270 | EGL_DEPTH_SIZE, 0, |
| 271 | EGL_NONE |
Mathias Agopian | 738b9a4 | 2009-08-06 16:41:02 -0700 | [diff] [blame] | 272 | }; |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 273 | EGLint w, h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | EGLint numConfigs; |
| 275 | EGLConfig config; |
| 276 | EGLSurface surface; |
| 277 | EGLContext context; |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 280 | |
| 281 | eglInitialize(display, 0, 0); |
Mathias Agopian | 1b253b7 | 2011-08-15 15:20:22 -0700 | [diff] [blame] | 282 | eglChooseConfig(display, attribs, &config, 1, &numConfigs); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 283 | surface = eglCreateWindowSurface(display, config, s.get(), NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | context = eglCreateContext(display, config, NULL, NULL); |
| 285 | eglQuerySurface(display, surface, EGL_WIDTH, &w); |
| 286 | eglQuerySurface(display, surface, EGL_HEIGHT, &h); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 287 | |
Mathias Agopian | abac010 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 288 | if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) |
| 289 | return NO_INIT; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | mDisplay = display; |
| 292 | mContext = context; |
| 293 | mSurface = surface; |
| 294 | mWidth = w; |
| 295 | mHeight = h; |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 296 | mFlingerSurfaceControl = control; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | mFlingerSurface = s; |
| 298 | |
Elliott Hughes | c367d48 | 2013-10-29 13:12:55 -0700 | [diff] [blame] | 299 | // If the device has encryption turned on or is in process |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 300 | // of being encrypted we show the encrypted boot animation. |
| 301 | char decrypt[PROPERTY_VALUE_MAX]; |
| 302 | property_get("vold.decrypt", decrypt, ""); |
| 303 | |
| 304 | bool encryptedAnimation = atoi(decrypt) != 0 || !strcmp("trigger_restart_min_framework", decrypt); |
| 305 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 306 | if (encryptedAnimation && (access(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, R_OK) == 0)) { |
| 307 | mZipFileName = SYSTEM_ENCRYPTED_BOOTANIMATION_FILE; |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 308 | } |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 309 | else if (access(OEM_BOOTANIMATION_FILE, R_OK) == 0) { |
| 310 | mZipFileName = OEM_BOOTANIMATION_FILE; |
| 311 | } |
| 312 | else if (access(SYSTEM_BOOTANIMATION_FILE, R_OK) == 0) { |
| 313 | mZipFileName = SYSTEM_BOOTANIMATION_FILE; |
| 314 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | return NO_ERROR; |
| 316 | } |
| 317 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 318 | bool BootAnimation::threadLoop() |
| 319 | { |
| 320 | bool r; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 321 | // We have no bootanimation file, so we use the stock android logo |
| 322 | // animation. |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 323 | if (mZipFileName.isEmpty()) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 324 | r = android(); |
| 325 | } else { |
| 326 | r = movie(); |
| 327 | } |
| 328 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 330 | eglDestroyContext(mDisplay, mContext); |
| 331 | eglDestroySurface(mDisplay, mSurface); |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 332 | mFlingerSurface.clear(); |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 333 | mFlingerSurfaceControl.clear(); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 334 | eglTerminate(mDisplay); |
Sai Kiran Korwar | 3eee9fb | 2015-06-16 17:13:35 +0530 | [diff] [blame] | 335 | eglReleaseThread(); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 336 | IPCThreadState::self()->stopProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | return r; |
| 338 | } |
| 339 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 340 | bool BootAnimation::android() |
| 341 | { |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 342 | initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png"); |
| 343 | initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | |
| 345 | // clear screen |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 346 | glShadeModel(GL_FLAT); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 347 | glDisable(GL_DITHER); |
| 348 | glDisable(GL_SCISSOR_TEST); |
Mathias Agopian | 59f19e4 | 2011-05-06 19:22:12 -0700 | [diff] [blame] | 349 | glClearColor(0,0,0,1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | glClear(GL_COLOR_BUFFER_BIT); |
| 351 | eglSwapBuffers(mDisplay, mSurface); |
| 352 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 353 | glEnable(GL_TEXTURE_2D); |
| 354 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 355 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 356 | const GLint xc = (mWidth - mAndroid[0].w) / 2; |
| 357 | const GLint yc = (mHeight - mAndroid[0].h) / 2; |
| 358 | const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(), |
| 361 | updateRect.height()); |
| 362 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 363 | // Blend state |
| 364 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 365 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | const nsecs_t startTime = systemTime(); |
| 368 | do { |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 369 | nsecs_t now = systemTime(); |
| 370 | double time = now - startTime; |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 371 | float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w; |
| 372 | GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w; |
| 373 | GLint x = xc - offset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 374 | |
Mathias Agopian | 8166864 | 2009-07-28 11:41:30 -0700 | [diff] [blame] | 375 | glDisable(GL_SCISSOR_TEST); |
| 376 | glClear(GL_COLOR_BUFFER_BIT); |
| 377 | |
| 378 | glEnable(GL_SCISSOR_TEST); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | glDisable(GL_BLEND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | glBindTexture(GL_TEXTURE_2D, mAndroid[1].name); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 381 | glDrawTexiOES(x, yc, 0, mAndroid[1].w, mAndroid[1].h); |
| 382 | glDrawTexiOES(x + mAndroid[1].w, yc, 0, mAndroid[1].w, mAndroid[1].h); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 384 | glEnable(GL_BLEND); |
| 385 | glBindTexture(GL_TEXTURE_2D, mAndroid[0].name); |
| 386 | glDrawTexiOES(xc, yc, 0, mAndroid[0].w, mAndroid[0].h); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 387 | |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 388 | EGLBoolean res = eglSwapBuffers(mDisplay, mSurface); |
| 389 | if (res == EGL_FALSE) |
| 390 | break; |
| 391 | |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 392 | // 12fps: don't animate too fast to preserve CPU |
| 393 | const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now); |
| 394 | if (sleepTime > 0) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 395 | usleep(sleepTime); |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 396 | |
| 397 | checkExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | } while (!exitPending()); |
| 399 | |
| 400 | glDeleteTextures(1, &mAndroid[0].name); |
| 401 | glDeleteTextures(1, &mAndroid[1].name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | return false; |
| 403 | } |
| 404 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 405 | |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 406 | void BootAnimation::checkExit() { |
| 407 | // Allow surface flinger to gracefully request shutdown |
| 408 | char value[PROPERTY_VALUE_MAX]; |
| 409 | property_get(EXIT_PROP_NAME, value, "0"); |
| 410 | int exitnow = atoi(value); |
| 411 | if (exitnow) { |
| 412 | requestExit(); |
| 413 | } |
| 414 | } |
| 415 | |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 416 | // Parse a color represented as an HTML-style 'RRGGBB' string: each pair of |
| 417 | // characters in str is a hex number in [0, 255], which are converted to |
| 418 | // floating point values in the range [0.0, 1.0] and placed in the |
| 419 | // corresponding elements of color. |
| 420 | // |
| 421 | // If the input string isn't valid, parseColor returns false and color is |
| 422 | // left unchanged. |
| 423 | static bool parseColor(const char str[7], float color[3]) { |
| 424 | float tmpColor[3]; |
| 425 | for (int i = 0; i < 3; i++) { |
| 426 | int val = 0; |
| 427 | for (int j = 0; j < 2; j++) { |
| 428 | val *= 16; |
| 429 | char c = str[2*i + j]; |
| 430 | if (c >= '0' && c <= '9') val += c - '0'; |
| 431 | else if (c >= 'A' && c <= 'F') val += (c - 'A') + 10; |
| 432 | else if (c >= 'a' && c <= 'f') val += (c - 'a') + 10; |
| 433 | else return false; |
| 434 | } |
| 435 | tmpColor[i] = static_cast<float>(val) / 255.0f; |
| 436 | } |
| 437 | memcpy(color, tmpColor, sizeof(tmpColor)); |
| 438 | return true; |
| 439 | } |
| 440 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 441 | |
| 442 | static bool readFile(ZipFileRO* zip, const char* name, String8& outString) |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 443 | { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 444 | ZipEntryRO entry = zip->findEntryByName(name); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 445 | ALOGE_IF(!entry, "couldn't find %s", name); |
| 446 | if (!entry) { |
| 447 | return false; |
| 448 | } |
| 449 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 450 | FileMap* entryMap = zip->createEntryFileMap(entry); |
| 451 | zip->releaseEntry(entry); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 452 | ALOGE_IF(!entryMap, "entryMap is null"); |
| 453 | if (!entryMap) { |
| 454 | return false; |
| 455 | } |
| 456 | |
| 457 | outString.setTo((char const*)entryMap->getDataPtr(), entryMap->getDataLength()); |
Narayan Kamath | 688ff4c | 2015-02-23 15:47:54 +0000 | [diff] [blame] | 458 | delete entryMap; |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 459 | return true; |
| 460 | } |
| 461 | |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 462 | // The time glyphs are stored in a single image of height 64 pixels. Each digit is 40 pixels wide, |
| 463 | // and the colon character is half that at 20 pixels. The glyph order is '0123456789:'. |
| 464 | // We render 24 hour time. |
| 465 | void BootAnimation::drawTime(const Texture& clockTex, const int yPos) { |
| 466 | static constexpr char TIME_FORMAT[] = "%H:%M"; |
| 467 | static constexpr int TIME_LENGTH = sizeof(TIME_FORMAT); |
| 468 | |
| 469 | static constexpr int DIGIT_HEIGHT = 64; |
| 470 | static constexpr int DIGIT_WIDTH = 40; |
| 471 | static constexpr int COLON_WIDTH = DIGIT_WIDTH / 2; |
| 472 | static constexpr int TIME_WIDTH = (DIGIT_WIDTH * 4) + COLON_WIDTH; |
| 473 | |
| 474 | if (clockTex.h < DIGIT_HEIGHT || clockTex.w < (10 * DIGIT_WIDTH + COLON_WIDTH)) { |
| 475 | ALOGE("Clock texture is too small; abandoning boot animation clock"); |
| 476 | mClockEnabled = false; |
| 477 | return; |
| 478 | } |
| 479 | |
| 480 | time_t rawtime; |
| 481 | time(&rawtime); |
| 482 | struct tm* timeInfo = localtime(&rawtime); |
| 483 | |
| 484 | char timeBuff[TIME_LENGTH]; |
| 485 | size_t length = strftime(timeBuff, TIME_LENGTH, TIME_FORMAT, timeInfo); |
| 486 | |
| 487 | if (length != TIME_LENGTH - 1) { |
| 488 | ALOGE("Couldn't format time; abandoning boot animation clock"); |
| 489 | mClockEnabled = false; |
| 490 | return; |
| 491 | } |
| 492 | |
| 493 | glEnable(GL_BLEND); // Allow us to draw on top of the animation |
| 494 | glBindTexture(GL_TEXTURE_2D, clockTex.name); |
| 495 | |
| 496 | int xPos = (mWidth - TIME_WIDTH) / 2; |
| 497 | int cropRect[4] = { 0, DIGIT_HEIGHT, DIGIT_WIDTH, -DIGIT_HEIGHT }; |
| 498 | |
| 499 | for (int i = 0; i < TIME_LENGTH - 1; i++) { |
| 500 | char c = timeBuff[i]; |
| 501 | int width = DIGIT_WIDTH; |
| 502 | int pos = c - '0'; // Position in the character list |
| 503 | if (pos < 0 || pos > 10) { |
| 504 | continue; |
| 505 | } |
| 506 | if (c == ':') { |
| 507 | width = COLON_WIDTH; |
| 508 | } |
| 509 | |
| 510 | // Crop the texture to only the pixels in the current glyph |
| 511 | int left = pos * DIGIT_WIDTH; |
| 512 | cropRect[0] = left; |
| 513 | cropRect[2] = width; |
| 514 | glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect); |
| 515 | |
| 516 | glDrawTexiOES(xPos, yPos, 0, width, DIGIT_HEIGHT); |
| 517 | |
| 518 | xPos += width; |
| 519 | } |
| 520 | |
| 521 | glDisable(GL_BLEND); // Return to the animation's default behaviour |
| 522 | glBindTexture(GL_TEXTURE_2D, 0); |
| 523 | } |
| 524 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 525 | bool BootAnimation::parseAnimationDesc(Animation& animation) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 526 | { |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 527 | String8 desString; |
| 528 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 529 | if (!readFile(animation.zip, "desc.txt", desString)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 530 | return false; |
| 531 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 532 | char const* s = desString.string(); |
| 533 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 534 | // Parse the description file |
| 535 | for (;;) { |
| 536 | const char* endl = strstr(s, "\n"); |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 537 | if (endl == NULL) break; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 538 | String8 line(s, endl - s); |
| 539 | const char* l = line.string(); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 540 | int fps = 0; |
| 541 | int width = 0; |
| 542 | int height = 0; |
| 543 | int count = 0; |
| 544 | int pause = 0; |
| 545 | int clockPosY = -1; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 546 | char path[ANIM_ENTRY_NAME_MAX]; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 547 | char color[7] = "000000"; // default to black if unspecified |
| 548 | |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 549 | char pathType; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 550 | if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) { |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 551 | // ALOGD("> w=%d, h=%d, fps=%d", width, height, fps); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 552 | animation.width = width; |
| 553 | animation.height = height; |
| 554 | animation.fps = fps; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 555 | } else if (sscanf(l, " %c %d %d %s #%6s %d", |
| 556 | &pathType, &count, &pause, path, color, &clockPosY) >= 4) { |
| 557 | // ALOGD("> type=%c, count=%d, pause=%d, path=%s, color=%s, clockPosY=%d", pathType, count, pause, path, color, clockPosY); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 558 | Animation::Part part; |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 559 | part.playUntilComplete = pathType == 'c'; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 560 | part.count = count; |
| 561 | part.pause = pause; |
| 562 | part.path = path; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 563 | part.clockPosY = clockPosY; |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 564 | part.audioData = NULL; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 565 | part.animation = NULL; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 566 | if (!parseColor(color, part.backgroundColor)) { |
| 567 | ALOGE("> invalid color '#%s'", color); |
| 568 | part.backgroundColor[0] = 0.0f; |
| 569 | part.backgroundColor[1] = 0.0f; |
| 570 | part.backgroundColor[2] = 0.0f; |
| 571 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 572 | animation.parts.add(part); |
| 573 | } |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 574 | else if (strcmp(l, "$SYSTEM") == 0) { |
| 575 | // ALOGD("> SYSTEM"); |
| 576 | Animation::Part part; |
| 577 | part.playUntilComplete = false; |
| 578 | part.count = 1; |
| 579 | part.pause = 0; |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 580 | part.audioData = NULL; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 581 | part.animation = loadAnimation(String8(SYSTEM_BOOTANIMATION_FILE)); |
| 582 | if (part.animation != NULL) |
| 583 | animation.parts.add(part); |
| 584 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 585 | s = ++endl; |
| 586 | } |
| 587 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 588 | return true; |
| 589 | } |
| 590 | |
| 591 | bool BootAnimation::preloadZip(Animation& animation) |
| 592 | { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 593 | // read all the data structures |
| 594 | const size_t pcount = animation.parts.size(); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 595 | void *cookie = NULL; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 596 | ZipFileRO* zip = animation.zip; |
| 597 | if (!zip->startIteration(&cookie)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 598 | return false; |
| 599 | } |
| 600 | |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 601 | Animation::Part* partWithAudio = NULL; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 602 | ZipEntryRO entry; |
| 603 | char name[ANIM_ENTRY_NAME_MAX]; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 604 | while ((entry = zip->nextEntry(cookie)) != NULL) { |
| 605 | const int foundEntryName = zip->getEntryFileName(entry, name, ANIM_ENTRY_NAME_MAX); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 606 | if (foundEntryName > ANIM_ENTRY_NAME_MAX || foundEntryName == -1) { |
| 607 | ALOGE("Error fetching entry file name"); |
| 608 | continue; |
| 609 | } |
| 610 | |
| 611 | const String8 entryName(name); |
| 612 | const String8 path(entryName.getPathDir()); |
| 613 | const String8 leaf(entryName.getPathLeaf()); |
| 614 | if (leaf.size() > 0) { |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 615 | for (size_t j = 0; j < pcount; j++) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 616 | if (path == animation.parts[j].path) { |
Narayan Kamath | 4600dd0 | 2015-06-16 12:02:57 +0100 | [diff] [blame] | 617 | uint16_t method; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 618 | // supports only stored png files |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 619 | if (zip->getEntryInfo(entry, &method, NULL, NULL, NULL, NULL, NULL)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 620 | if (method == ZipFileRO::kCompressStored) { |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 621 | FileMap* map = zip->createEntryFileMap(entry); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 622 | if (map) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 623 | Animation::Part& part(animation.parts.editItemAt(j)); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 624 | if (leaf == "audio.wav") { |
| 625 | // a part may have at most one audio file |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 626 | part.audioData = (uint8_t *)map->getDataPtr(); |
| 627 | part.audioLength = map->getDataLength(); |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 628 | partWithAudio = ∂ |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 629 | } else if (leaf == "trim.txt") { |
| 630 | part.trimData.setTo((char const*)map->getDataPtr(), |
| 631 | map->getDataLength()); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 632 | } else { |
| 633 | Animation::Frame frame; |
| 634 | frame.name = leaf; |
| 635 | frame.map = map; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 636 | frame.trimWidth = animation.width; |
| 637 | frame.trimHeight = animation.height; |
| 638 | frame.trimX = 0; |
| 639 | frame.trimY = 0; |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 640 | part.frames.add(frame); |
| 641 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 642 | } |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 643 | } else { |
| 644 | ALOGE("bootanimation.zip is compressed; must be only stored"); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 652 | // If there is trimData present, override the positioning defaults. |
| 653 | for (Animation::Part& part : animation.parts) { |
| 654 | const char* trimDataStr = part.trimData.string(); |
| 655 | for (size_t frameIdx = 0; frameIdx < part.frames.size(); frameIdx++) { |
| 656 | const char* endl = strstr(trimDataStr, "\n"); |
| 657 | // No more trimData for this part. |
| 658 | if (endl == NULL) { |
| 659 | break; |
| 660 | } |
| 661 | String8 line(trimDataStr, endl - trimDataStr); |
| 662 | const char* lineStr = line.string(); |
| 663 | trimDataStr = ++endl; |
| 664 | int width = 0, height = 0, x = 0, y = 0; |
| 665 | if (sscanf(lineStr, "%dx%d+%d+%d", &width, &height, &x, &y) == 4) { |
| 666 | Animation::Frame& frame(part.frames.editItemAt(frameIdx)); |
| 667 | frame.trimWidth = width; |
| 668 | frame.trimHeight = height; |
| 669 | frame.trimX = x; |
| 670 | frame.trimY = y; |
| 671 | } else { |
| 672 | ALOGE("Error parsing trim.txt, line: %s", lineStr); |
| 673 | break; |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 678 | // Create and initialize audioplay if there is a wav file in any of the animations. |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 679 | if (partWithAudio != NULL) { |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 680 | ALOGD("found audio.wav, creating playback engine"); |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 681 | if (!audioplay::create(partWithAudio->audioData, partWithAudio->audioLength)) { |
| 682 | return false; |
| 683 | } |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 686 | zip->endIteration(cookie); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 687 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 688 | return true; |
| 689 | } |
| 690 | |
| 691 | bool BootAnimation::movie() |
| 692 | { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 693 | Animation* animation = loadAnimation(mZipFileName); |
| 694 | if (animation == NULL) |
| 695 | return false; |
| 696 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 697 | bool anyPartHasClock = false; |
| 698 | for (size_t i=0; i < animation->parts.size(); i++) { |
| 699 | if(animation->parts[i].clockPosY >= 0) { |
| 700 | anyPartHasClock = true; |
| 701 | break; |
| 702 | } |
| 703 | } |
| 704 | if (!anyPartHasClock) { |
| 705 | mClockEnabled = false; |
| 706 | } |
| 707 | |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 708 | // Check if npot textures are supported |
| 709 | mUseNpotTextures = false; |
| 710 | String8 gl_extensions; |
| 711 | const char* exts = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); |
| 712 | if (!exts) { |
| 713 | glGetError(); |
| 714 | } else { |
| 715 | gl_extensions.setTo(exts); |
| 716 | if ((gl_extensions.find("GL_ARB_texture_non_power_of_two") != -1) || |
| 717 | (gl_extensions.find("GL_OES_texture_npot") != -1)) { |
| 718 | mUseNpotTextures = true; |
| 719 | } |
| 720 | } |
| 721 | |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 722 | // Blend required to draw time on top of animation frames. |
| 723 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 724 | glShadeModel(GL_FLAT); |
| 725 | glDisable(GL_DITHER); |
| 726 | glDisable(GL_SCISSOR_TEST); |
| 727 | glDisable(GL_BLEND); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 728 | |
| 729 | glBindTexture(GL_TEXTURE_2D, 0); |
| 730 | glEnable(GL_TEXTURE_2D); |
| 731 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 732 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
| 733 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); |
| 734 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 735 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 736 | |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 737 | bool clockTextureInitialized = false; |
| 738 | if (mClockEnabled) { |
| 739 | clockTextureInitialized = (initTexture(&mClock, mAssets, "images/clock64.png") == NO_ERROR); |
| 740 | mClockEnabled = clockTextureInitialized; |
| 741 | } |
| 742 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 743 | if (mClockEnabled && !updateIsTimeAccurate()) { |
| 744 | mTimeCheckThread = new TimeCheckThread(this); |
| 745 | mTimeCheckThread->run("BootAnimation::TimeCheckThread", PRIORITY_NORMAL); |
| 746 | } |
| 747 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 748 | playAnimation(*animation); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 749 | |
| 750 | if (mTimeCheckThread != NULL) { |
| 751 | mTimeCheckThread->requestExit(); |
| 752 | mTimeCheckThread = NULL; |
| 753 | } |
| 754 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 755 | releaseAnimation(animation); |
| 756 | |
Andriy Naborskyy | 815e51d | 2016-03-24 16:43:34 -0700 | [diff] [blame] | 757 | if (clockTextureInitialized) { |
| 758 | glDeleteTextures(1, &mClock.name); |
| 759 | } |
| 760 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 761 | return false; |
| 762 | } |
| 763 | |
| 764 | bool BootAnimation::playAnimation(const Animation& animation) |
| 765 | { |
| 766 | const size_t pcount = animation.parts.size(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 767 | nsecs_t frameDuration = s2ns(1) / animation.fps; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 768 | const int animationX = (mWidth - animation.width) / 2; |
| 769 | const int animationY = (mHeight - animation.height) / 2; |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 770 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 771 | for (size_t i=0 ; i<pcount ; i++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 772 | const Animation::Part& part(animation.parts[i]); |
| 773 | const size_t fcount = part.frames.size(); |
| 774 | glBindTexture(GL_TEXTURE_2D, 0); |
| 775 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 776 | // Handle animation package |
| 777 | if (part.animation != NULL) { |
| 778 | playAnimation(*part.animation); |
| 779 | if (exitPending()) |
| 780 | break; |
| 781 | continue; //to next part |
| 782 | } |
| 783 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 784 | for (int r=0 ; !part.count || r<part.count ; r++) { |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 785 | // Exit any non playuntil complete parts immediately |
| 786 | if(exitPending() && !part.playUntilComplete) |
| 787 | break; |
| 788 | |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 789 | // only play audio file the first time we animate the part |
Geoffrey Pitsch | 290c435 | 2016-08-09 14:35:10 -0400 | [diff] [blame] | 790 | if (r == 0 && part.audioData && playSoundsAllowed()) { |
| 791 | ALOGD("playing clip for part%d, size=%d", (int) i, part.audioLength); |
| 792 | audioplay::playClip(part.audioData, part.audioLength); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 793 | } |
| 794 | |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 795 | glClearColor( |
| 796 | part.backgroundColor[0], |
| 797 | part.backgroundColor[1], |
| 798 | part.backgroundColor[2], |
| 799 | 1.0f); |
| 800 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 801 | for (size_t j=0 ; j<fcount && (!exitPending() || part.playUntilComplete) ; j++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 802 | const Animation::Frame& frame(part.frames[j]); |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 803 | nsecs_t lastFrame = systemTime(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 804 | |
| 805 | if (r > 0) { |
| 806 | glBindTexture(GL_TEXTURE_2D, frame.tid); |
| 807 | } else { |
| 808 | if (part.count != 1) { |
| 809 | glGenTextures(1, &frame.tid); |
| 810 | glBindTexture(GL_TEXTURE_2D, frame.tid); |
| 811 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 812 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 813 | } |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 814 | initTexture(frame); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 817 | const int xc = animationX + frame.trimX; |
| 818 | const int yc = animationY + frame.trimY; |
| 819 | Region clearReg(Rect(mWidth, mHeight)); |
| 820 | clearReg.subtractSelf(Rect(xc, yc, xc+frame.trimWidth, yc+frame.trimHeight)); |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 821 | if (!clearReg.isEmpty()) { |
| 822 | Region::const_iterator head(clearReg.begin()); |
| 823 | Region::const_iterator tail(clearReg.end()); |
| 824 | glEnable(GL_SCISSOR_TEST); |
| 825 | while (head != tail) { |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 826 | const Rect& r2(*head++); |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 827 | glScissor(r2.left, mHeight - r2.bottom, r2.width(), r2.height()); |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 828 | glClear(GL_COLOR_BUFFER_BIT); |
| 829 | } |
| 830 | glDisable(GL_SCISSOR_TEST); |
| 831 | } |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 832 | // specify the y center as ceiling((mHeight - frame.trimHeight) / 2) |
| 833 | // which is equivalent to mHeight - (yc + frame.trimHeight) |
| 834 | glDrawTexiOES(xc, mHeight - (yc + frame.trimHeight), |
| 835 | 0, frame.trimWidth, frame.trimHeight); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 836 | if (mClockEnabled && mTimeIsAccurate && part.clockPosY >= 0) { |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 837 | drawTime(mClock, part.clockPosY); |
| 838 | } |
| 839 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 840 | eglSwapBuffers(mDisplay, mSurface); |
| 841 | |
| 842 | nsecs_t now = systemTime(); |
| 843 | nsecs_t delay = frameDuration - (now - lastFrame); |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 844 | //ALOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay)); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 845 | lastFrame = now; |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 846 | |
| 847 | if (delay > 0) { |
| 848 | struct timespec spec; |
| 849 | spec.tv_sec = (now + delay) / 1000000000; |
| 850 | spec.tv_nsec = (now + delay) % 1000000000; |
| 851 | int err; |
| 852 | do { |
| 853 | err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, NULL); |
| 854 | } while (err<0 && errno == EINTR); |
| 855 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 856 | |
| 857 | checkExit(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 858 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 859 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 860 | usleep(part.pause * ns2us(frameDuration)); |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 861 | |
| 862 | // For infinite parts, we've now played them at least once, so perhaps exit |
| 863 | if(exitPending() && !part.count) |
| 864 | break; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Geoffrey Pitsch | 2fb30fb | 2016-07-06 16:16:20 -0400 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | // Free textures created for looping parts now that the animation is done. |
| 870 | for (const Animation::Part& part : animation.parts) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 871 | if (part.count != 1) { |
Geoffrey Pitsch | 2fb30fb | 2016-07-06 16:16:20 -0400 | [diff] [blame] | 872 | const size_t fcount = part.frames.size(); |
| 873 | for (size_t j = 0; j < fcount; j++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 874 | const Animation::Frame& frame(part.frames[j]); |
| 875 | glDeleteTextures(1, &frame.tid); |
| 876 | } |
| 877 | } |
| 878 | } |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 879 | |
| 880 | // we've finally played everything we're going to play |
| 881 | audioplay::setPlaying(false); |
| 882 | audioplay::destroy(); |
| 883 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 884 | return true; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 887 | void BootAnimation::releaseAnimation(Animation* animation) const |
| 888 | { |
| 889 | for (Vector<Animation::Part>::iterator it = animation->parts.begin(), |
| 890 | e = animation->parts.end(); it != e; ++it) { |
| 891 | if (it->animation) |
| 892 | releaseAnimation(it->animation); |
| 893 | } |
| 894 | if (animation->zip) |
| 895 | delete animation->zip; |
| 896 | delete animation; |
| 897 | } |
| 898 | |
| 899 | BootAnimation::Animation* BootAnimation::loadAnimation(const String8& fn) |
| 900 | { |
| 901 | if (mLoadedFiles.indexOf(fn) >= 0) { |
| 902 | ALOGE("File \"%s\" is already loaded. Cyclic ref is not allowed", |
| 903 | fn.string()); |
| 904 | return NULL; |
| 905 | } |
| 906 | ZipFileRO *zip = ZipFileRO::open(fn); |
| 907 | if (zip == NULL) { |
| 908 | ALOGE("Failed to open animation zip \"%s\": %s", |
| 909 | fn.string(), strerror(errno)); |
| 910 | return NULL; |
| 911 | } |
| 912 | |
| 913 | Animation *animation = new Animation; |
| 914 | animation->fileName = fn; |
| 915 | animation->zip = zip; |
| 916 | mLoadedFiles.add(animation->fileName); |
| 917 | |
| 918 | parseAnimationDesc(*animation); |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 919 | if (!preloadZip(*animation)) { |
| 920 | return NULL; |
| 921 | } |
| 922 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 923 | |
| 924 | mLoadedFiles.remove(fn); |
| 925 | return animation; |
| 926 | } |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 927 | |
Geoffrey Pitsch | 290c435 | 2016-08-09 14:35:10 -0400 | [diff] [blame] | 928 | bool BootAnimation::playSoundsAllowed() const { |
| 929 | // Only play sounds for system boots, not runtime restarts. |
| 930 | if (!mSystemBoot) { |
| 931 | return false; |
| 932 | } |
| 933 | |
| 934 | // Read the system property to see if we should play the sound. |
| 935 | // If it's not present, default to allowed. |
| 936 | if (!property_get_bool(PLAY_SOUND_PROP_NAME, 1)) { |
| 937 | return false; |
| 938 | } |
| 939 | |
| 940 | // Don't play sounds if this is a reboot due to an error. |
| 941 | char bootreason[PROPERTY_VALUE_MAX]; |
| 942 | if (property_get(BOOTREASON_PROP_NAME, bootreason, nullptr) > 0) { |
| 943 | for (const auto& str : PLAY_SOUND_BOOTREASON_BLACKLIST) { |
| 944 | if (strcasecmp(str.c_str(), bootreason) == 0) { |
| 945 | return false; |
| 946 | } |
| 947 | } |
| 948 | } |
| 949 | return true; |
| 950 | } |
| 951 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 952 | bool BootAnimation::updateIsTimeAccurate() { |
| 953 | static constexpr long long MAX_TIME_IN_PAST = 60000LL * 60LL * 24LL * 30LL; // 30 days |
| 954 | static constexpr long long MAX_TIME_IN_FUTURE = 60000LL * 90LL; // 90 minutes |
| 955 | |
| 956 | if (mTimeIsAccurate) { |
| 957 | return true; |
| 958 | } |
| 959 | |
| 960 | struct stat statResult; |
| 961 | if(stat(ACCURATE_TIME_FLAG_FILE_PATH, &statResult) == 0) { |
| 962 | mTimeIsAccurate = true; |
| 963 | return true; |
| 964 | } |
| 965 | |
| 966 | FILE* file = fopen(LAST_TIME_CHANGED_FILE_PATH, "r"); |
| 967 | if (file != NULL) { |
| 968 | long long lastChangedTime = 0; |
| 969 | fscanf(file, "%lld", &lastChangedTime); |
| 970 | fclose(file); |
| 971 | if (lastChangedTime > 0) { |
| 972 | struct timespec now; |
| 973 | clock_gettime(CLOCK_REALTIME, &now); |
| 974 | // Match the Java timestamp format |
| 975 | long long rtcNow = (now.tv_sec * 1000LL) + (now.tv_nsec / 1000000LL); |
Damien Bargiacchi | 9676281 | 2016-07-12 15:53:40 -0700 | [diff] [blame] | 976 | if (ACCURATE_TIME_EPOCH < rtcNow |
| 977 | && lastChangedTime > (rtcNow - MAX_TIME_IN_PAST) |
| 978 | && lastChangedTime < (rtcNow + MAX_TIME_IN_FUTURE)) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 979 | mTimeIsAccurate = true; |
| 980 | } |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | return mTimeIsAccurate; |
| 985 | } |
| 986 | |
| 987 | BootAnimation::TimeCheckThread::TimeCheckThread(BootAnimation* bootAnimation) : Thread(false), |
| 988 | mInotifyFd(-1), mSystemWd(-1), mTimeWd(-1), mBootAnimation(bootAnimation) {} |
| 989 | |
| 990 | BootAnimation::TimeCheckThread::~TimeCheckThread() { |
| 991 | // mInotifyFd may be -1 but that's ok since we're not at risk of attempting to close a valid FD. |
| 992 | close(mInotifyFd); |
| 993 | } |
| 994 | |
| 995 | bool BootAnimation::TimeCheckThread::threadLoop() { |
| 996 | bool shouldLoop = doThreadLoop() && !mBootAnimation->mTimeIsAccurate |
| 997 | && mBootAnimation->mClockEnabled; |
| 998 | if (!shouldLoop) { |
| 999 | close(mInotifyFd); |
| 1000 | mInotifyFd = -1; |
| 1001 | } |
| 1002 | return shouldLoop; |
| 1003 | } |
| 1004 | |
| 1005 | bool BootAnimation::TimeCheckThread::doThreadLoop() { |
| 1006 | static constexpr int BUFF_LEN (10 * (sizeof(struct inotify_event) + NAME_MAX + 1)); |
| 1007 | |
| 1008 | // Poll instead of doing a blocking read so the Thread can exit if requested. |
| 1009 | struct pollfd pfd = { mInotifyFd, POLLIN, 0 }; |
| 1010 | ssize_t pollResult = poll(&pfd, 1, 1000); |
| 1011 | |
| 1012 | if (pollResult == 0) { |
| 1013 | return true; |
| 1014 | } else if (pollResult < 0) { |
| 1015 | ALOGE("Could not poll inotify events"); |
| 1016 | return false; |
| 1017 | } |
| 1018 | |
| 1019 | char buff[BUFF_LEN] __attribute__ ((aligned(__alignof__(struct inotify_event))));; |
| 1020 | ssize_t length = read(mInotifyFd, buff, BUFF_LEN); |
| 1021 | if (length == 0) { |
| 1022 | return true; |
| 1023 | } else if (length < 0) { |
| 1024 | ALOGE("Could not read inotify events"); |
| 1025 | return false; |
| 1026 | } |
| 1027 | |
| 1028 | const struct inotify_event *event; |
| 1029 | for (char* ptr = buff; ptr < buff + length; ptr += sizeof(struct inotify_event) + event->len) { |
| 1030 | event = (const struct inotify_event *) ptr; |
| 1031 | if (event->wd == mSystemWd && strcmp(SYSTEM_TIME_DIR_NAME, event->name) == 0) { |
| 1032 | addTimeDirWatch(); |
| 1033 | } else if (event->wd == mTimeWd && (strcmp(LAST_TIME_CHANGED_FILE_NAME, event->name) == 0 |
| 1034 | || strcmp(ACCURATE_TIME_FLAG_FILE_NAME, event->name) == 0)) { |
| 1035 | return !mBootAnimation->updateIsTimeAccurate(); |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | return true; |
| 1040 | } |
| 1041 | |
| 1042 | void BootAnimation::TimeCheckThread::addTimeDirWatch() { |
| 1043 | mTimeWd = inotify_add_watch(mInotifyFd, SYSTEM_TIME_DIR_PATH, |
| 1044 | IN_CLOSE_WRITE | IN_MOVED_TO | IN_ATTRIB); |
| 1045 | if (mTimeWd > 0) { |
| 1046 | // No need to watch for the time directory to be created if it already exists |
| 1047 | inotify_rm_watch(mInotifyFd, mSystemWd); |
| 1048 | mSystemWd = -1; |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | status_t BootAnimation::TimeCheckThread::readyToRun() { |
| 1053 | mInotifyFd = inotify_init(); |
| 1054 | if (mInotifyFd < 0) { |
| 1055 | ALOGE("Could not initialize inotify fd"); |
| 1056 | return NO_INIT; |
| 1057 | } |
| 1058 | |
| 1059 | mSystemWd = inotify_add_watch(mInotifyFd, SYSTEM_DATA_DIR_PATH, IN_CREATE | IN_ATTRIB); |
| 1060 | if (mSystemWd < 0) { |
| 1061 | close(mInotifyFd); |
| 1062 | mInotifyFd = -1; |
| 1063 | ALOGE("Could not add watch for %s", SYSTEM_DATA_DIR_PATH); |
| 1064 | return NO_INIT; |
| 1065 | } |
| 1066 | |
| 1067 | addTimeDirWatch(); |
| 1068 | |
| 1069 | if (mBootAnimation->updateIsTimeAccurate()) { |
| 1070 | close(mInotifyFd); |
| 1071 | mInotifyFd = -1; |
| 1072 | return ALREADY_EXISTS; |
| 1073 | } |
| 1074 | |
| 1075 | return NO_ERROR; |
| 1076 | } |
| 1077 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1078 | // --------------------------------------------------------------------------- |
| 1079 | |
| 1080 | } |
| 1081 | ; // namespace android |