#include <utility>
#include "lib/app_status/app_status_manager.hh"
+#include "lib/app_info/app_info_manager.hh"
#include "lib/amd_cynara.h"
#include "lib/amd_launchpad.h"
#include "lib/amd_noti.h"
std::string appid = b->GetString(AUL_K_APPID);
if (!appid.empty() && !operation.empty()) {
CheckerInfo checker_info(info, static_cast<request_h>(req));
- int ret = pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges(
- appid.c_str(), operation.c_str(),
- [](const char* privilege_name, void* user_data) {
- CheckerInfo* info = static_cast<CheckerInfo*>(user_data);
- int ret = _cynara_simple_checker(info->GetCallerInfo(),
- info->GetRequest(),
- static_cast<void*>(const_cast<char*>(privilege_name)));
- if (ret >= 0 && info->GetResult() == AMD_CYNARA_UNKNOWN)
- return ret;
-
- info->SetResult(ret);
+ auto app_info =
+ amd::AppInfoManager::GetInst().FindAppInfo(req->GetTargetUID(), appid);
+ if (!app_info) {
+ _E("Failed to find appinfo. appid=%s", appid.c_str());
+ return -1;
+ }
+
+ for (const auto& app_control : app_info->GetAppControls()) {
+ if (app_control->GetOperation() != operation) continue;
+
+ for (const auto& priv_name : app_control->GetPrivileges()) {
+ int ret = _cynara_simple_checker(
+ checker_info.GetCallerInfo(), checker_info.GetRequest(),
+ static_cast<void*>(const_cast<char*>(priv_name.c_str())));
+ if (ret >= 0 && checker_info.GetResult() == AMD_CYNARA_UNKNOWN)
return ret;
- }, static_cast<void*>(&checker_info),
- req->GetTargetUID());
- if (ret != PMINFO_R_OK) {
- _E("pkgmgrinfo_appinfo_usr_foreach_appcontrol_privileges() is failed");
- return ret;
+
+ checker_info.SetResult(ret);
+ }
}
if (checker_info.GetResult() < 0)
#include <string>
#include <utility>
+#include <vector>
namespace amd {
class AppControlInfo {
public:
AppControlInfo(std::string operation, std::string uri, std::string mime,
- std::string m_type, std::string s_type)
- : operation_(std::move(operation)),
- uri_(std::move(uri)),
- mime_(std::move(mime)),
- m_type_(std::move(m_type)),
- s_type_(std::move(s_type)) {
- }
+ std::string m_type, std::string s_type, std::string id,
+ std::vector<std::string> privileges)
+ : operation_(std::move(operation)),
+ uri_(std::move(uri)),
+ mime_(std::move(mime)),
+ m_type_(std::move(m_type)),
+ s_type_(std::move(s_type)),
+ id_(std::move(id)),
+ privileges_(std::move(privileges)) {}
+
+ AppControlInfo(std::string operation, std::string uri, std::string mime,
+ std::string m_type, std::string s_type)
+ : operation_(std::move(operation)),
+ uri_(std::move(uri)),
+ mime_(std::move(mime)),
+ m_type_(std::move(m_type)),
+ s_type_(std::move(s_type)) {}
virtual ~AppControlInfo() = default;
- const std::string& GetOperation() const {
- return operation_;
- }
+ const std::string& GetOperation() const { return operation_; }
+
+ const std::string& GetUri() const { return uri_; }
+
+ const std::string& GetMime() const { return mime_; }
- const std::string& GetUri() const {
- return uri_;
- }
+ const std::string& GetMType() const { return m_type_; }
- const std::string& GetMime() const {
- return mime_;
- }
+ const std::string& GetSType() const { return s_type_; }
- const std::string& GetMType() const {
- return m_type_;
- }
+ const std::string& GetId() const { return id_; }
- const std::string& GetSType() const {
- return s_type_;
- }
+ const std::vector<std::string>& GetPrivileges() const { return privileges_; }
private:
std::string operation_;
std::string mime_;
std::string m_type_;
std::string s_type_;
+ std::string id_;
+ std::vector<std::string> privileges_;
};
} // namespace amd
return *this;
}
+std::vector<std::string> AppInfo::Builder::GetAppControlPrivileges(
+ const char* operation) {
+ std::vector<std::string> privileges;
+ int ret = pkgmgrinfo_appinfo_foreach_appcontrol_privileges(
+ app_id_.c_str(), operation,
+ [](const char* privilege_name, void* user_data) {
+ if (privilege_name == nullptr || privilege_name[0] == '\n') return 0;
+
+ auto* privilege_list =
+ static_cast<std::vector<std::string>*>(user_data);
+ privilege_list->emplace_back(privilege_name);
+ return 0;
+ },
+ static_cast<void*>(&privileges));
+ if (ret != PMINFO_R_OK)
+ _E("pkgmgrinfo_appinfo_foreach_appcontrol_privileges() is failed");
+
+ return privileges;
+}
+
AppInfo::Builder& AppInfo::Builder::SetAppControl(pkgmgrinfo_appinfo_h handle) {
- int ret = pkgmgrinfo_appinfo_foreach_appcontrol(handle,
+ int ret = pkgmgrinfo_appinfo_foreach_appcontrol_v2(
+ handle,
[](const char* operation, const char* uri, const char* mime,
- void* user_data) -> int {
+ const char* id, void* user_data) -> int {
+ auto* builder = static_cast<AppInfo::Builder*>(user_data);
+ std::vector<std::string> privileges =
+ builder->GetAppControlPrivileges(operation);
auto mime_type = Util::Split(mime ? mime : "NULL/", "/");
- auto* app_control = new (std::nothrow) AppControlInfo(operation,
- uri ? uri : "NULL", mime ? mime : "NULL",
- mime_type[0], mime_type[1]);
+ auto* app_control = new (std::nothrow) AppControlInfo(
+ operation, uri ? uri : "NULL", mime ? mime : "NULL", mime_type[0],
+ mime_type[1], id, std::move(privileges));
if (app_control == nullptr) {
_E("Out of memory");
return -ENOMEM;
}
- _D("[APP_CONTROL] %s|%s|%s",
- app_control->GetOperation().c_str(),
- app_control->GetUri().c_str(),
- app_control->GetMime().c_str());
- auto* builder = static_cast<AppInfo::Builder*>(user_data);
+ _D("[APP_CONTROL] %s - %s|%s|%s",
+ app_control->GetId().c_str(),
+ app_control->GetOperation().c_str(),
+ app_control->GetUri().c_str(),
+ app_control->GetMime().c_str());
builder->app_controls_.emplace_back(app_control);
return 0;
- }, this);
+ },
+ this);
if (ret != PMINFO_R_OK)
_E("pkgmgrinfo_appinfo_foreach_app_control() is failed. error(%d)", ret);
#include <memory>
#include <string>
#include <unordered_map>
+#include <vector>
#include "lib/app_info/app_control_info.hh"
#include "lib/app_info/splash_screen.hh"
Builder& SetLightUserSwitchMode(pkgmgrinfo_appinfo_h handle);
operator AppInfo*();
+ private:
+ std::vector<std::string> GetAppControlPrivileges(const char* operation);
+
private:
std::string app_id_;
std::string component_type_;