plugin-api: deviced: Add interfaces for controlling display brightness 84/313084/1
authorYoungjae Cho <y0.cho@samsung.com>
Mon, 17 Jun 2024 05:37:51 +0000 (14:37 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Mon, 17 Jun 2024 08:59:44 +0000 (17:59 +0900)
Change-Id: I02850dc6fe19bc3c05fde89a83a82ce4421a2c1a
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
src/plugin-api/deviced/include/system/syscommon-plugin-deviced-display-interface.h
src/plugin-api/deviced/include/system/syscommon-plugin-deviced-display.h
src/plugin-api/deviced/src/syscommon-plugin-deviced-display.c
tests/plugin-api/deviced/test-plugin-display.c
tests/plugin-api/deviced/test.c

index c3c7183603322a6735a0d61300421eea7a305d77..21dc8a4fe4bbaeea9abb5f0289cd721b165a0a06 100644 (file)
@@ -151,6 +151,9 @@ typedef struct _syscommon_plugin_backend_deviced_display_funcs {
        int (*custom_lcd_off) (enum deviced_event reason);
        int (*on_by_reason) (const char *reason, int timeout);
        int (*off_by_reason) (const char *reason);
+       int (*get_brightness) (int *brightness);
+       int (*set_brightness) (int brightness);
+       int (*set_brightness_smooth) (int start_brightness, int end_brightness, int step);
 } syscommon_plugin_backend_deviced_display_funcs;
 
 #ifdef __cplusplus
index 1eaf316ec39984ee4f58bb6ef7ccd93a4120789b..652d38364856bc879da2b85dcda6adce20bf3908 100644 (file)
@@ -102,6 +102,30 @@ int syscommon_plugin_deviced_display_on_by_reason(const char *reason, int timeou
  */
 int syscommon_plugin_deviced_display_off_by_reason(const char *reason);
 
+/**
+ * @breif Plugin implementation for getting display brightness
+ * @param[out] brightness Get current brightness
+ * @return @c 0 on success, otherwise a negative error value
+ */
+int syscommon_plugin_deviced_display_get_brightness(int *brightness);
+
+/**
+ * @breif Plugin implementation for setting display brightness
+ * @param[in] brightness Brightness value to set
+ * @return @c 0 on success, otherwise a negative error value
+ */
+int syscommon_plugin_deviced_display_set_brightness(int brightness);
+
+/**
+ * @breif Plugin implementation for setting display brightness smoothly
+ * @param[in] start_brightness Start brightness
+ * @param[in] end_brightness End brightnes
+ * @param[in] step How many steps to change from start to end brightness
+ * @return @c 0 on success, otherwise a negative error value
+ */
+int syscommon_plugin_deviced_display_set_brightness_smooth(int start_brightness,
+       int end_brightness, int step);
+
 #ifdef __cplusplus
 }
 #endif
index fc335e48d7bf3014e0903e1c81327ca5a8e60c61..9f029934fbc410ddcbe102ad4f5441fae420d667 100644 (file)
@@ -232,3 +232,61 @@ int syscommon_plugin_deviced_display_off_by_reason(const char *reason)
 
        return g_display_funcs->off_by_reason(reason);
 }
+
+EXPORT
+int syscommon_plugin_deviced_display_get_brightness(int *brightness)
+{
+       int ret = 0;
+
+       if (!g_display_funcs) {
+               ret = syscommon_plugin_deviced_display_get_backend();
+               if (ret < 0)
+                       return -ENOTSUP;
+       }
+
+       assert(g_display_funcs);
+
+       if (!g_display_funcs->get_brightness)
+               return -EOPNOTSUPP;
+
+       return g_display_funcs->get_brightness(brightness);
+}
+
+EXPORT
+int syscommon_plugin_deviced_display_set_brightness(int brightness)
+{
+       int ret = 0;
+
+       if (!g_display_funcs) {
+               ret = syscommon_plugin_deviced_display_get_backend();
+               if (ret < 0)
+                       return -ENOTSUP;
+       }
+
+       assert(g_display_funcs);
+
+       if (!g_display_funcs->set_brightness)
+               return -EOPNOTSUPP;
+
+       return g_display_funcs->set_brightness(brightness);
+}
+
+EXPORT
+int syscommon_plugin_deviced_display_set_brightness_smooth(int start_brightness,
+       int end_brightness, int step)
+{
+       int ret = 0;
+
+       if (!g_display_funcs) {
+               ret = syscommon_plugin_deviced_display_get_backend();
+               if (ret < 0)
+                       return -ENOTSUP;
+       }
+
+       assert(g_display_funcs);
+
+       if (!g_display_funcs->set_brightness_smooth)
+               return -EOPNOTSUPP;
+
+       return g_display_funcs->set_brightness_smooth(start_brightness, end_brightness, step);
+}
index d5c1b9354b69fd4dec06df38c67de7e854f5d171..b57b07ca7bc4533e0807de26a1828e2f65309d3a 100644 (file)
@@ -84,6 +84,29 @@ static int off_by_reason(const char *reason)
        return 0;
 }
 
+static int get_brightness(int *brightness)
+{
+       check_expected(brightness);
+
+       return 0;
+}
+
+static int set_brightness(int brightness)
+{
+       check_expected(brightness);
+
+       return 0;
+}
+
+static int set_brightness_smooth(int start_brightness, int end_brightness, int step)
+{
+       check_expected(start_brightness);
+       check_expected(end_brightness);
+       check_expected(step);
+
+       return 0;
+}
+
 static syscommon_plugin_backend_deviced_display_funcs g_display_funcs = {
        .load_display_config = load_display_config,
        .on_changed_setting_value = on_changed_setting_value,
@@ -93,6 +116,9 @@ static syscommon_plugin_backend_deviced_display_funcs g_display_funcs = {
        .custom_lcd_off = custom_lcd_off,
        .on_by_reason = on_by_reason,
        .off_by_reason = off_by_reason,
+       .get_brightness = get_brightness,
+       .set_brightness = set_brightness,
+       .set_brightness_smooth = set_brightness_smooth,
 };
 
 static int deviced_display_init(void **data)
index edda91bcb519020e7f1b63e4f16adfd141cd0819..ad98bc00283832ea783ee63a04f3767a50693e90 100644 (file)
@@ -105,7 +105,39 @@ static void test_off_by_reason(void **state)
 
        ret = syscommon_plugin_deviced_display_off_by_reason("reason");
        assert_int_equal(ret, 0);
+}
+
+static void test_get_brightness(void **state)
+{
+       int ret;
+       int value;
+
+       expect_value(get_brightness, brightness, &value);
 
+       ret = syscommon_plugin_deviced_display_get_brightness(&value);
+       assert_int_equal(ret, 0);
+}
+
+static void test_set_brightness(void **state)
+{
+       int ret;
+       
+       expect_value(set_brightness, brightness, 100);
+
+       ret = syscommon_plugin_deviced_display_set_brightness(100);
+       assert_int_equal(ret, 0);
+}
+
+static void test_set_brightness_smooth(void **data)
+{
+       int ret;
+
+       expect_value(set_brightness_smooth, start_brightness, 100);
+       expect_value(set_brightness_smooth, end_brightness, 0);
+       expect_value(set_brightness_smooth, step, 30);
+
+       ret = syscommon_plugin_deviced_display_set_brightness_smooth(100, 0, 30);
+       assert_int_equal(ret, 0);
 }
 
 static const struct CMUnitTest testsuite_plugin_api_deviced[] = {
@@ -116,5 +148,8 @@ static const struct CMUnitTest testsuite_plugin_api_deviced[] = {
        cmocka_unit_test(test_custom_lcd_off),
        cmocka_unit_test(test_on_by_reason),
        cmocka_unit_test(test_off_by_reason),
+       cmocka_unit_test(test_get_brightness),
+       cmocka_unit_test(test_set_brightness),
+       cmocka_unit_test(test_set_brightness_smooth),
 };
 TESTSUITE_FIXTURE(testsuite_plugin_api_deviced, setup_plugin_deviced, teardown_plugin_deviced)