2 * Copyright (c) 2014-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.
22 #include <sys/types.h>
23 #include <sys/smack.h>
25 #include <dpl/test/test_runner.h>
27 struct AppInstallHelper {
28 AppInstallHelper(const std::string &name)
29 : m_appName(name), m_pkgName(name)
32 AppInstallHelper(const std::string &appName, const std::string &pkgName)
33 : m_appName(appName), m_pkgName(pkgName)
36 std::string getInstallDir() const {
37 return "/opt/usr/globalapps/" + getPkgId();
40 std::string getTrustedDir(int i = 0) const {
41 return getInstallDir() + "/trustedDir" + std::to_string(i);
44 std::string getPrivateDir() const {
45 return getInstallDir() + "/app_dir/";
48 std::string getSharedPath(int i = 0) const {
49 return getPrivateDir() + "shareme" + std::to_string(i);
51 std::string getAppId() const {
52 return m_appName + "_app_id";
55 std::string getPkgId() const {
56 return m_pkgName + "_pkg_id";
59 void createInstallDir() {
60 if (mkdir(getInstallDir().c_str(), 0777) == 0) {
61 m_dirs.push_back(getInstallDir());
65 void createTrustedDir(int i = 0) {
66 if (mkdir(getTrustedDir(i).c_str(), 0777) == 0) {
67 m_dirs.push_back(getTrustedDir(i));
70 void createPrivateDir() {
71 if (mkdir(getPrivateDir().c_str(), 0777) == 0) {
72 m_dirs.push_back(getPrivateDir());
76 void createSharedFile(int i = 0) {
77 if (creat(getSharedPath(i).c_str(), 0777) == 0) {
78 m_files.push_back(getSharedPath(i));
82 void revokeRules() const {
84 0 == smack_revoke_subject(generateAppLabel().c_str()),
85 "Revoking smack subject failed");
87 0 == smack_revoke_subject(generatePkgLabel().c_str()),
88 "Revoking smack subject failed");
91 std::string generateAppLabel() const {
92 return "User::App::" + getAppId();
95 std::string generatePkgLabel() const {
96 return "User::Pkg::" + getPkgId();
100 for (const auto &dir : m_dirs) {
104 for (const auto &file : m_files) {
105 unlink(file.c_str());
110 virtual ~AppInstallHelper() {
111 // TODO we should also remove trusted dirs created with custom params
116 std::string m_appName;
117 std::string m_pkgName;
118 std::vector<std::string> m_dirs;
119 std::vector<std::string> m_files;