Add datasharing privilege for add updated callback 10/186610/4
authorhyunho <hhstark.kang@samsung.com>
Mon, 13 Aug 2018 01:21:49 +0000 (10:21 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Fri, 17 Aug 2018 08:33:17 +0000 (08:33 +0000)
Change-Id: I90f3920a2721dbc6e31c4704132e4cb1a28d77d1
Signed-off-by: hyunho <hhstark.kang@samsung.com>
watchface-complication/include/watchface-complication.h
watchface-complication/watchface-complication.cc

index 5fa977f..89007c0 100644 (file)
@@ -155,6 +155,7 @@ int watchface_complication_get_current_type(complication_h handle,
 /**
  * @brief Adds the callback function to use for complication update.
  * @since_tizen 5.0
+ * @privilege http://tizen.org/privilege/datasharing
  * @param[in] handle Complication handle
  * @param[in] cb The callback function
  * @param[in] error_cb The error callback function
@@ -164,6 +165,8 @@ int watchface_complication_get_current_type(complication_h handle,
  * @retval #WATCHFACE_COMPLICATION_ERROR_OUT_OF_MEMORY Out of memory
  * @retval #WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED Not supported
+ * @retval #WATCHFACE_COMPLICATION_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #WATCHFACE_COMPLICATION_ERROR_IO_ERROR I/O error
  * @pre Complication handle should be created by watchface_complication_create().
  * @see watchface_complication_updated_cb()
  * @par Sample code:
index bdb7d28..fedea3a 100644 (file)
@@ -28,6 +28,7 @@
 #include "watchface-complication/include/watchface-complication-internal.h"
 #include "watchface-complication/complication.h"
 #include "watchface-complication/shared-handle.h"
+#include "watchface-common/watchface-util.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -157,7 +158,25 @@ extern "C" EXPORT_API int watchface_complication_add_updated_cb(
     watchface_complication_error_cb error_cb, void* user_data) {
   if (handle == NULL || cb == NULL || error_cb == NULL)
     return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
-  int ret;
+
+  static cynara_result pcr = COMPLICATION_CYNARA_UNKNOWN;
+  int ret = WATCHFACE_COMPLICATION_ERROR_NONE;
+
+  if (pcr == COMPLICATION_CYNARA_DENIED) {
+    LOGE("Permission denied");
+    return WATCHFACE_COMPLICATION_ERROR_PERMISSION_DENIED;
+  } else if (pcr == COMPLICATION_CYNARA_UNKNOWN) {
+    ret = watchface_complication::util::CheckPrivilege(PRIVILEGE_DATASHARING);
+    if (ret == WATCHFACE_COMPLICATION_ERROR_NONE) {
+      pcr = COMPLICATION_CYNARA_ALLOWED;
+    } else if (ret == WATCHFACE_COMPLICATION_ERROR_PERMISSION_DENIED) {
+      pcr = COMPLICATION_CYNARA_DENIED;
+      return ret;
+    } else {
+      return ret;
+    }
+  }
+
   auto sh = static_cast<SharedHandle<WatchComplicationStub>*>(handle);
   auto ptr = SharedHandle<WatchComplicationStub>::Share(sh);