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.
20 #include <sys/types.h>
21 #include <sys/smack.h>
26 struct AppInstallHelper {
27 AppInstallHelper(const std::string &name)
31 std::string getInstallDir() {
32 return "/usr/apps/" + getPkgId();
35 std::string getTrustedDir(int i = 0) {
36 return getInstallDir() + "/trustedDir" + std::to_string(i);
39 std::string getPrivateDir() {
40 return getInstallDir() + "/app_dir/";
43 std::string getSharedPath(int i = 0) {
44 return getPrivateDir() + "shareme" + std::to_string(i);
46 std::string getAppId() {
47 return m_name + "_app_id";
50 std::string getPkgId() {
51 return m_name + "_pkg_id";
54 void createInstallDir() {
55 if (mkdir(getInstallDir().c_str(), 0777) == 0) {
56 m_dirs.push_back(getInstallDir());
60 void createTrustedDir(int i = 0) {
61 if (mkdir(getTrustedDir(i).c_str(), 0777) == 0) {
62 m_dirs.push_back(getTrustedDir(i));
65 void createPrivateDir() {
66 if (mkdir(getPrivateDir().c_str(), 0777) == 0) {
67 m_dirs.push_back(getPrivateDir());
71 void createSharedFile(int i = 0) {
72 if (creat(getSharedPath(i).c_str(), 0777) == 0) {
73 m_files.push_back(getSharedPath(i));
79 0 == smack_revoke_subject(generateAppLabel().c_str()),
80 "Revoking smack subject failed");
82 0 == smack_revoke_subject(generatePkgLabel().c_str()),
83 "Revoking smack subject failed");
86 std::string generateAppLabel() {
87 return "User::App::" + getAppId();
90 std::string generatePkgLabel() {
91 return "User::Pkg::" + getPkgId();
94 virtual ~AppInstallHelper() {
95 // TODO we should also remove trusted dirs created with custom params
96 for (const auto &dir : m_dirs) {
99 for (const auto &file : m_files) {
100 unlink(file.c_str());
106 std::vector<std::string> m_dirs;
107 std::vector<std::string> m_files;