Skip to content

Add runtime WhoAmI checks in MaintenanceManager [Sprint Test] Experimental #6243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: sprint/25Q2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 108 additions & 70 deletions MaintenanceManager/MaintenanceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "UtilsJsonRpc.h"
#include "UtilscRunScript.h"
#include "UtilsfileExists.h"
#include "UtilsgetFileContent.h"

#if defined(USE_IARMBUS) || defined(USE_IARM_BUS)
#include "libIARM.h"
Expand All @@ -64,7 +65,7 @@ using namespace std;

#define API_VERSION_NUMBER_MAJOR 1
#define API_VERSION_NUMBER_MINOR 0
#define API_VERSION_NUMBER_PATCH 43
#define API_VERSION_NUMBER_PATCH 44
#define SERVER_DETAILS "127.0.0.1:9998"

#define PROC_DIR "/proc"
Expand All @@ -75,11 +76,9 @@ using namespace std;
#define TR181_STOP_MAINTENANCE "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.StopMaintenance.Enable"
#define TR181_RDKVFWUPGRADER "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.RDKFirmwareUpgrader.Enable"

#if defined(ENABLE_WHOAMI)
#define TR181_PARTNER_ID "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerName"
#define TR181_TARGET_OS_CLASS "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.OsClass"
#define TR181_XCONFURL "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.XconfUrl"
#endif

#define RFC_TASK RDK_PATH "Start_RFC.sh"
#define SWUPDATE_TASK RDK_PATH "swupdate_utility.sh"
Expand Down Expand Up @@ -340,21 +339,20 @@ namespace WPEFramework
MaintenanceManager::m_task_map[task_names_foreground[1].c_str()]=false;
MaintenanceManager::m_task_map[task_names_foreground[2].c_str()]=false;

#if defined(ENABLE_WHOAMI)
MaintenanceManager::m_param_map[kDeviceInitContextKeyVals[0].c_str()] = TR181_PARTNER_ID;
MaintenanceManager::m_param_map[kDeviceInitContextKeyVals[1].c_str()] = TR181_TARGET_OS_CLASS;
MaintenanceManager::m_param_map[kDeviceInitContextKeyVals[2].c_str()] = TR181_XCONFURL;

MaintenanceManager::m_paramType_map[kDeviceInitContextKeyVals[0].c_str()] = DATA_TYPE::WDMP_STRING;
MaintenanceManager::m_paramType_map[kDeviceInitContextKeyVals[1].c_str()] = DATA_TYPE::WDMP_STRING;
MaintenanceManager::m_paramType_map[kDeviceInitContextKeyVals[2].c_str()] = DATA_TYPE::WDMP_STRING;
#endif /* End of ENABLE_WHOAMI */
}

void MaintenanceManager::task_execution_thread()
{
int i = 0;
string task = "";
bool isMaintenanceSuppressed = false;
bool internetConnectStatus = false;
bool delayMaintenanceStarted = false;
bool exitOnNoNetwork = false;
Expand All @@ -364,13 +362,12 @@ namespace WPEFramework
std::unique_lock<std::mutex> wailck(m_waiMutex);
MM_LOGINFO("Executing Maintenance tasks");

#if defined(ENABLE_WHOAMI)
/* Purposefully delaying MAINTENANCE_STARTED status to honor POWER compliance */
if (UNSOLICITED_MAINTENANCE == g_maintenance_type)
if (UNSOLICITED_MAINTENANCE == g_maintenance_type && g_whoami_support_enabled)
{
delayMaintenanceStarted = true;
}
#endif

if (!delayMaintenanceStarted)
{
m_statusMutex.lock();
Expand All @@ -384,55 +381,68 @@ namespace WPEFramework
tasks.erase(tasks.begin(), tasks.end());
}

#if defined(SUPPRESS_MAINTENANCE) && !defined(ENABLE_WHOAMI)
bool activationStatus = false;
bool skipFirmwareCheck = false;
activationStatus = getActivatedStatus(skipFirmwareCheck); /* Activation Check */
#if defined(SUPPRESS_MAINTENANCE)
if (!g_whoami_support_enabled)
{
isMaintenanceSuppressed = true;
bool activationStatus = false;
bool skipFirmwareCheck = false;
activationStatus = getActivatedStatus(skipFirmwareCheck); /* Activation Check */

/* we proceed with network check only if activationStatus is
* "activation-connect",
* "activation-ready",
* "not-activated",
* "activated" */
if (activationStatus)
{
internetConnectStatus = isDeviceOnline(); /* Network Check */
}
#else
internetConnectStatus = isDeviceOnline(); /* Network Check */
/* we proceed with network check only if activationStatus is
* "activation-connect",
* "activation-ready",
* "not-activated",
* "activated" */
if (activationStatus)
{
internetConnectStatus = isDeviceOnline(); /* Network Check */
}
}
#endif
if (!isMaintenanceSuppressed)
{
internetConnectStatus = isDeviceOnline(); /* Network Check */
}

#if defined(ENABLE_WHOAMI)
if (UNSOLICITED_MAINTENANCE == g_maintenance_type) /* Unsolicited Maintenance in WHOAMI */
{
string activation_status = checkActivatedStatus(); /* Device Activation Status Check */
bool whoAmIStatus = knowWhoAmI(activation_status); /* WhoAmI Response & Set Status Check */
MM_LOGINFO("knowWhoAmI() returned %s", (whoAmIStatus) ? "successfully" : "false");

if (!whoAmIStatus && activation_status != "activated")
if (!g_whoami_support_enabled)
{
if (UNSOLICITED_MAINTENANCE == g_maintenance_type) /* Unsolicited Maintenance in WHOAMI */
{
MM_LOGINFO("knowWhoAmI() returned false and Device is not already Activated");
g_listen_to_deviceContextUpdate = true;
MM_LOGINFO("Waiting for onDeviceInitializationContextUpdate event");
task_thread.wait(wailck);
string activation_status = checkActivatedStatus(); /* Device Activation Status Check */
bool whoAmIStatus = knowWhoAmI(activation_status); /* WhoAmI Response & Set Status Check */
MM_LOGINFO("knowWhoAmI() returned %s", (whoAmIStatus) ? "successfully" : "false");

if (!whoAmIStatus && activation_status != "activated")
{
MM_LOGINFO("knowWhoAmI() returned false and Device is not already Activated");
g_listen_to_deviceContextUpdate = true;
MM_LOGINFO("Waiting for onDeviceInitializationContextUpdate event");
task_thread.wait(wailck);
}
else if (!internetConnectStatus && activation_status == "activated")
{
MM_LOGINFO("Device is not connected to the Internet and Device is already Activated");
exitOnNoNetwork = true;
}
}
else if (!internetConnectStatus && activation_status == "activated")
else /* Solicited Maintenance in WHOAMI */
{
MM_LOGINFO("Device is not connected to the Internet and Device is already Activated");
exitOnNoNetwork = true;
if (!internetConnectStatus)
{
exitOnNoNetwork = true;
}
}
}
else /* Solicited Maintenance in WHOAMI */
{
if (!internetConnectStatus)
}
else
{
if(!internetConnectStatus)
{
exitOnNoNetwork = true;
}
#else
if(!internetConnectStatus)
{
exitOnNoNetwork = true;
}
#endif
}
}

if (exitOnNoNetwork) /* Exit Maintenance Cycle if no Internet */
{
m_statusMutex.lock();
Expand All @@ -456,27 +466,33 @@ namespace WPEFramework
MM_LOGINFO("Reboot_Pending: %s",g_is_reboot_pending.c_str());
MM_LOGINFO("%s", UNSOLICITED_MAINTENANCE == g_maintenance_type ? "---------------UNSOLICITED_MAINTENANCE--------------" : "=============SOLICITED_MAINTENANCE===============");

#if defined(SUPPRESS_MAINTENANCE) && !defined(ENABLE_WHOAMI)
if(skipFirmwareCheck)
{
/* set the task status of Firmware Download */
SET_STATUS(g_task_status, SWUPDATE_SUCCESS);
SET_STATUS(g_task_status, SWUPDATE_COMPLETE);
/* Skip Firmware Download Task and add other tasks */
tasks.push_back(task_names_foreground[0].c_str());
tasks.push_back(task_names_foreground[2].c_str());
#if defined(SUPPRESS_MAINTENANCE)
if (!g_whoami_support_enabled && isMaintenanceSuppressed)
{
if(skipFirmwareCheck)
{
/* set the task status of Firmware Download */
SET_STATUS(g_task_status, SWUPDATE_SUCCESS);
SET_STATUS(g_task_status, SWUPDATE_COMPLETE);
/* Skip Firmware Download Task and add other tasks */
tasks.push_back(task_names_foreground[0].c_str());
tasks.push_back(task_names_foreground[2].c_str());
}
else
{
tasks.push_back(task_names_foreground[0].c_str());
tasks.push_back(task_names_foreground[1].c_str());
tasks.push_back(task_names_foreground[2].c_str());
}
}
else
{
#endif
if (!isMaintenanceSuppressed)
{
tasks.push_back(task_names_foreground[0].c_str());
tasks.push_back(task_names_foreground[1].c_str());
tasks.push_back(task_names_foreground[2].c_str());
}
#else
tasks.push_back(task_names_foreground[0].c_str());
tasks.push_back(task_names_foreground[1].c_str());
tasks.push_back(task_names_foreground[2].c_str());
#endif
}

std::unique_lock<std::mutex> lck(m_callMutex);
for (i = 0; i < static_cast<int>(tasks.size()) && !m_abort_flag; i++)
{
Expand Down Expand Up @@ -565,7 +581,28 @@ namespace WPEFramework
MM_LOGINFO("Worker Thread Completed");
} /* end of task_execution_thread() */

#if defined(ENABLE_WHOAMI)
void MaintenanceManager::isWhoAmIEnabled()
{
std::string wai_prop_val;
if (Utils::readPropertyFile(DEVICE_PROP_FILE, WHOAMI_PROP_KEY, wai_prop_val))
{
if (wai_prop_val == "true")
{
g_whoami_support_enabled = true;
MM_LOGINFO("Device is in WhoAmI mode");
}
else
{
g_whoami_support_enabled = false;
MM_LOGINFO("Device is not in WhoAmI mode");
}
}
else
{
MM_LOGERR("Failed to read %s property", WHOAMI_PROP_KEY);
}
}

/**
* @brief Determines the device identity by querying the Security Manager.
*
Expand Down Expand Up @@ -643,7 +680,6 @@ namespace WPEFramework
}
}while(true);
}
#endif /* end of ENABLE_WHOAMI */

/**
* @brief Retrieves a handle to the specified Thunder plugin with authentication.
Expand Down Expand Up @@ -1463,9 +1499,11 @@ namespace WPEFramework
m_service = service;
m_service->AddRef();

#if defined(ENABLE_WHOAMI)
subscribeToDeviceInitializationEvent();
#endif
isWhoAmIEnabled();
if (g_whoami_support_enabled)
{
subscribeToDeviceInitializationEvent();
}

#if defined(USE_IARMBUS) || defined(USE_IARM_BUS)
InitializeIARM();
Expand Down
5 changes: 5 additions & 0 deletions MaintenanceManager/MaintenanceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ typedef enum{

#define BASE_CLOCK CLOCK_BOOTTIME

#define WHOAMI_PROP_KEY "WHOAMI_ENABLED"
#define DEVICE_PROP_FILE "/etc/device.properties"

#define FOREGROUND_MODE "FOREGROUND"
#define BACKGROUND_MODE "BACKGROUND"

Expand Down Expand Up @@ -183,6 +186,7 @@ namespace WPEFramework {
bool g_subscribed_for_nwevents = false;
bool g_listen_to_deviceContextUpdate = false;
bool g_subscribed_for_deviceContextUpdate = false;
bool g_whoami_support_enabled = false;

std::mutex m_callMutex;
std::mutex m_waiMutex;
Expand Down Expand Up @@ -211,6 +215,7 @@ namespace WPEFramework {
void deviceInitializationContextEventHandler(const JsonObject& parameters);
void startCriticalTasks();
bool checkNetwork();
void isWhoAmIEnabled();
bool knowWhoAmI(string &activation_status);
bool subscribeToDeviceInitializationEvent();
bool setDeviceInitializationContext(JsonObject joGetResult);
Expand Down
5 changes: 0 additions & 5 deletions amlogic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ if (BUILD_DONT_SET_POWER_BRIGHTNESS)
add_definitions (-DDONT_SET_POWER_BRIGHTNESS)
endif()

if (ENABLE_WHOAMI)
message("Enable WHOAMI")
add_definitions (-DENABLE_WHOAMI=ON)
endif()

if (BUILD_ENABLE_HDCP)
message("Building with hdcp profile")
add_definitions (-DBUILD_ENABLE_HDCP)
Expand Down
5 changes: 0 additions & 5 deletions broadcom.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ if (BUILD_DONT_SET_POWER_BRIGHTNESS)
add_definitions (-DDONT_SET_POWER_BRIGHTNESS)
endif()

if (ENABLE_WHOAMI)
message("Enable WHOAMI")
add_definitions (-DENABLE_WHOAMI=ON)
endif()

if (BUILD_ENABLE_HDCP)
message("Building with hdcp profile")
add_definitions (-DBUILD_ENABLE_HDCP)
Expand Down
5 changes: 0 additions & 5 deletions realtek.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ if (BUILD_DONT_SET_POWER_BRIGHTNESS)
add_definitions (-DDONT_SET_POWER_BRIGHTNESS)
endif()

if (ENABLE_WHOAMI)
message("Enable WHOAMI")
add_definitions (-DENABLE_WHOAMI=ON)
endif()

if (BUILD_ENABLE_HDCP)
message("Building with hdcp profile")
add_definitions (-DBUILD_ENABLE_HDCP)
Expand Down
Loading