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_creatorPid(getpid())
41 SecurityManagerTest::InstallRequest instReq;
43 if (m_appInstallHelper.getIsHybrid())
45 instReq.setAppId(m_appInstallHelper.getAppId());
46 instReq.setPkgId(m_appInstallHelper.getPkgId());
47 if (m_appInstallHelper.getInstallType() != SM_APP_INSTALL_NONE)
48 instReq.setInstallType(m_appInstallHelper.getInstallType());
50 instReq.setUid(m_appInstallHelper.getUID());
51 if (!m_appInstallHelper.getVersion().empty())
52 instReq.setAppTizenVersion(m_appInstallHelper.getVersion());
53 if (!m_appInstallHelper.getAuthor().empty())
54 instReq.setAuthorId(m_appInstallHelper.getAuthor());
55 for (const auto& typePaths : m_appInstallHelper.getDirsMap())
56 for (const auto& path : typePaths.second)
57 instReq.addPath(path, typePaths.first);
58 for (const auto& typePaths : m_appInstallHelper.getFilesMap())
59 for (const auto& path : typePaths.second)
60 instReq.addPath(path, typePaths.first);
61 for (const auto &priv : m_appInstallHelper.getPrivileges()) {
62 instReq.addPrivilege(priv.c_str());
64 SecurityManagerTest::Api::install(instReq);
67 virtual ~ScopedInstaller() {
68 if (m_creatorPid == getpid())
73 if (!m_shouldUninstall)
75 SecurityManagerTest::InstallRequest uninstReq;
76 uninstReq.setAppId(m_appInstallHelper.getAppId());
77 uninstReq.setUid(m_appInstallHelper.getUID());
79 SecurityManagerTest::Api::uninstall(uninstReq);
80 m_shouldUninstall = false;
83 AppInstallHelper& getAIH() {
84 return m_appInstallHelper;
88 AppInstallHelper m_appInstallHelper;
89 bool m_shouldUninstall;