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>
26 #include <security-manager-types.h>
28 struct AppInstallHelper {
30 using TypePathsMap = std::map<app_install_path_type, std::vector<std::string>>;
31 AppInstallHelper(const std::string &appNamePrefix,
32 const std::string &pkgNamePrefix,
35 std::string version = std::string())
36 : m_appName(appNamePrefix), m_pkgName(pkgNamePrefix), m_isLocal(isLocal), m_uidGid(uid), m_version(version),
37 m_installType(SM_APP_INSTALL_NONE), m_isHybrid(false), m_creatorPid(getpid())
42 AppInstallHelper(const std::string &appNamePrefix,
43 const std::string &pkgNamePrefix,
45 : AppInstallHelper(appNamePrefix, pkgNamePrefix, false, uid)
48 AppInstallHelper(const std::string &namePrefix)
49 : AppInstallHelper(namePrefix, namePrefix, false, geteuid())
52 AppInstallHelper(const std::string &appNamePrefix, const std::string &pkgNamePrefix)
53 : AppInstallHelper(appNamePrefix, pkgNamePrefix, false, geteuid())
56 AppInstallHelper(const std::string &namePrefix, uid_t uid)
57 : AppInstallHelper(namePrefix, namePrefix, true, uid)
60 // TODO - copy constructor should be deleted
61 AppInstallHelper(const AppInstallHelper &other) = default;
62 AppInstallHelper(AppInstallHelper &&other);
64 // App info getters and setters
65 std::string getAppId() const;
66 std::string getPkgId() const;
69 void setVersion(const std::string &version);
70 std::string getVersion() const;
71 void setAuthor(const std::string &author);
72 std::string getAuthor() const;
73 void setInstallType(app_install_type type);
74 app_install_type getInstallType();
76 bool getIsHybrid() const;
78 // Path types creation and removal on file system
79 void createInstallDir();
80 void createTrustedDir(int i = 0);
81 void createPrivateDir();
82 void createPublicDir();
83 void createSharedFile(int i = 0);
84 void createSharedRODir();
85 void createPrivateRODir();
89 std::string getInstallDir() const;
90 std::string getTrustedDir(int i = 0) const;
91 std::string getPrivateDir() const;
92 std::string getPrivateRODir() const;
93 std::string getPublicDir() const;
94 std::string getSharedPath(int i = 0) const;
95 std::string getSharedRODir() const;
96 const TypePathsMap& getDirsMap() const;
97 const TypePathsMap& getFilesMap() const;
100 void addPrivilege(const std::string &privilege);
101 void addPrivileges(const std::vector<std::string> &privileges);
102 std::vector<std::string> getPrivileges() const;
105 std::string generateAppLabel() const;
106 std::string generatePkgLabel() const;
107 void revokeRules() const;
108 virtual ~AppInstallHelper() {
109 if (m_creatorPid == getpid())
114 void setInstallPath();
115 bool create(std::function<int(const char*, mode_t)> &&creatFun, const std::string &path);
116 std::string m_appName;
117 std::string m_pkgName;
120 std::string m_version;
121 app_install_type m_installType;
123 std::string m_installDir;
124 TypePathsMap m_dirTypeMap;
125 TypePathsMap m_fileTypeMap;
126 std::vector<std::string> m_privileges;
127 std::string m_author;