From 33f4b7d63b511b145e3ce72580a52f3551358a61 Mon Sep 17 00:00:00 2001 From: Ed Coyne Date: Tue, 10 Apr 2018 13:39:09 -0700 Subject: Refactor audio code out of bootanimation_main. So it can be shared with the iot/ variant I refactored it into the audioplay.h file. This keeps all of the audio code local, we could hide the functions and only expose the callback but that would make testing harder. Test: Ran a bootanimation.zip with audio.wav on Marlin, works as expected. Bug: 67051984 Change-Id: Ie31dc5f2cfaad5bb23134ef81be712afa6b3cd6f --- cmds/bootanimation/BootAnimationUtil.cpp | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'cmds/bootanimation/BootAnimationUtil.cpp') diff --git a/cmds/bootanimation/BootAnimationUtil.cpp b/cmds/bootanimation/BootAnimationUtil.cpp index 7718daf61d81..1e417e938359 100644 --- a/cmds/bootanimation/BootAnimationUtil.cpp +++ b/cmds/bootanimation/BootAnimationUtil.cpp @@ -16,14 +16,30 @@ #include "BootAnimationUtil.h" +#include #include #include #include #include #include +#include namespace android { +namespace { + +static constexpr char PLAY_SOUND_PROP_NAME[] = "persist.sys.bootanim.play_sound"; +static constexpr char BOOT_COMPLETED_PROP_NAME[] = "sys.boot_completed"; +static constexpr char POWER_CTL_PROP_NAME[] = "sys.powerctl"; +static constexpr char BOOTREASON_PROP_NAME[] = "ro.boot.bootreason"; +static const std::vector PLAY_SOUND_BOOTREASON_BLACKLIST { + "kernel_panic", + "Panic", + "Watchdog", +}; + +} // namespace + bool bootAnimationDisabled() { char value[PROPERTY_VALUE_MAX]; @@ -58,4 +74,31 @@ void waitForSurfaceFlinger() { } } +bool playSoundsAllowed() { + // Only play sounds for system boots, not runtime restarts. + if (android::base::GetBoolProperty(BOOT_COMPLETED_PROP_NAME, false)) { + return false; + } + // no audio while shutting down + if (!android::base::GetProperty(POWER_CTL_PROP_NAME, "").empty()) { + return false; + } + // Read the system property to see if we should play the sound. + // If it's not present, default to allowed. + if (!property_get_bool(PLAY_SOUND_PROP_NAME, 1)) { + return false; + } + + // Don't play sounds if this is a reboot due to an error. + char bootreason[PROPERTY_VALUE_MAX]; + if (property_get(BOOTREASON_PROP_NAME, bootreason, nullptr) > 0) { + for (const auto& str : PLAY_SOUND_BOOTREASON_BLACKLIST) { + if (strcasecmp(str.c_str(), bootreason) == 0) { + return false; + } + } + } + return true; +} + } // namespace android -- cgit v1.2.3-59-g8ed1b