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 | |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame] | 20 | #include <vector> |
| 21 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include <stdint.h> |
Wei Wang | a90c54c | 2017-02-02 11:35:21 -0800 | [diff] [blame] | 23 | #include <inttypes.h> |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 24 | #include <sys/inotify.h> |
| 25 | #include <sys/poll.h> |
| 26 | #include <sys/stat.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | #include <sys/types.h> |
| 28 | #include <math.h> |
| 29 | #include <fcntl.h> |
| 30 | #include <utils/misc.h> |
Mathias Agopian | b4d5a72 | 2009-09-23 17:05:19 -0700 | [diff] [blame] | 31 | #include <signal.h> |
Elliott Hughes | bb94f31 | 2014-10-21 10:41:33 -0700 | [diff] [blame] | 32 | #include <time.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
Steven Moreland | fb7952f | 2018-02-23 14:58:50 -0800 | [diff] [blame] | 34 | #include <cutils/atomic.h> |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 35 | #include <cutils/properties.h> |
| 36 | |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 37 | #include <android/imagedecoder.h> |
Mathias Agopian | b13b9bd | 2012-02-17 18:27:36 -0800 | [diff] [blame] | 38 | #include <androidfw/AssetManager.h> |
Mathias Agopian | ac31a3b | 2009-05-21 19:59:24 -0700 | [diff] [blame] | 39 | #include <binder/IPCThreadState.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | #include <utils/Errors.h> |
| 41 | #include <utils/Log.h> |
Wei Wang | a90c54c | 2017-02-02 11:35:21 -0800 | [diff] [blame] | 42 | #include <utils/SystemClock.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 44 | #include <android-base/properties.h> |
| 45 | |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 46 | #include <ui/DisplayMode.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | #include <ui/PixelFormat.h> |
| 48 | #include <ui/Rect.h> |
| 49 | #include <ui/Region.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 51 | #include <gui/ISurfaceComposer.h> |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 52 | #include <gui/DisplayEventReceiver.h> |
Mathias Agopian | 8335f1c | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 53 | #include <gui/Surface.h> |
| 54 | #include <gui/SurfaceComposerClient.h> |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 55 | #include <GLES2/gl2.h> |
| 56 | #include <GLES2/gl2ext.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | #include <EGL/eglext.h> |
| 58 | |
| 59 | #include "BootAnimation.h" |
| 60 | |
Kyeongkab.Nam | 35a8a11 | 2019-07-17 16:41:48 +0900 | [diff] [blame] | 61 | #define ANIM_PATH_MAX 255 |
| 62 | #define STR(x) #x |
| 63 | #define STRTO(x) STR(x) |
| 64 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | namespace android { |
| 66 | |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 67 | using ui::DisplayMode; |
| 68 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 69 | static const char OEM_BOOTANIMATION_FILE[] = "/oem/media/bootanimation.zip"; |
Beverly | 34ffe25 | 2019-05-17 11:03:54 -0400 | [diff] [blame] | 70 | static const char PRODUCT_BOOTANIMATION_DARK_FILE[] = "/product/media/bootanimation-dark.zip"; |
Jaekyun Seok | c521bb3 | 2018-01-30 11:52:47 +0900 | [diff] [blame] | 71 | static const char PRODUCT_BOOTANIMATION_FILE[] = "/product/media/bootanimation.zip"; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 72 | static const char SYSTEM_BOOTANIMATION_FILE[] = "/system/media/bootanimation.zip"; |
Anders Fridlund | e0b4d23 | 2018-11-06 14:23:25 +0100 | [diff] [blame] | 73 | static const char APEX_BOOTANIMATION_FILE[] = "/apex/com.android.bootanimation/etc/bootanimation.zip"; |
Jaekyun Seok | c521bb3 | 2018-01-30 11:52:47 +0900 | [diff] [blame] | 74 | static const char PRODUCT_ENCRYPTED_BOOTANIMATION_FILE[] = "/product/media/bootanimation-encrypted.zip"; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 75 | 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] | 76 | static const char OEM_SHUTDOWNANIMATION_FILE[] = "/oem/media/shutdownanimation.zip"; |
Jaekyun Seok | c521bb3 | 2018-01-30 11:52:47 +0900 | [diff] [blame] | 77 | static const char PRODUCT_SHUTDOWNANIMATION_FILE[] = "/product/media/shutdownanimation.zip"; |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 78 | static const char SYSTEM_SHUTDOWNANIMATION_FILE[] = "/system/media/shutdownanimation.zip"; |
| 79 | |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame] | 80 | static constexpr const char* PRODUCT_USERSPACE_REBOOT_ANIMATION_FILE = "/product/media/userspace-reboot.zip"; |
| 81 | static constexpr const char* OEM_USERSPACE_REBOOT_ANIMATION_FILE = "/oem/media/userspace-reboot.zip"; |
| 82 | static constexpr const char* SYSTEM_USERSPACE_REBOOT_ANIMATION_FILE = "/system/media/userspace-reboot.zip"; |
| 83 | |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 84 | static const char BOOTANIM_DATA_DIR_PATH[] = "/data/bootanim"; |
| 85 | static const char BOOTANIM_TIME_DIR_NAME[] = "time"; |
| 86 | static const char BOOTANIM_TIME_DIR_PATH[] = "/data/bootanim/time"; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 87 | static const char CLOCK_FONT_ASSET[] = "images/clock_font.png"; |
| 88 | static const char CLOCK_FONT_ZIP_NAME[] = "clock_font.png"; |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 89 | static const char PROGRESS_FONT_ASSET[] = "images/progress_font.png"; |
| 90 | static const char PROGRESS_FONT_ZIP_NAME[] = "progress_font.png"; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 91 | static const char LAST_TIME_CHANGED_FILE_NAME[] = "last_time_change"; |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 92 | static const char LAST_TIME_CHANGED_FILE_PATH[] = "/data/bootanim/time/last_time_change"; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 93 | static const char ACCURATE_TIME_FLAG_FILE_NAME[] = "time_is_accurate"; |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 94 | static const char ACCURATE_TIME_FLAG_FILE_PATH[] = "/data/bootanim/time/time_is_accurate"; |
| 95 | static const char TIME_FORMAT_12_HOUR_FLAG_FILE_PATH[] = "/data/bootanim/time/time_format_12_hour"; |
Damien Bargiacchi | 9676281 | 2016-07-12 15:53:40 -0700 | [diff] [blame] | 96 | // Java timestamp format. Don't show the clock if the date is before 2000-01-01 00:00:00. |
| 97 | static const long long ACCURATE_TIME_EPOCH = 946684800000; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 98 | static constexpr char FONT_BEGIN_CHAR = ' '; |
| 99 | static constexpr char FONT_END_CHAR = '~' + 1; |
| 100 | static constexpr size_t FONT_NUM_CHARS = FONT_END_CHAR - FONT_BEGIN_CHAR + 1; |
| 101 | static constexpr size_t FONT_NUM_COLS = 16; |
| 102 | static constexpr size_t FONT_NUM_ROWS = FONT_NUM_CHARS / FONT_NUM_COLS; |
| 103 | static const int TEXT_CENTER_VALUE = INT_MAX; |
| 104 | static const int TEXT_MISSING_VALUE = INT_MIN; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 105 | static const char EXIT_PROP_NAME[] = "service.bootanim.exit"; |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 106 | static const char PROGRESS_PROP_NAME[] = "service.bootanim.progress"; |
Huihong Luo | d4a217e | 2020-01-16 15:56:33 -0800 | [diff] [blame] | 107 | static const char DISPLAYS_PROP_NAME[] = "persist.service.bootanim.displays"; |
Thiébaud Weksteen | 08de443 | 2021-11-18 13:25:59 +1100 | [diff] [blame] | 108 | static const char CLOCK_ENABLED_PROP_NAME[] = "persist.sys.bootanim.clock.enabled"; |
Kyeongkab.Nam | 35a8a11 | 2019-07-17 16:41:48 +0900 | [diff] [blame] | 109 | static const int ANIM_ENTRY_NAME_MAX = ANIM_PATH_MAX + 1; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 110 | static constexpr size_t TEXT_POS_LEN_MAX = 16; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 111 | static const int DYNAMIC_COLOR_COUNT = 4; |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 112 | static const char U_TEXTURE[] = "uTexture"; |
| 113 | static const char U_FADE[] = "uFade"; |
| 114 | static const char U_CROP_AREA[] = "uCropArea"; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 115 | static const char U_START_COLOR_PREFIX[] = "uStartColor"; |
| 116 | static const char U_END_COLOR_PREFIX[] = "uEndColor"; |
| 117 | static const char U_COLOR_PROGRESS[] = "uColorProgress"; |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 118 | static const char A_UV[] = "aUv"; |
| 119 | static const char A_POSITION[] = "aPosition"; |
| 120 | static const char VERTEX_SHADER_SOURCE[] = R"( |
| 121 | precision mediump float; |
| 122 | attribute vec4 aPosition; |
| 123 | attribute highp vec2 aUv; |
| 124 | varying highp vec2 vUv; |
| 125 | void main() { |
| 126 | gl_Position = aPosition; |
| 127 | vUv = aUv; |
| 128 | })"; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 129 | static const char IMAGE_FRAG_DYNAMIC_COLORING_SHADER_SOURCE[] = R"( |
| 130 | precision mediump float; |
Shan Huang | 81846ba | 2021-09-07 19:07:47 +0000 | [diff] [blame] | 131 | const float cWhiteMaskThreshold = 0.05; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 132 | uniform sampler2D uTexture; |
| 133 | uniform float uFade; |
| 134 | uniform float uColorProgress; |
Andrew Zeng | f9f5822 | 2022-11-08 11:10:48 -0800 | [diff] [blame] | 135 | uniform vec3 uStartColor0; |
| 136 | uniform vec3 uStartColor1; |
| 137 | uniform vec3 uStartColor2; |
| 138 | uniform vec3 uStartColor3; |
| 139 | uniform vec3 uEndColor0; |
| 140 | uniform vec3 uEndColor1; |
| 141 | uniform vec3 uEndColor2; |
| 142 | uniform vec3 uEndColor3; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 143 | varying highp vec2 vUv; |
| 144 | void main() { |
| 145 | vec4 mask = texture2D(uTexture, vUv); |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 146 | float r = mask.r; |
| 147 | float g = mask.g; |
| 148 | float b = mask.b; |
| 149 | float a = mask.a; |
| 150 | // If all channels have values, render pixel as a shade of white. |
| 151 | float useWhiteMask = step(cWhiteMaskThreshold, r) |
| 152 | * step(cWhiteMaskThreshold, g) |
| 153 | * step(cWhiteMaskThreshold, b) |
| 154 | * step(cWhiteMaskThreshold, a); |
Andrew Zeng | f9f5822 | 2022-11-08 11:10:48 -0800 | [diff] [blame] | 155 | vec3 color = r * mix(uStartColor0, uEndColor0, uColorProgress) |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 156 | + g * mix(uStartColor1, uEndColor1, uColorProgress) |
| 157 | + b * mix(uStartColor2, uEndColor2, uColorProgress) |
| 158 | + a * mix(uStartColor3, uEndColor3, uColorProgress); |
Andrew Zeng | f9f5822 | 2022-11-08 11:10:48 -0800 | [diff] [blame] | 159 | color = mix(color, vec3((r + g + b + a) * 0.25), useWhiteMask); |
| 160 | gl_FragColor = vec4(color.x, color.y, color.z, (1.0 - uFade)); |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 161 | })"; |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 162 | static const char IMAGE_FRAG_SHADER_SOURCE[] = R"( |
| 163 | precision mediump float; |
| 164 | uniform sampler2D uTexture; |
| 165 | uniform float uFade; |
| 166 | varying highp vec2 vUv; |
| 167 | void main() { |
| 168 | vec4 color = texture2D(uTexture, vUv); |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 169 | gl_FragColor = vec4(color.x, color.y, color.z, (1.0 - uFade)) * color.a; |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 170 | })"; |
| 171 | static const char TEXT_FRAG_SHADER_SOURCE[] = R"( |
| 172 | precision mediump float; |
| 173 | uniform sampler2D uTexture; |
| 174 | uniform vec4 uCropArea; |
| 175 | varying highp vec2 vUv; |
| 176 | void main() { |
| 177 | vec2 uv = vec2(mix(uCropArea.x, uCropArea.z, vUv.x), |
| 178 | mix(uCropArea.y, uCropArea.w, vUv.y)); |
| 179 | gl_FragColor = texture2D(uTexture, uv); |
| 180 | })"; |
| 181 | |
| 182 | static GLfloat quadPositions[] = { |
| 183 | -0.5f, -0.5f, |
| 184 | +0.5f, -0.5f, |
| 185 | +0.5f, +0.5f, |
| 186 | +0.5f, +0.5f, |
| 187 | -0.5f, +0.5f, |
| 188 | -0.5f, -0.5f |
| 189 | }; |
| 190 | static GLfloat quadUVs[] = { |
| 191 | 0.0f, 1.0f, |
| 192 | 1.0f, 1.0f, |
| 193 | 1.0f, 0.0f, |
| 194 | 1.0f, 0.0f, |
| 195 | 0.0f, 0.0f, |
| 196 | 0.0f, 1.0f |
| 197 | }; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 198 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | // --------------------------------------------------------------------------- |
| 200 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 201 | BootAnimation::BootAnimation(sp<Callbacks> callbacks) |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 202 | : Thread(false), mLooper(new Looper(false)), mClockEnabled(true), mTimeIsAccurate(false), |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 203 | mTimeFormat12Hour(false), mTimeCheckThread(nullptr), mCallbacks(callbacks) { |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 204 | mSession = new SurfaceComposerClient(); |
Geoffrey Pitsch | 290c435 | 2016-08-09 14:35:10 -0400 | [diff] [blame] | 205 | |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 206 | std::string powerCtl = android::base::GetProperty("sys.powerctl", ""); |
| 207 | if (powerCtl.empty()) { |
| 208 | mShuttingDown = false; |
| 209 | } else { |
| 210 | mShuttingDown = true; |
| 211 | } |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 212 | ALOGD("%sAnimationStartTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
| 213 | elapsedRealtime()); |
| 214 | } |
| 215 | |
| 216 | BootAnimation::~BootAnimation() { |
| 217 | if (mAnimation != nullptr) { |
| 218 | releaseAnimation(mAnimation); |
| 219 | mAnimation = nullptr; |
| 220 | } |
| 221 | ALOGD("%sAnimationStopTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
| 222 | elapsedRealtime()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | } |
| 224 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | void BootAnimation::onFirstRef() { |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 226 | status_t err = mSession->linkToComposerDeath(this); |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 227 | SLOGE_IF(err, "linkToComposerDeath failed (%s) ", strerror(-err)); |
Mathias Agopian | 8434c53 | 2009-09-23 18:52:49 -0700 | [diff] [blame] | 228 | if (err == NO_ERROR) { |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 229 | // Load the animation content -- this can be slow (eg 200ms) |
| 230 | // called before waitForSurfaceFlinger() in main() to avoid wait |
| 231 | ALOGD("%sAnimationPreloadTiming start time: %" PRId64 "ms", |
| 232 | mShuttingDown ? "Shutdown" : "Boot", elapsedRealtime()); |
| 233 | preloadAnimation(); |
| 234 | ALOGD("%sAnimationPreloadStopTiming start time: %" PRId64 "ms", |
| 235 | mShuttingDown ? "Shutdown" : "Boot", elapsedRealtime()); |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 236 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | } |
| 238 | |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 239 | sp<SurfaceComposerClient> BootAnimation::session() const { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | return mSession; |
| 241 | } |
| 242 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 243 | void BootAnimation::binderDied(const wp<IBinder>&) { |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 244 | // woah, surfaceflinger died! |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 245 | SLOGD("SurfaceFlinger died, exiting..."); |
Mathias Agopian | bc72611 | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 246 | |
| 247 | // calling requestExit() is not enough here because the Surface code |
| 248 | // might be blocked on a condition variable that will never be updated. |
| 249 | kill( getpid(), SIGKILL ); |
| 250 | requestExit(); |
| 251 | } |
| 252 | |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 253 | static void* decodeImage(const void* encodedData, size_t dataLength, AndroidBitmapInfo* outInfo, |
| 254 | bool premultiplyAlpha) { |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 255 | AImageDecoder* decoder = nullptr; |
| 256 | AImageDecoder_createFromBuffer(encodedData, dataLength, &decoder); |
| 257 | if (!decoder) { |
| 258 | return nullptr; |
| 259 | } |
| 260 | |
| 261 | const AImageDecoderHeaderInfo* info = AImageDecoder_getHeaderInfo(decoder); |
| 262 | outInfo->width = AImageDecoderHeaderInfo_getWidth(info); |
| 263 | outInfo->height = AImageDecoderHeaderInfo_getHeight(info); |
| 264 | outInfo->format = AImageDecoderHeaderInfo_getAndroidBitmapFormat(info); |
| 265 | outInfo->stride = AImageDecoder_getMinimumStride(decoder); |
| 266 | outInfo->flags = 0; |
| 267 | |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 268 | if (!premultiplyAlpha) { |
| 269 | AImageDecoder_setUnpremultipliedRequired(decoder, true); |
| 270 | } |
| 271 | |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 272 | const size_t size = outInfo->stride * outInfo->height; |
| 273 | void* pixels = malloc(size); |
| 274 | int result = AImageDecoder_decodeImage(decoder, pixels, outInfo->stride, size); |
| 275 | AImageDecoder_delete(decoder); |
| 276 | |
| 277 | if (result != ANDROID_IMAGE_DECODER_SUCCESS) { |
| 278 | free(pixels); |
| 279 | return nullptr; |
| 280 | } |
| 281 | return pixels; |
| 282 | } |
| 283 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 284 | status_t BootAnimation::initTexture(Texture* texture, AssetManager& assets, |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 285 | const char* name, bool premultiplyAlpha) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | Asset* asset = assets.open(name, Asset::ACCESS_BUFFER); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 287 | if (asset == nullptr) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | return NO_INIT; |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 289 | |
| 290 | AndroidBitmapInfo bitmapInfo; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 291 | void* pixels = decodeImage(asset->getBuffer(false), asset->getLength(), &bitmapInfo, |
| 292 | premultiplyAlpha); |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 293 | auto pixelDeleter = std::unique_ptr<void, decltype(free)*>{ pixels, free }; |
| 294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 295 | asset->close(); |
| 296 | delete asset; |
| 297 | |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 298 | if (!pixels) { |
| 299 | return NO_INIT; |
| 300 | } |
| 301 | |
| 302 | const int w = bitmapInfo.width; |
| 303 | const int h = bitmapInfo.height; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | texture->w = w; |
| 306 | texture->h = h; |
| 307 | |
| 308 | glGenTextures(1, &texture->name); |
| 309 | glBindTexture(GL_TEXTURE_2D, texture->name); |
| 310 | |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 311 | switch (bitmapInfo.format) { |
| 312 | case ANDROID_BITMAP_FORMAT_A_8: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 314 | GL_UNSIGNED_BYTE, pixels); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | break; |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 316 | case ANDROID_BITMAP_FORMAT_RGBA_4444: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 317 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 318 | GL_UNSIGNED_SHORT_4_4_4_4, pixels); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 319 | break; |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 320 | case ANDROID_BITMAP_FORMAT_RGBA_8888: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 322 | GL_UNSIGNED_BYTE, pixels); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | break; |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 324 | case ANDROID_BITMAP_FORMAT_RGB_565: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 326 | GL_UNSIGNED_SHORT_5_6_5, pixels); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | break; |
| 328 | default: |
| 329 | break; |
| 330 | } |
| 331 | |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 332 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 333 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 334 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 335 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 336 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | return NO_ERROR; |
| 338 | } |
| 339 | |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 340 | status_t BootAnimation::initTexture(FileMap* map, int* width, int* height, |
| 341 | bool premultiplyAlpha) { |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 342 | AndroidBitmapInfo bitmapInfo; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 343 | void* pixels = decodeImage(map->getDataPtr(), map->getDataLength(), &bitmapInfo, |
| 344 | premultiplyAlpha); |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 345 | auto pixelDeleter = std::unique_ptr<void, decltype(free)*>{ pixels, free }; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 346 | |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 347 | // FileMap memory is never released until application exit. |
| 348 | // Release it now as the texture is already loaded and the memory used for |
| 349 | // the packed resource can be released. |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 350 | delete map; |
Mykola Kondratenko | 0c1eeb3 | 2014-04-15 09:35:44 +0200 | [diff] [blame] | 351 | |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 352 | if (!pixels) { |
| 353 | return NO_INIT; |
| 354 | } |
| 355 | |
| 356 | const int w = bitmapInfo.width; |
| 357 | const int h = bitmapInfo.height; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 358 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 359 | int tw = 1 << (31 - __builtin_clz(w)); |
| 360 | int th = 1 << (31 - __builtin_clz(h)); |
| 361 | if (tw < w) tw <<= 1; |
| 362 | if (th < h) th <<= 1; |
| 363 | |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 364 | switch (bitmapInfo.format) { |
| 365 | case ANDROID_BITMAP_FORMAT_RGBA_8888: |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 366 | if (!mUseNpotTextures && (tw != w || th != h)) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 367 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 368 | GL_UNSIGNED_BYTE, nullptr); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 369 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 370 | 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 371 | } else { |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 372 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 373 | GL_UNSIGNED_BYTE, pixels); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 374 | } |
| 375 | break; |
| 376 | |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 377 | case ANDROID_BITMAP_FORMAT_RGB_565: |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 378 | if (!mUseNpotTextures && (tw != w || th != h)) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 379 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB, |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 380 | GL_UNSIGNED_SHORT_5_6_5, nullptr); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 381 | glTexSubImage2D(GL_TEXTURE_2D, 0, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 382 | 0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, pixels); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 383 | } else { |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 384 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, |
Derek Sollenberger | 22d0d4c7 | 2020-04-08 10:53:46 -0400 | [diff] [blame] | 385 | GL_UNSIGNED_SHORT_5_6_5, pixels); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 386 | } |
| 387 | break; |
| 388 | default: |
| 389 | break; |
| 390 | } |
| 391 | |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 392 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 393 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 394 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 395 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 396 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 397 | *width = w; |
| 398 | *height = h; |
| 399 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 400 | return NO_ERROR; |
| 401 | } |
| 402 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 403 | class BootAnimation::DisplayEventCallback : public LooperCallback { |
| 404 | BootAnimation* mBootAnimation; |
| 405 | |
| 406 | public: |
| 407 | DisplayEventCallback(BootAnimation* bootAnimation) { |
| 408 | mBootAnimation = bootAnimation; |
| 409 | } |
| 410 | |
| 411 | int handleEvent(int /* fd */, int events, void* /* data */) { |
| 412 | if (events & (Looper::EVENT_ERROR | Looper::EVENT_HANGUP)) { |
| 413 | ALOGE("Display event receiver pipe was closed or an error occurred. events=0x%x", |
| 414 | events); |
| 415 | return 0; // remove the callback |
| 416 | } |
| 417 | |
| 418 | if (!(events & Looper::EVENT_INPUT)) { |
| 419 | ALOGW("Received spurious callback for unhandled poll event. events=0x%x", events); |
| 420 | return 1; // keep the callback |
| 421 | } |
| 422 | |
| 423 | constexpr int kBufferSize = 100; |
| 424 | DisplayEventReceiver::Event buffer[kBufferSize]; |
| 425 | ssize_t numEvents; |
| 426 | do { |
| 427 | numEvents = mBootAnimation->mDisplayEventReceiver->getEvents(buffer, kBufferSize); |
| 428 | for (size_t i = 0; i < static_cast<size_t>(numEvents); i++) { |
| 429 | const auto& event = buffer[i]; |
| 430 | if (event.header.type == DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG) { |
| 431 | SLOGV("Hotplug received"); |
| 432 | |
| 433 | if (!event.hotplug.connected) { |
| 434 | // ignore hotplug disconnect |
| 435 | continue; |
| 436 | } |
| 437 | auto token = SurfaceComposerClient::getPhysicalDisplayToken( |
| 438 | event.header.displayId); |
| 439 | |
| 440 | if (token != mBootAnimation->mDisplayToken) { |
| 441 | // ignore hotplug of a secondary display |
| 442 | continue; |
| 443 | } |
| 444 | |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 445 | DisplayMode displayMode; |
| 446 | const status_t error = SurfaceComposerClient::getActiveDisplayMode( |
| 447 | mBootAnimation->mDisplayToken, &displayMode); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 448 | if (error != NO_ERROR) { |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 449 | SLOGE("Can't get active display mode."); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 450 | } |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 451 | mBootAnimation->resizeSurface(displayMode.resolution.getWidth(), |
| 452 | displayMode.resolution.getHeight()); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | } while (numEvents > 0); |
| 456 | |
| 457 | return 1; // keep the callback |
| 458 | } |
| 459 | }; |
| 460 | |
| 461 | EGLConfig BootAnimation::getEglConfig(const EGLDisplay& display) { |
| 462 | const EGLint attribs[] = { |
Andrii Chepurnyi | d93f7b2 | 2023-03-15 11:22:07 +0200 | [diff] [blame^] | 463 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 464 | EGL_RED_SIZE, 8, |
| 465 | EGL_GREEN_SIZE, 8, |
| 466 | EGL_BLUE_SIZE, 8, |
| 467 | EGL_DEPTH_SIZE, 0, |
| 468 | EGL_NONE |
| 469 | }; |
| 470 | EGLint numConfigs; |
| 471 | EGLConfig config; |
| 472 | eglChooseConfig(display, attribs, &config, 1, &numConfigs); |
| 473 | return config; |
| 474 | } |
| 475 | |
Marin Shalamanov | 047802d | 2020-05-19 23:55:12 +0200 | [diff] [blame] | 476 | ui::Size BootAnimation::limitSurfaceSize(int width, int height) const { |
| 477 | ui::Size limited(width, height); |
| 478 | bool wasLimited = false; |
| 479 | const float aspectRatio = float(width) / float(height); |
| 480 | if (mMaxWidth != 0 && width > mMaxWidth) { |
| 481 | limited.height = mMaxWidth / aspectRatio; |
| 482 | limited.width = mMaxWidth; |
| 483 | wasLimited = true; |
| 484 | } |
| 485 | if (mMaxHeight != 0 && limited.height > mMaxHeight) { |
| 486 | limited.height = mMaxHeight; |
| 487 | limited.width = mMaxHeight * aspectRatio; |
| 488 | wasLimited = true; |
| 489 | } |
| 490 | SLOGV_IF(wasLimited, "Surface size has been limited to [%dx%d] from [%dx%d]", |
| 491 | limited.width, limited.height, width, height); |
| 492 | return limited; |
| 493 | } |
| 494 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 495 | status_t BootAnimation::readyToRun() { |
| 496 | mAssets.addDefaultAssets(); |
| 497 | |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 498 | mDisplayToken = SurfaceComposerClient::getInternalDisplayToken(); |
| 499 | if (mDisplayToken == nullptr) |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 500 | return NAME_NOT_FOUND; |
Dominik Laskowski | 3316a0a | 2019-01-25 02:56:41 -0800 | [diff] [blame] | 501 | |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 502 | DisplayMode displayMode; |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 503 | const status_t error = |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 504 | SurfaceComposerClient::getActiveDisplayMode(mDisplayToken, &displayMode); |
Dominik Laskowski | 69b281d | 2019-11-22 14:13:12 -0800 | [diff] [blame] | 505 | if (error != NO_ERROR) |
| 506 | return error; |
| 507 | |
Marin Shalamanov | 047802d | 2020-05-19 23:55:12 +0200 | [diff] [blame] | 508 | mMaxWidth = android::base::GetIntProperty("ro.surface_flinger.max_graphics_width", 0); |
| 509 | mMaxHeight = android::base::GetIntProperty("ro.surface_flinger.max_graphics_height", 0); |
Marin Shalamanov | cb783ca | 2021-01-29 21:26:07 +0100 | [diff] [blame] | 510 | ui::Size resolution = displayMode.resolution; |
Marin Shalamanov | 047802d | 2020-05-19 23:55:12 +0200 | [diff] [blame] | 511 | resolution = limitSurfaceSize(resolution.width, resolution.height); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | // create the native surface |
Jeff Brown | 0b722fe | 2012-08-24 22:40:14 -0700 | [diff] [blame] | 513 | sp<SurfaceControl> control = session()->createSurface(String8("BootAnimation"), |
xi yu | c341544 | 2022-05-09 08:58:02 +0000 | [diff] [blame] | 514 | resolution.getWidth(), resolution.getHeight(), PIXEL_FORMAT_RGB_565, |
| 515 | ISurfaceComposerClient::eOpaque); |
Mathias Agopian | 439863f | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 516 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 517 | SurfaceComposerClient::Transaction t; |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 518 | |
| 519 | // this guest property specifies multi-display IDs to show the boot animation |
| 520 | // multiple ids can be set with comma (,) as separator, for example: |
Huihong Luo | d4a217e | 2020-01-16 15:56:33 -0800 | [diff] [blame] | 521 | // setprop persist.boot.animation.displays 19260422155234049,19261083906282754 |
Marin Shalamanov | 11599ee | 2020-07-27 21:31:48 +0200 | [diff] [blame] | 522 | Vector<PhysicalDisplayId> physicalDisplayIds; |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 523 | char displayValue[PROPERTY_VALUE_MAX] = ""; |
Huihong Luo | d4a217e | 2020-01-16 15:56:33 -0800 | [diff] [blame] | 524 | property_get(DISPLAYS_PROP_NAME, displayValue, ""); |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 525 | bool isValid = displayValue[0] != '\0'; |
| 526 | if (isValid) { |
| 527 | char *p = displayValue; |
| 528 | while (*p) { |
| 529 | if (!isdigit(*p) && *p != ',') { |
| 530 | isValid = false; |
| 531 | break; |
| 532 | } |
| 533 | p ++; |
| 534 | } |
| 535 | if (!isValid) |
Huihong Luo | d4a217e | 2020-01-16 15:56:33 -0800 | [diff] [blame] | 536 | SLOGE("Invalid syntax for the value of system prop: %s", DISPLAYS_PROP_NAME); |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 537 | } |
| 538 | if (isValid) { |
| 539 | std::istringstream stream(displayValue); |
Marin Shalamanov | 11599ee | 2020-07-27 21:31:48 +0200 | [diff] [blame] | 540 | for (PhysicalDisplayId id; stream >> id.value; ) { |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 541 | physicalDisplayIds.add(id); |
| 542 | if (stream.peek() == ',') |
| 543 | stream.ignore(); |
| 544 | } |
| 545 | |
| 546 | // In the case of multi-display, boot animation shows on the specified displays |
| 547 | // in addition to the primary display |
Dominik Laskowski | 989de3d | 2021-07-27 21:09:34 -0700 | [diff] [blame] | 548 | const auto ids = SurfaceComposerClient::getPhysicalDisplayIds(); |
| 549 | for (const auto id : physicalDisplayIds) { |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 550 | if (std::find(ids.begin(), ids.end(), id) != ids.end()) { |
Dominik Laskowski | 989de3d | 2021-07-27 21:09:34 -0700 | [diff] [blame] | 551 | if (const auto token = SurfaceComposerClient::getPhysicalDisplayToken(id)) { |
| 552 | t.setDisplayLayerStack(token, ui::DEFAULT_LAYER_STACK); |
| 553 | } |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 554 | } |
| 555 | } |
Dominik Laskowski | 989de3d | 2021-07-27 21:09:34 -0700 | [diff] [blame] | 556 | t.setLayerStack(control, ui::DEFAULT_LAYER_STACK); |
Huihong Luo | f97c9e2 | 2019-05-29 11:08:01 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Robert Carr | e13b58e | 2017-08-31 14:50:44 -0700 | [diff] [blame] | 559 | t.setLayer(control, 0x40000000) |
| 560 | .apply(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 562 | sp<Surface> s = control->getSurface(); |
| 563 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 564 | // initialize opengl and egl |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 566 | eglInitialize(display, nullptr, nullptr); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 567 | EGLConfig config = getEglConfig(display); |
| 568 | EGLSurface surface = eglCreateWindowSurface(display, config, s.get(), nullptr); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 569 | // Initialize egl context with client version number 2.0. |
| 570 | EGLint contextAttributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; |
| 571 | EGLContext context = eglCreateContext(display, config, nullptr, contextAttributes); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 572 | EGLint w, h; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 573 | eglQuerySurface(display, surface, EGL_WIDTH, &w); |
| 574 | eglQuerySurface(display, surface, EGL_HEIGHT, &h); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 575 | |
Mathias Agopian | abac010 | 2009-07-31 14:47:00 -0700 | [diff] [blame] | 576 | if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) |
| 577 | return NO_INIT; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 578 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 579 | mDisplay = display; |
| 580 | mContext = context; |
| 581 | mSurface = surface; |
joenchen | 85b339f | 2022-04-11 23:58:34 +0800 | [diff] [blame] | 582 | mInitWidth = mWidth = w; |
| 583 | mInitHeight = mHeight = h; |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 584 | mFlingerSurfaceControl = control; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | mFlingerSurface = s; |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 586 | mTargetInset = -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | |
Mariia Sandrikova | a166f01 | 2022-12-10 02:32:14 +0000 | [diff] [blame] | 588 | // Rotate the boot animation according to the value specified in the sysprop |
| 589 | // ro.bootanim.set_orientation_<display_id>. Four values are supported: ORIENTATION_0, |
| 590 | // ORIENTATION_90, ORIENTATION_180 and ORIENTATION_270. |
| 591 | // If the value isn't specified or is ORIENTATION_0, nothing will be changed. |
| 592 | // This is needed to support having boot animation in orientations different from the natural |
| 593 | // device orientation. For example, on tablets that may want to keep natural orientation |
| 594 | // portrait for applications compatibility and to have the boot animation in landscape. |
| 595 | rotateAwayFromNaturalOrientationIfNeeded(); |
| 596 | |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 597 | projectSceneToWindow(); |
| 598 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 599 | // Register a display event receiver |
| 600 | mDisplayEventReceiver = std::make_unique<DisplayEventReceiver>(); |
| 601 | status_t status = mDisplayEventReceiver->initCheck(); |
| 602 | SLOGE_IF(status != NO_ERROR, "Initialization of DisplayEventReceiver failed with status: %d", |
| 603 | status); |
| 604 | mLooper->addFd(mDisplayEventReceiver->getFd(), 0, Looper::EVENT_INPUT, |
| 605 | new DisplayEventCallback(this), nullptr); |
| 606 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 607 | return NO_ERROR; |
| 608 | } |
| 609 | |
Mariia Sandrikova | a166f01 | 2022-12-10 02:32:14 +0000 | [diff] [blame] | 610 | void BootAnimation::rotateAwayFromNaturalOrientationIfNeeded() { |
| 611 | const auto orientation = parseOrientationProperty(); |
| 612 | |
| 613 | if (orientation == ui::ROTATION_0) { |
| 614 | // Do nothing if the sysprop isn't set or is set to ROTATION_0. |
| 615 | return; |
| 616 | } |
| 617 | |
| 618 | if (orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270) { |
| 619 | std::swap(mWidth, mHeight); |
| 620 | std::swap(mInitWidth, mInitHeight); |
| 621 | mFlingerSurfaceControl->updateDefaultBufferSize(mWidth, mHeight); |
| 622 | } |
| 623 | |
| 624 | Rect displayRect(0, 0, mWidth, mHeight); |
| 625 | Rect layerStackRect(0, 0, mWidth, mHeight); |
| 626 | |
| 627 | SurfaceComposerClient::Transaction t; |
| 628 | t.setDisplayProjection(mDisplayToken, orientation, layerStackRect, displayRect); |
| 629 | t.apply(); |
| 630 | } |
| 631 | |
| 632 | ui::Rotation BootAnimation::parseOrientationProperty() { |
| 633 | const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds(); |
| 634 | if (displayIds.size() == 0) { |
| 635 | return ui::ROTATION_0; |
| 636 | } |
| 637 | const auto displayId = displayIds[0]; |
| 638 | const auto syspropName = [displayId] { |
| 639 | std::stringstream ss; |
| 640 | ss << "ro.bootanim.set_orientation_" << displayId.value; |
| 641 | return ss.str(); |
| 642 | }(); |
| 643 | const auto syspropValue = android::base::GetProperty(syspropName, "ORIENTATION_0"); |
| 644 | if (syspropValue == "ORIENTATION_90") { |
| 645 | return ui::ROTATION_90; |
| 646 | } else if (syspropValue == "ORIENTATION_180") { |
| 647 | return ui::ROTATION_180; |
| 648 | } else if (syspropValue == "ORIENTATION_270") { |
| 649 | return ui::ROTATION_270; |
| 650 | } |
| 651 | return ui::ROTATION_0; |
| 652 | } |
| 653 | |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 654 | void BootAnimation::projectSceneToWindow() { |
| 655 | glViewport(0, 0, mWidth, mHeight); |
| 656 | glScissor(0, 0, mWidth, mHeight); |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 657 | } |
| 658 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 659 | void BootAnimation::resizeSurface(int newWidth, int newHeight) { |
| 660 | // We assume this function is called on the animation thread. |
| 661 | if (newWidth == mWidth && newHeight == mHeight) { |
| 662 | return; |
| 663 | } |
| 664 | SLOGV("Resizing the boot animation surface to %d %d", newWidth, newHeight); |
| 665 | |
| 666 | eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 667 | eglDestroySurface(mDisplay, mSurface); |
| 668 | |
joenchen | 85b339f | 2022-04-11 23:58:34 +0800 | [diff] [blame] | 669 | mFlingerSurfaceControl->updateDefaultBufferSize(newWidth, newHeight); |
Marin Shalamanov | 047802d | 2020-05-19 23:55:12 +0200 | [diff] [blame] | 670 | const auto limitedSize = limitSurfaceSize(newWidth, newHeight); |
| 671 | mWidth = limitedSize.width; |
| 672 | mHeight = limitedSize.height; |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 673 | |
| 674 | SurfaceComposerClient::Transaction t; |
| 675 | t.setSize(mFlingerSurfaceControl, mWidth, mHeight); |
| 676 | t.apply(); |
| 677 | |
| 678 | EGLConfig config = getEglConfig(mDisplay); |
| 679 | EGLSurface surface = eglCreateWindowSurface(mDisplay, config, mFlingerSurface.get(), nullptr); |
| 680 | if (eglMakeCurrent(mDisplay, surface, surface, mContext) == EGL_FALSE) { |
| 681 | SLOGE("Can't make the new surface current. Error %d", eglGetError()); |
| 682 | return; |
| 683 | } |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 684 | |
| 685 | projectSceneToWindow(); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 686 | |
| 687 | mSurface = surface; |
| 688 | } |
| 689 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 690 | bool BootAnimation::preloadAnimation() { |
| 691 | findBootAnimationFile(); |
| 692 | if (!mZipFileName.isEmpty()) { |
| 693 | mAnimation = loadAnimation(mZipFileName); |
| 694 | return (mAnimation != nullptr); |
| 695 | } |
| 696 | |
| 697 | return false; |
| 698 | } |
| 699 | |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame] | 700 | bool BootAnimation::findBootAnimationFileInternal(const std::vector<std::string> &files) { |
| 701 | for (const std::string& f : files) { |
| 702 | if (access(f.c_str(), R_OK) == 0) { |
| 703 | mZipFileName = f.c_str(); |
| 704 | return true; |
| 705 | } |
| 706 | } |
| 707 | return false; |
| 708 | } |
| 709 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 710 | void BootAnimation::findBootAnimationFile() { |
Elliott Hughes | c367d48 | 2013-10-29 13:12:55 -0700 | [diff] [blame] | 711 | // If the device has encryption turned on or is in process |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 712 | // of being encrypted we show the encrypted boot animation. |
| 713 | char decrypt[PROPERTY_VALUE_MAX]; |
| 714 | property_get("vold.decrypt", decrypt, ""); |
| 715 | |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 716 | bool encryptedAnimation = atoi(decrypt) != 0 || |
| 717 | !strcmp("trigger_restart_min_framework", decrypt); |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 718 | |
Jaekyun Seok | c521bb3 | 2018-01-30 11:52:47 +0900 | [diff] [blame] | 719 | if (!mShuttingDown && encryptedAnimation) { |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame] | 720 | static const std::vector<std::string> encryptedBootFiles = { |
| 721 | PRODUCT_ENCRYPTED_BOOTANIMATION_FILE, SYSTEM_ENCRYPTED_BOOTANIMATION_FILE, |
| 722 | }; |
| 723 | if (findBootAnimationFileInternal(encryptedBootFiles)) { |
| 724 | return; |
Jaekyun Seok | c521bb3 | 2018-01-30 11:52:47 +0900 | [diff] [blame] | 725 | } |
Jason parks | bd9a08d | 2011-01-31 15:04:34 -0600 | [diff] [blame] | 726 | } |
Beverly | 34ffe25 | 2019-05-17 11:03:54 -0400 | [diff] [blame] | 727 | |
| 728 | const bool playDarkAnim = android::base::GetIntProperty("ro.boot.theme", 0) == 1; |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame] | 729 | static const std::vector<std::string> bootFiles = { |
| 730 | APEX_BOOTANIMATION_FILE, playDarkAnim ? PRODUCT_BOOTANIMATION_DARK_FILE : PRODUCT_BOOTANIMATION_FILE, |
| 731 | OEM_BOOTANIMATION_FILE, SYSTEM_BOOTANIMATION_FILE |
| 732 | }; |
| 733 | static const std::vector<std::string> shutdownFiles = { |
| 734 | PRODUCT_SHUTDOWNANIMATION_FILE, OEM_SHUTDOWNANIMATION_FILE, SYSTEM_SHUTDOWNANIMATION_FILE, "" |
| 735 | }; |
| 736 | static const std::vector<std::string> userspaceRebootFiles = { |
| 737 | PRODUCT_USERSPACE_REBOOT_ANIMATION_FILE, OEM_USERSPACE_REBOOT_ANIMATION_FILE, |
| 738 | SYSTEM_USERSPACE_REBOOT_ANIMATION_FILE, |
| 739 | }; |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 740 | |
Nikita Ioffe | 06c986e | 2020-01-27 17:16:03 +0000 | [diff] [blame] | 741 | if (android::base::GetBoolProperty("sys.init.userspace_reboot.in_progress", false)) { |
| 742 | findBootAnimationFileInternal(userspaceRebootFiles); |
| 743 | } else if (mShuttingDown) { |
| 744 | findBootAnimationFileInternal(shutdownFiles); |
| 745 | } else { |
| 746 | findBootAnimationFileInternal(bootFiles); |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 747 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 750 | GLuint compileShader(GLenum shaderType, const GLchar *source) { |
| 751 | GLuint shader = glCreateShader(shaderType); |
| 752 | glShaderSource(shader, 1, &source, 0); |
| 753 | glCompileShader(shader); |
| 754 | GLint isCompiled = 0; |
| 755 | glGetShaderiv(shader, GL_COMPILE_STATUS, &isCompiled); |
| 756 | if (isCompiled == GL_FALSE) { |
| 757 | SLOGE("Compile shader failed. Shader type: %d", shaderType); |
Shan Huang | 81846ba | 2021-09-07 19:07:47 +0000 | [diff] [blame] | 758 | GLint maxLength = 0; |
| 759 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength); |
| 760 | std::vector<GLchar> errorLog(maxLength); |
| 761 | glGetShaderInfoLog(shader, maxLength, &maxLength, &errorLog[0]); |
| 762 | SLOGE("Shader compilation error: %s", &errorLog[0]); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 763 | return 0; |
| 764 | } |
| 765 | return shader; |
| 766 | } |
| 767 | |
| 768 | GLuint linkShader(GLuint vertexShader, GLuint fragmentShader) { |
| 769 | GLuint program = glCreateProgram(); |
| 770 | glAttachShader(program, vertexShader); |
| 771 | glAttachShader(program, fragmentShader); |
| 772 | glLinkProgram(program); |
| 773 | GLint isLinked = 0; |
| 774 | glGetProgramiv(program, GL_LINK_STATUS, (int *)&isLinked); |
| 775 | if (isLinked == GL_FALSE) { |
| 776 | SLOGE("Linking shader failed. Shader handles: vert %d, frag %d", |
| 777 | vertexShader, fragmentShader); |
| 778 | return 0; |
| 779 | } |
| 780 | return program; |
| 781 | } |
| 782 | |
| 783 | void BootAnimation::initShaders() { |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 784 | bool dynamicColoringEnabled = mAnimation != nullptr && mAnimation->dynamicColoringEnabled; |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 785 | GLuint vertexShader = compileShader(GL_VERTEX_SHADER, (const GLchar *)VERTEX_SHADER_SOURCE); |
| 786 | GLuint imageFragmentShader = |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 787 | compileShader(GL_FRAGMENT_SHADER, dynamicColoringEnabled |
| 788 | ? (const GLchar *)IMAGE_FRAG_DYNAMIC_COLORING_SHADER_SOURCE |
| 789 | : (const GLchar *)IMAGE_FRAG_SHADER_SOURCE); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 790 | GLuint textFragmentShader = |
| 791 | compileShader(GL_FRAGMENT_SHADER, (const GLchar *)TEXT_FRAG_SHADER_SOURCE); |
| 792 | |
| 793 | // Initialize image shader. |
| 794 | mImageShader = linkShader(vertexShader, imageFragmentShader); |
| 795 | GLint positionLocation = glGetAttribLocation(mImageShader, A_POSITION); |
| 796 | GLint uvLocation = glGetAttribLocation(mImageShader, A_UV); |
| 797 | mImageTextureLocation = glGetUniformLocation(mImageShader, U_TEXTURE); |
| 798 | mImageFadeLocation = glGetUniformLocation(mImageShader, U_FADE); |
| 799 | glEnableVertexAttribArray(positionLocation); |
| 800 | glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, quadPositions); |
| 801 | glVertexAttribPointer(uvLocation, 2, GL_FLOAT, GL_FALSE, 0, quadUVs); |
| 802 | glEnableVertexAttribArray(uvLocation); |
| 803 | |
| 804 | // Initialize text shader. |
| 805 | mTextShader = linkShader(vertexShader, textFragmentShader); |
| 806 | positionLocation = glGetAttribLocation(mTextShader, A_POSITION); |
| 807 | uvLocation = glGetAttribLocation(mTextShader, A_UV); |
| 808 | mTextTextureLocation = glGetUniformLocation(mTextShader, U_TEXTURE); |
| 809 | mTextCropAreaLocation = glGetUniformLocation(mTextShader, U_CROP_AREA); |
| 810 | glEnableVertexAttribArray(positionLocation); |
| 811 | glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, quadPositions); |
| 812 | glVertexAttribPointer(uvLocation, 2, GL_FLOAT, GL_FALSE, 0, quadUVs); |
| 813 | glEnableVertexAttribArray(uvLocation); |
| 814 | } |
| 815 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 816 | bool BootAnimation::threadLoop() { |
| 817 | bool result; |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 818 | initShaders(); |
| 819 | |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 820 | // We have no bootanimation file, so we use the stock android logo |
| 821 | // animation. |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 822 | if (mZipFileName.isEmpty()) { |
Yoshiaki Maruoka | 9ef19b8 | 2017-10-25 13:55:49 +0900 | [diff] [blame] | 823 | ALOGD("No animation file"); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 824 | result = android(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 825 | } else { |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 826 | result = movie(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 827 | } |
| 828 | |
Philip Junker | 6060056 | 2020-11-25 18:16:16 +0100 | [diff] [blame] | 829 | mCallbacks->shutdown(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 830 | eglMakeCurrent(mDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 831 | eglDestroyContext(mDisplay, mContext); |
| 832 | eglDestroySurface(mDisplay, mSurface); |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 833 | mFlingerSurface.clear(); |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 834 | mFlingerSurfaceControl.clear(); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 835 | eglTerminate(mDisplay); |
Sai Kiran Korwar | 3eee9fb | 2015-06-16 17:13:35 +0530 | [diff] [blame] | 836 | eglReleaseThread(); |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 837 | IPCThreadState::self()->stopProcess(); |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 838 | return result; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 839 | } |
| 840 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 841 | bool BootAnimation::android() { |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 842 | glActiveTexture(GL_TEXTURE0); |
| 843 | |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 844 | SLOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
Keun-young Park | d1794cd | 2017-04-04 12:21:19 -0700 | [diff] [blame] | 845 | elapsedRealtime()); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 846 | initTexture(&mAndroid[0], mAssets, "images/android-logo-mask.png"); |
| 847 | initTexture(&mAndroid[1], mAssets, "images/android-logo-shine.png"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 848 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 849 | mCallbacks->init({}); |
| 850 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 851 | // clear screen |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 852 | glDisable(GL_DITHER); |
| 853 | glDisable(GL_SCISSOR_TEST); |
Shan Huang | bfd2d3c | 2021-09-09 23:19:04 +0000 | [diff] [blame] | 854 | glUseProgram(mImageShader); |
| 855 | |
Mathias Agopian | 59f19e4 | 2011-05-06 19:22:12 -0700 | [diff] [blame] | 856 | glClearColor(0,0,0,1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 857 | glClear(GL_COLOR_BUFFER_BIT); |
| 858 | eglSwapBuffers(mDisplay, mSurface); |
| 859 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 860 | // Blend state |
| 861 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 862 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 863 | const nsecs_t startTime = systemTime(); |
| 864 | do { |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 865 | processDisplayEvents(); |
| 866 | const GLint xc = (mWidth - mAndroid[0].w) / 2; |
| 867 | const GLint yc = (mHeight - mAndroid[0].h) / 2; |
| 868 | const Rect updateRect(xc, yc, xc + mAndroid[0].w, yc + mAndroid[0].h); |
| 869 | glScissor(updateRect.left, mHeight - updateRect.bottom, updateRect.width(), |
| 870 | updateRect.height()); |
| 871 | |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 872 | nsecs_t now = systemTime(); |
| 873 | double time = now - startTime; |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 874 | float t = 4.0f * float(time / us2ns(16667)) / mAndroid[1].w; |
| 875 | GLint offset = (1 - (t - floorf(t))) * mAndroid[1].w; |
| 876 | GLint x = xc - offset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 877 | |
Mathias Agopian | 8166864 | 2009-07-28 11:41:30 -0700 | [diff] [blame] | 878 | glDisable(GL_SCISSOR_TEST); |
| 879 | glClear(GL_COLOR_BUFFER_BIT); |
| 880 | |
| 881 | glEnable(GL_SCISSOR_TEST); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 882 | glDisable(GL_BLEND); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 883 | glBindTexture(GL_TEXTURE_2D, mAndroid[1].name); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 884 | drawTexturedQuad(x, yc, mAndroid[1].w, mAndroid[1].h); |
| 885 | drawTexturedQuad(x + mAndroid[1].w, yc, mAndroid[1].w, mAndroid[1].h); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | |
Mathias Agopian | b2cf954 | 2009-03-24 18:34:16 -0700 | [diff] [blame] | 887 | glEnable(GL_BLEND); |
| 888 | glBindTexture(GL_TEXTURE_2D, mAndroid[0].name); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 889 | drawTexturedQuad(xc, yc, mAndroid[0].w, mAndroid[0].h); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 890 | |
Mathias Agopian | 627e7b5 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 891 | EGLBoolean res = eglSwapBuffers(mDisplay, mSurface); |
| 892 | if (res == EGL_FALSE) |
| 893 | break; |
| 894 | |
Mathias Agopian | 1379665 | 2009-03-24 22:49:21 -0700 | [diff] [blame] | 895 | // 12fps: don't animate too fast to preserve CPU |
| 896 | const nsecs_t sleepTime = 83333 - ns2us(systemTime() - now); |
| 897 | if (sleepTime > 0) |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 898 | usleep(sleepTime); |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 899 | |
| 900 | checkExit(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | } while (!exitPending()); |
| 902 | |
| 903 | glDeleteTextures(1, &mAndroid[0].name); |
| 904 | glDeleteTextures(1, &mAndroid[1].name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 905 | return false; |
| 906 | } |
| 907 | |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 908 | void BootAnimation::checkExit() { |
| 909 | // Allow surface flinger to gracefully request shutdown |
| 910 | char value[PROPERTY_VALUE_MAX]; |
| 911 | property_get(EXIT_PROP_NAME, value, "0"); |
| 912 | int exitnow = atoi(value); |
| 913 | if (exitnow) { |
| 914 | requestExit(); |
| 915 | } |
| 916 | } |
| 917 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 918 | bool BootAnimation::validClock(const Animation::Part& part) { |
| 919 | return part.clockPosX != TEXT_MISSING_VALUE && part.clockPosY != TEXT_MISSING_VALUE; |
| 920 | } |
| 921 | |
| 922 | bool parseTextCoord(const char* str, int* dest) { |
| 923 | if (strcmp("c", str) == 0) { |
| 924 | *dest = TEXT_CENTER_VALUE; |
| 925 | return true; |
| 926 | } |
| 927 | |
| 928 | char* end; |
| 929 | int val = (int) strtol(str, &end, 0); |
| 930 | if (end == str || *end != '\0' || val == INT_MAX || val == INT_MIN) { |
| 931 | return false; |
| 932 | } |
| 933 | *dest = val; |
| 934 | return true; |
| 935 | } |
| 936 | |
| 937 | // Parse two position coordinates. If only string is non-empty, treat it as the y value. |
| 938 | void parsePosition(const char* str1, const char* str2, int* x, int* y) { |
| 939 | bool success = false; |
| 940 | if (strlen(str1) == 0) { // No values were specified |
| 941 | // success = false |
| 942 | } else if (strlen(str2) == 0) { // we have only one value |
| 943 | if (parseTextCoord(str1, y)) { |
| 944 | *x = TEXT_CENTER_VALUE; |
| 945 | success = true; |
| 946 | } |
| 947 | } else { |
| 948 | if (parseTextCoord(str1, x) && parseTextCoord(str2, y)) { |
| 949 | success = true; |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | if (!success) { |
| 954 | *x = TEXT_MISSING_VALUE; |
| 955 | *y = TEXT_MISSING_VALUE; |
| 956 | } |
| 957 | } |
| 958 | |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 959 | // Parse a color represented as an HTML-style 'RRGGBB' string: each pair of |
| 960 | // characters in str is a hex number in [0, 255], which are converted to |
| 961 | // floating point values in the range [0.0, 1.0] and placed in the |
| 962 | // corresponding elements of color. |
| 963 | // |
| 964 | // If the input string isn't valid, parseColor returns false and color is |
| 965 | // left unchanged. |
| 966 | static bool parseColor(const char str[7], float color[3]) { |
| 967 | float tmpColor[3]; |
| 968 | for (int i = 0; i < 3; i++) { |
| 969 | int val = 0; |
| 970 | for (int j = 0; j < 2; j++) { |
| 971 | val *= 16; |
| 972 | char c = str[2*i + j]; |
| 973 | if (c >= '0' && c <= '9') val += c - '0'; |
| 974 | else if (c >= 'A' && c <= 'F') val += (c - 'A') + 10; |
| 975 | else if (c >= 'a' && c <= 'f') val += (c - 'a') + 10; |
| 976 | else return false; |
| 977 | } |
| 978 | tmpColor[i] = static_cast<float>(val) / 255.0f; |
| 979 | } |
| 980 | memcpy(color, tmpColor, sizeof(tmpColor)); |
| 981 | return true; |
| 982 | } |
| 983 | |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 984 | // Parse a color represented as a signed decimal int string. |
| 985 | // E.g. "-2757722" (whose hex 2's complement is 0xFFD5EBA6). |
| 986 | // If the input color string is empty, set color with values in defaultColor. |
| 987 | static void parseColorDecimalString(const std::string& colorString, |
| 988 | float color[3], float defaultColor[3]) { |
| 989 | if (colorString == "") { |
| 990 | memcpy(color, defaultColor, sizeof(float) * 3); |
| 991 | return; |
| 992 | } |
| 993 | int colorInt = atoi(colorString.c_str()); |
| 994 | color[0] = ((float)((colorInt >> 16) & 0xFF)) / 0xFF; // r |
| 995 | color[1] = ((float)((colorInt >> 8) & 0xFF)) / 0xFF; // g |
| 996 | color[2] = ((float)(colorInt & 0xFF)) / 0xFF; // b |
| 997 | } |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 998 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 999 | static bool readFile(ZipFileRO* zip, const char* name, String8& outString) { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1000 | ZipEntryRO entry = zip->findEntryByName(name); |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1001 | SLOGE_IF(!entry, "couldn't find %s", name); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1002 | if (!entry) { |
| 1003 | return false; |
| 1004 | } |
| 1005 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1006 | FileMap* entryMap = zip->createEntryFileMap(entry); |
| 1007 | zip->releaseEntry(entry); |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1008 | SLOGE_IF(!entryMap, "entryMap is null"); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1009 | if (!entryMap) { |
| 1010 | return false; |
| 1011 | } |
| 1012 | |
| 1013 | outString.setTo((char const*)entryMap->getDataPtr(), entryMap->getDataLength()); |
Narayan Kamath | 688ff4c | 2015-02-23 15:47:54 +0000 | [diff] [blame] | 1014 | delete entryMap; |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1015 | return true; |
| 1016 | } |
| 1017 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1018 | // The font image should be a 96x2 array of character images. The |
| 1019 | // columns are the printable ASCII characters 0x20 - 0x7f. The |
| 1020 | // top row is regular text; the bottom row is bold. |
| 1021 | status_t BootAnimation::initFont(Font* font, const char* fallback) { |
| 1022 | status_t status = NO_ERROR; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1023 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1024 | if (font->map != nullptr) { |
| 1025 | glGenTextures(1, &font->texture.name); |
| 1026 | glBindTexture(GL_TEXTURE_2D, font->texture.name); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1027 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1028 | status = initTexture(font->map, &font->texture.w, &font->texture.h); |
| 1029 | |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1030 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1031 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1032 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1033 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1034 | } else if (fallback != nullptr) { |
| 1035 | status = initTexture(&font->texture, mAssets, fallback); |
| 1036 | } else { |
| 1037 | return NO_INIT; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1038 | } |
| 1039 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1040 | if (status == NO_ERROR) { |
| 1041 | font->char_width = font->texture.w / FONT_NUM_COLS; |
| 1042 | font->char_height = font->texture.h / FONT_NUM_ROWS / 2; // There are bold and regular rows |
| 1043 | } |
| 1044 | |
| 1045 | return status; |
| 1046 | } |
| 1047 | |
| 1048 | void BootAnimation::drawText(const char* str, const Font& font, bool bold, int* x, int* y) { |
| 1049 | glEnable(GL_BLEND); // Allow us to draw on top of the animation |
| 1050 | glBindTexture(GL_TEXTURE_2D, font.texture.name); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1051 | glUseProgram(mTextShader); |
| 1052 | glUniform1i(mTextTextureLocation, 0); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1053 | |
| 1054 | const int len = strlen(str); |
| 1055 | const int strWidth = font.char_width * len; |
| 1056 | |
| 1057 | if (*x == TEXT_CENTER_VALUE) { |
| 1058 | *x = (mWidth - strWidth) / 2; |
| 1059 | } else if (*x < 0) { |
| 1060 | *x = mWidth + *x - strWidth; |
| 1061 | } |
| 1062 | if (*y == TEXT_CENTER_VALUE) { |
| 1063 | *y = (mHeight - font.char_height) / 2; |
| 1064 | } else if (*y < 0) { |
| 1065 | *y = mHeight + *y - font.char_height; |
| 1066 | } |
| 1067 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1068 | for (int i = 0; i < len; i++) { |
| 1069 | char c = str[i]; |
| 1070 | |
| 1071 | if (c < FONT_BEGIN_CHAR || c > FONT_END_CHAR) { |
| 1072 | c = '?'; |
| 1073 | } |
| 1074 | |
| 1075 | // Crop the texture to only the pixels in the current glyph |
| 1076 | const int charPos = (c - FONT_BEGIN_CHAR); // Position in the list of valid characters |
| 1077 | const int row = charPos / FONT_NUM_COLS; |
| 1078 | const int col = charPos % FONT_NUM_COLS; |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1079 | // Bold fonts are expected in the second half of each row. |
| 1080 | float v0 = (row + (bold ? 0.5f : 0.0f)) / FONT_NUM_ROWS; |
| 1081 | float u0 = ((float)col) / FONT_NUM_COLS; |
| 1082 | float v1 = v0 + 1.0f / FONT_NUM_ROWS / 2; |
| 1083 | float u1 = u0 + 1.0f / FONT_NUM_COLS; |
| 1084 | glUniform4f(mTextCropAreaLocation, u0, v0, u1, v1); |
| 1085 | drawTexturedQuad(*x, *y, font.char_width, font.char_height); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1086 | |
| 1087 | *x += font.char_width; |
| 1088 | } |
| 1089 | |
| 1090 | glDisable(GL_BLEND); // Return to the animation's default behaviour |
| 1091 | glBindTexture(GL_TEXTURE_2D, 0); |
| 1092 | } |
| 1093 | |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 1094 | // We render 12 or 24 hour time. |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1095 | void BootAnimation::drawClock(const Font& font, const int xPos, const int yPos) { |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 1096 | static constexpr char TIME_FORMAT_12[] = "%l:%M"; |
| 1097 | static constexpr char TIME_FORMAT_24[] = "%H:%M"; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1098 | static constexpr int TIME_LENGTH = 6; |
| 1099 | |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1100 | time_t rawtime; |
| 1101 | time(&rawtime); |
| 1102 | struct tm* timeInfo = localtime(&rawtime); |
| 1103 | |
| 1104 | char timeBuff[TIME_LENGTH]; |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 1105 | const char* timeFormat = mTimeFormat12Hour ? TIME_FORMAT_12 : TIME_FORMAT_24; |
| 1106 | size_t length = strftime(timeBuff, TIME_LENGTH, timeFormat, timeInfo); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1107 | |
| 1108 | if (length != TIME_LENGTH - 1) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1109 | SLOGE("Couldn't format time; abandoning boot animation clock"); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1110 | mClockEnabled = false; |
| 1111 | return; |
| 1112 | } |
| 1113 | |
Damien Bargiacchi | 45a7644 | 2016-12-05 18:02:18 -0800 | [diff] [blame] | 1114 | char* out = timeBuff[0] == ' ' ? &timeBuff[1] : &timeBuff[0]; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1115 | int x = xPos; |
| 1116 | int y = yPos; |
Damien Bargiacchi | 45a7644 | 2016-12-05 18:02:18 -0800 | [diff] [blame] | 1117 | drawText(out, font, false, &x, &y); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1118 | } |
| 1119 | |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1120 | void BootAnimation::drawProgress(int percent, const Font& font, const int xPos, const int yPos) { |
| 1121 | static constexpr int PERCENT_LENGTH = 5; |
| 1122 | |
| 1123 | char percentBuff[PERCENT_LENGTH]; |
| 1124 | // ';' has the ascii code just after ':', and the font resource contains '%' |
| 1125 | // for that ascii code. |
| 1126 | sprintf(percentBuff, "%d;", percent); |
| 1127 | int x = xPos; |
| 1128 | int y = yPos; |
| 1129 | drawText(percentBuff, font, false, &x, &y); |
| 1130 | } |
| 1131 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1132 | bool BootAnimation::parseAnimationDesc(Animation& animation) { |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1133 | String8 desString; |
| 1134 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1135 | if (!readFile(animation.zip, "desc.txt", desString)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1136 | return false; |
| 1137 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1138 | char const* s = desString.string(); |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1139 | std::string dynamicColoringPartName = ""; |
| 1140 | bool postDynamicColoring = false; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1141 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1142 | // Parse the description file |
| 1143 | for (;;) { |
| 1144 | const char* endl = strstr(s, "\n"); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1145 | if (endl == nullptr) break; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1146 | String8 line(s, endl - s); |
| 1147 | const char* l = line.string(); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1148 | int fps = 0; |
| 1149 | int width = 0; |
| 1150 | int height = 0; |
| 1151 | int count = 0; |
| 1152 | int pause = 0; |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1153 | int progress = 0; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1154 | int framesToFadeCount = 0; |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 1155 | int colorTransitionStart = 0; |
| 1156 | int colorTransitionEnd = 0; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1157 | char path[ANIM_ENTRY_NAME_MAX]; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 1158 | char color[7] = "000000"; // default to black if unspecified |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1159 | char clockPos1[TEXT_POS_LEN_MAX + 1] = ""; |
| 1160 | char clockPos2[TEXT_POS_LEN_MAX + 1] = ""; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1161 | char dynamicColoringPartNameBuffer[ANIM_ENTRY_NAME_MAX]; |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1162 | char pathType; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1163 | // start colors default to black if unspecified |
| 1164 | char start_color_0[7] = "000000"; |
| 1165 | char start_color_1[7] = "000000"; |
| 1166 | char start_color_2[7] = "000000"; |
| 1167 | char start_color_3[7] = "000000"; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1168 | |
| 1169 | int nextReadPos; |
| 1170 | |
yidong zhang | 87bb346 | 2022-12-07 15:55:31 +0800 | [diff] [blame] | 1171 | if (strlen(l) == 0) { |
| 1172 | s = ++endl; |
| 1173 | continue; |
| 1174 | } |
| 1175 | |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1176 | int topLineNumbers = sscanf(l, "%d %d %d %d", &width, &height, &fps, &progress); |
| 1177 | if (topLineNumbers == 3 || topLineNumbers == 4) { |
| 1178 | // SLOGD("> w=%d, h=%d, fps=%d, progress=%d", width, height, fps, progress); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1179 | animation.width = width; |
| 1180 | animation.height = height; |
| 1181 | animation.fps = fps; |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1182 | if (topLineNumbers == 4) { |
| 1183 | animation.progressEnabled = (progress != 0); |
| 1184 | } else { |
| 1185 | animation.progressEnabled = false; |
| 1186 | } |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 1187 | } else if (sscanf(l, "dynamic_colors %" STRTO(ANIM_PATH_MAX) "s #%6s #%6s #%6s #%6s %d %d", |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1188 | dynamicColoringPartNameBuffer, |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 1189 | start_color_0, start_color_1, start_color_2, start_color_3, |
| 1190 | &colorTransitionStart, &colorTransitionEnd)) { |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1191 | animation.dynamicColoringEnabled = true; |
| 1192 | parseColor(start_color_0, animation.startColors[0]); |
| 1193 | parseColor(start_color_1, animation.startColors[1]); |
| 1194 | parseColor(start_color_2, animation.startColors[2]); |
| 1195 | parseColor(start_color_3, animation.startColors[3]); |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 1196 | animation.colorTransitionStart = colorTransitionStart; |
| 1197 | animation.colorTransitionEnd = colorTransitionEnd; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1198 | dynamicColoringPartName = std::string(dynamicColoringPartNameBuffer); |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1199 | } else if (sscanf(l, "%c %d %d %" STRTO(ANIM_PATH_MAX) "s%n", |
| 1200 | &pathType, &count, &pause, path, &nextReadPos) >= 4) { |
| 1201 | if (pathType == 'f') { |
| 1202 | sscanf(l + nextReadPos, " %d #%6s %16s %16s", &framesToFadeCount, color, clockPos1, |
| 1203 | clockPos2); |
| 1204 | } else { |
| 1205 | sscanf(l + nextReadPos, " #%6s %16s %16s", color, clockPos1, clockPos2); |
| 1206 | } |
| 1207 | // SLOGD("> type=%c, count=%d, pause=%d, path=%s, framesToFadeCount=%d, color=%s, " |
| 1208 | // "clockPos1=%s, clockPos2=%s", |
| 1209 | // pathType, count, pause, path, framesToFadeCount, color, clockPos1, clockPos2); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1210 | Animation::Part part; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1211 | if (path == dynamicColoringPartName) { |
| 1212 | // Part is specified to use dynamic coloring. |
| 1213 | part.useDynamicColoring = true; |
| 1214 | part.postDynamicColoring = false; |
| 1215 | postDynamicColoring = true; |
| 1216 | } else { |
| 1217 | // Part does not use dynamic coloring. |
| 1218 | part.useDynamicColoring = false; |
| 1219 | part.postDynamicColoring = postDynamicColoring; |
| 1220 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1221 | part.playUntilComplete = pathType == 'c'; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1222 | part.framesToFadeCount = framesToFadeCount; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1223 | part.count = count; |
| 1224 | part.pause = pause; |
| 1225 | part.path = path; |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1226 | part.audioData = nullptr; |
| 1227 | part.animation = nullptr; |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 1228 | if (!parseColor(color, part.backgroundColor)) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1229 | SLOGE("> invalid color '#%s'", color); |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 1230 | part.backgroundColor[0] = 0.0f; |
| 1231 | part.backgroundColor[1] = 0.0f; |
| 1232 | part.backgroundColor[2] = 0.0f; |
| 1233 | } |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1234 | parsePosition(clockPos1, clockPos2, &part.clockPosX, &part.clockPosY); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1235 | animation.parts.add(part); |
| 1236 | } |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1237 | else if (strcmp(l, "$SYSTEM") == 0) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1238 | // SLOGD("> SYSTEM"); |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1239 | Animation::Part part; |
| 1240 | part.playUntilComplete = false; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1241 | part.framesToFadeCount = 0; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1242 | part.count = 1; |
| 1243 | part.pause = 0; |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1244 | part.audioData = nullptr; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1245 | part.animation = loadAnimation(String8(SYSTEM_BOOTANIMATION_FILE)); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1246 | if (part.animation != nullptr) |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1247 | animation.parts.add(part); |
| 1248 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1249 | s = ++endl; |
| 1250 | } |
| 1251 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1252 | return true; |
| 1253 | } |
| 1254 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1255 | bool BootAnimation::preloadZip(Animation& animation) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1256 | // read all the data structures |
| 1257 | const size_t pcount = animation.parts.size(); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1258 | void *cookie = nullptr; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1259 | ZipFileRO* zip = animation.zip; |
| 1260 | if (!zip->startIteration(&cookie)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1261 | return false; |
| 1262 | } |
| 1263 | |
| 1264 | ZipEntryRO entry; |
| 1265 | char name[ANIM_ENTRY_NAME_MAX]; |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1266 | while ((entry = zip->nextEntry(cookie)) != nullptr) { |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1267 | const int foundEntryName = zip->getEntryFileName(entry, name, ANIM_ENTRY_NAME_MAX); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1268 | if (foundEntryName > ANIM_ENTRY_NAME_MAX || foundEntryName == -1) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1269 | SLOGE("Error fetching entry file name"); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1270 | continue; |
| 1271 | } |
| 1272 | |
| 1273 | const String8 entryName(name); |
| 1274 | const String8 path(entryName.getPathDir()); |
| 1275 | const String8 leaf(entryName.getPathLeaf()); |
| 1276 | if (leaf.size() > 0) { |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1277 | if (entryName == CLOCK_FONT_ZIP_NAME) { |
| 1278 | FileMap* map = zip->createEntryFileMap(entry); |
| 1279 | if (map) { |
| 1280 | animation.clockFont.map = map; |
| 1281 | } |
| 1282 | continue; |
| 1283 | } |
| 1284 | |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1285 | if (entryName == PROGRESS_FONT_ZIP_NAME) { |
| 1286 | FileMap* map = zip->createEntryFileMap(entry); |
| 1287 | if (map) { |
| 1288 | animation.progressFont.map = map; |
| 1289 | } |
| 1290 | continue; |
| 1291 | } |
| 1292 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1293 | for (size_t j = 0; j < pcount; j++) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1294 | if (path == animation.parts[j].path) { |
Narayan Kamath | 4600dd0 | 2015-06-16 12:02:57 +0100 | [diff] [blame] | 1295 | uint16_t method; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1296 | // supports only stored png files |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1297 | if (zip->getEntryInfo(entry, &method, nullptr, nullptr, nullptr, nullptr, nullptr)) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1298 | if (method == ZipFileRO::kCompressStored) { |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1299 | FileMap* map = zip->createEntryFileMap(entry); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1300 | if (map) { |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1301 | Animation::Part& part(animation.parts.editItemAt(j)); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1302 | if (leaf == "audio.wav") { |
| 1303 | // a part may have at most one audio file |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 1304 | part.audioData = (uint8_t *)map->getDataPtr(); |
| 1305 | part.audioLength = map->getDataLength(); |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1306 | } else if (leaf == "trim.txt") { |
| 1307 | part.trimData.setTo((char const*)map->getDataPtr(), |
| 1308 | map->getDataLength()); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1309 | } else { |
| 1310 | Animation::Frame frame; |
| 1311 | frame.name = leaf; |
| 1312 | frame.map = map; |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1313 | frame.trimWidth = animation.width; |
| 1314 | frame.trimHeight = animation.height; |
| 1315 | frame.trimX = 0; |
| 1316 | frame.trimY = 0; |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1317 | part.frames.add(frame); |
| 1318 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1319 | } |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 1320 | } else { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1321 | SLOGE("bootanimation.zip is compressed; must be only stored"); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1322 | } |
| 1323 | } |
| 1324 | } |
| 1325 | } |
| 1326 | } |
| 1327 | } |
| 1328 | |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1329 | // If there is trimData present, override the positioning defaults. |
| 1330 | for (Animation::Part& part : animation.parts) { |
| 1331 | const char* trimDataStr = part.trimData.string(); |
| 1332 | for (size_t frameIdx = 0; frameIdx < part.frames.size(); frameIdx++) { |
| 1333 | const char* endl = strstr(trimDataStr, "\n"); |
| 1334 | // No more trimData for this part. |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1335 | if (endl == nullptr) { |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1336 | break; |
| 1337 | } |
| 1338 | String8 line(trimDataStr, endl - trimDataStr); |
| 1339 | const char* lineStr = line.string(); |
| 1340 | trimDataStr = ++endl; |
| 1341 | int width = 0, height = 0, x = 0, y = 0; |
| 1342 | if (sscanf(lineStr, "%dx%d+%d+%d", &width, &height, &x, &y) == 4) { |
| 1343 | Animation::Frame& frame(part.frames.editItemAt(frameIdx)); |
| 1344 | frame.trimWidth = width; |
| 1345 | frame.trimHeight = height; |
| 1346 | frame.trimX = x; |
| 1347 | frame.trimY = y; |
| 1348 | } else { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1349 | SLOGE("Error parsing trim.txt, line: %s", lineStr); |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1350 | break; |
| 1351 | } |
| 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | zip->endIteration(cookie); |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1356 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1357 | return true; |
| 1358 | } |
| 1359 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1360 | bool BootAnimation::movie() { |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 1361 | if (mAnimation == nullptr) { |
| 1362 | mAnimation = loadAnimation(mZipFileName); |
| 1363 | } |
| 1364 | |
| 1365 | if (mAnimation == nullptr) |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1366 | return false; |
| 1367 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 1368 | // mCallbacks->init() may get called recursively, |
| 1369 | // this loop is needed to get the same results |
| 1370 | for (const Animation::Part& part : mAnimation->parts) { |
| 1371 | if (part.animation != nullptr) { |
| 1372 | mCallbacks->init(part.animation->parts); |
| 1373 | } |
| 1374 | } |
| 1375 | mCallbacks->init(mAnimation->parts); |
| 1376 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1377 | bool anyPartHasClock = false; |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 1378 | for (size_t i=0; i < mAnimation->parts.size(); i++) { |
| 1379 | if(validClock(mAnimation->parts[i])) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1380 | anyPartHasClock = true; |
| 1381 | break; |
| 1382 | } |
| 1383 | } |
| 1384 | if (!anyPartHasClock) { |
| 1385 | mClockEnabled = false; |
Thiébaud Weksteen | 08de443 | 2021-11-18 13:25:59 +1100 | [diff] [blame] | 1386 | } else if (!android::base::GetBoolProperty(CLOCK_ENABLED_PROP_NAME, false)) { |
| 1387 | mClockEnabled = false; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
Sai Kiran Korwar | 2716749 | 2015-07-07 20:00:06 +0530 | [diff] [blame] | 1390 | // Check if npot textures are supported |
| 1391 | mUseNpotTextures = false; |
| 1392 | String8 gl_extensions; |
| 1393 | const char* exts = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)); |
| 1394 | if (!exts) { |
| 1395 | glGetError(); |
| 1396 | } else { |
| 1397 | gl_extensions.setTo(exts); |
| 1398 | if ((gl_extensions.find("GL_ARB_texture_non_power_of_two") != -1) || |
| 1399 | (gl_extensions.find("GL_OES_texture_npot") != -1)) { |
| 1400 | mUseNpotTextures = true; |
| 1401 | } |
| 1402 | } |
| 1403 | |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1404 | // Blend required to draw time on top of animation frames. |
| 1405 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1406 | glDisable(GL_DITHER); |
| 1407 | glDisable(GL_SCISSOR_TEST); |
| 1408 | glDisable(GL_BLEND); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1409 | |
Greg Kaiser | 2ded800 | 2021-07-19 17:03:27 +0000 | [diff] [blame] | 1410 | glEnable(GL_TEXTURE_2D); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1411 | glBindTexture(GL_TEXTURE_2D, 0); |
| 1412 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1413 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1414 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 1415 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1416 | bool clockFontInitialized = false; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1417 | if (mClockEnabled) { |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1418 | clockFontInitialized = |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 1419 | (initFont(&mAnimation->clockFont, CLOCK_FONT_ASSET) == NO_ERROR); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1420 | mClockEnabled = clockFontInitialized; |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1421 | } |
| 1422 | |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1423 | initFont(&mAnimation->progressFont, PROGRESS_FONT_ASSET); |
| 1424 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1425 | if (mClockEnabled && !updateIsTimeAccurate()) { |
| 1426 | mTimeCheckThread = new TimeCheckThread(this); |
| 1427 | mTimeCheckThread->run("BootAnimation::TimeCheckThread", PRIORITY_NORMAL); |
| 1428 | } |
| 1429 | |
George Burgess IV | 0f8e811 | 2021-08-23 17:32:23 -0700 | [diff] [blame] | 1430 | if (mAnimation->dynamicColoringEnabled) { |
Shan Huang | 7fee352 | 2021-08-18 00:56:08 +0000 | [diff] [blame] | 1431 | initDynamicColors(); |
| 1432 | } |
| 1433 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 1434 | playAnimation(*mAnimation); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1435 | |
Geoffrey Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 1436 | if (mTimeCheckThread != nullptr) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1437 | mTimeCheckThread->requestExit(); |
Geoffrey Pitsch | a917353 | 2016-07-19 14:56:39 -0400 | [diff] [blame] | 1438 | mTimeCheckThread = nullptr; |
| 1439 | } |
| 1440 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1441 | if (clockFontInitialized) { |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 1442 | glDeleteTextures(1, &mAnimation->clockFont.texture.name); |
Andriy Naborskyy | 815e51d | 2016-03-24 16:43:34 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
Huihong Luo | 50a2f36 | 2018-08-11 09:27:57 -0700 | [diff] [blame] | 1445 | releaseAnimation(mAnimation); |
| 1446 | mAnimation = nullptr; |
Damien Bargiacchi | 1a8a213 | 2018-07-24 15:20:26 -0700 | [diff] [blame] | 1447 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1448 | return false; |
| 1449 | } |
| 1450 | |
Nicolas Geoffray | a129875 | 2021-04-20 15:15:06 +0100 | [diff] [blame] | 1451 | bool BootAnimation::shouldStopPlayingPart(const Animation::Part& part, |
| 1452 | const int fadedFramesCount, |
| 1453 | const int lastDisplayedProgress) { |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1454 | // stop playing only if it is time to exit and it's a partial part which has been faded out |
Nicolas Geoffray | a129875 | 2021-04-20 15:15:06 +0100 | [diff] [blame] | 1455 | return exitPending() && !part.playUntilComplete && fadedFramesCount >= part.framesToFadeCount && |
| 1456 | (lastDisplayedProgress == 0 || lastDisplayedProgress == 100); |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1457 | } |
| 1458 | |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1459 | // Linear mapping from range <a1, a2> to range <b1, b2> |
| 1460 | float mapLinear(float x, float a1, float a2, float b1, float b2) { |
| 1461 | return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 ); |
| 1462 | } |
| 1463 | |
| 1464 | void BootAnimation::drawTexturedQuad(float xStart, float yStart, float width, float height) { |
| 1465 | // Map coordinates from screen space to world space. |
| 1466 | float x0 = mapLinear(xStart, 0, mWidth, -1, 1); |
| 1467 | float y0 = mapLinear(yStart, 0, mHeight, -1, 1); |
| 1468 | float x1 = mapLinear(xStart + width, 0, mWidth, -1, 1); |
| 1469 | float y1 = mapLinear(yStart + height, 0, mHeight, -1, 1); |
| 1470 | // Update quad vertex positions. |
| 1471 | quadPositions[0] = x0; |
| 1472 | quadPositions[1] = y0; |
| 1473 | quadPositions[2] = x1; |
| 1474 | quadPositions[3] = y0; |
| 1475 | quadPositions[4] = x1; |
| 1476 | quadPositions[5] = y1; |
| 1477 | quadPositions[6] = x1; |
| 1478 | quadPositions[7] = y1; |
| 1479 | quadPositions[8] = x0; |
| 1480 | quadPositions[9] = y1; |
| 1481 | quadPositions[10] = x0; |
| 1482 | quadPositions[11] = y0; |
| 1483 | glDrawArrays(GL_TRIANGLES, 0, |
| 1484 | sizeof(quadPositions) / sizeof(quadPositions[0]) / 2); |
| 1485 | } |
| 1486 | |
Shan Huang | 7fee352 | 2021-08-18 00:56:08 +0000 | [diff] [blame] | 1487 | void BootAnimation::initDynamicColors() { |
| 1488 | for (int i = 0; i < DYNAMIC_COLOR_COUNT; i++) { |
Lucas Dupin | cd25684 | 2022-03-29 15:46:36 -0700 | [diff] [blame] | 1489 | const auto syspropName = "persist.bootanim.color" + std::to_string(i + 1); |
| 1490 | const auto syspropValue = android::base::GetProperty(syspropName, ""); |
| 1491 | if (syspropValue != "") { |
| 1492 | SLOGI("Loaded dynamic color: %s -> %s", syspropName.c_str(), syspropValue.c_str()); |
| 1493 | mDynamicColorsApplied = true; |
| 1494 | } |
| 1495 | parseColorDecimalString(syspropValue, |
Shan Huang | 7fee352 | 2021-08-18 00:56:08 +0000 | [diff] [blame] | 1496 | mAnimation->endColors[i], mAnimation->startColors[i]); |
| 1497 | } |
| 1498 | glUseProgram(mImageShader); |
Lucas Dupin | cd25684 | 2022-03-29 15:46:36 -0700 | [diff] [blame] | 1499 | SLOGI("Dynamically coloring boot animation. Sysprops loaded? %i", mDynamicColorsApplied); |
Shan Huang | 7fee352 | 2021-08-18 00:56:08 +0000 | [diff] [blame] | 1500 | for (int i = 0; i < DYNAMIC_COLOR_COUNT; i++) { |
| 1501 | float *startColor = mAnimation->startColors[i]; |
| 1502 | float *endColor = mAnimation->endColors[i]; |
Andrew Zeng | f9f5822 | 2022-11-08 11:10:48 -0800 | [diff] [blame] | 1503 | glUniform3f(glGetUniformLocation(mImageShader, |
Shan Huang | 7fee352 | 2021-08-18 00:56:08 +0000 | [diff] [blame] | 1504 | (U_START_COLOR_PREFIX + std::to_string(i)).c_str()), |
Andrew Zeng | f9f5822 | 2022-11-08 11:10:48 -0800 | [diff] [blame] | 1505 | startColor[0], startColor[1], startColor[2]); |
| 1506 | glUniform3f(glGetUniformLocation(mImageShader, |
Shan Huang | 7fee352 | 2021-08-18 00:56:08 +0000 | [diff] [blame] | 1507 | (U_END_COLOR_PREFIX + std::to_string(i)).c_str()), |
Andrew Zeng | f9f5822 | 2022-11-08 11:10:48 -0800 | [diff] [blame] | 1508 | endColor[0], endColor[1], endColor[2]); |
Shan Huang | 7fee352 | 2021-08-18 00:56:08 +0000 | [diff] [blame] | 1509 | } |
| 1510 | mImageColorProgressLocation = glGetUniformLocation(mImageShader, U_COLOR_PROGRESS); |
| 1511 | } |
| 1512 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1513 | bool BootAnimation::playAnimation(const Animation& animation) { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1514 | const size_t pcount = animation.parts.size(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1515 | nsecs_t frameDuration = s2ns(1) / animation.fps; |
Mathias Agopian | 9f3020d | 2009-11-06 16:30:18 -0800 | [diff] [blame] | 1516 | |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1517 | SLOGD("%sAnimationShownTiming start time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
Keun-young Park | d1794cd | 2017-04-04 12:21:19 -0700 | [diff] [blame] | 1518 | elapsedRealtime()); |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1519 | |
| 1520 | int fadedFramesCount = 0; |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1521 | int lastDisplayedProgress = 0; |
Lucas Dupin | bfd1812 | 2022-04-25 11:26:08 -0700 | [diff] [blame] | 1522 | int colorTransitionStart = animation.colorTransitionStart; |
| 1523 | int colorTransitionEnd = animation.colorTransitionEnd; |
Narayan Kamath | afd31e0 | 2013-12-03 13:16:03 +0000 | [diff] [blame] | 1524 | for (size_t i=0 ; i<pcount ; i++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1525 | const Animation::Part& part(animation.parts[i]); |
| 1526 | const size_t fcount = part.frames.size(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1527 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1528 | // Handle animation package |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1529 | if (part.animation != nullptr) { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1530 | playAnimation(*part.animation); |
| 1531 | if (exitPending()) |
| 1532 | break; |
| 1533 | continue; //to next part |
| 1534 | } |
| 1535 | |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1536 | // process the part not only while the count allows but also if already fading |
| 1537 | for (int r=0 ; !part.count || r<part.count || fadedFramesCount > 0 ; r++) { |
Nicolas Geoffray | a129875 | 2021-04-20 15:15:06 +0100 | [diff] [blame] | 1538 | if (shouldStopPlayingPart(part, fadedFramesCount, lastDisplayedProgress)) break; |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1539 | |
Lucas Dupin | bfd1812 | 2022-04-25 11:26:08 -0700 | [diff] [blame] | 1540 | // It's possible that the sysprops were not loaded yet at this boot phase. |
| 1541 | // If that's the case, then we should keep trying until they are available. |
| 1542 | if (animation.dynamicColoringEnabled && !mDynamicColorsApplied |
| 1543 | && (part.useDynamicColoring || part.postDynamicColoring)) { |
| 1544 | SLOGD("Trying to load dynamic color sysprops."); |
| 1545 | initDynamicColors(); |
| 1546 | if (mDynamicColorsApplied) { |
| 1547 | // Sysprops were loaded. Next step is to adjust the animation if we loaded |
| 1548 | // the colors after the animation should have started. |
| 1549 | const int transitionLength = colorTransitionEnd - colorTransitionStart; |
| 1550 | if (part.postDynamicColoring) { |
| 1551 | colorTransitionStart = 0; |
| 1552 | colorTransitionEnd = fmin(transitionLength, fcount - 1); |
| 1553 | } |
| 1554 | } |
| 1555 | } |
| 1556 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 1557 | mCallbacks->playPart(i, part, r); |
Mike Lockwood | ebf9a0d | 2014-10-02 16:08:47 -0700 | [diff] [blame] | 1558 | |
Jesse Hall | 083b84c | 2014-09-22 10:51:09 -0700 | [diff] [blame] | 1559 | glClearColor( |
| 1560 | part.backgroundColor[0], |
| 1561 | part.backgroundColor[1], |
| 1562 | part.backgroundColor[2], |
| 1563 | 1.0f); |
| 1564 | |
Yoshiaki Maruoka | 9ef19b8 | 2017-10-25 13:55:49 +0900 | [diff] [blame] | 1565 | ALOGD("Playing files = %s/%s, Requested repeat = %d, playUntilComplete = %s", |
| 1566 | animation.fileName.string(), part.path.string(), part.count, |
| 1567 | part.playUntilComplete ? "true" : "false"); |
| 1568 | |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1569 | // For the last animation, if we have progress indicator from |
| 1570 | // the system, display it. |
| 1571 | int currentProgress = android::base::GetIntProperty(PROGRESS_PROP_NAME, 0); |
| 1572 | bool displayProgress = animation.progressEnabled && |
| 1573 | (i == (pcount -1)) && currentProgress != 0; |
| 1574 | |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1575 | for (size_t j=0 ; j<fcount ; j++) { |
Nicolas Geoffray | a129875 | 2021-04-20 15:15:06 +0100 | [diff] [blame] | 1576 | if (shouldStopPlayingPart(part, fadedFramesCount, lastDisplayedProgress)) break; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1577 | |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1578 | // Color progress is |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 1579 | // - the animation progress, normalized from |
| 1580 | // [colorTransitionStart,colorTransitionEnd] to [0, 1] for the dynamic coloring |
| 1581 | // part. |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1582 | // - 0 for parts that come before, |
| 1583 | // - 1 for parts that come after. |
| 1584 | float colorProgress = part.useDynamicColoring |
Shan Huang | 488ff74 | 2021-08-25 20:10:46 +0000 | [diff] [blame] | 1585 | ? fmin(fmax( |
Lucas Dupin | bfd1812 | 2022-04-25 11:26:08 -0700 | [diff] [blame] | 1586 | ((float)j - colorTransitionStart) / |
| 1587 | fmax(colorTransitionEnd - colorTransitionStart, 1.0f), 0.0f), 1.0f) |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1588 | : (part.postDynamicColoring ? 1 : 0); |
| 1589 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1590 | processDisplayEvents(); |
| 1591 | |
joenchen | 85b339f | 2022-04-11 23:58:34 +0800 | [diff] [blame] | 1592 | const double ratio_w = static_cast<double>(mWidth) / mInitWidth; |
| 1593 | const double ratio_h = static_cast<double>(mHeight) / mInitHeight; |
| 1594 | const int animationX = (mWidth - animation.width * ratio_w) / 2; |
| 1595 | const int animationY = (mHeight - animation.height * ratio_h) / 2; |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1596 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1597 | const Animation::Frame& frame(part.frames[j]); |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 1598 | nsecs_t lastFrame = systemTime(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1599 | |
| 1600 | if (r > 0) { |
| 1601 | glBindTexture(GL_TEXTURE_2D, frame.tid); |
| 1602 | } else { |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1603 | glGenTextures(1, &frame.tid); |
| 1604 | glBindTexture(GL_TEXTURE_2D, frame.tid); |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1605 | int w, h; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1606 | // Set decoding option to alpha unpremultiplied so that the R, G, B channels |
| 1607 | // of transparent pixels are preserved. |
| 1608 | initTexture(frame.map, &w, &h, false /* don't premultiply alpha */); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1609 | } |
| 1610 | |
joenchen | 85b339f | 2022-04-11 23:58:34 +0800 | [diff] [blame] | 1611 | const int trimWidth = frame.trimWidth * ratio_w; |
| 1612 | const int trimHeight = frame.trimHeight * ratio_h; |
| 1613 | const int trimX = frame.trimX * ratio_w; |
| 1614 | const int trimY = frame.trimY * ratio_h; |
| 1615 | const int xc = animationX + trimX; |
| 1616 | const int yc = animationY + trimY; |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1617 | glClear(GL_COLOR_BUFFER_BIT); |
Geoffrey Pitsch | dd214a7 | 2016-06-27 17:14:30 -0400 | [diff] [blame] | 1618 | // specify the y center as ceiling((mHeight - frame.trimHeight) / 2) |
| 1619 | // which is equivalent to mHeight - (yc + frame.trimHeight) |
joenchen | 85b339f | 2022-04-11 23:58:34 +0800 | [diff] [blame] | 1620 | const int frameDrawY = mHeight - (yc + trimHeight); |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1621 | |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1622 | float fade = 0; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1623 | // if the part hasn't been stopped yet then continue fading if necessary |
| 1624 | if (exitPending() && part.hasFadingPhase()) { |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1625 | fade = static_cast<float>(++fadedFramesCount) / part.framesToFadeCount; |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1626 | if (fadedFramesCount >= part.framesToFadeCount) { |
| 1627 | fadedFramesCount = MAX_FADED_FRAMES_COUNT; // no more fading |
| 1628 | } |
| 1629 | } |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1630 | glUseProgram(mImageShader); |
| 1631 | glUniform1i(mImageTextureLocation, 0); |
| 1632 | glUniform1f(mImageFadeLocation, fade); |
Shan Huang | 2b31a36 | 2021-08-16 16:45:39 +0000 | [diff] [blame] | 1633 | if (animation.dynamicColoringEnabled) { |
| 1634 | glUniform1f(mImageColorProgressLocation, colorProgress); |
| 1635 | } |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1636 | glEnable(GL_BLEND); |
joenchen | 85b339f | 2022-04-11 23:58:34 +0800 | [diff] [blame] | 1637 | drawTexturedQuad(xc, frameDrawY, trimWidth, trimHeight); |
Lucas Dupin | 8eedc02 | 2021-07-29 21:49:07 +0000 | [diff] [blame] | 1638 | glDisable(GL_BLEND); |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1639 | |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1640 | if (mClockEnabled && mTimeIsAccurate && validClock(part)) { |
| 1641 | drawClock(animation.clockFont, part.clockPosX, part.clockPosY); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1642 | } |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1643 | |
Nicolas Geoffray | 41fffb4 | 2020-12-15 10:50:29 +0000 | [diff] [blame] | 1644 | if (displayProgress) { |
| 1645 | int newProgress = android::base::GetIntProperty(PROGRESS_PROP_NAME, 0); |
| 1646 | // In case the new progress jumped suddenly, still show an |
| 1647 | // increment of 1. |
| 1648 | if (lastDisplayedProgress != 100) { |
| 1649 | // Artificially sleep 1/10th a second to slow down the animation. |
| 1650 | usleep(100000); |
| 1651 | if (lastDisplayedProgress < newProgress) { |
| 1652 | lastDisplayedProgress++; |
| 1653 | } |
| 1654 | } |
| 1655 | // Put the progress percentage right below the animation. |
| 1656 | int posY = animation.height / 3; |
| 1657 | int posX = TEXT_CENTER_VALUE; |
| 1658 | drawProgress(lastDisplayedProgress, animation.progressFont, posX, posY); |
| 1659 | } |
| 1660 | |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1661 | handleViewport(frameDuration); |
Damien Bargiacchi | a704b7d | 2016-02-16 16:55:49 -0800 | [diff] [blame] | 1662 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1663 | eglSwapBuffers(mDisplay, mSurface); |
| 1664 | |
| 1665 | nsecs_t now = systemTime(); |
| 1666 | nsecs_t delay = frameDuration - (now - lastFrame); |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1667 | //SLOGD("%lld, %lld", ns2ms(now - lastFrame), ns2ms(delay)); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1668 | lastFrame = now; |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 1669 | |
| 1670 | if (delay > 0) { |
| 1671 | struct timespec spec; |
| 1672 | spec.tv_sec = (now + delay) / 1000000000; |
| 1673 | spec.tv_nsec = (now + delay) % 1000000000; |
| 1674 | int err; |
| 1675 | do { |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1676 | err = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &spec, nullptr); |
Keith Mok | 0f2e668 | 2021-11-15 05:50:32 +0000 | [diff] [blame] | 1677 | } while (err == EINTR); |
Mathias Agopian | db7dd2a | 2012-05-12 15:08:21 -0700 | [diff] [blame] | 1678 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1679 | |
| 1680 | checkExit(); |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1681 | } |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1682 | |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1683 | usleep(part.pause * ns2us(frameDuration)); |
Kevin Hester | d3782b2 | 2012-04-26 10:38:55 -0700 | [diff] [blame] | 1684 | |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1685 | if (exitPending() && !part.count && mCurrentInset >= mTargetInset && |
| 1686 | !part.hasFadingPhase()) { |
Nicolas Geoffray | a129875 | 2021-04-20 15:15:06 +0100 | [diff] [blame] | 1687 | if (lastDisplayedProgress != 0 && lastDisplayedProgress != 100) { |
| 1688 | android::base::SetProperty(PROGRESS_PROP_NAME, "100"); |
| 1689 | continue; |
| 1690 | } |
Yegor Malyshev | 6925e1b | 2020-09-10 16:42:20 +0200 | [diff] [blame] | 1691 | break; // exit the infinite non-fading part when it has been played at least once |
| 1692 | } |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1693 | } |
Geoffrey Pitsch | 2fb30fb | 2016-07-06 16:16:20 -0400 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | // Free textures created for looping parts now that the animation is done. |
| 1697 | for (const Animation::Part& part : animation.parts) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1698 | if (part.count != 1) { |
Geoffrey Pitsch | 2fb30fb | 2016-07-06 16:16:20 -0400 | [diff] [blame] | 1699 | const size_t fcount = part.frames.size(); |
| 1700 | for (size_t j = 0; j < fcount; j++) { |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1701 | const Animation::Frame& frame(part.frames[j]); |
| 1702 | glDeleteTextures(1, &frame.tid); |
| 1703 | } |
| 1704 | } |
| 1705 | } |
Geoffrey Pitsch | d6d9a1d | 2016-06-08 00:38:58 -0700 | [diff] [blame] | 1706 | |
Yoshiaki Maruoka | 9ef19b8 | 2017-10-25 13:55:49 +0900 | [diff] [blame] | 1707 | ALOGD("%sAnimationShownTiming End time: %" PRId64 "ms", mShuttingDown ? "Shutdown" : "Boot", |
| 1708 | elapsedRealtime()); |
| 1709 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1710 | return true; |
Mathias Agopian | a8826d6 | 2009-10-01 03:10:14 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1713 | void BootAnimation::processDisplayEvents() { |
| 1714 | // This will poll mDisplayEventReceiver and if there are new events it'll call |
| 1715 | // displayEventCallback synchronously. |
| 1716 | mLooper->pollOnce(0); |
| 1717 | } |
| 1718 | |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1719 | void BootAnimation::handleViewport(nsecs_t timestep) { |
| 1720 | if (mShuttingDown || !mFlingerSurfaceControl || mTargetInset == 0) { |
| 1721 | return; |
| 1722 | } |
| 1723 | if (mTargetInset < 0) { |
| 1724 | // Poll the amount for the top display inset. This will return -1 until persistent properties |
| 1725 | // have been loaded. |
| 1726 | mTargetInset = android::base::GetIntProperty("persist.sys.displayinset.top", |
| 1727 | -1 /* default */, -1 /* min */, mHeight / 2 /* max */); |
| 1728 | } |
| 1729 | if (mTargetInset <= 0) { |
| 1730 | return; |
| 1731 | } |
| 1732 | |
| 1733 | if (mCurrentInset < mTargetInset) { |
| 1734 | // After the device boots, the inset will effectively be cropped away. We animate this here. |
| 1735 | float fraction = static_cast<float>(mCurrentInset) / mTargetInset; |
| 1736 | int interpolatedInset = (cosf((fraction + 1) * M_PI) / 2.0f + 0.5f) * mTargetInset; |
| 1737 | |
| 1738 | SurfaceComposerClient::Transaction() |
| 1739 | .setCrop(mFlingerSurfaceControl, Rect(0, interpolatedInset, mWidth, mHeight)) |
| 1740 | .apply(); |
| 1741 | } else { |
| 1742 | // At the end of the animation, we switch to the viewport that DisplayManager will apply |
| 1743 | // later. This changes the coordinate system, and means we must move the surface up by |
| 1744 | // the inset amount. |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1745 | Rect layerStackRect(0, 0, mWidth, mHeight - mTargetInset); |
| 1746 | Rect displayRect(0, mTargetInset, mWidth, mHeight); |
| 1747 | |
| 1748 | SurfaceComposerClient::Transaction t; |
| 1749 | t.setPosition(mFlingerSurfaceControl, 0, -mTargetInset) |
| 1750 | .setCrop(mFlingerSurfaceControl, Rect(0, mTargetInset, mWidth, mHeight)); |
Dominik Laskowski | 2a3d9aa | 2019-11-18 20:26:39 -0800 | [diff] [blame] | 1751 | t.setDisplayProjection(mDisplayToken, ui::ROTATION_0, layerStackRect, displayRect); |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 1752 | t.apply(); |
| 1753 | |
| 1754 | mTargetInset = mCurrentInset = 0; |
| 1755 | } |
| 1756 | |
| 1757 | int delta = timestep * mTargetInset / ms2ns(200); |
| 1758 | mCurrentInset += delta; |
| 1759 | } |
| 1760 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1761 | void BootAnimation::releaseAnimation(Animation* animation) const { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1762 | for (Vector<Animation::Part>::iterator it = animation->parts.begin(), |
| 1763 | e = animation->parts.end(); it != e; ++it) { |
| 1764 | if (it->animation) |
| 1765 | releaseAnimation(it->animation); |
| 1766 | } |
| 1767 | if (animation->zip) |
| 1768 | delete animation->zip; |
| 1769 | delete animation; |
| 1770 | } |
| 1771 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1772 | BootAnimation::Animation* BootAnimation::loadAnimation(const String8& fn) { |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1773 | if (mLoadedFiles.indexOf(fn) >= 0) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1774 | SLOGE("File \"%s\" is already loaded. Cyclic ref is not allowed", |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1775 | fn.string()); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1776 | return nullptr; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1777 | } |
| 1778 | ZipFileRO *zip = ZipFileRO::open(fn); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1779 | if (zip == nullptr) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1780 | SLOGE("Failed to open animation zip \"%s\": %s", |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1781 | fn.string(), strerror(errno)); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1782 | return nullptr; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
Yoshiaki Maruoka | 9ef19b8 | 2017-10-25 13:55:49 +0900 | [diff] [blame] | 1785 | ALOGD("%s is loaded successfully", fn.string()); |
| 1786 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1787 | Animation *animation = new Animation; |
| 1788 | animation->fileName = fn; |
| 1789 | animation->zip = zip; |
Damien Bargiacchi | 0e3d2ab | 2016-08-29 04:11:19 -0700 | [diff] [blame] | 1790 | animation->clockFont.map = nullptr; |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1791 | mLoadedFiles.add(animation->fileName); |
| 1792 | |
| 1793 | parseAnimationDesc(*animation); |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 1794 | if (!preloadZip(*animation)) { |
Greg Kaiser | 7426ec8 | 2019-09-11 14:34:27 -0700 | [diff] [blame] | 1795 | releaseAnimation(animation); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1796 | return nullptr; |
Geoffrey Pitsch | a91a2d7 | 2016-07-12 14:46:19 -0400 | [diff] [blame] | 1797 | } |
| 1798 | |
Andriy Naborskyy | 39218ba | 2015-08-16 21:32:50 -0700 | [diff] [blame] | 1799 | mLoadedFiles.remove(fn); |
| 1800 | return animation; |
| 1801 | } |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1802 | |
| 1803 | bool BootAnimation::updateIsTimeAccurate() { |
| 1804 | static constexpr long long MAX_TIME_IN_PAST = 60000LL * 60LL * 24LL * 30LL; // 30 days |
| 1805 | static constexpr long long MAX_TIME_IN_FUTURE = 60000LL * 90LL; // 90 minutes |
| 1806 | |
| 1807 | if (mTimeIsAccurate) { |
| 1808 | return true; |
| 1809 | } |
Keun-young Park | b593842 | 2017-03-23 13:46:24 -0700 | [diff] [blame] | 1810 | if (mShuttingDown) return true; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1811 | struct stat statResult; |
Damien Bargiacchi | 9071db1 | 2016-10-28 17:38:22 -0700 | [diff] [blame] | 1812 | |
| 1813 | if(stat(TIME_FORMAT_12_HOUR_FLAG_FILE_PATH, &statResult) == 0) { |
| 1814 | mTimeFormat12Hour = true; |
| 1815 | } |
| 1816 | |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1817 | if(stat(ACCURATE_TIME_FLAG_FILE_PATH, &statResult) == 0) { |
| 1818 | mTimeIsAccurate = true; |
| 1819 | return true; |
| 1820 | } |
| 1821 | |
| 1822 | FILE* file = fopen(LAST_TIME_CHANGED_FILE_PATH, "r"); |
Yi Kong | 911ac23 | 2019-03-24 01:49:02 -0700 | [diff] [blame] | 1823 | if (file != nullptr) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1824 | long long lastChangedTime = 0; |
| 1825 | fscanf(file, "%lld", &lastChangedTime); |
| 1826 | fclose(file); |
| 1827 | if (lastChangedTime > 0) { |
| 1828 | struct timespec now; |
| 1829 | clock_gettime(CLOCK_REALTIME, &now); |
| 1830 | // Match the Java timestamp format |
| 1831 | long long rtcNow = (now.tv_sec * 1000LL) + (now.tv_nsec / 1000000LL); |
Damien Bargiacchi | 9676281 | 2016-07-12 15:53:40 -0700 | [diff] [blame] | 1832 | if (ACCURATE_TIME_EPOCH < rtcNow |
| 1833 | && lastChangedTime > (rtcNow - MAX_TIME_IN_PAST) |
| 1834 | && lastChangedTime < (rtcNow + MAX_TIME_IN_FUTURE)) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1835 | mTimeIsAccurate = true; |
| 1836 | } |
| 1837 | } |
| 1838 | } |
| 1839 | |
| 1840 | return mTimeIsAccurate; |
| 1841 | } |
| 1842 | |
| 1843 | BootAnimation::TimeCheckThread::TimeCheckThread(BootAnimation* bootAnimation) : Thread(false), |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 1844 | mInotifyFd(-1), mBootAnimWd(-1), mTimeWd(-1), mBootAnimation(bootAnimation) {} |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1845 | |
| 1846 | BootAnimation::TimeCheckThread::~TimeCheckThread() { |
| 1847 | // mInotifyFd may be -1 but that's ok since we're not at risk of attempting to close a valid FD. |
| 1848 | close(mInotifyFd); |
| 1849 | } |
| 1850 | |
| 1851 | bool BootAnimation::TimeCheckThread::threadLoop() { |
| 1852 | bool shouldLoop = doThreadLoop() && !mBootAnimation->mTimeIsAccurate |
| 1853 | && mBootAnimation->mClockEnabled; |
| 1854 | if (!shouldLoop) { |
| 1855 | close(mInotifyFd); |
| 1856 | mInotifyFd = -1; |
| 1857 | } |
| 1858 | return shouldLoop; |
| 1859 | } |
| 1860 | |
| 1861 | bool BootAnimation::TimeCheckThread::doThreadLoop() { |
| 1862 | static constexpr int BUFF_LEN (10 * (sizeof(struct inotify_event) + NAME_MAX + 1)); |
| 1863 | |
| 1864 | // Poll instead of doing a blocking read so the Thread can exit if requested. |
| 1865 | struct pollfd pfd = { mInotifyFd, POLLIN, 0 }; |
| 1866 | ssize_t pollResult = poll(&pfd, 1, 1000); |
| 1867 | |
| 1868 | if (pollResult == 0) { |
| 1869 | return true; |
| 1870 | } else if (pollResult < 0) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1871 | SLOGE("Could not poll inotify events"); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1872 | return false; |
| 1873 | } |
| 1874 | |
| 1875 | char buff[BUFF_LEN] __attribute__ ((aligned(__alignof__(struct inotify_event))));; |
| 1876 | ssize_t length = read(mInotifyFd, buff, BUFF_LEN); |
| 1877 | if (length == 0) { |
| 1878 | return true; |
| 1879 | } else if (length < 0) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1880 | SLOGE("Could not read inotify events"); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1881 | return false; |
| 1882 | } |
| 1883 | |
| 1884 | const struct inotify_event *event; |
| 1885 | for (char* ptr = buff; ptr < buff + length; ptr += sizeof(struct inotify_event) + event->len) { |
| 1886 | event = (const struct inotify_event *) ptr; |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 1887 | if (event->wd == mBootAnimWd && strcmp(BOOTANIM_TIME_DIR_NAME, event->name) == 0) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1888 | addTimeDirWatch(); |
| 1889 | } else if (event->wd == mTimeWd && (strcmp(LAST_TIME_CHANGED_FILE_NAME, event->name) == 0 |
| 1890 | || strcmp(ACCURATE_TIME_FLAG_FILE_NAME, event->name) == 0)) { |
| 1891 | return !mBootAnimation->updateIsTimeAccurate(); |
| 1892 | } |
| 1893 | } |
| 1894 | |
| 1895 | return true; |
| 1896 | } |
| 1897 | |
| 1898 | void BootAnimation::TimeCheckThread::addTimeDirWatch() { |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 1899 | mTimeWd = inotify_add_watch(mInotifyFd, BOOTANIM_TIME_DIR_PATH, |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1900 | IN_CLOSE_WRITE | IN_MOVED_TO | IN_ATTRIB); |
| 1901 | if (mTimeWd > 0) { |
| 1902 | // No need to watch for the time directory to be created if it already exists |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 1903 | inotify_rm_watch(mInotifyFd, mBootAnimWd); |
| 1904 | mBootAnimWd = -1; |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | status_t BootAnimation::TimeCheckThread::readyToRun() { |
| 1909 | mInotifyFd = inotify_init(); |
| 1910 | if (mInotifyFd < 0) { |
Wei Wang | 159a410 | 2018-10-23 23:15:58 -0700 | [diff] [blame] | 1911 | SLOGE("Could not initialize inotify fd"); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1912 | return NO_INIT; |
| 1913 | } |
| 1914 | |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 1915 | mBootAnimWd = inotify_add_watch(mInotifyFd, BOOTANIM_DATA_DIR_PATH, IN_CREATE | IN_ATTRIB); |
| 1916 | if (mBootAnimWd < 0) { |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1917 | close(mInotifyFd); |
| 1918 | mInotifyFd = -1; |
Josh Yang | f95b200 | 2021-12-23 14:32:28 -0800 | [diff] [blame] | 1919 | SLOGE("Could not add watch for %s: %s", BOOTANIM_DATA_DIR_PATH, strerror(errno)); |
Damien Bargiacchi | 9748086 | 2016-03-29 14:55:55 -0700 | [diff] [blame] | 1920 | return NO_INIT; |
| 1921 | } |
| 1922 | |
| 1923 | addTimeDirWatch(); |
| 1924 | |
| 1925 | if (mBootAnimation->updateIsTimeAccurate()) { |
| 1926 | close(mInotifyFd); |
| 1927 | mInotifyFd = -1; |
| 1928 | return ALREADY_EXISTS; |
| 1929 | } |
| 1930 | |
| 1931 | return NO_ERROR; |
| 1932 | } |
| 1933 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1934 | // --------------------------------------------------------------------------- |
| 1935 | |
Marin Shalamanov | 9070c05 | 2020-05-18 19:05:17 +0200 | [diff] [blame] | 1936 | } // namespace android |