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_isInstallDirCreated(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 AppInstallHelper(const std::string &appNamePrefix, const std::string &pkgNamePrefix, uid_t uid,
61 const std::string &version)
62 : AppInstallHelper(appNamePrefix, pkgNamePrefix, true, uid, version)
65 AppInstallHelper(const std::string &namePrefix, uid_t uid, const std::string &version)
66 : AppInstallHelper(namePrefix, namePrefix, true, uid, version)
69 AppInstallHelper(const AppInstallHelper &other) = default;
70 AppInstallHelper& operator=(const AppInstallHelper &other) = delete;
71 AppInstallHelper(AppInstallHelper &&other);
73 // App info getters and setters
74 std::string getAppId() const;
75 std::string getPkgId() const;
78 void setVersion(const std::string &version);
79 std::string getVersion() const;
80 void setAuthor(const std::string &author);
81 std::string getAuthor() const;
82 void setInstallType(app_install_type type);
83 app_install_type getInstallType() const;
85 bool getIsHybrid() const;
87 // Path types creation and removal on file system
88 void createInstallDir();
89 void createTrustedDir(int i = 0);
90 void createPrivateDir(int i = 0);
91 void createPublicDir();
92 void createPrivateFile(int i = 0);
93 void createSharedRODir(int i = 0);
94 void createPrivateRODir(int i = 0);
98 std::string getInstallDir() const;
99 std::string getTrustedDir(int i = 0) const;
100 std::string getPrivateDir(int i = 0) const;
101 std::string getPrivateRODir(int i = 0) const;
102 std::string getPublicDir() const;
103 std::string getPrivatePath(int i = 0) const;
104 std::string getSharedRODir(int i = 0) const;
105 const TypePathsMap& getDirsMap() const;
106 const TypePathsMap& getFilesMap() const;
109 void addPrivilege(const std::string &privilege);
110 void addPrivileges(const std::vector<std::string> &privileges);
111 std::vector<std::string> getPrivileges() const;
114 std::string generateAppLabel() const;
115 std::string generatePkgLabel() const;
116 void revokeRules() const;
117 virtual ~AppInstallHelper() {
118 if (m_creatorPid == getpid())
123 void setInstallPath();
124 bool create(std::function<int(const char*, mode_t)> &&creatFun, const std::string &path);
125 std::string m_appName;
126 std::string m_pkgName;
129 std::string m_version;
130 app_install_type m_installType;
132 std::string m_installDir;
133 bool m_isInstallDirCreated;
134 TypePathsMap m_dirTypeMap;
135 TypePathsMap m_fileTypeMap;
136 std::vector<std::string> m_privileges;
137 std::string m_author;