Modify error handling in device_display_change_state() 46/182146/3
authorlokilee73 <changjoo.lee@samsung.com>
Thu, 21 Jun 2018 02:09:35 +0000 (11:09 +0900)
committerlokilee73 <changjoo.lee@samsung.com>
Thu, 21 Jun 2018 02:35:38 +0000 (11:35 +0900)
Allow dbus_method call, even if previous returned value was -EACCES, -ECOMM and -EPERM.

Change-Id: I9610dd75a2c36f207358117084838865dd9fa434
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
src/display.c
src/power.c

index 77ec7bf..173c868 100755 (executable)
@@ -251,9 +251,6 @@ int device_display_change_state(display_state_e state)
                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;
 
@@ -264,11 +261,10 @@ int device_display_change_state(display_state_e state)
                                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;
+               if (ret < 0)
+                       return ret;
 //LCOV_EXCL_STOP
-               else
+               else
                        privilege = 1;
        }
 
index 2a541d4..58c1bbf 100755 (executable)
@@ -87,8 +87,6 @@ static struct _lock_timeout {
        .padding = LOCK_CPU_PADDING_TIMEOUT,
 };
 
-static int privilege = -1;
-
 static char *get_state_str(display_state_e state)
 {
        switch (state) {
@@ -347,9 +345,7 @@ static int lock_state(display_state_e state, unsigned int flag, int timeout_ms)
        char *arr[4];
        char str_timeout[32];
        int ret;
-
-       if (privilege == 0)
-               return -EACCES;
+       static int privilege = -1;
 
        if (flag & GOTO_STATE_NOW)
                arr[1] = STR_GOTOSTATENOW;
@@ -372,10 +368,11 @@ static int lock_state(display_state_e state, unsigned int flag, int timeout_ms)
                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; //LCOV_EXCL_LINE System Error
-               } else
+//LCOV_EXCL_START System Error
+               if (ret < 0)
+                       return ret;
+//LCOV_EXCL_STOP
+               else
                        privilege = 1;
        }
 
@@ -407,9 +404,7 @@ static int unlock_state(display_state_e state, unsigned int flag)
 {
        char *arr[2];
        int ret;
-
-       if (privilege == 0)
-               return -EACCES;
+       static int privilege = -1;
 
        if (flag == PM_SLEEP_MARGIN)
                arr[1] = STR_SLEEP_MARGIN;
@@ -427,11 +422,10 @@ static int unlock_state(display_state_e state, unsigned int flag)
                                DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
                                METHOD_UNLOCK_STATE, "ss", arr);
 //LCOV_EXCL_START System Error
-               if (ret == -EACCES || ret == -ECOMM || ret == -EPERM) {
-                       privilege = 0;
-                       return -EACCES;
+               if (ret < 0)
+                       return ret;
 //LCOV_EXCL_STOP
-               else
+               else
                        privilege = 1;
        }