monado/src/xrt/auxiliary/android/android_load_class.hpp
Ryan Pavlik c924157c59 a/android: Only look up the standardized intent to find our own package.
Should allow a constrained query manifest in client apps.
2023-04-25 10:40:58 -05:00

66 lines
1.9 KiB
C++

// Copyright 2020, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Function for loading Java code from a package.
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
* @ingroup aux_android
*/
#pragma once
#include <xrt/xrt_config_os.h>
#include "wrap/android.app.h"
#ifdef XRT_OS_ANDROID
//! C++-only functionality in the Android auxiliary library
namespace xrt::auxiliary::android {
using wrap::android::content::pm::ApplicationInfo;
/*!
* @note Starting from Android 11, NameNotFoundException exception is thrown if application doesn't
* specify either <queries> or "android.permission.QUERY_ALL_PACKAGES".
* See https://developer.android.com/training/package-visibility for detail.
*
* We work around this by querying first for org.khronos.openxr.OpenXRRuntimeService, for which a query entry is
* added by the Loader manifest.
*/
ApplicationInfo
getAppInfo(std::string const &packageName, jobject application_context);
/*!
* @note Starting from Android 11, NameNotFoundException exception is thrown if application doesn't
* specify either <queries> or "android.permission.QUERY_ALL_PACKAGES".
* See https://developer.android.com/training/package-visibility for detail.
*/
wrap::java::lang::Class
loadClassFromPackage(ApplicationInfo applicationInfo, jobject application_context, const char *clazz_name);
/*!
* Loading class from given apk path.
*
* @param application_context Context.
* @param apk_path Path to apk.
* @param clazz_name Name of class to be loaded.
* @return Class object.
*/
wrap::java::lang::Class
loadClassFromApk(jobject application_context, const char *apk_path, const char *clazz_name);
/*!
* Loading class from runtime apk.
*
* @param application_context Context.
* @param clazz_name Name of class to be loaded.
* @return Class object.
*/
wrap::java::lang::Class
loadClassFromRuntimeApk(jobject application_context, const char *clazz_name);
} // namespace xrt::auxiliary::android
#endif // XRT_OS_ANDROID