From b01f275862c5decd6e2ab4fae5d9c51361748b15 Mon Sep 17 00:00:00 2001 From: Adrian Muzyka Date: Thu, 24 Aug 2023 08:15:13 +0200 Subject: [PATCH] RDK-43052 Autocheckpoint native apps and getState fix --- RDKShell/CMakeLists.txt | 5 +++ RDKShell/RDKShell.cpp | 70 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/RDKShell/CMakeLists.txt b/RDKShell/CMakeLists.txt index 25a8b60caa..4d9ce98a29 100755 --- a/RDKShell/CMakeLists.txt +++ b/RDKShell/CMakeLists.txt @@ -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) @@ -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") diff --git a/RDKShell/RDKShell.cpp b/RDKShell/RDKShell.cpp index 4db0769ed2..c333660209 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_NATIVE_APPS_ON_SUSPENDED +std::mutex nativeAppWasResumedMutex; +map nativeAppWasResumed; +#endif + #define ANY_KEY 65536 #define RDKSHELL_THUNDER_TIMEOUT 20000 #define RDKSHELL_POWER_TIME_WAIT 2.5 @@ -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(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) @@ -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) { @@ -4814,17 +4855,18 @@ 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(RDKSHELL_THUNDER_TIMEOUT, "state", stateString); +#endif + stateStatus = getThunderControllerClient(callsignWithVersion)->Get(RDKSHELL_THUNDER_TIMEOUT, "state", stateString); +#ifdef HIBERNATE_SUPPORT_ENABLED } else { @@ -4832,6 +4874,7 @@ namespace WPEFramework { } #endif + if (stateStatus == 0) { WPEFramework::Core::JSON::String urlString; @@ -4840,7 +4883,7 @@ namespace WPEFramework { if(service.JSONState != PluginHost::MetaData::Service::state::HIBERNATED) { #endif - urlStatus = thunderPlugin->Get(RDKSHELL_THUNDER_TIMEOUT, "url",urlString); + urlStatus = getThunderControllerClient(callsignWithVersion)->Get(RDKSHELL_THUNDER_TIMEOUT, "url",urlString); #ifdef HIBERNATE_SUPPORT_ENABLED } #endif @@ -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(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([=]() {