Skip to content
Merged
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
124 changes: 70 additions & 54 deletions MaintenanceManager/MaintenanceManager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**

Check failure on line 1 in MaintenanceManager/MaintenanceManager.cpp

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'MaintenanceManager/MaintenanceManager.cpp' (Match: rdkcentral/rdkservices/1, 2674 lines, url: https://github.com/rdkcentral/rdkservices/archive/GRT_v1.tar.gz, file: MaintenanceManager/MaintenanceManager.cpp)
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
Expand Down Expand Up @@ -45,6 +45,7 @@
#include "UtilsIarm.h"
#include "UtilsJsonRpc.h"
#include "UtilsfileExists.h"
#include "UtilsgetFileContent.h"

#if defined(USE_IARMBUS) || defined(USE_IARM_BUS)
#include "libIARM.h"
Expand All @@ -70,11 +71,10 @@
#define RDK_PATH "/lib/rdk/"
#define MAINTENANCE_MANAGER_RFC_CALLER_ID "MaintenanceManager"

#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 TASK_SCRIPT RDK_PATH "Start_MaintenanceTasks.sh"
#define IMAGE_CHECK_SCRIPT RDK_PATH "xconfImageCheck.sh"
Expand Down Expand Up @@ -337,15 +337,13 @@
MaintenanceManager::m_task_map[task_names_foreground[TASK_SWUPDATE].c_str()] = false;
MaintenanceManager::m_task_map[task_names_foreground[TASK_LOGUPLOAD].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
}

void MaintenanceManager::task_execution_thread()
Expand All @@ -361,13 +359,12 @@
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 @@ -381,55 +378,65 @@
tasks.erase(tasks.begin(), tasks.end());
}

#if defined(SUPPRESS_MAINTENANCE) && !defined(ENABLE_WHOAMI)
bool skipFirmwareCheck = false;
bool activationStatus = getActivatedStatus(skipFirmwareCheck); /* Activation check */
/* we proceed with network check only if
* "activation-connect",
* "activation-ready"
* "not-activated",
* "activated" */
if (activationStatus)
bool skipFirmwareCheck = false;
if (!g_whoami_support_enabled && g_suppress_maintenance_enabled)
{
MM_LOGINFO("WhoAmI feature is disabled and suppress maintenance is enabled");
bool activationStatus = getActivatedStatus(skipFirmwareCheck); /* Activation check */
/* we proceed with network check only if
* "activation-connect",
* "activation-ready"
* "not-activated",
* "activated" */
if (activationStatus)
{
internetConnectStatus = isDeviceOnline(); /* Network check */
}
}
else
{
internetConnectStatus = isDeviceOnline(); /* Network check */
}
#else
internetConnectStatus = isDeviceOnline(); /* Network check */
#endif

#if defined(ENABLE_WHOAMI)
if (UNSOLICITED_MAINTENANCE == g_maintenance_type)
if (g_whoami_support_enabled)
{
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("WhoAmI feature is enabled");
if (UNSOLICITED_MAINTENANCE == g_maintenance_type)
{
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 */
else
{
MM_LOGINFO("WhoAmI feature is disabled");
if (!internetConnectStatus)
{
exitOnNoNetwork = true;
}
}
#else
if (!internetConnectStatus)
{
exitOnNoNetwork = true;
}
#endif

if (exitOnNoNetwork) /* Exit Maintenance Cycle if no Internet */
{
m_statusMutex.lock();
Expand All @@ -453,9 +460,8 @@

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)

if (!g_whoami_support_enabled && g_suppress_maintenance_enabled && skipFirmwareCheck)
{
/* set the task status of Firmware Download */
SET_STATUS(g_task_status, SWUPDATE_SUCCESS);
Expand All @@ -464,17 +470,13 @@
tasks.push_back(task_names_foreground[TASK_RFC].c_str());
tasks.push_back(task_names_foreground[TASK_LOGUPLOAD].c_str());
}
else
else
{
tasks.push_back(task_names_foreground[TASK_RFC].c_str());
tasks.push_back(task_names_foreground[TASK_SWUPDATE].c_str());
tasks.push_back(task_names_foreground[TASK_LOGUPLOAD].c_str());
}
#else
tasks.push_back(task_names_foreground[TASK_RFC].c_str());
tasks.push_back(task_names_foreground[TASK_SWUPDATE].c_str());
tasks.push_back(task_names_foreground[TASK_LOGUPLOAD].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 @@ -563,7 +565,19 @@
MM_LOGINFO("Worker Thread Completed");
} /* end of task_execution_thread() */

#if defined(ENABLE_WHOAMI) || defined(GTEST_ENABLE)
bool MaintenanceManager::isWhoAmIEnabled()
{
bool wai_enabled = false;
std::string wai_prop_val;
if (!Utils::readPropertyFromFile(DEVICE_PROP_FILE, WHOAMI_PROP_KEY, wai_prop_val)) {
MM_LOGERR("Failed to read %s property", WHOAMI_PROP_KEY);
return wai_enabled;
}

wai_enabled = (wai_prop_val == "true");
return wai_enabled;
}

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

/**
* @brief Retrieves a handle to the specified Thunder plugin with authentication.
Expand Down Expand Up @@ -1453,9 +1466,12 @@

m_service = service;
m_service->AddRef();
#if defined(ENABLE_WHOAMI)
subscribeToDeviceInitializationEvent();
#endif
if ((g_whoami_support_enabled = isWhoAmIEnabled())) {
MM_LOGINFO("WhoAmI feature is enabled");
subscribeToDeviceInitializationEvent();
} else {
MM_LOGINFO("WhoAmI feature is disabled");
}

#if defined(USE_IARMBUS) || defined(USE_IARM_BUS)
InitializeIARM();
Expand Down
11 changes: 10 additions & 1 deletion MaintenanceManager/MaintenanceManager.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**

Check failure on line 1 in MaintenanceManager/MaintenanceManager.h

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'MaintenanceManager/MaintenanceManager.h' (Match: rdkcentral/rdkservices/1, 332 lines, url: https://github.com/rdkcentral/rdkservices/archive/GRT_v1.tar.gz, file: MaintenanceManager/MaintenanceManager.h)
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
Expand Down Expand Up @@ -113,6 +113,9 @@

#define BASE_CLOCK CLOCK_BOOTTIME

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

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

Expand Down Expand Up @@ -200,7 +203,12 @@
bool g_subscribed_for_nwevents = false;
bool g_listen_to_deviceContextUpdate = false;
bool g_subscribed_for_deviceContextUpdate = false;

bool g_whoami_support_enabled = false;
#if defined(SUPPRESS_MAINTENANCE)
bool g_suppress_maintenance_enabled = true;
#else
bool g_suppress_maintenance_enabled = false;
#endif
std::mutex m_callMutex;
std::mutex m_waiMutex;
std::mutex m_statusMutex;
Expand Down Expand Up @@ -229,6 +237,7 @@
void deviceInitializationContextEventHandler(const JsonObject &parameters);
void startCriticalTasks();
bool checkNetwork();
bool isWhoAmIEnabled();
bool knowWhoAmI(string &activation_status);
bool subscribeToDeviceInitializationEvent();
bool setDeviceInitializationContext(JsonObject joGetResult);
Expand Down
5 changes: 0 additions & 5 deletions services.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,6 @@ if(NET_DISABLE_NETSRVMGR_CHECK)
add_definitions (-DNET_DISABLE_NETSRVMGR_CHECK)
endif()

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

if (ENABLE_RFC_MANAGER)
message("Using binary for RFC Maintenance task")
add_definitions (-DENABLE_RFC_MANAGER=ON)
Expand Down
Loading