ANDROID: Add a method to get running SDK version

Co-authored-by: antoniou79 <a.antoniou79@gmail.com>
This commit is contained in:
Le Philousophe 2023-01-08 11:52:59 +01:00
parent c84c9cd313
commit 9631567923
3 changed files with 27 additions and 1 deletions

View file

@ -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() {

View file

@ -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);

View file

@ -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();