Load appcontrol privileges at bootup time 34/318534/3
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 2 Oct 2024 00:52:29 +0000 (09:52 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 2 Oct 2024 01:27:05 +0000 (10:27 +0900)
During the process of calling the pkgmgrinfo API, it was observed that the AMD
is blocked for a certain period of time.
This patch modifies the booting process to load the appcontrol privilege
information by AMD in order to solve this problem.

Change-Id: I343ad57e24a458746d2a9ae0d19fb028745d40ff
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/amd_launch.cc
src/lib/app_info/app_control_info.hh
src/lib/app_info/app_info.cc
src/lib/app_info/app_info.hh

index 0d21c5814c95bbe8df7eaf50c24c0c1b8c425625..b5570f7a3d69e70f8522b30c52ce5af40e1a112d 100644 (file)
@@ -33,6 +33,7 @@
 #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"
@@ -131,23 +132,25 @@ int CheckAppControlPrivilege(caller_info_h info, amd::Request* req,
   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)
index 40a12eeeb82d1a2608f3fcbf22cb79ef8b2d4cf5..69d273bc939f5af6c1d6b980b5334afe9051f4e3 100644 (file)
 
 #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_;
@@ -61,6 +66,8 @@ class AppControlInfo {
   std::string mime_;
   std::string m_type_;
   std::string s_type_;
+  std::string id_;
+  std::vector<std::string> privileges_;
 };
 
 }  // namespace amd
index 099206d798d3fed08b2d4af521b2d062d082d64b..2bb60b191327843c7518aeb842fa1262861095e5 100644 (file)
@@ -99,27 +99,52 @@ AppInfo::Builder& AppInfo::Builder::SetSubmodeMainId(
   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);
 
index 9a7c06d282ca028589821ef573ef5122d7767a93..a7c251668bf1168da6f22f6879198b94be598768 100644 (file)
@@ -23,6 +23,7 @@
 #include <memory>
 #include <string>
 #include <unordered_map>
+#include <vector>
 
 #include "lib/app_info/app_control_info.hh"
 #include "lib/app_info/splash_screen.hh"
@@ -69,6 +70,9 @@ class AppInfo : public std::enable_shared_from_this<AppInfo> {
     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_;