Add get default data API 36/221936/9
authorhyunho <hhstark.kang@samsung.com>
Wed, 8 Jan 2020 09:39:11 +0000 (18:39 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Mon, 20 Jan 2020 08:05:51 +0000 (08:05 +0000)
Change-Id: I3325bbe1a97afec1580cd3b51f9c49f125d79afe
Signed-off-by: hyunho <hhstark.kang@samsung.com>
15 files changed:
parser/complication_parser_plugin.cc
unittest/src/test-main.cc
unittest/src/test-watchface-complication.cc
watchface-complication-provider/complication-provider-event-interface.h
watchface-complication-provider/watchface-complication-provider.cc
watchface-complication/CMakeLists.txt
watchface-complication/complication-connector.h
watchface-complication/complication-event-interface.h
watchface-complication/complication-internal.h [new file with mode: 0644]
watchface-complication/complication.cc
watchface-complication/complication.h
watchface-complication/db-manager.cc
watchface-complication/editables-container.cc
watchface-complication/include/watchface-complication-internal.h
watchface-complication/watchface-complication.cc

index 5e7fea717500526c58925044d2ce1d59107f4941..e109977593167cd9a30f103d1cb2d26fa1717700 100644 (file)
@@ -33,7 +33,7 @@
 #include <memory>
 #include <list>
 
-#include "watchface-complication/include/watchface-complication-internal.h"
+#include "watchface-complication/complication-internal.h"
 #include "watchface-complication/include/watchface-complication.h"
 #include "watchface-common/watchface-util.h"
 #include "watchface-common/watchface-common-internal.h"
index d4aedfaf21365f69e46249926da166fe3f57df4b..424128a28ac978d47efff0ff17a3db1e2c10e6ad 100644 (file)
@@ -46,6 +46,7 @@ void UpdateDB() {
   }
 
   bundle* default_data = bundle_create();
+  bundle_add_str(default_data, "TEST_KEY", "TEST_DATA");
   bundle_raw* raw = nullptr;
   int len = 0;
   ret = bundle_encode(default_data, &raw, &len);
index 4839ac85543fb1fa39906182dab8a9a2cdf06b86..923f6727e5f8eb1b85c06c3135d74de6adcf2ab2 100644 (file)
@@ -17,6 +17,7 @@
 #include <gtest/gtest.h>
 #include <gmock/gmock.h>
 #include <watchface-complication.h>
+#include <watchface-complication-internal.h>
 #include <watchface-complication-provider.h>
 
 #include "watchface-complication/complication.h"
@@ -665,4 +666,25 @@ TEST_F(CWC, apply_not_exist_allowed_list)
   EXPECT_EQ(WATCHFACE_COMPLICATION_ERROR_PROVIDER_NOT_AVAILABLE, ret);
 }
 
+TEST_F(CWC, get_default_data)
+{
+  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_);
+  bundle *default_data;
+  ret = watchface_complication_get_default_data(
+      "org.tizen.gmock_comp_provider/test",
+      WATCHFACE_COMPLICATION_TYPE_SHORT_TEXT, &default_data);
+  EXPECT_EQ(WATCHFACE_COMPLICATION_ERROR_NONE, ret);
+
+  char *text;
+  bundle_get_str(default_data, "TEST_KEY", &text);
+  EXPECT_STREQ(text, "TEST_DATA");
+  bundle_free(default_data);
+}
+
 }
index 310b4702e2bb484787ce5d751b900bd4800b1ba1..62479afe519e011e51089b1d7b15de234ec37ed5 100644 (file)
@@ -21,7 +21,7 @@
 
 #include <string>
 
-#include "watchface-complication/include/watchface-complication-internal.h"
+#include "watchface-complication/complication-internal.h"
 
 namespace watchface_complication {
 
index 0e98ebbaed870dfc4a05b07fe06a92524dd5bf04..8f94781c5906eb9fd673f4fa4357a84c16534872 100644 (file)
@@ -34,7 +34,7 @@
 #include "watchface-complication-provider/complication-provider.h"
 #include "watchface-complication-provider/include/watchface-complication-provider.h"
 #include "watchface-complication/db-manager.h"
-#include "watchface-complication/include/watchface-complication-internal.h"
+#include "watchface-complication/complication-internal.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
index 15e16031c7dbc667a2bdb8cb3143138636b983ff..ca0a2f2dbc8271f67622f8932b6cc4925005d56d 100644 (file)
@@ -55,4 +55,6 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_I
 
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/watchface-editable-internal.h DESTINATION include/${PROJECT_NAME})
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/watchface-editable.h DESTINATION include/${PROJECT_NAME})
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/watchface-complication.h DESTINATION include/${PROJECT_NAME})
\ No newline at end of file
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/watchface-complication.h DESTINATION include/${PROJECT_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/watchface-complication-internal.h DESTINATION include/${PROJECT_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/complication-internal.h DESTINATION include/${PROJECT_NAME})
\ No newline at end of file
index 9716ff0303da012c06409752b928add5228b6dde..f3f2f6384e0682071c751c90aa595f3b6b0cf180 100644 (file)
@@ -21,7 +21,7 @@
 #include <string>
 #include <memory>
 
-#include "watchface-complication/include/watchface-complication-internal.h"
+#include "watchface-complication/complication-internal.h"
 #include "watchface-common/watchface-exception.h"
 #include "watchface-complication/gdbus-interface.h"
 #include "watchface-complication/package-manager-interface.h"
index 4a4d7e55761f109698e271467c583ed17c0439e2..68b0549544eca379c8725bb381bff1a01d6743a3 100644 (file)
@@ -21,7 +21,7 @@
 
 #include <string>
 
-#include "watchface-complication/include/watchface-complication-internal.h"
+#include "watchface-complication/complication-internal.h"
 
 namespace watchface_complication {
 
diff --git a/watchface-complication/complication-internal.h b/watchface-complication/complication-internal.h
new file mode 100644 (file)
index 0000000..1f07b02
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_APPFW_COMPLICATION_INTERNAL_H__
+#define __TIZEN_APPFW_COMPLICATION_INTERNAL_H__
+
+#include <watchface-common.h>
+
+namespace watchface_complication {
+
+typedef enum {
+  NoData = WATCHFACE_COMPLICATION_TYPE_NO_DATA,
+  ShortText = WATCHFACE_COMPLICATION_TYPE_SHORT_TEXT,
+  LongText = WATCHFACE_COMPLICATION_TYPE_LONG_TEXT,
+  RangedValue = WATCHFACE_COMPLICATION_TYPE_RANGED_VALUE,
+  Time = WATCHFACE_COMPLICATION_TYPE_TIME,
+  Icon = WATCHFACE_COMPLICATION_TYPE_ICON,
+  Image = WATCHFACE_COMPLICATION_TYPE_IMAGE
+} ComplicationType;
+
+typedef enum {
+  EventNone = WATCHFACE_COMPLICATION_EVENT_NONE,
+  EventTap = WATCHFACE_COMPLICATION_EVENT_TAP,
+  EventDoubleTap = WATCHFACE_COMPLICATION_EVENT_DOUBLE_TAP
+} ComplicationEventType;
+
+}  // namespace watchface_complication
+
+#endif  /* __TIZEN_APPFW_COMPLICATION_INTERNAL_H__ */
index 2eb5eb59acab82c82bb32f3554c01cbd0bf8ff11..6a4835bbdecc6ff13a03a14b3bf95f83d2a82e78 100644 (file)
@@ -26,7 +26,7 @@
 #include "watchface-complication/complication-implementation.h"
 #include "watchface-common/watchface-util.h"
 #include "watchface-common/watchface-common-internal.h"
-#include "watchface-complication/include/watchface-complication-internal.h"
+#include "watchface-complication/complication-internal.h"
 
 #include <iostream>
 
@@ -1026,4 +1026,24 @@ int Complication::ClearAllowedList() {
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
+int Complication::GetDefaultData(
+    string provider_id, int type, Bundle* default_data) {
+  std::list<std::string> privlege_list =
+      DBManager::GetRequiredPrivilegeList(provider_id);
+  std::string not_supported_privileges = "";
+  for (auto& i : privlege_list) {
+    if (util::CheckPrivilege(i.c_str()) != 0) {
+      LOGE("Privilege(%s) required for (%s)", i.c_str(), provider_id.c_str());
+      return WATCHFACE_COMPLICATION_ERROR_PERMISSION_DENIED;
+    }
+  }
+
+  std::unique_ptr<Bundle> ptr =
+      DBManager::GetDefaultData(provider_id.c_str(), type);
+  if (ptr == nullptr)
+    return WATCHFACE_COMPLICATION_ERROR_DB;
+  *default_data = *ptr;
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
 }  // namespace watchface_complication
index 570821789fcb2282c436759d969a1a2b8a0b3f19..d3e7337da441999776bb55ebe530f78ddbc4254a 100644 (file)
@@ -110,6 +110,8 @@ class EXPORT_API Complication : public IEditable
   static const char* GetSupportedEventsErrorKey();
   static const char* GetPrivilegeErrorKey();
   static gboolean PeriodCallback(gpointer user_data);
+  static int GetDefaultData(
+      std::string provider_id, int type, tizen_base::Bundle* data);
 
  private:
   class Impl;
index 4ffdd57938b79a0770311c40f2bb08637d44f87e..7511df0f8a6f85b04fe4548d3b7ab8d2d832ccf8 100644 (file)
@@ -22,7 +22,7 @@
 #include <pkgmgr_installer_info.h>
 #include <vconf.h>
 
-#include "watchface-complication/include/watchface-complication-internal.h"
+#include "watchface-complication/complication-internal.h"
 #include "watchface-complication/db-manager.h"
 #include "watchface-common/watchface-util.h"
 
index 2c3fe5d9dd2444198815c8af53ff099a4763ca17..ae8079a45afce3e23edd18b815ccbf3336b1f8aa 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "watchface-complication/editables-container.h"
 #include "watchface-complication/editables-container-implementation.h"
-#include "watchface-complication/include/watchface-complication-internal.h"
+#include "watchface-complication/complication-internal.h"
 #include "watchface-common/watchface-util.h"
 #include "watchface-complication/gdbus-interface.h"
 
index 10a04b6299c07cadd7fd0ea3a170d63faf282808..ffc9d0acc3deef98a5838526869be85013107ee7 100644 (file)
 #define __TIZEN_APPFW_WATCHFACE_COMPLICATION_INTERNAL_H__
 
 #include <watchface-common.h>
+#include <bundle.h>
 
-namespace watchface_complication {
+#ifdef __cplusplus
+extern "C" {
+#endif
 
-typedef enum {
-  NoData = WATCHFACE_COMPLICATION_TYPE_NO_DATA,
-  ShortText = WATCHFACE_COMPLICATION_TYPE_SHORT_TEXT,
-  LongText = WATCHFACE_COMPLICATION_TYPE_LONG_TEXT,
-  RangedValue = WATCHFACE_COMPLICATION_TYPE_RANGED_VALUE,
-  Time = WATCHFACE_COMPLICATION_TYPE_TIME,
-  Icon = WATCHFACE_COMPLICATION_TYPE_ICON,
-  Image = WATCHFACE_COMPLICATION_TYPE_IMAGE
-} ComplicationType;
-
-typedef enum {
-  EventNone = WATCHFACE_COMPLICATION_EVENT_NONE,
-  EventTap = WATCHFACE_COMPLICATION_EVENT_TAP,
-  EventDoubleTap = WATCHFACE_COMPLICATION_EVENT_DOUBLE_TAP
-} ComplicationEventType;
-
-}  // namespace watchface_complication
+int watchface_complication_get_default_data(const char *provider_id,
+    watchface_complication_type_e type, bundle **default_data);
+#ifdef __cplusplus
+}
+#endif
 
 #endif  /* __TIZEN_APPFW_WATCHFACE_COMPLICATION_INTERNAL_H__ */
index 0f60a972fa49ac2ba045b38b9890bcb8c70ef93d..72063cbc2a253f7950c67545d07c6f1232143f16 100644 (file)
@@ -27,7 +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"
 #include "watchface-common/watchface-util.h"
@@ -998,3 +998,25 @@ extern "C" EXPORT_API int watchface_complication_allowed_list_clear(
 
   return ptr.get()->ClearAllowedList();
 }
+
+extern "C" EXPORT_API int watchface_complication_get_default_data(
+    const char* provider_id, watchface_complication_type_e type,
+    bundle** default_data) {
+  if (!watchface_complication::util::CheckWatchFeatureEnabled())
+    return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
+
+  if (default_data == nullptr || provider_id == nullptr ||
+      !util::CheckComplicationType(type) ||
+      type == WATCHFACE_COMPLICATION_TYPE_NO_DATA) {
+    LOGE("Invalid param");
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  Bundle data;
+  int ret = Complication::GetDefaultData(provider_id, type, &data);
+  if (ret != WATCHFACE_COMPLICATION_ERROR_NONE)
+    return ret;
+
+  *default_data = bundle_dup(data.GetHandle());
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}