1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-02 16:48:55 +00:00

Deprecate and remove vendors specific XR APIs from the Godot core Android library

Follow-up to https://github.com/GodotVR/godot_openxr_vendors/pull/380, done in order to prevent vendors specific dependencies onto the Godot core Android library.
This commit is contained in:
Fredia Huya-Kouadio
2025-10-20 19:36:22 -07:00
committed by Fredia Huya-Kouadio
parent 9dd6c4dbac
commit 023024440b
13 changed files with 54 additions and 156 deletions

View File

@@ -1178,12 +1178,25 @@ class Godot private constructor(val context: Context) {
fun isProjectManagerHint() = isEditorBuild() && GodotLib.isProjectManagerHint()
/**
* Return true if the given feature is supported.
* Returns true if the feature for the given feature tag is supported in the currently running instance, depending
* on the platform, build, etc.
*
* For reference, see https://docs.godotengine.org/en/stable/classes/class_os.html#class-os-method-has-feature
*/
fun hasFeature(feature: String): Boolean {
return GodotLib.hasFeature(feature)
}
/**
* Internal method used to query whether the host or the registered plugins supports a given feature.
*
* This is invoked by the native code, and should not be confused with [hasFeature] which is the Android version of
* https://docs.godotengine.org/en/stable/classes/class_os.html#class-os-method-has-feature
*/
@Keep
private fun hasFeature(feature: String): Boolean {
private fun checkInternalFeatureSupport(feature: String): Boolean {
if (primaryHost?.supportsFeature(feature) == true) {
return true;
return true
}
for (plugin in pluginRegistry.allPlugins) {

View File

@@ -80,11 +80,13 @@ class GodotGLRenderView extends GLSurfaceView implements GodotRenderView {
private final GodotInputHandler inputHandler;
private final GodotRenderer godotRenderer;
private final SparseArray<PointerIcon> customPointerIcons = new SparseArray<>();
private final boolean isXrDevice;
public GodotGLRenderView(Godot godot, GodotInputHandler inputHandler, XRMode xrMode, boolean useDebugOpengl, boolean shouldBeTranslucent) {
super(godot.getContext());
this.godot = godot;
isXrDevice = godot.hasFeature("xr_runtime");
this.inputHandler = inputHandler;
this.godotRenderer = new GodotRenderer();
setPointerIcon(PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_DEFAULT));
@@ -172,6 +174,12 @@ class GodotGLRenderView extends GLSurfaceView implements GodotRenderView {
inputHandler.onPointerCaptureChange(hasCapture);
}
@Override
public boolean canCapturePointer() {
// Pointer capture is not supported on XR devices.
return !isXrDevice && inputHandler.canCapturePointer();
}
@Override
public void requestPointerCapture() {
if (canCapturePointer()) {

View File

@@ -314,4 +314,6 @@ public class GodotLib {
static native boolean isEditorHint();
static native boolean isProjectManagerHint();
static native boolean hasFeature(String feature);
}

View File

@@ -31,7 +31,6 @@
package org.godotengine.godot;
import org.godotengine.godot.input.GodotInputHandler;
import org.godotengine.godot.utils.DeviceUtils;
import android.view.SurfaceView;
@@ -67,8 +66,5 @@ public interface GodotRenderView {
/**
* @return true if pointer capture is supported.
*/
default boolean canCapturePointer() {
// Pointer capture is not supported on native XR devices.
return !DeviceUtils.isNativeXRDevice(getView().getContext()) && getInputHandler().canCapturePointer();
}
boolean canCapturePointer();
}

View File

@@ -55,11 +55,13 @@ class GodotVulkanRenderView extends VkSurfaceView implements GodotRenderView {
private final GodotInputHandler mInputHandler;
private final VkRenderer mRenderer;
private final SparseArray<PointerIcon> customPointerIcons = new SparseArray<>();
private final boolean isXrDevice;
public GodotVulkanRenderView(Godot godot, GodotInputHandler inputHandler, boolean shouldBeTranslucent) {
super(godot.getContext());
this.godot = godot;
isXrDevice = godot.hasFeature("xr_runtime");
mInputHandler = inputHandler;
mRenderer = new VkRenderer();
setPointerIcon(PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_DEFAULT));
@@ -151,6 +153,11 @@ class GodotVulkanRenderView extends VkSurfaceView implements GodotRenderView {
return mInputHandler.onGenericMotionEvent(event);
}
@Override
public boolean canCapturePointer() {
// Pointer capture is not supported on XR devices.
return !isXrDevice && mInputHandler.canCapturePointer();
}
@Override
public void requestPointerCapture() {
if (canCapturePointer()) {

View File

@@ -1,60 +0,0 @@
/**************************************************************************/
/* DeviceUtils.kt */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
/**
* Contains utility methods for detecting specific devices.
*/
@file:JvmName("DeviceUtils")
package org.godotengine.godot.utils
import android.content.Context
import android.os.Build
/**
* Returns true if running on Meta Horizon OS.
*/
fun isHorizonOSDevice(context: Context): Boolean {
return context.packageManager.hasSystemFeature("oculus.hardware.standalone_vr")
}
/**
* Returns true if running on PICO OS.
*/
fun isPicoOSDevice(): Boolean {
return ("Pico".equals(Build.BRAND, true))
}
/**
* Returns true if running on a native Android XR device.
*/
fun isNativeXRDevice(context: Context): Boolean {
return isHorizonOSDevice(context) || isPicoOSDevice()
}

View File

@@ -30,6 +30,8 @@
package org.godotengine.godot.utils;
import org.godotengine.godot.Godot;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
@@ -50,7 +52,6 @@ import androidx.core.content.ContextCompat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -159,7 +160,7 @@ public final class PermissionsUtil {
case "CAMERA":
permissions.add(Manifest.permission.CAMERA);
if (DeviceUtils.isHorizonOSDevice(activity)) {
if (Godot.getInstance(activity).hasFeature("horizonos")) {
// On HorizonOS, these permissions are required to get access to all the device's cameras.
permissions.add("horizonos.permission.AVATAR_CAMERA");
permissions.add("horizonos.permission.HEADSET_CAMERA");

View File

@@ -1,79 +0,0 @@
/**************************************************************************/
/* HybridAppUtils.kt */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
/**
* Contains utility methods and constants for hybrid apps.
*/
@file:JvmName("HybridAppUtils")
package org.godotengine.godot.xr
import android.util.Log
import org.godotengine.godot.GodotLib
private const val TAG = "HybridAppUtils"
enum class HybridMode(private val nativeValue: Int) {
NONE( -1),
IMMERSIVE(0),
PANEL(1);
companion object {
fun fromNative(nativeValue: Int): HybridMode {
for (mode in HybridMode.entries) {
if (mode.nativeValue == nativeValue) {
return mode
}
}
return NONE
}
}
}
const val HYBRID_APP_FEATURE = "godot_openxr_hybrid_app"
const val HYBRID_APP_PANEL_FEATURE = "godot_openxr_panel_app"
const val HYBRID_APP_PANEL_CATEGORY = "org.godotengine.xr.hybrid.PANEL"
const val HYBRID_APP_IMMERSIVE_CATEGORY = "org.godotengine.xr.hybrid.IMMERSIVE"
fun isHybridAppEnabled() = GodotLib.getGlobal("xr/hybrid_app/enabled").toBoolean()
fun getHybridAppLaunchMode(): HybridMode {
if (!isHybridAppEnabled()) {
return HybridMode.NONE
}
try {
val launchModeValue = GodotLib.getGlobal("xr/hybrid_app/launch_mode").toInt()
return HybridMode.fromNative(launchModeValue)
} catch (e: Exception) {
Log.w(TAG, "Unable to retrieve 'xr/hybrid_app/launch_mode' project setting", e)
return HybridMode.NONE
}
}