From 8dfe3361dc8b084dc54f028ab71d46000a895313 Mon Sep 17 00:00:00 2001 From: HaseenaSainul <41037131+HaseenaSainul@users.noreply.github.com> Date: Fri, 29 Apr 2022 22:23:41 +0530 Subject: [PATCH] Packager: syncup from rdkservices (#136) * Packager: syncup from rdkservices * Packager: define JSON Contianer for MetaData, instead of using JsonObject --- Packager/PackagerImplementation.cpp | 79 ++++++++++++++++- Packager/PackagerImplementation.h | 56 +++++++++++- Packager/cmake/FindGLIB.cmake | 128 ---------------------------- Packager/cmake/FindSqlite.cmake | 7 -- Packager/cmake/FindSqliteSee.cmake | 8 -- 5 files changed, 131 insertions(+), 147 deletions(-) delete mode 100644 Packager/cmake/FindGLIB.cmake delete mode 100644 Packager/cmake/FindSqlite.cmake delete mode 100644 Packager/cmake/FindSqliteSee.cmake diff --git a/Packager/PackagerImplementation.cpp b/Packager/PackagerImplementation.cpp index 861b2a60c6..9c80e7b7cc 100644 --- a/Packager/PackagerImplementation.cpp +++ b/Packager/PackagerImplementation.cpp @@ -25,7 +25,7 @@ #include #endif #include - +#include namespace WPEFramework { namespace Plugin { @@ -58,6 +58,10 @@ namespace Plugin { uint32_t result = Core::ERROR_NONE; Config config; + ASSERT(_service == nullptr); + _service = service; + _service->AddRef(); + config.FromString(service->ConfigLine()); if ((config.ConfigFile.IsSet() == true) && (config.ConfigFile.Value().empty() == false)) { @@ -118,6 +122,8 @@ namespace Plugin { PackagerImplementation::~PackagerImplementation() { FreeOPKG(); + _service->Release(); + _service = nullptr; } void PackagerImplementation::Register(Exchange::IPackager::INotification* notification) @@ -274,10 +280,77 @@ namespace Plugin { if (progress->percentage == 100) { self->_inProgress.Install->SetState(Exchange::IPackager::INSTALLED); self->NotifyStateChange(); + self->_inProgress.Install->SetAppName(progress->pkg->local_filename); + string callsign = self->GetCallsignFromMetaDataFile(self->_inProgress.Install->AppName()); + if (!callsign.empty()) { + self->DeactivatePlugin(callsign); + } } } #endif + string PackagerImplementation::GetCallsignFromMetaDataFile(const string& appName) + { + string callsign = ""; + string metaDataFileName = (string(opkg_config->cache_dir) + "/" + appName + string(AppPath) + appName + string(PackageJSONFile)); + TRACE(Trace::Information, (_T("[RDM]: Metadata is %s"), metaDataFileName.c_str())); + Core::File metaDataFile(metaDataFileName); + if (metaDataFile.Open()) { + MetaData metaData; + Core::OptionalType error; + if (metaData.IElement::FromFile(metaDataFile, error)) { + if (error.IsSet() == true) { + TRACE(Trace::Error, (_T("Parsing failed with %s"), ErrorDisplayMessage(error.Value()).c_str())); + } else { + if ((metaData.Type.IsSet() == true) && (metaData.Type.Value() == PackagerImplementation::PackageType::PLUGIN)) { + if (metaData.Callsign.IsSet() == true) { + callsign = metaData.Callsign.Value(); + } else { + TRACE(Trace::Information, (_T("[RDM]: callsign missing in metadata"))); + } + } else { + TRACE(Trace::Information, (_T("[RDM]: MetaData file does not contain plugin type"))); + } + } + } + } else { + TRACE(Trace::Error, (_T("[RDM]: Error in opening the file"))); + } + return callsign; + } + + void PackagerImplementation::DeactivatePlugin(const string& callsign) + { + ASSERT(_service != nullptr); + ASSERT(callsign.empty() == false); + + TRACE(Trace::Information, (_T("[RDM]: callsign from metadata is %s"), callsign.c_str())); + PluginHost::IShell* plugin = _service->QueryInterfaceByCallsign(callsign); + + if (plugin != nullptr) { + PluginHost::IShell::state currentState(plugin->State()); + if ((currentState == PluginHost::IShell::ACTIVATED) || (currentState == PluginHost::IShell::ACTIVATION) || (currentState == PluginHost::IShell::PRECONDITION)) { + TRACE(Trace::Information, (_T("[RDM]: Plugin %s is activated state, so deactivating"), callsign.c_str())); + uint32_t result = plugin->Deactivate(PluginHost::IShell::REQUESTED); + if (result == Core::ERROR_NONE) { + TRACE(Trace::Information, (_T("[RDM]: %s moved to Deactivated state"), callsign.c_str())); + } + else { + TRACE(Trace::Error, (_T("[RDM]: Failed to move %s to Deactivated state"), callsign.c_str())); + } + } else if (currentState == PluginHost::IShell::UNAVAILABLE) { + TRACE(Trace::Information, (_T("[RDM]: Plugin %s is unavailable"), callsign.c_str())); + } + else { + TRACE(Trace::Information, (_T("[RDM]: Plugin %s is already in deactivated state"), callsign.c_str())); + } + + plugin->Release(); + } else { + TRACE(Trace::Error, (_T("[RDM]: Plugin %s is not configured in this setup"), callsign.c_str())); + } + } + void PackagerImplementation::NotifyStateChange() { _adminLock.Lock(); @@ -350,4 +423,8 @@ namespace Plugin { } } // namespace Plugin +ENUM_CONVERSION_BEGIN(Plugin::PackagerImplementation::PackageType) + { Plugin::PackagerImplementation::PackageType::NONE, _TXT("none") }, + { Plugin::PackagerImplementation::PackageType::PLUGIN, _TXT("plugin") }, +ENUM_CONVERSION_END(Plugin::PackagerImplementation::PackageType); } // namespace WPEFramework diff --git a/Packager/PackagerImplementation.h b/Packager/PackagerImplementation.h index 73185ebd27..ab81d4a725 100644 --- a/Packager/PackagerImplementation.h +++ b/Packager/PackagerImplementation.h @@ -33,10 +33,17 @@ namespace WPEFramework { namespace Plugin { class PackagerImplementation : public Exchange::IPackager { + private: + static constexpr const TCHAR* AppPath = _T("/etc/apps/"); + static constexpr const TCHAR* PackageJSONFile = _T("_package.json"); + public: - PackagerImplementation(const PackagerImplementation&) = delete; - PackagerImplementation& operator=(const PackagerImplementation&) = delete; + enum PackageType { + NONE, + PLUGIN + }; + public: class EXTERNAL Config : public Core::JSON::Container { public: Config() @@ -66,6 +73,7 @@ namespace Plugin { Config(const Config&) = delete; Config& operator=(const Config&) = delete; + public: Core::JSON::String ConfigFile; Core::JSON::String TempDir; Core::JSON::String CacheDir; @@ -76,6 +84,35 @@ namespace Plugin { Core::JSON::Boolean AlwaysUpdateFirst; }; + class MetaData : public Core::JSON::Container { + public: + MetaData() + : Core::JSON::Container() + , Callsign() + , Type(NONE) + { + Add(_T("callsign"), &Callsign); + Add(_T("type"), &Type); + } + MetaData(const MetaData& copy) + : Core::JSON::Container() + , Callsign(copy.Callsign) + , Type(copy.Type) + { + Add(_T("callsign"), &Callsign); + Add(_T("type"), &Type); + } + ~MetaData() override = default; + + public: + Core::JSON::String Callsign; + Core::JSON::EnumType Type; + }; + + public: + PackagerImplementation(const PackagerImplementation&) = delete; + PackagerImplementation& operator=(const PackagerImplementation&) = delete; + PackagerImplementation() : _adminLock() , _configFile() @@ -87,6 +124,7 @@ namespace Plugin { , _alwaysUpdateFirst(false) , _volatileCache(false) , _opkgInitialized(false) + , _service(nullptr) , _worker(this) , _isUpgrade(false) , _isSyncing(false) @@ -179,7 +217,7 @@ namespace Plugin { string AppName() const override { - return (string()); + return _appname; } uint32_t ErrorCode() const override @@ -204,6 +242,14 @@ namespace Plugin { _progress = progress; } + void SetAppName(const TCHAR path[]) + { + string pathName = Core::File::PathName(string(path)); + if (pathName.empty() == false) { + _appname = Core::File::FileName(string(pathName.c_str(), pathName.size() - 1)); + } + } + void SetError(uint32_t err) { TRACE(Trace::Information, (_T("Setting error to %d"), err)); @@ -214,6 +260,7 @@ namespace Plugin { Exchange::IPackager::state _state = Exchange::IPackager::IDLE; uint32_t _error = 0u; uint8_t _progress = 0u; + string _appname; }; struct InstallationData { @@ -283,6 +330,8 @@ namespace Plugin { #if !defined (DO_NOT_USE_DEPRECATED_API) static void InstallationProgessNoLock(const _opkg_progress_data_t* progress, void* data); #endif + string GetCallsignFromMetaDataFile(const string& appName); + void DeactivatePlugin(const string& callsign); void NotifyStateChange(); void NotifyRepoSynced(uint32_t status); void BlockingInstallUntilCompletionNoLock(); @@ -300,6 +349,7 @@ namespace Plugin { bool _alwaysUpdateFirst; bool _volatileCache; bool _opkgInitialized; + PluginHost::IShell* _service; std::vector _notifications; InstallationData _inProgress; InstallThread _worker; diff --git a/Packager/cmake/FindGLIB.cmake b/Packager/cmake/FindGLIB.cmake deleted file mode 100644 index a04991af0e..0000000000 --- a/Packager/cmake/FindGLIB.cmake +++ /dev/null @@ -1,128 +0,0 @@ -# - Try to find Glib and its components (gio, gobject etc) -# Once done, this will define -# -# GLIB_FOUND - system has Glib -# GLIB_INCLUDE_DIRS - the Glib include directories -# GLIB_LIBRARIES - link these to use Glib -# -# Optionally, the COMPONENTS keyword can be passed to find_package() -# and Glib components can be looked for. Currently, the following -# components can be used, and they define the following variables if -# found: -# -# gio: GLIB_GIO_LIBRARIES -# gobject: GLIB_GOBJECT_LIBRARIES -# gmodule: GLIB_GMODULE_LIBRARIES -# gthread: GLIB_GTHREAD_LIBRARIES -# -# Note that the respective _INCLUDE_DIR variables are not set, since -# all headers are in the same directory as GLIB_INCLUDE_DIRS. -# -# Copyright (C) 2012 Raphael Kubo da Costa -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS -# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -if(GLIB_FIND_QUIETLY) - set(_GLIB_MODE QUIET) -elseif(GLIB_FIND_REQUIRED) - set(_GLIB_MODE REQUIRED) -endif() - -find_package(PkgConfig) -pkg_check_modules(PC_GLIB ${_GLIB_MODE} glib-2.0) - -find_library(GLIB_LIBRARIES - NAMES glib-2.0 - HINTS ${PC_GLIB_LIBDIR} - ${PC_GLIB_LIBRARY_DIRS} -) - -# Files in glib's main include path may include glibconfig.h, which, -# for some odd reason, is normally in $LIBDIR/glib-2.0/include. -get_filename_component(_GLIB_LIBRARY_DIR ${GLIB_LIBRARIES} PATH) -find_path(GLIBCONFIG_INCLUDE_DIR - NAMES glibconfig.h - HINTS ${PC_LIBDIR} ${PC_LIBRARY_DIRS} ${_GLIB_LIBRARY_DIR} - ${PC_GLIB_INCLUDEDIR} ${PC_GLIB_INCLUDE_DIRS} - PATH_SUFFIXES glib-2.0/include -) - -find_path(GLIB_INCLUDE_DIR - NAMES glib.h - HINTS ${PC_GLIB_INCLUDEDIR} - ${PC_GLIB_INCLUDE_DIRS} - PATH_SUFFIXES glib-2.0 -) - -set(GLIB_INCLUDE_DIRS ${GLIB_INCLUDE_DIR} ${GLIBCONFIG_INCLUDE_DIR}) - -# Version detection -if (EXISTS "${GLIBCONFIG_INCLUDE_DIR}/glibconfig.h") - file(READ "${GLIBCONFIG_INCLUDE_DIR}/glibconfig.h" GLIBCONFIG_H_CONTENTS) - string(REGEX MATCH "#define GLIB_MAJOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}") - set(GLIB_VERSION_MAJOR "${CMAKE_MATCH_1}") - string(REGEX MATCH "#define GLIB_MINOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}") - set(GLIB_VERSION_MINOR "${CMAKE_MATCH_1}") - string(REGEX MATCH "#define GLIB_MICRO_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}") - set(GLIB_VERSION_MICRO "${CMAKE_MATCH_1}") - set(GLIB_VERSION "${GLIB_VERSION_MAJOR}.${GLIB_VERSION_MINOR}.${GLIB_VERSION_MICRO}") -endif () - -# Additional Glib components. We only look for libraries, as not all of them -# have corresponding headers and all headers are installed alongside the main -# glib ones. -foreach (_component ${GLIB_FIND_COMPONENTS}) - if (${_component} STREQUAL "gio") - find_library(GLIB_GIO_LIBRARIES NAMES gio-2.0 HINTS ${_GLIB_LIBRARY_DIR}) - set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GIO_LIBRARIES) - elseif (${_component} STREQUAL "gobject") - find_library(GLIB_GOBJECT_LIBRARIES NAMES gobject-2.0 HINTS ${_GLIB_LIBRARY_DIR}) - set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GOBJECT_LIBRARIES) - elseif (${_component} STREQUAL "gmodule") - find_library(GLIB_GMODULE_LIBRARIES NAMES gmodule-2.0 HINTS ${_GLIB_LIBRARY_DIR}) - set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GMODULE_LIBRARIES) - elseif (${_component} STREQUAL "gthread") - find_library(GLIB_GTHREAD_LIBRARIES NAMES gthread-2.0 HINTS ${_GLIB_LIBRARY_DIR}) - set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GTHREAD_LIBRARIES) - elseif (${_component} STREQUAL "gio-unix") - # gio-unix is compiled as part of the gio library, but the include paths - # are separate from the shared glib ones. Since this is currently only used - # by WebKitGTK+ we don't go to extraordinary measures beyond pkg-config. - pkg_check_modules(GIO_UNIX QUIET gio-unix-2.0) - endif () -endforeach () - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(GLIB REQUIRED_VARS GLIB_INCLUDE_DIRS GLIB_LIBRARIES ${ADDITIONAL_REQUIRED_VARS} - VERSION_VAR GLIB_VERSION) - -mark_as_advanced( - GLIBCONFIG_INCLUDE_DIR - GLIB_GIO_LIBRARIES - GLIB_GIO_UNIX_LIBRARIES - GLIB_GMODULE_LIBRARIES - GLIB_GOBJECT_LIBRARIES - GLIB_GTHREAD_LIBRARIES - GLIB_INCLUDE_DIR - GLIB_INCLUDE_DIRS - GLIB_LIBRARIES -) diff --git a/Packager/cmake/FindSqlite.cmake b/Packager/cmake/FindSqlite.cmake deleted file mode 100644 index 5888ca329f..0000000000 --- a/Packager/cmake/FindSqlite.cmake +++ /dev/null @@ -1,7 +0,0 @@ -find_package(PkgConfig) -if(Sqlite_FIND_QUIETLY) - set(_SQLITE_MODE QUIET) -elseif(Sqlite_FIND_REQUIRED) - set(_SQLITE_MODE REQUIRED) -endif() -pkg_search_module(SQLITE ${_SQLITE_MODE} sqlite3) diff --git a/Packager/cmake/FindSqliteSee.cmake b/Packager/cmake/FindSqliteSee.cmake deleted file mode 100644 index eb94aeeeba..0000000000 --- a/Packager/cmake/FindSqliteSee.cmake +++ /dev/null @@ -1,8 +0,0 @@ -find_package(PkgConfig) - -if(SqliteSee_FIND_QUIETLY) - set(_SQLITE_SEE_MODE QUIET) -elseif(SqliteSee_FIND_REQUIRED) - set(_SQLITE_SEE_MODE REQUIRED) -endif() -pkg_search_module(SQLITE_SEE ${_SQLITE_SEE_MODE} sqlite3see)