From: TaeminYeom Date: Tue, 11 Oct 2022 01:14:47 +0000 (+0900) Subject: display: Add rotation state internal API X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5618625a07d5aeaf3dc48a57749f2ce9c83b1a6d;p=platform%2Fcore%2Fapi%2Fdevice.git display: Add rotation state internal API rotation state means "physical display" direction. Clients can rotate display or check current display state. API function -device_display_get_rotation_state -device_display_set_rotation_state Enumeration -display_rotation_state_e -display_rotation_direction_e Change-Id: Iae840b217977e2540883fec31f5e2631aa93b967 Signed-off-by: TaeminYeom --- diff --git a/CMakeLists.txt b/CMakeLists.txt index b10ff46..0631b8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,8 @@ SET(PKG_MODULES vconf capi-base-common capi-system-info + capi-system-sensor + sensor gio-2.0 tracker libsyscommon diff --git a/include/display-internal.h b/include/display-internal.h index f80e58e..6cb1460 100644 --- a/include/display-internal.h +++ b/include/display-internal.h @@ -29,6 +29,33 @@ extern "C" { #endif +/** + * @brief Enumeration for the available display rotation states. + * @since_tizen 7.0 + */ + +typedef enum +{ + DISPLAY_ROTATION_STATE_UNKNOWN = -1, + DISPLAY_ROTATION_STATE_PORTRAIT, + DISPLAY_ROTATION_STATE_LANDSCAPE, + DISPLAY_ROTATION_STATE_PORTRAIT_R, + DISPLAY_ROTATION_STATE_LANDSCAPE_R, +} display_rotation_state_e; + + +/** + * @brief Enumeration for the display rotation directions. + * @since_tizen 7.0 + */ + +typedef enum +{ + DISPLAY_ROTATION_CLOCKWISE, + DISPLAY_ROTATION_COUNTER_CLOCKWISE, +} display_rotation_direction_e; + + /** * @brief Gets the display brightness value. * @since_tizen @if MOBILE 5.0 @elseif WEARABLE 5.0 @endif @@ -128,6 +155,55 @@ int device_display_change_state_by_reason(display_state_e type, const char *reas */ int is_feature_display_supported(void); + +/** + * @brief Get display rotation state + * @since_tizen 7.0 + * @privilege %http://tizen.org/privilege/display + * @remarks It shows the physical display state, not SW screen state. + * @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 + * @param[out] rotation The type is display rotation state\n + * DISPLAY_ROTATION_STATE_UNKNOWN\n + * DISPLAY_ROTATION_STATE_PORTRAIT\n + * DISPLAY_ROTATION_STATE_LANDSCAPE\n + * DISPLAY_ROTATION_STATE_PORTRAIT_R\n + * DISPLAY_ROTATION_STATE_LANDSCAPE_R\n + * @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_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + */ +int device_display_get_rotation_state(int display_index, display_rotation_state_e *rotation); + +/** + * @brief Set display rotation state + * @since_tizen 7.0 + * @privilege %http://tizen.org/privilege/display + * @remarks It shows the physical display state, not SW screen state. + * @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 + * @param[in] rotation The type is display rotation state\n + * DISPLAY_ROTATION_STATE_PORTRAIT\n + * DISPLAY_ROTATION_STATE_LANDSCAPE\n + * DISPLAY_ROTATION_STATE_PORTRAIT_R\n + * DISPLAY_ROTATION_STATE_LANDSCAPE_R\n + * @param[in] direction The type is display rotation direction\n + * DEVICE_DISPLAY_ROTATION_CLOCKWISE\n + * DEVICE_DISPLAY_ROTATION_COUNTER_CLOCKWISE\n + * @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_PERMISSION_DENIED Permission denied + * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed + */ +int device_display_set_rotation_state(int display_index, display_rotation_state_e rotation, display_rotation_direction_e direction); + /** * @platform * @brief Check display state feature(http://tizen.org/feature/display.state) diff --git a/packaging/capi-system-device.spec b/packaging/capi-system-device.spec index f6a904e..3711d7a 100644 --- a/packaging/capi-system-device.spec +++ b/packaging/capi-system-device.spec @@ -9,6 +9,8 @@ Source1: capi-system-device.manifest BuildRequires: cmake BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(capi-system-sensor) +BuildRequires: pkgconfig(sensor) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(gio-2.0) diff --git a/src/display.c b/src/display.c index e8e25c8..c930152 100644 --- a/src/display.c +++ b/src/display.c @@ -17,9 +17,13 @@ #include #include + #include #include #include +#include +#include +#include #include "display.h" #include "display-internal.h" @@ -34,6 +38,8 @@ #define METHOD_SET_BRIGHTNESS "SetBrightness" #define METHOD_CHANGE_STATE "changestate" #define METHOD_CHANGE_STATE_BY_REASON "ChangeStateByReason" +#define METHOD_GET_ROTATION_STATE "GetRotationState" +#define METHOD_SET_ROTATION_STATE "SetRotationState" #define STR_LCD_OFF "lcdoff" #define STR_LCD_DIM "lcddim" @@ -45,6 +51,9 @@ struct display { int dim_max; } *display_arr; +static bool sensor_inited; +static sensor_listener_h listener_handle; + static int alloc_display(void) { int i; @@ -468,6 +477,170 @@ int is_feature_display_supported(void) return true; } +static int start_sensor(void) +{ + sensor_h *sensor_handle = NULL; + int count, ret; + bool supported = false; + + if (!sensor_inited) { + sensor_is_supported(AUTO_ROTATION_SENSOR, &supported); + if (!supported) { + _E("Auto rotation sensor is not supported in this device"); + return DEVICE_ERROR_OPERATION_FAILED; + } + + ret = sensor_get_sensor_list(AUTO_ROTATION_SENSOR, &sensor_handle, &count); + if (ret < 0 || !sensor_handle || count <= 0) { + _E("Failed to get sensor list"); + return DEVICE_ERROR_OPERATION_FAILED; + } + + ret = sensor_create_listener(sensor_handle[0], &listener_handle); + if (ret < 0) { + _E("Failed to create sensor listener"); + free(sensor_handle); + return DEVICE_ERROR_OPERATION_FAILED; + } + + free(sensor_handle); + sensor_inited = true; + } + + ret = sensor_listener_start(listener_handle); + if (ret < 0) { + _E("Failed to start auto-rotation sensor"); + return DEVICE_ERROR_OPERATION_FAILED; + } + + return DEVICE_ERROR_NONE; +} + +static int stop_sensor(void) +{ + int ret; + ret = sensor_listener_stop(listener_handle); + if (ret < 0) + return ret; + + return DEVICE_ERROR_NONE; +} + +static int sensor_get_rotation_state(display_rotation_state_e *rotation) +{ + int ret, count, event; + sensor_event_s *events = NULL; + + ret = start_sensor(); + if (ret < 0) + return ret; + + ret = sensor_listener_read_data_list(listener_handle, &events, &count); + if (ret < 0 || count <= 0) { + _E("Failed to read the value of auto-rotation sensor"); + stop_sensor(); + return DEVICE_ERROR_OPERATION_FAILED; + } + + event = (int)events->values[0]; + switch (event) { + case AUTO_ROTATION_DEGREE_0: + *rotation = DISPLAY_ROTATION_STATE_PORTRAIT; + break; + case AUTO_ROTATION_DEGREE_90: + *rotation = DISPLAY_ROTATION_STATE_LANDSCAPE; + break; + case AUTO_ROTATION_DEGREE_180: + *rotation = DISPLAY_ROTATION_STATE_PORTRAIT_R; + break; + case AUTO_ROTATION_DEGREE_270: + *rotation = DISPLAY_ROTATION_STATE_LANDSCAPE_R; + break; + default: + *rotation = DISPLAY_ROTATION_STATE_UNKNOWN; + break; + } + + free(events); + return stop_sensor(); +} + +int device_display_get_rotation_state(int display_index, display_rotation_state_e *rotation) +{ + int ret = 0, reply_val = 0; + GVariant *reply; + + if (!rotation) + return DEVICE_ERROR_INVALID_PARAMETER; + + /* + if (display_cnt < 0) { + ret = device_display_get_numbers(&display_cnt); + if (ret < 0) + return ret; + } + + if (display_index < 0 || display_index >= display_cnt || !rotation) + return DEVICE_ERROR_INVALID_PARAMETER; + */ + + ret = gdbus_call_sync_with_reply(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_GET_ROTATION_STATE, g_variant_new("(i)", display_index), &reply); + if (ret < 0) { + _E("Failed to call dbus method"); + return ret; + } + + g_variant_get(reply, "(ii)", &ret, &reply_val); + g_variant_unref(reply); + if (ret < 0 && ret != -ENODEV) { + _E("Failed to get display rotation state"); + return ret; + } + else if (ret >= 0) { + *rotation = reply_val; + return DEVICE_ERROR_NONE; + } + + return sensor_get_rotation_state(rotation); +} + +int device_display_set_rotation_state(int display_index, display_rotation_state_e rotation, display_rotation_direction_e direction) +{ + int ret, reply; + + /* + if (display_cnt < 0) { + ret = device_display_get_numbers(&display_cnt); + if (ret < 0) + return ret; + } + + if (display_index < 0 || display_index >= display_cnt) + return DEVICE_ERROR_INVALID_PARAMETER; + */ + + ret = gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_SET_ROTATION_STATE, g_variant_new("(iii)", display_index, rotation, direction), &reply); + if (ret < 0) { + _E("Failed to call dbus method"); + return ret; + } + + if (reply == -ENODEV) { + _E("Set display rotation is not supported"); + return DEVICE_ERROR_OPERATION_FAILED; + } + else if (ret < 0) { + _E("Failed to set display rotation state"); + return DEVICE_ERROR_OPERATION_FAILED; + } + + return DEVICE_ERROR_NONE; +} + int is_feature_display_state_supported(void) { int ret_val;