8#include "evan/openxr/platform/AndroidXrPlatform.hpp"
9#include "evan/openxr/XrDeviceBackend.hpp"
29 std::filesystem::path queryJavaCacheDirectory(JNIEnv *environment,
32 jclass contextClass = environment->GetObjectClass(activity);
33 if (contextClass ==
nullptr) {
37 jmethodID getCacheDir = environment->GetMethodID(
38 contextClass,
"getCacheDir",
"()Ljava/io/File;");
39 if (getCacheDir ==
nullptr || environment->ExceptionCheck()) {
44 environment->CallObjectMethod(activity, getCacheDir);
45 if (cacheFile ==
nullptr) {
49 jclass fileClass = environment->GetObjectClass(cacheFile);
50 if (fileClass ==
nullptr) {
54 jmethodID getAbsolutePath = environment->GetMethodID(
55 fileClass,
"getAbsolutePath",
"()Ljava/lang/String;");
56 if (getAbsolutePath ==
nullptr || environment->ExceptionCheck()) {
60 auto path =
reinterpret_cast<jstring
>(
61 environment->CallObjectMethod(cacheFile, getAbsolutePath));
62 if (path ==
nullptr) {
66 const char *characters = environment->GetStringUTFChars(path,
nullptr);
67 if (characters ==
nullptr) {
71 std::filesystem::path directory(characters);
72 environment->ReleaseStringUTFChars(path, characters);
91 std::filesystem::path getAndroidCacheDirectory(
void *applicationVM,
94 if (applicationVM ==
nullptr || activity ==
nullptr) {
98 auto *vm =
static_cast<JavaVM *
>(applicationVM);
99 auto *instance =
static_cast<jobject
>(activity);
100 JNIEnv *environment =
nullptr;
101 bool attached =
false;
103 if (vm->GetEnv(
reinterpret_cast<void **
>(&environment),
106 if (vm->AttachCurrentThread(&environment,
nullptr) != JNI_OK) {
112 std::filesystem::path directory;
113 if (environment->PushLocalFrame(16) == JNI_OK) {
114 directory = queryJavaCacheDirectory(environment, instance);
115 environment->PopLocalFrame(
nullptr);
118 if (environment->ExceptionCheck()) {
119 environment->ExceptionClear();
124 vm->DetachCurrentThread();
135 this->
getLogger().info() <<
"Initializing AndroidXrPlatform with provided "
136 "Android platform data.";
166std::vector<std::string>
171#ifdef XR_USE_PLATFORM_ANDROID
196 _platformData.applicationActivity);
Small result wrapper used by helpers that must return both a status and a value (e....