Pandroid: Storage Access Framework (SAF) (#408)

This commit is contained in:
Gabriel Machado 2024-02-17 12:09:46 -04:00 committed by GitHub
parent 3c25be4c63
commit 6af4a04987
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 292 additions and 63 deletions

View file

@ -7,6 +7,7 @@
#include "emulator.hpp"
#include "renderer_gl/renderer_gl.hpp"
#include "services/hid.hpp"
#include "android_utils.hpp"
std::unique_ptr<Emulator> emulator = nullptr;
HIDService* hidService = nullptr;
@ -14,6 +15,9 @@ RendererGL* renderer = nullptr;
bool romLoaded = false;
JavaVM* jvm = nullptr;
jclass alberClass;
jmethodID alberClassOpenDocument;
#define AlberFunction(type, name) JNIEXPORT type JNICALL Java_com_panda3ds_pandroid_AlberDriver_##name
void throwException(JNIEnv* env, const char* message) {
@ -42,7 +46,13 @@ MAKE_SETTING(setShaderJitEnabled, jboolean, shaderJitEnabled)
#undef MAKE_SETTING
AlberFunction(void, Setup)(JNIEnv* env, jobject obj) { env->GetJavaVM(&jvm); }
AlberFunction(void, Setup)(JNIEnv* env, jobject obj) {
env->GetJavaVM(&jvm);
alberClass = (jclass)env->NewGlobalRef((jclass)env->FindClass("com/panda3ds/pandroid/AlberDriver"));
alberClassOpenDocument = env->GetStaticMethodID(alberClass, "openDocument", "(Ljava/lang/String;Ljava/lang/String;)I");
}
AlberFunction(void, Pause)(JNIEnv* env, jobject obj) { emulator->pause(); }
AlberFunction(void, Resume)(JNIEnv* env, jobject obj) { emulator->resume(); }
@ -116,3 +126,17 @@ AlberFunction(jbyteArray, GetSmdh)(JNIEnv* env, jobject obj) {
}
#undef AlberFunction
int AndroidUtils::openDocument(const char* path, const char* perms) {
auto env = jniEnv();
jstring uri = env->NewStringUTF(path);
jstring jmode = env->NewStringUTF(perms);
jint result = env->CallStaticIntMethod(alberClass, alberClassOpenDocument, uri, jmode);
env->DeleteLocalRef(uri);
env->DeleteLocalRef(jmode);
return (int)result;
}