diff options
Diffstat (limited to 'cmds/bootanimation/bootanimation_main.cpp')
-rw-r--r-- | cmds/bootanimation/bootanimation_main.cpp | 116 |
1 files changed, 49 insertions, 67 deletions
diff --git a/cmds/bootanimation/bootanimation_main.cpp b/cmds/bootanimation/bootanimation_main.cpp index c11d90522ffd..8501982d071c 100644 --- a/cmds/bootanimation/bootanimation_main.cpp +++ b/cmds/bootanimation/bootanimation_main.cpp @@ -30,6 +30,7 @@ #include <android-base/properties.h> #include "BootAnimation.h" +#include "BootAnimationUtil.h" #include "audioplay.h" using namespace android; @@ -95,6 +96,49 @@ bool playSoundsAllowed() { return true; } +class AudioAnimationCallbacks : public android::BootAnimation::Callbacks { +public: + void init(const Vector<Animation::Part>& parts) override { + const Animation::Part* partWithAudio = nullptr; + for (const Animation::Part& part : parts) { + if (part.audioData != nullptr) { + partWithAudio = ∂ + } + } + + if (partWithAudio == nullptr) { + return; + } + + ALOGD("found audio.wav, creating playback engine"); + initAudioThread = new InitAudioThread(partWithAudio->audioData, + partWithAudio->audioLength); + initAudioThread->run("BootAnimation::InitAudioThread", PRIORITY_NORMAL); + }; + + void playPart(int partNumber, const Animation::Part& part, int playNumber) override { + // only play audio file the first time we animate the part + if (playNumber == 0 && part.audioData && playSoundsAllowed()) { + ALOGD("playing clip for part%d, size=%d", + partNumber, part.audioLength); + // Block until the audio engine is finished initializing. + if (initAudioThread != nullptr) { + initAudioThread->join(); + } + audioplay::playClip(part.audioData, part.audioLength); + } + }; + + void shutdown() override { + // we've finally played everything we're going to play + audioplay::setPlaying(false); + audioplay::destroy(); + }; + +private: + sp<InitAudioThread> initAudioThread = nullptr; +}; + } // namespace @@ -102,83 +146,21 @@ int main() { setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_DISPLAY); - char value[PROPERTY_VALUE_MAX]; - property_get("debug.sf.nobootanimation", value, "0"); - int noBootAnimation = atoi(value); - if (!noBootAnimation) { - property_get("ro.boot.quiescent", value, "0"); - noBootAnimation = atoi(value); - } + bool noBootAnimation = bootAnimationDisabled(); ALOGI_IF(noBootAnimation, "boot animation disabled"); if (!noBootAnimation) { sp<ProcessState> proc(ProcessState::self()); ProcessState::self()->startThreadPool(); - // TODO: replace this with better waiting logic in future, b/35253872 - int64_t waitStartTime = elapsedRealtime(); - sp<IServiceManager> sm = defaultServiceManager(); - const String16 name("SurfaceFlinger"); - const int SERVICE_WAIT_SLEEP_MS = 100; - const int LOG_PER_RETRIES = 10; - int retry = 0; - while (sm->checkService(name) == nullptr) { - retry++; - if ((retry % LOG_PER_RETRIES) == 0) { - ALOGW("Waiting for SurfaceFlinger, waited for %" PRId64 " ms", - elapsedRealtime() - waitStartTime); - } - usleep(SERVICE_WAIT_SLEEP_MS * 1000); - }; - int64_t totalWaited = elapsedRealtime() - waitStartTime; - if (totalWaited > SERVICE_WAIT_SLEEP_MS) { - ALOGI("Waiting for SurfaceFlinger took %" PRId64 " ms", totalWaited); - } - - // TODO: Move audio code to a new class that just exports the callbacks. - sp<InitAudioThread> initAudioThread = nullptr; - - auto initCallback = [&](const Vector<Animation::Part>& parts) { - const Animation::Part* partWithAudio = nullptr; - for (const Animation::Part& part : parts) { - if (part.audioData != nullptr) { - partWithAudio = ∂ - } - } - - if (partWithAudio == nullptr) { - return; - } - - ALOGD("found audio.wav, creating playback engine"); - initAudioThread = new InitAudioThread(partWithAudio->audioData, - partWithAudio->audioLength); - initAudioThread->run("BootAnimation::InitAudioThread", PRIORITY_NORMAL); - - }; - - auto partCallback = [&](int partNumber, const Animation::Part& part, - int playNumber) { - // only play audio file the first time we animate the part - if (playNumber == 0 && part.audioData && playSoundsAllowed()) { - ALOGD("playing clip for part%d, size=%d", - partNumber, part.audioLength); - // Block until the audio engine is finished initializing. - if (initAudioThread != nullptr) { - initAudioThread->join(); - } - audioplay::playClip(part.audioData, part.audioLength); - } - }; + waitForSurfaceFlinger(); // create the boot animation object - sp<BootAnimation> boot = new BootAnimation(initCallback, partCallback); + sp<BootAnimation> boot = new BootAnimation(new AudioAnimationCallbacks()); + ALOGV("Boot animation set up. Joining pool."); IPCThreadState::self()->joinThreadPool(); - - // we've finally played everything we're going to play - audioplay::setPlaying(false); - audioplay::destroy(); } + ALOGV("Boot animation exit"); return 0; } |