Skip to content

Commit

Permalink
Add a project setting to enable/disable automatic requests for runtim…
Browse files Browse the repository at this point in the history
…e permissions
  • Loading branch information
m4gr3d committed Sep 8, 2024
1 parent 7e7c32c commit db5c902
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
4 changes: 4 additions & 0 deletions demo/export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ khronos_xr_features/htc/eye_tracking=0
khronos_xr_features/htc/lip_expression=0
pico_xr_features/eye_tracking=0
pico_xr_features/face_tracking=0
khronos_xr_features/vendors=0

[preset.1]

Expand Down Expand Up @@ -465,6 +466,7 @@ meta_xr_features/quest_pro_support=true
xr_features/enable_pico_plugin=false
pico_xr_features/eye_tracking=0
pico_xr_features/face_tracking=0
khronos_xr_features/vendors=0

[preset.2]

Expand Down Expand Up @@ -699,6 +701,7 @@ meta_xr_features/quest_pro_support=true
xr_features/enable_pico_plugin=true
pico_xr_features/eye_tracking=1
pico_xr_features/face_tracking=3
khronos_xr_features/vendors=0

[preset.3]

Expand Down Expand Up @@ -933,6 +936,7 @@ meta_xr_features/quest_pro_support=true
xr_features/enable_pico_plugin=false
pico_xr_features/eye_tracking=0
pico_xr_features/face_tracking=0
khronos_xr_features/vendors=0

[preset.4]

Expand Down
2 changes: 2 additions & 0 deletions godotopenxr/src/main/cpp/include/register_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ using namespace godot;

void initialize_plugin_module(ModuleInitializationLevel p_level);
void terminate_plugin_module(ModuleInitializationLevel p_level);

void add_plugin_project_settings();
27 changes: 27 additions & 0 deletions godotopenxr/src/main/cpp/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <gdextension_interface.h>

#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/project_settings.hpp>
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>
Expand Down Expand Up @@ -154,6 +155,8 @@ void initialize_plugin_module(ModuleInitializationLevel p_level) {
break;

case MODULE_INITIALIZATION_LEVEL_SCENE: {
add_plugin_project_settings();

Engine::get_singleton()->register_singleton("OpenXRFbPassthroughExtensionWrapper", OpenXRFbPassthroughExtensionWrapper::get_singleton());
Engine::get_singleton()->register_singleton("OpenXRFbRenderModelExtensionWrapper", OpenXRFbRenderModelExtensionWrapper::get_singleton());
Engine::get_singleton()->register_singleton("OpenXRFbSceneCaptureExtensionWrapper", OpenXRFbSceneCaptureExtensionWrapper::get_singleton());
Expand Down Expand Up @@ -209,6 +212,30 @@ void initialize_plugin_module(ModuleInitializationLevel p_level) {
void terminate_plugin_module(ModuleInitializationLevel p_level) {
}

void add_plugin_project_settings() {
ProjectSettings* project_settings = ProjectSettings::get_singleton();
if (project_settings == nullptr) {
return;
}

{
// Add the 'automatically_request_runtime_permissions' project setting
String request_permissions_setting = "xr/openxr/extensions/automatically_request_runtime_permissions";
if (!project_settings->has_setting(request_permissions_setting)) {
// Default value is `true` to match prior plugin behavior
project_settings->set_setting(request_permissions_setting, true);
}

project_settings->set_initial_value(request_permissions_setting, true);
project_settings->set_as_basic(request_permissions_setting, false);
Dictionary property_info;
property_info["name"] = request_permissions_setting;
property_info["type"] = Variant::Type::BOOL;
property_info["hint"] = PROPERTY_HINT_NONE;
project_settings->add_property_info(property_info);
}
}

extern "C" {
GDExtensionBool GDE_EXPORT plugin_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ package org.godotengine.openxr.vendors

import android.util.Log
import org.godotengine.godot.Godot
import org.godotengine.godot.GodotLib
import org.godotengine.godot.plugin.GodotPlugin
import org.godotengine.godot.utils.PermissionsUtil

Expand All @@ -56,10 +57,19 @@ abstract class GodotOpenXR(godot: Godot?) : GodotPlugin(godot) {
override fun onGodotSetupCompleted() {
super.onGodotSetupCompleted()

// Request plugin permissions if needed
val permissionsToRequest = getPluginPermissionsToEnable()
if (permissionsToRequest.isNotEmpty()) {
PermissionsUtil.requestPermissions(activity, permissionsToRequest)
// Check if automatic permissions request is enabled.
val automaticallyRequestPermissionsSetting = GodotLib.getGlobal("xr/openxr/extensions/automatically_request_runtime_permissions")
// We only request permissions when the project setting is enabled.
// If the project setting is not defined, we fall-back to the default behavior which is
// to automatically request permissions.
val requestPermissionsEnabled = automaticallyRequestPermissionsSetting.isNullOrEmpty() ||
automaticallyRequestPermissionsSetting.toBoolean()
if (requestPermissionsEnabled) {
val permissionsToRequest = getPluginPermissionsToEnable()
if (permissionsToRequest.isNotEmpty()) {
Log.v(TAG, "Performing automatic request of runtime permissions")
PermissionsUtil.requestPermissions(activity, permissionsToRequest)
}
}
}

Expand Down

0 comments on commit db5c902

Please sign in to comment.