From 3556bdb4ad943e1d10dbbebf1be362f90ef9551a Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 11 Jun 2020 18:52:22 +0900 Subject: [PATCH] Add uid attribute of ThemeInfo Change-Id: I2cbc7fac05bcb6915f9fc629703530e85be86e3a Signed-off-by: Sangyoon Jang --- CMakeLists.txt | 1 + packaging/tizen-theme-manager.spec | 1 + src/theme/loader/theme_info.cc | 5 +++++ src/theme/loader/theme_info.h | 2 ++ src/theme_plugin/CMakeLists.txt | 1 + src/theme_plugin/theme_metadata_plugin.cc | 27 ++++++++++++++++++++++++--- src/theme_plugin/theme_parser.cc | 4 +++- src/theme_plugin/theme_parser.h | 5 ++++- test/unit_tests/test_theme_info.cc | 8 ++++++++ test/unit_tests/test_theme_parser.cc | 3 ++- 10 files changed, 51 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 202a2ae..3fe9fb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ PKG_CHECK_MODULES(GMOCK_DEPS REQUIRED gmock) PKG_CHECK_MODULES(JSONCPP_DEPS REQUIRED jsoncpp) PKG_CHECK_MODULES(PKGMGR_PARSER_DEPS REQUIRED pkgmgr-parser) PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info) +PKG_CHECK_MODULES(PKGMGR_INSTALLER_DEPS REQUIRED pkgmgr-installer) PKG_CHECK_MODULES(SQLITE_DEPS REQUIRED sqlite3) PKG_CHECK_MODULES(GOBJECT_DEPS REQUIRED gobject-2.0) diff --git a/packaging/tizen-theme-manager.spec b/packaging/tizen-theme-manager.spec index 3ed76fe..df25d5d 100644 --- a/packaging/tizen-theme-manager.spec +++ b/packaging/tizen-theme-manager.spec @@ -15,6 +15,7 @@ BuildRequires: pkgconfig(gmock) BuildRequires: pkgconfig(jsoncpp) BuildRequires: pkgconfig(pkgmgr-parser) BuildRequires: pkgconfig(pkgmgr-info) +BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(sqlite3) %if 0%{?gcov:1} diff --git a/src/theme/loader/theme_info.cc b/src/theme/loader/theme_info.cc index 4f7ccb6..3f54a27 100644 --- a/src/theme/loader/theme_info.cc +++ b/src/theme/loader/theme_info.cc @@ -33,6 +33,11 @@ std::string ThemeInfo::GetPkgid() const { return bundle_.GetString("pkgid"); } +uid_t ThemeInfo::GetUid() const { + std::string uid_str = bundle_.GetString("uid"); + return std::stoi(uid_str); +} + std::string ThemeInfo::GetVersion() const { return bundle_.GetString("version"); } diff --git a/src/theme/loader/theme_info.h b/src/theme/loader/theme_info.h index e28323b..cc4ff41 100644 --- a/src/theme/loader/theme_info.h +++ b/src/theme/loader/theme_info.h @@ -18,6 +18,7 @@ #define THEME_LOADER_THEME_INFO_H_ #include +#include #include #include @@ -34,6 +35,7 @@ class ThemeInfo { std::string GetId() const; std::string GetPkgid() const; + uid_t GetUid() const; std::string GetVersion() const; std::string GetToolVersion() const; std::string GetTitle() const; diff --git a/src/theme_plugin/CMakeLists.txt b/src/theme_plugin/CMakeLists.txt index 6e8aa33..fe12d96 100644 --- a/src/theme_plugin/CMakeLists.txt +++ b/src/theme_plugin/CMakeLists.txt @@ -8,6 +8,7 @@ APPLY_PKG_CONFIG(${TARGET_TIZEN_THEME_PLUGIN} PUBLIC GLIB_DEPS JSONCPP_DEPS PKGMGR_INFO_DEPS + PKGMGR_INSTALLER_DEPS PKGMGR_PARSER_DEPS ) diff --git a/src/theme_plugin/theme_metadata_plugin.cc b/src/theme_plugin/theme_metadata_plugin.cc index d4ca146..eadf073 100644 --- a/src/theme_plugin/theme_metadata_plugin.cc +++ b/src/theme_plugin/theme_metadata_plugin.cc @@ -5,13 +5,16 @@ #include #include +#include #include #include +#include #include #include #include "theme/utils/glist_range.h" +#include "theme/utils/logging.h" #include "theme_plugin/theme_parser.h" namespace { @@ -41,9 +44,15 @@ std::string GetThemeFilePath(const char* pkgid) { bool InstallTheme(const std::string& id, const std::string& pkgid, const std::string& path) { + uid_t uid; + int r = pkgmgr_installer_info_get_target_uid(&uid); + if (r < 0) { + LOG(ERROR) << "Failed to get target uid"; + return false; + } ttm::plugin::ThemeParser parser(path); if (!parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::ADD, - parser.Inflate(id, pkgid))) + parser.Inflate(id, pkgid, uid))) return false; return true; } @@ -65,9 +74,15 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL( bool UpgradeTheme(const std::string& id, const std::string& pkgid, const std::string& path) { + uid_t uid; + int r = pkgmgr_installer_info_get_target_uid(&uid); + if (r < 0) { + LOG(ERROR) << "Failed to get target uid"; + return false; + } ttm::plugin::ThemeParser parser(path); if (!parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::UPDATE, - parser.Inflate(id, pkgid))) + parser.Inflate(id, pkgid, uid))) return false; return true; } @@ -89,9 +104,15 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE( bool UninstallTheme(const std::string& id, const std::string& pkgid, const std::string& path) { + uid_t uid; + int r = pkgmgr_installer_info_get_target_uid(&uid); + if (r < 0) { + LOG(ERROR) << "Failed to get target uid"; + return false; + } ttm::plugin::ThemeParser parser(path); if (!parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::REMOVE, - parser.Inflate(id, pkgid))) + parser.Inflate(id, pkgid, uid))) return false; return true; } diff --git a/src/theme_plugin/theme_parser.cc b/src/theme_plugin/theme_parser.cc index e48cb4f..12c2479 100644 --- a/src/theme_plugin/theme_parser.cc +++ b/src/theme_plugin/theme_parser.cc @@ -5,6 +5,7 @@ #include "theme_plugin/theme_parser.h" #include +#include #include #include @@ -18,7 +19,7 @@ namespace ttm { namespace plugin { loader::ThemeInfo ThemeParser::Inflate(const std::string id, - const std::string pkgid) { + const std::string pkgid, uid_t uid) { Json::CharReaderBuilder rbuilder; rbuilder["collectComments"] = false; @@ -34,6 +35,7 @@ loader::ThemeInfo ThemeParser::Inflate(const std::string id, // FIXME: this parser should parse more theme information. ThemeInfoBuilder builder("testid"); builder.PutString("pkgid", pkgid). + PutString("uid", std::to_string(uid)). PutString("version", root["version"].asString()). PutString("tool_version", root["tool_version"].asString()). PutString("title", root["header"]["title"].asString()). diff --git a/src/theme_plugin/theme_parser.h b/src/theme_plugin/theme_parser.h index 6d08b9b..b6b120b 100644 --- a/src/theme_plugin/theme_parser.h +++ b/src/theme_plugin/theme_parser.h @@ -5,6 +5,8 @@ #ifndef THEME_PLUGIN_THEME_PARSER_H_ #define THEME_PLUGIN_THEME_PARSER_H_ +#include + #include #include @@ -22,7 +24,8 @@ class ThemeParser { }; explicit ThemeParser(const std::string& path) : path_(path) {} - loader::ThemeInfo Inflate(const std::string id, const std::string pkgid); + loader::ThemeInfo Inflate(const std::string id, const std::string pkgid, + uid_t uid); int Commit(ThemeOperation operation, const loader::ThemeInfo& theme); private: diff --git a/test/unit_tests/test_theme_info.cc b/test/unit_tests/test_theme_info.cc index dbbbe3e..895e931 100644 --- a/test/unit_tests/test_theme_info.cc +++ b/test/unit_tests/test_theme_info.cc @@ -31,6 +31,7 @@ class ThemeInfoTest : public testing::Test { virtual void SetUp() { b_.Add("id", "testid"); b_.Add("pkgid", "testpkgid"); + b_.Add("uid", "5001"); b_.Add("version", "1.0"); b_.Add("tool_version", "1.1"); b_.Add("title", "Test"); @@ -57,6 +58,12 @@ TEST_F(ThemeInfoTest, ThemeInfo_GetPkgid) { EXPECT_EQ(info.GetPkgid(), "testpkgid"); } +TEST_F(ThemeInfoTest, ThemeInfo_GetUid) { + ThemeInfo info(b_); + + EXPECT_EQ(info.GetUid(), 5001); +} + TEST_F(ThemeInfoTest, ThemeInfo_GetVersion) { ThemeInfo info(b_); @@ -99,6 +106,7 @@ TEST_F(ThemeInfoTest, ThemeInfo_Serialize) { tizen_base::Bundle b = info.Serialize(); EXPECT_EQ(b.GetString("id"), "testid"); EXPECT_EQ(b.GetString("pkgid"), "testpkgid"); + EXPECT_EQ(b.GetString("uid"), "5001"); EXPECT_EQ(b.GetString("version"), "1.0"); EXPECT_EQ(b.GetString("tool_version"), "1.1"); EXPECT_EQ(b.GetString("title"), "Test"); diff --git a/test/unit_tests/test_theme_parser.cc b/test/unit_tests/test_theme_parser.cc index 2723413..500bab0 100644 --- a/test/unit_tests/test_theme_parser.cc +++ b/test/unit_tests/test_theme_parser.cc @@ -32,9 +32,10 @@ class ThemeParserTest : public testing::Test { TEST_F(ThemeParserTest, Inflate) { ttm::plugin::ThemeParser parser("test_samples/test_theme.json"); - auto info = parser.Inflate("testid", "testpkgid"); + auto info = parser.Inflate("testid", "testpkgid", 5001); EXPECT_EQ(info.GetId(), "testid"); EXPECT_EQ(info.GetPkgid(), "testpkgid"); + EXPECT_EQ(info.GetUid(), 5001); EXPECT_EQ(info.GetVersion(), "1.0.0"); EXPECT_EQ(info.GetToolVersion(), "1.00.38.820793"); EXPECT_EQ(info.GetTitle(), "GOGO Theme"); -- 2.7.4