Fix not to send duplcated reply
[platform/core/system/system-popup.git] / src / power / power.c
index 8c39e60..d546f49 100644 (file)
@@ -30,7 +30,7 @@
 #define METHOD_LOCK_TIMEOUT_INPUT "LockTimeoutInput"
 
 static const struct popup_ops power_lock_expired_ops;
-static bool result_sended;
+static int button_id = -1;
 static char *request_id;
 
 enum button_selected {
@@ -45,11 +45,6 @@ static void send_result(int result)
        char buf[8];
        char *param[2];
 
-       if (result_sended)
-               return;
-
-       result_sended = true;
-
        param[0] = request_id;
        snprintf(buf, sizeof(buf), "%d", result);
        param[1] = buf;
@@ -60,7 +55,7 @@ static void send_result(int result)
                        METHOD_LOCK_TIMEOUT_INPUT,
                        "si", param);
        if (ret < 0)
-               _E("Failed to deliver the result (%d)", ret);
+               _E("Failed to deliver the result: %d", ret);
 }
 
 static int power_lock_expired_get_content(const struct popup_ops *ops, char *content, unsigned int len)
@@ -75,19 +70,19 @@ static int power_lock_expired_get_content(const struct popup_ops *ops, char *con
 
        ret = get_object_by_ops(ops, &obj);
        if (ret < 0) {
-               _E("Failed to get object (%d)", ret);
+               _E("Failed to get object: %d", ret);
                return -ENOENT;
        }
 
        pid_str = (char *)bundle_get_val(obj->b, APP_PID);
        if (!pid_str) {
-               _E("Failed to get app pid");
+               _E("Failed to get app pid.");
                return -ENOENT;
        }
 
        request_id = (char *)bundle_get_val(obj->b, REQ_ID);
        if (!request_id) {
-               _E("Failed to get request id");
+               _E("Failed to get request id.");
                return -ENOENT;
        }
 
@@ -96,7 +91,7 @@ static int power_lock_expired_get_content(const struct popup_ops *ops, char *con
        if (ret != APP_MANAGER_ERROR_NONE) {
                name = (char *)bundle_get_val(obj->b, APP_COMM);
                if (!name) {
-                       _E("Failed to get app command");
+                       _E("Failed to get app command.");
                return -ENOENT;
        }
        }
@@ -111,8 +106,9 @@ static int power_lock_expired_get_content(const struct popup_ops *ops, char *con
 
 static void power_lock_expired_allow_app(const struct popup_ops *ops)
 {
-       _I("Allow is selected");
+       _I("Allow is selected.");
 
+       button_id = ALLOW_APP;
        unload_simple_popup(ops);
 
        send_result(ALLOW_APP);
@@ -122,8 +118,9 @@ static void power_lock_expired_allow_app(const struct popup_ops *ops)
 
 static void power_lock_expired_close_app(const struct popup_ops *ops)
 {
-       _I("Close is selected");
+       _I("Close is selected.");
 
+       button_id = CLOSE_APP;
        unload_simple_popup(ops);
 
        send_result(CLOSE_APP);
@@ -133,8 +130,8 @@ static void power_lock_expired_close_app(const struct popup_ops *ops)
 
 static void power_lock_expired_terminate(const struct popup_ops *ops)
 {
-       send_result(CLOSE_APP);
-       result_sended = false;
+       if (button_id == -1)
+               send_result(CLOSE_APP);
 }
 
 static const struct popup_ops power_lock_expired_ops = {