Check the bundle is valid before create ThemeInfo object 63/237563/1
authorSangyoon Jang <jeremy.jang@samsung.com>
Wed, 1 Jul 2020 08:55:35 +0000 (17:55 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Wed, 1 Jul 2020 08:55:35 +0000 (17:55 +0900)
Change-Id: I5297ba0a4102496d5a881af34169bc46a512c4a0
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/theme/loader/theme_info_loader.cc
src/theme_provider/theme_info_proxy.cc

index c3bfb47da5c6f01704183f1aa6a8fb8a245bae0f..4b837836a2f5a47d52d985004cccfc7a4ace0d71 100644 (file)
@@ -110,6 +110,10 @@ std::shared_ptr<ThemeInfo> ThemeInfoLoader::LoadCurrent() {
     dbus::RequestBroker::GetInst().SendData(dbus::Command::GET, b);
   std::string str = reply.GetString(dbus::kCmdDataKey);
   tizen_base::Bundle serialized(str);
+  if (serialized.IsEmpty()) {
+    LOG(ERROR) << "Failed to load current theme info";
+    return nullptr;
+  }
 
   cache_ = std::make_shared<ThemeInfo>(serialized);
 
@@ -126,6 +130,10 @@ std::shared_ptr<ThemeInfo> ThemeInfoLoader::Load(const std::string& id) const {
   tizen_base::Bundle reply =
     dbus::RequestBroker::GetInst().SendData(dbus::Command::GET, b);
   tizen_base::Bundle serialized(reply.GetString(dbus::kCmdDataKey));
+  if (serialized.IsEmpty()) {
+    LOG(ERROR) << "Failed to load theme info of id: " << id;
+    return nullptr;
+  }
 
   std::shared_ptr<ThemeInfo> info =
       std::make_shared<ThemeInfo>(serialized);
index 5b2dd2df687e64d224eeecc6426d8fbddf903c20..cdd5fc9124fe09f9faee2596d30a77cfb7a46990 100644 (file)
@@ -43,11 +43,13 @@ std::shared_ptr<loader::ThemeInfo> ThemeInfoProxy::GetLoadedTheme() {
   if (cur_theme_)
     return cur_theme_;
 
-  cur_theme_ =
-      std::make_shared<loader::ThemeInfo>(db_manager_->SelectCurrent());
-  if (!cur_theme_)
+  tizen_base::Bundle cur_b = db_manager_->SelectCurrent();
+  if (cur_b.IsEmpty()) {
     LOG(WARNING) << "Cannot load current theme";
+    return nullptr;
+  }
 
+  cur_theme_ = std::make_shared<loader::ThemeInfo>(cur_b);
   return cur_theme_;
 }
 
@@ -55,11 +57,12 @@ std::shared_ptr<loader::ThemeInfo> ThemeInfoProxy::GetDefaultTheme() {
   if (default_theme_)
     return default_theme_;
 
-  default_theme_ =
-      std::make_shared<loader::ThemeInfo>(db_manager_->SelectDefault());
-  if (!default_theme_)
+  tizen_base::Bundle default_b = db_manager_->SelectDefault();
+  if (default_b.IsEmpty()) {
     LOG(WARNING) << "Cannot load default theme";
-
+    return nullptr;
+  }
+  default_theme_ = std::make_shared<loader::ThemeInfo>(default_b);
   return default_theme_;
 }
 
@@ -72,7 +75,13 @@ bool ThemeInfoProxy::SetCurrentTheme(const std::string& id) {
 }
 
 void ThemeInfoProxy::OnThemePackageChanged(const std::string& id) {
-  cur_theme_ = std::make_shared<loader::ThemeInfo>(db_manager_->Select(id));
+  tizen_base::Bundle cur_b = db_manager_->Select(id);
+  if (cur_b.IsEmpty()) {
+    LOG(ERROR) << "Failed to get changed current theme info";
+    // just keep previous cur theme info
+    return;
+  }
+  cur_theme_ = std::make_shared<loader::ThemeInfo>(cur_b);
 }
 
 }  // namespace provider