From edeefa8d6d1890dcc20b49458ea9a19b1562c833 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 5 Dec 2017 16:17:31 +0900 Subject: [PATCH] Display: add a flag to prevent duplicated privilege check Change-Id: I3c3599d30f72b732d9140b4b23d104d4a0f2e6f5 Signed-off-by: lokilee73 --- src/power.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/power.c b/src/power.c index b585325..d3f6393 100755 --- a/src/power.c +++ b/src/power.c @@ -86,6 +86,8 @@ static struct _lock_timeout { .padding = LOCK_CPU_PADDING_TIMEOUT, }; +static int privilege = -1; + static char *get_state_str(display_state_e state) { switch (state) { @@ -331,6 +333,9 @@ static int lock_state(display_state_e state, unsigned int flag, int timeout_ms) char str_timeout[32]; int ret; + if (privilege == 0) + return -EACCES; + if (flag & GOTO_STATE_NOW) arr[1] = STR_GOTOSTATENOW; else @@ -346,13 +351,18 @@ static int lock_state(display_state_e state, unsigned int flag, int timeout_ms) snprintf(str_timeout, sizeof(str_timeout), "%d", timeout_ms); arr[3] = str_timeout; - arr[0] = "privilege check"; - - ret = dbus_method_sync(DEVICED_BUS_NAME, - DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, - METHOD_LOCK_STATE, "sssi", arr); - if (ret == -EACCES || ret == -ECOMM || ret == -EPERM) - return -EACCES; + if (privilege < 0) { + arr[0] = "privilege check"; + + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_LOCK_STATE, "sssi", arr); + if (ret == -EACCES || ret == -ECOMM || ret == -EPERM) { + privilege = 0; + return -EACCES; + } else + privilege = 1; + } arr[0] = get_state_str(state); if (!arr[0]) @@ -381,6 +391,9 @@ static int unlock_state(display_state_e state, unsigned int flag) char *arr[2]; int ret; + if (privilege == 0) + return -EACCES; + if (flag == PM_SLEEP_MARGIN) arr[1] = STR_SLEEP_MARGIN; else if (flag == PM_RESET_TIMER) @@ -390,13 +403,18 @@ static int unlock_state(display_state_e state, unsigned int flag) else return -EINVAL; - arr[0] = "privilege check"; - - ret = dbus_method_sync(DEVICED_BUS_NAME, - DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, - METHOD_UNLOCK_STATE, "ss", arr); - if (ret == -EACCES || ret == -ECOMM || ret == -EPERM) - return -EACCES; + if (privilege < 0) { + arr[0] = "privilege check"; + + ret = dbus_method_sync(DEVICED_BUS_NAME, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, + METHOD_UNLOCK_STATE, "ss", arr); + if (ret == -EACCES || ret == -ECOMM || ret == -EPERM) { + privilege = 0; + return -EACCES; + } else + privilege = 1; + } arr[0] = get_state_str(state); if (!arr[0]) -- 2.7.4