#include <stdlib.h>
#include <system_info.h>
#include "common.h"
+#include <sys/time.h>
#define MAX_LINE 128
#define MAX_SECTION 64
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;
+}
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);
}
//LCOV_EXCL_START Not used function
snprintf(str_val, sizeof(str_val), "%d", brightness);
arr[1] = str_val;
break;
+
+ default:
+ break;
}
ret = dbus_method_sync(DEVICED_BUS_NAME,
_I("power_lock_e = %d", type);
if (check_rate() < 0) {
- _E("Rejected by too frequent calls; %d (calls per sec.) limit is over."
+ _E("Rejected by too frequent calls; %d (calls per sec.) limit is violated."
, CHECK_RATE_THRESHOLD);
return DEVICE_ERROR_OPERATION_FAILED;
}
_I("power_lock_e = %d", type);
if (check_rate() < 0) {
- _E("Rejected by too frequent calls; %d (calls per sec.) limit is over."
+ _E("Rejected by too frequent calls; %d (calls per sec.) limit is violated."
, CHECK_RATE_THRESHOLD);
return DEVICE_ERROR_OPERATION_FAILED;
}