From 8fbe0775c6055fa253d084cae43059bffd4964eb Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Thu, 17 Mar 2022 12:34:54 +0900 Subject: [PATCH] Add parameters for offline mode Callback registration for language change is unnecessary if code operates as offline mode. Change-Id: I89067c8305a81c8ffc3b0bf67f7bb10789051767 Signed-off-by: Junghyun Yeon --- src/client/pkginfo_client.cc | 2 +- src/common/system_locale.cc | 13 ++++++++----- src/common/system_locale.hh | 5 +++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/client/pkginfo_client.cc b/src/client/pkginfo_client.cc index 4d179f9..43ad8ff 100644 --- a/src/client/pkginfo_client.cc +++ b/src/client/pkginfo_client.cc @@ -151,7 +151,7 @@ bool PkgInfoClient::RequestHandlerDirectAccess() { result_parcel_.reset( reinterpret_cast( dl_func(req_type_, &raw[0], raw.size(), - pkgmgr_common::SystemLocale::GetInst().Get().c_str()))); + pkgmgr_common::SystemLocale::GetInst(false).Get().c_str()))); return true; } diff --git a/src/common/system_locale.cc b/src/common/system_locale.cc index 06c4442..449a716 100644 --- a/src/common/system_locale.cc +++ b/src/common/system_locale.cc @@ -12,14 +12,16 @@ constexpr const char DEFAULT_LOCALE[] = "No Locale"; namespace pkgmgr_common { -SystemLocale& SystemLocale::GetInst() { - static SystemLocale inst; +SystemLocale& SystemLocale::GetInst(bool is_online) { + static SystemLocale inst(is_online); return inst; } -SystemLocale::SystemLocale() { - vconf_notify_key_changed(VCONFKEY_LANGSET, LanChangedCb, this); +SystemLocale::SystemLocale(bool is_online) : is_online_(is_online) { + if (is_online_) + vconf_notify_key_changed(VCONFKEY_LANGSET, LanChangedCb, this); + char* lang = vconf_get_str(VCONFKEY_LANGSET); lang_ = lang ? std::string(lang) : ""; free(lang); @@ -27,7 +29,8 @@ SystemLocale::SystemLocale() { } SystemLocale::~SystemLocale() { - vconf_ignore_key_changed(VCONFKEY_LANGSET, LanChangedCb); + if (is_online_) + vconf_ignore_key_changed(VCONFKEY_LANGSET, LanChangedCb); } void SystemLocale::RegisterEvent(IEvent* listener) { diff --git a/src/common/system_locale.hh b/src/common/system_locale.hh index 76a02b8..d7416b9 100644 --- a/src/common/system_locale.hh +++ b/src/common/system_locale.hh @@ -23,7 +23,7 @@ class EXPORT_API SystemLocale { virtual void OnChanged(const std::string& locale) = 0; }; - static SystemLocale& GetInst(); + static SystemLocale& GetInst(bool is_online = true); const std::string& Get() const; void RegisterEvent(IEvent* listener); void UnRegisterEvent(); @@ -31,9 +31,10 @@ class EXPORT_API SystemLocale { private: std::string lang_; std::string locale_; + bool is_online_; IEvent* listener_ = nullptr; - SystemLocale(); + SystemLocale(bool is_online); ~SystemLocale(); void SetLocale(); static void LanChangedCb(keynode_t* node, void* user_data); -- 2.7.4