From: lokilee73 Date: Wed, 20 Jun 2018 12:56:02 +0000 (+0900) Subject: Modify device_display_change_state() to be asynchronous X-Git-Tag: submit/tizen_4.0/20180621.024300^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e4573f779dd6f0c0f1b43d8e21e32ff76355f71f;p=platform%2Fcore%2Fapi%2Fdevice.git Modify device_display_change_state() to be asynchronous To change from Off to Normal, time of more than 200ms was required. Change-Id: I3e8918dac376c5ff5c3259a30df85f049340ee85 Signed-off-by: lokilee73 --- diff --git a/src/common.c b/src/common.c index c6fd0a1..7157b42 100755 --- a/src/common.c +++ b/src/common.c @@ -20,6 +20,7 @@ #include #include #include "common.h" +#include #define MAX_LINE 128 #define MAX_SECTION 64 @@ -161,3 +162,46 @@ tizen_profile_t _get_tizen_profile() return profile; } + +int check_async_call_rate(void) +{ + static int status; + static long num_calls; + static struct timeval prev; + struct timeval cur; + int ret; + + if (status < 0) + return status; + + ret = gettimeofday(&cur, NULL); + if (ret < 0) + return 0; + + if (num_calls > 0) { + long rate; + struct timeval diff; + timersub(&cur, &prev, &diff); + + if (diff.tv_sec > 0) { + rate = num_calls / diff.tv_sec; + + if (rate > CHECK_RATE_THRESHOLD) { + status = -1; + return status; + } + + if (diff.tv_sec > CHECK_RATE_PERIOD_LEN) { + /* Reset the check period */ + num_calls = 0; + return 0; + } + } + } else { + /* Start a new check period */ + prev = cur; + } + + num_calls++; + return 0; +} diff --git a/src/common.h b/src/common.h old mode 100644 new mode 100755 index 0fe6bc2..cd633ac --- a/src/common.h +++ b/src/common.h @@ -76,6 +76,10 @@ typedef enum { } tizen_profile_t; extern tizen_profile_t _get_tizen_profile(); +#define CHECK_RATE_THRESHOLD 100 +#define CHECK_RATE_PERIOD_LEN 5 +int check_async_call_rate(void); + #define TIZEN_FEATURE_TRACKER (_get_tizen_profile() == TIZEN_PROFILE_TV) #endif /* __COMMON_H__ */ diff --git a/src/display.c b/src/display.c old mode 100644 new mode 100755 index e633d8c..6817f28 --- a/src/display.c +++ b/src/display.c @@ -207,26 +207,62 @@ static char *get_state_str(display_state_e state) return NULL; } +static void change_cb(void *data, GVariant *result, GError *err) +{ + int ret; + + if (!result) { +//LCOV_EXCL_START System Error + _E("no message : %s", err->message); + return; +//LCOV_EXCL_STOP + } + + g_variant_get(result, "(i)", &ret); + _D("%s-%s : %d", DEVICED_INTERFACE_DISPLAY, METHOD_CHANGE_STATE, ret); +} + int device_display_change_state(display_state_e state) { char *str, *arr[1]; int ret; + static int privilege = -1; _W("DEPRECATION WARNING: device_display_change_state() is deprecated and will be removed from next release."); + if (check_async_call_rate() < 0) { + _E("Rejected by too frequent calls; %d (calls per sec.) limit is violated." + , CHECK_RATE_THRESHOLD); + return DEVICE_ERROR_OPERATION_FAILED; + } + + if (privilege == 0) + return -EACCES; + if (state < DISPLAY_STATE_NORMAL || state > DISPLAY_STATE_SCREEN_OFF) return DEVICE_ERROR_INVALID_PARAMETER; + if (privilege < 0) { + arr[0] = "privilege check"; + + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_CHANGE_STATE, "s", arr); +//LCOV_EXCL_START System Error + if (ret == -EACCES || ret == -ECOMM || ret == -EPERM) { + privilege = 0; + return -EACCES; +//LCOV_EXCL_STOP + } else + privilege = 1; + } + str = get_state_str(state); if (!str) return DEVICE_ERROR_INVALID_PARAMETER; arr[0] = str; - ret = dbus_method_sync(DEVICED_BUS_NAME, + return dbus_method_async_with_reply(DEVICED_BUS_NAME, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, - METHOD_CHANGE_STATE, "s", arr); - if (ret < 0) - return errno_to_device_error(ret); - - return DEVICE_ERROR_NONE; + METHOD_CHANGE_STATE, "s", arr, change_cb, -1, NULL); } diff --git a/src/haptic.c b/src/haptic.c old mode 100644 new mode 100755 index 10704b5..25a0a30 --- a/src/haptic.c +++ b/src/haptic.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "haptic.h" #include "common.h"