Skip to content

Commit cadac5e

Browse files
committed
Add android.permission.EYE_TRACKING_FINE request
1 parent 8fa17da commit cadac5e

1 file changed

Lines changed: 48 additions & 1 deletion

File tree

org.mixedrealitytoolkit.input/Interactors/Gaze/GazeInteractor.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
using UnityEngine;
66
using UnityEngine.XR.Interaction.Toolkit.Interactors;
77

8+
#if UNITY_ANDROID && !UNITY_EDITOR
9+
using UnityEngine.Android;
10+
#endif
11+
812
namespace MixedReality.Toolkit.Input
913
{
1014
/// <summary>
@@ -25,7 +29,7 @@ public class GazeInteractor :
2529
/// interaction mode manager and is assigned an interaction mode. This GameObject represents the group that this interactor belongs to.
2630
/// </summary>
2731
/// <remarks>
28-
/// This will default to the GameObject that this attached to a parent <see cref="TrackedPoseDriver"/>.
32+
/// This will default to the GameObject that this attached to a parent <see cref="UnityEngine.InputSystem.XR.TrackedPoseDriver"/>.
2933
/// </remarks>
3034
public GameObject ModeManagedRoot
3135
{
@@ -41,5 +45,48 @@ public GameObject GetModeManagedController()
4145
// interaction mode manager is used instead.
4246
return forceDeprecatedInput ? null : ModeManagedRoot;
4347
}
48+
49+
#if UNITY_ANDROID && !UNITY_EDITOR
50+
protected override void Start()
51+
{
52+
base.Start();
53+
54+
if (!Permission.HasUserAuthorizedPermission(EyeTrackingPermission))
55+
{
56+
PermissionCallbacks callbacks = new();
57+
callbacks.PermissionDenied += OnPermissionDenied;
58+
callbacks.PermissionGranted += OnPermissionGranted;
59+
60+
Permission.RequestUserPermission(EyeTrackingPermission, callbacks);
61+
Debug.Log($"MRTK is requesting {EyeTrackingPermission}.");
62+
}
63+
else
64+
{
65+
Debug.Log($"{EyeTrackingPermission} already granted for MRTK.");
66+
}
67+
}
68+
69+
private const string EyeTrackingPermission = "android.permission.EYE_TRACKING_FINE";
70+
71+
void OnPermissionDenied(string permission)
72+
{
73+
if (permission == EyeTrackingPermission)
74+
{
75+
Debug.Log($"{EyeTrackingPermission} denied or not needed on this runtime" +
76+
#if UNITY_OPENXR_PRESENT
77+
$" ({UnityEngine.XR.OpenXR.OpenXRRuntime.name})" +
78+
#endif
79+
". MRTK eye gaze tracking may not work as expected.");
80+
}
81+
}
82+
83+
void OnPermissionGranted(string permission)
84+
{
85+
if (permission == EyeTrackingPermission)
86+
{
87+
Debug.Log($"{EyeTrackingPermission} newly granted for MRTK.");
88+
}
89+
}
90+
#endif // UNITY_ANDROID && !UNITY_EDITOR
4491
}
4592
}

0 commit comments

Comments
 (0)