Add denied list APIs 14/224214/3
authorJusung Son <jusung07.son@samsung.com>
Fri, 7 Feb 2020 05:39:50 +0000 (14:39 +0900)
committerJusung Son <jusung07.son@samsung.com>
Mon, 17 Feb 2020 09:17:03 +0000 (18:17 +0900)
Change-Id: I8d8218b4b159fd014714c78d13ab57a6dbec8d75
Signed-off-by: Jusung Son <jusung07.son@samsung.com>
unittest/src/test-watchface-complication.cc
watchface-complication/complication-implementation.h
watchface-complication/complication.cc
watchface-complication/complication.h
watchface-complication/include/watchface-complication-internal.h
watchface-complication/watchface-complication.cc

index 0eef6f9..fa68bf0 100644 (file)
@@ -136,12 +136,14 @@ class CWC : public ::testing::Test {
  public:
   complication_allowed_list_h allowed_list_;
   complication_h complication_;
+  complication_denied_list_h denied_list_;
   void RunLoop() {
     g_main_loop_run(loop_);
   }
   virtual void SetUp() {
     complication_ = nullptr;
     allowed_list_ = nullptr;
+    denied_list_ = nullptr;
     loop_ = g_main_loop_new(NULL, FALSE);
     system_info_get_platform_bool_fake.custom_fake = __fake_system_info_get_platform_bool;
 
@@ -168,6 +170,8 @@ class CWC : public ::testing::Test {
       watchface_complication_destroy(complication_);
     if (allowed_list_ != nullptr)
       watchface_complication_allowed_list_destroy(allowed_list_);
+    if (denied_list_!= nullptr)
+      watchface_complication_denied_list_destroy(denied_list_);
     if (event_timer__ != 0) {
       g_source_remove(event_timer__);
       event_timer__ = 0;
@@ -694,4 +698,43 @@ TEST_F(CWC, get_default_data)
   bundle_free(default_data);
 }
 
+TEST_F(CWC, watchface_complication_denied_list_apply)
+{
+  g_dbus_connection_signal_subscribe_fake.custom_fake =
+      __fake_signal_subscribe_on_data_updated;
+  int comp_id = 777;
+  int ret = watchface_complication_create(comp_id,
+    "org.tizen.gmock_comp_provider/test",
+    WATCHFACE_COMPLICATION_TYPE_SHORT_TEXT,
+    WATCHFACE_COMPLICATION_TYPE_SHORT_TEXT,
+    WATCHFACE_COMPLICATION_EVENT_TAP,
+    &complication_);
+  ret = watchface_complication_denied_list_create(&denied_list_);
+  EXPECT_EQ(WATCHFACE_COMPLICATION_ERROR_NONE, ret);
+  ret = watchface_complication_denied_list_add(denied_list_,
+      "org.tizen.gmock_comp_provider/test",
+      WATCHFACE_COMPLICATION_TYPE_SHORT_TEXT);
+  ret = watchface_complication_denied_list_add(denied_list_,
+      "org.tizen.gmock_comp_provider2/test",
+      WATCHFACE_COMPLICATION_TYPE_LONG_TEXT);
+  char* ret_provider_id;
+  int ret_type;
+  watchface_complication_denied_list_get_nth(denied_list_, 1,
+      &ret_provider_id, &ret_type);
+  EXPECT_STREQ(ret_provider_id, "org.tizen.gmock_comp_provider2/test");
+  free(ret_provider_id);
+
+  EXPECT_EQ(ret_type, WATCHFACE_COMPLICATION_TYPE_LONG_TEXT);
+
+  ret = watchface_complication_denied_list_apply(complication_,
+      denied_list_);
+  EXPECT_EQ(WATCHFACE_COMPLICATION_ERROR_NONE, ret);
+
+  ret = watchface_complication_denied_list_clear(complication_);
+  EXPECT_EQ(WATCHFACE_COMPLICATION_ERROR_NONE, ret);
+  ret = watchface_complication_denied_list_delete(denied_list_,
+      "org.tizen.gmock_comp_provider/test");
+  EXPECT_EQ(WATCHFACE_COMPLICATION_ERROR_NONE, ret);
+}
+
 }
index cf1ca59..d0c3cea 100644 (file)
@@ -104,6 +104,7 @@ class Complication::Impl : IGDBus::IGDBusEvent, IPackageManager::IPackageEvent {
   ComplicationType last_type_ = NoData;
   std::list<std::shared_ptr<tizen_base::Bundle>> candidates_list_;
   std::list<std::unique_ptr<ProviderInfo>> allowed_list_;
+  std::list<std::unique_ptr<ProviderInfo>> denied_list_;
   std::list<std::string> privilege_list_;
   int cur_data_idx_ = -1;
   std::unique_ptr<tizen_base::Bundle> context_data_;
index 8c5e0cd..124f416 100644 (file)
@@ -924,6 +924,17 @@ int Complication::Impl::GetNotSupportedEvents(
 }
 
 int Complication::Impl::AddCandidate(std::string provider_id, int type) {
+  if (denied_list_.size() != 0) {
+    for (auto& i : denied_list_) {
+      std::string denied_provider_id = i.get()->GetProviderId();
+      int denied_types = i.get()->GetTypes();
+      if (denied_provider_id.compare(provider_id) == 0 && (denied_types & type) != 0) {
+        LOGI("denied item : %s, %d)", provider_id.c_str(), type);
+        return WATCHFACE_COMPLICATION_ERROR_NONE;
+      }
+    }
+  }
+
   unique_ptr<Bundle> data;
   try {
     data = unique_ptr<Bundle>(new Bundle());
@@ -965,6 +976,7 @@ int Complication::Impl::AddCandidates(std::string provider_id, int types) {
   for (int type = ShortText; type <= Image; type *= 2) {
     if ((type & types) == 0)
       continue;
+
     int ret = AddCandidate(provider_id, type);
     if (ret != WATCHFACE_COMPLICATION_ERROR_NONE) {
       candidates_list_.clear();
@@ -1077,12 +1089,37 @@ int Complication::ApplyAllowedList(
   return ret;
 }
 
+int Complication::ApplyDeniedList(
+      std::list<std::unique_ptr<ProviderInfo>> denied_list) {
+  impl_->denied_list_ = std::move(denied_list);
+  impl_->candidates_list_.clear();
+  int ret = impl_->UpdateProviderInfo();
+
+  /*
+  * If current selected provider id is not included in candidate list,
+  * clear all selected provider info
+  */
+  if (ret == WATCHFACE_COMPLICATION_ERROR_NOT_EXIST) {
+    impl_->cur_data_idx_ = -1;
+    impl_->cur_provider_appid_ = "";
+    impl_->cur_provider_id_ = "";
+    return WATCHFACE_COMPLICATION_ERROR_NONE;
+  }
+  return ret;
+}
+
 int Complication::ClearAllowedList() {
   impl_->allowed_list_.clear();
   impl_->UpdateProviderInfo();
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
+int Complication::ClearDeniedList() {
+  impl_->denied_list_.clear();
+  impl_->UpdateProviderInfo();
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
 int Complication::GetDefaultData(
     string provider_id, int type, Bundle* default_data) {
   std::list<std::string> privlege_list =
index acfbc64..f1d1845 100644 (file)
@@ -102,7 +102,10 @@ class EXPORT_API Complication : public IEditable
   int TouchLaunch(watchface_complication_event_type_e event_type);
   int ApplyAllowedList(
       std::list<std::unique_ptr<ProviderInfo>> allowed_list);
+  int ApplyDeniedList(
+      std::list<std::unique_ptr<ProviderInfo>> denied_list);
   int ClearAllowedList();
+  int ClearDeniedList();
   int Init();
   void SetListeningStatus(watchface_complication_consumer_status_e state);
   void NotifyListeningStatus(watchface_complication_consumer_status_e state);
index a704d01..34a752f 100644 (file)
@@ -30,6 +30,23 @@ int watchface_complication_data_get_aod_icon_path(const bundle *shared_data,
 int watchface_complication_data_get_aod_image_path(const bundle *shared_data,
         char **image_path);
 
+typedef struct complication_denied_list_ *complication_denied_list_h;
+
+int watchface_complication_denied_list_create(
+        complication_denied_list_h *handle);
+int watchface_complication_denied_list_destroy(
+        complication_denied_list_h handle);
+int watchface_complication_denied_list_add(complication_denied_list_h handle,
+        const char *provider_id, int types);
+int watchface_complication_denied_list_delete(complication_denied_list_h handle,
+        const char *provider_id);
+int watchface_complication_denied_list_get_nth(
+        complication_denied_list_h handle, int index,
+        char **provider_id, int *types);
+int watchface_complication_denied_list_apply(complication_h handle,
+        complication_denied_list_h list_handle);
+int watchface_complication_denied_list_clear(complication_h handle);
+
 #ifdef __cplusplus
 }
 #endif
index e0bf784..f990011 100644 (file)
@@ -27,6 +27,7 @@
 #include <dlog.h>
 
 #include "watchface-complication/include/watchface-complication.h"
+#include "watchface-complication/include/watchface-complication-internal.h"
 #include "watchface-complication/complication-internal.h"
 #include "watchface-complication/complication.h"
 #include "watchface-complication/shared-handle.h"
@@ -43,6 +44,10 @@ struct complication_allowed_list_ {
   GList* allowed_list;
 };
 
+struct complication_denied_list_ {
+  GList* denied_list;
+};
+
 using namespace std;
 using namespace tizen_base;
 using namespace watchface_complication;
@@ -1053,3 +1058,184 @@ extern "C" EXPORT_API int watchface_complication_get_default_data(
   *default_data = bundle_dup(data.GetHandle());
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
+
+extern "C" EXPORT_API int watchface_complication_denied_list_create(
+    complication_denied_list_h* handle) {
+  complication_denied_list_h h = nullptr;
+
+  if (!watchface_complication::util::CheckWatchFeatureEnabled())
+    return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
+
+  if (handle == nullptr) {
+    LOGE("Invalid param");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  h = (complication_denied_list_h)calloc(1,
+      sizeof(struct complication_denied_list_));
+  if (h == nullptr) {
+    LOGE("Out of memory");
+    return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+  }
+
+  *handle = h;
+
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int watchface_complication_denied_list_destroy(
+    complication_denied_list_h handle) {
+  if (!watchface_complication::util::CheckWatchFeatureEnabled())
+    return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
+
+  if (handle == nullptr) {
+    LOGE("Invalid param");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  if (handle->denied_list)
+    g_list_free_full(handle->denied_list, __free_provider_info);
+  free(handle);
+
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int watchface_complication_denied_list_add(
+    complication_denied_list_h handle, const char* provider_id, int types) {
+  if (!watchface_complication::util::CheckWatchFeatureEnabled())
+    return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
+
+  if (handle == nullptr || provider_id == nullptr) {
+    LOGE("Invalid param");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  GList* find = g_list_find_custom(handle->denied_list, provider_id,
+      __provider_info_cmp);
+  if (find) {
+    LOGE("Provider id (%s) already exist", provider_id);
+    return WATCHFACE_COMPLICATION_ERROR_EXIST_ID;
+  }
+
+  provider_info* info = reinterpret_cast<provider_info*>(calloc(1,
+                            sizeof(provider_info)));
+  if (info == nullptr) {
+    LOGE("Out of memory");
+    return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+  }
+  info->provider_id = strdup(provider_id);
+  if (info->provider_id == nullptr) {
+    LOGE("Out of memory");
+    free(info);
+    return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+  }
+  info->types = types;
+  handle->denied_list = g_list_append(handle->denied_list, info);
+
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int watchface_complication_denied_list_delete(
+    complication_denied_list_h handle, const char* provider_id) {
+  if (!watchface_complication::util::CheckWatchFeatureEnabled())
+    return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
+
+  if (handle == nullptr || provider_id == nullptr || handle->denied_list == nullptr) {
+    LOGE("Invalid param");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  GList* find = g_list_find_custom(handle->denied_list,
+      provider_id, __provider_info_cmp);
+  if (!find) {
+    LOGE("Provider id (%s) already exist", provider_id);
+    return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
+  }
+
+  provider_info* data = reinterpret_cast<provider_info*>(find->data);
+  handle->denied_list = g_list_remove(handle->denied_list, find->data);
+  __free_provider_info(data);
+
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int watchface_complication_denied_list_get_nth(
+    complication_denied_list_h handle, int index, char** provider_id,
+    int* types) {
+  if (!watchface_complication::util::CheckWatchFeatureEnabled())
+    return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
+
+  if (handle == nullptr || provider_id == nullptr || types == nullptr ||
+      handle->denied_list == nullptr ||
+      index >= static_cast<int>(g_list_length(handle->denied_list)) ||
+      index < 0) {
+    LOGE("Invalid param");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+  provider_info* info =
+    reinterpret_cast<provider_info*>(g_list_nth_data(handle->denied_list,
+                    index));
+  if (info == nullptr || info->provider_id == nullptr) {
+    LOGE("fail to get provider id");
+    return WATCHFACE_COMPLICATION_ERROR_IO_ERROR;
+  }
+  char* id = strdup(info->provider_id);
+  if (id == nullptr) {
+    LOGE("Out of memory");
+    return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+  }
+  *provider_id = id;
+  *types = info->types;
+
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
+extern "C" EXPORT_API int watchface_complication_denied_list_apply(
+    complication_h handle, complication_denied_list_h list_handle) {
+  if (!watchface_complication::util::CheckWatchFeatureEnabled())
+    return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
+
+  if (handle == nullptr || list_handle == nullptr || list_handle->denied_list == nullptr
+      || g_list_length(list_handle->denied_list) == 0) {
+    LOGE("Invalid param");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  auto sh = static_cast<SharedHandle<WatchComplicationStub>*>(handle);
+  auto ptr = SharedHandle<WatchComplicationStub>::Share(sh);
+  std::list<std::unique_ptr<Complication::ProviderInfo>> denied_list;
+
+  for (unsigned int i = 0; i < g_list_length(list_handle->denied_list); i++) {
+    provider_info* info =
+      reinterpret_cast<provider_info*>(g_list_nth_data(
+                    list_handle->denied_list, i));
+    if (info == nullptr || info->provider_id == nullptr)
+      continue;
+    try {
+      denied_list.emplace_back(std::unique_ptr<Complication::ProviderInfo>(
+        new Complication::ProviderInfo(
+          std::string(info->provider_id), info->types)));
+    } catch(const std::bad_alloc &ba) {
+      LOGE("ProviderInfo::Exception bad_alloc");
+      return WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY;
+    }
+  }
+
+  return  ptr.get()->ApplyDeniedList(std::move(denied_list));
+}
+
+extern "C" EXPORT_API int watchface_complication_denied_list_clear(
+    complication_h handle) {
+  if (!watchface_complication::util::CheckWatchFeatureEnabled())
+    return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
+
+  if (handle == nullptr) {
+    LOGE("Invalid param");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+  auto sh = static_cast<SharedHandle<WatchComplicationStub>*>(handle);
+  auto ptr = SharedHandle<WatchComplicationStub>::Share(sh);
+
+  return ptr.get()->ClearDeniedList();
+}
+