[Common] Get package, application ID from GetRuntimeVariable 05/282305/4
authorDongHyun Song <dh81.song@samsung.com>
Tue, 27 Sep 2022 05:42:27 +0000 (14:42 +0900)
committerPiotr Kosko/Tizen API (PLT) /SRPOL/Engineer/Samsung Electronics <p.kosko@samsung.com>
Tue, 4 Apr 2023 10:07:56 +0000 (12:07 +0200)
[Verification] Code compiles without errors

Change-Id: Id3f9d8ca1db07c3615a7741a8445209171425ac6
Signed-off-by: DongHyun Song <dh81.song@samsung.com>
src/common/current_application.cc
src/common/extension.cc
src/common/extension.h

index eaa85be..e99e6b8 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 4c444fe..cf5edec 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 6c5d916..942ea55 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);