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 bool isHybrid = false)
37 : m_appName(appNamePrefix), m_pkgName(pkgNamePrefix), m_isLocal(isLocal), m_uidGid(uid), m_version(version),
38 m_installType(SM_APP_INSTALL_NONE), m_isHybrid(isHybrid), m_creatorPid(getpid())
43 AppInstallHelper(const std::string &appNamePrefix,
44 const std::string &pkgNamePrefix,
46 : AppInstallHelper(appNamePrefix, pkgNamePrefix, false, uid)
49 AppInstallHelper(const std::string &namePrefix)
50 : AppInstallHelper(namePrefix, namePrefix, false, geteuid())
53 AppInstallHelper(const std::string &appNamePrefix, const std::string &pkgNamePrefix)
54 : AppInstallHelper(appNamePrefix, pkgNamePrefix, false, geteuid())
57 AppInstallHelper(const std::string &namePrefix, uid_t uid)
58 : AppInstallHelper(namePrefix, namePrefix, true, uid)
61 // App info getters and setters
62 std::string getAppId() const;
63 std::string getPkgId() const;
66 void setVersion(const std::string &version);
67 std::string getVersion() const;
68 void setAuthor(const std::string &author);
69 std::string getAuthor() const;
70 void setInstallType(app_install_type type);
71 app_install_type getInstallType();
72 bool getIsHybrid() const;
74 // Path types creation and removal on file system
75 void createInstallDir();
76 void createTrustedDir(int i = 0);
77 void createPrivateDir();
78 void createPublicDir();
79 void createSharedFile(int i = 0);
80 void createSharedRODir();
81 void createPrivateRODir();
85 std::string getInstallDir() const;
86 std::string getTrustedDir(int i = 0) const;
87 std::string getPrivateDir() const;
88 std::string getPrivateRODir() const;
89 std::string getPublicDir() const;
90 std::string getSharedPath(int i = 0) const;
91 std::string getSharedRODir() const;
92 const TypePathsMap& getDirsMap() const;
93 const TypePathsMap& getFilesMap() const;
96 void addPrivilege(const std::string &privilege);
97 void addPrivileges(const std::vector<std::string> &privileges);
98 std::vector<std::string> getPrivileges() const;
101 std::string generateAppLabel() const;
102 std::string generatePkgLabel() const;
103 void revokeRules() const;
104 virtual ~AppInstallHelper() {
105 if (m_creatorPid == getpid())
110 void setInstallPath();
111 bool create(std::function<int(const char*, mode_t)> &&creatFun, const std::string &path);
112 std::string m_appName;
113 std::string m_pkgName;
116 std::string m_version;
117 app_install_type m_installType;
119 std::string m_installDir;
120 TypePathsMap m_dirTypeMap;
121 TypePathsMap m_fileTypeMap;
122 std::vector<std::string> m_privileges;
123 std::string m_author;