diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp index e014520f824..ca7c3fce8e9 100644 --- a/backends/platform/android/android.cpp +++ b/backends/platform/android/android.cpp @@ -154,6 +154,12 @@ OSystem_Android::OSystem_Android(int audio_sample_rate, int audio_buffer_size) : getSystemProperty("ro.build.display.id").c_str(), getSystemProperty("ro.build.version.sdk").c_str(), getSystemProperty("ro.product.cpu.abi").c_str()); + // JNI::getAndroidSDKVersionId() should be identical to the result from ("ro.build.version.sdk"), + // though getting it via JNI is maybe the most reliable option (?) + // Also __system_property_get which is used by getSystemProperty() is being deprecated in recent NDKs + + int sdkVersion = JNI::getAndroidSDKVersionId(); + LOGI("SDK Version: %d", sdkVersion); } OSystem_Android::~OSystem_Android() { diff --git a/backends/platform/android/jni-android.cpp b/backends/platform/android/jni-android.cpp index 9d8854e2419..29d67cc0df9 100644 --- a/backends/platform/android/jni-android.cpp +++ b/backends/platform/android/jni-android.cpp @@ -872,11 +872,30 @@ void JNI::setPause(JNIEnv *env, jobject self, jboolean value) { } } - jstring JNI::getNativeVersionInfo(JNIEnv *env, jobject self) { return convertToJString(env, Common::U32String(gScummVMVersion)); } +jint JNI::getAndroidSDKVersionId() { + // based on: https://stackoverflow.com/a/10511880 + JNIEnv *env = JNI::getEnv(); + // VERSION is a nested class within android.os.Build (hence "$" rather than "/") + jclass versionClass = env->FindClass("android/os/Build$VERSION"); + if (!versionClass) { + return 0; + } + + jfieldID sdkIntFieldID = NULL; + sdkIntFieldID = env->GetStaticFieldID(versionClass, "SDK_INT", "I"); + if (!sdkIntFieldID) { + return 0; + } + + jint sdkInt = env->GetStaticIntField(versionClass, sdkIntFieldID); + //LOGD("sdkInt = %d", sdkInt); + return sdkInt; +} + jstring JNI::convertToJString(JNIEnv *env, const Common::U32String &str) { uint len = 0; uint16 *u16str = str.encodeUTF16Native(&len); diff --git a/backends/platform/android/jni-android.h b/backends/platform/android/jni-android.h index b00ceff8aba..2942e754fd4 100644 --- a/backends/platform/android/jni-android.h +++ b/backends/platform/android/jni-android.h @@ -89,6 +89,7 @@ public: static int getTouchMode(); static void showSAFRevokePermsControl(bool enable); static void addSysArchivesToSearchSet(Common::SearchSet &s, int priority); + static jint getAndroidSDKVersionId(); static inline bool haveSurface(); static inline bool swapBuffers();