Support NUIGadgetViewer
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 21 Mar 2023 09:35:07 +0000 (09:35 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 14 Apr 2023 00:51:02 +0000 (00:51 +0000)
When the target application ID is "org.tizen.NUIGadgetViewer", AMD assigns
the mount information for NUIGadget to the bundle object.
This patch includes the "org.tizen.NUIGadgetViewer" tpk file for installation.

Change-Id: Iab29b2ec86818794c048b3b9f004439228018592
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
CMakeLists.txt
package/org.tizen.NUIGadgetViewer-1.0.0.tpk [new file with mode: 0644]
packaging/amd.spec
src/lib/amd_res_info.cc
src/lib/res_info/res_info.cc
src/lib/res_info/res_info.hh

index 59be724a3ccb6b7123d7e18bde5b3a88545ae66a..0d123768fc88a93001ba1866740fe80810697aee 100644 (file)
@@ -89,3 +89,6 @@ PKG_CHECK_MODULES(WAYLAND_TBM_CLIENT_DEPS REQUIRED wayland-tbm-client)
 PKG_CHECK_MODULES(XKBCOMMON_DEPS REQUIRED xkbcommon)
 
 ADD_SUBDIRECTORY(src)
+
+INSTALL(FILES package/org.tizen.NUIGadgetViewer-1.0.0.tpk
+  DESTINATION /usr/apps/.preload-tpk)
diff --git a/package/org.tizen.NUIGadgetViewer-1.0.0.tpk b/package/org.tizen.NUIGadgetViewer-1.0.0.tpk
new file mode 100644 (file)
index 0000000..bc061a9
Binary files /dev/null and b/package/org.tizen.NUIGadgetViewer-1.0.0.tpk differ
index e2ae7d23ec7c81fc160cb16190fe5f415fbbad32..2a9276a6bafea91b17d8d98a65f0b7e59626a6af 100644 (file)
@@ -235,6 +235,7 @@ AMD gcov objects
 %endif
 
 %define _moddir %{_datadir}/amd
+%define _preload_tpk_dir %{TZ_SYS_RO_APP}/.preload-tpk
 
 %if "%{?_prelink_enable}" == "y"
 %define tizen_feature_prelink 1
@@ -338,6 +339,7 @@ systemctl daemon-reload
 %{_libdir}/libamd.so.*
 %{_moddir}/conf/amd.conf
 %{_sysconfdir}/resourced/vip-process.d/amd.conf
+%{_preload_tpk_dir}/org.tizen.NUIGadgetViewer-1.0.0.tpk
 
 %files devel
 %{_includedir}/amd/*.h*
index 99a055f92a4981093c03c6a6c70dd530b348f78c..1df2bc200d9aab86a36da75460fbed0997dd17f4 100644 (file)
@@ -26,6 +26,7 @@
 #include <string>
 #include <tuple>
 #include <unordered_map>
+#include <utility>
 #include <vector>
 
 #include "lib/amd_app_status.h"
@@ -330,8 +331,52 @@ int _resinfo_init(void) {
   return 0;
 }
 
+static int ResInfoGetGadgetResPackagesInfo(uid_t uid, GList** pkgids,
+  GList** allowed_paths, GList** global_paths) {
+  std::shared_ptr<amd::ResInfo> resinfo = amd::ResInfoManager::GetInst()
+      .GetUserResInfo(uid);
+  if (!resinfo)
+    return -1;
+
+  pkgmgrinfo_version_compare_type ver_comp;
+  std::unordered_map<std::string, std::shared_ptr<amd::ResPkgInfo>> gadget_map;
+  for (const auto& [_, res_pkginfo] : resinfo->GetGadgetResPkgs()) {
+    auto found = gadget_map.find(res_pkginfo->GetResType());
+    if (found != gadget_map.end()) {
+      if (pkgmgrinfo_compare_package_version(
+          found->second->GetResVersion().c_str(),
+          res_pkginfo->GetResVersion().c_str(),
+          &ver_comp) != PMINFO_R_OK)
+          continue;
+
+      if (ver_comp != PMINFO_VERSION_NEW)
+        continue;
+
+      gadget_map.erase(found);
+    }
+
+    gadget_map[res_pkginfo->GetResType()] = std::move(res_pkginfo);
+  }
+
+  for (const auto& [_, res_pkginfo] : gadget_map) {
+    *pkgids = g_list_append(*pkgids, strdup(res_pkginfo->GetPkgId().c_str()));
+    std::string allowed_path = res_pkginfo->GetRootPath() + "/res/allowed/";
+    *allowed_paths = g_list_append(*allowed_paths,
+        strdup(allowed_path.c_str()));
+    std::string global_path = res_pkginfo->GetRootPath() + "/res/global/";
+    *global_paths = g_list_append(*global_paths, strdup(global_path.c_str()));
+  }
+
+  return 0;
+}
+
 int _resinfo_get_res_packages_info(const char* appid, uid_t uid,
     GList** pkgids, GList** allowed_paths, GList** global_paths) {
+  if (!strcmp(appid, "org.tizen.NUIGadgetViewer")) {
+    return ResInfoGetGadgetResPackagesInfo(uid, pkgids, allowed_paths,
+        global_paths);
+  }
+
   std::shared_ptr<amd::ResInfo> resinfo = amd::ResInfoManager::GetInst()
       .GetUserResInfo(uid);
   if (!resinfo)
index 987814b3820dca70f16300e0f5df2e79b1d7a87b..112d2d6e89761e83ec9dcf07b3b3d1a6b1d07d20 100644 (file)
  * limitations under the License.
  */
 
+#include "lib/res_info/res_info.hh"
+
+#include <utility>
+
 #include "lib/common/log_private.hh"
 #include "lib/res_info/res_app_info.hh"
-#include "lib/res_info/res_info.hh"
 
 namespace amd {
+namespace {
+
+constexpr const char kResTypeGadget[] = "org.tizen.appfw.gadget.";
+
+}  // namespace
 
 std::shared_ptr<ResAppInfo> ResInfo::GetResAppInfo(const std::string& appid) {
   if (!res_appinfo_.count(appid))
@@ -42,6 +50,10 @@ void ResInfo::InsertPkgInfo(std::shared_ptr<ResPkgInfo> res_pkginfo) {
   res_pkginfo_[res_pkginfo->GetPkgId()] = std::move(res_pkginfo);
 }
 
+void ResInfo::InsertGadgetPkgInfo(std::shared_ptr<ResPkgInfo> res_pkginfo) {
+  gadget_pkginfo_[res_pkginfo->GetPkgId()] = std::move(res_pkginfo);
+}
+
 bool ResInfo::DeleteAppInfo(const std::string& appid) {
   if (!res_appinfo_.count(appid))
     return false;
@@ -56,6 +68,7 @@ bool ResInfo::DeletePkgInfo(const std::string& pkgid) {
     return false;
 
   res_pkginfo_.erase(pkgid);
+  gadget_pkginfo_.erase(pkgid);
 
   return true;
 }
@@ -65,6 +78,11 @@ const std::unordered_map<std::string, std::shared_ptr<ResPkgInfo>>&
   return res_pkginfo_;
 }
 
+const std::unordered_map<std::string, std::shared_ptr<ResPkgInfo>>&
+    ResInfo::GetGadgetResPkgs() {
+  return gadget_pkginfo_;
+}
+
 bool ResInfo::ResPkgInit() {
   pkgmgrinfo_pkginfo_filter_h filter;
 
@@ -92,8 +110,14 @@ bool ResInfo::ResPkgInit() {
         if (!res_pkg_info)
           return 0;
 
-        resinfo->InsertPkgInfo(std::move(res_pkg_info));
+        char* res_type = nullptr;
+        pkgmgrinfo_pkginfo_get_res_type(handle, &res_type);
+        if (res_type != nullptr &&
+            strlen(res_type) > strlen(kResTypeGadget) &&
+            !strncmp(res_type, kResTypeGadget, strlen(kResTypeGadget)))
+          resinfo->InsertGadgetPkgInfo(res_pkg_info);
 
+        resinfo->InsertPkgInfo(std::move(res_pkg_info));
         return 0;
       }, this, uid_) != PMINFO_R_OK) {
     _E("pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo() failed");
index 1bb2190f933f1f0536ba95a93352a7d6975ae6a0..b840d4220c1bd6bad7533adea319579564278566 100644 (file)
@@ -34,15 +34,19 @@ class ResInfo {
   bool ResPkgInit();
   void InsertAppInfo(std::shared_ptr<ResAppInfo> res_appinfo);
   void InsertPkgInfo(std::shared_ptr<ResPkgInfo> res_pkginfo);
+  void InsertGadgetPkgInfo(std::shared_ptr<ResPkgInfo> res_pkginfo);
   bool DeleteAppInfo(const std::string& appid);
   bool DeletePkgInfo(const std::string& pkgid);
   const std::unordered_map<std::string, std::shared_ptr<ResPkgInfo>>&
   GetResPkgs();
+  const std::unordered_map<std::string, std::shared_ptr<ResPkgInfo>>&
+  GetGadgetResPkgs();
 
  private:
   uid_t uid_;
   std::unordered_map<std::string, std::shared_ptr<ResPkgInfo>> res_pkginfo_;
   std::unordered_map<std::string, std::shared_ptr<ResAppInfo>> res_appinfo_;
+  std::unordered_map<std::string, std::shared_ptr<ResPkgInfo>> gadget_pkginfo_;
 };
 
 }  // namespace amd