Display: add a flag to prevent duplicated privilege check 60/162760/3 accepted/tizen/unified/20171207.070159 submit/tizen/20171204.104825 submit/tizen/20171205.105834 submit/tizen/20171206.045221 submit/tizen/20171206.125708
authorlokilee73 <changjoo.lee@samsung.com>
Tue, 5 Dec 2017 07:17:31 +0000 (16:17 +0900)
committerlokilee73 <changjoo.lee@samsung.com>
Tue, 5 Dec 2017 08:55:25 +0000 (17:55 +0900)
Change-Id: I3c3599d30f72b732d9140b4b23d104d4a0f2e6f5
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
src/power.c

index b585325..d3f6393 100755 (executable)
@@ -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])