board: Add display_rotation setter sandbox/cw00.choi/display-rotation-v2
authorTaemin Yeom <taemin.yeom@samsung.com>
Mon, 19 Dec 2022 10:29:02 +0000 (19:29 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Wed, 21 Dec 2022 03:28:22 +0000 (12:28 +0900)
todo

Signed-off-by: Taemin Yeom <taemin.yeom@samsung.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
CMakeLists.txt
include/board-internal.h
packaging/capi-system-device.spec
src/board-internal.c

index b10ff46fbf007132e5d1698b8fe37bf15c15e12d..05d9660973bc3de551677ad306ec10e760a5516a 100644 (file)
@@ -15,6 +15,7 @@ SET(PKG_MODULES
                vconf
                capi-base-common
                capi-system-info
+               capi-system-sensor
                gio-2.0
                tracker
                libsyscommon
index f8e029bbd51d067eb1cee643958618a1f8424afd..f55321e2df1aaf6577670d8fff0eab89258788f9 100644 (file)
@@ -5,6 +5,29 @@
 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);
@@ -15,6 +38,49 @@ int device_board_clear_partition_ab_cloned(void);
 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
index f6a904e692f89bac8de58adecf2ab03cba3c48b3..45e9489cb4713944f434e15667bd10b9ba377a2d 100644 (file)
@@ -9,6 +9,7 @@ Source1:    capi-system-device.manifest
 BuildRequires:  cmake
 BuildRequires:  pkgconfig(capi-base-common)
 BuildRequires:  pkgconfig(capi-system-info)
+BuildRequires:  pkgconfig(capi-system-sensor)
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(gio-2.0)
index 01686b0819331a4e68a12bcf22a20c3342059cdb..04e4d43f9061459f436ade24955f5562d3c0249f 100644 (file)
  * 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;
@@ -59,3 +72,174 @@ int device_board_set_partition_status(char partition_ab, const char *status)
 {
        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;
+}