Resolve Dbus Poweroff Issue 70/218370/4 submit/tizen/20191127.063918
authorAmritanshu <a.pandia1@samsung.com>
Thu, 21 Nov 2019 13:31:07 +0000 (19:01 +0530)
committerAmritanshu <a.pandia1@samsung.com>
Fri, 22 Nov 2019 08:02:38 +0000 (13:32 +0530)
Change-Id: I30a39242c3e1e4f3d6ded250e3a9fd0611bd0d70
Signed-off-by: Amritanshu <a.pandia1@samsung.com>
src/mobile/home_mgr.c
src/mobile/hw_key.c
src/mobile/starter.c

index 3a006e8..2efcaa8 100644 (file)
@@ -427,7 +427,7 @@ static int _power_off_cb(status_active_key_e key, void *data)
 {
        int val = status_active_get()->sysman_power_off_status;
 
-       if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART) {
+       if (val > VCONFKEY_SYSMAN_POWER_OFF_NONE) {
                s_home_mgr.power_off = 1;
        } else {
                s_home_mgr.power_off = 0;
index 7f400f3..db041c8 100755 (executable)
@@ -34,6 +34,8 @@
 #include "lock_mgr.h"
 #include "status.h"
 #include "process_mgr.h"
+#include <dd-display.h>
+#include <pkgmgr-info.h>
 
 #define APPID_CAMERA "org.tizen.camera-app"
 #define APPID_MUSIC_PLAYER "org.tizen.music-player"
 #define HOME_KEY_TIMER_SEC 0.4
 #define DELAY_TIME_SEC 1.0
 
+#define POWERKEY_LONG_PRESS_TIMER_SEC 0.7
+#define POWERKEY_LCDOFF_TIMER_SEC 0.4
+#define POWERKEY_TIMER_SEC 0.25
+
 enum {
        LAUNCH_BY_HOME_KEY = 0,
        LAUNCH_BY_LONG_PRESS,
@@ -112,6 +118,14 @@ static struct {
        Eina_Bool global_added_flag;
        int home_key_count;
        double home_key_press_timestamp;
+
+       Ecore_Timer *power_long_press_timer;
+       Ecore_Timer *power_release_timer;
+       Eina_Bool is_lcd_on;
+       Eina_Bool is_long_press;
+       int powerkey_count;
+       Eina_Bool is_cancel;
+       Eina_Bool is_home_focused;
 } key_info = {
        .key_up = NULL,
        .key_down = NULL,
@@ -126,13 +140,93 @@ static struct {
        .global_added_flag = EINA_FALSE,
        .home_key_count = 0,
        .home_key_press_timestamp = 0,
+
+       .power_long_press_timer = NULL,
+       .power_release_timer = NULL,
+       .is_lcd_on = EINA_FALSE,
+       .is_long_press = EINA_FALSE,
+       .powerkey_count = 0,
+       .is_cancel = EINA_FALSE,
+       .is_home_focused = EINA_FALSE
 };
 
+static void _destroy_precondition_handlers_for_keygrab(void);
 
+static Eina_Bool _long_press_timer_cb(void* data)
+{
+       key_info.power_long_press_timer = NULL;
+       key_info.is_long_press = EINA_TRUE;
+       key_info.powerkey_count = 0;
 
-static void _destroy_precondition_handlers_for_keygrab(void);
+       if (0 < status_passive_get()->remote_lock_islocked) {
+               _W("remote lock is on top (%d), -> just turn off LCD", status_passive_get()->remote_lock_islocked);
+               return ECORE_CALLBACK_CANCEL;
+       }
+
+       if (key_info.power_release_timer) {
+               ecore_timer_del(key_info.power_release_timer);
+               key_info.power_release_timer = NULL;
+               _D("delete power_release_timer");
+       }
+
+       _D("Inside _long_press_timer_cb");
+       dbus_util_send_poweroff_signal();
+
+       feedback_initialize();
+       feedback_play_type(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_HOLD);
+       feedback_deinitialize();
+
+       return ECORE_CALLBACK_CANCEL;
+}
+
+static Eina_Bool _powerkey_timer_cb(void *data)
+{
+       _W("%s, powerkey count[%d]", __func__, key_info.powerkey_count);
+
+       key_info.power_release_timer = NULL;
 
+       if (VCONFKEY_PM_KEY_LOCK == status_passive_get()->pm_key_ignore) {
+               _E("Critical Low Batt Clock Mode");
+               key_info.powerkey_count = 0;
+               if (key_info.is_lcd_on) {
+                       _W("just turn off LCD");
+                       display_change_state(LCD_OFF);
+               } else {
+                       _W("just turn on LCD by powerkey.. starter ignore powerkey operation");
+               }
+               return ECORE_CALLBACK_CANCEL;
+       }
+
+       if (key_info.is_lcd_on) {
+               if (VCONFKEY_PM_STATE_LCDOFF <= status_active_get()->pm_state) {
+                       _E("Already lcd state was changed while powerkey op. starter ignore powerkey operation");
+                       return ECORE_CALLBACK_CANCEL;
+               }
+       } else {
+               _W("just turn on LCD by powerkey.. starter ignore powerkey operation");
+               return ECORE_CALLBACK_CANCEL;
+       }
+
+       if (VCONFKEY_CALL_VOICE_ACTIVE == status_passive_get()->call_state) {
+               _W("call state is ->[%d] just turn off LCD", VCONFKEY_CALL_VOICE_ACTIVE);
+               display_change_state(LCD_OFF);
+               return ECORE_CALLBACK_CANCEL;
+       }
+
+       if (VCONFKEY_IDLE_LOCK == status_passive_get()->idle_lock_state) {
+               _W("lock state is ->[%d] just turn off LCD", VCONFKEY_IDLE_LOCK);
+               display_change_state(LCD_OFF);
+               return ECORE_CALLBACK_CANCEL;
+       }
+
+       if (0 < status_passive_get()->remote_lock_islocked) {
+               _W("remote lock is on top (%d), -> just turn off LCD", status_passive_get()->remote_lock_islocked);
+               display_change_state(LCD_OFF);
+               return ECORE_CALLBACK_CANCEL;
+       }
 
+       return ECORE_CALLBACK_CANCEL;
+}
 
 static void _cancel_key_events(void)
 {
@@ -423,6 +517,50 @@ static Eina_Bool _key_release_cb(void *data, int type, void *event)
                return ECORE_CALLBACK_RENEW;
        }
 
+       if (!strcmp(ev->keyname, key_name[KEY_POWER])) {
+               _W("POWER Key is released");
+
+               if (key_info.power_long_press_timer) {
+                       ecore_timer_del(key_info.power_long_press_timer);
+                       key_info.power_long_press_timer = NULL;
+                       _D("delete long press timer");
+               }
+
+               // Check powerkey timer
+               if (key_info.power_release_timer) {
+                       ecore_timer_del(key_info.power_release_timer);
+                       key_info.power_release_timer = NULL;
+                       _D("delete powerkey timer");
+               }
+
+               // Cancel key operation
+               if (EINA_TRUE == key_info.is_cancel) {
+                       _D("Cancel key is activated");
+                       key_info.is_cancel = EINA_FALSE;
+                       key_info.powerkey_count = 0; //initialize powerkey count
+                       return ECORE_CALLBACK_RENEW;
+               }
+
+               // Check long press operation
+               if (key_info.is_long_press) {
+                       _D("ignore power key release by long press");
+                       key_info.is_long_press = EINA_FALSE;
+                       return ECORE_CALLBACK_RENEW;
+               }
+
+               if (key_info.is_lcd_on) {
+                       _D("lcd on --> [%f]sec timer", POWERKEY_TIMER_SEC);
+                       key_info.power_release_timer = ecore_timer_add(POWERKEY_TIMER_SEC, _powerkey_timer_cb, NULL);
+               } else {
+                       _D("lcd off --> [%f]sec timer", POWERKEY_LCDOFF_TIMER_SEC);
+                       key_info.power_release_timer = ecore_timer_add(POWERKEY_LCDOFF_TIMER_SEC, _powerkey_timer_cb, NULL);
+               }
+               if (!key_info.power_release_timer) {
+                       _E("Critical, cannot add a timer for powerkey");
+               }
+               return ECORE_CALLBACK_RENEW;
+       }
+
        /* Priority 1 : Cancel event */
        if (!strcmp(ev->keyname, key_name[KEY_CANCEL])) {
                _D("CANCEL Key is released");
@@ -498,8 +636,54 @@ static Eina_Bool _key_press_cb(void *data, int type, void *event)
                return ECORE_CALLBACK_RENEW;
        }
 
+       /* Check for Power off */
+       if (!strcmp(ev->keyname, key_name[KEY_POWER])) {
+
+               int status = 0;
+
+               _W("POWER Key is pressed");
+
+               /**
+                * lcd status
+                * 1 : lcd normal
+                * 2 : lcd dim
+                * 3 : lcd off
+                * 4 : suspend
+                */
+               if (VCONFKEY_PM_STATE_LCDDIM >= status_active_get()->pm_state) {
+                       key_info.is_lcd_on = EINA_TRUE;
+               } else if (VCONFKEY_PM_STATE_LCDOFF <= status_active_get()->pm_state) {
+                       key_info.is_lcd_on = EINA_FALSE;
+               }
+
+               key_info.powerkey_count++;
+               _W("powerkey count : %d", key_info.powerkey_count);
+
+               if (key_info.power_release_timer) {
+                       ecore_timer_del(key_info.power_release_timer);
+                       key_info.power_release_timer = NULL;
+               }
+
+               if (key_info.power_long_press_timer) {
+                       ecore_timer_del(key_info.power_long_press_timer);
+                       key_info.power_long_press_timer = NULL;
+               }
+
+               key_info.is_long_press = EINA_FALSE;
+               key_info.power_long_press_timer = ecore_timer_add(POWERKEY_LONG_PRESS_TIMER_SEC, _long_press_timer_cb, NULL);
+               if (!key_info.power_long_press_timer) {
+                       _E("Failed to add power_long_press_timer");
+               }
+
+               status = aul_app_get_status("org.tizen.homescreen-efl");
+               key_info.is_home_focused = (status == STATUS_FOCUS) ? EINA_TRUE : EINA_FALSE;
+               _D("home focus status : %d", key_info.is_home_focused);
+
+               return ECORE_CALLBACK_RENEW;
+       }
+
        /* Priority 1 : Cancel */
-       /*              every reserved events have to be canceld when cancel key is pressed */
+       /* every reserved events have to be canceld when cancel key is pressed */
        if (!strcmp(ev->keyname, key_name[KEY_CANCEL])) {
                _D("Cancel button is pressed");
                key_info.cancel = EINA_TRUE;
index 2618211..842fa1c 100755 (executable)
@@ -62,8 +62,7 @@ static int _power_off_cb(status_active_key_e key, void *data)
 {
        int val = status_active_get()->sysman_power_off_status;
 
-       if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT
-               || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART) {
+       if (val > VCONFKEY_SYSMAN_POWER_OFF_NONE) {
            _D("_power_off_cb : Terminated...");
            elm_exit();
        }