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> |
Wei Wang | a90c54c | 2017-02-02 11:35:21 -0800 | [diff] [blame] | 21 | #include <inttypes.h> |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 22 | #include <sys/inotify.h> |
| 23 | #include <sys/poll.h> |
| 24 | #include <sys/stat.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <sys/types.h> |
| 26 | #include <math.h> |
| 27 | #include <fcntl.h> |
| 28 | #include <utils/misc.h> |
Mathias Agopian | b4d5a72 | 2009-09-23 17:05:19 -0700 | [diff] [blame] | 29 | #include <signal.h> |
Elliott Hughes | bb94f31 | 2014-10-21 10:41:33 -0700 | [diff] [blame] | 30 | #include <time.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 32 | #include <cutils/properties.h> |
| 33 | |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 34 | #include <androidfw/AssetManager.h> |
Mathias Agopian | ac31a3b | 2009-05-21 19:59:24 -0700 | [diff] [blame] | 35 | #include <binder/IPCThreadState.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | #include <utils/Atomic.h> |
| 37 | #include <utils/Errors.h> |
| 38 | #include <utils/Log.h> |
Wei Wang | a90c54c | 2017-02-02 11:35:21 -0800 | [diff] [blame] | 39 | #include <utils/SystemClock.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 41 | #include <android-base/properties.h> |
| 42 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | #include <ui/PixelFormat.h> |
| 44 | #include <ui/Rect.h> |
| 45 | #include <ui/Region.h> |
| 46 | #include <ui/DisplayInfo.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 48 | #include <gui/ISurfaceComposer.h> |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 49 | #include <gui/Surface.h> |
| 50 | #include <gui/SurfaceComposerClient.h> |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 51 | |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 52 | // TODO: Fix Skia. |
| 53 | #pragma GCC diagnostic push |
| 54 | #pragma GCC diagnostic ignored "-Wunused-parameter" |
Derek Sollenberger | eece0dd | 2014-02-27 14:31:29 -0500 | [diff] [blame] | 55 | #include <SkBitmap.h> |
Matt Sarett | 8898c16 | 2016-03-24 16:11:01 -0400 | [diff] [blame] | 56 | #include <SkImage.h> |
Derek Sollenberger | eece0dd | 2014-02-27 14:31:29 -0500 | [diff] [blame] | 57 | #include <SkStream.h> |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 58 | #pragma GCC diagnostic pop |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | |
| 60 | #include <GLES/gl.h> |
| 61 | #include <GLES/glext.h> |
| 62 | #include <EGL/eglext.h> |
| 63 | |
| 64 | #include "BootAnimation.h" |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 65 | #include "audioplay.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | |
| 67 | namespace android { |
| 68 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 69 | static const char OEM_BOOTANIMATION_FILE[] = "/oem/media/bootanimation.zip"; |
| 70 | static const char SYSTEM_BOOTANIMATION_FILE[] = "/system/media/bootanimation.zip"; |
| 71 | static const char SYSTEM_ENCRYPTED_BOOTANIMATION_FILE[] = "/system/media/bootanimation-encrypted.zip"; |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 72 | static const char OEM_SHUTDOWNANIMATION_FILE[] = "/oem/media/shutdownanimation.zip"; |
| 73 | static const char SYSTEM_SHUTDOWNANIMATION_FILE[] = "/system/media/shutdownanimation.zip"; |
| 74 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 75 | static const char SYSTEM_DATA_DIR_PATH[] = "/data/system"; |
| 76 | static const char SYSTEM_TIME_DIR_NAME[] = "time"; |
| 77 | static const char SYSTEM_TIME_DIR_PATH[] = "/data/system/time"; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 78 | static const char CLOCK_FONT_ASSET[] = "images/clock_font.png"; |
| 79 | static const char CLOCK_FONT_ZIP_NAME[] = "clock_font.png"; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 80 | static const char LAST_TIME_CHANGED_FILE_NAME[] = "last_time_change"; |
| 81 | static const char LAST_TIME_CHANGED_FILE_PATH[] = "/data/system/time/last_time_change"; |
| 82 | static const char ACCURATE_TIME_FLAG_FILE_NAME[] = "time_is_accurate"; |
| 83 | static const char ACCURATE_TIME_FLAG_FILE_PATH[] = "/data/system/time/time_is_accurate"; |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 84 | static const char TIME_FORMAT_12_HOUR_FLAG_FILE_PATH[] = "/data/system/time/time_format_12_hour"; |
Damien Bargiacchi | 9676281 | 2016-07-12 15:53:40 -0700 | [diff] [blame] | 85 | // Java timestamp format. Don't show the clock if the date is before 2000-01-01 00:00:00. |
| 86 | static const long long ACCURATE_TIME_EPOCH = 946684800000; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 87 | static constexpr char FONT_BEGIN_CHAR = ' '; |
| 88 | static constexpr char FONT_END_CHAR = '~' + 1; |
| 89 | static constexpr size_t FONT_NUM_CHARS = FONT_END_CHAR - FONT_BEGIN_CHAR + 1; |
| 90 | static constexpr size_t FONT_NUM_COLS = 16; |
| 91 | static constexpr size_t FONT_NUM_ROWS = FONT_NUM_CHARS / FONT_NUM_COLS; |
| 92 | static const int TEXT_CENTER_VALUE = INT_MAX; |
| 93 | static const int TEXT_MISSING_VALUE = INT_MIN; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 94 | static const char EXIT_PROP_NAME[] = "service.bootanim.exit"; |
Geoffrey Pitsch | 3050879 | 2016-07-22 17:04:21 -0400 | [diff] [blame] | 95 | static const char PLAY_SOUND_PROP_NAME[] = "persist.sys.bootanim.play_sound"; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 96 | static const int ANIM_ENTRY_NAME_MAX = 256; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 97 | static constexpr size_t TEXT_POS_LEN_MAX = 16; |
Geoffrey Pitsch | 290c435 | 2016-08-09 14:35:10 -0400 | [diff] [blame] | 98 | static const char BOOT_COMPLETED_PROP_NAME[] = "sys.boot_completed"; |
| 99 | static const char BOOTREASON_PROP_NAME[] = "ro.boot.bootreason"; |
| 100 | // bootreasons list in "system/core/bootstat/bootstat.cpp". |
| 101 | static const std::vector<std::string> PLAY_SOUND_BOOTREASON_BLACKLIST { |
| 102 | "kernel_panic", |
| 103 | "Panic", |
| 104 | "Watchdog", |
| 105 | }; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | // --------------------------------------------------------------------------- |
| 108 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 109 | BootAnimation::BootAnimation() : Thread(false), mClockEnabled(true), mTimeIsAccurate(false), |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 110 | mTimeFormat12Hour(false), mTimeCheckThread(NULL) { |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 111 | mSession = new SurfaceComposerClient(); |
Geoffrey Pitsch | 290c435 | 2016-08-09 14:35:10 -0400 | [diff] [blame] | 112 | |
| 113 | // If the system has already booted, the animation is not being used for a boot. |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 114 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | } |
| 122 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | void BootAnimation::onFirstRef() { |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 124 | status_t err = mSession->linkToComposerDeath(this); |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 125 | ALOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err)); |
Mathias Agopian | 8434c53 | 2009-09-23 18:52:49 -0700 | [diff] [blame] | 126 | if (err == NO_ERROR) { |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 127 | run("BootAnimation", PRIORITY_DISPLAY); |
| 128 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 131 | sp<SurfaceComposerClient> BootAnimation::session() const { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | return mSession; |
| 133 | } |
| 134 | |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 135 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 136 | void BootAnimation::binderDied(const wp<IBinder>&) |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 137 | { |
| 138 | // woah, surfaceflinger died! |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 139 | ALOGD("SurfaceFlinger died, exiting..."); |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 140 | |
| 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 Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 145 | audioplay::destroy(); |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 146 | } |
| 147 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets, |
| 149 | const char* name) { |
| 150 | Asset* asset = assets.open(name, Asset::ACCESS_BUFFER); |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 151 | if (asset == NULL) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | return NO_INIT; |
| 153 | SkBitmap bitmap; |
Matt Sarett | 8898c16 | 2016-03-24 16:11:01 -0400 | [diff] [blame] | 154 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | asset->close(); |
| 159 | delete asset; |
| 160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | 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 Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 172 | switch (bitmap.colorType()) { |
| 173 | case kAlpha_8_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, |
| 175 | GL_UNSIGNED_BYTE, p); |
| 176 | break; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 177 | case kARGB_4444_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
| 179 | GL_UNSIGNED_SHORT_4_4_4_4, p); |
| 180 | break; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 181 | case kN32_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
| 183 | GL_UNSIGNED_BYTE, p); |
| 184 | break; |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 185 | case kRGB_565_SkColorType: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | 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 Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | return NO_ERROR; |
| 200 | } |
| 201 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 202 | status_t BootAnimation::initTexture(FileMap* map, int* width, int* height) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 203 | { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 204 | SkBitmap bitmap; |
Damien Bargiacchi | f67b317 | 2016-09-07 20:17:14 -0700 | [diff] [blame] | 205 | sk_sp<SkData> data = SkData::MakeWithoutCopy(map->getDataPtr(), |
| 206 | map->getDataLength()); |
Matt Sarett | 8898c16 | 2016-03-24 16:11:01 -0400 | [diff] [blame] | 207 | sk_sp<SkImage> image = SkImage::MakeFromEncoded(data); |
| 208 | image->asLegacyBitmap(&bitmap, SkImage::kRO_LegacyBitmapMode); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 209 | |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 210 | // 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 Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 213 | delete map; |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 214 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 215 | 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 Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 225 | switch (bitmap.colorType()) { |
| 226 | case kN32_SkColorType: |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 227 | if (!mUseNpotTextures && (tw != w || th != h)) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 228 | 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 Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 233 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 234 | GL_UNSIGNED_BYTE, p); |
| 235 | } |
| 236 | break; |
| 237 | |
Mike Reed | 42a1d08 | 2014-07-07 18:06:18 -0400 | [diff] [blame] | 238 | case kRGB_565_SkColorType: |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 239 | if (!mUseNpotTextures && (tw != w || th != h)) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 240 | 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 Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 245 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 246 | 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 Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 255 | *width = w; |
| 256 | *height = h; |
| 257 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 258 | return NO_ERROR; |
| 259 | } |
| 260 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | status_t BootAnimation::readyToRun() { |
| 262 | mAssets.addDefaultAssets(); |
| 263 | |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 264 | sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay( |
| 265 | ISurfaceComposer::eDisplayIdMain)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 266 | DisplayInfo dinfo; |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 267 | status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &dinfo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | if (status) |
| 269 | return -1; |
| 270 | |
| 271 | // create the native surface |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 272 | sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"), |
| 273 | dinfo.w, dinfo.h, PIXEL_FORMAT_RGB_565); |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 274 | |
| 275 | SurfaceComposerClient::openGlobalTransaction(); |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 276 | control->setLayer(0x40000000); |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 277 | SurfaceComposerClient::closeGlobalTransaction(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 279 | sp<Surface> s = control->getSurface(); |
| 280 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | // initialize opengl and egl |
Mathias Agopian | 738b9a4 | 2009-08-06 16:41:02 -0700 | [diff] [blame] | 282 | const EGLint attribs[] = { |
Mathias Agopian | 1b253b7 | 2011-08-15 15:20:22 -0700 | [diff] [blame] | 283 | EGL_RED_SIZE, 8, |
| 284 | EGL_GREEN_SIZE, 8, |
| 285 | EGL_BLUE_SIZE, 8, |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 286 | EGL_DEPTH_SIZE, 0, |
| 287 | EGL_NONE |
Mathias Agopian | 738b9a4 | 2009-08-06 16:41:02 -0700 | [diff] [blame] | 288 | }; |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 289 | EGLint w, h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 290 | EGLint numConfigs; |
| 291 | EGLConfig config; |
| 292 | EGLSurface surface; |
| 293 | EGLContext context; |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 296 | |
| 297 | eglInitialize(display, 0, 0); |
Mathias Agopian | 1b253b7 | 2011-08-15 15:20:22 -0700 | [diff] [blame] | 298 | eglChooseConfig(display, attribs, &config, 1, &numConfigs); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 299 | surface = eglCreateWindowSurface(display, config, s.get(), NULL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | context = eglCreateContext(display, config, NULL, NULL); |
| 301 | eglQuerySurface(display, surface, EGL_WIDTH, &w); |
| 302 | eglQuerySurface(display, surface, EGL_HEIGHT, &h); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 303 | |
Mathias Agopian | abac010 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 304 | if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) |
| 305 | return NO_INIT; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 306 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | mDisplay = display; |
| 308 | mContext = context; |
| 309 | mSurface = surface; |
| 310 | mWidth = w; |
| 311 | mHeight = h; |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 312 | mFlingerSurfaceControl = control; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | mFlingerSurface = s; |
| 314 | |
Elliott Hughes | c367d48 | 2013-10-29 13:12:55 -0700 | [diff] [blame] | 315 | // If the device has encryption turned on or is in process |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 316 | // of being encrypted we show the encrypted boot animation. |
| 317 | char decrypt[PROPERTY_VALUE_MAX]; |
| 318 | property_get("vold.decrypt", decrypt, ""); |
| 319 | |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 320 | bool encryptedAnimation = atoi(decrypt) != 0 || |
| 321 | !strcmp("trigger_restart_min_framework", decrypt); |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 322 | |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 323 | if (!mShuttingDown && encryptedAnimation && |
| 324 | (access(SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, R_OK) == 0)) { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 325 | mZipFileName = SYSTEM_ENCRYPTED_BOOTANIMATION_FILE; |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 326 | return NO_ERROR; |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 327 | } |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 328 | 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 Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 337 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | return NO_ERROR; |
| 339 | } |
| 340 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 341 | bool BootAnimation::threadLoop() |
| 342 | { |
| 343 | bool r; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 344 | // We have no bootanimation file, so we use the stock android logo |
| 345 | // animation. |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 346 | if (mZipFileName.isEmpty()) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 347 | r = android(); |
| 348 | } else { |
| 349 | r = movie(); |
| 350 | } |
| 351 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 353 | eglDestroyContext(mDisplay, mContext); |
| 354 | eglDestroySurface(mDisplay, mSurface); |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 355 | mFlingerSurface.clear(); |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 356 | mFlingerSurfaceControl.clear(); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 357 | eglTerminate(mDisplay); |
Sai Kiran Korwar | 3eee9fb | 2015-06-16 17:13:35 +0530 | [diff] [blame] | 358 | eglReleaseThread(); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 359 | IPCThreadState::self()->stopProcess(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 360 | return r; |
| 361 | } |
| 362 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 363 | bool BootAnimation::android() |
| 364 | { |
Keun-young Park | d1794cd | 2017-04-04 12:21:19 -0700 | [diff] [blame] | 365 | ALOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
| 366 | elapsedRealtime()); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 367 | initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png"); |
| 368 | initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | |
| 370 | // clear screen |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 371 | glShadeModel(GL_FLAT); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 372 | glDisable(GL_DITHER); |
| 373 | glDisable(GL_SCISSOR_TEST); |
Mathias Agopian | 59f19e4 | 2011-05-06 19:22:12 -0700 | [diff] [blame] | 374 | glClearColor(0,0,0,1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | glClear(GL_COLOR_BUFFER_BIT); |
| 376 | eglSwapBuffers(mDisplay, mSurface); |
| 377 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 378 | glEnable(GL_TEXTURE_2D); |
| 379 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 380 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 381 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 384 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(), |
| 386 | updateRect.height()); |
| 387 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 388 | // 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 392 | const nsecs_t startTime = systemTime(); |
| 393 | do { |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 394 | nsecs_t now = systemTime(); |
| 395 | double time = now - startTime; |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 396 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | |
Mathias Agopian | 8166864 | 2009-07-28 11:41:30 -0700 | [diff] [blame] | 400 | glDisable(GL_SCISSOR_TEST); |
| 401 | glClear(GL_COLOR_BUFFER_BIT); |
| 402 | |
| 403 | glEnable(GL_SCISSOR_TEST); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | glDisable(GL_BLEND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 405 | glBindTexture(GL_TEXTURE_2D, mAndroid[1].name); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 406 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 408 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 409 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 413 | EGLBoolean res = eglSwapBuffers(mDisplay, mSurface); |
| 414 | if (res == EGL_FALSE) |
| 415 | break; |
| 416 | |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 417 | // 12fps: don't animate too fast to preserve CPU |
| 418 | const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now); |
| 419 | if (sleepTime > 0) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 420 | usleep(sleepTime); |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 421 | |
| 422 | checkExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | } while (!exitPending()); |
| 424 | |
| 425 | glDeleteTextures(1, &mAndroid[0].name); |
| 426 | glDeleteTextures(1, &mAndroid[1].name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 427 | return false; |
| 428 | } |
| 429 | |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 430 | void 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 Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 440 | bool BootAnimation::validClock(const Animation::Part& part) { |
| 441 | return part.clockPosX != TEXT_MISSING_VALUE && part.clockPosY != TEXT_MISSING_VALUE; |
| 442 | } |
| 443 | |
| 444 | bool 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. |
| 460 | void 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 Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 481 | // 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. |
| 488 | static 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 Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 506 | |
| 507 | static bool readFile(ZipFileRO* zip, const char* name, String8& outString) |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 508 | { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 509 | ZipEntryRO entry = zip->findEntryByName(name); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 510 | ALOGE_IF(!entry, "couldn't find %s", name); |
| 511 | if (!entry) { |
| 512 | return false; |
| 513 | } |
| 514 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 515 | FileMap* entryMap = zip->createEntryFileMap(entry); |
| 516 | zip->releaseEntry(entry); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 517 | ALOGE_IF(!entryMap, "entryMap is null"); |
| 518 | if (!entryMap) { |
| 519 | return false; |
| 520 | } |
| 521 | |
| 522 | outString.setTo((char const*)entryMap->getDataPtr(), entryMap->getDataLength()); |
Narayan Kamath | 688ff4c | 2015-02-23 15:47:54 +0000 | [diff] [blame] | 523 | delete entryMap; |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 524 | return true; |
| 525 | } |
| 526 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 527 | // 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. |
| 530 | status_t BootAnimation::initFont(Font* font, const char* fallback) { |
| 531 | status_t status = NO_ERROR; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 532 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 533 | if (font->map != nullptr) { |
| 534 | glGenTextures(1, &font->texture.name); |
| 535 | glBindTexture(GL_TEXTURE_2D, font->texture.name); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 536 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 537 | 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 Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 549 | 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 | |
| 557 | void 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 Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 603 | // We render 12 or 24 hour time. |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 604 | void BootAnimation::drawClock(const Font& font, const int xPos, const int yPos) { |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 605 | static constexpr char TIME_FORMAT_12[] = "%l:%M"; |
| 606 | static constexpr char TIME_FORMAT_24[] = "%H:%M"; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 607 | static constexpr int TIME_LENGTH = 6; |
| 608 | |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 609 | time_t rawtime; |
| 610 | time(&rawtime); |
| 611 | struct tm* timeInfo = localtime(&rawtime); |
| 612 | |
| 613 | char timeBuff[TIME_LENGTH]; |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 614 | const char* timeFormat = mTimeFormat12Hour ? TIME_FORMAT_12 : TIME_FORMAT_24; |
| 615 | size_t length = strftime(timeBuff, TIME_LENGTH, timeFormat, timeInfo); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 616 | |
| 617 | if (length != TIME_LENGTH - 1) { |
| 618 | ALOGE("Couldn't format time; abandoning boot animation clock"); |
| 619 | mClockEnabled = false; |
| 620 | return; |
| 621 | } |
| 622 | |
Damien Bargiacchi | 45a7644 | 2016-12-05 18:02:18 -0800 | [diff] [blame] | 623 | char* out = timeBuff[0] == ' ' ? &timeBuff[1] : &timeBuff[0]; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 624 | int x = xPos; |
| 625 | int y = yPos; |
Damien Bargiacchi | 45a7644 | 2016-12-05 18:02:18 -0800 | [diff] [blame] | 626 | drawText(out, font, false, &x, &y); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 627 | } |
| 628 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 629 | bool BootAnimation::parseAnimationDesc(Animation& animation) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 630 | { |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 631 | String8 desString; |
| 632 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 633 | if (!readFile(animation.zip, "desc.txt", desString)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 634 | return false; |
| 635 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 636 | char const* s = desString.string(); |
| 637 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 638 | // Parse the description file |
| 639 | for (;;) { |
| 640 | const char* endl = strstr(s, "\n"); |
Andreas Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 641 | if (endl == NULL) break; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 642 | String8 line(s, endl - s); |
| 643 | const char* l = line.string(); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 644 | int fps = 0; |
| 645 | int width = 0; |
| 646 | int height = 0; |
| 647 | int count = 0; |
| 648 | int pause = 0; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 649 | char path[ANIM_ENTRY_NAME_MAX]; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 650 | char color[7] = "000000"; // default to black if unspecified |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 651 | char clockPos1[TEXT_POS_LEN_MAX + 1] = ""; |
| 652 | char clockPos2[TEXT_POS_LEN_MAX + 1] = ""; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 653 | |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 654 | char pathType; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 655 | if (sscanf(l, "%d %d %d", &width, &height, &fps) == 3) { |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 656 | // ALOGD("> w=%d, h=%d, fps=%d", width, height, fps); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 657 | animation.width = width; |
| 658 | animation.height = height; |
| 659 | animation.fps = fps; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 660 | } 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 Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 664 | Animation::Part part; |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 665 | part.playUntilComplete = pathType == 'c'; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 666 | part.count = count; |
| 667 | part.pause = pause; |
| 668 | part.path = path; |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 669 | part.audioData = NULL; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 670 | part.animation = NULL; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 671 | 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 Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 677 | parsePosition(clockPos1, clockPos2, &part.clockPosX, &part.clockPosY); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 678 | animation.parts.add(part); |
| 679 | } |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 680 | 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 Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 686 | part.audioData = NULL; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 687 | part.animation = loadAnimation(String8(SYSTEM_BOOTANIMATION_FILE)); |
| 688 | if (part.animation != NULL) |
| 689 | animation.parts.add(part); |
| 690 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 691 | s = ++endl; |
| 692 | } |
| 693 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 694 | return true; |
| 695 | } |
| 696 | |
| 697 | bool BootAnimation::preloadZip(Animation& animation) |
| 698 | { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 699 | // read all the data structures |
| 700 | const size_t pcount = animation.parts.size(); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 701 | void *cookie = NULL; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 702 | ZipFileRO* zip = animation.zip; |
| 703 | if (!zip->startIteration(&cookie)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 704 | return false; |
| 705 | } |
| 706 | |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 707 | Animation::Part* partWithAudio = NULL; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 708 | ZipEntryRO entry; |
| 709 | char name[ANIM_ENTRY_NAME_MAX]; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 710 | while ((entry = zip->nextEntry(cookie)) != NULL) { |
| 711 | const int foundEntryName = zip->getEntryFileName(entry, name, ANIM_ENTRY_NAME_MAX); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 712 | 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 Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 721 | 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 Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 729 | for (size_t j = 0; j < pcount; j++) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 730 | if (path == animation.parts[j].path) { |
Narayan Kamath | 4600dd0 | 2015-06-16 12:02:57 +0100 | [diff] [blame] | 731 | uint16_t method; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 732 | // supports only stored png files |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 733 | if (zip->getEntryInfo(entry, &method, NULL, NULL, NULL, NULL, NULL)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 734 | if (method == ZipFileRO::kCompressStored) { |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 735 | FileMap* map = zip->createEntryFileMap(entry); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 736 | if (map) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 737 | Animation::Part& part(animation.parts.editItemAt(j)); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 738 | if (leaf == "audio.wav") { |
| 739 | // a part may have at most one audio file |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 740 | part.audioData = (uint8_t *)map->getDataPtr(); |
| 741 | part.audioLength = map->getDataLength(); |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 742 | partWithAudio = ∂ |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 743 | } else if (leaf == "trim.txt") { |
| 744 | part.trimData.setTo((char const*)map->getDataPtr(), |
| 745 | map->getDataLength()); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 746 | } else { |
| 747 | Animation::Frame frame; |
| 748 | frame.name = leaf; |
| 749 | frame.map = map; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 750 | frame.trimWidth = animation.width; |
| 751 | frame.trimHeight = animation.height; |
| 752 | frame.trimX = 0; |
| 753 | frame.trimY = 0; |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 754 | part.frames.add(frame); |
| 755 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 756 | } |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 757 | } else { |
| 758 | ALOGE("bootanimation.zip is compressed; must be only stored"); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 759 | } |
| 760 | } |
| 761 | } |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 766 | // 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 Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 792 | // Create and initialize audioplay if there is a wav file in any of the animations. |
Geoffrey Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 793 | // Do it on a separate thread so we don't hold up the animation intro. |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 794 | if (partWithAudio != NULL) { |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 795 | ALOGD("found audio.wav, creating playback engine"); |
Geoffrey Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 796 | mInitAudioThread = new InitAudioThread(partWithAudio->audioData, |
| 797 | partWithAudio->audioLength); |
| 798 | mInitAudioThread->run("BootAnimation::InitAudioThread", PRIORITY_NORMAL); |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 799 | } |
| 800 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 801 | zip->endIteration(cookie); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 802 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 803 | return true; |
| 804 | } |
| 805 | |
| 806 | bool BootAnimation::movie() |
| 807 | { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 808 | Animation* animation = loadAnimation(mZipFileName); |
| 809 | if (animation == NULL) |
| 810 | return false; |
| 811 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 812 | bool anyPartHasClock = false; |
| 813 | for (size_t i=0; i < animation->parts.size(); i++) { |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 814 | if(validClock(animation->parts[i])) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 815 | anyPartHasClock = true; |
| 816 | break; |
| 817 | } |
| 818 | } |
| 819 | if (!anyPartHasClock) { |
| 820 | mClockEnabled = false; |
| 821 | } |
| 822 | |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 823 | // 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 Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 837 | // Blend required to draw time on top of animation frames. |
| 838 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 839 | glShadeModel(GL_FLAT); |
| 840 | glDisable(GL_DITHER); |
| 841 | glDisable(GL_SCISSOR_TEST); |
| 842 | glDisable(GL_BLEND); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 843 | |
| 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 Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 852 | bool clockFontInitialized = false; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 853 | if (mClockEnabled) { |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 854 | clockFontInitialized = |
| 855 | (initFont(&animation->clockFont, CLOCK_FONT_ASSET) == NO_ERROR); |
| 856 | mClockEnabled = clockFontInitialized; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 857 | } |
| 858 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 859 | if (mClockEnabled && !updateIsTimeAccurate()) { |
| 860 | mTimeCheckThread = new TimeCheckThread(this); |
| 861 | mTimeCheckThread->run("BootAnimation::TimeCheckThread", PRIORITY_NORMAL); |
| 862 | } |
| 863 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 864 | playAnimation(*animation); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 865 | |
Geoffrey Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 866 | if (mTimeCheckThread != nullptr) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 867 | mTimeCheckThread->requestExit(); |
Geoffrey Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 868 | mTimeCheckThread = nullptr; |
| 869 | } |
| 870 | |
Wei Wang | a90c54c | 2017-02-02 11:35:21 -0800 | [diff] [blame] | 871 | // We should have joined mInitAudioThread thread in playAnimation |
Geoffrey Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 872 | if (mInitAudioThread != nullptr) { |
Geoffrey Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 873 | mInitAudioThread = nullptr; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 876 | releaseAnimation(animation); |
| 877 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 878 | if (clockFontInitialized) { |
| 879 | glDeleteTextures(1, &animation->clockFont.texture.name); |
Andriy Naborskyy | 815e51d | 2016-03-24 16:43:34 -0700 | [diff] [blame] | 880 | } |
| 881 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 882 | return false; |
| 883 | } |
| 884 | |
| 885 | bool BootAnimation::playAnimation(const Animation& animation) |
| 886 | { |
| 887 | const size_t pcount = animation.parts.size(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 888 | nsecs_t frameDuration = s2ns(1) / animation.fps; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 889 | const int animationX = (mWidth - animation.width) / 2; |
| 890 | const int animationY = (mHeight - animation.height) / 2; |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 891 | |
Keun-young Park | d1794cd | 2017-04-04 12:21:19 -0700 | [diff] [blame] | 892 | ALOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
| 893 | elapsedRealtime()); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 894 | for (size_t i=0 ; i<pcount ; i++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 895 | const Animation::Part& part(animation.parts[i]); |
| 896 | const size_t fcount = part.frames.size(); |
| 897 | glBindTexture(GL_TEXTURE_2D, 0); |
| 898 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 899 | // 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 Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 907 | for (int r=0 ; !part.count || r<part.count ; r++) { |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 908 | // Exit any non playuntil complete parts immediately |
| 909 | if(exitPending() && !part.playUntilComplete) |
| 910 | break; |
| 911 | |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 912 | // only play audio file the first time we animate the part |
Geoffrey Pitsch | 290c435 | 2016-08-09 14:35:10 -0400 | [diff] [blame] | 913 | if (r == 0 && part.audioData && playSoundsAllowed()) { |
| 914 | ALOGD("playing clip for part%d, size=%d", (int) i, part.audioLength); |
Geoffrey Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 915 | // Block until the audio engine is finished initializing. |
| 916 | if (mInitAudioThread != nullptr) { |
| 917 | mInitAudioThread->join(); |
| 918 | } |
Geoffrey Pitsch | 290c435 | 2016-08-09 14:35:10 -0400 | [diff] [blame] | 919 | audioplay::playClip(part.audioData, part.audioLength); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 922 | glClearColor( |
| 923 | part.backgroundColor[0], |
| 924 | part.backgroundColor[1], |
| 925 | part.backgroundColor[2], |
| 926 | 1.0f); |
| 927 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 928 | for (size_t j=0 ; j<fcount && (!exitPending() || part.playUntilComplete) ; j++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 929 | const Animation::Frame& frame(part.frames[j]); |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 930 | nsecs_t lastFrame = systemTime(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 931 | |
| 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 Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 941 | int w, h; |
| 942 | initTexture(frame.map, &w, &h); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 943 | } |
| 944 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 945 | 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 Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 949 | 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 Gampe | cfedceb | 2014-09-30 21:48:18 -0700 | [diff] [blame] | 954 | const Rect& r2(*head++); |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 955 | glScissor(r2.left, mHeight - r2.bottom, r2.width(), r2.height()); |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 956 | glClear(GL_COLOR_BUFFER_BIT); |
| 957 | } |
| 958 | glDisable(GL_SCISSOR_TEST); |
| 959 | } |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 960 | // 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 Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 964 | if (mClockEnabled && mTimeIsAccurate && validClock(part)) { |
| 965 | drawClock(animation.clockFont, part.clockPosX, part.clockPosY); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 966 | } |
| 967 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 968 | eglSwapBuffers(mDisplay, mSurface); |
| 969 | |
| 970 | nsecs_t now = systemTime(); |
| 971 | nsecs_t delay = frameDuration - (now - lastFrame); |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 972 | //ALOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay)); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 973 | lastFrame = now; |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 974 | |
| 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 Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 984 | |
| 985 | checkExit(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 986 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 987 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 988 | usleep(part.pause * ns2us(frameDuration)); |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 989 | |
| 990 | // For infinite parts, we've now played them at least once, so perhaps exit |
| 991 | if(exitPending() && !part.count) |
| 992 | break; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Geoffrey Pitsch | 2fb30fb | 2016-07-06 16:16:20 -0400 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | // Free textures created for looping parts now that the animation is done. |
| 998 | for (const Animation::Part& part : animation.parts) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 999 | if (part.count != 1) { |
Geoffrey Pitsch | 2fb30fb | 2016-07-06 16:16:20 -0400 | [diff] [blame] | 1000 | const size_t fcount = part.frames.size(); |
| 1001 | for (size_t j = 0; j < fcount; j++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1002 | const Animation::Frame& frame(part.frames[j]); |
| 1003 | glDeleteTextures(1, &frame.tid); |
| 1004 | } |
| 1005 | } |
| 1006 | } |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 1007 | |
| 1008 | // we've finally played everything we're going to play |
| 1009 | audioplay::setPlaying(false); |
| 1010 | audioplay::destroy(); |
| 1011 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1012 | return true; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1015 | void 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 | |
| 1027 | BootAnimation::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 Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1044 | animation->clockFont.map = nullptr; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1045 | mLoadedFiles.add(animation->fileName); |
| 1046 | |
| 1047 | parseAnimationDesc(*animation); |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 1048 | if (!preloadZip(*animation)) { |
| 1049 | return NULL; |
| 1050 | } |
| 1051 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1052 | |
| 1053 | mLoadedFiles.remove(fn); |
| 1054 | return animation; |
| 1055 | } |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1056 | |
Geoffrey Pitsch | 290c435 | 2016-08-09 14:35:10 -0400 | [diff] [blame] | 1057 | bool BootAnimation::playSoundsAllowed() const { |
| 1058 | // Only play sounds for system boots, not runtime restarts. |
| 1059 | if (!mSystemBoot) { |
| 1060 | return false; |
| 1061 | } |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 1062 | if (mShuttingDown) { // no audio while shutting down |
| 1063 | return false; |
| 1064 | } |
Geoffrey Pitsch | 290c435 | 2016-08-09 14:35:10 -0400 | [diff] [blame] | 1065 | // 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 Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1083 | bool 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 Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 1090 | if (mShuttingDown) return true; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1091 | struct stat statResult; |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 1092 | |
| 1093 | if(stat(TIME_FORMAT_12_HOUR_FLAG_FILE_PATH, &statResult) == 0) { |
| 1094 | mTimeFormat12Hour = true; |
| 1095 | } |
| 1096 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1097 | 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 Bargiacchi | 9676281 | 2016-07-12 15:53:40 -0700 | [diff] [blame] | 1112 | if (ACCURATE_TIME_EPOCH < rtcNow |
| 1113 | && lastChangedTime > (rtcNow - MAX_TIME_IN_PAST) |
| 1114 | && lastChangedTime < (rtcNow + MAX_TIME_IN_FUTURE)) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1115 | mTimeIsAccurate = true; |
| 1116 | } |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | return mTimeIsAccurate; |
| 1121 | } |
| 1122 | |
| 1123 | BootAnimation::TimeCheckThread::TimeCheckThread(BootAnimation* bootAnimation) : Thread(false), |
| 1124 | mInotifyFd(-1), mSystemWd(-1), mTimeWd(-1), mBootAnimation(bootAnimation) {} |
| 1125 | |
| 1126 | BootAnimation::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 | |
| 1131 | bool 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 | |
| 1141 | bool 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 | |
| 1178 | void 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 | |
| 1188 | status_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 Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 1214 | BootAnimation::InitAudioThread::InitAudioThread(uint8_t* exampleAudioData, int exampleAudioLength) |
| 1215 | : Thread(false), |
| 1216 | mExampleAudioData(exampleAudioData), |
| 1217 | mExampleAudioLength(exampleAudioLength) {} |
| 1218 | |
| 1219 | bool BootAnimation::InitAudioThread::threadLoop() { |
| 1220 | audioplay::create(mExampleAudioData, mExampleAudioLength); |
| 1221 | // Exit immediately |
| 1222 | return false; |
| 1223 | } |
| 1224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1225 | // --------------------------------------------------------------------------- |
| 1226 | |
| 1227 | } |
| 1228 | ; // namespace android |