From 76016ef32e868dfb9a33b143c261414edfcbf677 Mon Sep 17 00:00:00 2001 From: Adrian Muzyka Date: Thu, 16 Nov 2023 11:03:10 +0100 Subject: [PATCH] RDKShell: Skip SetFocus to false for Suspended or Hibernated plugins --- RDKShell/RDKShell.cpp | 76 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 6 deletions(-) diff --git a/RDKShell/RDKShell.cpp b/RDKShell/RDKShell.cpp index 6bb572483f..75673dc905 100755 --- a/RDKShell/RDKShell.cpp +++ b/RDKShell/RDKShell.cpp @@ -197,6 +197,11 @@ bool sForceResidentAppLaunch = false; static bool sRunning = true; bool needsScreenshot = false; +#ifdef HIBERNATE_SUPPORT_ENABLED +std::mutex gSuspendedOrHibernatedApplicationsMutex; +map gSuspendedOrHibernatedApplications; +#endif + #define ANY_KEY 65536 #define RDKSHELL_THUNDER_TIMEOUT 20000 #define RDKSHELL_POWER_TIME_WAIT 2.5 @@ -605,6 +610,11 @@ namespace WPEFramework { mRDKShell.notify(RDKShell::RDKSHELL_EVENT_ON_LAUNCHED, params); mLaunchEnabled = false; } +#ifdef HIBERNATE_SUPPORT_ENABLED + gSuspendedOrHibernatedApplicationsMutex.lock(); + gSuspendedOrHibernatedApplications[mCallSign] = isSuspended; + gSuspendedOrHibernatedApplicationsMutex.unlock(); +#endif if (isSuspended) { @@ -1035,6 +1045,17 @@ namespace WPEFramework { } gExitReasonMutex.lock(); gApplicationsExitReason[service->Callsign()] = AppLastExitReason::DEACTIVATED; + +#ifdef HIBERNATE_SUPPORT_ENABLED + //Reset app suspended/hibernated + gSuspendedOrHibernatedApplicationsMutex.lock(); + auto suspendedOrHibernatedIt = gSuspendedOrHibernatedApplications.find(service->Callsign()); + if (suspendedOrHibernatedIt != gSuspendedOrHibernatedApplications.end()) + { + gSuspendedOrHibernatedApplications.erase(suspendedOrHibernatedIt); + } + gSuspendedOrHibernatedApplicationsMutex.unlock(); +#endif if(service->Reason() == PluginHost::IShell::FAILURE) { gApplicationsExitReason[service->Callsign()] = AppLastExitReason::CRASH; @@ -1105,6 +1126,16 @@ namespace WPEFramework { if ((currentState == PluginHost::IShell::DEACTIVATED) || (currentState == PluginHost::IShell::DESTROYED)) { gApplicationsExitReason[service->Callsign()] = AppLastExitReason::DEACTIVATED; +#ifdef HIBERNATE_SUPPORT_ENABLED + //Reset app suspended/hibernated on Deactivation/Destroy + gSuspendedOrHibernatedApplicationsMutex.lock(); + auto suspendedOrHibernatedIt = gSuspendedOrHibernatedApplications.find(service->Callsign()); + if (suspendedOrHibernatedIt != gSuspendedOrHibernatedApplications.end()) + { + gSuspendedOrHibernatedApplications.erase(suspendedOrHibernatedIt); + } + gSuspendedOrHibernatedApplicationsMutex.unlock(); +#endif } if(service->Reason() == PluginHost::IShell::FAILURE) { @@ -3834,6 +3865,16 @@ namespace WPEFramework { setAVBlocked(callsign, blockAV); } } +#ifdef HIBERNATE_SUPPORT_ENABLED + //Reset app suspended/hibernated for launch + gSuspendedOrHibernatedApplicationsMutex.lock(); + auto suspendedOrHibernatedIt = gSuspendedOrHibernatedApplications.find(appCallsign); + if (suspendedOrHibernatedIt != gSuspendedOrHibernatedApplications.end()) + { + gSuspendedOrHibernatedApplications.erase(suspendedOrHibernatedIt); + } + gSuspendedOrHibernatedApplicationsMutex.unlock(); +#endif //check to see if plugin already exists bool newPluginFound = false; @@ -6288,6 +6329,9 @@ namespace WPEFramework { else { eventMsg["success"] = true; + gSuspendedOrHibernatedApplicationsMutex.lock(); + gSuspendedOrHibernatedApplications[callsign] = true; + gSuspendedOrHibernatedApplicationsMutex.unlock(); } notify(RDKShell::RDKSHELL_EVENT_ON_HIBERNATED, eventMsg); }); @@ -6590,14 +6634,34 @@ namespace WPEFramework { std::string compositorName = toLower(previousFocusedIterator->first); if (compositorName == previousFocusedClient) { - std::cout << "setting the focus of " << compositorName << " to false " << std::endl; - Exchange::IFocus *focusedCallsign = mCurrentService->QueryInterfaceByCallsign(previousFocusedIterator->first); - if (focusedCallsign != NULL) +#ifdef HIBERNATE_SUPPORT_ENABLED + // Skip for suspended and hibernated apps, since not needed and may cause unwanted restore from hibernation + bool skipFocus = false; + gSuspendedOrHibernatedApplicationsMutex.lock(); + if (gSuspendedOrHibernatedApplications.find(previousFocusedIterator->first) != gSuspendedOrHibernatedApplications.end()) + { + skipFocus = gSuspendedOrHibernatedApplications[previousFocusedIterator->first]; + } + + if (skipFocus == false) { - uint32_t status = focusedCallsign->Focused(false); - std::cout << "result of set focus to false: " << status << std::endl; - focusedCallsign->Release(); +#endif + std::cout << "setting the focus of " << compositorName << " to false " << std::endl; + Exchange::IFocus *focusedCallsign = mCurrentService->QueryInterfaceByCallsign(previousFocusedIterator->first); + if (focusedCallsign != NULL) + { + uint32_t status = focusedCallsign->Focused(false); + std::cout << "result of set focus to false: " << status << std::endl; + focusedCallsign->Release(); + } +#ifdef HIBERNATE_SUPPORT_ENABLED + } + else + { + std::cout << "setting the focus for " << compositorName << " to false skipped, plugin suspended or hibernated " << std::endl; } + gSuspendedOrHibernatedApplicationsMutex.unlock(); +#endif break; } }