Move scoped installer to commons 24/156724/1
authorZofia Abramowska <z.abramowska@samsung.com>
Thu, 19 Oct 2017 15:43:21 +0000 (17:43 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Thu, 19 Oct 2017 15:43:21 +0000 (17:43 +0200)
Change-Id: Ica11bbb06be6eeecf2377e142b2fb89ef8b82222

src/common/scoped_installer.h [new file with mode: 0644]
src/security-manager-tests/common/scoped_installer.h [deleted file]

diff --git a/src/common/scoped_installer.h b/src/common/scoped_installer.h
new file mode 100644 (file)
index 0000000..4a0ff06
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#pragma once
+
+#include <ftw.h>
+#include <string>
+#include <sys/capability.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <vector>
+
+#include <security-manager-types.h>
+
+#include <app_install_helper.h>
+#include <memory.h>
+#include <sm_request.h>
+#include <sm_api.h>
+#include <temp_test_user.h>
+#include <synchronization_pipe.h>
+#include <dpl/test/safe_cleanup.h>
+
+class ScopedInstaller {
+public:
+    ScopedInstaller(const AppInstallHelper &app, bool requestUid = true)
+        : m_appId(app.getAppId()),
+          m_uid(app.getUID()),
+          m_installType(app.getInstallType()),
+          m_shouldUninstall(true),
+          m_requestUid(requestUid),
+          m_creatorPid(getpid())
+    {
+        SecurityManagerTest::InstallRequest instReq;
+        instReq.setAppId(app.getAppId());
+        instReq.setPkgId(app.getPkgId());
+        if (app.getIsHybrid())
+            instReq.setHybrid();
+        if (app.getInstallType() != SM_APP_INSTALL_NONE)
+            instReq.setInstallType(app.getInstallType());
+        if (requestUid)
+            instReq.setUid(app.getUID());
+        if (!app.getVersion().empty())
+            instReq.setAppTizenVersion(app.getVersion());
+        if (!app.getAuthor().empty())
+            instReq.setAuthorId(app.getAuthor());
+        for (const auto& typePaths : app.getDirsMap())
+            for (const auto& path : typePaths.second)
+                instReq.addPath(path, typePaths.first);
+        for (const auto& typePaths : app.getFilesMap())
+            for (const auto& path : typePaths.second)
+                instReq.addPath(path, typePaths.first);
+        for (const auto &priv : app.getPrivileges())
+            instReq.addPrivilege(priv);
+        for (const auto &priv : app.getAppDefinedPrivileges())
+            instReq.addAppDefinedPrivilege(priv);
+
+        SecurityManagerTest::Api::install(instReq);
+    }
+
+    ScopedInstaller(const ScopedInstaller &) = delete;
+    ScopedInstaller(ScopedInstaller &&other)
+        : m_appId(std::move(other.m_appId)),
+          m_uid(other.m_uid),
+          m_installType(other.m_installType),
+          m_shouldUninstall(other.m_shouldUninstall),
+          m_requestUid(other.m_requestUid),
+          m_creatorPid(other.m_creatorPid)
+    {
+        other.m_uid = 0;
+        other.m_shouldUninstall = false;
+        other.m_creatorPid = -1;
+    }
+
+    ScopedInstaller& operator=(const ScopedInstaller &) = delete;
+
+    virtual ~ScopedInstaller() {
+        if (m_creatorPid == getpid())
+        {
+            SafeCleanup::run([this]{ uninstallApp(); });
+        }
+    }
+
+    void uninstallApp() {
+        if (!m_shouldUninstall)
+            return;
+        SecurityManagerTest::InstallRequest uninstReq;
+        uninstReq.setAppId(m_appId);
+        if (m_requestUid)
+            uninstReq.setUid(m_uid);
+        if (m_installType != SM_APP_INSTALL_NONE)
+            uninstReq.setInstallType(m_installType);
+        SecurityManagerTest::Api::uninstall(uninstReq);
+        m_shouldUninstall = false;
+    }
+
+protected:
+    std::string m_appId;
+    uid_t m_uid;
+    app_install_type m_installType;
+    bool m_shouldUninstall;
+    bool m_requestUid;
+    pid_t m_creatorPid;
+};
diff --git a/src/security-manager-tests/common/scoped_installer.h b/src/security-manager-tests/common/scoped_installer.h
deleted file mode 100644 (file)
index 4a0ff06..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd All Rights Reserved
- *
- *    Licensed under the Apache License, Version 2.0 (the "License");
- *    you may not use this file except in compliance with the License.
- *    You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *
- *    Unless required by applicable law or agreed to in writing, software
- *    distributed under the License is distributed on an "AS IS" BASIS,
- *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *    See the License for the specific language governing permissions and
- *    limitations under the License.
- */
-
-#pragma once
-
-#include <ftw.h>
-#include <string>
-#include <sys/capability.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <vector>
-
-#include <security-manager-types.h>
-
-#include <app_install_helper.h>
-#include <memory.h>
-#include <sm_request.h>
-#include <sm_api.h>
-#include <temp_test_user.h>
-#include <synchronization_pipe.h>
-#include <dpl/test/safe_cleanup.h>
-
-class ScopedInstaller {
-public:
-    ScopedInstaller(const AppInstallHelper &app, bool requestUid = true)
-        : m_appId(app.getAppId()),
-          m_uid(app.getUID()),
-          m_installType(app.getInstallType()),
-          m_shouldUninstall(true),
-          m_requestUid(requestUid),
-          m_creatorPid(getpid())
-    {
-        SecurityManagerTest::InstallRequest instReq;
-        instReq.setAppId(app.getAppId());
-        instReq.setPkgId(app.getPkgId());
-        if (app.getIsHybrid())
-            instReq.setHybrid();
-        if (app.getInstallType() != SM_APP_INSTALL_NONE)
-            instReq.setInstallType(app.getInstallType());
-        if (requestUid)
-            instReq.setUid(app.getUID());
-        if (!app.getVersion().empty())
-            instReq.setAppTizenVersion(app.getVersion());
-        if (!app.getAuthor().empty())
-            instReq.setAuthorId(app.getAuthor());
-        for (const auto& typePaths : app.getDirsMap())
-            for (const auto& path : typePaths.second)
-                instReq.addPath(path, typePaths.first);
-        for (const auto& typePaths : app.getFilesMap())
-            for (const auto& path : typePaths.second)
-                instReq.addPath(path, typePaths.first);
-        for (const auto &priv : app.getPrivileges())
-            instReq.addPrivilege(priv);
-        for (const auto &priv : app.getAppDefinedPrivileges())
-            instReq.addAppDefinedPrivilege(priv);
-
-        SecurityManagerTest::Api::install(instReq);
-    }
-
-    ScopedInstaller(const ScopedInstaller &) = delete;
-    ScopedInstaller(ScopedInstaller &&other)
-        : m_appId(std::move(other.m_appId)),
-          m_uid(other.m_uid),
-          m_installType(other.m_installType),
-          m_shouldUninstall(other.m_shouldUninstall),
-          m_requestUid(other.m_requestUid),
-          m_creatorPid(other.m_creatorPid)
-    {
-        other.m_uid = 0;
-        other.m_shouldUninstall = false;
-        other.m_creatorPid = -1;
-    }
-
-    ScopedInstaller& operator=(const ScopedInstaller &) = delete;
-
-    virtual ~ScopedInstaller() {
-        if (m_creatorPid == getpid())
-        {
-            SafeCleanup::run([this]{ uninstallApp(); });
-        }
-    }
-
-    void uninstallApp() {
-        if (!m_shouldUninstall)
-            return;
-        SecurityManagerTest::InstallRequest uninstReq;
-        uninstReq.setAppId(m_appId);
-        if (m_requestUid)
-            uninstReq.setUid(m_uid);
-        if (m_installType != SM_APP_INSTALL_NONE)
-            uninstReq.setInstallType(m_installType);
-        SecurityManagerTest::Api::uninstall(uninstReq);
-        m_shouldUninstall = false;
-    }
-
-protected:
-    std::string m_appId;
-    uid_t m_uid;
-    app_install_type m_installType;
-    bool m_shouldUninstall;
-    bool m_requestUid;
-    pid_t m_creatorPid;
-};