Skip to content

Commit

Permalink
RDKShell: Skip SetFocus to false for Suspended or Hibernated plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianM27 committed Nov 17, 2023
1 parent a6bd9dd commit 76016ef
Showing 1 changed file with 70 additions and 6 deletions.
76 changes: 70 additions & 6 deletions RDKShell/RDKShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ bool sForceResidentAppLaunch = false;
static bool sRunning = true;
bool needsScreenshot = false;

#ifdef HIBERNATE_SUPPORT_ENABLED
std::mutex gSuspendedOrHibernatedApplicationsMutex;
map<string, bool> gSuspendedOrHibernatedApplications;
#endif

#define ANY_KEY 65536
#define RDKSHELL_THUNDER_TIMEOUT 20000
#define RDKSHELL_POWER_TIME_WAIT 2.5
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -6288,6 +6329,9 @@ namespace WPEFramework {
else
{
eventMsg["success"] = true;
gSuspendedOrHibernatedApplicationsMutex.lock();
gSuspendedOrHibernatedApplications[callsign] = true;
gSuspendedOrHibernatedApplicationsMutex.unlock();
}
notify(RDKShell::RDKSHELL_EVENT_ON_HIBERNATED, eventMsg);
});
Expand Down Expand Up @@ -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<Exchange::IFocus>(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<Exchange::IFocus>(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;
}
}
Expand Down

0 comments on commit 76016ef

Please sign in to comment.