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 <sm_commons.h>
27 #include <tzplatform.h>
29 struct AppInstallHelper {
30 AppInstallHelper(const std::string &name)
31 : m_appName(name), m_pkgName(name)
34 AppInstallHelper(const std::string &appName, const std::string &pkgName)
35 : m_appName(appName), m_pkgName(pkgName)
38 std::string getInstallDir() const {
39 return TzPlatformConfig::globalAppDir() + "/" + getPkgId();
42 std::string getTrustedDir(int i = 0) const {
43 return getInstallDir() + "/trustedDir" + std::to_string(i);
46 std::string getPrivateDir() const {
47 return getInstallDir() + "/app_dir/";
50 std::string getSharedPath(int i = 0) const {
51 return getPrivateDir() + "shareme" + std::to_string(i);
53 std::string getAppId() const {
54 return m_appName + "_app_id";
57 std::string getPkgId() const {
58 return m_pkgName + "_pkg_id";
61 void createInstallDir() {
62 if (mkdir(getInstallDir().c_str(), 0777) == 0) {
63 m_dirs.push_back(getInstallDir());
67 void createTrustedDir(int i = 0) {
68 if (mkdir(getTrustedDir(i).c_str(), 0777) == 0) {
69 m_dirs.push_back(getTrustedDir(i));
72 void createPrivateDir() {
73 if (mkdir(getPrivateDir().c_str(), 0777) == 0) {
74 m_dirs.push_back(getPrivateDir());
78 void createSharedFile(int i = 0) {
79 if (creat(getSharedPath(i).c_str(), 0777) == 0) {
80 m_files.push_back(getSharedPath(i));
84 void revokeRules() const {
86 0 == smack_revoke_subject(generateAppLabel().c_str()),
87 "Revoking smack subject failed");
89 0 == smack_revoke_subject(generatePkgLabel().c_str()),
90 "Revoking smack subject failed");
93 std::string generateAppLabel() const {
94 return generateProcessLabel(getAppId());
97 std::string generatePkgLabel() const {
98 return generatePathRWLabel(getPkgId());
102 for (const auto &dir : m_dirs) {
106 for (const auto &file : m_files) {
107 unlink(file.c_str());
112 virtual ~AppInstallHelper() {
113 // TODO we should also remove trusted dirs created with custom params
118 std::string m_appName;
119 std::string m_pkgName;
120 std::vector<std::string> m_dirs;
121 std::vector<std::string> m_files;