2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <sys/capability.h>
23 #include <sys/types.h>
26 #include <security-manager-types.h>
28 #include <app_install_helper.h>
31 #include <sm_request.h>
33 #include <temp_test_user.h>
34 #include <synchronization_pipe.h>
36 class ScopedInstaller {
38 ScopedInstaller(const AppInstallHelper &appInstallHelper, bool requestUid = true)
39 : m_appInstallHelper(appInstallHelper), m_shouldUninstall(true), m_requestUid(requestUid),
40 m_creatorPid(getpid())
42 SecurityManagerTest::InstallRequest instReq;
44 if (m_appInstallHelper.getIsHybrid())
46 instReq.setAppId(m_appInstallHelper.getAppId());
47 instReq.setPkgId(m_appInstallHelper.getPkgId());
48 if (m_appInstallHelper.getInstallType() != SM_APP_INSTALL_NONE)
49 instReq.setInstallType(m_appInstallHelper.getInstallType());
51 instReq.setUid(m_appInstallHelper.getUID());
52 if (!m_appInstallHelper.getVersion().empty())
53 instReq.setAppTizenVersion(m_appInstallHelper.getVersion());
54 if (!m_appInstallHelper.getAuthor().empty())
55 instReq.setAuthorId(m_appInstallHelper.getAuthor());
56 for (const auto& typePaths : m_appInstallHelper.getDirsMap())
57 for (const auto& path : typePaths.second)
58 instReq.addPath(path, typePaths.first);
59 for (const auto& typePaths : m_appInstallHelper.getFilesMap())
60 for (const auto& path : typePaths.second)
61 instReq.addPath(path, typePaths.first);
62 for (const auto &priv : m_appInstallHelper.getPrivileges()) {
63 instReq.addPrivilege(priv.c_str());
65 SecurityManagerTest::Api::install(instReq);
68 ScopedInstaller(const ScopedInstaller &) = delete;
69 ScopedInstaller(ScopedInstaller &&other)
70 : m_appInstallHelper(std::move(other.m_appInstallHelper)),
71 m_shouldUninstall(other.m_shouldUninstall),
72 m_requestUid(other.m_requestUid),
73 m_creatorPid(other.m_creatorPid)
75 other.m_shouldUninstall = false;
76 other.m_creatorPid = -1;
79 ScopedInstaller& operator=(const ScopedInstaller &) = delete;
81 virtual ~ScopedInstaller() {
82 if (m_creatorPid == getpid())
87 if (!m_shouldUninstall)
89 SecurityManagerTest::InstallRequest uninstReq;
90 uninstReq.setAppId(m_appInstallHelper.getAppId());
92 uninstReq.setUid(m_appInstallHelper.getUID());
94 SecurityManagerTest::Api::uninstall(uninstReq);
95 m_shouldUninstall = false;
98 AppInstallHelper& getAIH() {
99 return m_appInstallHelper;
103 AppInstallHelper m_appInstallHelper;
104 bool m_shouldUninstall;