summaryrefslogtreecommitdiff
path: root/src/common/fs/fs_android.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/fs/fs_android.h')
-rw-r--r--src/common/fs/fs_android.h65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/common/fs/fs_android.h b/src/common/fs/fs_android.h
new file mode 100644
index 000000000..b441c2a12
--- /dev/null
+++ b/src/common/fs/fs_android.h
@@ -0,0 +1,65 @@
1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <string>
7#include <vector>
8#include <jni.h>
9
10#define ANDROID_STORAGE_FUNCTIONS(V) \
11 V(OpenContentUri, int, (const std::string& filepath, OpenMode openmode), open_content_uri, \
12 "openContentUri", "(Ljava/lang/String;Ljava/lang/String;)I")
13
14#define ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(V) \
15 V(GetSize, std::uint64_t, get_size, CallStaticLongMethod, "getSize", "(Ljava/lang/String;)J") \
16 V(IsDirectory, bool, is_directory, CallStaticBooleanMethod, "isDirectory", \
17 "(Ljava/lang/String;)Z") \
18 V(Exists, bool, file_exists, CallStaticBooleanMethod, "exists", "(Ljava/lang/String;)Z")
19
20namespace Common::FS::Android {
21
22static JavaVM* g_jvm = nullptr;
23static jclass native_library = nullptr;
24
25#define FR(FunctionName, ReturnValue, JMethodID, Caller, JMethodName, Signature) F(JMethodID)
26#define FS(FunctionName, ReturnValue, Parameters, JMethodID, JMethodName, Signature) F(JMethodID)
27#define F(JMethodID) static jmethodID JMethodID = nullptr;
28ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(FR)
29ANDROID_STORAGE_FUNCTIONS(FS)
30#undef F
31#undef FS
32#undef FR
33
34enum class OpenMode {
35 Read,
36 Write,
37 ReadWrite,
38 WriteAppend,
39 WriteTruncate,
40 ReadWriteAppend,
41 ReadWriteTruncate,
42 Never
43};
44
45void RegisterCallbacks(JNIEnv* env, jclass clazz);
46
47void UnRegisterCallbacks();
48
49bool IsContentUri(const std::string& path);
50
51#define FS(FunctionName, ReturnValue, Parameters, JMethodID, JMethodName, Signature) \
52 F(FunctionName, Parameters, ReturnValue)
53#define F(FunctionName, Parameters, ReturnValue) ReturnValue FunctionName Parameters;
54ANDROID_STORAGE_FUNCTIONS(FS)
55#undef F
56#undef FS
57
58#define FR(FunctionName, ReturnValue, JMethodID, Caller, JMethodName, Signature) \
59 F(FunctionName, ReturnValue)
60#define F(FunctionName, ReturnValue) ReturnValue FunctionName(const std::string& filepath);
61ANDROID_SINGLE_PATH_DETERMINE_FUNCTIONS(FR)
62#undef F
63#undef FR
64
65} // namespace Common::FS::Android