Add parameters for offline mode 51/272451/1
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 17 Mar 2022 03:34:54 +0000 (12:34 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 17 Mar 2022 03:34:54 +0000 (12:34 +0900)
Callback registration for language change is unnecessary
if code operates as offline mode.

Change-Id: I89067c8305a81c8ffc3b0bf67f7bb10789051767
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/client/pkginfo_client.cc
src/common/system_locale.cc
src/common/system_locale.hh

index 4d179f974bfc88833f0c07e5faec1b1526f8d4eb..43ad8ff94ede546c40d09f5b9f4d86a826b64a49 100644 (file)
@@ -151,7 +151,7 @@ bool PkgInfoClient::RequestHandlerDirectAccess() {
   result_parcel_.reset(
       reinterpret_cast<pkgmgr_common::parcel::AbstractParcelable *>(
           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;
 }
index 06c44422db02ed498b2f3dec5b7d01762d2b2fa8..449a7165848898f182aa8b4463ee827b076eeccd 100644 (file)
@@ -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) {
index 76a02b85aff3925cd989988e7add536049d6ae93..d7416b956dbb2a08a0c3b26b263ea4c41c043c4a 100644 (file)
@@ -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);