#ifndef COMMON_PKGMGR_INTERFACE_H_
#define COMMON_PKGMGR_INTERFACE_H_
+#include <manifest_parser/utils/logging.h>
#include <pkgmgr_installer.h>
+#include <filesystem>
+#include <map>
#include <memory>
+#include <optional>
+#include <string>
#include "common/app_query_interface.h"
#include "common/utils/macros.h"
-#include "common/utils/logging.h"
+#include "common/utils/request.h"
namespace common_installer {
+enum class InstallationMode {
+ ONLINE,
+ OFFLINE
+};
+
+class PkgmgrSignal;
class PkgMgrInterface;
typedef std::shared_ptr<PkgMgrInterface> PkgMgrPtr;
-/** Class that covers pkgmgr_installer basic platform calls.
+/**
+ * \brief The PkgmgrInstallerInterface class
+ * Interface defining strategy for creation of pkgmgr_installer object
+ * and PkgmgrSignal object.
*
- * PkgMgr covers all pkgmgr_installer platform calls (and manages its
- * creation/destruction.
+ * This interface is injected to PkgMgrInterface class to decide:
+ * - how to create pkgmgr_installer,
+ * - if to create PkgmgrSignal object,
+ * - what installation mode should be set in installer context.
+ */
+class PkgmgrInstallerInterface {
+ public:
+ virtual ~PkgmgrInstallerInterface() = default;
+
+ virtual bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
+ InstallationMode* mode) = 0;
+ virtual bool ShouldCreateSignal() const = 0;
+};
+
+/**
+ * \brief The PkgmgrInstaller class
+ * Implementation of PkgmgrInstallerInterface that handles creation of
+ * pkgmgr_installer class in online and offline mode.
+ */
+class PkgmgrInstaller : public PkgmgrInstallerInterface {
+ public:
+ bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
+ InstallationMode* mode) override;
+ bool ShouldCreateSignal() const override;
+};
+
+/**
+ * \brief Encapsulates pkgmgr API which handles parsing backend options
+ * and returns values/modes for installation process.
*/
class PkgMgrInterface {
public:
- /** Request type received from pkgmgr_installer
+ /**
+ * Set current AppQueryInterface for request
+ *
+ * \param idx index of request
+ *
+ * \return True if setting was success. Otherwise, return false
+ */
+ bool SetAppQueryInterface(int idx);
+
+ /**
+ * Add AppQueryInterface for request
+ *
+ * \param idx index of request
+ * \param interface AppQueryInterface for request
*/
- enum class Type {
- Unknown,
- Install,
- Update,
- Uninstall,
- Reinstall
- };
-
- /** Returns Request type passed from pkgmgr_installer
+ void AddAppQueryInterface(int idx,
+ std::shared_ptr<AppQueryInterface> interface);
+
+ /**
+ * Get AppQueryInterface for current request
+ *
+ * \return AppQueryInterface ptr if current AppQueryInterface exist.
+ * Otherwise, return null shared_ptr
+ */
+ std::shared_ptr<AppQueryInterface> GetAppQueryInterface();
+
+ /**
+ * Returns Request type passed from pkgmgr_installer
+ *
+ * \param idx index of request
+ *
+ * \return request type retrieved from pkgmgr_installer
*/
- PkgMgrInterface::Type GetRequestType() const;
+ RequestType GetRequestType(int idx = 0) const;
- /** Returns Request info passed from pkgmgr_installer
+ /**
+ * Returns uid passed from pkgmgr_installer
+ *
+ * \return uid retrieved from pkgmgr_installer
*/
- const char *GetRequestInfo() const;
+ uid_t GetUid() const;
- /** Returns instance of PkgrMgr (Singleton pattern).
+ /**
+ * Returns Request info passed from pkgmgr_installer
*
- * However, Init method has to be called first (otherwise, this Instance
- * returns nullptr).
+ * \param idx index of request
*
- * @see PkgMgr::Init(int argc, char** argv)
+ * \return request info retrieved from pkgmgr_installer
*/
- static PkgMgrPtr Instance();
+ std::string GetRequestInfo(int idx = 0) const;
- /** Initialize PkgMgrInterface.
+ /**
+ * Creates PkgMgrInterface
+ *
+ * \param argc main() argc argument passed to the backend
+ * \param argv main() argv argument passed to the backend
+ * \param pkgmgr_installer_interface interface defining strategy of creation
+ * of pkgmgr_installer
+ * \param interface pointer to AppQueryInterface
+ *
+ * \return Smart pointer to the PkgMgrInterface
*/
- static int Init(int argc, char** argv,
- AppQueryInterface* interface = nullptr);
+ static PkgMgrPtr Create(int argc, char** argv,
+ PkgmgrInstallerInterface* pkgmgr_installer_interface,
+ std::shared_ptr<AppQueryInterface> interface = nullptr);
+
+ /**
+ * Returns TEP path passed from pkgmgr_installer
+ *
+ * \return TEP path retrieved from pkgmgr_installer
+ */
+ std::filesystem::path GetTepPath() const;
+
+ /**
+ * Returns True if TEP file should be moved. Otherwise, return false
+ *
+ * \return True if TEP file should be moved. Otherwise, return false
+ */
+ bool GetIsTepMove() const;
+
+ /**
+ * Returns True if move request is to external. Otherwise, return false
+ *
+ * \return True if move request is to external. Otherwise, return false
+ */
+ bool GetIsMoveToExternal() const;
- /** Get Raw pointer to pkgmgr_installer object
+ /**
+ * Get MoveType for Move request
*
- * It should not be used (PkgMgrInterface can destroy it
+ * \return value of MoveType
+ */
+ int GetMoveType() const;
+
+ /**
+ * Returns True if the request is for preload. Otherwise, return false
+ *
+ * \return True if the request is for preload. Otherwise, return false
+ */
+ bool GetIsPreloadRequest() const;
+
+ /**
+ * Returns True if the request is for preload-rw. Otherwise, return false
+ *
+ * \return True if the request is for preload-rw. Otherwise, return false
+ */
+ bool GetIsPreloadRWRequest() const;
+
+ /**
+ * Returns True if the request has force-remove flag. Otherwise, return false
+ *
+ * \return True if the request has force-remove flag. Otherwise, return false
+ */
+ bool GetIsForceRemoval() const;
+
+ /**
+ * Returns True if the request has no-remove flag. Otherwise, return false
+ *
+ * \return True if the request has no-remove flag. Otherwise, return false
+ */
+ bool GetIsNoRemoval() const;
+
+ /**
+ * Returns True if the request has keep-rwdata flag. Otherwise, return false
+ *
+ * \return True if the request has keep-rwdata flag. Otherwise, return false
+ */
+ bool GetIsKeepRWData() const;
+
+ /**
+ * Returns True if the request has partial-rw flag. Otherwise, return false
+ *
+ * \return True if the request has partial-rw flag. Otherwise, return false
+ */
+ bool GetIsPartialRW() const;
+
+ /**
+ * Returns True if the request is debug mode. Otherwise, return false;
+ *
+ * \return True if the request is debug mode. Otherwise, return false;
+ */
+ bool GetDebugMode() const;
+
+ /**
+ * Returns True if the request has skip-check-reference flag.
+ * Otherwise, return false;
+ *
+ * \return True if the request has skip-check-reference flag.
+ * Otherwise, return false;
+ */
+ bool GetIsSkipCheckReference() const;
+
+ /**
+ * Returns True if the request is skip optimization. Otherwise, return false;
+ *
+ * \return True if the request is skip optimization. Otherwise, return false;
+ */
+ bool GetSkipOptimization() const;
+
+ /**
+ * Returns the number of request info count.
+ *
+ * \return The number of request info count.
+ */
+ int GetRequestInfoCount() const;
+
+ /**
+ * Returns whether recovery mode is set to cleanup or not.
+ *
+ * \return True if recovery mode is set to cleanup. Otherwise, return false.
+ */
+ bool GetRecoveryCleanup() const;
+
+ /**
+ * Get Raw pointer to pkgmgr_installer object
+ * NOTE: It should not be used (PkgMgrInterface can destroy it
+ *
+ * \return raw pkgmgr_installer pointer
*/
DEPRECATED pkgmgr_installer *GetRawPi() const { return pi_; }
- /** PkgMgrInstance destructor.
+ /**
+ * Returns installation mode
+ *
+ * \return 'ONLINE' for online installation, 'OFFLINE' otherwise
+ */
+ InstallationMode GetInstallationMode() const { return install_mode_; }
+
+ /**
+ * @brief CreatePkgmgrSignal
*
+ * @return creates pkgmgr signal
*/
+ std::unique_ptr<PkgmgrSignal> CreatePkgmgrSignal() const;
+
+ /** PkgMgrInstance destructor. */
~PkgMgrInterface();
private:
- explicit PkgMgrInterface(AppQueryInterface* interface)
+ explicit PkgMgrInterface(PkgmgrInstallerInterface* pkgmgr_installer_interface,
+ std::shared_ptr<AppQueryInterface> interface)
: pi_(nullptr),
+ install_mode_(InstallationMode::ONLINE),
+ is_app_installed_(std::nullopt),
+ pkgmgr_installer_interface_(pkgmgr_installer_interface),
query_interface_(interface) {}
int InitInternal(int argc, char** argv);
pkgmgr_installer* pi_;
- bool is_app_installed_;
- AppQueryInterface* query_interface_;
- static PkgMgrPtr instance_;
+ InstallationMode install_mode_;
+ mutable std::optional<bool> is_app_installed_;
+ PkgmgrInstallerInterface* pkgmgr_installer_interface_;
+
+ std::shared_ptr<AppQueryInterface> query_interface_;
+ std::map<int, std::shared_ptr<AppQueryInterface>> query_interface_map_;
SCOPE_LOG_TAG(PkgMgrInterface)
DISALLOW_COPY_AND_ASSIGN(PkgMgrInterface);