Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
159 changes: 99 additions & 60 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: HariniElangovan890/rdkservices/d73bf6eda46ff140b2d678f5a2eaf3fca1c07bbd, 2684 lines, url: https://github.com/HariniElangovan890/rdkservices/archive/d73bf6eda46ff140b2d678f5a2eaf3fca1c07bbd.tar.gz, file: MaintenanceManager/MaintenanceManager.cpp)

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, 2684 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,21 +337,20 @@
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()
{
int i = 0;
string task = "";
bool isMaintenanceSuppressed = false;
bool internetConnectStatus = false;
bool delayMaintenanceStarted = false;
bool exitOnNoNetwork = false;
Expand All @@ -361,13 +360,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 +379,68 @@
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)
#if defined(SUPPRESS_MAINTENANCE)
if (!g_whoami_support_enabled)
{
MM_LOGINFO("WHOAMI_SUPPORT is disabled\n");
isMaintenanceSuppressed = true;
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)
{
internetConnectStatus = isDeviceOnline(); /* Network check */
}
}
#endif
if (!isMaintenanceSuppressed)
{
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_SUPPORT is enabled\n");
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_SUPPORT is disabled\n");
if (!internetConnectStatus)
{
exitOnNoNetwork = true;
}
}
#else
if (!internetConnectStatus)
{
exitOnNoNetwork = true;
}
#endif

if (exitOnNoNetwork) /* Exit Maintenance Cycle if no Internet */
{
m_statusMutex.lock();
Expand All @@ -453,28 +464,34 @@

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 defined(SUPPRESS_MAINTENANCE)
if (!g_whoami_support_enabled && isMaintenanceSuppressed)
{
/* 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[TASK_RFC].c_str());
tasks.push_back(task_names_foreground[TASK_LOGUPLOAD].c_str());
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[TASK_RFC].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());
}
}
else
#endif
if (!isMaintenanceSuppressed)
{
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 @@ -561,7 +578,28 @@
MM_LOGINFO("Worker Thread Completed");
} /* end of task_execution_thread() */

#if defined(ENABLE_WHOAMI)
void MaintenanceManager::isWhoAmIEnabled()
{
std::string wai_prop_val;
if (Utils::readPropertyFromFile(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 @@ -639,7 +677,6 @@
}
} while (true);
}
#endif /* end of ENABLE_WHOAMI */

/**
* @brief Retrieves a handle to the specified Thunder plugin with authentication.
Expand Down Expand Up @@ -1437,15 +1474,17 @@

const string MaintenanceManager::Initialize(PluginHost::IShell *service)
{
isWhoAmIEnabled();
ASSERT(service != nullptr);
ASSERT(m_service == nullptr);
ASSERT(timerid != nullptr);

m_service = service;
m_service->AddRef();
#if defined(ENABLE_WHOAMI)
subscribeToDeviceInitializationEvent();
#endif
if (g_whoami_support_enabled) {
MM_LOGINFO("WHOAMI_SUPPORT is enabled\n");
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
@@ -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, 321 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 @@ -114,6 +114,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 @@ -193,6 +196,7 @@
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 @@ -222,6 +226,7 @@
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 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