Skip to content

Commit 54f17f6

Browse files
RDK-57914: Dynamic WhoAmI feature control for Manintenance Manager (#82)
1 parent fb587ea commit 54f17f6

File tree

3 files changed

+80
-60
lines changed

3 files changed

+80
-60
lines changed

MaintenanceManager/MaintenanceManager.cpp

Lines changed: 70 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "UtilsIarm.h"
4646
#include "UtilsJsonRpc.h"
4747
#include "UtilsfileExists.h"
48+
#include "UtilsgetFileContent.h"
4849

4950
#if defined(USE_IARMBUS) || defined(USE_IARM_BUS)
5051
#include "libIARM.h"
@@ -70,11 +71,10 @@ using namespace std;
7071
#define RDK_PATH "/lib/rdk/"
7172
#define MAINTENANCE_MANAGER_RFC_CALLER_ID "MaintenanceManager"
7273

73-
#if defined(ENABLE_WHOAMI)
7474
#define TR181_PARTNER_ID "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerName"
7575
#define TR181_TARGET_OS_CLASS "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.OsClass"
7676
#define TR181_XCONFURL "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.XconfUrl"
77-
#endif
77+
7878

7979
#define TASK_SCRIPT RDK_PATH "Start_MaintenanceTasks.sh"
8080
#define IMAGE_CHECK_SCRIPT RDK_PATH "xconfImageCheck.sh"
@@ -337,15 +337,13 @@ namespace WPEFramework
337337
MaintenanceManager::m_task_map[task_names_foreground[TASK_SWUPDATE].c_str()] = false;
338338
MaintenanceManager::m_task_map[task_names_foreground[TASK_LOGUPLOAD].c_str()] = false;
339339

340-
#if defined(ENABLE_WHOAMI)
341340
MaintenanceManager::m_param_map[kDeviceInitContextKeyVals[0].c_str()] = TR181_PARTNER_ID;
342341
MaintenanceManager::m_param_map[kDeviceInitContextKeyVals[1].c_str()] = TR181_TARGET_OS_CLASS;
343342
MaintenanceManager::m_param_map[kDeviceInitContextKeyVals[2].c_str()] = TR181_XCONFURL;
344343

345344
MaintenanceManager::m_paramType_map[kDeviceInitContextKeyVals[0].c_str()] = DATA_TYPE::WDMP_STRING;
346345
MaintenanceManager::m_paramType_map[kDeviceInitContextKeyVals[1].c_str()] = DATA_TYPE::WDMP_STRING;
347346
MaintenanceManager::m_paramType_map[kDeviceInitContextKeyVals[2].c_str()] = DATA_TYPE::WDMP_STRING;
348-
#endif
349347
}
350348

351349
void MaintenanceManager::task_execution_thread()
@@ -361,13 +359,12 @@ namespace WPEFramework
361359
std::unique_lock<std::mutex> wailck(m_waiMutex);
362360
MM_LOGINFO("Executing Maintenance tasks");
363361

364-
#if defined(ENABLE_WHOAMI)
365362
/* Purposefully delaying MAINTENANCE_STARTED status to honor POWER compliance */
366-
if (UNSOLICITED_MAINTENANCE == g_maintenance_type)
363+
if (UNSOLICITED_MAINTENANCE == g_maintenance_type && g_whoami_support_enabled)
367364
{
368365
delayMaintenanceStarted = true;
369366
}
370-
#endif
367+
371368
if (!delayMaintenanceStarted)
372369
{
373370
m_statusMutex.lock();
@@ -381,55 +378,65 @@ namespace WPEFramework
381378
tasks.erase(tasks.begin(), tasks.end());
382379
}
383380

384-
#if defined(SUPPRESS_MAINTENANCE) && !defined(ENABLE_WHOAMI)
385-
bool skipFirmwareCheck = false;
386-
bool activationStatus = getActivatedStatus(skipFirmwareCheck); /* Activation check */
387-
/* we proceed with network check only if
388-
* "activation-connect",
389-
* "activation-ready"
390-
* "not-activated",
391-
* "activated" */
392-
if (activationStatus)
381+
bool skipFirmwareCheck = false;
382+
if (!g_whoami_support_enabled && g_suppress_maintenance_enabled)
383+
{
384+
MM_LOGINFO("WhoAmI feature is disabled and suppress maintenance is enabled");
385+
bool activationStatus = getActivatedStatus(skipFirmwareCheck); /* Activation check */
386+
/* we proceed with network check only if
387+
* "activation-connect",
388+
* "activation-ready"
389+
* "not-activated",
390+
* "activated" */
391+
if (activationStatus)
392+
{
393+
internetConnectStatus = isDeviceOnline(); /* Network check */
394+
}
395+
}
396+
else
393397
{
394398
internetConnectStatus = isDeviceOnline(); /* Network check */
395399
}
396-
#else
397-
internetConnectStatus = isDeviceOnline(); /* Network check */
398-
#endif
399400

400-
#if defined(ENABLE_WHOAMI)
401-
if (UNSOLICITED_MAINTENANCE == g_maintenance_type)
401+
if (g_whoami_support_enabled)
402402
{
403-
string activation_status = checkActivatedStatus(); /* Device Activation Status Check */
404-
bool whoAmIStatus = knowWhoAmI(activation_status); /* WhoAmI Response & Set Status Check */
405-
MM_LOGINFO("knowWhoAmI() returned %s", (whoAmIStatus) ? "successfully" : "false");
406-
407-
if (!whoAmIStatus && activation_status != "activated")
403+
MM_LOGINFO("WhoAmI feature is enabled");
404+
if (UNSOLICITED_MAINTENANCE == g_maintenance_type)
408405
{
409-
MM_LOGINFO("knowWhoAmI() returned false and Device is not already Activated");
410-
g_listen_to_deviceContextUpdate = true;
411-
MM_LOGINFO("Waiting for onDeviceInitializationContextUpdate event");
412-
task_thread.wait(wailck);
406+
string activation_status = checkActivatedStatus(); /* Device Activation Status Check */
407+
bool whoAmIStatus = knowWhoAmI(activation_status); /* WhoAmI Response & Set Status Check */
408+
MM_LOGINFO("knowWhoAmI() returned %s", (whoAmIStatus) ? "successfully" : "false");
409+
410+
if (!whoAmIStatus && activation_status != "activated")
411+
{
412+
MM_LOGINFO("knowWhoAmI() returned false and Device is not already Activated");
413+
g_listen_to_deviceContextUpdate = true;
414+
MM_LOGINFO("Waiting for onDeviceInitializationContextUpdate event");
415+
task_thread.wait(wailck);
416+
}
417+
else if (!internetConnectStatus && activation_status == "activated")
418+
{
419+
MM_LOGINFO("Device is not connected to the Internet and Device is already Activated");
420+
exitOnNoNetwork = true;
421+
}
413422
}
414-
else if (!internetConnectStatus && activation_status == "activated")
423+
else /* Solicited Maintenance in WHOAMI */
415424
{
416-
MM_LOGINFO("Device is not connected to the Internet and Device is already Activated");
417-
exitOnNoNetwork = true;
425+
if (!internetConnectStatus)
426+
{
427+
exitOnNoNetwork = true;
428+
}
418429
}
419430
}
420-
else /* Solicited Maintenance in WHOAMI */
431+
else
421432
{
433+
MM_LOGINFO("WhoAmI feature is disabled");
422434
if (!internetConnectStatus)
423435
{
424436
exitOnNoNetwork = true;
425437
}
426438
}
427-
#else
428-
if (!internetConnectStatus)
429-
{
430-
exitOnNoNetwork = true;
431-
}
432-
#endif
439+
433440
if (exitOnNoNetwork) /* Exit Maintenance Cycle if no Internet */
434441
{
435442
m_statusMutex.lock();
@@ -453,9 +460,8 @@ namespace WPEFramework
453460

454461
MM_LOGINFO("Reboot_Pending :%s", g_is_reboot_pending.c_str());
455462
MM_LOGINFO("%s", UNSOLICITED_MAINTENANCE == g_maintenance_type ? "---------------UNSOLICITED_MAINTENANCE--------------" : "=============SOLICITED_MAINTENANCE===============");
456-
457-
#if defined(SUPPRESS_MAINTENANCE) && !defined(ENABLE_WHOAMI)
458-
if (skipFirmwareCheck)
463+
464+
if (!g_whoami_support_enabled && g_suppress_maintenance_enabled && skipFirmwareCheck)
459465
{
460466
/* set the task status of Firmware Download */
461467
SET_STATUS(g_task_status, SWUPDATE_SUCCESS);
@@ -464,17 +470,13 @@ namespace WPEFramework
464470
tasks.push_back(task_names_foreground[TASK_RFC].c_str());
465471
tasks.push_back(task_names_foreground[TASK_LOGUPLOAD].c_str());
466472
}
467-
else
473+
else
468474
{
469475
tasks.push_back(task_names_foreground[TASK_RFC].c_str());
470476
tasks.push_back(task_names_foreground[TASK_SWUPDATE].c_str());
471477
tasks.push_back(task_names_foreground[TASK_LOGUPLOAD].c_str());
472478
}
473-
#else
474-
tasks.push_back(task_names_foreground[TASK_RFC].c_str());
475-
tasks.push_back(task_names_foreground[TASK_SWUPDATE].c_str());
476-
tasks.push_back(task_names_foreground[TASK_LOGUPLOAD].c_str());
477-
#endif
479+
478480
std::unique_lock<std::mutex> lck(m_callMutex);
479481
for (i = 0; i < static_cast<int>(tasks.size()) && !m_abort_flag; i++)
480482
{
@@ -563,7 +565,19 @@ namespace WPEFramework
563565
MM_LOGINFO("Worker Thread Completed");
564566
} /* end of task_execution_thread() */
565567

566-
#if defined(ENABLE_WHOAMI) || defined(GTEST_ENABLE)
568+
bool MaintenanceManager::isWhoAmIEnabled()
569+
{
570+
bool wai_enabled = false;
571+
std::string wai_prop_val;
572+
if (!Utils::readPropertyFromFile(DEVICE_PROP_FILE, WHOAMI_PROP_KEY, wai_prop_val)) {
573+
MM_LOGERR("Failed to read %s property", WHOAMI_PROP_KEY);
574+
return wai_enabled;
575+
}
576+
577+
wai_enabled = (wai_prop_val == "true");
578+
return wai_enabled;
579+
}
580+
567581
/**
568582
* @brief Determines the device identity by querying the Security Manager.
569583
*
@@ -641,7 +655,6 @@ namespace WPEFramework
641655
}
642656
} while (true);
643657
}
644-
#endif /* end of ENABLE_WHOAMI */
645658

646659
/**
647660
* @brief Retrieves a handle to the specified Thunder plugin with authentication.
@@ -1453,9 +1466,12 @@ namespace WPEFramework
14531466

14541467
m_service = service;
14551468
m_service->AddRef();
1456-
#if defined(ENABLE_WHOAMI)
1457-
subscribeToDeviceInitializationEvent();
1458-
#endif
1469+
if ((g_whoami_support_enabled = isWhoAmIEnabled())) {
1470+
MM_LOGINFO("WhoAmI feature is enabled");
1471+
subscribeToDeviceInitializationEvent();
1472+
} else {
1473+
MM_LOGINFO("WhoAmI feature is disabled");
1474+
}
14591475

14601476
#if defined(USE_IARMBUS) || defined(USE_IARM_BUS)
14611477
InitializeIARM();

MaintenanceManager/MaintenanceManager.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ typedef enum
113113

114114
#define BASE_CLOCK CLOCK_BOOTTIME
115115

116+
#define WHOAMI_PROP_KEY "WHOAMI_SUPPORT"
117+
#define DEVICE_PROP_FILE "/etc/device.properties"
118+
116119
#define FOREGROUND_MODE "FOREGROUND"
117120
#define BACKGROUND_MODE "BACKGROUND"
118121

@@ -200,7 +203,12 @@ namespace WPEFramework
200203
bool g_subscribed_for_nwevents = false;
201204
bool g_listen_to_deviceContextUpdate = false;
202205
bool g_subscribed_for_deviceContextUpdate = false;
203-
206+
bool g_whoami_support_enabled = false;
207+
#if defined(SUPPRESS_MAINTENANCE)
208+
bool g_suppress_maintenance_enabled = true;
209+
#else
210+
bool g_suppress_maintenance_enabled = false;
211+
#endif
204212
std::mutex m_callMutex;
205213
std::mutex m_waiMutex;
206214
std::mutex m_statusMutex;
@@ -229,6 +237,7 @@ namespace WPEFramework
229237
void deviceInitializationContextEventHandler(const JsonObject &parameters);
230238
void startCriticalTasks();
231239
bool checkNetwork();
240+
bool isWhoAmIEnabled();
232241
bool knowWhoAmI(string &activation_status);
233242
bool subscribeToDeviceInitializationEvent();
234243
bool setDeviceInitializationContext(JsonObject joGetResult);

services.cmake

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,6 @@ if(NET_DISABLE_NETSRVMGR_CHECK)
140140
add_definitions (-DNET_DISABLE_NETSRVMGR_CHECK)
141141
endif()
142142

143-
if (ENABLE_WHOAMI)
144-
message("Enable WHOAMI")
145-
add_definitions (-DENABLE_WHOAMI=ON)
146-
endif()
147-
148143
if (ENABLE_RFC_MANAGER)
149144
message("Using binary for RFC Maintenance task")
150145
add_definitions (-DENABLE_RFC_MANAGER=ON)

0 commit comments

Comments
 (0)