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>
26 #include <tzplatform.h>
28 struct AppInstallHelper {
29 AppInstallHelper(const std::string &name)
30 : m_appName(name), m_pkgName(name)
33 AppInstallHelper(const std::string &appName, const std::string &pkgName)
34 : m_appName(appName), m_pkgName(pkgName)
37 std::string getInstallDir() const {
38 return TzPlatformConfig::globalAppDir() + "/" + getPkgId();
41 std::string getTrustedDir(int i = 0) const {
42 return getInstallDir() + "/trustedDir" + std::to_string(i);
45 std::string getPrivateDir() const {
46 return getInstallDir() + "/app_dir/";
49 std::string getSharedPath(int i = 0) const {
50 return getPrivateDir() + "shareme" + std::to_string(i);
52 std::string getAppId() const {
53 return m_appName + "_app_id";
56 std::string getPkgId() const {
57 return m_pkgName + "_pkg_id";
60 void createInstallDir() {
61 if (mkdir(getInstallDir().c_str(), 0777) == 0) {
62 m_dirs.push_back(getInstallDir());
66 void createTrustedDir(int i = 0) {
67 if (mkdir(getTrustedDir(i).c_str(), 0777) == 0) {
68 m_dirs.push_back(getTrustedDir(i));
71 void createPrivateDir() {
72 if (mkdir(getPrivateDir().c_str(), 0777) == 0) {
73 m_dirs.push_back(getPrivateDir());
77 void createSharedFile(int i = 0) {
78 if (creat(getSharedPath(i).c_str(), 0777) == 0) {
79 m_files.push_back(getSharedPath(i));
83 void revokeRules() const {
85 0 == smack_revoke_subject(generateAppLabel().c_str()),
86 "Revoking smack subject failed");
88 0 == smack_revoke_subject(generatePkgLabel().c_str()),
89 "Revoking smack subject failed");
92 std::string generateAppLabel() const {
93 return "User::App::" + getAppId();
96 std::string generatePkgLabel() const {
97 return "User::Pkg::" + getPkgId();
101 for (const auto &dir : m_dirs) {
105 for (const auto &file : m_files) {
106 unlink(file.c_str());
111 virtual ~AppInstallHelper() {
112 // TODO we should also remove trusted dirs created with custom params
117 std::string m_appName;
118 std::string m_pkgName;
119 std::vector<std::string> m_dirs;
120 std::vector<std::string> m_files;