From 133bfcfeb4ec0c3045bc38ba099f64132dbe3f90 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 10 Jul 2019 11:38:37 +0900 Subject: [PATCH] Add display feature for all profiles Display feature is necessary for all profiles such as headed and headless. ex) http://tizen.org/feature/display So, add it. Change-Id: If0a9f9d0cda5e31784fc5b38df0e7544ad41138c Signed-off-by: lokilee73 --- doc/device_doc.h | 1 + include/callback.h | 4 ++++ include/display.h | 10 ++++++++++ src/callback.c | 6 ++++++ src/common.c | 17 +++++++++++++++++ src/common.h | 1 + src/display.c | 32 ++++++++++++++++++++++++++++++++ 7 files changed, 71 insertions(+) diff --git a/doc/device_doc.h b/doc/device_doc.h index e18706d..661bbe8 100644 --- a/doc/device_doc.h +++ b/doc/device_doc.h @@ -91,6 +91,7 @@ * * @section CAPI_SYSTEM_DEVICE_DISPLAY_MODULE__FEATURE Related Features * This API is related with the following features:\n + * - %http://tizen.org/feature/display\n * - %http://tizen.org/feature/display.state\n * * It is recommended to design feature related codes in your application for reliability.\n diff --git a/include/callback.h b/include/callback.h index ee06cc7..d953780 100644 --- a/include/callback.h +++ b/include/callback.h @@ -70,6 +70,7 @@ typedef void (*device_changed_cb)(device_callback_e type, void *value, void *use /** * @brief Adds a callback to the observing device state. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @remarks the following feature should be supported for #DEVICE_CALLBACK_DISPLAY_STATE: %http://tizen.org/feature/display. Otherwise #DEVICE_ERROR_NOT_SUPPORTED is returned. * @param[in] type The device type to monitor * @param[in] callback The callback function to add * @param[in] user_data The user data to be passed to the callback function @@ -79,6 +80,7 @@ typedef void (*device_changed_cb)(device_callback_e type, void *value, void *use * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DEVICE_ERROR_ALREADY_IN_PROGRESS Operation already * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device */ int device_add_callback(device_callback_e type, device_changed_cb callback, void *user_data); @@ -86,6 +88,7 @@ int device_add_callback(device_callback_e type, device_changed_cb callback, void /** * @brief Removes a device callback function. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @remarks the following feature should be supported for #DEVICE_CALLBACK_DISPLAY_STATE: %http://tizen.org/feature/display. Otherwise #DEVICE_ERROR_NOT_SUPPORTED is returned. * @param[in] type The device type to monitor * @param[in] callback The callback function to remove * @return @c 0 on success, @@ -93,6 +96,7 @@ int device_add_callback(device_callback_e type, device_changed_cb callback, void * @retval #DEVICE_ERROR_NONE Successful * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device */ int device_remove_callback(device_callback_e type, device_changed_cb callback); diff --git a/include/display.h b/include/display.h index 63e1156..04b5eb5 100644 --- a/include/display.h +++ b/include/display.h @@ -38,6 +38,7 @@ extern "C" { * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public * @privilege %http://tizen.org/privilege/display + * @remarks #DEVICE_ERROR_NOT_SUPPORTED is returned, when the following feature is not supported: %http://tizen.org/feature/display * @param[out] device_number The total number of displays * @return @c 0 on success, * otherwise a negative error value @@ -45,6 +46,7 @@ extern "C" { * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device * @see device_display_get_brightness() * @see device_display_set_brightness() * @see device_display_get_max_brightness() @@ -57,6 +59,7 @@ int device_display_get_numbers(int *device_number); * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public * @privilege %http://tizen.org/privilege/display + * @remarks #DEVICE_ERROR_NOT_SUPPORTED is returned, when the following feature is not supported: %http://tizen.org/feature/display * @param[in] display_index The index of the display \n * It can be greater than or equal to @c 0 and less than the number of displays returned by device_display_get_numbers(). \n * The index zero is always assigned to the main display @@ -67,6 +70,7 @@ int device_display_get_numbers(int *device_number); * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device * @see device_display_get_numbers() * @see device_display_set_brightness() * @see device_display_get_brightness() @@ -79,6 +83,7 @@ int device_display_get_max_brightness(int display_index, int *max_brightness); * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public * @privilege %http://tizen.org/privilege/display + * @remarks #DEVICE_ERROR_NOT_SUPPORTED is returned, when the following feature is not supported: %http://tizen.org/feature/display * @param[in] display_index The index of the display \n * It can be greater than or equal to @c 0 and less than the number of displays returned by device_display_get_numbers(). \n * The index zero is always assigned to the main display @@ -89,6 +94,7 @@ int device_display_get_max_brightness(int display_index, int *max_brightness); * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device * @see device_display_get_numbers() * @see device_display_set_brightness() * @see device_display_get_max_brightness() @@ -101,6 +107,7 @@ int device_display_get_brightness(int display_index, int *brightness); * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public * @privilege %http://tizen.org/privilege/display + * @remarks #DEVICE_ERROR_NOT_SUPPORTED is returned, when the following feature is not supported: %http://tizen.org/feature/display * @param[in] display_index The index of the display \n * It can be greater than or equal to @c 0 and less than the number of displays returned by device_display_get_numbers(). \n * The index zero is always assigned to the main display @@ -112,6 +119,7 @@ int device_display_get_brightness(int display_index, int *brightness); * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device * @see device_display_get_numbers() * @see device_display_get_max_brightness() * @see device_display_get_brightness() @@ -134,12 +142,14 @@ typedef enum /** * @brief Gets the current display state. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @remarks #DEVICE_ERROR_NOT_SUPPORTED is returned, when the following feature is not supported: %http://tizen.org/feature/display * @param[out] state The display state * @return @c 0 on success, * otherwise a negative error value * @retval #DEVICE_ERROR_NONE Successful * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + * @retval #DEVICE_ERROR_NOT_SUPPORTED Not supported device * @see device_add_callback * @see device_remove_callback * @see #DEVICE_CALLBACK_DISPLAY_STATE diff --git a/src/callback.c b/src/callback.c index eb54bc5..f4d7d45 100644 --- a/src/callback.c +++ b/src/callback.c @@ -286,6 +286,9 @@ int device_add_callback(device_callback_e type, device_changed_cb cb, void *data dd_list *elem, *elem_next; int ret, n; + if (!is_display_supported() && type == DEVICE_CALLBACK_DISPLAY_STATE) + return DEVICE_ERROR_NOT_SUPPORTED; + if (type < 0 || type >= DEVICE_CALLBACK_MAX) return DEVICE_ERROR_INVALID_PARAMETER; @@ -325,6 +328,9 @@ int device_remove_callback(device_callback_e type, device_changed_cb cb) dd_list *elem, *elem_next; int ret, n; + if (!is_display_supported() && type == DEVICE_CALLBACK_DISPLAY_STATE) + return DEVICE_ERROR_NOT_SUPPORTED; + if (type < 0 || type >= DEVICE_CALLBACK_MAX) return DEVICE_ERROR_INVALID_PARAMETER; diff --git a/src/common.c b/src/common.c index 5f801b7..b455fef 100644 --- a/src/common.c +++ b/src/common.c @@ -30,6 +30,7 @@ #define MODEL_NAME "http://tizen.org/system/model_name" #define MODEL_EMULATOR "Emulator" +#define DISPLAY_FEATURE "http://tizen.org/feature/display" #define DISPLAY_STATE_FEATURE "http://tizen.org/feature/display.state" static inline char *trim_str(char *s) @@ -241,6 +242,22 @@ bool is_emulator(void) return emul; } +int is_display_supported(void) +{ + int ret; + bool display_avail; + + ret = system_info_get_platform_bool(DISPLAY_FEATURE, &display_avail); + if (ret < 0) { + _E("Failed to get value of display feature"); + return false; + } else if (ret == 0 && !display_avail) { + _D("Display feature is not supported"); + return false; + } else + return true; +} + int is_display_state_supported(void) { int ret; diff --git a/src/common.h b/src/common.h index 4e720d6..524fdc7 100644 --- a/src/common.h +++ b/src/common.h @@ -84,4 +84,5 @@ int check_async_call_rate(void); bool is_emulator(void); int is_display_state_supported(void); +int is_display_supported(void); #endif /* __COMMON_H__ */ diff --git a/src/display.c b/src/display.c index f8d958f..351febf 100644 --- a/src/display.c +++ b/src/display.c @@ -62,6 +62,10 @@ int device_display_get_numbers(int *device_number) { int ret; + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + if (!device_number) return DEVICE_ERROR_INVALID_PARAMETER; @@ -87,6 +91,10 @@ int device_display_get_max_brightness(int display_index, int *max_brightness) char str_val[32]; int ret; + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + if (!max_brightness) return DEVICE_ERROR_INVALID_PARAMETER; @@ -123,6 +131,10 @@ int device_display_get_brightness(int display_index, int *brightness) char str_val[32]; int ret; + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + if (!brightness) return DEVICE_ERROR_INVALID_PARAMETER; @@ -155,6 +167,10 @@ int device_display_set_brightness(int display_index, int brightness) char str_val[32]; int ret, max; + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + if (display_cnt < 0) { ret = device_display_get_numbers(&display_cnt); if (ret != DEVICE_ERROR_NONE) //LCOV_EXCL_LINE System Error @@ -189,6 +205,10 @@ int device_display_get_state(display_state_e *state) { int ret, val; + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + if (!state) return DEVICE_ERROR_INVALID_PARAMETER; @@ -289,6 +309,10 @@ int device_display_get_max_brightness_state(int display_index, display_state_e s char str_val[32]; int ret; + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + if (!brightness) return DEVICE_ERROR_INVALID_PARAMETER; @@ -338,6 +362,10 @@ int device_display_get_brightness_state(int display_index, display_state_e state char str_val[32]; int ret; + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + if (!brightness) return DEVICE_ERROR_INVALID_PARAMETER; @@ -379,6 +407,10 @@ int device_display_set_brightness_state(int display_index, display_state_e state char str_val[32]; int ret, max; + ret = is_display_supported(); + if (!ret) + return DEVICE_ERROR_NOT_SUPPORTED; + if (display_cnt < 0) { ret = device_display_get_numbers(&display_cnt); if (ret != DEVICE_ERROR_NONE) //LCOV_EXCL_LINE System Error -- 2.7.4