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>
30 #include <sm_request.h>
32 #include <temp_test_user.h>
33 #include <synchronization_pipe.h>
35 class ScopedInstaller {
37 ScopedInstaller(const AppInstallHelper &app, bool requestUid = true)
38 : m_appId(app.getAppId()),
40 m_shouldUninstall(true),
41 m_requestUid(requestUid),
42 m_creatorPid(getpid())
44 SecurityManagerTest::InstallRequest instReq;
45 instReq.setAppId(app.getAppId());
46 instReq.setPkgId(app.getPkgId());
47 if (app.getIsHybrid())
49 if (app.getInstallType() != SM_APP_INSTALL_NONE)
50 instReq.setInstallType(app.getInstallType());
52 instReq.setUid(app.getUID());
53 if (!app.getVersion().empty())
54 instReq.setAppTizenVersion(app.getVersion());
55 if (!app.getAuthor().empty())
56 instReq.setAuthorId(app.getAuthor());
57 for (const auto& typePaths : app.getDirsMap())
58 for (const auto& path : typePaths.second)
59 instReq.addPath(path, typePaths.first);
60 for (const auto& typePaths : app.getFilesMap())
61 for (const auto& path : typePaths.second)
62 instReq.addPath(path, typePaths.first);
63 for (const auto &priv : app.getPrivileges()) {
64 instReq.addPrivilege(priv.c_str());
66 SecurityManagerTest::Api::install(instReq);
69 ScopedInstaller(const ScopedInstaller &) = delete;
70 ScopedInstaller(ScopedInstaller &&other)
71 : m_appId(std::move(other.m_appId)),
73 m_shouldUninstall(other.m_shouldUninstall),
74 m_requestUid(other.m_requestUid),
75 m_creatorPid(other.m_creatorPid)
78 other.m_shouldUninstall = false;
79 other.m_creatorPid = -1;
82 ScopedInstaller& operator=(const ScopedInstaller &) = delete;
84 virtual ~ScopedInstaller() {
85 if (m_creatorPid == getpid())
90 if (!m_shouldUninstall)
92 SecurityManagerTest::InstallRequest uninstReq;
93 uninstReq.setAppId(m_appId);
95 uninstReq.setUid(m_uid);
97 SecurityManagerTest::Api::uninstall(uninstReq);
98 m_shouldUninstall = false;
104 bool m_shouldUninstall;