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 <manifest_parser/utils/logging.h>
9 #include <pkgmgr_installer.h>
17 #include "common/app_query_interface.h"
18 #include "common/utils/macros.h"
19 #include "common/utils/request.h"
21 namespace common_installer {
23 enum class InstallationMode {
29 class PkgMgrInterface;
30 typedef std::shared_ptr<PkgMgrInterface> PkgMgrPtr;
33 * \brief The PkgmgrInstallerInterface class
34 * Interface defining strategy for creation of pkgmgr_installer object
35 * and PkgmgrSignal object.
37 * This interface is injected to PkgMgrInterface class to decide:
38 * - how to create pkgmgr_installer,
39 * - if to create PkgmgrSignal object,
40 * - what installation mode should be set in installer context.
42 class PkgmgrInstallerInterface {
44 virtual ~PkgmgrInstallerInterface() = default;
46 virtual bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
47 InstallationMode* mode) = 0;
48 virtual bool ShouldCreateSignal() const = 0;
52 * \brief The PkgmgrInstaller class
53 * Implementation of PkgmgrInstallerInterface that handles creation of
54 * pkgmgr_installer class in online and offline mode.
56 class PkgmgrInstaller : public PkgmgrInstallerInterface {
58 bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
59 InstallationMode* mode) override;
60 bool ShouldCreateSignal() const override;
64 * \brief Encapsulates pkgmgr API which handles parsing backend options
65 * and returns values/modes for installation process.
67 class PkgMgrInterface {
70 * Set current AppQueryInterface for request
72 * \param idx index of request
74 * \return True if setting was success. Otherwise, return false
76 bool SetAppQueryInterface(int idx);
79 * Add AppQueryInterface for request
81 * \param idx index of request
82 * \param interface AppQueryInterface for request
84 void AddAppQueryInterface(int idx,
85 std::shared_ptr<AppQueryInterface> interface);
88 * Get AppQueryInterface for current request
90 * \return AppQueryInterface ptr if current AppQueryInterface exist.
91 * Otherwise, return null shared_ptr
93 std::shared_ptr<AppQueryInterface> GetAppQueryInterface();
96 * Returns Request type passed from pkgmgr_installer
98 * \param idx index of request
100 * \return request type retrieved from pkgmgr_installer
102 RequestType GetRequestType(int idx = 0) const;
105 * Returns uid passed from pkgmgr_installer
107 * \return uid retrieved from pkgmgr_installer
109 uid_t GetUid() const;
112 * Returns Request info passed from pkgmgr_installer
114 * \param idx index of request
116 * \return request info retrieved from pkgmgr_installer
118 std::string GetRequestInfo(int idx = 0) const;
121 * Creates PkgMgrInterface
123 * \param argc main() argc argument passed to the backend
124 * \param argv main() argv argument passed to the backend
125 * \param pkgmgr_installer_interface interface defining strategy of creation
126 * of pkgmgr_installer
127 * \param interface pointer to AppQueryInterface
129 * \return Smart pointer to the PkgMgrInterface
131 static PkgMgrPtr Create(int argc, char** argv,
132 PkgmgrInstallerInterface* pkgmgr_installer_interface,
133 std::shared_ptr<AppQueryInterface> interface = nullptr);
136 * Returns TEP path passed from pkgmgr_installer
138 * \return TEP path retrieved from pkgmgr_installer
140 std::filesystem::path GetTepPath() const;
143 * Returns True if TEP file should be moved. Otherwise, return false
145 * \return True if TEP file should be moved. Otherwise, return false
147 bool GetIsTepMove() const;
150 * Returns True if move request is to external. Otherwise, return false
152 * \return True if move request is to external. Otherwise, return false
154 bool GetIsMoveToExternal() const;
157 * Get MoveType for Move request
159 * \return value of MoveType
161 int GetMoveType() const;
164 * Returns True if the request is for preload. Otherwise, return false
166 * \return True if the request is for preload. Otherwise, return false
168 bool GetIsPreloadRequest() const;
171 * Returns True if the request is for preload-rw. Otherwise, return false
173 * \return True if the request is for preload-rw. Otherwise, return false
175 bool GetIsPreloadRWRequest() const;
178 * Returns True if the request has force-remove flag. Otherwise, return false
180 * \return True if the request has force-remove flag. Otherwise, return false
182 bool GetIsForceRemoval() const;
185 * Returns True if the request has no-remove flag. Otherwise, return false
187 * \return True if the request has no-remove flag. Otherwise, return false
189 bool GetIsNoRemoval() const;
192 * Returns True if the request has keep-rwdata flag. Otherwise, return false
194 * \return True if the request has keep-rwdata flag. Otherwise, return false
196 bool GetIsKeepRWData() const;
199 * Returns True if the request has partial-rw flag. Otherwise, return false
201 * \return True if the request has partial-rw flag. Otherwise, return false
203 bool GetIsPartialRW() const;
206 * Returns True if the request is debug mode. Otherwise, return false;
208 * \return True if the request is debug mode. Otherwise, return false;
210 bool GetDebugMode() const;
213 * Returns True if the request has skip-check-reference flag.
214 * Otherwise, return false;
216 * \return True if the request has skip-check-reference flag.
217 * Otherwise, return false;
219 bool GetIsSkipCheckReference() const;
222 * Returns True if the request is skip optimization. Otherwise, return false;
224 * \return True if the request is skip optimization. Otherwise, return false;
226 bool GetSkipOptimization() const;
229 * Returns the number of request info count.
231 * \return The number of request info count.
233 int GetRequestInfoCount() const;
236 * Returns whether recovery mode is set to cleanup or not.
238 * \return True if recovery mode is set to cleanup. Otherwise, return false.
240 bool GetRecoveryCleanup() const;
243 * Get Raw pointer to pkgmgr_installer object
244 * NOTE: It should not be used (PkgMgrInterface can destroy it
246 * \return raw pkgmgr_installer pointer
248 DEPRECATED pkgmgr_installer *GetRawPi() const { return pi_; }
251 * Returns installation mode
253 * \return 'ONLINE' for online installation, 'OFFLINE' otherwise
255 InstallationMode GetInstallationMode() const { return install_mode_; }
258 * @brief CreatePkgmgrSignal
260 * @return creates pkgmgr signal
262 std::unique_ptr<PkgmgrSignal> CreatePkgmgrSignal() const;
264 /** PkgMgrInstance destructor. */
268 explicit PkgMgrInterface(PkgmgrInstallerInterface* pkgmgr_installer_interface,
269 std::shared_ptr<AppQueryInterface> interface)
271 install_mode_(InstallationMode::ONLINE),
272 is_app_installed_(std::nullopt),
273 pkgmgr_installer_interface_(pkgmgr_installer_interface),
274 query_interface_(interface) {}
275 int InitInternal(int argc, char** argv);
277 pkgmgr_installer* pi_;
278 InstallationMode install_mode_;
279 mutable std::optional<bool> is_app_installed_;
280 PkgmgrInstallerInterface* pkgmgr_installer_interface_;
282 std::shared_ptr<AppQueryInterface> query_interface_;
283 std::map<int, std::shared_ptr<AppQueryInterface>> query_interface_map_;
285 SCOPE_LOG_TAG(PkgMgrInterface)
286 DISALLOW_COPY_AND_ASSIGN(PkgMgrInterface);
289 } // namespace common_installer
291 #endif // COMMON_PKGMGR_INTERFACE_H_