diff --git a/src/aaudio/AudioStreamAAudio.cpp b/src/aaudio/AudioStreamAAudio.cpp index a256ef1c4..452f8407e 100644 --- a/src/aaudio/AudioStreamAAudio.cpp +++ b/src/aaudio/AudioStreamAAudio.cpp @@ -16,12 +16,16 @@ #include #include +#include #include "aaudio/AAudioLoader.h" #include "aaudio/AudioStreamAAudio.h" #include "common/OboeDebug.h" #include "oboe/Utilities.h" +#ifdef __ANDROID__ +#include +#endif using namespace oboe; @@ -89,7 +93,22 @@ AudioStreamAAudio::~AudioStreamAAudio() delete[] mShortCallbackBuffer; } +static bool isRunningOnAndroid8_1OrHigher() { +#ifdef __ANDROID__ + char sdk[PROP_VALUE_MAX] = {0}; + if (__system_property_get("ro.build.version.sdk", sdk) != 0) { + return atoi(sdk) >= 27; // SDK Level 27 is Android Oreo 8.1 + } +#endif + return false; +} + bool AudioStreamAAudio::isSupported() { + if (!isRunningOnAndroid8_1OrHigher()) { + // See https://github.com/google/oboe/issues/40, + // AAudio is not stable enough on Android 8.0. + return false; + } mLibLoader = AAudioLoader::getInstance(); int openResult = mLibLoader->open(); return openResult == 0; @@ -380,4 +399,4 @@ Result AudioStreamAAudio::getTimestamp(clockid_t clockId, } } -} // namespace oboe \ No newline at end of file +} // namespace oboe