summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorliamwhite <liamwhite@users.noreply.github.com>2024-02-09 17:49:25 +0100
committerGitHub <noreply@github.com>2024-02-09 17:49:25 +0100
commit7ec7ff0f303504950e4270e91076a33efd0ceb17 (patch)
tree1e8346f775550eefd491aa8280412d86000dd637 /src/common
parentMerge pull request #12927 from german77/cheat-pause (diff)
parentandroid: Run OnEmulationStarted frontend callback in another thread (diff)
downloadyuzu-7ec7ff0f303504950e4270e91076a33efd0ceb17.tar
yuzu-7ec7ff0f303504950e4270e91076a33efd0ceb17.tar.gz
yuzu-7ec7ff0f303504950e4270e91076a33efd0ceb17.tar.bz2
yuzu-7ec7ff0f303504950e4270e91076a33efd0ceb17.tar.lz
yuzu-7ec7ff0f303504950e4270e91076a33efd0ceb17.tar.xz
yuzu-7ec7ff0f303504950e4270e91076a33efd0ceb17.tar.zst
yuzu-7ec7ff0f303504950e4270e91076a33efd0ceb17.zip
Diffstat (limited to '')
-rw-r--r--src/common/CMakeLists.txt8
-rw-r--r--src/common/android/android_common.cpp (renamed from src/android/app/src/main/jni/android_common/android_common.cpp)23
-rw-r--r--src/common/android/android_common.h (renamed from src/android/app/src/main/jni/android_common/android_common.h)4
-rw-r--r--src/common/android/applets/software_keyboard.cpp (renamed from src/android/app/src/main/jni/applets/software_keyboard.cpp)24
-rw-r--r--src/common/android/applets/software_keyboard.h (renamed from src/android/app/src/main/jni/applets/software_keyboard.h)4
-rw-r--r--src/common/android/id_cache.cpp (renamed from src/android/app/src/main/jni/id_cache.cpp)12
-rw-r--r--src/common/android/id_cache.h (renamed from src/android/app/src/main/jni/id_cache.h)26
-rw-r--r--src/common/fs/fs_android.cpp167
-rw-r--r--src/common/fs/fs_android.h58
9 files changed, 159 insertions, 167 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index c19af2ab8..779be211e 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -182,9 +182,15 @@ endif()
if(ANDROID)
target_sources(common
- PRIVATE
+ PUBLIC
fs/fs_android.cpp
fs/fs_android.h
+ android/android_common.cpp
+ android/android_common.h
+ android/id_cache.cpp
+ android/id_cache.h
+ android/applets/software_keyboard.cpp
+ android/applets/software_keyboard.h
)
endif()
diff --git a/src/android/app/src/main/jni/android_common/android_common.cpp b/src/common/android/android_common.cpp
index 7018a52af..e79005658 100644
--- a/src/android/app/src/main/jni/android_common/android_common.cpp
+++ b/src/common/android/android_common.cpp
@@ -1,15 +1,17 @@
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
-#include "jni/android_common/android_common.h"
+#include "android_common.h"
#include <string>
#include <string_view>
#include <jni.h>
+#include "common/android/id_cache.h"
#include "common/string_util.h"
-#include "jni/id_cache.h"
+
+namespace Common::Android {
std::string GetJString(JNIEnv* env, jstring jstr) {
if (!jstr) {
@@ -18,7 +20,8 @@ std::string GetJString(JNIEnv* env, jstring jstr) {
const jchar* jchars = env->GetStringChars(jstr, nullptr);
const jsize length = env->GetStringLength(jstr);
- const std::u16string_view string_view(reinterpret_cast<const char16_t*>(jchars), length);
+ const std::u16string_view string_view(reinterpret_cast<const char16_t*>(jchars),
+ static_cast<u32>(length));
const std::string converted_string = Common::UTF16ToUTF8(string_view);
env->ReleaseStringChars(jstr, jchars);
@@ -36,25 +39,27 @@ jstring ToJString(JNIEnv* env, std::u16string_view str) {
}
double GetJDouble(JNIEnv* env, jobject jdouble) {
- return env->GetDoubleField(jdouble, IDCache::GetDoubleValueField());
+ return env->GetDoubleField(jdouble, GetDoubleValueField());
}
jobject ToJDouble(JNIEnv* env, double value) {
- return env->NewObject(IDCache::GetDoubleClass(), IDCache::GetDoubleConstructor(), value);
+ return env->NewObject(GetDoubleClass(), GetDoubleConstructor(), value);
}
s32 GetJInteger(JNIEnv* env, jobject jinteger) {
- return env->GetIntField(jinteger, IDCache::GetIntegerValueField());
+ return env->GetIntField(jinteger, GetIntegerValueField());
}
jobject ToJInteger(JNIEnv* env, s32 value) {
- return env->NewObject(IDCache::GetIntegerClass(), IDCache::GetIntegerConstructor(), value);
+ return env->NewObject(GetIntegerClass(), GetIntegerConstructor(), value);
}
bool GetJBoolean(JNIEnv* env, jobject jboolean) {
- return env->GetBooleanField(jboolean, IDCache::GetBooleanValueField());
+ return env->GetBooleanField(jboolean, GetBooleanValueField());
}
jobject ToJBoolean(JNIEnv* env, bool value) {
- return env->NewObject(IDCache::GetBooleanClass(), IDCache::GetBooleanConstructor(), value);
+ return env->NewObject(GetBooleanClass(), GetBooleanConstructor(), value);
}
+
+} // namespace Common::Android
diff --git a/src/android/app/src/main/jni/android_common/android_common.h b/src/common/android/android_common.h
index 29a338c0a..d0ccb4ec2 100644
--- a/src/android/app/src/main/jni/android_common/android_common.h
+++ b/src/common/android/android_common.h
@@ -8,6 +8,8 @@
#include <jni.h>
#include "common/common_types.h"
+namespace Common::Android {
+
std::string GetJString(JNIEnv* env, jstring jstr);
jstring ToJString(JNIEnv* env, std::string_view str);
jstring ToJString(JNIEnv* env, std::u16string_view str);
@@ -20,3 +22,5 @@ jobject ToJInteger(JNIEnv* env, s32 value);
bool GetJBoolean(JNIEnv* env, jobject jboolean);
jobject ToJBoolean(JNIEnv* env, bool value);
+
+} // namespace Common::Android
diff --git a/src/android/app/src/main/jni/applets/software_keyboard.cpp b/src/common/android/applets/software_keyboard.cpp
index 9943483e8..477e62b16 100644
--- a/src/android/app/src/main/jni/applets/software_keyboard.cpp
+++ b/src/common/android/applets/software_keyboard.cpp
@@ -6,12 +6,12 @@
#include <jni.h>
+#include "common/android/android_common.h"
+#include "common/android/applets/software_keyboard.h"
+#include "common/android/id_cache.h"
#include "common/logging/log.h"
#include "common/string_util.h"
#include "core/core.h"
-#include "jni/android_common/android_common.h"
-#include "jni/applets/software_keyboard.h"
-#include "jni/id_cache.h"
static jclass s_software_keyboard_class;
static jclass s_keyboard_config_class;
@@ -19,10 +19,10 @@ static jclass s_keyboard_data_class;
static jmethodID s_swkbd_execute_normal;
static jmethodID s_swkbd_execute_inline;
-namespace SoftwareKeyboard {
+namespace Common::Android::SoftwareKeyboard {
static jobject ToJKeyboardParams(const Core::Frontend::KeyboardInitializeParameters& config) {
- JNIEnv* env = IDCache::GetEnvForThread();
+ JNIEnv* env = GetEnvForThread();
jobject object = env->AllocObject(s_keyboard_config_class);
env->SetObjectField(object,
@@ -78,7 +78,7 @@ static jobject ToJKeyboardParams(const Core::Frontend::KeyboardInitializeParamet
}
AndroidKeyboard::ResultData AndroidKeyboard::ResultData::CreateFromFrontend(jobject object) {
- JNIEnv* env = IDCache::GetEnvForThread();
+ JNIEnv* env = GetEnvForThread();
const jstring string = reinterpret_cast<jstring>(env->GetObjectField(
object, env->GetFieldID(s_keyboard_data_class, "text", "Ljava/lang/String;")));
return ResultData{GetJString(env, string),
@@ -141,7 +141,7 @@ void AndroidKeyboard::ShowNormalKeyboard() const {
// Pivot to a new thread, as we cannot call GetEnvForThread() from a Fiber.
std::thread([&] {
- data = ResultData::CreateFromFrontend(IDCache::GetEnvForThread()->CallStaticObjectMethod(
+ data = ResultData::CreateFromFrontend(GetEnvForThread()->CallStaticObjectMethod(
s_software_keyboard_class, s_swkbd_execute_normal, ToJKeyboardParams(parameters)));
}).join();
@@ -183,8 +183,8 @@ void AndroidKeyboard::ShowInlineKeyboard(
// Pivot to a new thread, as we cannot call GetEnvForThread() from a Fiber.
m_is_inline_active = true;
std::thread([&] {
- IDCache::GetEnvForThread()->CallStaticVoidMethod(
- s_software_keyboard_class, s_swkbd_execute_inline, ToJKeyboardParams(parameters));
+ GetEnvForThread()->CallStaticVoidMethod(s_software_keyboard_class, s_swkbd_execute_inline,
+ ToJKeyboardParams(parameters));
}).join();
}
@@ -220,7 +220,7 @@ void AndroidKeyboard::SubmitInlineKeyboardText(std::u16string submitted_text) {
m_current_text += submitted_text;
submit_inline_callback(Service::AM::Frontend::SwkbdReplyType::ChangedString, m_current_text,
- m_current_text.size());
+ static_cast<int>(m_current_text.size()));
}
void AndroidKeyboard::SubmitInlineKeyboardInput(int key_code) {
@@ -242,7 +242,7 @@ void AndroidKeyboard::SubmitInlineKeyboardInput(int key_code) {
case KEYCODE_DEL:
m_current_text.pop_back();
submit_inline_callback(Service::AM::Frontend::SwkbdReplyType::ChangedString, m_current_text,
- m_current_text.size());
+ static_cast<int>(m_current_text.size()));
break;
}
}
@@ -274,4 +274,4 @@ void CleanupJNI(JNIEnv* env) {
env->DeleteGlobalRef(s_keyboard_data_class);
}
-} // namespace SoftwareKeyboard
+} // namespace Common::Android::SoftwareKeyboard
diff --git a/src/android/app/src/main/jni/applets/software_keyboard.h b/src/common/android/applets/software_keyboard.h
index 2affc01f6..9fd09d27c 100644
--- a/src/android/app/src/main/jni/applets/software_keyboard.h
+++ b/src/common/android/applets/software_keyboard.h
@@ -7,7 +7,7 @@
#include "core/frontend/applets/software_keyboard.h"
-namespace SoftwareKeyboard {
+namespace Common::Android::SoftwareKeyboard {
class AndroidKeyboard final : public Core::Frontend::SoftwareKeyboardApplet {
public:
@@ -66,7 +66,7 @@ void InitJNI(JNIEnv* env);
// Should be called in JNI_Unload
void CleanupJNI(JNIEnv* env);
-} // namespace SoftwareKeyboard
+} // namespace Common::Android::SoftwareKeyboard
// Native function calls
extern "C" {
diff --git a/src/android/app/src/main/jni/id_cache.cpp b/src/common/android/id_cache.cpp
index f30100bd8..f39262db9 100644
--- a/src/android/app/src/main/jni/id_cache.cpp
+++ b/src/common/android/id_cache.cpp
@@ -3,10 +3,10 @@
#include <jni.h>
+#include "applets/software_keyboard.h"
+#include "common/android/id_cache.h"
#include "common/assert.h"
#include "common/fs/fs_android.h"
-#include "jni/applets/software_keyboard.h"
-#include "jni/id_cache.h"
#include "video_core/rasterizer_interface.h"
static JavaVM* s_java_vm;
@@ -67,7 +67,7 @@ static jfieldID s_boolean_value_field;
static constexpr jint JNI_VERSION = JNI_VERSION_1_6;
-namespace IDCache {
+namespace Common::Android {
JNIEnv* GetEnvForThread() {
thread_local static struct OwnedEnv {
@@ -276,8 +276,6 @@ jfieldID GetBooleanValueField() {
return s_boolean_value_field;
}
-} // namespace IDCache
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -393,7 +391,7 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
Common::FS::Android::RegisterCallbacks(env, s_native_library_class);
// Initialize applets
- SoftwareKeyboard::InitJNI(env);
+ Common::Android::SoftwareKeyboard::InitJNI(env);
return JNI_VERSION;
}
@@ -426,3 +424,5 @@ void JNI_OnUnload(JavaVM* vm, void* reserved) {
#ifdef __cplusplus
}
#endif
+
+} // namespace Common::Android
diff --git a/src/android/app/src/main/jni/id_cache.h b/src/common/android/id_cache.h
index 00e48afc0..47802f96c 100644
--- a/src/android/app/src/main/jni/id_cache.h
+++ b/src/common/android/id_cache.h
@@ -3,20 +3,40 @@
#pragma once
+#include <future>
#include <jni.h>
#include "video_core/rasterizer_interface.h"
-namespace IDCache {
+namespace Common::Android {
JNIEnv* GetEnvForThread();
+
+/**
+ * Starts a new thread to run JNI. Intended to be used when you must run JNI from a fiber.
+ * @tparam T Typename of the return value for the work param
+ * @param work Lambda that runs JNI code. This function will take care of attaching this thread to
+ * the JVM
+ * @return The result from the work lambda param
+ */
+template <typename T = void>
+T RunJNIOnFiber(const std::function<T(JNIEnv*)>& work) {
+ std::future<T> j_result = std::async(std::launch::async, [&] {
+ auto env = GetEnvForThread();
+ return work(env);
+ });
+ return j_result.get();
+}
+
jclass GetNativeLibraryClass();
+
jclass GetDiskCacheProgressClass();
jclass GetDiskCacheLoadCallbackStageClass();
jclass GetGameDirClass();
jmethodID GetGameDirConstructor();
-jmethodID GetExitEmulationActivity();
jmethodID GetDiskCacheLoadProgress();
+
+jmethodID GetExitEmulationActivity();
jmethodID GetOnEmulationStarted();
jmethodID GetOnEmulationStopped();
jmethodID GetOnProgramChanged();
@@ -65,4 +85,4 @@ jclass GetBooleanClass();
jmethodID GetBooleanConstructor();
jfieldID GetBooleanValueField();
-} // namespace IDCache
+} // namespace Common::Android
diff --git a/src/common/fs/fs_android.cpp b/src/common/fs/fs_android.cpp
index 1dd826a4a..9a8053222 100644
--- a/src/common/fs/fs_android.cpp
+++ b/src/common/fs/fs_android.cpp
@@ -1,63 +1,38 @@
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
+#include "common/android/android_common.h"
+#include "common/android/id_cache.h"
+#include "common/assert.h"
#include "common/fs/fs_android.h"
#include "common/string_util.h"
namespace Common::FS::Android {
-JNIEnv* GetEnvForThread() {
- thread_local static struct OwnedEnv {
- OwnedEnv() {
- status = g_jvm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6);
- if (status == JNI_EDETACHED)
- g_jvm->AttachCurrentThread(&env, nullptr);
- }
-
- ~OwnedEnv() {
- if (status == JNI_EDETACHED)
- g_jvm->DetachCurrentThread();
- }
-
- int status;
- JNIEnv* env = nullptr;
- } owned;
- return owned.env;
-}
-
void RegisterCallbacks(JNIEnv* env, jclass clazz) {
env->GetJavaVM(&g_jvm);
native_library = clazz;
-#define FH(FunctionName, JMethodID, Caller, JMethodName, Signature) \
- F(JMethodID, JMethodName, Signature)
-#define FR(FunctionName, ReturnValue, JMethodID, Caller, JMethodName, Signature) \
- F(JMethodID, JMethodName, Signature)
-#define FS(FunctionName, ReturnValue, Parameters, JMethodID, JMethodName, Signature) \
- F(JMethodID, JMethodName, Signature)
-#define F(JMethodID, JMethodName, Signature) \
- JMethodID = env->GetStaticMethodID(native_library, JMethodName, Signature);
- ANDROID_SINGLE_PATH_HELPER_FUNCTIONS(FH)
- ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(FR)
- ANDROID_STORAGE_FUNCTIONS(FS)
-#undef F
-#undef FS
-#undef FR
-#undef FH
+ s_get_parent_directory = env->GetStaticMethodID(native_library, "getParentDirectory",
+ "(Ljava/lang/String;)Ljava/lang/String;");
+ s_get_filename = env->GetStaticMethodID(native_library, "getFilename",
+ "(Ljava/lang/String;)Ljava/lang/String;");
+ s_get_size = env->GetStaticMethodID(native_library, "getSize", "(Ljava/lang/String;)J");
+ s_is_directory = env->GetStaticMethodID(native_library, "isDirectory", "(Ljava/lang/String;)Z");
+ s_file_exists = env->GetStaticMethodID(native_library, "exists", "(Ljava/lang/String;)Z");
+ s_open_content_uri = env->GetStaticMethodID(native_library, "openContentUri",
+ "(Ljava/lang/String;Ljava/lang/String;)I");
}
void UnRegisterCallbacks() {
-#define FH(FunctionName, JMethodID, Caller, JMethodName, Signature) F(JMethodID)
-#define FR(FunctionName, ReturnValue, JMethodID, Caller, JMethodName, Signature) F(JMethodID)
-#define FS(FunctionName, ReturnValue, Parameters, JMethodID, JMethodName, Signature) F(JMethodID)
-#define F(JMethodID) JMethodID = nullptr;
- ANDROID_SINGLE_PATH_HELPER_FUNCTIONS(FH)
- ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(FR)
- ANDROID_STORAGE_FUNCTIONS(FS)
-#undef F
-#undef FS
-#undef FR
-#undef FH
+ s_get_parent_directory = nullptr;
+ s_get_filename = nullptr;
+
+ s_get_size = nullptr;
+ s_is_directory = nullptr;
+ s_file_exists = nullptr;
+
+ s_open_content_uri = nullptr;
}
bool IsContentUri(const std::string& path) {
@@ -69,8 +44,8 @@ bool IsContentUri(const std::string& path) {
return path.find(prefix) == 0;
}
-int OpenContentUri(const std::string& filepath, OpenMode openmode) {
- if (open_content_uri == nullptr)
+s32 OpenContentUri(const std::string& filepath, OpenMode openmode) {
+ if (s_open_content_uri == nullptr)
return -1;
const char* mode = "";
@@ -82,50 +57,66 @@ int OpenContentUri(const std::string& filepath, OpenMode openmode) {
UNIMPLEMENTED();
return -1;
}
- auto env = GetEnvForThread();
- jstring j_filepath = env->NewStringUTF(filepath.c_str());
- jstring j_mode = env->NewStringUTF(mode);
- return env->CallStaticIntMethod(native_library, open_content_uri, j_filepath, j_mode);
+ auto env = Common::Android::GetEnvForThread();
+ jstring j_filepath = Common::Android::ToJString(env, filepath);
+ jstring j_mode = Common::Android::ToJString(env, mode);
+ return env->CallStaticIntMethod(native_library, s_open_content_uri, j_filepath, j_mode);
+}
+
+u64 GetSize(const std::string& filepath) {
+ if (s_get_size == nullptr) {
+ return 0;
+ }
+ auto env = Common::Android::GetEnvForThread();
+ return static_cast<u64>(env->CallStaticLongMethod(
+ native_library, s_get_size,
+ Common::Android::ToJString(Common::Android::GetEnvForThread(), filepath)));
+}
+
+bool IsDirectory(const std::string& filepath) {
+ if (s_is_directory == nullptr) {
+ return 0;
+ }
+ auto env = Common::Android::GetEnvForThread();
+ return env->CallStaticBooleanMethod(
+ native_library, s_is_directory,
+ Common::Android::ToJString(Common::Android::GetEnvForThread(), filepath));
}
-#define FR(FunctionName, ReturnValue, JMethodID, Caller, JMethodName, Signature) \
- F(FunctionName, ReturnValue, JMethodID, Caller)
-#define F(FunctionName, ReturnValue, JMethodID, Caller) \
- ReturnValue FunctionName(const std::string& filepath) { \
- if (JMethodID == nullptr) { \
- return 0; \
- } \
- auto env = GetEnvForThread(); \
- jstring j_filepath = env->NewStringUTF(filepath.c_str()); \
- return env->Caller(native_library, JMethodID, j_filepath); \
+bool Exists(const std::string& filepath) {
+ if (s_file_exists == nullptr) {
+ return 0;
}
-ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(FR)
-#undef F
-#undef FR
-
-#define FH(FunctionName, JMethodID, Caller, JMethodName, Signature) \
- F(FunctionName, JMethodID, Caller)
-#define F(FunctionName, JMethodID, Caller) \
- std::string FunctionName(const std::string& filepath) { \
- if (JMethodID == nullptr) { \
- return 0; \
- } \
- auto env = GetEnvForThread(); \
- jstring j_filepath = env->NewStringUTF(filepath.c_str()); \
- jstring j_return = \
- static_cast<jstring>(env->Caller(native_library, JMethodID, j_filepath)); \
- if (!j_return) { \
- return {}; \
- } \
- const jchar* jchars = env->GetStringChars(j_return, nullptr); \
- const jsize length = env->GetStringLength(j_return); \
- const std::u16string_view string_view(reinterpret_cast<const char16_t*>(jchars), length); \
- const std::string converted_string = Common::UTF16ToUTF8(string_view); \
- env->ReleaseStringChars(j_return, jchars); \
- return converted_string; \
+ auto env = Common::Android::GetEnvForThread();
+ return env->CallStaticBooleanMethod(
+ native_library, s_file_exists,
+ Common::Android::ToJString(Common::Android::GetEnvForThread(), filepath));
+}
+
+std::string GetParentDirectory(const std::string& filepath) {
+ if (s_get_parent_directory == nullptr) {
+ return 0;
}
-ANDROID_SINGLE_PATH_HELPER_FUNCTIONS(FH)
-#undef F
-#undef FH
+ auto env = Common::Android::GetEnvForThread();
+ jstring j_return = static_cast<jstring>(env->CallStaticObjectMethod(
+ native_library, s_get_parent_directory, Common::Android::ToJString(env, filepath)));
+ if (!j_return) {
+ return {};
+ }
+ return Common::Android::GetJString(env, j_return);
+}
+
+std::string GetFilename(const std::string& filepath) {
+ if (s_get_filename == nullptr) {
+ return 0;
+ }
+ auto env = Common::Android::GetEnvForThread();
+ jstring j_return = static_cast<jstring>(env->CallStaticObjectMethod(
+ native_library, s_get_filename, Common::Android::ToJString(env, filepath)));
+ if (!j_return) {
+ return {};
+ }
+ return Common::Android::GetJString(env, j_return);
+}
} // namespace Common::FS::Android
diff --git a/src/common/fs/fs_android.h b/src/common/fs/fs_android.h
index 2c9234313..b33f4beb8 100644
--- a/src/common/fs/fs_android.h
+++ b/src/common/fs/fs_android.h
@@ -7,38 +7,17 @@
#include <vector>
#include <jni.h>
-#define ANDROID_STORAGE_FUNCTIONS(V) \
- V(OpenContentUri, int, (const std::string& filepath, OpenMode openmode), open_content_uri, \
- "openContentUri", "(Ljava/lang/String;Ljava/lang/String;)I")
-
-#define ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(V) \
- V(GetSize, std::uint64_t, get_size, CallStaticLongMethod, "getSize", "(Ljava/lang/String;)J") \
- V(IsDirectory, bool, is_directory, CallStaticBooleanMethod, "isDirectory", \
- "(Ljava/lang/String;)Z") \
- V(Exists, bool, file_exists, CallStaticBooleanMethod, "exists", "(Ljava/lang/String;)Z")
-
-#define ANDROID_SINGLE_PATH_HELPER_FUNCTIONS(V) \
- V(GetParentDirectory, get_parent_directory, CallStaticObjectMethod, "getParentDirectory", \
- "(Ljava/lang/String;)Ljava/lang/String;") \
- V(GetFilename, get_filename, CallStaticObjectMethod, "getFilename", \
- "(Ljava/lang/String;)Ljava/lang/String;")
-
namespace Common::FS::Android {
static JavaVM* g_jvm = nullptr;
static jclass native_library = nullptr;
-#define FH(FunctionName, JMethodID, Caller, JMethodName, Signature) F(JMethodID)
-#define FR(FunctionName, ReturnValue, JMethodID, Caller, JMethodName, Signature) F(JMethodID)
-#define FS(FunctionName, ReturnValue, Parameters, JMethodID, JMethodName, Signature) F(JMethodID)
-#define F(JMethodID) static jmethodID JMethodID = nullptr;
-ANDROID_SINGLE_PATH_HELPER_FUNCTIONS(FH)
-ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(FR)
-ANDROID_STORAGE_FUNCTIONS(FS)
-#undef F
-#undef FS
-#undef FR
-#undef FH
+static jmethodID s_get_parent_directory;
+static jmethodID s_get_filename;
+static jmethodID s_get_size;
+static jmethodID s_is_directory;
+static jmethodID s_file_exists;
+static jmethodID s_open_content_uri;
enum class OpenMode {
Read,
@@ -57,24 +36,11 @@ void UnRegisterCallbacks();
bool IsContentUri(const std::string& path);
-#define FS(FunctionName, ReturnValue, Parameters, JMethodID, JMethodName, Signature) \
- F(FunctionName, Parameters, ReturnValue)
-#define F(FunctionName, Parameters, ReturnValue) ReturnValue FunctionName Parameters;
-ANDROID_STORAGE_FUNCTIONS(FS)
-#undef F
-#undef FS
-
-#define FR(FunctionName, ReturnValue, JMethodID, Caller, JMethodName, Signature) \
- F(FunctionName, ReturnValue)
-#define F(FunctionName, ReturnValue) ReturnValue FunctionName(const std::string& filepath);
-ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(FR)
-#undef F
-#undef FR
-
-#define FH(FunctionName, JMethodID, Caller, JMethodName, Signature) F(FunctionName)
-#define F(FunctionName) std::string FunctionName(const std::string& filepath);
-ANDROID_SINGLE_PATH_HELPER_FUNCTIONS(FH)
-#undef F
-#undef FH
+int OpenContentUri(const std::string& filepath, OpenMode openmode);
+std::uint64_t GetSize(const std::string& filepath);
+bool IsDirectory(const std::string& filepath);
+bool Exists(const std::string& filepath);
+std::string GetParentDirectory(const std::string& filepath);
+std::string GetFilename(const std::string& filepath);
} // namespace Common::FS::Android