summaryrefslogtreecommitdiffstats
path: root/thirdparty/openxr/src/loader/android_utilities.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/openxr/src/loader/android_utilities.cpp')
-rw-r--r--thirdparty/openxr/src/loader/android_utilities.cpp54
1 files changed, 34 insertions, 20 deletions
diff --git a/thirdparty/openxr/src/loader/android_utilities.cpp b/thirdparty/openxr/src/loader/android_utilities.cpp
index 5c9b846b5a..1f7424b8e6 100644
--- a/thirdparty/openxr/src/loader/android_utilities.cpp
+++ b/thirdparty/openxr/src/loader/android_utilities.cpp
@@ -15,6 +15,7 @@
#include <openxr/openxr.h>
+#include <dlfcn.h>
#include <sstream>
#include <vector>
#include <android/log.h>
@@ -82,7 +83,6 @@ static Uri makeContentUri(bool systemBroker, int majorVersion, const char *abi)
.appendPath(abi)
.appendPath(RUNTIMES_PATH)
.appendPath(TABLE_PATH);
- ContentUris::appendId(builder, 0);
return builder.build();
}
@@ -175,7 +175,6 @@ static inline jni::Array<std::string> makeArray(std::initializer_list<const char
}
return ret;
}
-static constexpr auto TAG = "OpenXR-Loader";
#if defined(__arm__)
static constexpr auto ABI = "armeabi-v7l";
@@ -313,26 +312,41 @@ int getActiveRuntimeVirtualManifest(wrap::android::content::Context const &conte
cursor.moveToFirst();
- auto filename = cursor.getString(cursor.getColumnIndex(active_runtime::Columns::SO_FILENAME));
- auto libDir = cursor.getString(cursor.getColumnIndex(active_runtime::Columns::NATIVE_LIB_DIR));
- auto packageName = cursor.getString(cursor.getColumnIndex(active_runtime::Columns::PACKAGE_NAME));
-
- auto hasFunctions = cursor.getInt(cursor.getColumnIndex(active_runtime::Columns::HAS_FUNCTIONS)) == 1;
- __android_log_print(ANDROID_LOG_INFO, TAG, "Got runtime: package: %s, so filename: %s, native lib dir: %s, has functions: %s",
- packageName.c_str(), filename.c_str(), libDir.c_str(), (hasFunctions ? "yes" : "no"));
+ do {
+ auto filename = cursor.getString(cursor.getColumnIndex(active_runtime::Columns::SO_FILENAME));
+ auto libDir = cursor.getString(cursor.getColumnIndex(active_runtime::Columns::NATIVE_LIB_DIR));
+ auto packageName = cursor.getString(cursor.getColumnIndex(active_runtime::Columns::PACKAGE_NAME));
+
+ auto hasFunctions = cursor.getInt(cursor.getColumnIndex(active_runtime::Columns::HAS_FUNCTIONS)) == 1;
+ ALOGI("Got runtime: package: %s, so filename: %s, native lib dir: %s, has functions: %s", packageName.c_str(),
+ filename.c_str(), libDir.c_str(), (hasFunctions ? "yes" : "no"));
+
+ auto lib_path = libDir + "/" + filename;
+ auto *lib = dlopen(lib_path.c_str(), RTLD_LAZY | RTLD_LOCAL);
+ if (lib) {
+ // we found a runtime that we can dlopen, use it.
+ dlclose(lib);
+
+ JsonManifestBuilder builder{"runtime", lib_path};
+ if (hasFunctions) {
+ int result = populateFunctions(context, systemBroker, packageName, builder);
+ if (result != 0) {
+ ALOGW("Unable to populate functions from runtime: %s, checking for more records...", lib_path.c_str());
+ continue;
+ }
+ }
+ virtualManifest = builder.build();
+ cursor.close();
+ return 0;
+ }
+ // this runtime was not accessible, see if the broker has more runtimes on
+ // offer.
+ ALOGV("Unable to open broker provided runtime at %s, checking for more records...", lib_path.c_str());
+ } while (cursor.moveToNext());
- auto lib_path = libDir + "/" + filename;
+ ALOGE("Unable to open any of the broker provided runtimes.");
cursor.close();
-
- JsonManifestBuilder builder{"runtime", lib_path};
- if (hasFunctions) {
- int result = populateFunctions(context, systemBroker, packageName, builder);
- if (result != 0) {
- return result;
- }
- }
- virtualManifest = builder.build();
- return 0;
+ return -1;
}
} // namespace openxr_android