From: DongHyun Song Date: Tue, 27 Sep 2022 05:42:27 +0000 (+0900) Subject: [Common] Get package, application ID from GetRuntimeVariable X-Git-Tag: accepted/tizen/7.0/unified/20240509.012454~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7acf6977effcfcf0fbfc9eba755e4b54a9f28992;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Common] Get package, application ID from GetRuntimeVariable [Verification] Code compiles without errors Change-Id: Id3f9d8ca1db07c3615a7741a8445209171425ac6 Signed-off-by: DongHyun Song (cherry picked from commit 98eac70955c377a91ecc69a1f1948c9e0dd6fa08) --- diff --git a/src/common/current_application.cc b/src/common/current_application.cc index eaa85be9..e99e6b89 100644 --- a/src/common/current_application.cc +++ b/src/common/current_application.cc @@ -21,12 +21,21 @@ #include #include +#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() diff --git a/src/common/extension.cc b/src/common/extension.cc index 4c444fee..cf5edeca 100644 --- a/src/common/extension.cc +++ b/src/common/extension.cc @@ -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 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 ""; diff --git a/src/common/extension.h b/src/common/extension.h index 6c5d9166..942ea556 100644 --- a/src/common/extension.h +++ b/src/common/extension.h @@ -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);