Skip to content

Commit

Permalink
RDK-43052 Autocheckpoint native apps and getState fix
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianM27 committed Oct 3, 2023
1 parent 38c5059 commit b01f275
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 5 deletions.
5 changes: 5 additions & 0 deletions RDKShell/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(PLUGIN_RDKSHELL_STARTUPORDER "" CACHE STRING "Automatically start RDKShell p

option(PLUGIN_RDKSHELL_READ_MAC_ON_STARTUP "PLUGIN_RDKSHELL_READ_MAC_ON_STARTUP" OFF)
option(PLUGIN_HIBERNATESUPPORT "Include hibernate support in the build." OFF)
option(PLUGIN_HIBERNATE_NATIVE_APPS_ON_SUSPENDED "Try to hibernate native apps on suspended." OFF)

find_package(${NAMESPACE}Plugins REQUIRED)
find_package(IARMBus)
Expand Down Expand Up @@ -55,6 +56,10 @@ if(PLUGIN_HIBERNATESUPPORT)
target_compile_definitions(${MODULE_NAME} PRIVATE HIBERNATE_SUPPORT_ENABLED=1)
endif()

if(PLUGIN_HIBERNATE_NATIVE_APPS_ON_SUSPENDED)
target_compile_definitions(${MODULE_NAME} PRIVATE HIBERNATE_NATIVE_APPS_ON_SUSPENDED=1)
endif()

target_include_directories(${MODULE_NAME} PRIVATE ../helpers ${IARMBUS_INCLUDE_DIRS} )

set_source_files_properties(RDKShell.cpp PROPERTIES COMPILE_FLAGS "-fexceptions")
Expand Down
70 changes: 65 additions & 5 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_NATIVE_APPS_ON_SUSPENDED
std::mutex nativeAppWasResumedMutex;
map<string,bool> nativeAppWasResumed;
#endif

#define ANY_KEY 65536
#define RDKSHELL_THUNDER_TIMEOUT 20000
#define RDKSHELL_POWER_TIME_WAIT 2.5
Expand Down Expand Up @@ -578,7 +583,38 @@ namespace WPEFramework {
JsonObject params;
params["client"] = mCallSign;
mRDKShell.notify(RDKShell::RDKSHELL_EVENT_ON_PLUGIN_SUSPENDED, params);
}

#ifdef HIBERNATE_NATIVE_APPS_ON_SUSPENDED
RFC_ParamData_t param;
if (Utils::getRFCConfig("Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.AppHibernate.Enable", param)
&& strncasecmp(param.value, "true", 4) == 0)
{
nativeAppWasResumedMutex.lock();
if ((mCallSign.find("Netflix") != std::string::npos || mCallSign.find("Cobalt") != std::string::npos)
&& nativeAppWasResumed.find(mCallSign) != nativeAppWasResumed.end()
&& nativeAppWasResumed[mCallSign])
{
// call RDKShell.checkpoint
std::thread requestsThread =
std::thread([=]()
{
JsonObject checkpointParams;
JsonObject checkpointResponse;
checkpointParams["callsign"] = mCallSign;
mRDKShell.getThunderControllerClient("org.rdk.RDKShell.1")->Invoke<JsonObject, JsonObject>(0, "checkpoint", checkpointParams, checkpointResponse); });

requestsThread.detach();
}
nativeAppWasResumedMutex.unlock();
}
#endif
}
#ifdef HIBERNATE_NATIVE_APPS_ON_SUSPENDED
nativeAppWasResumedMutex.lock();
nativeAppWasResumed[mCallSign] = (state == PluginHost::IStateControl::RESUMED);
nativeAppWasResumedMutex.unlock();
#endif

}

BEGIN_INTERFACE_MAP(Notification)
Expand Down Expand Up @@ -939,6 +975,11 @@ namespace WPEFramework {
if ((currentState == PluginHost::IShell::DEACTIVATED) || (currentState == PluginHost::IShell::DESTROYED))
{
gApplicationsExitReason[service->Callsign()] = AppLastExitReason::DEACTIVATED;
#ifdef HIBERNATE_NATIVE_APPS_ON_SUSPENDED
nativeAppWasResumedMutex.lock();
nativeAppWasResumed[service->Callsign()] = false;
nativeAppWasResumedMutex.unlock();
#endif
}
if(service->Reason() == PluginHost::IShell::FAILURE)
{
Expand Down Expand Up @@ -4814,24 +4855,26 @@ namespace WPEFramework {
{
std::string callsign;
service.Callsign.ToString(callsign);
callsign.erase(std::remove(callsign.begin(),callsign.end(),'\"'),callsign.end());

callsign.erase(std::remove(callsign.begin(),callsign.end(),'\"'),callsign.end());
WPEFramework::Core::JSON::String stateString;
const string callsignWithVersion = callsign + ".1";
auto thunderPlugin = getThunderControllerClient(callsignWithVersion);
uint32_t stateStatus = 0;

#ifdef HIBERNATE_SUPPORT_ENABLED
if(service.JSONState != PluginHost::MetaData::Service::state::HIBERNATED)
{
stateStatus = thunderPlugin->Get<WPEFramework::Core::JSON::String>(RDKSHELL_THUNDER_TIMEOUT, "state", stateString);
#endif
stateStatus = getThunderControllerClient(callsignWithVersion)->Get<WPEFramework::Core::JSON::String>(RDKSHELL_THUNDER_TIMEOUT, "state", stateString);
#ifdef HIBERNATE_SUPPORT_ENABLED
}
else
{
stateString = "checkpointed";
}
#endif


if (stateStatus == 0)
{
WPEFramework::Core::JSON::String urlString;
Expand All @@ -4840,7 +4883,7 @@ namespace WPEFramework {
if(service.JSONState != PluginHost::MetaData::Service::state::HIBERNATED)
{
#endif
urlStatus = thunderPlugin->Get<WPEFramework::Core::JSON::String>(RDKSHELL_THUNDER_TIMEOUT, "url",urlString);
urlStatus = getThunderControllerClient(callsignWithVersion)->Get<WPEFramework::Core::JSON::String>(RDKSHELL_THUNDER_TIMEOUT, "url",urlString);
#ifdef HIBERNATE_SUPPORT_ENABLED
}
#endif
Expand Down Expand Up @@ -5977,6 +6020,23 @@ namespace WPEFramework {
returnResponse(status);
}

if( callsign.find("Netflix") != string::npos || callsign.find("Cobalt") != string::npos )
{
//Check if native app is suspended
WPEFramework::Core::JSON::String stateString;
const string callsignWithVersion = callsign + ".1";
auto thunderPlugin = getThunderControllerClient(callsignWithVersion);
uint32_t stateStatus = 0;
stateStatus = thunderPlugin->Get<WPEFramework::Core::JSON::String>(RDKSHELL_THUNDER_TIMEOUT, "state", stateString);
if(stateStatus || stateString != "suspended")
{
std::cout << "ignoring checkpoint for " << callsign << " as it is not suspended " << std::endl;
status = false;
response["message"] = "failed to checkpoint native application, not suspended";
returnResponse(status);
}
}

std::thread requestsThread =
std::thread([=]()
{
Expand Down

0 comments on commit b01f275

Please sign in to comment.