From cf5b427a5d21a4c23fc82841c59f26c0385985d6 Mon Sep 17 00:00:00 2001 From: hugbug Date: Wed, 10 Apr 2024 00:31:04 +0200 Subject: [PATCH] [Android] Fix wake-up when sleeping with active hdmi Improved logic for wake-up handling. If hdmi was unplugged after switching screen off, the wake-up routine is executed after hdmi is plugged in. If hdmi remained active during sleep, the wake-up routine is executed directly after receiving screen-on event (do not wait for hdmi event, which never comes in that case). --- xbmc/platform/android/activity/XBMCApp.cpp | 17 ++++++++--------- xbmc/platform/android/activity/XBMCApp.h | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/xbmc/platform/android/activity/XBMCApp.cpp b/xbmc/platform/android/activity/XBMCApp.cpp index 8f5cd4765506e..a912c1da0e170 100644 --- a/xbmc/platform/android/activity/XBMCApp.cpp +++ b/xbmc/platform/android/activity/XBMCApp.cpp @@ -1332,22 +1332,21 @@ void CXBMCApp::onReceive(CJNIIntent intent) } else if (action == CJNIAudioManager::ACTION_HDMI_AUDIO_PLUG) { - m_supportsHdmiAudioPlug = true; - const bool hdmiPlugged = (intent.getIntExtra(CJNIAudioManager::EXTRA_AUDIO_PLUG_STATE, 0) != 0); - android_printf("-- HDMI is plugged in: %s", hdmiPlugged ? "yes" : "no"); + m_hdmiPlugged = (intent.getIntExtra(CJNIAudioManager::EXTRA_AUDIO_PLUG_STATE, 0) != 0); + android_printf("-- HDMI is plugged in: %s", m_hdmiPlugged ? "yes" : "no"); if (g_application.IsInitialized()) { CWinSystemBase* winSystem = CServiceBroker::GetWinSystem(); if (winSystem && dynamic_cast(winSystem)) - dynamic_cast(winSystem)->SetHdmiState(hdmiPlugged); + dynamic_cast(winSystem)->SetHdmiState(m_hdmiPlugged); } - if (hdmiPlugged && m_aeReset) + if (m_hdmiPlugged && m_aeReset) { android_printf("CXBMCApp::onReceive: Reset audio engine"); CServiceBroker::GetActiveAE()->DeviceChange(); m_aeReset = false; } - if (hdmiPlugged && m_wakeUp) + if (m_hdmiPlugged && m_wakeUp) { OnWakeup(); m_wakeUp = false; @@ -1361,11 +1360,11 @@ void CXBMCApp::onReceive(CJNIIntent intent) // screen but it is actually sent in response to changes in the overall interactive state of // the device. CLog::Log(LOGINFO, "Got device wakeup intent"); - if (m_supportsHdmiAudioPlug) + if (m_hdmiPlugged) + OnWakeup(); + else // wake-up sequence continues in ACTION_HDMI_AUDIO_PLUG intent m_wakeUp = true; - else - OnWakeup(); } else if (action == CJNIIntent::ACTION_SCREEN_OFF) { diff --git a/xbmc/platform/android/activity/XBMCApp.h b/xbmc/platform/android/activity/XBMCApp.h index 93644c55b4268..305c8513c0902 100644 --- a/xbmc/platform/android/activity/XBMCApp.h +++ b/xbmc/platform/android/activity/XBMCApp.h @@ -257,7 +257,7 @@ class CXBMCApp : public IActivityHandler, bool m_hdmiSource{false}; bool m_wakeUp{false}; bool m_aeReset{false}; - bool m_supportsHdmiAudioPlug{false}; + bool m_hdmiPlugged{true}; IInputDeviceCallbacks* m_inputDeviceCallbacks{nullptr}; IInputDeviceEventHandler* m_inputDeviceEventHandler{nullptr}; bool m_hasReqVisible{false};