From 88785e0bf6f5b4acb7990fcde138d278a07a776f Mon Sep 17 00:00:00 2001 From: Zofia Abramowska Date: Tue, 28 Mar 2017 19:11:13 +0200 Subject: [PATCH] Move PkgInfo to separate file PkgInfo will be used separately from Policy wrappers Change-Id: I33cd2643b2f854f991a9db9bb98e809f009ed0e9 --- packaging/askuser-notification.spec | 1 + src/agent/main/Policy.cpp | 41 +---------------- src/agent/notification-daemon/CMakeLists.txt | 1 + src/common/policy/PkgInfo.h | 67 ++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 40 deletions(-) create mode 100644 src/common/policy/PkgInfo.h diff --git a/packaging/askuser-notification.spec b/packaging/askuser-notification.spec index 8932ceb..99fadd3 100644 --- a/packaging/askuser-notification.spec +++ b/packaging/askuser-notification.spec @@ -17,6 +17,7 @@ BuildRequires: pkgconfig(elementary) %if %{with_systemd_daemon} BuildRequires: pkgconfig(libsystemd) %endif +BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(security-privilege-manager) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(vconf) diff --git a/src/agent/main/Policy.cpp b/src/agent/main/Policy.cpp index 3d4aa57..e63faa7 100644 --- a/src/agent/main/Policy.cpp +++ b/src/agent/main/Policy.cpp @@ -21,12 +21,12 @@ #include -#include #include #include #include +#include #include "Policy.h" namespace { @@ -35,45 +35,6 @@ inline void throwOnSMError(std::string err, int ret) if (ret != SECURITY_MANAGER_SUCCESS) throw AskUser::Exception(err + " : " + std::to_string(ret)); } - -struct PkgInfo { - PkgInfo(const std::string &pkgId, uid_t uid) : m_handle(nullptr) { - int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgId.c_str(), uid, &m_handle); - if (ret != PMINFO_R_OK) { - ALOGE("pkgmgrinfo_pkginfo_get_usr_pkginfo failed for " << pkgId << " with " << ret); - m_handle = nullptr; - } - } - ~PkgInfo() { - if (m_handle) - pkgmgrinfo_pkginfo_destroy_pkginfo(m_handle); - } - const std::string mainAppId(){ - if (!m_handle) { - return ""; - } - char *mainAppId; - int ret = pkgmgrinfo_pkginfo_get_mainappid(m_handle, &mainAppId); - if (ret != PMINFO_R_OK) { - ALOGE("pkgmgrinfo_pkginfo_get_mainappid failed with " << ret); - return ""; - } - return mainAppId ? mainAppId : ""; - } - const std::string pkgLabel() { - if (!m_handle) { - return ""; - } - char *pkgLabel; - int ret = pkgmgrinfo_pkginfo_get_label(m_handle, &pkgLabel); - if (ret != PMINFO_R_OK) { - ALOGE("pkgmgrinfo_pkginfo_get_label failed with " << ret); - return ""; - } - return pkgLabel ? pkgLabel : ""; - } - pkgmgrinfo_pkginfo_h m_handle; -}; } namespace AskUser { diff --git a/src/agent/notification-daemon/CMakeLists.txt b/src/agent/notification-daemon/CMakeLists.txt index 6e89216..5a8d33a 100644 --- a/src/agent/notification-daemon/CMakeLists.txt +++ b/src/agent/notification-daemon/CMakeLists.txt @@ -9,6 +9,7 @@ PKG_CHECK_MODULES(ASKUSER_NOTIFICATION_DEP elementary libsystemd vconf + pkgmgr-info glib-2.0 capi-ui-efl-util capi-system-info diff --git a/src/common/policy/PkgInfo.h b/src/common/policy/PkgInfo.h new file mode 100644 index 0000000..e2f9e59 --- /dev/null +++ b/src/common/policy/PkgInfo.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +/** + * @file src/common/policy/PkgInfo.h + * @author Zofia Abramowska + * @brief Definition of pkgmgr-info wrappers + */ + +#pragma once + +#include +#include +#include + +#include + +struct PkgInfo { + PkgInfo(const std::string &pkgId, uid_t uid) : m_handle(nullptr) { + int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgId.c_str(), uid, &m_handle); + if (ret != PMINFO_R_OK) { + ALOGE("pkgmgrinfo_pkginfo_get_usr_pkginfo failed for " << pkgId << " with " << ret); + m_handle = nullptr; + } + } + ~PkgInfo() { + if (m_handle) + pkgmgrinfo_pkginfo_destroy_pkginfo(m_handle); + } + const std::string mainAppId(){ + if (!m_handle) { + return ""; + } + char *mainAppId; + int ret = pkgmgrinfo_pkginfo_get_mainappid(m_handle, &mainAppId); + if (ret != PMINFO_R_OK) { + ALOGE("pkgmgrinfo_pkginfo_get_mainappid failed with " << ret); + return ""; + } + return mainAppId ? mainAppId : ""; + } + const std::string pkgLabel() { + if (!m_handle) { + return ""; + } + char *pkgLabel; + int ret = pkgmgrinfo_pkginfo_get_label(m_handle, &pkgLabel); + if (ret != PMINFO_R_OK) { + ALOGE("pkgmgrinfo_pkginfo_get_label failed with " << ret); + return ""; + } + return pkgLabel ? pkgLabel : ""; + } + pkgmgrinfo_pkginfo_h m_handle; +}; -- 2.7.4