Jump to content

[Unity] Using android Wake Lock to keep the main thread running when the screens are off after the user removed the headset


Romain

Recommended Posts

Hello,

I'm working with a Vive Focus 3 and for one of my projects I need to keep the Update running while the screens are off when a user remove the headset. To be precise I need to keep the update running from when the user presence switch to false and the Wave WVR_Event OnRenderingToBePaused is called until the activation of the sleep mode after the duration that we can set in the headset advanced settings.

My understanding was that using android wake lock and acquiring the wake lock before the screens turn off would keep the main thread running while the screens are off but in practice the Update still stops to run even if I’m acquiring the wake lock at the start of the app and never release it. I acquire the Wake Lock using Unity AndroidJavaClass and I added the wake lock permissions in the android manifest. To be sure I correctly acquired the wake lock I also used adb dumpsys on the power service and everything seems alright, I see the wake lock on my app.

Has anybody already achieved to do this successfully? Does the headset itself prevent you to do that and it’s impossible to keep the Update running when the user is not present or am I missing something?

For example, if the main thread continue to run, should I still received event like OnRenderingToBePaused ? It sometimes feels like Wave SDK is forcing to pause everything.

Thanks!

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 3 months later...

Hi @JulienActiveMe,

Sorry, I just saw your message. Yes I managed to catch OnRenderingToBePaused event, you can using SystemEvent.Listen() from Wave.Essence.Events namespace.

Here is an example:

private void Start()
{
  // Add the listener
  SystemEvent.Listen(WVR_EventType.WVR_EventType_RenderingToBePaused, OnRenderingToBePaused);
}

private void OnDestroy()
{
  // Remove the listener when object is destroyed
  SystemEvent.Remove(WVR_EventType.WVR_EventType_RenderingToBePaused, OnRenderingToBePaused);
}

private void OnRenderingToBePaused(WVR_Event_t systemEvent)
{
  // Function triggered when the event is listened
}

 

Edited by Romain
Link to comment
Share on other sites

  • 2 months later...

A little update on this, since the release 5.3.0 (https://hub.vive.com/storage/docs/en-us/ReleaseNote.html#release-5-3-0) of the Wave XR Plugin, the main thread is no longer stopped when the user remove the headset which solve my initial issue.

Regarding the OnRenderingToBePaused/OnRenderingToBeResumed events since 5.3.0 I think they are no longer triggered since the rendering is no longer Paused when the headset is removed.

The weird thing is that, also since 5.3.0, CommonUsages.UserPresence is no longer supported to know when someone is wearing the headset, so there is no longer a way to know when the screens are on or off. For now, I found a workaround by using this asset (https://assetstore.unity.com/packages/tools/integration/pa-proximity-25685#description) but it would be nice to be able to get the userPresence out of the box.

Edited by Romain
Link to comment
Share on other sites

  • 1 month later...
On 12/1/2023 at 7:51 AM, Romain said:

Hi @JulienActiveMe,

Sorry, I just saw your message. Yes I managed to catch OnRenderingToBePaused event, you can using SystemEvent.Listen() from Wave.Essence.Events namespace.

Here is an example:

private void Start()
{
  // Add the listener
  SystemEvent.Listen(WVR_EventType.WVR_EventType_RenderingToBePaused, OnRenderingToBePaused);
}

private void OnDestroy()
{
  // Remove the listener when object is destroyed
  SystemEvent.Remove(WVR_EventType.WVR_EventType_RenderingToBePaused, OnRenderingToBePaused);
}

private void OnRenderingToBePaused(WVR_Event_t systemEvent)
{
  // Function triggered when the event is listened
}

 

 

I tried to use this to test and I could not make it work on 5.4.0, here some tests I've made:

void Start()
{
    Wave.Essence.Events.SystemEvent.Listen(WVR_EventType.WVR_EventType_DeviceResume, OnEventResume1);
    Wave.Essence.Events.SystemEvent.Listen(WVR_EventType.WVR_EventType_DeviceSuspend, OnEventResume2);
    Wave.Essence.Events.SystemEvent.Listen(WVR_EventType.WVR_EventType_DeviceInfoUpdate, OnEventResume3);
    Wave.Essence.Events.SystemEvent.Listen(WVR_EventType.WVR_EventType_RenderingToBePaused, OnEventResume4);
    Wave.Essence.Events.SystemEvent.Listen(WVR_EventType.WVR_EventType_RenderingToBeResumed, OnEventResume5);
}

private void OnEventResume1(WVR_Event_t systemEvent)
{
    Debug.LogError("--------------- CALLED EVENT 1");
}
private void OnEventResume2(WVR_Event_t systemEvent)
{
    Debug.LogError("--------------- CALLED EVENT 2");
}
private void OnEventResume3(WVR_Event_t systemEvent)
{
    Debug.LogError("--------------- CALLED EVENT 3");
}
private void OnEventResume4(WVR_Event_t systemEvent)
{
    Debug.LogError("--------------- CALLED EVENT 4");
}
private void OnEventResume5(WVR_Event_t systemEvent)
{
    Debug.LogError("--------------- CALLED EVENT 5");
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...