callback: check feature before add/remove callback 85/260685/2 submit/tizen/20210701.065306 submit/tizen/20210719.034923
authorYoungjae Cho <y0.cho@samsung.com>
Thu, 1 Jul 2021 05:36:12 +0000 (14:36 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Thu, 1 Jul 2021 06:05:50 +0000 (15:05 +0900)
Change-Id: Id9ab9c9d68a54bcba444606ba7c62f46cc2c6d4c
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/callback.c

index 91d9d25..f19d785 100644 (file)
@@ -23,6 +23,7 @@
 #include <gio/gio.h>
 #include <libsyscommon/libgdbus.h>
 #include <libsyscommon/list.h>
+#include <system_info.h>
 
 #include "callback.h"
 #include "battery.h"
@@ -287,21 +288,71 @@ static int release_request(device_callback_e type)
        return -EINVAL;
 }
 
+static int device_callback_check_feature_supported(device_callback_e type)
+{
+       static bool f_display = false;
+       static bool f_battery = false;
+       static bool f_flash = false;
+
+       int retval;
+       bool supported;
+
+       switch (type) {
+       case DEVICE_CALLBACK_BATTERY_CAPACITY:
+       case DEVICE_CALLBACK_BATTERY_LEVEL:
+       case DEVICE_CALLBACK_BATTERY_CHARGING:
+               if (f_battery)
+                       return 0;
+
+               retval = system_info_get_platform_bool("http://tizen.org/feature/battery", &supported);
+               if (retval != SYSTEM_INFO_ERROR_NONE || !supported)
+                       return -ENOTSUP;
+
+               f_battery = true;
+               return 0;
+       case DEVICE_CALLBACK_DISPLAY_STATE:
+               if (f_display)
+                       return 0;
+
+               retval = system_info_get_platform_bool("http://tizen.org/feature/display", &supported);
+               if (retval != SYSTEM_INFO_ERROR_NONE || !supported)
+                       return -ENOTSUP;
+               retval = system_info_get_platform_bool("http://tizen.org/feature/display.state", &supported);
+               if (retval != SYSTEM_INFO_ERROR_NONE || !supported)
+                       return -ENOTSUP;
+
+               f_display = true;
+               return 0;
+       case DEVICE_CALLBACK_FLASH_BRIGHTNESS:
+               if (f_flash)
+                       return 0;
+
+               retval = system_info_get_platform_bool("http://tizen.org/feature/camera.back.flash", &supported);
+               if (retval != SYSTEM_INFO_ERROR_NONE || !supported)
+                       return -ENOTSUP;
+
+               f_flash = true;
+               return 0;
+       default:
+               return -EINVAL;
+       }
+}
+
 int device_add_callback(device_callback_e type, device_changed_cb cb, void *data)
 {
        struct device_cb_info *cb_info;
        GList *elem, *elem_next;
        int ret_request, n;
 
-       if (!is_feature_display_supported() && type == DEVICE_CALLBACK_DISPLAY_STATE)
-               return DEVICE_ERROR_NOT_SUPPORTED;
-
        if (type < 0 || type >= DEVICE_CALLBACK_MAX)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
        if (!cb)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
+       if (device_callback_check_feature_supported(type) != 0)
+               return DEVICE_ERROR_NOT_SUPPORTED;
+
        /* check if it is the first request */
        n = SYS_G_LIST_LENGTH(device_cb_list[type]);
        if (n == 0) {
@@ -335,15 +386,15 @@ int device_remove_callback(device_callback_e type, device_changed_cb cb)
        GList *elem, *elem_next;
        int ret_request, n;
 
-       if (!is_feature_display_supported() && type == DEVICE_CALLBACK_DISPLAY_STATE)
-               return DEVICE_ERROR_NOT_SUPPORTED;
-
        if (type < 0 || type >= DEVICE_CALLBACK_MAX)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
        if (!cb)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
+       if (device_callback_check_feature_supported(type) != 0)
+               return DEVICE_ERROR_NOT_SUPPORTED;
+
        /* search for the same element with callback */
        SYS_G_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info) {
                if (cb_info->cb == cb)