Allow SCS to launch without any container 98/28698/3
authorLukasz Kostyra <l.kostyra@samsung.com>
Mon, 13 Oct 2014 12:02:40 +0000 (14:02 +0200)
committerLukasz Kostyra <l.kostyra@samsung.com>
Wed, 15 Oct 2014 08:56:51 +0000 (10:56 +0200)
[Bug]           SCS segfaulted when launching without any containers provided in config.
[Cause]         Some functions assumed that certain config fields should never be empty
[Solution]      Additional checks to avoid segfault.
[Verification]  Build, install, run tests, launch SCS without any predefined containers.
                Try to switch between containers when less than two containers are present.

Change-Id: I58a69d55807f686fb168057dfb1b447707351a46

server/containers-manager.cpp

index d8858ab..c9c7ff8 100644 (file)
@@ -112,7 +112,7 @@ ContainersManager::ContainersManager(const std::string& managerConfigPath): mDet
     }
 
     // check if default container exists, throw ContainerOperationException if not found
-    if (mContainers.find(mConfig.defaultId) == mContainers.end()) {
+    if (!mConfig.defaultId.empty() && mContainers.find(mConfig.defaultId) == mContainers.end()) {
         LOGE("Provided default container ID " << mConfig.defaultId << " is invalid.");
         throw ContainerOperationException("Provided default container ID " + mConfig.defaultId +
                                           " is invalid.");
@@ -219,9 +219,11 @@ void ContainersManager::startAll()
                                                        return c1.second->getPrivilege() < c2.second->getPrivilege();
                                                    });
 
-        mConfig.foregroundId = foregroundIterator->second->getId();
-        LOGI(mConfig.foregroundId << ": no foreground container configured, setting one with highest priority");
-        foregroundIterator->second->goForeground();
+        if (foregroundIterator != mContainers.end()) {
+            mConfig.foregroundId = foregroundIterator->second->getId();
+            LOGI(mConfig.foregroundId << ": no foreground container configured, setting one with highest priority");
+            foregroundIterator->second->goForeground();
+        }
     }
 }
 
@@ -269,7 +271,10 @@ void ContainersManager::switchingSequenceMonitorNotify()
     LOGI("switchingSequenceMonitorNotify() called");
 
     auto nextContainerId = getNextToForegroundContainerId();
-    focus(nextContainerId);
+
+    if (!nextContainerId.empty()) {
+        focus(nextContainerId);
+    }
 }