Skip to content

Commit

Permalink
LLAMA-4597:Bring back the Network Check
Browse files Browse the repository at this point in the history
Reason for change:Periodic maintenance lasts 1'32''
when eth0 interface established, but router has not internet connection.
Add 4 retries with 30 sec sleep.
Ref:XIONE-5622.
Test Procedure:Refer Ticket.
Risk: Medium
  • Loading branch information
livinsunny519 committed Jan 24, 2022
1 parent 06b9ad0 commit 50d4d7b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
53 changes: 36 additions & 17 deletions MaintenanceManager/MaintenanceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,7 @@ namespace WPEFramework {

LOGINFO("Reboot_Pending :%s",g_is_reboot_pending.c_str());

#if defined (SKY_BUILD)
bool internetConnectStatus = true;
#else
bool internetConnectStatus = isDeviceOnline();
#endif

MaintenanceManager::_instance->onMaintenanceStatusChange(MAINTENANCE_STARTED);
/* In an unsolicited maintenance we make sure only after
Expand Down Expand Up @@ -281,22 +277,19 @@ namespace WPEFramework {
}
}

bool MaintenanceManager::isDeviceOnline()
bool MaintenanceManager::checkNetwork()
{
LOGINFO("Checking device has network connectivity\n");
JsonObject joGetParams;
JsonObject joGetResult;
std::string callsign = "org.rdk.Network.1";
std::string token;

/* check if plugin active */
if (false == Utils::isPluginActivated("org.rdk.Network")) {
sleep(30);
if (false == Utils::isPluginActivated("org.rdk.Network")) {
LOGINFO("Network plugin is not activated and considered as offline\n");
return false;
}
LOGINFO("Network plugin is not activated \n");
return false;
}

JsonObject joGetParams;
JsonObject joGetResult;
std::string callsign = "org.rdk.Network.1";
std::string token;
Utils::SecurityToken::getSecurityToken(token);

string query = "token=" + token;
Expand All @@ -308,16 +301,42 @@ namespace WPEFramework {
LOGINFO("%s call failed %d", callsign.c_str(), status);
return false;
} else if (joGetResult.HasLabel("connectedToInternet")) {
LOGINFO("connectedToInternet status %d", joGetResult["connectedToInternet"].Boolean());
LOGINFO("connectedToInternet status %s",(joGetResult["connectedToInternet"].Boolean())? "true":"false");
return joGetResult["connectedToInternet"].Boolean();
} else {
return false;
}
}
}

LOGINFO("thunder client failed");
return false;
}

bool MaintenanceManager::isDeviceOnline()
{
bool network_available = false;
LOGINFO("Checking device has network connectivity\n");

/* add 4 checks every 30 seconds */
int i=0;
do{
network_available = checkNetwork();
if ( !network_available ){
sleep(30);
i++;
LOGINFO("Network retries [%d/4] \n",i);
}else{
break;
}
}while( i < MAX_NETWORK_RETRIES );

if ( network_available ){
return true;
}else {
return false;
}
}

MaintenanceManager::~MaintenanceManager()
{
MaintenanceManager::_instance = nullptr;
Expand Down
2 changes: 2 additions & 0 deletions MaintenanceManager/MaintenanceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ typedef enum{
#define ALL_TASKS_SUCCESS 0xFF
#define MAINTENANCE_TASK_SKIPPED 0x200

#define MAX_NETWORK_RETRIES 4

#define DCM_SUCCESS 0
#define DCM_COMPLETE 1
Expand Down Expand Up @@ -139,6 +140,7 @@ namespace WPEFramework {
void maintenanceManagerOnBootup();
bool checkAutoRebootFlag();
bool checkAbortFlag();
bool checkNetwork();
pid_t getTaskPID(const char*);

string getLastRebootReason();
Expand Down

0 comments on commit 50d4d7b

Please sign in to comment.