ANDROID: Fix android3d compilation (#2594)

SAF was added to android but not android3d yet it is in both cases
in posifxfs.

Merging android and android3d will be a separate project
This commit is contained in:
Vladimir Serbinenko 2020-11-03 12:36:51 +01:00 committed by GitHub
parent 8c6d690e23
commit a1a53eb205
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 0 deletions

View file

@ -91,6 +91,9 @@ jmethodID JNI::_MID_convertEncoding = 0;
jmethodID JNI::_MID_getAllStorageLocations = 0; jmethodID JNI::_MID_getAllStorageLocations = 0;
jmethodID JNI::_MID_initSurface = 0; jmethodID JNI::_MID_initSurface = 0;
jmethodID JNI::_MID_deinitSurface = 0; jmethodID JNI::_MID_deinitSurface = 0;
jmethodID JNI::_MID_createDirectoryWithSAF = 0;
jmethodID JNI::_MID_createFileWithSAF = 0;
jmethodID JNI::_MID_closeFileWithSAF = 0;
jmethodID JNI::_MID_EGL10_eglSwapBuffers = 0; jmethodID JNI::_MID_EGL10_eglSwapBuffers = 0;
@ -570,6 +573,9 @@ void JNI::create(JNIEnv *env, jobject self, jobject asset_manager,
FIND_METHOD(, convertEncoding, "(Ljava/lang/String;Ljava/lang/String;[B)[B"); FIND_METHOD(, convertEncoding, "(Ljava/lang/String;Ljava/lang/String;[B)[B");
FIND_METHOD(, initSurface, "()Ljavax/microedition/khronos/egl/EGLSurface;"); FIND_METHOD(, initSurface, "()Ljavax/microedition/khronos/egl/EGLSurface;");
FIND_METHOD(, deinitSurface, "()V"); FIND_METHOD(, deinitSurface, "()V");
FIND_METHOD(, createDirectoryWithSAF, "(Ljava/lang/String;)Z");
FIND_METHOD(, createFileWithSAF, "(Ljava/lang/String;)Ljava/lang/String;");
FIND_METHOD(, closeFileWithSAF, "(Ljava/lang/String;)V");
_jobj_egl = env->NewGlobalRef(egl); _jobj_egl = env->NewGlobalRef(egl);
_jobj_egl_display = env->NewGlobalRef(egl_display); _jobj_egl_display = env->NewGlobalRef(egl_display);
@ -788,5 +794,62 @@ Common::Array<Common::String> JNI::getAllStorageLocations() {
return *res; return *res;
} }
bool JNI::createDirectoryWithSAF(const Common::String &dirPath) {
JNIEnv *env = JNI::getEnv();
jstring javaDirPath = env->NewStringUTF(dirPath.c_str());
bool created = env->CallBooleanMethod(_jobj, _MID_createDirectoryWithSAF, javaDirPath);
if (env->ExceptionCheck()) {
LOGE("JNI - Failed to create directory with SAF enhanced method");
env->ExceptionDescribe();
env->ExceptionClear();
created = false;
}
return created;
}
Common::String JNI::createFileWithSAF(const Common::String &filePath) {
JNIEnv *env = JNI::getEnv();
jstring javaFilePath = env->NewStringUTF(filePath.c_str());
jstring hackyFilenameJSTR = (jstring)env->CallObjectMethod(_jobj, _MID_createFileWithSAF, javaFilePath);
if (env->ExceptionCheck()) {
LOGE("JNI - Failed to create file with SAF enhanced method");
env->ExceptionDescribe();
env->ExceptionClear();
hackyFilenameJSTR = env->NewStringUTF("");
}
Common::String hackyFilenameStr = convertFromJString(env, hackyFilenameJSTR, "UTF-8");
//LOGD("JNI - _MID_createFileWithSAF returned %s", hackyFilenameStr.c_str());
env->DeleteLocalRef(hackyFilenameJSTR);
return hackyFilenameStr;
}
void JNI::closeFileWithSAF(const Common::String &hackyFilename) {
JNIEnv *env = JNI::getEnv();
jstring javaHackyFilename = env->NewStringUTF(hackyFilename.c_str());
env->CallVoidMethod(_jobj, _MID_closeFileWithSAF, javaHackyFilename);
if (env->ExceptionCheck()) {
LOGE("JNI - Failed to close file with SAF enhanced method");
env->ExceptionDescribe();
env->ExceptionClear();
}
}
#endif #endif

View file

@ -85,6 +85,10 @@ public:
static Common::Array<Common::String> getAllStorageLocations(); static Common::Array<Common::String> getAllStorageLocations();
static bool createDirectoryWithSAF(const Common::String &dirPath);
static Common::String createFileWithSAF(const Common::String &filePath);
static void closeFileWithSAF(const Common::String &hackyFilename);
private: private:
static JavaVM *_vm; static JavaVM *_vm;
// back pointer to (java) peer instance // back pointer to (java) peer instance
@ -114,6 +118,9 @@ private:
static jmethodID _MID_getAllStorageLocations; static jmethodID _MID_getAllStorageLocations;
static jmethodID _MID_initSurface; static jmethodID _MID_initSurface;
static jmethodID _MID_deinitSurface; static jmethodID _MID_deinitSurface;
static jmethodID _MID_createDirectoryWithSAF;
static jmethodID _MID_createFileWithSAF;
static jmethodID _MID_closeFileWithSAF;
static jmethodID _MID_EGL10_eglSwapBuffers; static jmethodID _MID_EGL10_eglSwapBuffers;