#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 {
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 {
--- /dev/null
+/*
+ * 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;
+};