1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache 2.0 license that can be
3 // found in the LICENSE file.
5 #ifndef COMMON_PKGMGR_INTERFACE_H_
6 #define COMMON_PKGMGR_INTERFACE_H_
8 #include <boost/filesystem/path.hpp>
9 #include <boost/none.hpp>
10 #include <boost/optional/optional.hpp>
11 #include <manifest_parser/utils/logging.h>
12 #include <pkgmgr_installer.h>
18 #include "common/app_query_interface.h"
19 #include "common/utils/macros.h"
20 #include "common/utils/request.h"
22 namespace common_installer {
24 enum class InstallationMode {
30 class PkgMgrInterface;
31 typedef std::shared_ptr<PkgMgrInterface> PkgMgrPtr;
34 * \brief The PkgmgrInstallerInterface class
35 * Interface defining strategy for creation of pkgmgr_installer object
36 * and PkgmgrSignal object.
38 * This interface is injected to PkgMgrInterface class to decide:
39 * - how to create pkgmgr_installer,
40 * - if to create PkgmgrSignal object,
41 * - what installation mode should be set in installer context.
43 class PkgmgrInstallerInterface {
45 virtual ~PkgmgrInstallerInterface() = default;
47 virtual bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
48 InstallationMode* mode) = 0;
49 virtual bool ShouldCreateSignal() const = 0;
53 * \brief The PkgmgrInstaller class
54 * Implementation of PkgmgrInstallerInterface that handles creation of
55 * pkgmgr_installer class in online and offline mode.
57 class PkgmgrInstaller : public PkgmgrInstallerInterface {
59 bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
60 InstallationMode* mode) override;
61 bool ShouldCreateSignal() const override;
65 * \brief Encapsulates pkgmgr API which handles parsing backend options
66 * and returns values/modes for installation process.
68 class PkgMgrInterface {
71 * Set current AppQueryInterface for request
73 * \param idx index of request
75 * \return True if setting was success. Otherwise, return false
77 bool SetAppQueryInterface(int idx);
80 * Add AppQueryInterface for request
82 * \param idx index of request
83 * \param interface AppQueryInterface for request
85 void AddAppQueryInterface(int idx,
86 std::shared_ptr<AppQueryInterface> interface);
89 * Returns Request type passed from pkgmgr_installer
91 * \param idx index of request
93 * \return request type retrieved from pkgmgr_installer
95 RequestType GetRequestType(int idx = 0) const;
98 * Returns uid passed from pkgmgr_installer
100 * \return uid retrieved from pkgmgr_installer
102 uid_t GetUid() const;
105 * Returns Request info passed from pkgmgr_installer
107 * \param idx index of request
109 * \return request info retrieved from pkgmgr_installer
111 std::string GetRequestInfo(int idx = 0) const;
114 * Creates PkgMgrInterface
116 * \param argc main() argc argument passed to the backend
117 * \param argv main() argv argument passed to the backend
118 * \param pkgmgr_installer_interface interface defining strategy of creation
119 * of pkgmgr_installer
120 * \param interface pointer to AppQueryInterface
122 * \return Smart pointer to the PkgMgrInterface
124 static PkgMgrPtr Create(int argc, char** argv,
125 PkgmgrInstallerInterface* pkgmgr_installer_interface,
126 std::shared_ptr<AppQueryInterface> interface = nullptr);
129 * Returns TEP path passed from pkgmgr_installer
131 * \return TEP path retrieved from pkgmgr_installer
133 boost::filesystem::path GetTepPath() const;
136 * Returns True if TEP file should be moved. Otherwise, return false
138 * \return True if TEP file should be moved. Otherwise, return false
140 bool GetIsTepMove() const;
143 * Returns True if move request is to external. Otherwise, return false
145 * \return True if move request is to external. Otherwise, return false
147 bool GetIsMoveToExternal() const;
150 * Get MoveType for Move request
152 * \return value of MoveType
154 int GetMoveType() const;
157 * Returns True if the request is for preload. Otherwise, return false
159 * \return True if the request is for preload. Otherwise, return false
161 bool GetIsPreloadRequest() const;
164 * Returns True if the request is for preload-rw. Otherwise, return false
166 * \return True if the request is for preload-rw. Otherwise, return false
168 bool GetIsPreloadRWRequest() const;
171 * Returns True if the request has force-remove flag. Otherwise, return false
173 * \return True if the request has force-remove flag. Otherwise, return false
175 bool GetIsForceRemoval() const;
178 * Returns True if the request has no-remove flag. Otherwise, return false
180 * \return True if the request has no-remove flag. Otherwise, return false
182 bool GetIsNoRemoval() const;
185 * Returns True if the request has keep-rwdata flag. Otherwise, return false
187 * \return True if the request has keep-rwdata flag. Otherwise, return false
189 bool GetIsKeepRWData() const;
192 * Returns True if the request has partial-rw flag. Otherwise, return false
194 * \return True if the request has partial-rw flag. Otherwise, return false
196 bool GetIsPartialRW() const;
199 * Returns True if the request is debug mode. Otherwise, return false;
201 * \return True if the request is debug mode. Otherwise, return false;
203 bool GetDebugMode() const;
206 * Returns True if the request has skip-check-reference flag.
207 * Otherwise, return false;
209 * \return True if the request has skip-check-reference flag.
210 * Otherwise, return false;
212 bool GetIsSkipCheckReference() const;
215 * Returns True if the request is skip optimization. Otherwise, return false;
217 * \return True if the request is skip optimization. Otherwise, return false;
219 bool GetSkipOptimization() const;
222 * Returns the number of request info count.
224 * \return The number of request info count.
226 int GetRequestInfoCount() const;
229 * Returns whether recovery mode is set to cleanup or not.
231 * \return True if recovery mode is set to cleanup. Otherwise, return false.
233 bool GetRecoveryCleanup() const;
236 * Get Raw pointer to pkgmgr_installer object
237 * NOTE: It should not be used (PkgMgrInterface can destroy it
239 * \return raw pkgmgr_installer pointer
241 DEPRECATED pkgmgr_installer *GetRawPi() const { return pi_; }
244 * Returns installation mode
246 * \return 'ONLINE' for online installation, 'OFFLINE' otherwise
248 InstallationMode GetInstallationMode() const { return install_mode_; }
251 * @brief CreatePkgmgrSignal
253 * @return creates pkgmgr signal
255 std::unique_ptr<PkgmgrSignal> CreatePkgmgrSignal() const;
257 /** PkgMgrInstance destructor. */
261 explicit PkgMgrInterface(PkgmgrInstallerInterface* pkgmgr_installer_interface,
262 std::shared_ptr<AppQueryInterface> interface)
264 install_mode_(InstallationMode::ONLINE),
265 is_app_installed_(boost::none),
266 pkgmgr_installer_interface_(pkgmgr_installer_interface),
267 query_interface_(interface) {}
268 int InitInternal(int argc, char** argv);
270 pkgmgr_installer* pi_;
271 InstallationMode install_mode_;
272 mutable boost::optional<bool> is_app_installed_;
273 PkgmgrInstallerInterface* pkgmgr_installer_interface_;
275 std::shared_ptr<AppQueryInterface> query_interface_;
276 std::map<int, std::shared_ptr<AppQueryInterface>> query_interface_map_;
278 SCOPE_LOG_TAG(PkgMgrInterface)
279 DISALLOW_COPY_AND_ASSIGN(PkgMgrInterface);
282 } // namespace common_installer
284 #endif // COMMON_PKGMGR_INTERFACE_H_