summaryrefslogtreecommitdiff
path: root/cmds/bootanimation/BootAnimationUtil.cpp
diff options
context:
space:
mode:
authorEd Coyne <edcoyne@google.com>2018-04-10 13:39:09 -0700
committerEd Coyne <edcoyne@google.com>2018-05-31 11:50:47 -0700
commit33f4b7d63b511b145e3ce72580a52f3551358a61 (patch)
tree3231e0a33be92e7758f9e6b11b33172c3e89288e /cmds/bootanimation/BootAnimationUtil.cpp
parent3bb9562f198bbbdf2bf949203936b092903803f1 (diff)
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
Diffstat (limited to 'cmds/bootanimation/BootAnimationUtil.cpp')
-rw-r--r--cmds/bootanimation/BootAnimationUtil.cpp43
1 files changed, 43 insertions, 0 deletions
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 <vector>
#include <inttypes.h>
#include <binder/IServiceManager.h>
#include <cutils/properties.h>
#include <utils/Log.h>
#include <utils/SystemClock.h>
+#include <android-base/properties.h>
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<std::string> 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