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 bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
46 InstallationMode* mode) = 0;
47 virtual bool ShouldCreateSignal() const = 0;
51 * \brief The PkgmgrInstaller class
52 * Implementation of PkgmgrInstallerInterface that handles creation of
53 * pkgmgr_installer class in online and offline mode.
55 class PkgmgrInstaller : public PkgmgrInstallerInterface {
57 bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
58 InstallationMode* mode) override;
59 bool ShouldCreateSignal() const override;
63 * \brief Encapsulates pkgmgr API which handles parsing backend options
64 * and returns values/modes for installation process.
66 class PkgMgrInterface {
69 * Set current AppQueryInterface for request
71 * \param idx index of request
73 * \return True if setting was success. Otherwise, return false
75 bool SetAppQueryInterface(int idx);
78 * Add AppQueryInterface for request
80 * \param idx index of request
81 * \param interface AppQueryInterface for request
83 void AddAppQueryInterface(int idx, std::shared_ptr<AppQueryInterface> interface);
86 * Returns Request type passed from pkgmgr_installer
88 * \param idx index of request
90 * \return request type retrieved from pkgmgr_installer
92 RequestType GetRequestType(int idx = 0) const;
95 * Returns uid passed from pkgmgr_installer
97 * \return uid retrieved from pkgmgr_installer
102 * Returns Request info passed from pkgmgr_installer
104 * \param idx index of request
106 * \return request info retrieved from pkgmgr_installer
108 std::string GetRequestInfo(int idx = 0) const;
111 * Creates PkgMgrInterface
113 * \param argc main() argc argument passed to the backend
114 * \param argv main() argv argument passed to the backend
115 * \param pkgmgr_installer_interface interface defining strategy of creation
116 * of pkgmgr_installer
117 * \param interface pointer to AppQueryInterface
119 * \return Smart pointer to the PkgMgrInterface
121 static PkgMgrPtr Create(int argc, char** argv,
122 PkgmgrInstallerInterface* pkgmgr_installer_interface,
123 std::shared_ptr<AppQueryInterface> interface = nullptr);
126 * Returns TEP path passed from pkgmgr_installer
128 * \return TEP path retrieved from pkgmgr_installer
130 boost::filesystem::path GetTepPath() const;
133 * Returns True if TEP file should be moved. Otherwise, return false
135 * \return True if TEP file should be moved. Otherwise, return false
137 bool GetIsTepMove() const;
140 * Returns True if move request is to external. Otherwise, return false
142 * \return True if move request is to external. Otherwise, return false
144 bool GetIsMoveToExternal() const;
147 * Get MoveType for Move request
149 * \return value of MoveType
151 int GetMoveType() const;
154 * Returns True if the request is for preload. Otherwise, return false
156 * \return True if the request is for preload. Otherwise, return false
158 bool GetIsPreloadRequest() const;
161 * Returns True if the request is for preload-rw. Otherwise, return false
163 * \return True if the request is for preload-rw. Otherwise, return false
165 bool GetIsPreloadRWRequest() const;
168 * Returns True if the request has force-remove flag. Otherwise, return false
170 * \return True if the request has force-remove flag. Otherwise, return false
172 bool GetIsForceRemoval() const;
175 * Returns True if the request has no-remove flag. Otherwise, return false
177 * \return True if the request has no-remove flag. Otherwise, return false
179 bool GetIsNoRemoval() const;
182 * Returns True if the request has keep-rwdata flag. Otherwise, return false
184 * \return True if the request has keep-rwdata flag. Otherwise, return false
186 bool GetIsKeepRWData() const;
189 * Returns True if the request has partial-rw flag. Otherwise, return false
191 * \return True if the request has partial-rw flag. Otherwise, return false
193 bool GetIsPartialRW() const;
196 * Returns True if the request is debug mode. Otherwise, return false;
198 * \return True if the request is debug mode. Otherwise, return false;
200 bool GetDebugMode() const;
203 * Returns True if the request has skip-check-reference flag.
204 * Otherwise, return false;
206 * \return True if the request has skip-check-reference flag.
207 * Otherwise, return false;
209 bool GetIsSkipCheckReference() const;
212 * Returns True if the request is skip optimization. Otherwise, return false;
214 * \return True if the request is skip optimization. Otherwise, return false;
216 bool GetSkipOptimization() const;
219 * Returns the number of request info count.
221 * \return The number of request info count.
223 int GetRequestInfoCount() const;
226 * Returns whether recovery mode is set to cleanup or not.
228 * \return True if recovery mode is set to cleanup. Otherwise, return false.
230 bool GetRecoveryCleanup() const;
233 * Get Raw pointer to pkgmgr_installer object
234 * NOTE: It should not be used (PkgMgrInterface can destroy it
236 * \return raw pkgmgr_installer pointer
238 DEPRECATED pkgmgr_installer *GetRawPi() const { return pi_; }
241 * Returns installation mode
243 * \return 'ONLINE' for online installation, 'OFFLINE' otherwise
245 InstallationMode GetInstallationMode() const { return install_mode_; }
248 * @brief CreatePkgmgrSignal
250 * @return creates pkgmgr signal
252 std::unique_ptr<PkgmgrSignal> CreatePkgmgrSignal() const;
254 /** PkgMgrInstance destructor. */
258 explicit PkgMgrInterface(PkgmgrInstallerInterface* pkgmgr_installer_interface,
259 std::shared_ptr<AppQueryInterface> interface)
261 install_mode_(InstallationMode::ONLINE),
262 is_app_installed_(boost::none),
263 pkgmgr_installer_interface_(pkgmgr_installer_interface),
264 query_interface_(interface) {}
265 int InitInternal(int argc, char** argv);
267 pkgmgr_installer* pi_;
268 InstallationMode install_mode_;
269 mutable boost::optional<bool> is_app_installed_;
270 PkgmgrInstallerInterface* pkgmgr_installer_interface_;
272 std::shared_ptr<AppQueryInterface> query_interface_;
273 std::map<int, std::shared_ptr<AppQueryInterface>> query_interface_map_;
275 SCOPE_LOG_TAG(PkgMgrInterface)
276 DISALLOW_COPY_AND_ASSIGN(PkgMgrInterface);
279 } // namespace common_installer
281 #endif // COMMON_PKGMGR_INTERFACE_H_