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
*/
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)
#include <stdio.h>
#include <errno.h>
+
#include <vconf.h>
#include <libsyscommon/libgdbus.h>
#include <system_info.h>
+#include <sensor.h>
+#include <sensor_internal.h>
+#include <glib.h>
#include "display.h"
#include "display-internal.h"
#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"
int dim_max;
} *display_arr;
+static bool sensor_inited;
+static sensor_listener_h listener_handle;
+
static int alloc_display(void)
{
int i;
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;