Move PkgInfo to separate file 01/122201/7
authorZofia Abramowska <z.abramowska@samsung.com>
Tue, 28 Mar 2017 17:11:13 +0000 (19:11 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Mon, 3 Apr 2017 17:13:21 +0000 (19:13 +0200)
PkgInfo will be used separately from Policy wrappers

Change-Id: I33cd2643b2f854f991a9db9bb98e809f009ed0e9

packaging/askuser-notification.spec
src/agent/main/Policy.cpp
src/agent/notification-daemon/CMakeLists.txt
src/common/policy/PkgInfo.h [new file with mode: 0644]

index 8932ceb..99fadd3 100644 (file)
@@ -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)
index 3d4aa57..e63faa7 100644 (file)
 
 #include <memory>
 
-#include <pkgmgr-info.h>
 #include <security-manager.h>
 
 #include <exception/Exception.h>
 #include <log/alog.h>
 
+#include <policy/PkgInfo.h>
 #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 {
index 6e89216..5a8d33a 100644 (file)
@@ -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 (file)
index 0000000..e2f9e59
--- /dev/null
@@ -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 <z.abramowska@samsung.com>
+ * @brief       Definition of pkgmgr-info wrappers
+ */
+
+#pragma once
+
+#include <string>
+#include <sys/types.h>
+#include <pkgmgr-info.h>
+
+#include <log/alog.h>
+
+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;
+};