extern "C" {
#endif
+/**
+ * @brief Enumeration for the available board display rotation states.
+ * @since_tizen 7.0
+ */
+typedef enum
+{
+ DEVICE_BOARD_DISPLAY_ROTATION_UNKNOWN = 0, /**< Unknown display rotation state */
+ DEVICE_BOARD_DISPLAY_ROTATION_PORTRAIT, /**< Portrait display rotation */
+ DEVICE_BOARD_DISPLAY_ROTATION_LANDSCAPE, /**< Landscape display rotation */
+ DEVICE_BOARD_DISPLAY_ROTATION_PORTRAIT_R, /**< Reverse Portrait display rotation */
+ DEVICE_BOARD_DISPLAY_ROTATION_LANDSCAPE_R, /**< Reverse Landscape display rotation */
+} device_board_display_rotation_e;
+
+/**
+ * @brief Enumeration for the board display rotation directions.
+ * @since_tizen 7.0
+ */
+typedef enum
+{
+ DEVICE_BOARD_DISPLAY_ROTATION_CLOCKWISE = 0, /**< Clockwise direction for display rotation */
+ DEVICE_BOARD_DISPLAY_ROTATION_COUNTER_CLOCKWISE, /**< Counter clockwise direction for display rotation */
+} device_board_display_rotation_direction_e;
+
int device_board_get_serial_number(char *buffer, const int max_len);
int device_board_get_boot_mode(char *buffer, const int max_len);
int device_board_get_partition_ab_cloned(int *cloned);
int device_board_set_partition_status(char partition_ab, const char *status);
+/**
+ * @brief Get board 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[out] rotation The type is board display rotation state\n
+ * DEVICE_BOARD_DISPLAY_ROTATION_UNKNOWN\n
+ * DEVICE_BOARD_DISPLAY_ROTATION_PORTRAIT\n
+ * DEVICE_BOARD_DISPLAY_ROTATION_LANDSCAPE\n
+ * DEVICE_BOARD_DISPLAY_ROTATION_PORTRAIT_R\n
+ * DEVICE_BOARD_DISPLAY_ROTATION_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_board_get_display_rotation(device_board_display_rotation_e *rotation);
+
+/**
+ * @brief Set board 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] rotation The type is board display rotation state\n
+ * DEVICE_BOARD_DISPLAY_ROTATION_PORTRAIT\n
+ * DEVICE_BOARD_DISPLAY_ROTATION_LANDSCAPE\n
+ * DEVICE_BOARD_DISPLAY_ROTATION_PORTRAIT_R\n
+ * DEVICE_BOARD_DISPLAY_ROTATION_LANDSCAPE_R\n
+ * @param[in] direction The type is board display rotation direction\n
+ * DEVICE_BOARD_DISPLAY_ROTATION_CLOCKWISE\n
+ * DEVICE_BOARD_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_board_set_display_rotation(device_board_display_rotation_e rotation,
+ device_board_display_rotation_direction_e direction);
+
#ifdef __cplusplus
}
#endif
* limitations under the License.
*/
+#include <glib.h>
+
+#include <sensor.h>
+#include <sensor_internal.h>
+#include <libsyscommon/libgdbus.h>
#include <hal/device/hal-board.h>
+#include "board-internal.h"
+#include "common.h"
+
+#define METHOD_GET_DISPLAY_ROTATION "GetDisplayRotation"
+#define METHOD_SET_DISPLAY_ROTATION "SetDisplayRotation"
+
+static sensor_listener_h g_sensor_listener_handle;
+
int device_board_get_serial_number(char *buffer, const int max_len)
{
int ret;
{
return hal_device_board_set_partition_status(partition_ab, status);
}
+
+static int board_sensor_listener_start(void)
+{
+ static bool sensor_inited = false;
+ 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], &g_sensor_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(g_sensor_listener_handle);
+ if (ret < 0) {
+ _E("Failed to start auto-rotation sensor");
+ return DEVICE_ERROR_OPERATION_FAILED;
+ }
+
+ return DEVICE_ERROR_NONE;
+}
+
+static int board_sensor_listener_stop(void)
+{
+ int ret;
+ ret = sensor_listener_stop(g_sensor_listener_handle);
+ if (ret < 0)
+ return ret;
+
+ return DEVICE_ERROR_NONE;
+}
+
+static int board_sensor_get_display_rotation_state(device_board_display_rotation_e *rotation)
+{
+ int ret, count, event;
+ sensor_event_s *events = NULL;
+
+ ret = board_sensor_listener_start();
+ if (ret < 0)
+ return ret;
+
+ ret = sensor_listener_read_data_list(g_sensor_listener_handle, &events, &count);
+ if (ret < 0 || count <= 0) {
+ _E("Failed to read the value of auto-rotation sensor");
+ board_sensor_listener_stop();
+ return DEVICE_ERROR_OPERATION_FAILED;
+ }
+
+ event = (int)events->values[0];
+ switch (event) {
+ case AUTO_ROTATION_DEGREE_0:
+ *rotation = DEVICE_BOARD_DISPLAY_ROTATION_PORTRAIT;
+ break;
+ case AUTO_ROTATION_DEGREE_90:
+ *rotation = DEVICE_BOARD_DISPLAY_ROTATION_LANDSCAPE;
+ break;
+ case AUTO_ROTATION_DEGREE_180:
+ *rotation = DEVICE_BOARD_DISPLAY_ROTATION_PORTRAIT_R;
+ break;
+ case AUTO_ROTATION_DEGREE_270:
+ *rotation = DEVICE_BOARD_DISPLAY_ROTATION_LANDSCAPE_R;
+ break;
+ default:
+ *rotation = DEVICE_BOARD_DISPLAY_ROTATION_UNKNOWN;
+ break;
+ }
+
+ free(events);
+ return board_sensor_listener_stop();
+}
+
+int device_board_get_display_rotation(device_board_display_rotation_e *rotation)
+{
+ int ret = 0, reply_val = 0;
+ GVariant *reply;
+
+ if (!rotation)
+ return DEVICE_ERROR_INVALID_PARAMETER;
+
+ /* Get display rotation state from deviced */
+ ret = gdbus_call_sync_with_reply(DEVICED_BUS_NAME,
+ DEVICED_PATH_BOARD, DEVICED_INTERFACE_BOARD,
+ METHOD_GET_DISPLAY_ROTATION, NULL, &reply);
+ if (ret < 0) {
+ _E("Failed to call dbus method to get display rotation state");
+ 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;
+ }
+
+ /**
+ * If deviced doesn't support the display rotation,
+ * try to get the display rotation state from sensord
+ * which supports the auto rotation feature.
+ */
+ return board_sensor_get_display_rotation_state(rotation);
+}
+
+int device_board_set_display_rotation(device_board_display_rotation_e rotation,
+ device_board_display_rotation_direction_e direction)
+{
+ int ret, reply;
+
+ switch (rotation) {
+ case DEVICE_BOARD_DISPLAY_ROTATION_UNKNOWN:
+ case DEVICE_BOARD_DISPLAY_ROTATION_PORTRAIT:
+ case DEVICE_BOARD_DISPLAY_ROTATION_LANDSCAPE:
+ case DEVICE_BOARD_DISPLAY_ROTATION_PORTRAIT_R:
+ case DEVICE_BOARD_DISPLAY_ROTATION_LANDSCAPE_R:
+ break;
+ default:
+ return DEVICE_ERROR_INVALID_PARAMETER;
+ };
+
+ switch (direction) {
+ case DEVICE_BOARD_DISPLAY_ROTATION_CLOCKWISE:
+ case DEVICE_BOARD_DISPLAY_ROTATION_COUNTER_CLOCKWISE:
+ break;
+ default:
+ return DEVICE_ERROR_INVALID_PARAMETER;
+ };
+
+ ret = gdbus_call_sync_with_reply_int(DEVICED_BUS_NAME,
+ DEVICED_PATH_BOARD, DEVICED_INTERFACE_BOARD,
+ METHOD_SET_DISPLAY_ROTATION,
+ g_variant_new("(ii)", rotation, direction),
+ &reply);
+ if (ret < 0) {
+ _E("Failed to call dbus method to set display rotation state");
+ 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;
+}