Static layout: Do not update PNOR when host is on

Static layout only has 1 active and functional PNOR. When host is
running, do not update PNOR.
This is done by checking the return value of freeSpace(), and if it
returns false, it means there is no space for PNOR because the host is
running and erase() returns false.

Tested: Verify the status becomes Failed when trying to activate a PNOR
        while host is running.

Change-Id: Ie2986b0c6fd29557685f67eb77ccc29709e1669a
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/static/activation_static.cpp b/static/activation_static.cpp
index 9768d41..193d6b3 100644
--- a/static/activation_static.cpp
+++ b/static/activation_static.cpp
@@ -19,6 +19,7 @@
 auto ActivationStatic::activation(Activations value) -> Activations
 {
 
+    auto ret = value;
     if (value != softwareServer::Activation::Activations::Active)
     {
         redundancyPriority.reset(nullptr);
@@ -26,9 +27,14 @@
 
     if (value == softwareServer::Activation::Activations::Activating)
     {
-        parent.freeSpace();
-        startActivation();
-        return softwareServer::Activation::activation(value);
+        if (parent.freeSpace())
+        {
+            startActivation();
+        }
+        else
+        {
+            ret = softwareServer::Activation::Activations::Failed;
+        }
     }
     else
     {
@@ -36,7 +42,7 @@
         activationProgress.reset(nullptr);
     }
 
-    return softwareServer::Activation::activation(value);
+    return softwareServer::Activation::activation(ret);
 }
 
 void ActivationStatic::startActivation()
diff --git a/static/item_updater_static.cpp b/static/item_updater_static.cpp
index 628f824..140d5cc 100644
--- a/static/item_updater_static.cpp
+++ b/static/item_updater_static.cpp
@@ -335,7 +335,7 @@
     // There is no implementation for this interface
 }
 
-void ItemUpdaterStatic::freeSpace()
+bool ItemUpdaterStatic::freeSpace()
 {
     // For now assume static layout only has 1 active PNOR,
     // so erase the active PNOR
@@ -344,10 +344,10 @@
         if (iter.second.get()->activation() ==
             server::Activation::Activations::Active)
         {
-            erase(iter.second->versionId);
-            break;
+            return erase(iter.second->versionId);
         }
     }
+    return false;
 }
 
 void ItemUpdaterStatic::updateFunctionalAssociation(
diff --git a/static/item_updater_static.hpp b/static/item_updater_static.hpp
index 75afeda..c3f273d 100644
--- a/static/item_updater_static.hpp
+++ b/static/item_updater_static.hpp
@@ -33,7 +33,7 @@
 
     void deleteAll() override;
 
-    void freeSpace() override;
+    bool freeSpace() override;
 
     void updateFunctionalAssociation(const std::string& versionId) override;