oboe: add general purpose getSdkVersion() query
Use this for deciding whether to support AAudio.
diff --git a/include/oboe/Utilities.h b/include/oboe/Utilities.h
index 4f2b139..29a9b6d 100644
--- a/include/oboe/Utilities.h
+++ b/include/oboe/Utilities.h
@@ -43,6 +43,15 @@
template <typename FromType>
const char * convertToText(FromType);
+/**
+ * Return the version of the SDK that is currently running.
+ *
+ * For example, on Android, this would return 27 for Oreo 8.1.
+ * If the version number cannot be determined then this will return -1.
+ *
+ * @return version number or -1
+ */
+int getSdkVersion();
} // namespace oboe
diff --git a/src/aaudio/AudioStreamAAudio.cpp b/src/aaudio/AudioStreamAAudio.cpp
index d44ee9c..44036c6 100644
--- a/src/aaudio/AudioStreamAAudio.cpp
+++ b/src/aaudio/AudioStreamAAudio.cpp
@@ -83,24 +83,14 @@
isSupported();
}
-AudioStreamAAudio::~AudioStreamAAudio()
-{
+AudioStreamAAudio::~AudioStreamAAudio() {
delete[] mFloatCallbackBuffer;
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()) {
+ const int SDK_8_1 = 27; // OC-MR1
+ if (getSdkVersion() < SDK_8_1) {
// See https://github.com/google/oboe/issues/40,
// AAudio is not stable enough on Android 8.0.
return false;
@@ -110,7 +100,6 @@
return openResult == 0;
}
-
Result AudioStreamAAudio::open() {
Result result = Result::OK;
diff --git a/src/common/Utilities.cpp b/src/common/Utilities.cpp
index 04dc426..42c86b0 100644
--- a/src/common/Utilities.cpp
+++ b/src/common/Utilities.cpp
@@ -15,7 +15,13 @@
*/
+#include <stdlib.h>
#include <unistd.h>
+
+#ifdef __ANDROID__
+#include <sys/system_properties.h>
+#endif
+
#include "oboe/Definitions.h"
#include "oboe/Utilities.h"
@@ -162,4 +168,14 @@
}
}
-}// namespace oboe
\ No newline at end of file
+int getSdkVersion() {
+#ifdef __ANDROID__
+ char sdk[PROP_VALUE_MAX] = {0};
+ if (__system_property_get("ro.build.version.sdk", sdk) != 0) {
+ return atoi(sdk);
+ }
+#endif
+ return -1;
+}
+
+}// namespace oboe