/*
- * Copyright (c) 2017 Samsung Electronics Co.
+ * Copyright (c) 2017-2018 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.
/**
* @file src/common/policy/AppInfo.h
* @author Zofia Abramowska <z.abramowska@samsung.com>
- * @brief Definition of pkgmgr-info wrappers
+ * @author Tomasz Swierczek <t.swierczek@samsung.com>
+ * @brief Definition of app-data wrapper/cache (sub)classes
*/
#pragma once
#include <string>
#include <sys/types.h>
-#include <pkgmgr-info.h>
-
-#include <log/alog.h>
namespace AskUser {
-struct AppInfo {
- AppInfo(const std::string &appId, uid_t uid) : m_handle(nullptr) {
- int ret = pkgmgrinfo_appinfo_get_usr_appinfo(appId.c_str(), uid, &m_handle);
- if (ret != PMINFO_R_OK) {
- ALOGE("pkgmgrinfo_appinfo_get_usr_appinfo failed for " << appId << " with " << ret);
- m_handle = nullptr;
- }
+class AppInfo {
+public:
+
+ AppInfo() : m_uid(0) {};
+
+ virtual ~AppInfo() {};
+
+ virtual void purgeCache() {
+ m_appId.clear();
+ m_type.clear();
+ m_version.clear();
+ m_uid = 0;
}
- ~AppInfo() {
- if (m_handle)
- pkgmgrinfo_appinfo_destroy_appinfo(m_handle);
+
+ virtual std::string type(const std::string &appId, uid_t uid) {
+ update(appId, uid);
+ return m_type;
}
- const std::string type() {
- char *type = nullptr;
- int ret = pkgmgrinfo_appinfo_get_apptype(m_handle, &type);
- if (ret != PMINFO_R_OK) {
- ALOGE("pkgmgrinfo_appinfo_get_apptype failed with " << ret);
- return "";
- }
- return type ? type : "";
+
+ virtual std::string apiVersion(const std::string &appId, uid_t uid) {
+ update(appId, uid);
+ return m_version;
}
- const std::string apiVersion() {
- char *version = nullptr;
- int ret = pkgmgrinfo_appinfo_get_api_version(m_handle, &version);
- if (ret != PMINFO_R_OK) {
- ALOGE("pkgmgrinfo_appinfo_get_api_version failed with " << ret);
- return "";
+protected:
+ virtual void fetch(const std::string &appId, uid_t uid) = 0;
+
+ virtual void update(const std::string &appId, uid_t uid) {
+ if (m_appId != appId || uid != m_uid) {
+ purgeCache();
+ fetch(appId, uid);
}
- return version ? version : "";
}
- pkgmgrinfo_appinfo_h m_handle;
+ std::string m_appId;
+ uid_t m_uid;
+ std::string m_type;
+ std::string m_version;
+};
+
+class AulAppInfo : public AppInfo {
+protected:
+ virtual void fetch(const std::string &appId, uid_t uid);
};
+class PkgMgrAppInfo : public AppInfo {
+protected:
+ virtual void fetch(const std::string &appId, uid_t uid);
+};
+
+
} // namespace AskUser