[Common] Get package, application ID from GetRuntimeVariable 23/295523/1
authorDongHyun Song <dh81.song@samsung.com>
Tue, 27 Sep 2022 05:42:27 +0000 (14:42 +0900)
committerPiotr Kosko <p.kosko@samsung.com>
Mon, 10 Jul 2023 08:23:18 +0000 (08:23 +0000)
[Verification] Code compiles without errors

Change-Id: Id3f9d8ca1db07c3615a7741a8445209171425ac6
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
(cherry picked from commit 98eac70955c377a91ecc69a1f1948c9e0dd6fa08)

src/common/current_application.cc
src/common/extension.cc
src/common/extension.h

index eaa85be9ceccb0e54c66be042b451d8556b84558..e99e6b8945b645e522a72fdf2838371a417e96bb 100644 (file)
 #include <package_manager.h>
 #include <unistd.h>
 
+#include "common/extension.h"
 #include "common/logger.h"
 #include "common/scope_exit.h"
 
 namespace common {
 
-CurrentApplication& CurrentApplication::GetInstance() {
+namespace {
+
+std::string GetRuntimeVariable(const char* variable_name) {
+  return common::Extension::GetRuntimeVariableString(variable_name);
+}
+
+}  // namespace
+
+CurrentApplication &CurrentApplication::GetInstance() {
   ScopeLogger();
   static CurrentApplication current_application;
   return current_application;
@@ -39,17 +48,23 @@ pid_t CurrentApplication::GetProcessId() const {
 
 std::string CurrentApplication::GetApplicationId() const {
   ScopeLogger();
-  return app_id_;
+  auto app_id = GetRuntimeVariable("application_id");
+  LoggerI("GetRuntimeVariable: cached application_id: %s, runtime application_id: %s", app_id_.c_str(), app_id.c_str());
+  return app_id.empty() ? app_id_ : app_id;
 }
 
 std::string CurrentApplication::GetPackageId() const {
   ScopeLogger();
-  return package_id_;
+  auto pkg_id = GetRuntimeVariable("package_id");
+  LoggerI("GetRuntimeVariable: cached package_id: %s, runtime package_id: %s", package_id_.c_str(), pkg_id.c_str());
+  return pkg_id.empty() ? package_id_ : pkg_id;
 }
 
 std::string CurrentApplication::GetRoot() const {
   ScopeLogger();
-  return root_;
+  auto app_root = GetRuntimeVariable("app_root");
+  LoggerI("GetRuntimeVariable: cached app_root: %s, runtime app_root: %s", root_.c_str(), app_root.c_str());
+  return app_root.empty() ? root_ : app_root;
 }
 
 CurrentApplication::CurrentApplication()
index 4c444fee0f2329935d2e37c41a50051acc054e70..cf5edecaf9ee628c8eedad81ee7d2a177c641f9f 100644 (file)
@@ -134,6 +134,18 @@ Instance* Extension::CreateInstance() {
   return NULL;
 }
 
+// static
+std::string Extension::GetRuntimeVariableString(const char* var_name) {
+  ScopeLogger();
+  if (!g_runtime) return "";
+
+  const int result_len = 1024;
+  std::vector<char> res(result_len + 1, 0);
+  g_runtime->GetRuntimeVariableString(0, var_name, &res[0], result_len);
+  LoggerI("GetRuntimeVariable: result %s: \"%s\"", var_name, &res[0]);
+  return std::string(res.data());
+}
+
 std::string Extension::GetRuntimeVariable(const char* var_name, unsigned len) {
   ScopeLogger();
   if (!g_runtime) return "";
index 6c5d91664f57ed668a8630474ce744c94184d9a8..942ea556fb276c211136853835099c33ccfeb643 100644 (file)
@@ -69,7 +69,8 @@ class Extension {
 
   virtual Instance* CreateInstance();
 
-  std::string GetRuntimeVariable(const char* var_name, unsigned len);
+  std::string GetRuntimeVariable(const char* var_name, unsigned len = 512);
+  static std::string GetRuntimeVariableString(const char* var_name);
 
  private:
   friend int32_t(::XW_Initialize)(XW_Extension extension, XW_GetInterface get_interface);