Enable set null for nullable attribute 91/217491/9
authorhyunho <hhstark.kang@samsung.com>
Tue, 12 Nov 2019 05:54:13 +0000 (14:54 +0900)
committerJusung Son <jusung07.son@samsung.com>
Fri, 29 Nov 2019 00:27:43 +0000 (09:27 +0900)
There is no way to set null for nullable attribute.

Change-Id: I3783423971aaaf4ccad3e53988e3e368063d711c
Signed-off-by: hyunho <hhstark.kang@samsung.com>
Signed-off-by: Jusung Son <jusung07.son@samsung.com>
Signed-off-by: hyunho <hhstark.kang@samsung.com>
Signed-off-by: Jusung Son <jusung07.son@samsung.com>
notification-ex/group_item.cc
notification-ex/stub.cc

index 965e6c8..3407938 100644 (file)
@@ -23,6 +23,7 @@
 #include "notification-ex/group_item.h"
 #include "notification-ex/group_item_implementation.h"
 #include "notification-ex/factory_manager.h"
+#include "notification-ex/ex_util.h"
 #include "notification-ex/exception.h"
 
 #ifdef LOG_TAG
@@ -53,6 +54,12 @@ GroupItem::GroupItem(shared_ptr<AbstractAction> action)
 GroupItem::Impl::Impl(GroupItem* parent)
     : parent_(parent) {
   LOGI("GroupItem created");
+  char* name;
+  int ret = app_get_name(&name);
+  if (ret != APP_ERROR_NONE)
+    app_label_ = util::GetAppId();
+  else
+    app_label_ = string(name);
 }
 
 GroupItem::~GroupItem() {
@@ -67,9 +74,8 @@ Bundle GroupItem::Serialize() const {
   b = AbstractItem::Serialize();
   b.Add(GROUP_DIRECTION_KEY, impl_->is_vertical_ ?
       GROUP_DIRECTION_VERTICAL : GROUP_DIRECTION_HORIZONTAL);
-  if (!impl_->app_label_.empty())
-    b.Add(GROUP_APP_LABEL_KEY, impl_->app_label_);
 
+  b.Add(GROUP_APP_LABEL_KEY, impl_->app_label_);
   if (impl_->children_list_.size() == 0)
     return b;
 
@@ -211,14 +217,6 @@ bool GroupItem::IsVertical() {
 }
 
 string GroupItem::GetAppLabel() {
-  if (impl_->app_label_.empty()) {
-    char* name;
-    int ret = app_get_name(&name);
-    if (ret != APP_ERROR_NONE)
-      THROW(ERROR_IO_ERROR);
-    impl_->app_label_ = string(name);
-    free(name);
-  }
   return impl_->app_label_;
 }
 
index 74d1a84..14dab89 100644 (file)
 #include <sstream>
 #include <iomanip>
 
-#include "api/notification_ex_app_control_action.h"
-#include "api/notification_ex_button.h"
-#include "api/notification_ex_chat_message.h"
-#include "api/notification_ex_checkbox.h"
-#include "api/notification_ex_entry.h"
-#include "api/notification_ex_event_info.h"
-#include "api/notification_ex_group.h"
-#include "api/notification_ex_image.h"
-#include "api/notification_ex_input_selector.h"
-#include "api/notification_ex_item.h"
-#include "api/notification_ex_manager.h"
-#include "api/notification_ex_progress.h"
-#include "api/notification_ex_reporter.h"
-#include "api/notification_ex_text.h"
-#include "api/notification_ex_time.h"
-#include "api/notification_ex_visibility_action.h"
-#include "api/notification_ex_visibility_action.h"
+#include "api/notification_ex.h"
 #include "api/notification_ex_internal.h"
 #include "notification-ex/reporter.h"
 #include "notification-ex/app_control_action.h"
@@ -1039,6 +1023,8 @@ extern "C" EXPORT_API int noti_ex_item_image_get_image_path(
       LOGE("Out-of-memory");
       return NOTI_EX_ERROR_OUT_OF_MEMORY;
     }
+  } else {
+    *image_path = nullptr;
   }
 
   return NOTI_EX_ERROR_NONE;
@@ -1470,7 +1456,8 @@ extern "C" EXPORT_API int noti_ex_style_get_padding(noti_ex_style_h handle,
       new (std::nothrow) Padding(*((*p)->GetPadding())));
   if (padd == nullptr || padd->get() == nullptr) {
     LOGE("Out-of-memory");
-    return NOTI_EX_ERROR_OUT_OF_MEMORY;
+    *padding = nullptr;
+    return NOTI_EX_ERROR_NONE;
   }
 
   *padding = padd;
@@ -1508,7 +1495,8 @@ extern "C" EXPORT_API int noti_ex_style_get_color(noti_ex_style_h handle,
   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
   if ((*p)->GetColor() == nullptr) {
     LOGW("Color info is null");
-    return NOTI_EX_ERROR_INVALID_PARAMETER;
+    *color = nullptr;
+    return NOTI_EX_ERROR_NONE;
   }
 
   shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
@@ -1552,7 +1540,8 @@ extern "C" EXPORT_API int noti_ex_style_get_geometry(noti_ex_style_h handle,
   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
   if ((*p)->GetGeometry() == nullptr) {
     LOGW("Geometry info is null");
-    return NOTI_EX_ERROR_INVALID_PARAMETER;
+    *geometry = nullptr;
+    return NOTI_EX_ERROR_NONE;
   }
 
   shared_ptr<Geometry>* geo = new (std::nothrow) shared_ptr<Geometry>(
@@ -1594,20 +1583,27 @@ extern "C" EXPORT_API int noti_ex_style_get_background_image(
   }
 
   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
-  *background_image = strdup((*p)->GetBackgroundImage().c_str());
+
+  if ((*p)->GetBackgroundImage().empty())
+    *background_image = nullptr;
+  else
+    *background_image = strdup((*p)->GetBackgroundImage().c_str());
 
   return NOTI_EX_ERROR_NONE;
 }
 
 extern "C" EXPORT_API int noti_ex_style_set_background_image(
     noti_ex_style_h handle, char* background_image) {
-  if (handle == nullptr || background_image == nullptr) {
+  if (handle == nullptr) {
     LOGE("Invalid parameter");
     return NOTI_EX_ERROR_INVALID_PARAMETER;
   }
 
   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
-  (*p)->SetBackgroundImage(background_image);
+  if (background_image == nullptr)
+    (*p)->SetBackgroundImage("");
+  else
+    (*p)->SetBackgroundImage(background_image);
 
   return NOTI_EX_ERROR_NONE;
 }
@@ -1622,7 +1618,8 @@ extern "C" EXPORT_API int noti_ex_style_get_background_color(
   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
   if ((*p)->GetBackgroundColor() == nullptr) {
     LOGW("Color info is null");
-    return NOTI_EX_ERROR_INVALID_PARAMETER;
+    *color = nullptr;
+    return NOTI_EX_ERROR_NONE;
   }
 
   shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
@@ -1639,12 +1636,17 @@ extern "C" EXPORT_API int noti_ex_style_get_background_color(
 
 extern "C" EXPORT_API int noti_ex_style_set_background_color(
     noti_ex_style_h handle, noti_ex_color_h color) {
-  if (handle == nullptr || color == nullptr) {
+  if (handle == nullptr) {
     LOGE("Invalid parameter");
     return NOTI_EX_ERROR_INVALID_PARAMETER;
   }
 
   shared_ptr<Style>* p = static_cast<shared_ptr<Style>*>(handle);
+  if (color == nullptr) {
+    (*p)->SetBackgroundColor(nullptr);
+    return NOTI_EX_ERROR_NONE;
+  }
+
   shared_ptr<Color>* col = static_cast<shared_ptr<Color>*>(color);
   (*p)->SetBackgroundColor(*col);
 
@@ -1749,8 +1751,9 @@ extern "C" EXPORT_API int noti_ex_led_info_get_color(
   shared_ptr<LEDInfo>* led_ptr =
       reinterpret_cast<shared_ptr<LEDInfo>*>(handle);
   if ((*led_ptr)->GetColor() == nullptr) {
-    LOGE("Color is null");
-    return NOTI_EX_ERROR_INVALID_PARAMETER;
+    LOGW("Color is null");
+    *color = nullptr;
+    return NOTI_EX_ERROR_NONE;
   }
 
   shared_ptr<Color>* col = new (std::nothrow) shared_ptr<Color>(
@@ -1854,6 +1857,8 @@ extern "C" EXPORT_API int noti_ex_action_get_extra(noti_ex_action_h handle,
       LOGE("Out-of-memory");
       return NOTI_EX_ERROR_OUT_OF_MEMORY;
     }
+  } else {
+    *extra = nullptr;
   }
 
   return NOTI_EX_ERROR_NONE;
@@ -2030,12 +2035,16 @@ extern "C" EXPORT_API int noti_ex_item_get_action(noti_ex_item_h handle,
 
 extern "C" EXPORT_API int noti_ex_item_set_action(noti_ex_item_h handle,
     noti_ex_action_h action) {
-  if (handle == nullptr || action == nullptr) {
+  if (handle == nullptr) {
     LOGE("Invalid parameter");
     return NOTI_EX_ERROR_INVALID_PARAMETER;
   }
 
   Handle* p = static_cast<Handle*>(handle);
+  if (action == nullptr) {
+    p->Get()->SetAction(nullptr);
+    return NOTI_EX_ERROR_NONE;
+  }
 
   shared_ptr<AbstractAction>* ptr =
       static_cast<shared_ptr<AbstractAction>*>(action);
@@ -2052,7 +2061,7 @@ extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
 
   Handle* p = static_cast<Handle*>(handle);
   shared_ptr<Style> s = p->Get()->GetStyle();
-  if (s == nullptr || s.get() == nullptr) {
+  if (s.get() == nullptr) {
     LOGW("Style is null");
     *style = nullptr;
     return NOTI_EX_ERROR_NONE;
@@ -2070,12 +2079,17 @@ extern "C" EXPORT_API int noti_ex_item_get_style(noti_ex_item_h handle,
 
 extern "C" EXPORT_API int noti_ex_item_set_style(noti_ex_item_h handle,
     noti_ex_style_h style) {
-  if (handle == nullptr || style == nullptr) {
+  if (handle == nullptr) {
     LOGE("Invalid parameter");
     return NOTI_EX_ERROR_INVALID_PARAMETER;
   }
 
   Handle* p = static_cast<Handle*>(handle);
+  if (style == nullptr) {
+    p->Get()->SetStyle(nullptr);
+    return NOTI_EX_ERROR_NONE;
+  }
+
   shared_ptr<Style>* s = static_cast<shared_ptr<Style>*>(style);
   p->Get()->SetStyle(*s);
   return NOTI_EX_ERROR_NONE;
@@ -2162,6 +2176,12 @@ extern "C" EXPORT_API int noti_ex_item_get_receiver_list(noti_ex_item_h handle,
 
   Handle* p = static_cast<Handle*>(handle);
   list<string> receivers = p->Get()->GetReceiverList();
+  if (receivers.size() == 0) {
+    *receiver_list = nullptr;
+    *count = 0;
+    return NOTI_EX_ERROR_NONE;
+  }
+
   char **tmp_list = (char**)calloc(receivers.size(), sizeof(char*));
   if (tmp_list == nullptr) {
     LOGE("Out of memory");
@@ -2245,8 +2265,8 @@ extern "C" EXPORT_API int noti_ex_item_set_led_info(noti_ex_item_h handle,
 
   Handle* p = static_cast<Handle*>(handle);
   if (led == nullptr) {
-     p->Get()->SetLEDInfo(nullptr);
-     return NOTI_EX_ERROR_NONE;
+    p->Get()->SetLEDInfo(nullptr);
+    return NOTI_EX_ERROR_NONE;
   }
   shared_ptr<LEDInfo>* led_ptr =
       reinterpret_cast<shared_ptr<LEDInfo>*>(led);
@@ -3129,6 +3149,8 @@ extern "C" EXPORT_API int noti_ex_item_text_get_hyperlink(
       LOGE("Out-of-memory");
       return NOTI_EX_ERROR_OUT_OF_MEMORY;
     }
+  } else {
+    *hyper_link = nullptr;
   }
 
   return NOTI_EX_ERROR_NONE;