From 99ebb49b90ec9c8da0bb8c92a230b600bf44c8ee Mon Sep 17 00:00:00 2001 From: Kamil Rojewski Date: Tue, 19 Apr 2016 10:43:07 +0200 Subject: [PATCH] saving ime info in the manifest Requires: - https://review.tizen.org/gerrit/#/c/67903/ Change-Id: Icf7c4fd9403f50ecd3db90f9f4a86ab336e9c6e1 --- src/hybrid/hybrid_installer.cc | 12 ++++ src/wgt/CMakeLists.txt | 2 + src/wgt/step/common/privileges.cc | 12 ++++ src/wgt/step/common/privileges.h | 16 +++++ src/wgt/step/configuration/step_parse.cc | 20 +++++- src/wgt/step/configuration/step_parse.h | 1 + src/wgt/step/pkgmgr/step_generate_xml.cc | 32 +++++++++ .../step/security/step_check_wgt_ime_privilege.cc | 84 ++++++++++++++++++++++ .../step/security/step_check_wgt_ime_privilege.h | 39 ++++++++++ src/wgt/wgt_installer.cc | 8 +++ 10 files changed, 225 insertions(+), 1 deletion(-) create mode 100644 src/wgt/step/common/privileges.cc create mode 100644 src/wgt/step/common/privileges.h create mode 100644 src/wgt/step/security/step_check_wgt_ime_privilege.cc create mode 100644 src/wgt/step/security/step_check_wgt_ime_privilege.h diff --git a/src/hybrid/hybrid_installer.cc b/src/hybrid/hybrid_installer.cc index e6ea1fa..2f9c274 100644 --- a/src/hybrid/hybrid_installer.cc +++ b/src/hybrid/hybrid_installer.cc @@ -69,6 +69,8 @@ #include "wgt/step/pkgmgr/step_generate_xml.h" #include "wgt/step/security/step_check_settings_level.h" #include "wgt/step/security/step_check_wgt_background_category.h" +#include "wgt/step/security/step_check_wgt_notification_category.h" +#include "wgt/step/security/step_check_wgt_ime_privilege.h" namespace ci = common_installer; @@ -92,6 +94,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -123,6 +127,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep( @@ -185,6 +191,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep( @@ -242,6 +250,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -274,6 +284,8 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep( diff --git a/src/wgt/CMakeLists.txt b/src/wgt/CMakeLists.txt index 41de461..7a63521 100644 --- a/src/wgt/CMakeLists.txt +++ b/src/wgt/CMakeLists.txt @@ -1,5 +1,6 @@ # Target - sources SET(SRCS + step/common/privileges.cc step/configuration/step_parse.cc step/configuration/step_parse_recovery.cc step/encryption/step_encrypt_resources.cc @@ -16,6 +17,7 @@ SET(SRCS step/security/step_check_settings_level.cc step/security/step_check_wgt_background_category.cc step/security/step_check_wgt_notification_category.cc + step/security/step_check_wgt_ime_privilege.cc wgt_app_query_interface.cc wgt_installer.cc ) diff --git a/src/wgt/step/common/privileges.cc b/src/wgt/step/common/privileges.cc new file mode 100644 index 0000000..5634f90 --- /dev/null +++ b/src/wgt/step/common/privileges.cc @@ -0,0 +1,12 @@ +// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. +#include "privileges.h" + +namespace wgt { +namespace common { +namespace privileges { +const char kImePrivilegeName[] = "http://tizen.org/privilege/ime"; +} // namespace privileges +} // namespace common +} // namespace wgt diff --git a/src/wgt/step/common/privileges.h b/src/wgt/step/common/privileges.h new file mode 100644 index 0000000..5a36ba6 --- /dev/null +++ b/src/wgt/step/common/privileges.h @@ -0,0 +1,16 @@ +// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#ifndef WGT_STEP_COMMON_PRIVILEGES_H_ +#define WGT_STEP_COMMON_PRIVILEGES_H_ + +namespace wgt { +namespace common { +namespace privileges { +extern const char kImePrivilegeName[]; +} // namespace privileges +} // namespace common +} // namespace wgt + +#endif // WGT_STEP_COMMON_PRIVILEGES_H_ diff --git a/src/wgt/step/configuration/step_parse.cc b/src/wgt/step/configuration/step_parse.cc index 35e248e..c19e7d9 100644 --- a/src/wgt/step/configuration/step_parse.cc +++ b/src/wgt/step/configuration/step_parse.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -466,8 +467,25 @@ bool StepParse::FillAccounts(manifest_x* manifest) { return true; } +bool StepParse::FillImeInfo() { + const auto ime_info = std::static_pointer_cast( + parser_->GetManifestData(app_keys::kTizenImeKey)); + if (!ime_info) + return true; + + common_installer::ImeInfo info; + info.setUuid(ime_info->uuid()); + + const auto &languages = ime_info->languages(); + for (const auto &language : languages) + info.AddLanguage(language); + + context_->manifest_plugins_data.get().ime_info.set(std::move(info)); + return true; +} + bool StepParse::FillExtraManifestInfo(manifest_x* manifest) { - return FillAccounts(manifest); + return FillAccounts(manifest) && FillImeInfo(); } bool StepParse::FillManifestX(manifest_x* manifest) { diff --git a/src/wgt/step/configuration/step_parse.h b/src/wgt/step/configuration/step_parse.h index 17a7ed6..93a9328 100644 --- a/src/wgt/step/configuration/step_parse.h +++ b/src/wgt/step/configuration/step_parse.h @@ -58,6 +58,7 @@ class StepParse : public common_installer::Step { bool FillMetadata(manifest_x* manifest); bool FillExtraManifestInfo(manifest_x* manifest); bool FillAccounts(manifest_x* manifest); + bool FillImeInfo(); bool FillBackgroundCategoryInfo(manifest_x* manifest); bool FillManifestX(manifest_x* manifest); diff --git a/src/wgt/step/pkgmgr/step_generate_xml.cc b/src/wgt/step/pkgmgr/step_generate_xml.cc index 0b21b3c..43c96ee 100644 --- a/src/wgt/step/pkgmgr/step_generate_xml.cc +++ b/src/wgt/step/pkgmgr/step_generate_xml.cc @@ -22,6 +22,7 @@ #include #include +#include "wgt/step/common/privileges.h" namespace bs = boost::system; namespace bf = boost::filesystem; @@ -360,6 +361,9 @@ common_installer::Step::Status StepGenerateXml::process() { xmlTextWriterEndElement(writer); } + const auto &ime = context_->manifest_plugins_data.get().ime_info.get(); + const auto ime_uuid = ime.uuid(); + // add privilege element if (context_->manifest_data.get()->privileges) { xmlTextWriterStartElement(writer, BAD_CAST "privileges"); @@ -368,6 +372,7 @@ common_installer::Step::Status StepGenerateXml::process() { xmlTextWriterWriteFormatElement(writer, BAD_CAST "privilege", "%s", BAD_CAST priv); } + xmlTextWriterEndElement(writer); } @@ -421,6 +426,33 @@ common_installer::Step::Status StepGenerateXml::process() { xmlTextWriterEndElement(writer); } + if (!ime_uuid.empty()) { + xmlTextWriterStartElement(writer, BAD_CAST "ime"); + + GListRange app_range(context_->manifest_data.get()->application); + if (!app_range.Empty()) { + // wgt app have ui-application as first application element. + // there may be service-applications but not as first element. + xmlTextWriterWriteAttribute(writer, BAD_CAST "appid", BAD_CAST (*app_range.begin())->appid); + } + + xmlTextWriterStartElement(writer, BAD_CAST "uuid"); + xmlTextWriterWriteString(writer, BAD_CAST ime_uuid.c_str()); + xmlTextWriterEndElement(writer); + + xmlTextWriterStartElement(writer, BAD_CAST "languages"); + + for (auto it = ime.LanguagesBegin(); it != ime.LanguagesEnd(); ++it) { + xmlTextWriterStartElement(writer, BAD_CAST "language"); + xmlTextWriterWriteString(writer, BAD_CAST it->c_str()); + xmlTextWriterEndElement(writer); + } + + xmlTextWriterEndElement(writer); + + xmlTextWriterEndElement(writer); + } + for (const char* profile : GListRange(context_->manifest_data.get()->deviceprofile)) { xmlTextWriterStartElement(writer, BAD_CAST "profile"); diff --git a/src/wgt/step/security/step_check_wgt_ime_privilege.cc b/src/wgt/step/security/step_check_wgt_ime_privilege.cc new file mode 100644 index 0000000..a791bfc --- /dev/null +++ b/src/wgt/step/security/step_check_wgt_ime_privilege.cc @@ -0,0 +1,84 @@ +// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#include +#include + +#include +#include + +#include + +namespace { +const char kImeCategoryName[] = "http://tizen.org/category/ime"; +} + +namespace wgt { +namespace security { + +common_installer::Step::Status StepCheckWgtImePrivilege::process() { + utils::VersionNumber apiVersion(context_->manifest_data.get()->api_version); + + const auto version23 = apiVersion < utils::VersionNumber("2.4"); + auto has_ime = false; + + for (const auto app : + GListRange(context_->manifest_data.get()->application)) { + for (const auto category : GListRange(app->category)) { + if (!strcmp(category, kImeCategoryName)) { + has_ime = true; + + const auto result = version23 ? Check23Api() : Check24Api(); + if (result != Status::OK) { + LOG(ERROR) << "Insufficient privileges for IME application."; + return result; + } + + break; + } + } + } + + if (!has_ime) { + // be sure no ime data is present without the category + context_->manifest_plugins_data.get().ime_info.get().setUuid(std::string()); + } else if (version23) { + // be sure there's a privilege in manifest + context_->manifest_data.get()->privileges + = g_list_append(context_->manifest_data.get()->privileges, + strdup(common::privileges::kImePrivilegeName)); + } + + return Status::OK; +} + +common_installer::Step::Status StepCheckWgtImePrivilege::Check23Api() const { + const auto &ime = context_->manifest_plugins_data.get().ime_info.get(); + if (ime.uuid().empty()) { + LOG(ERROR) << "Missing IME tag."; + return Status::CONFIG_ERROR; + } + + // ime priv not supported in 2.3 + return CheckImePrivilege() != Status::OK ? + Status::OK : Status::PRIVILEGE_ERROR; +} + +common_installer::Step::Status StepCheckWgtImePrivilege::Check24Api() const { + return CheckImePrivilege(); +} + +common_installer::Step::Status +StepCheckWgtImePrivilege::CheckImePrivilege() const { + for (const auto privilege : + GListRange(context_->manifest_data.get()->privileges)) { + if (!strcmp(privilege, common::privileges::kImePrivilegeName)) + return Status::OK; + } + + LOG(DEBUG) << "Missing IME privilege."; + return Status::PRIVILEGE_ERROR; +} +} // namespace security +} // namespace wgt diff --git a/src/wgt/step/security/step_check_wgt_ime_privilege.h b/src/wgt/step/security/step_check_wgt_ime_privilege.h new file mode 100644 index 0000000..d5595db --- /dev/null +++ b/src/wgt/step/security/step_check_wgt_ime_privilege.h @@ -0,0 +1,39 @@ +// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#ifndef WGT_STEP_SECURITY_STEP_CHECK_WGT_IME_PRIVILEGE_H_ +#define WGT_STEP_SECURITY_STEP_CHECK_WGT_IME_PRIVILEGE_H_ + +#include + +namespace wgt { +namespace security { + +/** + * \brief Checks if the app has IME privileges. + */ +class StepCheckWgtImePrivilege : + public common_installer::Step { + public: + using common_installer::Step::Step; + ~StepCheckWgtImePrivilege() override = default; + + Status process() override; + + Status clean() override { return Status::OK; } + Status undo() override { return Status::OK; } + Status precheck() override { return Status::OK; } + + private: + Status Check23Api() const; + Status Check24Api() const; + + Status CheckImePrivilege() const; + + SCOPE_LOG_TAG(CheckWgtImePrivilege) +}; +} // namespace security +} // namespace wgt + +#endif // WGT_STEP_SECURITY_STEP_CHECK_WGT_IME_PRIVILEGE_H_ diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc index 6fdaa51..55c7a53 100644 --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -75,6 +75,7 @@ #include "wgt/step/security/step_check_settings_level.h" #include "wgt/step/security/step_check_wgt_background_category.h" #include "wgt/step/security/step_check_wgt_notification_category.h" +#include "wgt/step/security/step_check_wgt_ime_privilege.h" namespace ci = common_installer; @@ -96,6 +97,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -124,6 +126,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep( @@ -196,6 +199,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep( @@ -245,6 +249,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -272,6 +278,8 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); + AddStep(); + AddStep(); AddStep(); AddStep( ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, -- 2.7.4