From ad194720c0b7988a4528aed2fb197192ba2fc7d5 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Wed, 14 Aug 2019 17:22:50 +0900 Subject: [PATCH 01/16] dbus: modified to use revised api Change-Id: I781eb867a01f460ff9022a3ac59497469b621e47 Signed-off-by: sanghyeok.oh --- plugins/iot/display/core.c | 15 +++++++++------ plugins/iot/display/key-filter.c | 15 +++++++++------ plugins/mobile/display/core.c | 15 +++++++++------ plugins/mobile/display/key-filter.c | 15 +++++++++------ plugins/tv/display/core.c | 15 +++++++++------ plugins/tv/display/key-filter.c | 15 +++++++++------ plugins/tv/display/state-tv.c | 15 ++++++++++----- plugins/wearable/display/core.c | 15 +++++++++------ plugins/wearable/display/enhance.c | 3 ++- plugins/wearable/display/key-filter.c | 15 +++++++++------ src/battery/battery-time.c | 7 +++++-- src/battery/power-supply.c | 13 +++++++++---- src/display/ambient-mode.c | 3 ++- src/dump/dump.c | 6 ++++-- src/extcon/cradle.c | 3 ++- src/extcon/earjack.c | 3 ++- src/extcon/hdmi.c | 3 ++- src/led/torch.c | 3 ++- src/power/power-handler.c | 3 ++- src/time/time-handler.c | 5 +++-- src/usb/usb-dbus.c | 18 ++++++++++++------ src/usbhost/usb-host.c | 9 +++++---- 22 files changed, 134 insertions(+), 80 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index b9d7d14..7522866 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -229,10 +229,11 @@ static void set_process_active(bool flag, pid_t pid) return; /* Send dbug to resourced */ - ret = dbus_handle_broadcast_dbus_signal_var(RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - RESOURCED_METHOD_ACTIVE, - g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); + ret = dbus_handle_broadcast_dbus_signal(NULL, + RESOURCED_PATH_PROCESS, + RESOURCED_INTERFACE_PROCESS, + RESOURCED_METHOD_ACTIVE, + g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); if (ret < 0) _E("Failed to send dbus signal to resourced."); } @@ -310,7 +311,8 @@ static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) signal = lcdon_sig_lookup[type]; _I("lcdstep : Broadcast signal(%s:%s).", signal, str); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, g_variant_new("(s)", str)); @@ -341,7 +343,8 @@ static void broadcast_lcd_off(enum signal_type type, enum device_flags flags) str = UNKNOWN_STR; _I("lcdstep : Broadcast signal(%s).", signal); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, g_variant_new("(s)", str)); diff --git a/plugins/iot/display/key-filter.c b/plugins/iot/display/key-filter.c index 4dd1080..b55e311 100644 --- a/plugins/iot/display/key-filter.c +++ b/plugins/iot/display/key-filter.c @@ -180,18 +180,20 @@ static inline void check_key_pair(int code, int new, int *old) static inline void broadcast_lcdon_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(DEVICED_PATH_DISPLAY, + dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDON_BY_POWERKEY, - NULL, NULL); + NULL); } static inline void broadcast_lcdoff_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(DEVICED_PATH_DISPLAY, + dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDOFF_BY_POWERKEY, - NULL, NULL); + NULL); } static inline bool switch_on_lcd(void) @@ -402,10 +404,11 @@ static void sound_vibrate_hardkey(void) /* device notify(vibrator) */ /* sound(dbus) */ /* Need to notify to deviced-vibrator. deviced-vibrator receives ChangedHardKey signal */ - dbus_handle_broadcast_dbus_signal(DEVICED_PATH_KEY, + dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_KEY, DEVICED_INTERFACE_KEY, SIGNAL_CHANGE_HARDKEY, - NULL, NULL); + NULL); } static void process_hardkey_backlight(struct input_event *pinput) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index f252e4e..c2bafa2 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -230,10 +230,11 @@ static void set_process_active(bool flag, pid_t pid) return; /* Send dbug to resourced */ - ret = dbus_handle_broadcast_dbus_signal_var(RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - RESOURCED_METHOD_ACTIVE, - g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); + ret = dbus_handle_broadcast_dbus_signal(NULL, + RESOURCED_PATH_PROCESS, + RESOURCED_INTERFACE_PROCESS, + RESOURCED_METHOD_ACTIVE, + g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); if (ret < 0) _E("Failed to send dbus signal to resourced."); } @@ -311,7 +312,8 @@ static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) signal = lcdon_sig_lookup[type]; _I("lcdstep : Broadcast signal(%s:%s).", signal, str); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, g_variant_new("(s)", str)); @@ -342,7 +344,8 @@ static void broadcast_lcd_off(enum signal_type type, enum device_flags flags) str = UNKNOWN_STR; _I("lcdstep : Broadcast signal(%s).", signal); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, g_variant_new("(s)", str)); diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index 52010d2..a407b03 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -180,18 +180,20 @@ static inline void check_key_pair(int code, int new, int *old) static inline void broadcast_lcdon_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(DEVICED_PATH_DISPLAY, + dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDON_BY_POWERKEY, - NULL, NULL); + NULL); } static inline void broadcast_lcdoff_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(DEVICED_PATH_DISPLAY, + dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDOFF_BY_POWERKEY, - NULL, NULL); + NULL); } static inline bool switch_on_lcd(void) @@ -460,10 +462,11 @@ static void sound_vibrate_hardkey(void) /* device notify(vibrator) */ /* sound(dbus) */ /* Need to notify to deviced-vibrator. deviced-vibrator receives ChangedHardKey signal */ - dbus_handle_broadcast_dbus_signal(DEVICED_PATH_KEY, + dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_KEY, DEVICED_INTERFACE_KEY, SIGNAL_CHANGE_HARDKEY, - NULL, NULL); + NULL); } static void process_hardkey_backlight(struct input_event *pinput) diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 5f07dde..920245f 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -231,10 +231,11 @@ static void set_process_active(bool flag, pid_t pid) return; /* Send dbug to resourced */ - ret = dbus_handle_broadcast_dbus_signal_var(RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - RESOURCED_METHOD_ACTIVE, - g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); + ret = dbus_handle_broadcast_dbus_signal(NULL, + RESOURCED_PATH_PROCESS, + RESOURCED_INTERFACE_PROCESS, + RESOURCED_METHOD_ACTIVE, + g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); if (ret < 0) _E("Failed to send dbus signal to resourced."); } @@ -312,7 +313,8 @@ static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) signal = lcdon_sig_lookup[type]; _I("lcdstep : Broadcast signal(%s:%s).", signal, str); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, g_variant_new("(s)", str)); @@ -343,7 +345,8 @@ static void broadcast_lcd_off(enum signal_type type, enum device_flags flags) str = UNKNOWN_STR; _I("lcdstep : Broadcast signal(%s).", signal); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, g_variant_new("(s)", str)); diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 4dd1080..b55e311 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -180,18 +180,20 @@ static inline void check_key_pair(int code, int new, int *old) static inline void broadcast_lcdon_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(DEVICED_PATH_DISPLAY, + dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDON_BY_POWERKEY, - NULL, NULL); + NULL); } static inline void broadcast_lcdoff_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(DEVICED_PATH_DISPLAY, + dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDOFF_BY_POWERKEY, - NULL, NULL); + NULL); } static inline bool switch_on_lcd(void) @@ -402,10 +404,11 @@ static void sound_vibrate_hardkey(void) /* device notify(vibrator) */ /* sound(dbus) */ /* Need to notify to deviced-vibrator. deviced-vibrator receives ChangedHardKey signal */ - dbus_handle_broadcast_dbus_signal(DEVICED_PATH_KEY, + dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_KEY, DEVICED_INTERFACE_KEY, SIGNAL_CHANGE_HARDKEY, - NULL, NULL); + NULL); } static void process_hardkey_backlight(struct input_event *pinput) diff --git a/plugins/tv/display/state-tv.c b/plugins/tv/display/state-tv.c index 8753a8d..e50463c 100644 --- a/plugins/tv/display/state-tv.c +++ b/plugins/tv/display/state-tv.c @@ -129,7 +129,8 @@ static int lcdon_pre(void *data) if (pm_cur_state == S_STANDBY) { _I("send pre state change NORMAL"); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_PRE_CHANGE_STATE, g_variant_new("(s)", states[S_LCDON].name)); @@ -146,7 +147,8 @@ static int lcdon_post(void *data) { int ret; - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_CHANGE_STATE, g_variant_new("(s)", states[S_LCDON].name)); @@ -219,7 +221,8 @@ static int lcdoff_post(void *data) int ret; /* broadcast to other application */ - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_CHANGE_STATE, g_variant_new("(s)", states[S_LCDOFF].name)); @@ -298,7 +301,8 @@ static int standby_post(void *data) int ret; /* broadcast to other application */ - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_CHANGE_STATE, g_variant_new("(s)", states[S_STANDBY].name)); @@ -399,7 +403,8 @@ static int suspend_post(void *data) _E("Fail to change state to next_state(%s)", states[cond].name); /* Broadcast pre-wakeup signal */ - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_POWER, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_POWER, DEVICED_INTERFACE_POWER, SIGNAL_PRE_WAKEUP, g_variant_new("(i)", 0)); diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index d5e35f9..ea99bab 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -230,10 +230,11 @@ static void set_process_active(bool flag, pid_t pid) return; /* Send dbug to resourced */ - ret = dbus_handle_broadcast_dbus_signal_var(RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - RESOURCED_METHOD_ACTIVE, - g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); + ret = dbus_handle_broadcast_dbus_signal(NULL, + RESOURCED_PATH_PROCESS, + RESOURCED_INTERFACE_PROCESS, + RESOURCED_METHOD_ACTIVE, + g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); if (ret < 0) _E("Failed to send dbus signal to resourced."); } @@ -311,7 +312,8 @@ static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) signal = lcdon_sig_lookup[type]; _I("lcdstep : Broadcast signal(%s:%s).", signal, str); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, g_variant_new("(s)", str)); @@ -342,7 +344,8 @@ static void broadcast_lcd_off(enum signal_type type, enum device_flags flags) str = UNKNOWN_STR; _I("lcdstep : Broadcast signal(%s).", signal); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, g_variant_new("(s)", str)); diff --git a/plugins/wearable/display/enhance.c b/plugins/wearable/display/enhance.c index a771cb4..51b9c84 100644 --- a/plugins/wearable/display/enhance.c +++ b/plugins/wearable/display/enhance.c @@ -154,7 +154,8 @@ static void enhance_init(void *data) state = enhance_update_state(); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, "Enhance", g_variant_new("(i)", state)); diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 6d2b864..5ae407e 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -199,18 +199,20 @@ static inline void check_key_pair(int code, int new, int *old) static inline void broadcast_lcdon_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(DEVICED_PATH_DISPLAY, + dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDON_BY_POWERKEY, - NULL, NULL); + NULL); } static inline void broadcast_lcdoff_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(DEVICED_PATH_DISPLAY, + dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDOFF_BY_POWERKEY, - NULL, NULL); + NULL); } static inline bool switch_on_lcd(enum device_flags flags) @@ -501,10 +503,11 @@ static void sound_vibrate_hardkey(void) /* device notify(vibrator) */ /* sound(dbus) */ /* Need to notify to deviced-vibrator. deviced-vibrator receives ChangedHardKey signal */ - dbus_handle_broadcast_dbus_signal(DEVICED_PATH_KEY, + dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_KEY, DEVICED_INTERFACE_KEY, SIGNAL_CHANGE_HARDKEY, - NULL, NULL); + NULL); } static void process_hardkey_backlight(struct input_event *pinput) diff --git a/src/battery/battery-time.c b/src/battery/battery-time.c index 75db00d..5b86e63 100644 --- a/src/battery/battery-time.c +++ b/src/battery/battery-time.c @@ -225,8 +225,11 @@ static void broadcast_battery_time(char *signal, int time) if (!signal) return; - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, - signal, g_variant_new("(i)", time)); + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_BATTERY, + DEVICED_INTERFACE_BATTERY, + signal, + g_variant_new("(i)", time)); if (ret < 0) _E("Failed to send dbus signal(%s)", signal); } diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 3d8bcb1..bbc61e7 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -150,7 +150,8 @@ static int power_supply_broadcast_str(char *sig, char *status) str = status; - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_BATTERY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, sig, g_variant_new("(s)", str)); @@ -182,8 +183,11 @@ static void abnormal_popup_timer_init(void) static void health_status_broadcast(void) { - dbus_handle_broadcast_dbus_signal(DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, - SIGNAL_TEMP_GOOD, NULL, NULL); + dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_BATTERY, + DEVICED_INTERFACE_BATTERY, + SIGNAL_TEMP_GOOD, + NULL); } @@ -419,7 +423,8 @@ int power_supply_broadcast(char *sig, int status) snprintf(sig_old, sizeof(sig_old), "%s", sig); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_BATTERY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, sig, g_variant_new("(i)", status)); diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index fdec29b..8de1c39 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -51,7 +51,8 @@ void broadcast_ambient_state(int state) char *signal; signal = (state == true ? SIGNAL_ALPM_ON : SIGNAL_ALPM_OFF); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_DISPLAY, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, NULL); diff --git a/src/dump/dump.c b/src/dump/dump.c index c082fda..b3c29a1 100644 --- a/src/dump/dump.c +++ b/src/dump/dump.c @@ -39,8 +39,10 @@ static void send_dump_signal(char *signal) pid = getpid(); - ret = dbus_handle_broadcast_dbus_signal_var(DUMP_SERVICE_OBJECT_PATH, - DUMP_SERVICE_INTERFACE_NAME, signal, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DUMP_SERVICE_OBJECT_PATH, + DUMP_SERVICE_INTERFACE_NAME, + signal, g_variant_new("(i)", pid)); if (ret < 0) _E("Failed to send dbus signal(%s)", signal); diff --git a/src/extcon/cradle.c b/src/extcon/cradle.c index 282cd79..1c46ea3 100644 --- a/src/extcon/cradle.c +++ b/src/extcon/cradle.c @@ -44,7 +44,8 @@ static void cradle_send_broadcast(int status) _I("Broadcast cradle status(%d).", status); old = status; - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_SYSNOTI, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, SIGNAL_CRADLE_STATE, g_variant_new("(i)", status)); diff --git a/src/extcon/earjack.c b/src/extcon/earjack.c index d02aeb0..8f76f88 100644 --- a/src/extcon/earjack.c +++ b/src/extcon/earjack.c @@ -41,7 +41,8 @@ static void earjack_send_broadcast(int status) _I("Broadcast earjack status(%d).", status); old = status; - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_SYSNOTI, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, SIGNAL_EARJACK_STATE, g_variant_new("(i)", status)); diff --git a/src/extcon/hdmi.c b/src/extcon/hdmi.c index 8ab10e5..e145132 100644 --- a/src/extcon/hdmi.c +++ b/src/extcon/hdmi.c @@ -41,7 +41,8 @@ static void hdmi_send_broadcast(int status) _I("Broadcast hdmi status(%d)", status); old = status; - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_SYSNOTI, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, SIGNAL_HDMI_STATE, g_variant_new("(i)", status)); diff --git a/src/led/torch.c b/src/led/torch.c index 94acf50..4b1e807 100644 --- a/src/led/torch.c +++ b/src/led/torch.c @@ -46,7 +46,8 @@ static void flash_state_broadcast(int val) { int ret; - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_LED, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_LED, DEVICED_INTERFACE_LED, SIGNAL_FLASH_STATE, g_variant_new("(i)", val)); diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 41aac63..e6ce746 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -450,7 +450,8 @@ static void poweroff_send_broadcast(int status) old = status; /* Need to notify to deviced-vibrator. deviced-vibrator receives ChangeState signal for POWEROFF_TYPE_DIRECT and POWEROFF_TYPE_RESTART */ - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_POWEROFF, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, SIGNAL_POWEROFF_STATE, g_variant_new("(i)", status)); diff --git a/src/time/time-handler.c b/src/time/time-handler.c index b49e91c..a706aa0 100644 --- a/src/time/time-handler.c +++ b/src/time/time-handler.c @@ -227,8 +227,9 @@ int set_timezone_action(int argc, char **argv) static void time_changed_broadcast(void) { - dbus_handle_broadcast_dbus_signal(DEVICED_PATH_TIME, DEVICED_INTERFACE_TIME, - TIME_CHANGE_SIGNAL, NULL, NULL); + dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_TIME, DEVICED_INTERFACE_TIME, + TIME_CHANGE_SIGNAL, NULL); } static int timerfd_check_start(void) diff --git a/src/usb/usb-dbus.c b/src/usb/usb-dbus.c index fcd9068..eefb98f 100644 --- a/src/usb/usb-dbus.c +++ b/src/usb/usb-dbus.c @@ -76,8 +76,10 @@ void broadcast_usb_config_enabled(int state) _I("USB config(%d) enabled.", state); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_USB, - DEVICED_INTERFACE_USB, SIGNAL_CONFIG_ENABLED, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_USB, + DEVICED_INTERFACE_USB, + SIGNAL_CONFIG_ENABLED, g_variant_new("(i)", state)); if (ret < 0) _E("Failed to send dbus signal."); @@ -96,8 +98,10 @@ void broadcast_usb_state_changed(void) _I("USB state(%u) changed.", state); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_USB, - DEVICED_INTERFACE_USB, SIGNAL_STATE_CHANGED, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_USB, + DEVICED_INTERFACE_USB, + SIGNAL_STATE_CHANGED, g_variant_new("(u)", state)); if (ret < 0) _E("Failed to send dbus signal."); @@ -116,8 +120,10 @@ void broadcast_usb_mode_changed(void) _I("USB mode(%u) changed.", mode); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_USB, - DEVICED_INTERFACE_USB, SIGNAL_MODE_CHANGED, + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_USB, + DEVICED_INTERFACE_USB, + SIGNAL_MODE_CHANGED, g_variant_new("(u)", mode)); if (ret < 0) _E("Failed to send dbus signal(%s)", SIGNAL_MODE_CHANGED); diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index d3d46c2..76e7f72 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -189,10 +189,11 @@ static void broadcast_usbhost_signal(enum usbhost_state state, (usbhost->product ? usbhost->product : ""), (usbhost->serial ? usbhost->serial : "")); - ret = dbus_handle_broadcast_dbus_signal_var(DEVICED_PATH_USBHOST, - DEVICED_INTERFACE_USBHOST, - SIGNAL_USB_HOST_CHANGED, - param); + ret = dbus_handle_broadcast_dbus_signal(NULL, + DEVICED_PATH_USBHOST, + DEVICED_INTERFACE_USBHOST, + SIGNAL_USB_HOST_CHANGED, + param); if (ret < 0) _E("Failed to send dbus signal(%s)", SIGNAL_USB_HOST_CHANGED); } -- 2.7.4 From 65ab172e48078e739daf9f018d83d2e531651c92 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Fri, 16 Aug 2019 10:56:36 +0900 Subject: [PATCH 02/16] dbus: modified to use renamed api change 'dbus_handle_broadcast_dbus_signal' to 'dbus_handle_emit_dbus_signal' Change-Id: If35e9bc2bb52c15585a57a8a012be3bedadd79ff Signed-off-by: sanghyeok.oh --- plugins/iot/display/core.c | 6 +++--- plugins/iot/display/key-filter.c | 6 +++--- plugins/mobile/display/core.c | 6 +++--- plugins/mobile/display/key-filter.c | 6 +++--- plugins/tv/display/core.c | 6 +++--- plugins/tv/display/key-filter.c | 6 +++--- plugins/tv/display/state-tv.c | 10 +++++----- plugins/wearable/display/core.c | 6 +++--- plugins/wearable/display/enhance.c | 2 +- plugins/wearable/display/key-filter.c | 6 +++--- src/battery/battery-time.c | 2 +- src/battery/power-supply.c | 6 +++--- src/display/ambient-mode.c | 2 +- src/dump/dump.c | 2 +- src/extcon/cradle.c | 2 +- src/extcon/earjack.c | 2 +- src/extcon/hdmi.c | 2 +- src/led/torch.c | 2 +- src/power/power-handler.c | 2 +- src/time/time-handler.c | 2 +- src/usb/usb-dbus.c | 6 +++--- src/usbhost/usb-host.c | 2 +- 22 files changed, 46 insertions(+), 46 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 7522866..5f08790 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -229,7 +229,7 @@ static void set_process_active(bool flag, pid_t pid) return; /* Send dbug to resourced */ - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, RESOURCED_PATH_PROCESS, RESOURCED_INTERFACE_PROCESS, RESOURCED_METHOD_ACTIVE, @@ -311,7 +311,7 @@ static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) signal = lcdon_sig_lookup[type]; _I("lcdstep : Broadcast signal(%s:%s).", signal, str); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, @@ -343,7 +343,7 @@ static void broadcast_lcd_off(enum signal_type type, enum device_flags flags) str = UNKNOWN_STR; _I("lcdstep : Broadcast signal(%s).", signal); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, diff --git a/plugins/iot/display/key-filter.c b/plugins/iot/display/key-filter.c index b55e311..8b35f7c 100644 --- a/plugins/iot/display/key-filter.c +++ b/plugins/iot/display/key-filter.c @@ -180,7 +180,7 @@ static inline void check_key_pair(int code, int new, int *old) static inline void broadcast_lcdon_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(NULL, + dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDON_BY_POWERKEY, @@ -189,7 +189,7 @@ static inline void broadcast_lcdon_by_powerkey(void) static inline void broadcast_lcdoff_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(NULL, + dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDOFF_BY_POWERKEY, @@ -404,7 +404,7 @@ static void sound_vibrate_hardkey(void) /* device notify(vibrator) */ /* sound(dbus) */ /* Need to notify to deviced-vibrator. deviced-vibrator receives ChangedHardKey signal */ - dbus_handle_broadcast_dbus_signal(NULL, + dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_KEY, DEVICED_INTERFACE_KEY, SIGNAL_CHANGE_HARDKEY, diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index c2bafa2..9d3f642 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -230,7 +230,7 @@ static void set_process_active(bool flag, pid_t pid) return; /* Send dbug to resourced */ - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, RESOURCED_PATH_PROCESS, RESOURCED_INTERFACE_PROCESS, RESOURCED_METHOD_ACTIVE, @@ -312,7 +312,7 @@ static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) signal = lcdon_sig_lookup[type]; _I("lcdstep : Broadcast signal(%s:%s).", signal, str); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, @@ -344,7 +344,7 @@ static void broadcast_lcd_off(enum signal_type type, enum device_flags flags) str = UNKNOWN_STR; _I("lcdstep : Broadcast signal(%s).", signal); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index a407b03..3462aa7 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -180,7 +180,7 @@ static inline void check_key_pair(int code, int new, int *old) static inline void broadcast_lcdon_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(NULL, + dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDON_BY_POWERKEY, @@ -189,7 +189,7 @@ static inline void broadcast_lcdon_by_powerkey(void) static inline void broadcast_lcdoff_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(NULL, + dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDOFF_BY_POWERKEY, @@ -462,7 +462,7 @@ static void sound_vibrate_hardkey(void) /* device notify(vibrator) */ /* sound(dbus) */ /* Need to notify to deviced-vibrator. deviced-vibrator receives ChangedHardKey signal */ - dbus_handle_broadcast_dbus_signal(NULL, + dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_KEY, DEVICED_INTERFACE_KEY, SIGNAL_CHANGE_HARDKEY, diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 920245f..79bd919 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -231,7 +231,7 @@ static void set_process_active(bool flag, pid_t pid) return; /* Send dbug to resourced */ - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, RESOURCED_PATH_PROCESS, RESOURCED_INTERFACE_PROCESS, RESOURCED_METHOD_ACTIVE, @@ -313,7 +313,7 @@ static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) signal = lcdon_sig_lookup[type]; _I("lcdstep : Broadcast signal(%s:%s).", signal, str); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, @@ -345,7 +345,7 @@ static void broadcast_lcd_off(enum signal_type type, enum device_flags flags) str = UNKNOWN_STR; _I("lcdstep : Broadcast signal(%s).", signal); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index b55e311..8b35f7c 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -180,7 +180,7 @@ static inline void check_key_pair(int code, int new, int *old) static inline void broadcast_lcdon_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(NULL, + dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDON_BY_POWERKEY, @@ -189,7 +189,7 @@ static inline void broadcast_lcdon_by_powerkey(void) static inline void broadcast_lcdoff_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(NULL, + dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDOFF_BY_POWERKEY, @@ -404,7 +404,7 @@ static void sound_vibrate_hardkey(void) /* device notify(vibrator) */ /* sound(dbus) */ /* Need to notify to deviced-vibrator. deviced-vibrator receives ChangedHardKey signal */ - dbus_handle_broadcast_dbus_signal(NULL, + dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_KEY, DEVICED_INTERFACE_KEY, SIGNAL_CHANGE_HARDKEY, diff --git a/plugins/tv/display/state-tv.c b/plugins/tv/display/state-tv.c index e50463c..b99ea0f 100644 --- a/plugins/tv/display/state-tv.c +++ b/plugins/tv/display/state-tv.c @@ -129,7 +129,7 @@ static int lcdon_pre(void *data) if (pm_cur_state == S_STANDBY) { _I("send pre state change NORMAL"); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_PRE_CHANGE_STATE, @@ -147,7 +147,7 @@ static int lcdon_post(void *data) { int ret; - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_CHANGE_STATE, @@ -221,7 +221,7 @@ static int lcdoff_post(void *data) int ret; /* broadcast to other application */ - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_CHANGE_STATE, @@ -301,7 +301,7 @@ static int standby_post(void *data) int ret; /* broadcast to other application */ - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_CHANGE_STATE, @@ -403,7 +403,7 @@ static int suspend_post(void *data) _E("Fail to change state to next_state(%s)", states[cond].name); /* Broadcast pre-wakeup signal */ - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_POWER, DEVICED_INTERFACE_POWER, SIGNAL_PRE_WAKEUP, diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index ea99bab..3f8c686 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -230,7 +230,7 @@ static void set_process_active(bool flag, pid_t pid) return; /* Send dbug to resourced */ - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, RESOURCED_PATH_PROCESS, RESOURCED_INTERFACE_PROCESS, RESOURCED_METHOD_ACTIVE, @@ -312,7 +312,7 @@ static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) signal = lcdon_sig_lookup[type]; _I("lcdstep : Broadcast signal(%s:%s).", signal, str); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, @@ -344,7 +344,7 @@ static void broadcast_lcd_off(enum signal_type type, enum device_flags flags) str = UNKNOWN_STR; _I("lcdstep : Broadcast signal(%s).", signal); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, diff --git a/plugins/wearable/display/enhance.c b/plugins/wearable/display/enhance.c index 51b9c84..4b60807 100644 --- a/plugins/wearable/display/enhance.c +++ b/plugins/wearable/display/enhance.c @@ -154,7 +154,7 @@ static void enhance_init(void *data) state = enhance_update_state(); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, "Enhance", diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 5ae407e..01e43ff 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -199,7 +199,7 @@ static inline void check_key_pair(int code, int new, int *old) static inline void broadcast_lcdon_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(NULL, + dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDON_BY_POWERKEY, @@ -208,7 +208,7 @@ static inline void broadcast_lcdon_by_powerkey(void) static inline void broadcast_lcdoff_by_powerkey(void) { - dbus_handle_broadcast_dbus_signal(NULL, + dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_LCDOFF_BY_POWERKEY, @@ -503,7 +503,7 @@ static void sound_vibrate_hardkey(void) /* device notify(vibrator) */ /* sound(dbus) */ /* Need to notify to deviced-vibrator. deviced-vibrator receives ChangedHardKey signal */ - dbus_handle_broadcast_dbus_signal(NULL, + dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_KEY, DEVICED_INTERFACE_KEY, SIGNAL_CHANGE_HARDKEY, diff --git a/src/battery/battery-time.c b/src/battery/battery-time.c index 5b86e63..d7bc170 100644 --- a/src/battery/battery-time.c +++ b/src/battery/battery-time.c @@ -225,7 +225,7 @@ static void broadcast_battery_time(char *signal, int time) if (!signal) return; - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, signal, diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index bbc61e7..2bf2db1 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -150,7 +150,7 @@ static int power_supply_broadcast_str(char *sig, char *status) str = status; - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, sig, @@ -183,7 +183,7 @@ static void abnormal_popup_timer_init(void) static void health_status_broadcast(void) { - dbus_handle_broadcast_dbus_signal(NULL, + dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, SIGNAL_TEMP_GOOD, @@ -423,7 +423,7 @@ int power_supply_broadcast(char *sig, int status) snprintf(sig_old, sizeof(sig_old), "%s", sig); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, sig, diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index 8de1c39..7192f44 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -51,7 +51,7 @@ void broadcast_ambient_state(int state) char *signal; signal = (state == true ? SIGNAL_ALPM_ON : SIGNAL_ALPM_OFF); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, diff --git a/src/dump/dump.c b/src/dump/dump.c index b3c29a1..1695628 100644 --- a/src/dump/dump.c +++ b/src/dump/dump.c @@ -39,7 +39,7 @@ static void send_dump_signal(char *signal) pid = getpid(); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DUMP_SERVICE_OBJECT_PATH, DUMP_SERVICE_INTERFACE_NAME, signal, diff --git a/src/extcon/cradle.c b/src/extcon/cradle.c index 1c46ea3..2f37d04 100644 --- a/src/extcon/cradle.c +++ b/src/extcon/cradle.c @@ -44,7 +44,7 @@ static void cradle_send_broadcast(int status) _I("Broadcast cradle status(%d).", status); old = status; - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, SIGNAL_CRADLE_STATE, diff --git a/src/extcon/earjack.c b/src/extcon/earjack.c index 8f76f88..aa40699 100644 --- a/src/extcon/earjack.c +++ b/src/extcon/earjack.c @@ -41,7 +41,7 @@ static void earjack_send_broadcast(int status) _I("Broadcast earjack status(%d).", status); old = status; - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, SIGNAL_EARJACK_STATE, diff --git a/src/extcon/hdmi.c b/src/extcon/hdmi.c index e145132..1a3b2f6 100644 --- a/src/extcon/hdmi.c +++ b/src/extcon/hdmi.c @@ -41,7 +41,7 @@ static void hdmi_send_broadcast(int status) _I("Broadcast hdmi status(%d)", status); old = status; - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, SIGNAL_HDMI_STATE, diff --git a/src/led/torch.c b/src/led/torch.c index 4b1e807..2024ebd 100644 --- a/src/led/torch.c +++ b/src/led/torch.c @@ -46,7 +46,7 @@ static void flash_state_broadcast(int val) { int ret; - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_LED, DEVICED_INTERFACE_LED, SIGNAL_FLASH_STATE, diff --git a/src/power/power-handler.c b/src/power/power-handler.c index e6ce746..4303a4d 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -450,7 +450,7 @@ static void poweroff_send_broadcast(int status) old = status; /* Need to notify to deviced-vibrator. deviced-vibrator receives ChangeState signal for POWEROFF_TYPE_DIRECT and POWEROFF_TYPE_RESTART */ - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, SIGNAL_POWEROFF_STATE, diff --git a/src/time/time-handler.c b/src/time/time-handler.c index a706aa0..82169e2 100644 --- a/src/time/time-handler.c +++ b/src/time/time-handler.c @@ -227,7 +227,7 @@ int set_timezone_action(int argc, char **argv) static void time_changed_broadcast(void) { - dbus_handle_broadcast_dbus_signal(NULL, + dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_TIME, DEVICED_INTERFACE_TIME, TIME_CHANGE_SIGNAL, NULL); } diff --git a/src/usb/usb-dbus.c b/src/usb/usb-dbus.c index eefb98f..b83e64c 100644 --- a/src/usb/usb-dbus.c +++ b/src/usb/usb-dbus.c @@ -76,7 +76,7 @@ void broadcast_usb_config_enabled(int state) _I("USB config(%d) enabled.", state); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_USB, DEVICED_INTERFACE_USB, SIGNAL_CONFIG_ENABLED, @@ -98,7 +98,7 @@ void broadcast_usb_state_changed(void) _I("USB state(%u) changed.", state); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_USB, DEVICED_INTERFACE_USB, SIGNAL_STATE_CHANGED, @@ -120,7 +120,7 @@ void broadcast_usb_mode_changed(void) _I("USB mode(%u) changed.", mode); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_USB, DEVICED_INTERFACE_USB, SIGNAL_MODE_CHANGED, diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 76e7f72..3f95ea9 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -189,7 +189,7 @@ static void broadcast_usbhost_signal(enum usbhost_state state, (usbhost->product ? usbhost->product : ""), (usbhost->serial ? usbhost->serial : "")); - ret = dbus_handle_broadcast_dbus_signal(NULL, + ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_USBHOST, DEVICED_INTERFACE_USBHOST, SIGNAL_USB_HOST_CHANGED, -- 2.7.4 From a7c02a657652b143dea9bedd1061bf9edd30099d Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Mon, 26 Aug 2019 19:58:09 +0900 Subject: [PATCH 03/16] Fix svace issue - check return value before refer Change-Id: I085162d37bc94d5df858454323a142bce3c5f0cd Signed-off-by: Yunmi Ha --- src/battery/lowbat-handler.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 226beb3..b2a491a 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -160,6 +160,8 @@ static int power_execute(void *data) static const struct device_ops *ops; FIND_DEVICE_INT(ops, POWER_OPS_NAME); + if (NOT_SUPPORT_OPS(ops)) + return -EINVAL; return ops->execute(data); } @@ -908,6 +910,9 @@ static int lowbat_probe(void *data) int ret = -EINVAL; FIND_DEVICE_INT(ops, "power_supply"); + if (NOT_SUPPORT_OPS(ops)) + return ret; + ret = ops->probe(data); if (ret == 0) _I("Support lowbat handler."); -- 2.7.4 From bf9160eaaae561158273f08316da80c857960286 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Tue, 27 Aug 2019 10:26:27 +0900 Subject: [PATCH 04/16] Safe umount an sdcard partition (/opt/media/SDCardA1) Change-Id: I7a27f311e1da52a5e8930854ec9fa22f00fbb443 Signed-off-by: Hyotaek Shim --- src/power-shutdown/shutdown.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/power-shutdown/shutdown.c b/src/power-shutdown/shutdown.c index 9c6032d..7e4fa71 100644 --- a/src/power-shutdown/shutdown.c +++ b/src/power-shutdown/shutdown.c @@ -46,6 +46,7 @@ enum { CMD_EXIT, }; +#define UMOUNT_RW_PATH_SDCARD "/opt/media/SDCardA1" #define UMOUNT_RW_PATH_USER "/opt/usr" #define UMOUNT_RW_PATH_SYSTEM "/opt" #define MAX_UMOUNT_KILL_RETRY 4 @@ -60,6 +61,7 @@ static int usage(void) static void umount_partitions(void) { + umount_partition_by_kill(UMOUNT_RW_PATH_SDCARD, MAX_UMOUNT_KILL_RETRY); umount_partition_by_kill(UMOUNT_RW_PATH_USER, MAX_UMOUNT_KILL_RETRY); umount_partition_by_kill(UMOUNT_RW_PATH_SYSTEM, MAX_UMOUNT_KILL_RETRY); } -- 2.7.4 From 85f04968238b4e53653f7b684dde1bc99dce07bd Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 26 Aug 2019 14:39:11 +0900 Subject: [PATCH 05/16] Add critical-log module Change-Id: Ic719ce9f2156bdaebedb5cda60643e7462dce792 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 13 +- conf/critical-log.conf | 13 ++ packaging/deviced.spec | 3 + src/core/device-notifier.h | 1 + src/core/log.c | 14 ++ src/core/log.h | 4 + src/critical-log/critical-log.c | 474 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 520 insertions(+), 2 deletions(-) create mode 100644 conf/critical-log.conf create mode 100644 src/critical-log/critical-log.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 072b6c6..e68f5bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,8 +153,13 @@ IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) ENDIF() IF(DEVICE_BOARD_MODULE STREQUAL on) - ADD_SOURCE(src/board PRODUCT_BOARD_SRCS) - SET(SRCS ${SRCS} ${PRODUCT_BOARD_SRCS}) + ADD_SOURCE(src/board BOARD_SRCS) + SET(SRCS ${SRCS} ${BOARD_SRCS}) +ENDIF() + +IF(CRITICAL_LOG_MODULE STREQUAL on) + ADD_SOURCE(src/critical-log CRITICAL_LOG_SRCS) + SET(SRCS ${SRCS} ${CRITICAL_LOG_SRCS}) ENDIF() INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) @@ -265,6 +270,10 @@ IF(TIZEN_FEATURE_CPU_MODULE STREQUAL on) INSTALL_CONF(conf cpu) ENDIF() +IF(CRITICAL_LOG_MODULE STREQUAL on) + INSTALL_CONF(conf critical-log) +ENDIF() + CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/conf/critical-log.conf b/conf/critical-log.conf new file mode 100644 index 0000000..0f76445 --- /dev/null +++ b/conf/critical-log.conf @@ -0,0 +1,13 @@ +#Critical Log will be saved under the /var/log/ghost/boot/#booting_count +#Critical Log Format is "Section|String Value" +#Limit means Last Critical Log Logging Count +[Common] +Limit=100 +[Battery] +Limit=20 +[BatteryHealth] +Limit=10 +[PowerHandle] +Limit=10 +[CoolDown] +Limit=10 diff --git a/packaging/deviced.spec b/packaging/deviced.spec index f56037b..ea01b19 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -163,6 +163,7 @@ Plugin libraries for IoT devices -DTOUCH_SENSITIVITY_MODULE=on \ -DDUMP_MODULE=on \ -DDEVICE_BOARD_MODULE=on \ + -DCRITICAL_LOG_MODULE=on \ #eol %build @@ -286,6 +287,7 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %license LICENSE.Apache-2.0 %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/mobile-display.conf +%config %{_sysconfdir}/deviced/critical-log.conf %{_libdir}/mobile-display.so %files plugin-profile-wearable @@ -293,6 +295,7 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %license LICENSE.Apache-2.0 %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/wearable-display.conf +%config %{_sysconfdir}/deviced/critical-log.conf %{_libdir}/wearable-display.so %files plugin-profile-tv diff --git a/src/core/device-notifier.h b/src/core/device-notifier.h index 3196468..fe89950 100644 --- a/src/core/device-notifier.h +++ b/src/core/device-notifier.h @@ -72,6 +72,7 @@ enum device_notifier_type { DEVICE_NOTIFIER_BEZEL_WAKEUP, DEVICE_NOTIFIER_LONGKEY_RESTORE, DEVICE_NOTIFIER_ULTRAPOWERSAVING, + DEVICE_NOTIFIER_CRITICAL_LOG, DEVICE_NOTIFIER_MAX, }; diff --git a/src/core/log.c b/src/core/log.c index 86310cd..bd629a8 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -17,7 +17,9 @@ */ #include +#include #include "log.h" +#include "device-notifier.h" #ifdef DEBUG void __cyg_profile_func_enter(void *, void *) @@ -37,3 +39,15 @@ void __cyg_profile_func_exit(void *func, void *caller) g_trace_depth--; } #endif + +void critical_log_internal(const char *func, const char *fmt, ...) +{ + va_list ap; + char buf[256]; + + va_start(ap, fmt); + vsnprintf(buf, 256, fmt, ap); + va_end(ap); + _I("%s:%s", func, buf); + device_notify(DEVICE_NOTIFIER_CRITICAL_LOG, (void *)buf); +} diff --git a/src/core/log.h b/src/core/log.h index 9684f38..915e4a9 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -31,3 +31,7 @@ #define LOG_TAG "DEVICED" #include "shared/log-macro.h" #endif + +void critical_log_internal(const char *caller, const char *fmt, ...); + +#define critical_log(fmt, arg...) critical_log_internal(__func__, fmt, ##arg) diff --git a/src/critical-log/critical-log.c b/src/critical-log/critical-log.c new file mode 100644 index 0000000..154859a --- /dev/null +++ b/src/critical-log/critical-log.c @@ -0,0 +1,474 @@ +/* + * deviced + * + * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include +#include +#include + +#include "core/log.h" +#include "core/devices.h" +#include "core/common.h" +#include "core/config-parser.h" +#include "core/device-notifier.h" +#include "battery/power-supply.h" +#include "power/power-handler.h" + +#define CLOG_SAVE_FILE "/var/log/critical-log.log" +#define CLOG_BACKUP_FILE "/var/log/critical-log.1.log" +#define CLOG_CONF_FILE "/etc/deviced/critical-log.conf" +#define CLOG_TIME_FORMAT "%y-%m-%d/%H:%M:%S" +#define CLOG_MIN_SIZE 3 +#define CLOG_MSG_MAX 512 +#define CLOG_PATH_MAX 256 +#define BOOT_REASON_PATH "/sys/class/system_stats/rbrs" +#define CLOG_FILE_MAX 51200 + +#define CLOG_INDENTED_TAG "%*s" + +struct clog_tag_info { + char *name; + int name_len; + int type; + int count; + int limit; +}; + +struct clog_msg_info { + int type; + char *log; +}; + +static dd_list *clog_tags; +static dd_list *clog_msgs; +static int max_name_len; + +static void free_clog_data(void) +{ + dd_list *n, *next; + struct clog_tag_info *tag; + struct clog_msg_info *msg; + + DD_LIST_FOREACH_SAFE(clog_tags, n, next, tag) { + DD_LIST_REMOVE(clog_tags, tag); + if (tag->name) { + free(tag->name); + tag->name = NULL; + } + free(tag); + tag = NULL; + } + DD_LIST_FOREACH_SAFE(clog_msgs, n, next, msg) { + DD_LIST_REMOVE(clog_msgs, msg); + if (msg->log) { + free(msg->log); + msg->log = NULL; + } + free(msg); + msg = NULL; + } +} + +static int clog_load_config(struct parse_result *result, void *user_data) +{ + static int type; + struct clog_tag_info *tag = NULL; + int ret; + + if (!result || !result->section) { + _E("There is no section."); + ret = -EINVAL; + goto out; + } + + tag = calloc(1, sizeof(struct clog_tag_info)); + if (!tag) { + _E("Failed to allocate memory."); + ret = -ENOMEM; + goto out; + } + + tag->name = strdup(result->section); + if (!tag->name) { + _E("Failed to allocate memory."); + ret = -ENOMEM; + goto out; + } + type++; + tag->type = type; + tag->name_len = strlen(tag->name); + if (max_name_len < tag->name_len) + max_name_len = tag->name_len; + if (result->name && result->value && MATCH(result->name, "Limit")) + tag->limit = strtol(result->value, NULL, 10); + else + tag->limit = CLOG_MIN_SIZE; + + DD_LIST_APPEND(clog_tags, tag); + + _D("[%d]%s count %d limit %d.", tag->type, tag->name, tag->count, tag->limit); + return 0; +out: + if (tag) + free(tag); + free_clog_data(); + return ret; +} + +static int clog_execute(void *data) +{ + dd_list *n, *next; + struct clog_tag_info *tag; + struct clog_msg_info *msg; + char *input, *check, *tag_name, *name = NULL; + int name_len, ret; + struct timespec tspec; + struct tm tm_now; + char str_buff[CLOG_MSG_MAX] = {0,}; + char str_time[32] = {0,}; + char str_msec[6] = {0,}; + + if (!data) + return -EINVAL; + + msg = calloc(1, sizeof(struct clog_msg_info)); + if (!msg) { + _E("Failed to allocate memory."); + return -EINVAL; + } + + input = (char *)data; + check = strchr(input, '|'); + if (!check) { + _E("There is no tag name separator(|)."); + ret = -EINVAL; + goto out; + } + + *check = '\0'; + tag_name = input; + while (*tag_name == ' ') + tag_name++; + name = strdup(tag_name); + if (!name) { + _E("Failed to allocate memory."); + ret = -ENOMEM; + goto out; + } + *check = '|'; + + name_len = strlen(name); + DD_LIST_FOREACH_SAFE(clog_tags, n, next, tag) { + if (tag->name_len != name_len) + continue; + if (strncmp(tag->name, name, name_len)) + continue; + break; + } + if (!tag) { + _E("There is no matched tag name."); + ret = -EINVAL; + goto out; + } + + clock_gettime(CLOCK_REALTIME, &tspec); + localtime_r((time_t *)&tspec.tv_sec, &tm_now); + strftime(str_time, sizeof(str_time), CLOG_TIME_FORMAT, &tm_now); + snprintf(str_msec, sizeof(str_msec), ":%03ld|", tspec.tv_nsec / 1000000); + snprintf(str_buff, sizeof(str_buff), "%s%s[%d]%s BAT(P:%s S:%s C:%d M:%d Chg_ON:%d)\n", + str_time, str_msec, getpid(), input, + battery.power_source_s, + battery.status_s, + battery.capacity, + battery.misc, + battery.charger_charging); + _D("%s", str_buff); + msg->log = strdup(str_buff); + msg->type = tag->type; + DD_LIST_APPEND(clog_msgs, msg); + tag->count++; + + if (tag->count > tag->limit) { + DD_LIST_FOREACH_SAFE(clog_msgs, n, next, msg) { + if (tag->type != msg->type) + continue; + DD_LIST_REMOVE(clog_msgs, msg); + if (msg->log) + free(msg->log); + free(msg); + tag->count--; + break; + } + } + if (name) + free(name); + return 0; +out: + if (name) + free(name); + if (msg) { + if (msg->log) + free(msg->log); + free(msg); + } + return ret; +} + +static int clog_battery_health(void *data) +{ + char clog[CLOG_MSG_MAX] = {0,}; + static int old = HEALTH_GOOD; + int health; + + if (!data) { + _E("There is no data."); + return -EINVAL; + } + + health = *(int *)data; + if (old == health) + return 0; + + old = health; + snprintf(clog, CLOG_MSG_MAX, CLOG_INDENTED_TAG"|%s", max_name_len, "BatteryHealth", battery.health_s); + + return clog_execute((void *)clog); +} + +static int clog_battery_present(void *data) +{ + char clog[CLOG_MSG_MAX] = {0,}; + static int old = PRESENT_NORMAL; + int present; + + if (!data) { + _E("There is no data."); + return -EINVAL; + } + + present = *(int *)data; + if (old == present) + return 0; + + old = present; + snprintf(clog, CLOG_MSG_MAX, CLOG_INDENTED_TAG"|%s", max_name_len, "Battery", (present == PRESENT_ABNORMAL) ? "CFOpened" : "CFNormal"); + + return clog_execute((void *)clog); +} + +static void clog_save_log(void) +{ + dd_list *n, *next; + struct clog_tag_info *tag; + struct clog_msg_info *msg; + struct stat st; + int fd; + int ret; + + fd = open(CLOG_SAVE_FILE, O_RDONLY); + if (fd != -1) { + if (fstat(fd, &st) >= 0 && st.st_size > CLOG_FILE_MAX) { + if (remove(CLOG_BACKUP_FILE) < 0) + _E("Failed to remove %d.", errno); + if (rename(CLOG_SAVE_FILE, CLOG_BACKUP_FILE) < 0) + _E("Failed to backup %d.", errno); + } + close(fd); + } + + fd = open(CLOG_SAVE_FILE, O_CREAT | O_EXCL | O_WRONLY, 0644); + if (fd == -1) { + fd = open(CLOG_SAVE_FILE, O_APPEND | O_WRONLY); + if (fd == -1) { + _E("Fail to open clog file."); + return; + } + } + DD_LIST_FOREACH_SAFE(clog_msgs, n, next, msg) { + ret = write(fd, msg->log, strlen(msg->log)); + if (ret < 0) + _E("Failed to write %d", errno); + } + close(fd); + + DD_LIST_FOREACH_SAFE(clog_tags, n, next, tag) + tag->count = 0; + DD_LIST_FOREACH_SAFE(clog_msgs, n, next, msg) { + DD_LIST_REMOVE(clog_msgs, msg); + if (msg->log) { + free(msg->log); + msg->log = NULL; + } + free(msg); + msg = NULL; + } +} + +static int clog_common_log(void *data) +{ + char clog[CLOG_MSG_MAX] = {0,}; + + if (data) + snprintf(clog, CLOG_MSG_MAX, CLOG_INDENTED_TAG"|%s", max_name_len, "Common", (char *)data); + else + snprintf(clog, CLOG_MSG_MAX, CLOG_INDENTED_TAG"|LogDump", max_name_len, "Common"); + + clog_execute((void *)clog); + + if (!data) + clog_save_log(); + return 0; +} + +static int clog_power_off(void *data) +{ + char clog[CLOG_MSG_MAX] = {0,}; + struct power_option *opt = (struct power_option *)data; + + if (!opt || (opt->type != POWEROFF_TYPE_DIRECT && opt->type != POWEROFF_TYPE_RESTART)) + goto save_log; + + if (opt->type == POWEROFF_TYPE_DIRECT) + snprintf(clog, CLOG_MSG_MAX, CLOG_INDENTED_TAG"|%s ", max_name_len, "PowerHandle", "PowerOff"); + else + snprintf(clog, CLOG_MSG_MAX, CLOG_INDENTED_TAG"|%s with %s ", max_name_len, "PowerHandle", + "Reboot", (opt->option) ? opt->option : "NULL"); + + clog_execute((void *)clog); + +save_log: + clog_save_log(); + return 0; +} + +static int clog_booting_done(void *data) +{ + DIR *dir; + struct dirent *result; + static int done; + char clog[CLOG_MSG_MAX] = {0,}; + char node[CLOG_PATH_MAX] = {0,}; + char val[CLOG_PATH_MAX] = {0,}; + char elem; + int prefix; + int fd; + unsigned int cnt; + int ret; + + if (data == NULL) + return done; + done = *(int *)data; + if (done == 0) + return 0; + + snprintf(clog, CLOG_MSG_MAX, CLOG_INDENTED_TAG"|Boot", max_name_len, "PowerHandle"); + + dir = opendir(BOOT_REASON_PATH); + if (!dir) { + _E("Failed to opendir %s.", BOOT_REASON_PATH); + goto out; + } + + prefix = strlen(clog); + while ((result = readdir(dir))) { + if (strncmp(result->d_name, "summary", 7) != 0) + continue; + snprintf(node, sizeof(node), BOOT_REASON_PATH"/%s", result->d_name); + fd = open(node, O_RDONLY); + if (fd < 0) + continue; + ret = 0; + cnt = 0; + while (read(fd, &elem, 1) != 0) { + if (cnt >= 4 || ret >= CLOG_PATH_MAX - 1) + break; + if (elem != '\n') { + val[ret++] = elem; + } else { + val[ret++] = ' '; + cnt++; + } + } + val[ret] = '\0'; + snprintf(clog + prefix, CLOG_MSG_MAX - prefix, "|%s(%s) ", result->d_name, val); + close(fd); + closedir(dir); + goto out; + } + + while ((result = readdir(dir))) { + if (result->d_name[0] == '.' || + result->d_type == DT_DIR || + strncmp(result->d_name, "uevent", 6) == 0 || + strncmp(result->d_name, "power", 5) == 0 || + strncmp(result->d_name, "subsystem", 9) == 0) + continue; + snprintf(node, sizeof(node), BOOT_REASON_PATH"/%s", result->d_name); + fd = open(node, O_RDONLY); + if (fd < 0) + continue; + ret = read(fd, val, CLOG_PATH_MAX); + if (ret < 0 || ret >= CLOG_PATH_MAX) { + cnt = UINT_MAX; + } else { + val[ret] = '\0'; + cnt = strtoul(val, NULL, 10); + } + snprintf(clog + prefix, CLOG_MSG_MAX - prefix, "|%s%u ", result->d_name, cnt); + close(fd); + prefix = strlen(clog); + } + if (dir) + closedir(dir); +out: + clog_execute((void *)clog); + clog_save_log(); + unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, clog_booting_done); + return done; +} + +static void clog_init(void *none) +{ + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, clog_booting_done); + register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, clog_battery_health); + register_notifier(DEVICE_NOTIFIER_BATTERY_PRESENT, clog_battery_present); + register_notifier(DEVICE_NOTIFIER_CRITICAL_LOG, clog_common_log); + register_notifier(DEVICE_NOTIFIER_POWEROFF, clog_power_off); + if (config_parse(CLOG_CONF_FILE, clog_load_config, NULL) < 0) + _E("Fail to init configuration."); +} + +static void clog_exit(void *data) +{ + unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, clog_battery_health); + unregister_notifier(DEVICE_NOTIFIER_BATTERY_PRESENT, clog_battery_present); + unregister_notifier(DEVICE_NOTIFIER_CRITICAL_LOG, clog_common_log); + unregister_notifier(DEVICE_NOTIFIER_POWEROFF, clog_power_off); + free_clog_data(); +} + +static const struct device_ops clog_device_ops = { + .name = "clog", + .init = clog_init, + .exit = clog_exit, + .execute = clog_execute, +}; + +DEVICE_OPS_REGISTER(&clog_device_ops) -- 2.7.4 From ce471ec18f19bb184848f4c84e813b834ef4bdee Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 23 Aug 2019 17:28:08 +0900 Subject: [PATCH 06/16] Apply MCD display Change-Id: I3ee82aafab34390d6907239c2ab6542540f3abf7 Signed-off-by: lokilee73 --- plugins/iot/display/core.c | 1027 +++++++++++++++++++------- plugins/iot/display/device-interface.c | 500 +++++++++++-- plugins/iot/display/key-filter.c | 322 ++++++-- plugins/mobile/display/core.c | 1025 +++++++++++++++++++------- plugins/mobile/display/device-interface.c | 500 +++++++++++-- plugins/mobile/display/display-info.h | 50 ++ plugins/mobile/display/key-filter.c | 262 +++++-- plugins/mobile/display/proximity.c | 47 ++ plugins/mobile/display/proximity.h | 35 + plugins/tv/display/core.c | 1035 +++++++++++++++++++------- plugins/tv/display/device-interface.c | 500 +++++++++++-- plugins/tv/display/key-filter.c | 324 +++++++-- plugins/wearable/display/bezel.c | 2 +- plugins/wearable/display/core.c | 1052 ++++++++++++++++++++------- plugins/wearable/display/device-interface.c | 464 ++++++++++-- plugins/wearable/display/display-info.h | 50 ++ plugins/wearable/display/enhance.c | 7 +- plugins/wearable/display/key-filter.c | 230 ++++-- plugins/wearable/display/swim.c | 53 +- src/battery/battery-time.c | 1 - src/battery/lowbat-handler.c | 7 +- src/battery/power-supply.c | 2 +- src/board/board-info.c | 9 +- src/control/control.c | 2 +- src/core/common.c | 171 ++++- src/core/common.h | 37 +- src/core/config-parser.c | 7 +- src/core/device-notifier.c | 112 ++- src/core/device-notifier.h | 36 +- src/core/devices.c | 28 +- src/core/devices.h | 10 +- src/core/event-handler.c | 2 +- src/core/launch.c | 14 +- src/core/log.h | 7 + src/core/sig-handler.c | 2 +- src/core/udev.c | 2 +- src/core/udev.h | 9 + src/cpu/pmqos.c | 2 +- src/display/ambient-mode.c | 19 +- src/display/auto-brightness.c | 7 +- src/display/core.h | 26 +- src/display/device-interface.h | 41 +- src/display/display-dbus.c | 245 +++++-- src/display/display-ops.h | 11 + src/display/input.c | 54 +- src/display/lock-detector.c | 237 ++++-- src/display/lock-detector.h | 9 +- src/display/poll.h | 10 +- src/display/setting.c | 64 +- src/display/setting.h | 11 + src/display/slave-logging.c | 94 +++ src/dump/dump.c | 2 +- src/extcon/extcon.c | 2 +- src/extcon/extcon.h | 5 - src/ir/ir.c | 2 +- src/led/rgb.c | 2 +- src/led/torch.c | 2 +- src/led/touch-key.c | 2 +- src/power/power-handler.c | 2 +- src/shared/common.h | 6 + src/shared/deviced-systemd.c | 43 +- src/shared/deviced-systemd.h | 3 +- src/thermal/thermal.c | 2 +- src/touchscreen/sensitivity.c | 2 +- src/touchscreen/touchscreen.c | 2 +- src/tzip/tzip.c | 2 +- src/usb-host-test/usb-host-test.c | 2 +- 67 files changed, 6892 insertions(+), 1962 deletions(-) create mode 100644 plugins/mobile/display/display-info.h create mode 100644 plugins/mobile/display/proximity.c create mode 100644 plugins/mobile/display/proximity.h create mode 100644 plugins/wearable/display/display-info.h create mode 100644 src/display/slave-logging.c diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 5f08790..87ceda1 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -35,10 +35,9 @@ #include #include #include +#include #include #include -#include -#include #include "ambient-mode.h" #include "util.h" @@ -53,13 +52,13 @@ #include "core/common.h" #include "core/config-parser.h" #include "core/launch.h" +#include "apps/apps.h" #include "extcon/extcon.h" +#include "battery/power-supply.h" #include "power/power-handler.h" #include "dd-display.h" #include "display/display-dpms.h" -#include "battery/battery.h" -#define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" /** @@ -70,18 +69,28 @@ #define SET_BRIGHTNESS_IN_BOOTLOADER "/usr/bin/save_blenv SLP_LCD_BRIGHT" #define LOCK_SCREEN_INPUT_TIMEOUT 10000 #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 -#define DD_LCDOFF_INPUT_TIMEOUT 3000 -#define ALWAYS_ON_TIMEOUT 3600000 //3600000 = 1 hour +#define ALWAYS_ON_TIMEOUT 3600000 +#define LATE_LCD_TRANSIT 1 + +#define PID_MAX 6 #define GESTURE_STR "gesture" #define POWER_KEY_STR "powerkey" #define TOUCH_STR "touch" #define EVENT_STR "event" #define TIMEOUT_STR "timeout" +#define PROXI_STR "proximity" +#define PALM_STR "palm" #define UNKNOWN_STR "unknown" +#define METHOD_APP_STATUS "CheckAppStatus" + +#define PM_WAKEUP 0 +#define PM_SUSPEND 1 + extern void init_pm_internal(); extern int get_charging_status(int *val); +extern void init_save_userlock(void); unsigned int pm_status_flag; static int trans_condition; @@ -92,6 +101,7 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; int pm_cur_state; int pm_old_state; guint timeout_src_id; +int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; static int custom_holdkey_block = false; @@ -99,13 +109,21 @@ static int custom_change_pid = -1; static char *custom_change_name; static bool hallic_open = true; static guint lock_timeout_id; +static guint transit_timer; static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; +static long displayoff_time; static struct timeval lcdon_tv; static int lcd_paneloff_mode = false; static int stay_touchscreen_off = false; +dd_list *lcdon_ops; +/* + * The two variables(lcdon_broadcast, pmstate_suspend) must be set initial + * state because it should be sent from previous state at booting time. + */ static bool lcdon_broadcast = true; +static int pmstate_suspend = PM_SUSPEND; + static bool touch_blocked = false; -dd_list *lcdon_ops; /* default transition, action fuctions */ static int default_trans(int evt); @@ -116,6 +134,10 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); +static gboolean pmlock_normal_check(void *data); +static gboolean pmlock_dim_check(void *data); +static gboolean pmlock_off_check(void *data); + static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; @@ -140,6 +162,10 @@ static int trans_table[S_END][EVENT_END] = { { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */ }; +static GSourceFunc warning_cb[S_END] = { + NULL, pmlock_normal_check, pmlock_dim_check, pmlock_off_check, +}; + enum signal_type { SIGNAL_INVALID = 0, SIGNAL_PRE, @@ -147,6 +173,11 @@ enum signal_type { SIGNAL_MAX, }; +enum platform_control { + PLATFORM_DISPLAY_OFF, + PLATFORM_DISPLAY_ON, +}; + static const char *lcdon_sig_lookup[SIGNAL_MAX] = { [SIGNAL_PRE] = "LCDOn", [SIGNAL_POST] = "LCDOnCompleted", @@ -178,7 +209,7 @@ static const char *lcdoff_sig_lookup[SIGNAL_MAX] = { #define LONG_PRESS_INTERVAL 2 /* 2 seconds */ #define SAMPLING_INTERVAL 1 /* 1 sec */ #define BRIGHTNESS_CHANGE_STEP 10 -#define LCD_ALWAYS_ON 1 +#define LCD_ALWAYS_ON 0 #define ACCEL_SENSOR_ON 1 #define CONTINUOUS_SAMPLING 1 #define LCDOFF_TIMEOUT 500 /* milli second */ @@ -195,13 +226,18 @@ struct display_config display_conf = { .lcdoff_timeout = LCDOFF_TIMEOUT, .brightness_change_step = BRIGHTNESS_CHANGE_STEP, .lcd_always_on = LCD_ALWAYS_ON, - .framerate_app = {1, 0, 0, 0}, - .control_display = 1, + .dimming = 1, + .framerate_app = {0, 0, 0, 0}, + .control_display = 0, .powerkey_doublepress = 0, .accel_sensor_on = ACCEL_SENSOR_ON, .continuous_sampling = CONTINUOUS_SAMPLING, - .timeout_enable = false, + .timeout_enable = true, .input_support = true, + .lockcheck_timeout = 600, + .aod_enter_level = 40, + .aod_tsp = true, + .touch_wakeup = false, }; struct display_function_info display_info = { @@ -214,9 +250,11 @@ struct display_function_info display_info = { typedef struct _pm_lock_node { pid_t pid; guint timeout_id; + guint warning_id; time_t time; bool holdkey_block; bool background; + bool broadcast_warning; } PmLockNode; static dd_list *cond_head[S_END]; @@ -231,9 +269,9 @@ static void set_process_active(bool flag, pid_t pid) /* Send dbug to resourced */ ret = dbus_handle_emit_dbus_signal(NULL, RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - RESOURCED_METHOD_ACTIVE, - g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); + RESOURCED_INTERFACE_PROCESS, + RESOURCED_METHOD_ACTIVE, + g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); if (ret < 0) _E("Failed to send dbus signal to resourced."); } @@ -287,17 +325,64 @@ void change_proc_change_state(int (*func)(unsigned int cond, pid_t pid)) proc_change_state = func; } +static inline long clock_gettime_to_long(void) +{ + struct timespec now; + int ret; + + ret = clock_gettime(CLOCK_REALTIME, &now); + + if (ret < 0) { + _E("Failed to clock gettime!"); + return 0; + } + + return SEC_TO_MSEC(now.tv_sec) + NSEC_TO_MSEC(now.tv_nsec); +} + +static int display_brightness_changed(void *data) +{ + int brt, ret; + + brt = DATA_VALUE_INT(data); + + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "Brightness", + g_variant_new("(i)", brt)); + if (ret < 0) + _E("Failed to send dbus signal Brightness."); + + return 0; +} + +static int display_auto_brightness_sensing(void *data) +{ + if (!transit_timer) + return 0; + + g_source_remove(transit_timer); + transit_timer = 0; + + return 0; +} + static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) { const char *str; const char *signal; int ret; + long diff = 0; if (type <= SIGNAL_INVALID || type >= SIGNAL_MAX) { _E("Invalid signal type(%d).", type); return; } + if (type == SIGNAL_PRE && displayoff_time != 0) + diff = clock_gettime_to_long() - displayoff_time; + if (flags & LCD_ON_BY_GESTURE) str = GESTURE_STR; else if (flags & LCD_ON_BY_POWER_KEY) @@ -315,7 +400,7 @@ static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, - g_variant_new("(s)", str)); + g_variant_new("(si)", str, diff)); if (ret < 0) _E("Failed to send dbus signal(%s)", signal); } @@ -331,6 +416,9 @@ static void broadcast_lcd_off(enum signal_type type, enum device_flags flags) return; } + if (type == SIGNAL_PRE) + displayoff_time = clock_gettime_to_long(); + signal = lcdoff_sig_lookup[type]; if (flags & LCD_OFF_BY_POWER_KEY) @@ -369,9 +457,6 @@ static unsigned long get_lcd_on_flags(void) if (lcd_paneloff_mode) flags |= LCD_PANEL_OFF_MODE; - if (stay_touchscreen_off) - flags |= TOUCH_SCREEN_OFF_MODE; - if (ambient_get_condition() == true) { flags |= AMBIENT_MODE; flags |= LCD_PHASED_TRANSIT_MODE; @@ -385,6 +470,18 @@ bool touch_event_blocked(void) return touch_blocked; } +static gboolean late_transit_on(void *data) +{ + if (!transit_timer) + return G_SOURCE_REMOVE; + + g_source_remove(transit_timer); + transit_timer = 0; + + backlight_ops.transit_state(DPMS_ON); + return G_SOURCE_REMOVE; +} + void lcd_on_procedure(int state, enum device_flags flag) { dd_list *l = NULL; @@ -392,19 +489,29 @@ void lcd_on_procedure(int state, enum device_flags flag) unsigned long flags = get_lcd_on_flags(); flags |= flag; - /* send LCDOn dbus signal */ - if (!lcdon_broadcast) { - broadcast_lcd_on(SIGNAL_PRE, flags); - lcdon_broadcast = true; - } + /* + * Display on procedure + * step 1. broadcast lcd on signal with cause + * step 2. set brightness + * step 3. set pmstate of vconf + * step 4. display on operate + * - a. display on + * - b. TSP(touch screen) and touchkey enable + * step 5. broadcast lcd on complete siganl + * step 6. key backlight enable + */ + _I("[lcdstep] %lu", flags); if (flags & AMBIENT_MODE) { - if (ambient_get_state() == false && - backlight_ops.get_lcd_power() == DPMS_ON) + if (ambient_get_state() == false && backlight_ops.get_lcd_power() == DPMS_ON) return; ambient_set_state(false); } + /* send LCDOn dbus signal */ + if (!lcdon_broadcast) + broadcast_lcd_on(SIGNAL_PRE, flags); + if (!(flags & LCD_PHASED_TRANSIT_MODE)) { /* Update brightness level */ if (state == LCD_DIM) @@ -421,7 +528,13 @@ void lcd_on_procedure(int state, enum device_flags flag) DD_LIST_FOREACH(lcdon_ops, l, ops) ops->start(flags); + if (!lcdon_broadcast) { broadcast_lcd_on(SIGNAL_POST, flags); + if (flags & LCD_PHASED_TRANSIT_MODE) + transit_timer = g_timeout_add_seconds(LATE_LCD_TRANSIT, + late_transit_on, NULL); + lcdon_broadcast = true; + } if (CHECK_OPS(keyfilter_ops, backlight_enable)) keyfilter_ops->backlight_enable(true); @@ -429,7 +542,7 @@ void lcd_on_procedure(int state, enum device_flags flag) touch_blocked = false; } -static inline unsigned long get_lcd_off_flags(void) +static unsigned long get_lcd_off_flags(void) { unsigned long flags = NORMAL_MODE; @@ -438,10 +551,12 @@ static inline unsigned long get_lcd_off_flags(void) flags |= LCD_PHASED_TRANSIT_MODE; } + if (stay_touchscreen_off) + flags |= TOUCH_SCREEN_OFF_MODE; + return flags; } - inline void lcd_off_procedure(enum device_flags flag) { dd_list *l = NULL; @@ -449,6 +564,20 @@ inline void lcd_off_procedure(enum device_flags flag) unsigned long flags = get_lcd_off_flags(); flags |= flag; + /* + * Display off procedure + * step 0. enhance mode off using nofity (e.g mdnie, HBM, LBM) + * step 1. broadcast lcd off signal with cause + * step 2. set pmstate of vconf + * step 3. display off operate + * - a. display off + * - b. TSP(touch screen) and touchkey disable + * step 4. broadcast lcd off complete siganl + */ + _I("[lcdstep] %lu", flags); + + device_notify(DEVICE_NOTIFIER_LCD_OFF, NULL); + touch_blocked = true; if (flags & AMBIENT_MODE) { @@ -461,18 +590,23 @@ inline void lcd_off_procedure(enum device_flags flag) broadcast_lcd_off(SIGNAL_PRE, flags); lcdon_broadcast = false; } + set_setting_pmstate(S_LCDOFF); + if (CHECK_OPS(keyfilter_ops, backlight_enable)) keyfilter_ops->backlight_enable(false); - set_setting_pmstate(S_LCDOFF); + if (transit_timer) { + g_source_remove(transit_timer); + transit_timer = 0; + } + + if (flags & LCD_PHASED_TRANSIT_MODE) + backlight_ops.transit_state(DPMS_OFF); DD_LIST_FOREACH(lcdon_ops, l, ops) ops->stop(flags); if (flags & AMBIENT_MODE) - /* Do not broadcast the post signal here. - * The signal will be broadcasted - * after showing Ambient clock */ broadcast_lcd_off_late(flags); else broadcast_lcd_off(SIGNAL_POST, flags); @@ -480,20 +614,20 @@ inline void lcd_off_procedure(enum device_flags flag) void set_stay_touchscreen_off(int val) { - _D("stay touch screen off: %d", val); + _I("Stay touch screen off: %d", val); stay_touchscreen_off = val; - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - set_setting_pmstate(LCD_NORMAL); + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } void set_lcd_paneloff_mode(int val) { - _D("lcd paneloff mode: %d", val); + _I("Lcd paneloff mode: %d", val); lcd_paneloff_mode = val; - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - set_setting_pmstate(LCD_NORMAL); + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } int low_battery_state(int val) @@ -537,7 +671,7 @@ static void makeup_trans_condition(void) static PmLockNode *find_node(enum state_t s_index, pid_t pid) { dd_list *elem; - PmLockNode *t; + PmLockNode *t = NULL; DD_LIST_FOREACH(cond_head[s_index], elem, t) { if (t->pid == pid) @@ -550,21 +684,28 @@ static PmLockNode *find_node(enum state_t s_index, pid_t pid) static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, bool holdkey_block) { + guint warning_id = 0; PmLockNode *n; time_t now; n = (PmLockNode *) malloc(sizeof(PmLockNode)); if (n == NULL) { - _E("Failed to add cond. Not enough memory."); + _E("Not enough memory, add cond. fail"); return NULL; } + if (pid < INTERNAL_LOCK_BASE) + warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, + warning_cb[s_index], (void *)((intptr_t)pid)); + time(&now); n->pid = pid; n->timeout_id = timeout_id; + n->warning_id = warning_id; n->time = now; n->holdkey_block = holdkey_block; n->background = false; + n->broadcast_warning = true; DD_LIST_APPEND(cond_head[s_index], n); refresh_app_cond(); @@ -583,6 +724,11 @@ static int del_node(enum state_t s_index, PmLockNode *n) g_source_remove(n->timeout_id); n->timeout_id = 0; } + if (n->warning_id) { + g_source_remove(n->warning_id); + n->warning_id = 0; + } + free(n); refresh_app_cond(); return 0; @@ -590,6 +736,7 @@ static int del_node(enum state_t s_index, PmLockNode *n) static void print_node(int next) { + int ret; dd_list *elem; PmLockNode *n; char buf[30]; @@ -604,10 +751,20 @@ static void print_node(int next) diff = difftime(now, n->time); ctime_r(&n->time, buf); - if (diff > LOCK_TIME_WARNING) - _W("over=%.0f s pid=%5d locktime=%s", diff, n->pid, buf); - else - _I("pid=%5d locktime=%s", n->pid, buf); + if (diff > LOCK_TIME_WARNING) { + if (diff > LOCK_TIME_WARNING * 60 && n->pid < INTERNAL_LOCK_BASE && n->broadcast_warning) { + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "pmlock_over", + g_variant_new("(i)", n->pid)); + if (ret < 0) + _E("Failed to send dbus signal pmlock_over."); + n->broadcast_warning = false; + } + _W("Over(%.0f s) pid( %5d) lock time(%s)", diff, n->pid, buf); + } else + _I("Pid(%5d) lock time(%s)", n->pid, buf); } } @@ -640,7 +797,6 @@ void get_pname(pid_t pid, char *pname) static void del_state_cond(void *data, enum state_t state) { PmLockNode *tmp = NULL; - char pname[PATH_MAX]; pid_t pid; if (!data) @@ -648,18 +804,20 @@ static void del_state_cond(void *data, enum state_t state) /* A passed data is a pid_t type data, not a 64bit data. */ pid = (pid_t)((intptr_t)data); - _I("Delete process(%d)'s prohibit dim condition by timeout.", pid); + _I("delete prohibit dim condition by timeout (%d)", pid); + + if (pid == INTERNAL_LOCK_AMBIENT) + ambient_check_invalid_state(pid); tmp = find_node(state, pid); del_node(state, tmp); - get_pname(pid, pname); - set_unlock_time(pname, state); + set_unlock_time(pid, state); if (!timeout_src_id) states[pm_cur_state].trans(EVENT_TIMEOUT); if (state == S_LCDOFF) - set_process_active(FALSE, pid); + set_process_active(false, pid); } static gboolean del_normal_cond(void *data) @@ -680,23 +838,91 @@ static gboolean del_off_cond(void *data) return G_SOURCE_REMOVE; } -/* timeout handler */ -gboolean timeout_handler(void *data) +static void pmlock_check_cb(GVariant *var, void *user_data, GError *err) { - int run_timeout; + pid_t pid; + int ret, state; + char *app_id; - _I("Time out state %s.\n", states[pm_cur_state].name); - /* default setting */ - get_run_timeout(&run_timeout); + if (!var) + return; - /* for sdk - * if the run_timeout is zero, it regards AlwaysOn state + if (!dh_get_param_from_var(var, "(iis)", &pid, &state, &app_id)) { + _E("Failed to notify low: no message(%s)", g_variant_get_type_string(var)); + goto out; + } + + _W("%s(%d) was requested pmlock for a long time.", app_id, pid); + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "pmlock_expired", + g_variant_new("(i)", pid)); + if (ret < 0) + _E("Failed to send dbus pmlock_expired"); + +out: + g_variant_unref(var); +} + +/* + * Any process is possible many time lock, deviced can not know malicious + * or good process. so infinity or more then 1 min lock process, deviced + * will be checked it to resoured. And then, it will be asked quit or maintain to user. */ - if (pm_cur_state == S_NORMAL && (run_timeout == 0 || display_conf.lcd_always_on)) { - _D("'run_timeout' is always on."); - return G_SOURCE_CONTINUE; +static void pmlock_check(void *data, char *st) +{ + const char *arr[2]; + char chr_pid[PID_MAX]; + pid_t pid; + int ret; + + if (!data || !st) + return; + + if (!strncmp(st, "lcdoff", 4) && backlight_ops.get_lcd_power() == DPMS_ON) { + _D("Lcd state is PM_LCD_POWER_ON"); + return; } + pid = (pid_t)((intptr_t)data); + snprintf(chr_pid, sizeof(chr_pid), "%d", pid); + + arr[0] = chr_pid; + arr[1] = st; + + ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, + RESOURCED_PATH_PROCESS, + RESOURCED_INTERFACE_PROCESS, + METHOD_APP_STATUS, + "is", arr, pmlock_check_cb, -1, NULL); + if (ret < 0) + _E("Failed to call dbus method"); +} + +static gboolean pmlock_normal_check(void *data) +{ + pmlock_check(data, "normal"); + return G_SOURCE_CONTINUE; +} + +static gboolean pmlock_dim_check(void *data) +{ + pmlock_check(data, "lcddim"); + return G_SOURCE_CONTINUE; +} + +static gboolean pmlock_off_check(void *data) +{ + pmlock_check(data, "lcdoff"); + return G_SOURCE_CONTINUE; +} + +/* timeout handler */ +gboolean timeout_handler(void *data) +{ + _I("Time out state %s", states[pm_cur_state].name); + if (timeout_src_id) { g_source_remove(timeout_src_id); timeout_src_id = 0; @@ -711,7 +937,7 @@ void reset_timeout(int timeout) if (!display_conf.timeout_enable) return; - _I("Reset timeout(%d ms)", timeout); + _I("Reset timeout(%d ms).", timeout); if (timeout_src_id != 0) { g_source_remove(timeout_src_id); timeout_src_id = 0; @@ -752,7 +978,7 @@ static int get_lcd_timeout_from_settings(void) if (val > 0) states[i].timeout = val; - _I("state=%s timeout=%d ms", states[i].name, + _I("State(%s) timeout(%d) ms", states[i].name, states[i].timeout); } @@ -775,7 +1001,7 @@ static void update_display_time(void) if (custom_normal_timeout > 0) { states[S_NORMAL].timeout = custom_normal_timeout; states[S_LCDDIM].timeout = custom_dim_timeout; - _I("CUSTOM: Timeout(%d ms) and dim(%d ms) are set by normal.", + _I("CUSTOM : timeout is set by normal(%d ms), dim(%d ms)", custom_normal_timeout, custom_dim_timeout); return; } @@ -806,7 +1032,8 @@ static void update_display_time(void) get_dim_timeout(&val); states[S_LCDDIM].timeout = val; - _I("Normal: timeout(%d ms) and dim(%d ms) are set.", states[S_NORMAL].timeout, states[S_LCDDIM].timeout); + _I("Normal: NORMAL timeout is set by %d ms", states[S_NORMAL].timeout); + _I("Normal: DIM timeout is set by %d ms", states[S_LCDDIM].timeout); } static void update_display_locktime(int time) @@ -815,7 +1042,6 @@ static void update_display_locktime(int time) update_display_time(); } - void set_dim_state(bool on) { _I("Dim state is %d.", on); @@ -823,31 +1049,58 @@ void set_dim_state(bool on) states[pm_cur_state].trans(EVENT_INPUT); } +static void broadcast_pm_suspend(void) +{ + int ret; -void lcd_on_direct(enum device_flags flags) + if (pmstate_suspend) + return; + + _D("PM will be changed to sleep."); + + pmstate_suspend = PM_SUSPEND; + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "sleep", + NULL); + if (ret < 0) + _E("Failed to send dbus signal sleep."); +} + +static void broadcast_pm_wakeup(void) { - int ret, call_state; + int ret; + + if (!pmstate_suspend) + return; + + _D("PM is changed to wakeup."); + + pmstate_suspend = PM_WAKEUP; + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "wakeup", + NULL); + if (ret < 0) + _E("Failed to send dbus signal wakeup."); +} + +void lcd_on_direct(enum device_flags flags) +{ if (power_ops.get_power_lock_support() - && pm_cur_state == S_SLEEP) + && pm_cur_state == S_SLEEP) { + broadcast_pm_wakeup(); power_ops.power_lock(); + pm_cur_state = S_NORMAL; + } -#ifdef MICRO_DD - _D("Lcd is on directly."); + _D("lcd is on directly"); gettimeofday(&lcdon_tv, NULL); lcd_on_procedure(LCD_NORMAL, flags); - reset_timeout(DD_LCDOFF_INPUT_TIMEOUT); -#else - ret = vconf_get_int(VCONFKEY_CALL_STATE, &call_state); - if ((ret >= 0 && call_state != VCONFKEY_CALL_OFF) || - (__get_lock_screen_state() == VCONFKEY_IDLE_LOCK)) { - _D("LOCK state, lcd is on directly."); - lcd_on_procedure(LCD_NORMAL, flags); - } else if (ret < 0) - _E("Failed to get vconf value for call state: %d", vconf_get_ext_errno()); - - reset_timeout(display_conf.lcdoff_timeout); -#endif + update_display_locktime(LOCK_SCREEN_INPUT_TIMEOUT); } @@ -859,6 +1112,41 @@ static inline bool check_lcd_is_on(void) return true; } +static int check_lock_condition(enum state_t state) +{ + dd_list *elem; + PmLockNode *t = NULL; + int ret = false; + pid_t owner = getpid(); + + _D("check holdkey block : state of %s", states[state].name); + + DD_LIST_FOREACH(cond_head[state], elem, t) { + if (t->pid != owner && t->background == false) { + ret = true; + _I("state change was blocked by pid(%d)!", t->pid); + break; + } + } + + return ret; +} + +static gboolean timer_refresh_cb(gpointer data) +{ + struct state *st; + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_NORMAL; + st = &states[pm_cur_state]; + + if (st->action) + st->action(st->timeout); + + return 0; +} + int custom_lcdon(int timeout) { struct state *st; @@ -882,9 +1170,157 @@ int custom_lcdon(int timeout) if (st->action) st->action(st->timeout); + g_idle_add(timer_refresh_cb, NULL); + + return 0; +} + +int custom_lcdoff(enum device_flags flag) +{ + struct state *st; + + check_processes(S_NORMAL); + check_processes(S_LCDDIM); + + /* check holdkey block flag in lock node */ + if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + /* + * When another proccess is normal lock, device is received call then, + * call app can be changed to lcd state by proximity. + * If proximity is near then normal lock will be unlocked. + */ + if (flag & LCD_OFF_BY_PROXIMITY) { + _I("custom lcd off by proximity, delete normal lock"); + delete_condition(S_NORMAL); + } else { + _I("skip custom lcd off"); + return -ECANCELED; + } + } + + _I("custom lcd off by flag(%d)", flag); + if (backlight_ops.get_lcd_power() == DPMS_ON) + lcd_off_procedure(flag); + + if (set_custom_lcdon_timeout(0) == true) + update_display_time(); + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_LCDOFF; + st = &states[pm_cur_state]; + + /* enter action */ + if (st->action) + st->action(st->timeout); + + return 0; +} + +static int display_platform_on(char *reason, int timeout) +{ + struct state *st; + int flag; + int str_len; + + str_len = strlen(reason); + + if (!strncmp(reason, GESTURE_STR, str_len)) + flag = LCD_ON_BY_GESTURE; + else if (!strncmp(reason, EVENT_STR, str_len)) + flag = LCD_ON_BY_EVENT; + else { + _E("Reason is unkown(%s)", reason); + return -EINVAL; + } + + if (timeout <= 0) { + _E("Cannot setting timeout %d", timeout); + return -EINVAL; + } + + if (check_lcd_is_on() == false) + lcd_on_direct(flag); + + _I("platform lcd on by %s (%d ms)", reason, timeout); + if (set_custom_lcdon_timeout(timeout) == true) + update_display_time(); + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_NORMAL; + st = &states[pm_cur_state]; + + /* enter action */ + if (st->action) + st->action(st->timeout); + + return 0; +} + +static int display_platform_off(char *reason) +{ + struct state *st; + int flag; + int str_len; + + str_len = strlen(reason); + + if (!strncmp(reason, GESTURE_STR, str_len)) { + check_processes(S_NORMAL); + check_processes(S_LCDDIM); + + /* check holdkey block flag in lock node */ + if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + _I("skip platform lcd off by gesture"); + return -ECANCELED; + } + flag = LCD_OFF_BY_GESTURE; + } else if (!strncmp(reason, PALM_STR, str_len)) { + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); + + flag = LCD_OFF_BY_PALM; + } else { + _E("Reason is unkown(%s)", reason); + return -EINVAL; + } + + _I("platform lcd off by %s", reason); + if (backlight_ops.get_lcd_power() == DPMS_ON) + lcd_off_procedure(flag); + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_LCDOFF; + st = &states[pm_cur_state]; + + /* enter action */ + if (st->action) + st->action(st->timeout); + return 0; } +int display_platform_control(int type, char *reason, int timeout) +{ + int ret; + + switch (type) { + case PLATFORM_DISPLAY_ON: + ret = display_platform_on(reason, timeout); + break; + case PLATFORM_DISPLAY_OFF: + ret = display_platform_off(reason); + break; + default: + _E("Unkown type(%d)", type); + ret = -EINVAL; + } + + return ret; +} + static void default_proc_change_state_action(enum state_t next, int timeout) { struct state *st; @@ -920,7 +1356,7 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) default_proc_change_state_action(next, -1); break; case S_LCDOFF: - if (backlight_ops.get_lcd_power() != DPMS_OFF) + if (backlight_ops.get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_EVENT); if (set_custom_lcdon_timeout(0)) update_display_time(); @@ -931,7 +1367,14 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) /* at first LCD_OFF and then goto sleep */ /* state transition */ default_proc_change_state_action(S_LCDOFF, TIMEOUT_NONE); + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); delete_condition(S_LCDOFF); + if (lcdon_broadcast) { + _I("broadcast lcd off signal at non-lcd device"); + broadcast_lcd_off(SIGNAL_PRE, 0); + broadcast_lcd_off(SIGNAL_POST, 0); + } default_proc_change_state_action(S_SLEEP, TIMEOUT_NONE); break; @@ -966,15 +1409,18 @@ static void proc_condition_lock(PMMsg *data) pid_t pid = data->pid; enum state_t state; int holdkey_block; + bool value = true; + unsigned int flags; state = GET_COND_STATE(data->cond); - if (!state) + if (state == S_START) return; + flags = GET_COND_FLAG(data->cond); get_pname(pid, pname); - if (state == S_LCDOFF && - pm_cur_state == S_SLEEP) + if (state == S_LCDOFF && pm_cur_state == S_SLEEP && + power_ops.get_power_lock() == POWER_UNLOCK) proc_change_state(data->cond, INTERNAL_LOCK_PM); if (data->timeout > 0) { @@ -1000,14 +1446,15 @@ static void proc_condition_lock(PMMsg *data) } if (state == S_LCDOFF) - set_process_active(TRUE, pid); + set_process_active(true, pid); + _I("[%s] locked by %5d with %u ms", states[state].name, pid, data->timeout); /* for debug */ - _SD("[%s] Locked by pid=%d process=%s holdkeyblock=%d\n", - states[state].name, pid, pname, holdkey_block); - set_lock_time(pname, state); + _SD("be requested LOCK info pname(%s), holdkeyblock(%d) flags(%d)", + pname, holdkey_block, flags); + set_lock_time(pid, pname, state); - device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)true); + device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value); } static void proc_condition_unlock(PMMsg *data) @@ -1016,27 +1463,28 @@ static void proc_condition_unlock(PMMsg *data) enum state_t state; PmLockNode *tmp; char pname[PATH_MAX]; + bool value = false; + unsigned int flags; state = GET_COND_STATE(data->cond); if (!state) return; + flags = GET_COND_FLAG(data->cond); get_pname(pid, pname); tmp = find_node(state, pid); del_node(state, tmp); if (state == S_LCDOFF) - set_process_active(FALSE, pid); + set_process_active(false, pid); - if (ambient_get_state()) - ambient_check_invalid_state(pid); - - _SD("[%s] Unlocked by pid=%d process=%s\n", - states[state].name, pid, pname); - set_unlock_time(pname, state); + _I("[%s] unlocked by %5d", states[state].name, pid); + /* for debug */ + _SD("be requested UNLOCK info pname(%s) flag(%d)", pname, flags); + set_unlock_time(pid, state); - device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)false); + device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value); } static int proc_condition(PMMsg *data) @@ -1055,15 +1503,11 @@ static int proc_condition(PMMsg *data) flags = GET_COND_FLAG(data->cond); if (flags == 0) { /* guard time for suspend */ - if (pm_cur_state == S_LCDOFF) { + if (pm_cur_state == S_LCDOFF) reset_timeout(states[S_LCDOFF].timeout); - _I("Margin timeout(%d ms)", states[S_LCDOFF].timeout); - } } else { - if (flags & PM_FLAG_RESET_TIMER) { + if (flags & PM_FLAG_RESET_TIMER) reset_timeout(states[pm_cur_state].timeout); - _I("Reset timeout(%d ms)", states[pm_cur_state].timeout); - } } if (!timeout_src_id) @@ -1076,13 +1520,13 @@ static int proc_condition(PMMsg *data) int check_processes(enum state_t prohibit_state) { dd_list *elem, *next; - PmLockNode *t; + PmLockNode *t = NULL; int ret = 0; DD_LIST_FOREACH_SAFE(cond_head[prohibit_state], elem, next, t) { if (t->pid < INTERNAL_LOCK_BASE && kill(t->pid, 0) == -1) { - _E("Process(%d) does not exist, delete the REQ" - " - prohibit state=%d.", + _E("%d process does not exist, delete the REQ" + " - prohibit state %d ", t->pid, prohibit_state); if (t->pid == custom_change_pid) { get_lcd_timeout_from_settings(); @@ -1090,6 +1534,7 @@ int check_processes(enum state_t prohibit_state) custom_change_pid = -1; } ret = 1; + set_unlock_time(t->pid, prohibit_state); del_node(prohibit_state, t); } } @@ -1100,7 +1545,7 @@ int check_processes(enum state_t prohibit_state) int check_holdkey_block(enum state_t state) { dd_list *elem; - PmLockNode *t; + PmLockNode *t = NULL; int ret = 0; _I("Check holdkey block: state of %s", states[state].name); @@ -1125,11 +1570,9 @@ int check_holdkey_block(enum state_t state) int delete_condition(enum state_t state) { dd_list *elem, *next; - PmLockNode *t; - pid_t pid; - char pname[PATH_MAX]; + PmLockNode *t = NULL; - _I("Delete condition: state of %s", states[state].name); + _I("delete condition : state of %s", states[state].name); if (!cond_head[state]) return 0; @@ -1139,13 +1582,11 @@ int delete_condition(enum state_t state) g_source_remove(t->timeout_id); t->timeout_id = 0; } - pid = t->pid; if (state == S_LCDOFF) - set_process_active(FALSE, pid); - _I("Delete node of pid(%d).", pid); + set_process_active(false, t->pid); + _I("delete node of pid(%d)", t->pid); + set_unlock_time(t->pid, state); del_node(state, t); - get_pname(pid, pname); - set_unlock_time(pname, state-1); } DD_LIST_FREE_LIST(cond_head[state]); @@ -1187,8 +1628,9 @@ static pm_history pm_history_log[MAX_LOG_COUNT] = {{0, }, }; static int history_count = 0; static const char history_string[PM_LOG_MAX][15] = { - "PRESS", "LONG PRESS", "RELEASE", "LCD ON", "LCD ON FAIL", - "LCD DIM", "LCD DIM FAIL", "LCD OFF", "LCD OFF FAIL", "SLEEP"}; + "PRESS", "LONG PRESS", "RELEASE", "LCD ON", "LCD ON COMPL", "LCD ON FAIL", + "LCD DIM", "LCD DIM FAIL", "LCD OFF", "LCD OFF COMPL", "LCD OFF FAIL", + "LCD FAIL", "SLEEP"}; void pm_history_init() { @@ -1241,7 +1683,7 @@ void pm_history_print(int fd, int count) time_buf); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); } } #endif @@ -1265,13 +1707,13 @@ void print_info(int fd) "===========================\n"); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Timeout Info: Run[%dms] Dim[%dms] Off[%dms]\n", states[S_NORMAL].timeout, states[S_LCDDIM].timeout, states[S_LCDOFF].timeout); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Tran. Locked : %s %s %s\n", (trans_condition & MASK_NORMAL) ? states[S_NORMAL].name : "-", @@ -1279,18 +1721,18 @@ void print_info(int fd) (trans_condition & MASK_OFF) ? states[S_LCDOFF].name : "-"); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Current State: %s\n", states[pm_cur_state].name); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Current Lock Conditions: \n"); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); for (s_index = S_NORMAL; s_index < S_END; s_index++) { DD_LIST_FOREACH(cond_head[s_index], elem, t) { @@ -1301,7 +1743,7 @@ void print_info(int fd) i++, states[s_index].name, t->pid, pname, time_buf); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); } } @@ -1312,37 +1754,39 @@ void print_info(int fd) #endif } -void save_display_log(void) +void save_display_log(char *path) { int fd, ret; char buf[255]; time_t now_time; char time_buf[30]; - _D("Internal state is saved."); + _D("internal state is saved!"); time(&now_time); ctime_r(&now_time, time_buf); - fd = open(PM_STATE_LOG_FILE, O_CREAT | O_TRUNC | O_WRONLY, 0644); + fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0644); if (fd != -1) { snprintf(buf, sizeof(buf), "\npm_state_log now-time : %d(s) %s\n\n", (int)now_time, time_buf); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("write() failed (%d)", errno); snprintf(buf, sizeof(buf), "pm_status_flag: %x\n", pm_status_flag); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("write() failed (%d)", errno); - snprintf(buf, sizeof(buf), "screen lock status : %d\n", - __get_lock_screen_state()); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed: %d", errno); + if (disp_plgn.get_lock_screen_state ) { + snprintf(buf, sizeof(buf), "screen lock status : %d\n", + disp_plgn.get_lock_screen_state()); + ret = write(fd, buf, strlen(buf)); + if (ret < 0) + _E("write() failed (%d)", errno); + } print_info(fd); close(fd); } @@ -1359,7 +1803,9 @@ void save_display_log(void) */ static void sig_hup(int signo) { - save_display_log(); + _I("received sig hub %d", signo); + + pm_save_logdump(); } int check_lcdoff_direct(void) @@ -1373,6 +1819,9 @@ int check_lcdoff_direct(void) if (pm_cur_state != S_LCDDIM) return false; + if (!display_conf.dimming) + return true; + lock = __get_lock_screen_state(); if (lock != VCONFKEY_IDLE_LOCK && hallic_open) return false; @@ -1387,7 +1836,7 @@ int check_lcdoff_direct(void) else if (ret < 0) _E("Failed to get vconf value for cradle status: %d", vconf_get_ext_errno()); - _D("Goto LCDOFF direct(lock=%d hdmi=%d cradle=%d).", lock, hdmi_state, cradle); + _D("Goto LCDOFF direct: lock(%d) hdmi(%d) cradle(%d).", lock, hdmi_state, cradle); return true; } @@ -1481,22 +1930,10 @@ static inline void stop_lock_timer(void) static void check_lock_screen(void) { - int lock_setting, lock_state, app_state, ret; + int lock_state, ret; stop_lock_timer(); - ret = vconf_get_int(VCONFKEY_CALL_STATE, &app_state); - if (ret >= 0 && app_state != VCONFKEY_CALL_OFF) - goto lcd_on; - else if (ret < 0) - _E("Failed to get vconf value for call state: %d", vconf_get_ext_errno()); - - /* check setting of lock screen is enabled. */ - ret = vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, - &lock_setting); - if (ret < 0) - _E("Failed to get vconf value for screen lock type: %d", vconf_get_ext_errno()); - /* check state of lock */ ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); if (ret < 0 || lock_state == VCONFKEY_IDLE_LOCK) { @@ -1551,10 +1988,12 @@ static int default_action(int timeout) } if (pm_cur_state != pm_old_state && pm_cur_state != S_SLEEP) { - if (power_ops.get_power_lock_support()) + if (power_ops.get_power_lock_support()) { + broadcast_pm_wakeup(); power_ops.power_lock(); + } set_setting_pmstate(pm_cur_state); - device_notify(DEVICE_NOTIFIER_LCD, &pm_cur_state); + device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); } if (pm_old_state == S_NORMAL && pm_cur_state != S_NORMAL) { @@ -1594,11 +2033,11 @@ static int default_action(int timeout) if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) { stop_lock_timer(); /* lcd off state : turn off the backlight */ - if (backlight_ops.get_lcd_power() != DPMS_OFF) + if (backlight_ops.get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); } - if (backlight_ops.get_lcd_power() != DPMS_OFF + if (backlight_ops.get_lcd_power() == DPMS_ON || lcd_paneloff_mode) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); break; @@ -1607,7 +2046,7 @@ static int default_action(int timeout) if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) stop_lock_timer(); - if (backlight_ops.get_lcd_power() != DPMS_OFF) + if (backlight_ops.get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); if (!power_ops.get_power_lock_support()) { @@ -1634,6 +2073,7 @@ go_suspend: #ifdef ENABLE_PM_LOG pm_history_save(PM_LOG_SLEEP, pm_cur_state); #endif + broadcast_pm_suspend(); if (power_ops.get_power_lock_support()) { if (power_ops.enable_autosleep) power_ops.enable_autosleep(); @@ -1641,24 +2081,9 @@ go_suspend: if (power_ops.power_unlock() < 0) _E("Power unlock state error."); } else { - dd_list *elem, *elem_n; - const struct device_ops *dev; - /* Devices Suspend */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->suspend) - dev->suspend(); - } - power_ops.suspend(); - - /* Devices Resume */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->resume) - dev->resume(); - } - - _I("System wakeup."); - disp_plgn.system_wakeup_flag = true; + _I("system wakeup!!"); + system_wakeup_flag = true; /* Resume !! */ if (power_ops.check_wakeup_src() == EVENT_DEVICE) /* system waked up by devices */ @@ -1739,7 +2164,7 @@ static int poll_callback(int condition, PMMsg *data) if (condition == INPUT_POLL_EVENT) { if (pm_cur_state == S_LCDOFF || pm_cur_state == S_SLEEP) - _I("Power key input."); + _I("Input event signal at Display Off"); time(&now); if (last_t != now || pm_cur_state == S_LCDOFF || @@ -1800,11 +2225,13 @@ static int update_setting(int key_idx, int val) } pm_status_flag |= CHRGR_FLAG; } else { - int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; + int bat_state; ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state); - if (ret < 0) + if (ret < 0) { + bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); + } if (low_battery_state(bat_state)) { power_saving_func(true); pm_status_flag |= LOWBT_FLAG; @@ -1877,9 +2304,9 @@ static void check_seed_status(void) { int ret = -1; int tmp = 0; - int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; + int bat_state; int brt = 0; - int lock_state = -1; + int lock_state; /* Charging check */ if ((get_charging_status(&tmp) == 0) && (tmp > 0)) @@ -1898,10 +2325,13 @@ static void check_seed_status(void) } _I("Set brightness(%d) from setting app.", tmp); backlight_ops.set_default_brt(tmp); + backlight_ops.set_brightness(tmp); ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state); - if (ret < 0) + if (ret < 0) { + bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); + } if (low_battery_state(bat_state)) { if (!(pm_status_flag & CHRGR_FLAG)) { power_saving_func(true); @@ -1911,9 +2341,10 @@ static void check_seed_status(void) /* lock screen check */ ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret < 0) + if (ret < 0) { + lock_state = -1; _E("Failed to get vconf value for idle lock state: %d", vconf_get_ext_errno()); - + } set_lock_screen_state(lock_state); if (lock_state == VCONFKEY_IDLE_LOCK) { states[S_NORMAL].timeout = lock_screen_timeout; @@ -2043,36 +2474,20 @@ void reset_lcd_timeout(GDBusConnection *conn, static int booting_done(void *data) { - static int done; - - if (!data) - return done; + static bool done = false; + if (data != NULL) { done = *(int*)data; - if (!done) - return done; - - _I("Booting done. Release display and power lock."); - if (disp_plgn.pm_unlock_internal) { - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, PM_SLEEP_MARGIN); + if (done) + return 0; + _I("booting done, unlock LCD_OFF"); + if (disp_plgn.pm_unlock_internal) { + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, PM_SLEEP_MARGIN); + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); + } } - return done; -} - -int device_poweroff(void *data) -{ - static int off; - - if (!data) - return off; - - off = *(int *)data; - if (off) - _I("Poweroff"); - - return off; + return 0; } static int process_background(void *data) @@ -2085,7 +2500,7 @@ static int process_background(void *data) node = find_node(S_NORMAL, pid); if (node) { node->background = true; - _I("Process(%d) is background, then PM will be unlocked LCD_NORMAL.", pid); + _I("%d pid is background, then PM will be unlocked LCD_NORMAL", pid); } return 0; @@ -2101,9 +2516,29 @@ static int process_foreground(void *data) node = find_node(S_NORMAL, pid); if (node) { node->background = false; - _I("Process(%d) is foreground, then PM will be maintained locked LCD_NORMAL.", pid); + _I("Process(%d) is background, then PM will be unlocked LCD_NORMAL.", pid); + } + + return 0; +} + +static int battery_health_changed(void *data) +{ + int health = DATA_VALUE_INT(data); + + _I("battery health change %d", health); + + if (health == HEALTH_GOOD) { + pm_status_flag &= ~BATTERY_FLAG; + pm_status_flag &= ~DIMSTAY_FLAG; + } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) { + pm_status_flag |= BATTERY_FLAG; + pm_status_flag |= DIMSTAY_FLAG; } + if (backlight_ops.get_lcd_power() == DPMS_ON) + backlight_ops.update(); + return 0; } @@ -2121,49 +2556,58 @@ static int display_load_config(struct parse_result *result, void *user_data) if (MATCH(result->name, "LockScreenWaitingTime")) { SET_CONF(c->lock_wait_time, atof(result->value)); - _D("'lock wait time' is %.3f.", c->lock_wait_time); + _D("lock wait time is %.3f", c->lock_wait_time); } else if (MATCH(result->name, "LongPressInterval")) { SET_CONF(c->longpress_interval, atof(result->value)); - _D("'long press interval' is %.3f.", c->longpress_interval); + _D("long press interval is %.3f", c->longpress_interval); } else if (MATCH(result->name, "LightSensorSamplingInterval")) { SET_CONF(c->lightsensor_interval, atof(result->value)); - _D("'lightsensor interval' is %.3f.", c->lightsensor_interval); + _D("lightsensor interval is %.3f", c->lightsensor_interval); } else if (MATCH(result->name, "LCDOffTimeout")) { SET_CONF(c->lcdoff_timeout, atoi(result->value)); - _D("'lcdoff timeout' is %d ms.", c->lcdoff_timeout); + _D("lcdoff timeout is %d ms", c->lcdoff_timeout); } else if (MATCH(result->name, "BrightnessChangeStep")) { SET_CONF(c->brightness_change_step, atoi(result->value)); - _D("'brightness change step' is %d.", c->brightness_change_step); + _D("brightness change step is %d", c->brightness_change_step); } else if (MATCH(result->name, "LCDAlwaysOn")) { c->lcd_always_on = (MATCH(result->value, "yes") ? 1 : 0); - _D("'LCD always on' is %d.", c->lcd_always_on); + _D("LCD always on is %d", c->lcd_always_on); + } else if (MATCH(result->name, "Dimming")) { + c->dimming = (MATCH(result->value, "yes") ? 1 : 0); + _D("Dimming is %d", c->dimming); } else if (MATCH(result->name, "ChangedFrameRateAllowed")) { if (strstr(result->value, "setting")) { c->framerate_app[REFRESH_SETTING] = 1; - _D("'framerate app' is setting"); + _D("framerate app is Setting"); } if (strstr(result->value, "all")) { memset(c->framerate_app, 1, sizeof(c->framerate_app)); - _D("'framerate app' is all"); + _D("framerate app is All"); } } else if (MATCH(result->name, "ControlDisplay")) { c->control_display = (MATCH(result->value, "yes") ? 1 : 0); - _D("'ControlDisplay' is %d.", c->control_display); + _D("ControlDisplay is %d", c->control_display); } else if (MATCH(result->name, "PowerKeyDoublePressSupport")) { c->powerkey_doublepress = (MATCH(result->value, "yes") ? 1 : 0); - _D("'PowerKeyDoublePressSupport' is %d.", c->powerkey_doublepress); + _D("PowerKeyDoublePressSupport is %d", c->powerkey_doublepress); } else if (MATCH(result->name, "AccelSensorOn")) { c->accel_sensor_on = (MATCH(result->value, "yes") ? 1 : 0); - _D("'AccelSensorOn' is %d.", c->accel_sensor_on); + _D("AccelSensorOn is %d", c->accel_sensor_on); } else if (MATCH(result->name, "ContinuousSampling")) { c->continuous_sampling = (MATCH(result->value, "yes") ? 1 : 0); - _D("'ContinuousSampling' is %d.", c->continuous_sampling); + _D("ContinuousSampling is %d", c->continuous_sampling); } else if (MATCH(result->name, "TimeoutEnable")) { c->timeout_enable = (MATCH(result->value, "yes") ? true : false); - _D("'Timeout' is %s.", c->timeout_enable ? "enalbed" : "disabled"); + _D("Timeout is %s", c->timeout_enable ? "enalbed" : "disabled"); } else if (MATCH(result->name, "InputSupport")) { c->input_support = (MATCH(result->value, "yes") ? true : false); - _D("'Input' is %s.", c->input_support ? "supported" : "NOT supported"); + _D("Input is %s", c->input_support ? "supported" : "NOT supported"); + } else if (MATCH(result->name, "LockCheckTimeout")) { + SET_CONF(c->lockcheck_timeout, atoi(result->value)); + _D("LockCheckTimeout is %d", c->lockcheck_timeout); + } else if (MATCH(result->name, "AODTSP")) { + c->aod_tsp = (MATCH(result->value, "yes") ? true : false); + _D("TSP control at is %d at aod", c->aod_tsp); } return 0; @@ -2226,9 +2670,58 @@ static int display_probe(void *data) return 0; } +static int input_init_handler(void) +{ + if (!display_conf.input_support) + return 0; + + g_idle_add(init_input, NULL); + + return 0; +} + +static void esd_action(void) +{ + const struct device_ops *touchscreen_ops = NULL; + + _I("ESD on"); + + touchscreen_ops = find_device("touchscreen"); + + if (!check_default(touchscreen_ops)) + touchscreen_ops->stop(NORMAL_MODE); + backlight_ops.off(NORMAL_MODE); + backlight_ops.on(NORMAL_MODE); + if (!check_default(touchscreen_ops)) + touchscreen_ops->start(NORMAL_MODE); +} + +static void lcd_uevent_changed(struct udev_device *dev) +{ + const char *devpath; + const char *action; + + devpath = udev_device_get_devpath(dev); + if (!devpath) + return; + + if (!fnmatch(LCD_ESD_PATH, devpath, 0)) { + action = udev_device_get_action(dev); + if (!strcmp(action, UDEV_CHANGE)) + esd_action(); + } +} + +static const struct uevent_handler lcd_uevent_ops = { + .subsystem = LCD_EVENT_SUBSYSTEM, + .uevent_func = lcd_uevent_changed, + .data = NULL, +}; + static void display_init(void *data) { int ret, i; + unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); int timeout = 0; bool wm_ready; @@ -2244,10 +2737,16 @@ static void display_init(void *data) _W("Failed to load '%s', use default value: %d", DISPLAY_CONF_FILE, ret); + register_kernel_uevent_control(&lcd_uevent_ops); + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); register_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); register_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); - register_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); + register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); + register_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); + register_notifier(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, display_auto_brightness_sensing); + + init_save_userlock(); for (i = INIT_SETTING; i < INIT_END; i++) { switch (i) { @@ -2257,15 +2756,14 @@ static void display_init(void *data) case INIT_INTERFACE: if (display_conf.timeout_enable) get_lcd_timeout_from_settings(); - ret = init_sysfs(); + ret = init_sysfs(flags); break; case INIT_POLL: - _I("Input init."); + _I("input init"); pm_callback = poll_callback; - if (display_conf.input_support) - ret = init_input(); - else - ret = 0; + ret = input_init_handler(); + + pm_lock_detector_init(); break; case INIT_DBUS: _I("Dbus init."); @@ -2286,6 +2784,13 @@ static void display_init(void *data) init_lcd_operation(); check_seed_status(); + /* In smd test, TSP should be turned off if display panel is not existed. */ + if (backlight_ops.get_lcd_power() == -ENOENT) { + _I("Display panel is not existed."); + lcd_direct_control(DPMS_OFF, NORMAL_MODE); + exit_lcd_operation(); + } + /* wm_ready needs to be checked * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ @@ -2300,33 +2805,35 @@ static void display_init(void *data) trans_table[S_NORMAL][EVENT_TIMEOUT] = S_NORMAL; } - _I("Start Power managing without noti."); - if (power_ops.get_power_lock_support()) + if (flags & WITHOUT_STARTNOTI) { /* start without noti */ + _I("Start Power managing without noti"); + if (power_ops.get_power_lock_support()) { + broadcast_pm_wakeup(); power_ops.power_lock(); + } + pm_cur_state = S_NORMAL; + vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + + status = DEVICE_OPS_STATUS_START; + if (display_conf.timeout_enable) { + timeout = states[S_NORMAL].timeout; + /* check minimun lcd on time */ + if (timeout < SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT)) + timeout = SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT); + + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, + STAY_CUR_STATE, timeout); + } - pm_cur_state = S_NORMAL; - set_setting_pmstate(pm_cur_state); - - if (display_conf.timeout_enable) { - timeout = states[S_NORMAL].timeout; - /* check minimun lcd on time */ - if (timeout < SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT)) - timeout = SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT); - - reset_timeout(timeout); - } - - status = DEVICE_OPS_STATUS_START; - /* - * Lock lcd off until booting is done. - * deviced guarantees all booting script is executing. - * Last script of booting unlocks this suspend blocking state. - */ - if (disp_plgn.pm_lock_internal) { - disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, - STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); - disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, - STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); + /* + * Lock lcd off until booting is done. + * deviced guarantees all booting script is executing. + * Last script of booting unlocks this suspend blocking state. + */ + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, + STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); } if (display_conf.input_support) @@ -2350,6 +2857,8 @@ static void display_exit(void *data) if (CHECK_OPS(keyfilter_ops, exit)) keyfilter_ops->exit(); + unregister_kernel_uevent_control(&lcd_uevent_ops); + display_ops_exit(NULL); for (i = i - 1; i >= INIT_SETTING; i--) { @@ -2364,7 +2873,8 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); unregister_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); unregister_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); - unregister_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); + unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); + unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); exit_input(); break; @@ -2390,6 +2900,7 @@ static int display_start(enum device_flags flags) else /* normal lcd on */ backlight_ops.on(flags); + return 0; } @@ -2411,7 +2922,7 @@ static int display_start(enum device_flags flags) static int display_stop(enum device_flags flags) { /* NORMAL MODE */ - if (flags & NORMAL_MODE) { + if (flags & NORMAL_MODE || flags & FORCE_OFF_MODE) { backlight_ops.off(flags); return 0; } @@ -2435,7 +2946,7 @@ static int display_status(void) static const struct device_ops display_device_ops = { .priority = DEVICE_PRIORITY_HIGH, - .name = "display", + DECLARE_NAME_LEN("display"), .probe = display_probe, .init = display_init, .exit = display_exit, diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index 01b98ac..37a86cb 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -29,19 +29,21 @@ #include #include #include -#include +#include #include "ambient-mode.h" #include "core/log.h" #include "core/devices.h" -#include "core/list.h" #include "core/common.h" -#include "display/display-dpms.h" +#include "core/device-notifier.h" #include "util.h" #include "device-interface.h" #include "vconf.h" #include "core.h" #include "device-node.h" +#include "display/display-dpms.h" + +#define SET_SUSPEND_TIME 0.5 #define TOUCH_ON 1 #define TOUCH_OFF 0 @@ -49,7 +51,8 @@ #define LCD_PHASED_MIN_BRIGHTNESS 1 #define LCD_PHASED_MAX_BRIGHTNESS 100 #define LCD_PHASED_CHANGE_STEP 5 -#define LCD_PHASED_DELAY 35000 /* microsecond */ +#define LCD_PHASED_DELAY 10000 /* microsecond */ +#define DUMP_MODE_WAITING_TIME 600000 /* microsecond */ #define POWER_AUTOSLEEP_PATH "/sys/power/autosleep" #define POWER_LOCK_PATH "/sys/power/wake_lock" @@ -57,24 +60,57 @@ #define POWER_WAKEUP_PATH "/sys/power/wakeup_count" #define POWER_STATE_PATH "/sys/power/state" -enum { - POWER_UNLOCK = 0, - POWER_LOCK, -}; +#define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" + +#define GESTURE_STR "gesture" +#define POWERKEY_STR "powerkey" +#define EVENT_STR "event" +#define TOUCH_STR "touch" +#define TIMEOUT_STR "timeout" +#define PROXIMITY_STR "proximity" +#define PALM_STR "palm" +#define UNKNOWN_STR "unknown" + +#define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" struct _backlight_ops backlight_ops; struct _power_ops power_ops; +static int mainlock_status = POWER_UNLOCK; static bool custom_status; static int custom_brightness; static int force_brightness; static int default_brightness; - +static int vital_support = -2; +static int vital_service; +static bool vital_sleep; +static int dpms_running_state = DPMS_SETTING_DONE; static struct display_device *display_dev; +static guint release_timer; -static int bl_onoff(int on) +struct display_device *display_dev_get(void) +{ + return display_dev; +} + +void dpms_set_running_state(int val) +{ + dpms_running_state = val; +} + +static int bl_onoff(int on, enum device_flags flags) { dpms_set_state(on); + +#ifdef ENABLE_PM_LOG + if (on == DPMS_ON) + pm_history_save(PM_LOG_LCD_ON_COMPLETE, pm_cur_state); + else if (on == DPMS_OFF || on == DPMS_FORCE_OFF) + pm_history_save(PM_LOG_LCD_OFF_COMPLETE, pm_cur_state); + else + pm_history_save(PM_LOG_LCD_CONTROL_FAIL, on); +#endif + return 0; } @@ -85,12 +121,6 @@ static int bl_brt(int brightness, int delay) if (delay > 0) usleep(delay); - if (force_brightness > 0) { - _I("brightness=%d force brightness=%d", - brightness, force_brightness); - brightness = force_brightness; - } - /* Update device brightness */ ret = backlight_ops.set_brightness(brightness); @@ -115,39 +145,96 @@ static int system_enable_autosleep(void) return sys_set_str(POWER_AUTOSLEEP_PATH, "mem"); } -static int system_power_lock(void) +static int vital_mode_support(void) { - dd_list *elem, *elem_n; - const struct device_ops *dev; - int ret; + if (vital_support < 0) { + FILE *fp; + + fp = fopen(FREEZER_VITAL_WAKEUP_CGROUP, "r"); + if (fp == NULL) { + _E("%s open failed", FREEZER_VITAL_WAKEUP_CGROUP); + /* read max 2 times to check if this file exist */ + vital_support++; + return 0; + } + vital_support = 1; + fclose(fp); + } + return vital_support; +} - _I("system power lock."); - ret = sys_set_str(POWER_LOCK_PATH, "mainlock"); +static int suspend_other_process(int type) +{ + int ret = 0; + char buf[8]; + const char *command[1]; - /* Devices Resume */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->resume) - dev->resume(); - } + if (vital_service == type) + return ret; + + if (type == VITAL_WAKEUP && vital_service > VITAL_SLEEP) + return ret; + + vital_service = type; + + if (!vital_mode_support()) + return ret; + if (type == VITAL_SLEEP) { + snprintf(buf, sizeof(buf), "%s", "sleep"); + command[0] = buf; + dbus_handle_method_sync_timeout(RESOURCED_BUS_NAME, + RESOURCED_PATH_FREEZER, + RESOURCED_INTERFACE_FREEZER, + "SetSuspend", + "s", + command, + SET_SUSPEND_TIME*1000); + vital_sleep = true; + } else if (type == VITAL_WAKEUP) { + snprintf(buf, sizeof(buf), "%s", "wakeup"); + command[0] = buf; + ret = dbus_handle_method_async(RESOURCED_BUS_NAME, + RESOURCED_PATH_FREEZER, + RESOURCED_INTERFACE_FREEZER, + "SetSuspend", + "s", command); + } else if (type == VITAL_EXIT) { + snprintf(buf, sizeof(buf), "%s", "exit"); + command[0] = buf; + ret = dbus_handle_method_async(RESOURCED_BUS_NAME, + RESOURCED_PATH_FREEZER, + RESOURCED_INTERFACE_FREEZER, + "SetSuspend", + "s", command); + vital_sleep = false; + } return ret; } -static int system_power_unlock(void) +static int system_power_lock(void) { - dd_list *elem, *elem_n; - const struct device_ops *dev; + _I("system power lock"); + suspend_other_process(VITAL_WAKEUP); + mainlock_status = POWER_LOCK; - /* Devices Suspend */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->suspend) - dev->suspend(); - } + return sys_set_str(POWER_LOCK_PATH, "mainlock"); +} + +static int system_power_unlock(void) +{ + _I("system power unlock"); + suspend_other_process(VITAL_SLEEP); + mainlock_status = POWER_UNLOCK; - _I("system power unlock."); return sys_set_str(POWER_UNLOCK_PATH, "mainlock"); } +static int system_get_power_lock(void) +{ + return mainlock_status; +} + static int system_get_power_lock_support(void) { static int power_lock_support = -1; @@ -162,7 +249,7 @@ static int system_get_power_lock_support(void) else power_lock_support = true; - _I("system power lock: %s", + _I("System power lock: %s", (power_lock_support ? "support" : "not support")); out: @@ -174,9 +261,6 @@ static int get_lcd_power(void) enum display_state val; int ret; - if (ambient_get_state()) - return DPMS_OFF; - if (!display_dev || !display_dev->get_state) { _E("There is no display device."); return -ENOENT; @@ -186,6 +270,12 @@ static int get_lcd_power(void) if (ret < 0) return ret; + if (val == DISPLAY_ON && ambient_get_state()) + return DPMS_OFF; + + if (dpms_running_state != DPMS_SETTING_DONE) + return dpms_running_state; + switch (val) { case DISPLAY_ON: return DPMS_ON; @@ -202,13 +292,16 @@ static int get_lcd_power(void) bool display_dimstay_check(void) { + if (pm_status_flag & DIM_FLAG) + return true; + if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) return true; return false; } -void change_brightness(int start, int end, int step) +static void change_brightness(int start, int end, int step) { int diff, val; int ret = -1; @@ -226,7 +319,20 @@ void change_brightness(int start, int end, int step) if (prev == end) return; - _D("start=%d end=%d step=%d", start, end, step); + if (pm_status_flag & DIM_MASK) + end = 0; + + _I("start %d end %d step %d", start, end, step); + + if (display_dev && display_dev->set_multi_brightness) { + ret = display_dev->set_multi_brightness(end, step, LCD_PHASED_DELAY); + if (ret < 0) + _E("Failed to set_multi_brightness (%d)", ret); + + backlight_ops.set_brightness(end); + + return; + } diff = end - start; @@ -250,16 +356,15 @@ void change_brightness(int start, int end, int step) static int backlight_on(enum device_flags flags) { int ret = -1; + static int cnt; - _D("LCD on %x", flags); + _I("[DPMS XLIB Backlight] LCD on %x cnt:%d", flags, cnt); - ret = bl_onoff(DPMS_ON); - if (ret < 0) - _E("Failed to turn on backlight."); - - if (flags & LCD_PHASED_TRANSIT_MODE) - change_brightness(LCD_PHASED_MIN_BRIGHTNESS, - default_brightness, LCD_PHASED_CHANGE_STEP); + cnt++; + ret = bl_onoff(DPMS_ON, flags); +#ifdef ENABLE_PM_LOG + pm_history_save(PM_LOG_LCD_ON, pm_cur_state); +#endif return ret; } @@ -267,19 +372,30 @@ static int backlight_on(enum device_flags flags) static int backlight_off(enum device_flags flags) { int ret = -1; + static int cnt, ambient_cnt; + + if (flags & AMBIENT_MODE) { + _I("[DPMS XLIB Backlight] LCD suspend %x cnt:%d", flags, ambient_cnt); + ambient_cnt++; + + return 0; + } - _D("LCD off %x", flags); + _I("[DPMS XLIB Backlight] LCD off %x cnt:%d", flags, cnt); + cnt++; if (flags & LCD_PHASED_TRANSIT_MODE) - change_brightness(default_brightness, + backlight_ops.transit_brt(default_brightness, LCD_PHASED_MIN_BRIGHTNESS, LCD_PHASED_CHANGE_STEP); - if (flags & AMBIENT_MODE) - return 0; + if (flags & FORCE_OFF_MODE) + ret = bl_onoff(DPMS_FORCE_OFF, flags); + else + ret = bl_onoff(DPMS_OFF, flags); - ret = bl_onoff(DPMS_OFF); - if (ret < 0) - _E("Failed to turn off backlight."); +#ifdef ENABLE_PM_LOG + pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); +#endif return ret; } @@ -287,15 +403,8 @@ static int backlight_off(enum device_flags flags) static int backlight_dim(void) { int ret; - int brightness; - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, &brightness); - if (ret < 0) { - _E("Failed to get vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - return -EPERM; - } - - ret = bl_brt(brightness, 0); + ret = backlight_ops.set_brightness(PM_DIM_BRIGHTNESS); #ifdef ENABLE_PM_LOG if (!ret) pm_history_save(PM_LOG_LCD_DIM, pm_cur_state); @@ -335,11 +444,11 @@ static int custom_backlight_update(void) custom_brightness > PM_MAX_BRIGHTNESS) return -EINVAL; - if (display_dimstay_check()) { + if (display_dimstay_check()) ret = backlight_dim(); - } else { - _I("Custom brightness(%d) restored.", custom_brightness); - ret = bl_brt(custom_brightness, 0); + else { + _I("custom brightness restored! %d", custom_brightness); + ret = backlight_ops.set_brightness(custom_brightness); } return ret; @@ -358,16 +467,18 @@ static int set_force_brightness(int level) static int backlight_update(void) { int ret = 0; + int brt; if (get_custom_status()) { - _I("Custom brightness mode. brt no updated."); + _I("custom brightness mode! brt no updated"); return 0; } if (display_dimstay_check()) ret = backlight_dim(); - else - ret = bl_brt(default_brightness, 0); - + else { + brt = backlight_ops.get_default_brt(); + ret = backlight_ops.set_brightness(brt); + } return ret; } @@ -377,7 +488,7 @@ static int backlight_standby(int force) if ((get_lcd_power() == DPMS_ON) || force) { _I("LCD standby"); - ret = bl_onoff(DPMS_STANDBY); + ret = bl_onoff(DPMS_STANDBY, 0); } return ret; @@ -393,6 +504,11 @@ static int set_default_brt(int level) return 0; } +static int get_default_brt(void) +{ + return default_brightness; +} + static int check_wakeup_src(void) { /* TODO if nedded. @@ -470,10 +586,22 @@ static int set_brightness(int val) return max; } + if (force_brightness > 0 && val != PM_DIM_BRIGHTNESS) { + _I("brightness(%d), force brightness(%d)", + val, force_brightness); + val = force_brightness; + } + + if (pm_status_flag & DIM_MASK) + val = 0; + /* Maximum Brightness to users is 100. * Thus real brightness need to be calculated */ val = val * max / 100; + _I("set brightness %d (default:%d)", val, default_brightness); + device_notify(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, (void *)&val); + return display_dev->set_brightness(val); } @@ -544,6 +672,84 @@ static int get_brightness_by_light_sensor(float lmax, float lmin, float light, i return 0; } +static int get_image_effect(enum display_image_effect *effect) +{ + int ret; + enum display_image_effect val; + + if (!display_dev || !display_dev->get_image_effect) { + _E("There is no display device."); + return -ENOENT; + } + + ret = display_dev->get_image_effect(&val); + if (ret < 0) { + _E("Failed to get image effect: %d", ret); + return ret; + } + + *effect = val; + + return 0; +} + +static int set_image_effect(enum display_image_effect effect) +{ + int ret; + + if (!display_dev || !display_dev->set_image_effect) { + _E("There is no display device."); + return -ENOENT; + } + + ret = display_dev->set_image_effect(effect); + if (ret < 0) { + _E("Failed to set image effect: %d", ret); + return ret; + } + + return 0; +} + +static int get_panel_mode(enum display_panel_mode *mode) +{ + int ret; + enum display_panel_mode val; + + if (!display_dev || !display_dev->get_panel_mode) { + _E("there is no display device"); + return -ENOENT; + } + + ret = display_dev->get_panel_mode(&val); + if (ret < 0) { + _E("failed to get panel mode(%d)", ret); + return ret; + } + + *mode = val; + + return 0; +} + +static int set_panel_mode(enum display_panel_mode mode) +{ + int ret; + + if (!display_dev || !display_dev->set_panel_mode) { + _E("there is no display device"); + return -ENOENT; + } + + ret = display_dev->set_panel_mode(mode); + if (ret < 0) { + _E("failed to set panel mode(%d)", ret); + return ret; + } + + return 0; +} + static int get_frame_rate(int *rate) { if (!rate) @@ -595,6 +801,101 @@ static int set_frame_rate(int rate) return display_dev->set_frame_rate(rate); } +/* It was operated only AOD enter & leave */ +static int backlight_transit_state(int state) +{ + int brt, val; + int start, end; + + backlight_ops.get_brightness(&brt); + + if (state == DPMS_OFF) { + start = brt; + end = display_conf.aod_enter_level; + + /* + * The value of backlight_ops.get_brightness is system brightness. + * But when device is LBM, the value is not same with real brightness. + * So it should be read exactly value for transit smooth effect + */ + get_brightness(&val); + + if (val > display_conf.aod_enter_level) + backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + } else { + /* prevent transit effect when another effect is already executed */ + if (brt != display_conf.aod_enter_level) { + _W("effect is already executed brt(%d) aod_level(%d)", + brt, display_conf.aod_enter_level); + return 0; + } + + start = display_conf.aod_enter_level; + end = default_brightness; + backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + } + + return 0; +} + +static gboolean blink_cb(gpointer data) +{ + static bool flag; + + set_brightness(flag ? PM_MAX_BRIGHTNESS : PM_MIN_BRIGHTNESS); + + flag = !flag; + + return G_SOURCE_CONTINUE; +} + +static void blink(int timeout) +{ + static guint timer; + + if (timer) { + g_source_remove(timer); + timer = 0; + } + + if (timeout < 0) { + _E("timeout value is invalid %d", timeout); + return; + } + + if (timeout == 0) { + backlight_update(); + return; + } + + timer = g_timeout_add(timeout, blink_cb, NULL); +} + +static gboolean release_blink_cb(gpointer data) +{ + blink(0); + + release_timer = 0; + return G_SOURCE_REMOVE; +} + +static void release_blink(void) +{ + if (release_timer) { + g_source_remove(release_timer); + release_timer = 0; + } + + release_timer = g_timeout_add(DUMP_MODE_WAITING_TIME, release_blink_cb, NULL); +} + +static void restore_brightness_func(void) +{ + backlight_ops.set_brightness = set_brightness; + backlight_ops.get_brightness = get_brightness; + backlight_ops.transit_brt = change_brightness; +} + static void _init_ops(void) { backlight_ops.off = backlight_off; @@ -603,6 +904,7 @@ static void _init_ops(void) backlight_ops.update = backlight_update; backlight_ops.standby = backlight_standby; backlight_ops.set_default_brt = set_default_brt; + backlight_ops.get_default_brt = get_default_brt; backlight_ops.get_lcd_power = get_lcd_power; backlight_ops.set_custom_status = set_custom_status; backlight_ops.get_custom_status = get_custom_status; @@ -611,14 +913,24 @@ static void _init_ops(void) backlight_ops.set_force_brightness = set_force_brightness; backlight_ops.set_brightness = set_brightness; backlight_ops.get_brightness = get_brightness; + backlight_ops.restore_brightness_func = restore_brightness_func; backlight_ops.get_brightness_by_light_sensor = get_brightness_by_light_sensor; + backlight_ops.get_image_effect = get_image_effect; + backlight_ops.set_image_effect = set_image_effect; + backlight_ops.get_panel_mode = get_panel_mode; + backlight_ops.set_panel_mode = set_panel_mode; backlight_ops.get_frame_rate = get_frame_rate; backlight_ops.set_frame_rate = set_frame_rate; + backlight_ops.transit_state = backlight_transit_state; + backlight_ops.transit_brt = change_brightness; + backlight_ops.blink = blink; + backlight_ops.release_blink = release_blink; power_ops.suspend = system_suspend; power_ops.enable_autosleep = system_enable_autosleep; power_ops.power_lock = system_power_lock; power_ops.power_unlock = system_power_unlock; + power_ops.get_power_lock = system_get_power_lock; power_ops.get_power_lock_support = system_get_power_lock_support; power_ops.check_wakeup_src = check_wakeup_src; power_ops.get_wakeup_count = get_wakeup_count; @@ -636,12 +948,12 @@ int display_service_load(void) r = hw_get_info(DISPLAY_HARDWARE_DEVICE_ID, (const struct hw_info **)&info); if (r < 0) { - _I("Display shared library is not supported: %d", r); - return -ENODEV; + _I("display shared library is not supported: %d", r); + return 0; } if (!info->open) { - _E("Failed to open display device: open(NULL)"); + _E("Failed to open display device: open(NULL)."); return -EPERM; } @@ -672,17 +984,44 @@ int display_service_free(void) return 0; } -int init_sysfs() +bool vital_mode(void) +{ + return vital_sleep; +} + +static int vital_state_changed(void *data) +{ + int type; + + assert(data); + + type = *(int *)data; + if (type == VITAL_EXIT) + suspend_other_process(VITAL_EXIT); + + return 0; +} + +int init_sysfs(unsigned int flags) { _init_ops(); + register_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); + return 0; } int exit_sysfs(void) { + int fd; const struct device_ops *ops = NULL; + fd = open("/tmp/sem.pixmap_1", O_RDONLY); + if (fd == -1) { + _E("X server disable"); + backlight_on(NORMAL_MODE); + } + backlight_update(); disconnect_interface_with_dpms(); @@ -694,5 +1033,10 @@ int exit_sysfs(void) if (!check_default(ops)) ops->start(NORMAL_MODE); + if (fd != -1) + close(fd); + + unregister_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); + return 0; } diff --git a/plugins/iot/display/key-filter.c b/plugins/iot/display/key-filter.c index 8b35f7c..5d16df7 100644 --- a/plugins/iot/display/key-filter.c +++ b/plugins/iot/display/key-filter.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "ambient-mode.h" #include "util.h" @@ -36,11 +37,11 @@ #include "core/common.h" #include "core/devices.h" #include "core/device-notifier.h" +#include "shared/common.h" #include "power/power-handler.h" #include "led/touch-key.h" #include "apps/apps.h" -#include #ifndef KEY_SCREENLOCK #define KEY_SCREENLOCK 0x98 #endif @@ -50,21 +51,24 @@ #define PREDEF_LEAVESLEEP "leavesleep" #define POWEROFF_ACT "poweroff" +#define PWROFF_POPUP_ACT "pwroff_popup" #define USEC_PER_SEC 1000000 +#define CSC_CONFIG_MODE_RUNNING 1 #define CAPTURE_COMBINATION_INTERVAL 0.5 /* 0.5 second */ +#define TORCH_COMBINATION_INTERVAL 0.1 /* 0.1 second */ +#define DEFAULT_COMBINATION_INTERVAL 0.1 /* 0.1 second */ -#define KEY_MAX_DELAY_TIME 700 /* ms */ +#define LONGKEY_PRESSED_TIME 4 /* 4 second */ -#define KEY_RELEASED 0 -#define KEY_PRESSED 1 -#define KEY_BEING_PRESSED 2 +#define KEY_MAX_DELAY_TIME 700 /* ms */ #define SIGNAL_CHANGE_HARDKEY "ChangeHardkey" #define SIGNAL_LCDON_BY_POWERKEY "LCDOnByPowerkey" #define SIGNAL_LCDOFF_BY_POWERKEY "LCDOffByPowerkey" -#define TOUCH_RELEASE (-1) +#define NORMAL_POWER 0 +#define KEY_TEST_MODE_POWER 2 #define GLOVE_MODE 1 @@ -72,39 +76,30 @@ enum key_combination_flags { KEY_COMBINATION_STOP = 0, KEY_COMBINATION_POWERKEY = BIT(0), KEY_COMBINATION_MENUKEY = BIT(1), + KEY_COMBINATION_VOLUMEUP = BIT(2), + KEY_COMBINATION_VOLUMEDOWN = BIT(3), }; enum combination_process { COMBINATION_STOP = KEY_COMBINATION_STOP, COMBINATION_SCREENCAPTURE = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_MENUKEY, + COMBINATION_TORCH = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_VOLUMEUP, + COMBINATION_QUICKTALK = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_VOLUMEDOWN, }; -int __WEAK__ get_glove_state(void); -void __WEAK__ switch_glove_key(int val); - static struct timeval pressed_time; static guint longkey_timeout_id = 0; +static guint longkey_restore_id = 0; +static guint displayon_by_powerkey_timeout_id = 0; static int cancel_lcdoff; static int key_combination = KEY_COMBINATION_STOP; static double combination_pressed_time; static bool touch_pressed = false; static int skip_lcd_off = false; static int skip_combination = false; +static int bezel_wakeup = true; static const struct device_ops *touchled; - -static int booting_done(void *data) -{ - static int done = 0; - - if (!data) - return done; - - done = *(int *)data; - - _I("Booting done(%d)", done); - - return done; -} +static int booting_check = true; static inline int current_state_in_on(void) { @@ -128,7 +123,7 @@ static void pwroff_popup(void) _E("Failed to launch power off popup."); } -static void longkey_pressed() +static void longkey_pressed(void) { unsigned int caps; @@ -152,6 +147,14 @@ static void longkey_pressed() pwroff_popup(); } +static gboolean longkey_restore_cb(void *data) +{ + device_notify(DEVICE_NOTIFIER_LONGKEY_RESTORE, (void *)NULL); + longkey_restore_id = 0; + + return G_SOURCE_REMOVE; +} + static gboolean longkey_pressed_cb(void *data) { longkey_pressed(); @@ -196,7 +199,7 @@ static inline void broadcast_lcdoff_by_powerkey(void) NULL); } -static inline bool switch_on_lcd(void) +static inline bool switch_on_lcd(enum device_flags flags) { if (current_state_in_on()) return false; @@ -206,9 +209,12 @@ static inline bool switch_on_lcd(void) return false; } - broadcast_lcdon_by_powerkey(); + if (flags & LCD_ON_BY_POWER_KEY) + broadcast_lcdon_by_powerkey(); + else if (flags & LCD_ON_BY_TOUCH) + _I("Display on by Touch_wakeup event"); - lcd_on_direct(LCD_ON_BY_POWER_KEY); + lcd_on_direct(flags); return true; } @@ -230,15 +236,37 @@ static void check_key_combination(struct input_event *pinput) { double press_time, diff_time; press_time = (pinput->time).tv_sec + USEC_TO_SEC((pinput->time).tv_usec); + diff_time = press_time - combination_pressed_time; switch (key_combination) { case COMBINATION_SCREENCAPTURE: - diff_time = press_time - combination_pressed_time; if (diff_time <= CAPTURE_COMBINATION_INTERVAL) { _I("Combination key : SCREENCAPTURE mode"); skip_combination = true; } break; + case COMBINATION_TORCH: + if (diff_time <= TORCH_COMBINATION_INTERVAL) { + /* When torch combination, display control should be not change. */ + if (displayon_by_powerkey_timeout_id) { + g_source_remove(displayon_by_powerkey_timeout_id); + displayon_by_powerkey_timeout_id = 0; + } + _I("Combination key : TORCH mode"); + skip_combination = true; + } else + key_combination = COMBINATION_STOP; + break; + case COMBINATION_QUICKTALK: + if (diff_time <= DEFAULT_COMBINATION_INTERVAL) { + _I("Combination key : QUICK-TALK mode"); + skip_combination = true; + if (longkey_timeout_id) { + g_source_remove(longkey_timeout_id); + longkey_timeout_id = 0; + } + } + break; default: combination_pressed_time = press_time; return; @@ -255,6 +283,12 @@ static void start_key_combination(struct input_event *pinput) case KEY_MENU: key_combination |= KEY_COMBINATION_MENUKEY; break; + case KEY_VOLUMEUP: + key_combination |= KEY_COMBINATION_VOLUMEUP; + break; + case KEY_VOLUMEDOWN: + key_combination |= KEY_COMBINATION_VOLUMEDOWN; + break; default: return; } @@ -276,8 +310,14 @@ static void stop_key_combination(struct input_event *pinput) case KEY_MENU: key_combination &= ~KEY_COMBINATION_MENUKEY; break; + case KEY_VOLUMEUP: + key_combination &= ~KEY_COMBINATION_VOLUMEUP; + break; + case KEY_VOLUMEDOWN: + key_combination &= ~KEY_COMBINATION_VOLUMEDOWN; + break; default: - _E("Thid code(%d) is not combination type", pinput->code); + _E("This code(%d) is not combination type.", pinput->code); break; } } @@ -301,24 +341,118 @@ static int process_menu_key(struct input_event *pinput) return false; _D("No lcd-on capability!"); return true; - } else if (pinput->value == KEY_PRESSED) { - switch_on_lcd(); - } + } else if (pinput->value == KEY_PRESSED) + switch_on_lcd(LCD_ON_BY_POWER_KEY); return false; } -static bool release_short_powerkey(void) +static int decide_lcdoff(void) { -// tv d - no, a - yes - if (!display_conf.powerkey_doublepress && display_conf.lcd_always_on) { - longkey_pressed(); + /* It's not needed if it's already LCD off state */ + if (!current_state_in_on() && + backlight_ops.get_lcd_power() != DPMS_ON) + return false; + + /* + * This flag is set at the moment + * that LCD is turned on by power key + * LCD has not to turned off in the situation. + */ + if (skip_lcd_off) + return false; + + /* LCD is not turned off when powerkey is pressed,not released */ + if (key_combination == KEY_COMBINATION_POWERKEY) + return false; + + /* LCD-off is blocked at the moment poweroff popup shows */ + if (cancel_lcdoff) + return false; + + /* LCD-off is blocked when powerkey and volmedown key are pressed */ + if (skip_combination) + return false; + + /* At booting time, display must do not turn off */ + if (booting_check) + return false; + + return true; +} + +static int lcdoff_powerkey(void) +{ + int ignore = true; + + if (decide_lcdoff() == true) { + check_processes(S_NORMAL); + check_processes(S_LCDDIM); + + if (!check_holdkey_block(S_NORMAL) && + !check_holdkey_block(S_LCDDIM)) { + if (display_info.update_auto_brightness) + display_info.update_auto_brightness(false); + switch_off_lcd(); + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); + update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); + } + } else { + ignore = false; + skip_combination = false; + } + cancel_lcdoff = 0; + + return ignore; +} + +static bool key_check_display_on(void) +{ + if (current_state_in_on()) + return false; + + if (backlight_ops.get_lcd_power() == DPMS_ON) { + _W("display power was on"); return false; } return true; } +static gboolean display_on_cb(void *data) +{ + if (displayon_by_powerkey_timeout_id == 0) + return G_SOURCE_REMOVE; + + displayon_by_powerkey_timeout_id = 0; + if (backlight_ops.get_lcd_power() != DPMS_ON || + current_state_in_on() == false) { + broadcast_lcdon_by_powerkey(); + lcd_on_direct(LCD_ON_BY_POWER_KEY); + + if (pm_callback) + (*pm_callback) (INPUT_POLL_EVENT, NULL); + } + + return G_SOURCE_REMOVE; +} + +static int process_back_key(struct input_event *pinput) +{ + int ignore = true; + + if (pinput->value == KEY_PRESSED) { + switch_on_lcd(LCD_ON_BY_POWER_KEY); + _I("back key pressed"); + ignore = false; + } + + return ignore; +} + static int process_power_key(struct input_event *pinput) { int ignore = true; @@ -331,7 +465,13 @@ static int process_power_key(struct input_event *pinput) case KEY_RELEASED: check_key_pair(pinput->code, pinput->value, &value); - ignore = release_short_powerkey(); + if (!display_conf.powerkey_doublepress) { + if (display_has_caps(caps, DISPLAY_CAPA_LCDOFF)) + lcdoff_powerkey(); + else + _D("No lcdoff capability!"); + } else if (skip_lcd_off) + ignore = false; if (!display_has_caps(caps, DISPLAY_CAPA_LCDON)) ignore = true; @@ -341,10 +481,32 @@ static int process_power_key(struct input_event *pinput) longkey_timeout_id = 0; } + if (longkey_restore_id > 0) { + g_source_remove(longkey_restore_id); + longkey_restore_id = 0; + } + break; case KEY_PRESSED: if (display_has_caps(caps, DISPLAY_CAPA_LCDON)) { - skip_lcd_off = switch_on_lcd(); + if (wearable_mode()) + skip_lcd_off = switch_on_lcd(LCD_ON_BY_POWER_KEY); + else { + /* + * LCD does not turn on immediately at mobile. + * It will be turned on after 0.1 second because of torch concept. + */ + skip_lcd_off = key_check_display_on(); + ignore = true; + + if (!displayon_by_powerkey_timeout_id && + backlight_ops.get_lcd_power() != DPMS_ON && + key_combination != COMBINATION_TORCH) { + displayon_by_powerkey_timeout_id = g_timeout_add( + 100, + display_on_cb, NULL); + } + } } else { _D("No lcdon capability!"); skip_lcd_off = false; @@ -358,9 +520,11 @@ static int process_power_key(struct input_event *pinput) longkey_timeout_id = g_timeout_add_seconds( display_conf.longpress_interval, longkey_pressed_cb, NULL); + /* add long key restore timer */ + longkey_restore_id = g_timeout_add_seconds( + LONGKEY_PRESSED_TIME, + longkey_restore_cb, NULL); } - if (skip_lcd_off) - ignore = false; cancel_lcdoff = 0; break; @@ -421,10 +585,12 @@ static void process_hardkey_backlight(struct input_event *pinput) _I("Touch is pressed, then hard key is not working!"); return; } + if (!wearable_mode()) { /* Sound & Vibrate only in unlock state */ if (__get_lock_screen_state() == VCONFKEY_IDLE_UNLOCK || get_lock_screen_bg_state()) sound_vibrate_hardkey(); + } if (touchled && touchled->execute) { opt = TOUCHLED_PRESS; @@ -444,6 +610,23 @@ static void process_hardkey_backlight(struct input_event *pinput) } } +static void update_vital_state(struct input_event *pinput) +{ + int type; + + /* Change vital state to VITAL_EXIT only if vital mode is active */ + if (!vital_mode()) + return; + + /* Touch or Menu Key Release Event */ + if (pinput->type == EV_ABS || (pinput->type == EV_KEY && + pinput->value == KEY_RELEASED && pinput->code == KEY_MENU)) { + /* Enable all services upon receiving user input, else maintain same state */ + type = VITAL_EXIT; + device_notify(DEVICE_NOTIFIER_VITAL_STATE, &type); + } +} + static int check_key(struct input_event *pinput, int fd) { int ignore = true; @@ -462,6 +645,13 @@ static int check_key(struct input_event *pinput, int fd) ignore = process_screenlock_key(pinput); break; case KEY_BACK: + ignore = process_back_key(pinput); + stop_key_combination(NULL); + if (current_state_in_on()) { + process_hardkey_backlight(pinput); + ignore = false; + } + break; case KEY_PHONE: stop_key_combination(NULL); if (current_state_in_on()) { @@ -471,6 +661,9 @@ static int check_key(struct input_event *pinput, int fd) break; case KEY_VOLUMEUP: case KEY_VOLUMEDOWN: + if (current_state_in_on()) + ignore = false; + break; case KEY_CAMERA: case KEY_EXIT: case KEY_CONFIG: @@ -536,34 +729,36 @@ static int check_key_filter(void *data, int fd) code = pinput->code; value = pinput->value; + update_vital_state(pinput); ignore = check_key(pinput, fd); restore_custom_brightness(); break; case EV_REL: + if (pm_cur_state == S_LCDOFF && bezel_wakeup) { + switch_on_lcd(LCD_ON_BY_BEZEL); ignore = false; + } else if (pm_cur_state != S_LCDOFF) + ignore = false; break; case EV_ABS: - if (current_state_in_on()) + update_vital_state(pinput); + if (pinput->value == KEY_PRESSED) { + switch_on_lcd(LCD_ON_BY_TOUCH); ignore = false; + } - if (ambient_get_condition() == true) { - switch_on_lcd(); + if (current_state_in_on()) ignore = false; - } restore_custom_brightness(); - touch_pressed = - (pinput->value == TOUCH_RELEASE ? false : true); + if (pinput->value == KEY_PRESSED) + touch_pressed = true; + else if (pinput->value == KEY_RELEASED) + touch_pressed = false; break; case EV_SW: - if (!get_glove_state || !switch_glove_key) - break; - if (pinput->code == SW_GLOVE && - get_glove_state() == GLOVE_MODE) { - switch_glove_key(pinput->value); - } break; } @@ -573,6 +768,20 @@ static int check_key_filter(void *data, int fd) return 0; } +static int booting_done_cb(void *data) +{ + booting_check = 0; + + return 0; +} + +static int bezel_wakeup_cb(void *data) +{ + bezel_wakeup = (int)data; + + return 0; +} + /* * Default capability * powerkey := LCDON | LCDOFF | POWEROFF @@ -597,12 +806,8 @@ static void keyfilter_init(void) touchled = find_device(TOUCHLED_NAME); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); -} - -static void keyfilter_exit(void) -{ - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); + register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb); } static void key_backlight_enable(bool enable) @@ -622,7 +827,6 @@ static void key_backlight_enable(bool enable) static const struct display_keyfilter_ops normal_keyfilter_ops = { .init = keyfilter_init, - .exit = keyfilter_exit, .check = check_key_filter, .set_powerkey_ignore = NULL, .powerkey_lcdoff = NULL, diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 9d3f642..30ca2bd 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -35,10 +35,9 @@ #include #include #include +#include #include #include -#include -#include #include "ambient-mode.h" #include "util.h" @@ -53,14 +52,15 @@ #include "core/common.h" #include "core/config-parser.h" #include "core/launch.h" +#include "apps/apps.h" #include "extcon/extcon.h" +#include "battery/power-supply.h" #include "power/power-handler.h" #include "dd-display.h" #include "display/display-dpms.h" -#include "battery/battery.h" -#include "battery/power-supply.h" +#include "proximity.h" +#include "display-info.h" -#define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" /** @@ -71,18 +71,28 @@ #define SET_BRIGHTNESS_IN_BOOTLOADER "/usr/bin/save_blenv SLP_LCD_BRIGHT" #define LOCK_SCREEN_INPUT_TIMEOUT 10000 #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 -#define DD_LCDOFF_INPUT_TIMEOUT 3000 -#define ALWAYS_ON_TIMEOUT 3600000 //3600000 = 1 hour +#define ALWAYS_ON_TIMEOUT 3600000 +#define LATE_LCD_TRANSIT 1 + +#define PID_MAX 6 #define GESTURE_STR "gesture" #define POWER_KEY_STR "powerkey" #define TOUCH_STR "touch" #define EVENT_STR "event" #define TIMEOUT_STR "timeout" +#define PROXI_STR "proximity" +#define PALM_STR "palm" #define UNKNOWN_STR "unknown" +#define METHOD_APP_STATUS "CheckAppStatus" + +#define PM_WAKEUP 0 +#define PM_SUSPEND 1 + extern void init_pm_internal(); extern int get_charging_status(int *val); +extern void init_save_userlock(void); unsigned int pm_status_flag; static int trans_condition; @@ -93,6 +103,7 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; int pm_cur_state; int pm_old_state; guint timeout_src_id; +int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; static int custom_holdkey_block = false; @@ -100,13 +111,21 @@ static int custom_change_pid = -1; static char *custom_change_name; static bool hallic_open = true; static guint lock_timeout_id; +static guint transit_timer; static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; +static long displayoff_time; static struct timeval lcdon_tv; static int lcd_paneloff_mode = false; static int stay_touchscreen_off = false; +dd_list *lcdon_ops; +/* + * The two variables(lcdon_broadcast, pmstate_suspend) must be set initial + * state because it should be sent from previous state at booting time. + */ static bool lcdon_broadcast = true; +static int pmstate_suspend = PM_SUSPEND; + static bool touch_blocked = false; -dd_list *lcdon_ops; /* default transition, action fuctions */ static int default_trans(int evt); @@ -117,6 +136,10 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); +static gboolean pmlock_normal_check(void *data); +static gboolean pmlock_dim_check(void *data); +static gboolean pmlock_off_check(void *data); + static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; @@ -141,6 +164,10 @@ static int trans_table[S_END][EVENT_END] = { { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */ }; +static GSourceFunc warning_cb[S_END] = { + NULL, pmlock_normal_check, pmlock_dim_check, pmlock_off_check, +}; + enum signal_type { SIGNAL_INVALID = 0, SIGNAL_PRE, @@ -148,6 +175,11 @@ enum signal_type { SIGNAL_MAX, }; +enum platform_control { + PLATFORM_DISPLAY_OFF, + PLATFORM_DISPLAY_ON, +}; + static const char *lcdon_sig_lookup[SIGNAL_MAX] = { [SIGNAL_PRE] = "LCDOn", [SIGNAL_POST] = "LCDOnCompleted", @@ -179,7 +211,7 @@ static const char *lcdoff_sig_lookup[SIGNAL_MAX] = { #define LONG_PRESS_INTERVAL 2 /* 2 seconds */ #define SAMPLING_INTERVAL 1 /* 1 sec */ #define BRIGHTNESS_CHANGE_STEP 10 -#define LCD_ALWAYS_ON 1 +#define LCD_ALWAYS_ON 0 #define ACCEL_SENSOR_ON 1 #define CONTINUOUS_SAMPLING 1 #define LCDOFF_TIMEOUT 500 /* milli second */ @@ -196,13 +228,18 @@ struct display_config display_conf = { .lcdoff_timeout = LCDOFF_TIMEOUT, .brightness_change_step = BRIGHTNESS_CHANGE_STEP, .lcd_always_on = LCD_ALWAYS_ON, - .framerate_app = {1, 0, 0, 0}, - .control_display = 1, + .dimming = 1, + .framerate_app = {0, 0, 0, 0}, + .control_display = 0, .powerkey_doublepress = 0, .accel_sensor_on = ACCEL_SENSOR_ON, .continuous_sampling = CONTINUOUS_SAMPLING, - .timeout_enable = false, + .timeout_enable = true, .input_support = true, + .lockcheck_timeout = 600, + .aod_enter_level = 40, + .aod_tsp = true, + .touch_wakeup = false, }; struct display_function_info display_info = { @@ -215,9 +252,11 @@ struct display_function_info display_info = { typedef struct _pm_lock_node { pid_t pid; guint timeout_id; + guint warning_id; time_t time; bool holdkey_block; bool background; + bool broadcast_warning; } PmLockNode; static dd_list *cond_head[S_END]; @@ -232,9 +271,9 @@ static void set_process_active(bool flag, pid_t pid) /* Send dbug to resourced */ ret = dbus_handle_emit_dbus_signal(NULL, RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - RESOURCED_METHOD_ACTIVE, - g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); + RESOURCED_INTERFACE_PROCESS, + RESOURCED_METHOD_ACTIVE, + g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); if (ret < 0) _E("Failed to send dbus signal to resourced."); } @@ -288,17 +327,64 @@ void change_proc_change_state(int (*func)(unsigned int cond, pid_t pid)) proc_change_state = func; } +static inline long clock_gettime_to_long(void) +{ + struct timespec now; + int ret; + + ret = clock_gettime(CLOCK_REALTIME, &now); + + if (ret < 0) { + _E("Failed to clock gettime!"); + return 0; + } + + return SEC_TO_MSEC(now.tv_sec) + NSEC_TO_MSEC(now.tv_nsec); +} + +static int display_brightness_changed(void *data) +{ + int brt, ret; + + brt = DATA_VALUE_INT(data); + + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "Brightness", + g_variant_new("(i)", brt)); + if (ret < 0) + _E("Failed to send dbus signal Brightness."); + + return 0; +} + +static int display_auto_brightness_sensing(void *data) +{ + if (!transit_timer) + return 0; + + g_source_remove(transit_timer); + transit_timer = 0; + + return 0; +} + static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) { const char *str; const char *signal; int ret; + long diff = 0; if (type <= SIGNAL_INVALID || type >= SIGNAL_MAX) { _E("Invalid signal type(%d).", type); return; } + if (type == SIGNAL_PRE && displayoff_time != 0) + diff = clock_gettime_to_long() - displayoff_time; + if (flags & LCD_ON_BY_GESTURE) str = GESTURE_STR; else if (flags & LCD_ON_BY_POWER_KEY) @@ -316,7 +402,7 @@ static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, - g_variant_new("(s)", str)); + g_variant_new("(si)", str, diff)); if (ret < 0) _E("Failed to send dbus signal(%s)", signal); } @@ -332,6 +418,9 @@ static void broadcast_lcd_off(enum signal_type type, enum device_flags flags) return; } + if (type == SIGNAL_PRE) + displayoff_time = clock_gettime_to_long(); + signal = lcdoff_sig_lookup[type]; if (flags & LCD_OFF_BY_POWER_KEY) @@ -340,6 +429,12 @@ static void broadcast_lcd_off(enum signal_type type, enum device_flags flags) str = TIMEOUT_STR; else if (flags & LCD_OFF_BY_EVENT) str = EVENT_STR; + else if (flags & LCD_OFF_BY_PROXIMITY) + str = PROXI_STR; + else if (flags & LCD_OFF_BY_PALM) + str = PALM_STR; + else if (flags & LCD_OFF_BY_GESTURE) + str = GESTURE_STR; else str = UNKNOWN_STR; @@ -370,9 +465,6 @@ static unsigned long get_lcd_on_flags(void) if (lcd_paneloff_mode) flags |= LCD_PANEL_OFF_MODE; - if (stay_touchscreen_off) - flags |= TOUCH_SCREEN_OFF_MODE; - if (ambient_get_condition() == true) { flags |= AMBIENT_MODE; flags |= LCD_PHASED_TRANSIT_MODE; @@ -386,6 +478,18 @@ bool touch_event_blocked(void) return touch_blocked; } +static gboolean late_transit_on(void *data) +{ + if (!transit_timer) + return G_SOURCE_REMOVE; + + g_source_remove(transit_timer); + transit_timer = 0; + + backlight_ops.transit_state(DPMS_ON); + return G_SOURCE_REMOVE; +} + void lcd_on_procedure(int state, enum device_flags flag) { dd_list *l = NULL; @@ -393,19 +497,29 @@ void lcd_on_procedure(int state, enum device_flags flag) unsigned long flags = get_lcd_on_flags(); flags |= flag; - /* send LCDOn dbus signal */ - if (!lcdon_broadcast) { - broadcast_lcd_on(SIGNAL_PRE, flags); - lcdon_broadcast = true; - } + /* + * Display on procedure + * step 1. broadcast lcd on signal with cause + * step 2. set brightness + * step 3. set pmstate of vconf + * step 4. display on operate + * - a. display on + * - b. TSP(touch screen) and touchkey enable + * step 5. broadcast lcd on complete siganl + * step 6. key backlight enable + */ + _I("[lcdstep] %lu", flags); if (flags & AMBIENT_MODE) { - if (ambient_get_state() == false && - backlight_ops.get_lcd_power() == DPMS_ON) + if (ambient_get_state() == false && backlight_ops.get_lcd_power() == DPMS_ON) return; ambient_set_state(false); } + /* send LCDOn dbus signal */ + if (!lcdon_broadcast) + broadcast_lcd_on(SIGNAL_PRE, flags); + if (!(flags & LCD_PHASED_TRANSIT_MODE)) { /* Update brightness level */ if (state == LCD_DIM) @@ -422,7 +536,13 @@ void lcd_on_procedure(int state, enum device_flags flag) DD_LIST_FOREACH(lcdon_ops, l, ops) ops->start(flags); + if (!lcdon_broadcast) { broadcast_lcd_on(SIGNAL_POST, flags); + if (flags & LCD_PHASED_TRANSIT_MODE) + transit_timer = g_timeout_add_seconds(LATE_LCD_TRANSIT, + late_transit_on, NULL); + lcdon_broadcast = true; + } if (CHECK_OPS(keyfilter_ops, backlight_enable)) keyfilter_ops->backlight_enable(true); @@ -430,7 +550,7 @@ void lcd_on_procedure(int state, enum device_flags flag) touch_blocked = false; } -static inline unsigned long get_lcd_off_flags(void) +static unsigned long get_lcd_off_flags(void) { unsigned long flags = NORMAL_MODE; @@ -439,10 +559,12 @@ static inline unsigned long get_lcd_off_flags(void) flags |= LCD_PHASED_TRANSIT_MODE; } + if (stay_touchscreen_off) + flags |= TOUCH_SCREEN_OFF_MODE; + return flags; } - inline void lcd_off_procedure(enum device_flags flag) { dd_list *l = NULL; @@ -450,6 +572,20 @@ inline void lcd_off_procedure(enum device_flags flag) unsigned long flags = get_lcd_off_flags(); flags |= flag; + /* + * Display off procedure + * step 0. enhance mode off using nofity (e.g mdnie, HBM, LBM) + * step 1. broadcast lcd off signal with cause + * step 2. set pmstate of vconf + * step 3. display off operate + * - a. display off + * - b. TSP(touch screen) and touchkey disable + * step 4. broadcast lcd off complete siganl + */ + _I("[lcdstep] %lu", flags); + + device_notify(DEVICE_NOTIFIER_LCD_OFF, NULL); + touch_blocked = true; if (flags & AMBIENT_MODE) { @@ -462,18 +598,23 @@ inline void lcd_off_procedure(enum device_flags flag) broadcast_lcd_off(SIGNAL_PRE, flags); lcdon_broadcast = false; } + set_setting_pmstate(S_LCDOFF); + if (CHECK_OPS(keyfilter_ops, backlight_enable)) keyfilter_ops->backlight_enable(false); - set_setting_pmstate(S_LCDOFF); + if (transit_timer) { + g_source_remove(transit_timer); + transit_timer = 0; + } + + if (flags & LCD_PHASED_TRANSIT_MODE) + backlight_ops.transit_state(DPMS_OFF); DD_LIST_FOREACH(lcdon_ops, l, ops) ops->stop(flags); if (flags & AMBIENT_MODE) - /* Do not broadcast the post signal here. - * The signal will be broadcasted - * after showing Ambient clock */ broadcast_lcd_off_late(flags); else broadcast_lcd_off(SIGNAL_POST, flags); @@ -481,20 +622,20 @@ inline void lcd_off_procedure(enum device_flags flag) void set_stay_touchscreen_off(int val) { - _D("stay touch screen off: %d", val); + _I("Stay touch screen off: %d", val); stay_touchscreen_off = val; - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - set_setting_pmstate(LCD_NORMAL); + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } void set_lcd_paneloff_mode(int val) { - _D("lcd paneloff mode: %d", val); + _I("Lcd paneloff mode: %d", val); lcd_paneloff_mode = val; - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - set_setting_pmstate(LCD_NORMAL); + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } int low_battery_state(int val) @@ -538,7 +679,7 @@ static void makeup_trans_condition(void) static PmLockNode *find_node(enum state_t s_index, pid_t pid) { dd_list *elem; - PmLockNode *t; + PmLockNode *t = NULL; DD_LIST_FOREACH(cond_head[s_index], elem, t) { if (t->pid == pid) @@ -551,21 +692,28 @@ static PmLockNode *find_node(enum state_t s_index, pid_t pid) static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, bool holdkey_block) { + guint warning_id = 0; PmLockNode *n; time_t now; n = (PmLockNode *) malloc(sizeof(PmLockNode)); if (n == NULL) { - _E("Failed to add cond. Not enough memory."); + _E("Not enough memory, add cond. fail"); return NULL; } + if (pid < INTERNAL_LOCK_BASE) + warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, + warning_cb[s_index], (void *)((intptr_t)pid)); + time(&now); n->pid = pid; n->timeout_id = timeout_id; + n->warning_id = warning_id; n->time = now; n->holdkey_block = holdkey_block; n->background = false; + n->broadcast_warning = true; DD_LIST_APPEND(cond_head[s_index], n); refresh_app_cond(); @@ -584,6 +732,11 @@ static int del_node(enum state_t s_index, PmLockNode *n) g_source_remove(n->timeout_id); n->timeout_id = 0; } + if (n->warning_id) { + g_source_remove(n->warning_id); + n->warning_id = 0; + } + free(n); refresh_app_cond(); return 0; @@ -591,6 +744,7 @@ static int del_node(enum state_t s_index, PmLockNode *n) static void print_node(int next) { + int ret; dd_list *elem; PmLockNode *n; char buf[30]; @@ -605,10 +759,20 @@ static void print_node(int next) diff = difftime(now, n->time); ctime_r(&n->time, buf); - if (diff > LOCK_TIME_WARNING) - _W("over=%.0f s pid=%5d locktime=%s", diff, n->pid, buf); - else - _I("pid=%5d locktime=%s", n->pid, buf); + if (diff > LOCK_TIME_WARNING) { + if (diff > LOCK_TIME_WARNING * 60 && n->pid < INTERNAL_LOCK_BASE && n->broadcast_warning) { + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "pmlock_over", + g_variant_new("(i)", n->pid)); + if (ret < 0) + _E("Failed to send dbus signal pmlock_over."); + n->broadcast_warning = false; + } + _W("Over(%.0f s) pid( %5d) lock time(%s)", diff, n->pid, buf); + } else + _I("Pid(%5d) lock time(%s)", n->pid, buf); } } @@ -641,7 +805,6 @@ void get_pname(pid_t pid, char *pname) static void del_state_cond(void *data, enum state_t state) { PmLockNode *tmp = NULL; - char pname[PATH_MAX]; pid_t pid; if (!data) @@ -649,18 +812,20 @@ static void del_state_cond(void *data, enum state_t state) /* A passed data is a pid_t type data, not a 64bit data. */ pid = (pid_t)((intptr_t)data); - _I("Delete process(%d)'s prohibit dim condition by timeout.", pid); + _I("delete prohibit dim condition by timeout (%d)", pid); + + if (pid == INTERNAL_LOCK_AMBIENT) + ambient_check_invalid_state(pid); tmp = find_node(state, pid); del_node(state, tmp); - get_pname(pid, pname); - set_unlock_time(pname, state); + set_unlock_time(pid, state); if (!timeout_src_id) states[pm_cur_state].trans(EVENT_TIMEOUT); if (state == S_LCDOFF) - set_process_active(FALSE, pid); + set_process_active(false, pid); } static gboolean del_normal_cond(void *data) @@ -681,23 +846,91 @@ static gboolean del_off_cond(void *data) return G_SOURCE_REMOVE; } -/* timeout handler */ -gboolean timeout_handler(void *data) +static void pmlock_check_cb(GVariant *var, void *user_data, GError *err) { - int run_timeout; + pid_t pid; + int ret, state; + char *app_id; - _I("Time out state %s.\n", states[pm_cur_state].name); - /* default setting */ - get_run_timeout(&run_timeout); + if (!var) + return; - /* for sdk - * if the run_timeout is zero, it regards AlwaysOn state + if (!dh_get_param_from_var(var, "(iis)", &pid, &state, &app_id)) { + _E("Failed to notify low: no message(%s)", g_variant_get_type_string(var)); + goto out; + } + + _W("%s(%d) was requested pmlock for a long time.", app_id, pid); + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "pmlock_expired", + g_variant_new("(i)", pid)); + if (ret < 0) + _E("Failed to send dbus pmlock_expired"); + +out: + g_variant_unref(var); +} + +/* + * Any process is possible many time lock, deviced can not know malicious + * or good process. so infinity or more then 1 min lock process, deviced + * will be checked it to resoured. And then, it will be asked quit or maintain to user. */ - if (pm_cur_state == S_NORMAL && (run_timeout == 0 || display_conf.lcd_always_on)) { - _D("'run_timeout' is always on."); - return G_SOURCE_CONTINUE; +static void pmlock_check(void *data, char *st) +{ + const char *arr[2]; + char chr_pid[PID_MAX]; + pid_t pid; + int ret; + + if (!data || !st) + return; + + if (!strncmp(st, "lcdoff", 4) && backlight_ops.get_lcd_power() == DPMS_ON) { + _D("Lcd state is PM_LCD_POWER_ON"); + return; } + pid = (pid_t)((intptr_t)data); + snprintf(chr_pid, sizeof(chr_pid), "%d", pid); + + arr[0] = chr_pid; + arr[1] = st; + + ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, + RESOURCED_PATH_PROCESS, + RESOURCED_INTERFACE_PROCESS, + METHOD_APP_STATUS, + "is", arr, pmlock_check_cb, -1, NULL); + if (ret < 0) + _E("Failed to call dbus method"); +} + +static gboolean pmlock_normal_check(void *data) +{ + pmlock_check(data, "normal"); + return G_SOURCE_CONTINUE; +} + +static gboolean pmlock_dim_check(void *data) +{ + pmlock_check(data, "lcddim"); + return G_SOURCE_CONTINUE; +} + +static gboolean pmlock_off_check(void *data) +{ + pmlock_check(data, "lcdoff"); + return G_SOURCE_CONTINUE; +} + +/* timeout handler */ +gboolean timeout_handler(void *data) +{ + _I("Time out state %s", states[pm_cur_state].name); + if (timeout_src_id) { g_source_remove(timeout_src_id); timeout_src_id = 0; @@ -712,7 +945,7 @@ void reset_timeout(int timeout) if (!display_conf.timeout_enable) return; - _I("Reset timeout(%d ms)", timeout); + _I("Reset timeout(%d ms).", timeout); if (timeout_src_id != 0) { g_source_remove(timeout_src_id); timeout_src_id = 0; @@ -753,7 +986,7 @@ static int get_lcd_timeout_from_settings(void) if (val > 0) states[i].timeout = val; - _I("state=%s timeout=%d ms", states[i].name, + _I("State(%s) timeout(%d) ms", states[i].name, states[i].timeout); } @@ -776,7 +1009,7 @@ static void update_display_time(void) if (custom_normal_timeout > 0) { states[S_NORMAL].timeout = custom_normal_timeout; states[S_LCDDIM].timeout = custom_dim_timeout; - _I("CUSTOM: Timeout(%d ms) and dim(%d ms) are set by normal.", + _I("CUSTOM : timeout is set by normal(%d ms), dim(%d ms)", custom_normal_timeout, custom_dim_timeout); return; } @@ -807,7 +1040,8 @@ static void update_display_time(void) get_dim_timeout(&val); states[S_LCDDIM].timeout = val; - _I("Normal: timeout(%d ms) and dim(%d ms) are set.", states[S_NORMAL].timeout, states[S_LCDDIM].timeout); + _I("Normal: NORMAL timeout is set by %d ms", states[S_NORMAL].timeout); + _I("Normal: DIM timeout is set by %d ms", states[S_LCDDIM].timeout); } static void update_display_locktime(int time) @@ -816,7 +1050,6 @@ static void update_display_locktime(int time) update_display_time(); } - void set_dim_state(bool on) { _I("Dim state is %d.", on); @@ -824,31 +1057,58 @@ void set_dim_state(bool on) states[pm_cur_state].trans(EVENT_INPUT); } +static void broadcast_pm_suspend(void) +{ + int ret; -void lcd_on_direct(enum device_flags flags) + if (pmstate_suspend) + return; + + _D("PM will be changed to sleep."); + + pmstate_suspend = PM_SUSPEND; + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "sleep", + NULL); + if (ret < 0) + _E("Failed to send dbus signal sleep."); +} + +static void broadcast_pm_wakeup(void) { - int ret, call_state; + int ret; + + if (!pmstate_suspend) + return; + + _D("PM is changed to wakeup."); + + pmstate_suspend = PM_WAKEUP; + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "wakeup", + NULL); + if (ret < 0) + _E("Failed to send dbus signal wakeup."); +} + +void lcd_on_direct(enum device_flags flags) +{ if (power_ops.get_power_lock_support() - && pm_cur_state == S_SLEEP) + && pm_cur_state == S_SLEEP) { + broadcast_pm_wakeup(); power_ops.power_lock(); + pm_cur_state = S_NORMAL; + } -#ifdef MICRO_DD - _D("Lcd is on directly."); + _D("lcd is on directly"); gettimeofday(&lcdon_tv, NULL); lcd_on_procedure(LCD_NORMAL, flags); - reset_timeout(DD_LCDOFF_INPUT_TIMEOUT); -#else - ret = vconf_get_int(VCONFKEY_CALL_STATE, &call_state); - if ((ret >= 0 && call_state != VCONFKEY_CALL_OFF) || - (__get_lock_screen_state() == VCONFKEY_IDLE_LOCK)) { - _D("LOCK state, lcd is on directly."); - lcd_on_procedure(LCD_NORMAL, flags); - } else if (ret < 0) - _E("Failed to get vconf value for call state: %d", vconf_get_ext_errno()); - - reset_timeout(display_conf.lcdoff_timeout); -#endif + update_display_locktime(LOCK_SCREEN_INPUT_TIMEOUT); } @@ -860,6 +1120,41 @@ static inline bool check_lcd_is_on(void) return true; } +static int check_lock_condition(enum state_t state) +{ + dd_list *elem; + PmLockNode *t = NULL; + int ret = false; + pid_t owner = getpid(); + + _D("check holdkey block : state of %s", states[state].name); + + DD_LIST_FOREACH(cond_head[state], elem, t) { + if (t->pid != owner && t->background == false) { + ret = true; + _I("state change was blocked by pid(%d)!", t->pid); + break; + } + } + + return ret; +} + +static gboolean timer_refresh_cb(gpointer data) +{ + struct state *st; + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_NORMAL; + st = &states[pm_cur_state]; + + if (st->action) + st->action(st->timeout); + + return 0; +} + int custom_lcdon(int timeout) { struct state *st; @@ -883,9 +1178,157 @@ int custom_lcdon(int timeout) if (st->action) st->action(st->timeout); + g_idle_add(timer_refresh_cb, NULL); + return 0; } +int custom_lcdoff(enum device_flags flag) +{ + struct state *st; + + check_processes(S_NORMAL); + check_processes(S_LCDDIM); + + /* check holdkey block flag in lock node */ + if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + /* + * When another proccess is normal lock, device is received call then, + * call app can be changed to lcd state by proximity. + * If proximity is near then normal lock will be unlocked. + */ + if (flag & LCD_OFF_BY_PROXIMITY) { + _I("custom lcd off by proximity, delete normal lock"); + delete_condition(S_NORMAL); + } else { + _I("skip custom lcd off"); + return -ECANCELED; + } + } + + _I("custom lcd off by flag(%d)", flag); + if (backlight_ops.get_lcd_power() == DPMS_ON) + lcd_off_procedure(flag); + + if (set_custom_lcdon_timeout(0) == true) + update_display_time(); + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_LCDOFF; + st = &states[pm_cur_state]; + + /* enter action */ + if (st->action) + st->action(st->timeout); + + return 0; +} + +static int display_platform_on(char *reason, int timeout) +{ + struct state *st; + int flag; + int str_len; + + str_len = strlen(reason); + + if (!strncmp(reason, GESTURE_STR, str_len)) + flag = LCD_ON_BY_GESTURE; + else if (!strncmp(reason, EVENT_STR, str_len)) + flag = LCD_ON_BY_EVENT; + else { + _E("Reason is unkown(%s)", reason); + return -EINVAL; + } + + if (timeout <= 0) { + _E("Cannot setting timeout %d", timeout); + return -EINVAL; + } + + if (check_lcd_is_on() == false) + lcd_on_direct(flag); + + _I("platform lcd on by %s (%d ms)", reason, timeout); + if (set_custom_lcdon_timeout(timeout) == true) + update_display_time(); + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_NORMAL; + st = &states[pm_cur_state]; + + /* enter action */ + if (st->action) + st->action(st->timeout); + + return 0; +} + +static int display_platform_off(char *reason) +{ + struct state *st; + int flag; + int str_len; + + str_len = strlen(reason); + + if (!strncmp(reason, GESTURE_STR, str_len)) { + check_processes(S_NORMAL); + check_processes(S_LCDDIM); + + /* check holdkey block flag in lock node */ + if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + _I("skip platform lcd off by gesture"); + return -ECANCELED; + } + flag = LCD_OFF_BY_GESTURE; + } else if (!strncmp(reason, PALM_STR, str_len)) { + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); + + flag = LCD_OFF_BY_PALM; + } else { + _E("Reason is unkown(%s)", reason); + return -EINVAL; + } + + _I("platform lcd off by %s", reason); + if (backlight_ops.get_lcd_power() == DPMS_ON) + lcd_off_procedure(flag); + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_LCDOFF; + st = &states[pm_cur_state]; + + /* enter action */ + if (st->action) + st->action(st->timeout); + + return 0; +} + +int display_platform_control(int type, char *reason, int timeout) +{ + int ret; + + switch (type) { + case PLATFORM_DISPLAY_ON: + ret = display_platform_on(reason, timeout); + break; + case PLATFORM_DISPLAY_OFF: + ret = display_platform_off(reason); + break; + default: + _E("Unkown type(%d)", type); + ret = -EINVAL; + } + + return ret; +} + static void default_proc_change_state_action(enum state_t next, int timeout) { struct state *st; @@ -921,8 +1364,12 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) default_proc_change_state_action(next, -1); break; case S_LCDOFF: - if (backlight_ops.get_lcd_power() != DPMS_OFF) + if (backlight_ops.get_lcd_power() == DPMS_ON) { + if (get_proximity_state() == SENSOR_PROXIMITY_NEAR) + lcd_off_procedure(LCD_OFF_BY_PROXIMITY); + else lcd_off_procedure(LCD_OFF_BY_EVENT); + } if (set_custom_lcdon_timeout(0)) update_display_time(); default_proc_change_state_action(next, -1); @@ -932,7 +1379,14 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) /* at first LCD_OFF and then goto sleep */ /* state transition */ default_proc_change_state_action(S_LCDOFF, TIMEOUT_NONE); + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); delete_condition(S_LCDOFF); + if (lcdon_broadcast) { + _I("broadcast lcd off signal at non-lcd device"); + broadcast_lcd_off(SIGNAL_PRE, 0); + broadcast_lcd_off(SIGNAL_POST, 0); + } default_proc_change_state_action(S_SLEEP, TIMEOUT_NONE); break; @@ -967,15 +1421,18 @@ static void proc_condition_lock(PMMsg *data) pid_t pid = data->pid; enum state_t state; int holdkey_block; + bool value = true; + unsigned int flags; state = GET_COND_STATE(data->cond); - if (!state) + if (state == S_START) return; + flags = GET_COND_FLAG(data->cond); get_pname(pid, pname); - if (state == S_LCDOFF && - pm_cur_state == S_SLEEP) + if (state == S_LCDOFF && pm_cur_state == S_SLEEP && + power_ops.get_power_lock() == POWER_UNLOCK) proc_change_state(data->cond, INTERNAL_LOCK_PM); if (data->timeout > 0) { @@ -1001,14 +1458,15 @@ static void proc_condition_lock(PMMsg *data) } if (state == S_LCDOFF) - set_process_active(TRUE, pid); + set_process_active(true, pid); + _I("[%s] locked by %5d with %u ms", states[state].name, pid, data->timeout); /* for debug */ - _SD("[%s] Locked by pid=%d process=%s holdkeyblock=%d\n", - states[state].name, pid, pname, holdkey_block); - set_lock_time(pname, state); + _SD("be requested LOCK info pname(%s), holdkeyblock(%d) flags(%d)", + pname, holdkey_block, flags); + set_lock_time(pid, pname, state); - device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)true); + device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value); } static void proc_condition_unlock(PMMsg *data) @@ -1017,27 +1475,28 @@ static void proc_condition_unlock(PMMsg *data) enum state_t state; PmLockNode *tmp; char pname[PATH_MAX]; + bool value = false; + unsigned int flags; state = GET_COND_STATE(data->cond); if (!state) return; + flags = GET_COND_FLAG(data->cond); get_pname(pid, pname); tmp = find_node(state, pid); del_node(state, tmp); if (state == S_LCDOFF) - set_process_active(FALSE, pid); - - if (ambient_get_state()) - ambient_check_invalid_state(pid); + set_process_active(false, pid); - _SD("[%s] Unlocked by pid=%d process=%s\n", - states[state].name, pid, pname); - set_unlock_time(pname, state); + _I("[%s] unlocked by %5d", states[state].name, pid); + /* for debug */ + _SD("be requested UNLOCK info pname(%s) flag(%d)", pname, flags); + set_unlock_time(pid, state); - device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)false); + device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value); } static int proc_condition(PMMsg *data) @@ -1056,15 +1515,11 @@ static int proc_condition(PMMsg *data) flags = GET_COND_FLAG(data->cond); if (flags == 0) { /* guard time for suspend */ - if (pm_cur_state == S_LCDOFF) { + if (pm_cur_state == S_LCDOFF) reset_timeout(states[S_LCDOFF].timeout); - _I("Margin timeout(%d ms)", states[S_LCDOFF].timeout); - } } else { - if (flags & PM_FLAG_RESET_TIMER) { + if (flags & PM_FLAG_RESET_TIMER) reset_timeout(states[pm_cur_state].timeout); - _I("Reset timeout(%d ms)", states[pm_cur_state].timeout); - } } if (!timeout_src_id) @@ -1077,13 +1532,13 @@ static int proc_condition(PMMsg *data) int check_processes(enum state_t prohibit_state) { dd_list *elem, *next; - PmLockNode *t; + PmLockNode *t = NULL; int ret = 0; DD_LIST_FOREACH_SAFE(cond_head[prohibit_state], elem, next, t) { if (t->pid < INTERNAL_LOCK_BASE && kill(t->pid, 0) == -1) { - _E("Process(%d) does not exist, delete the REQ" - " - prohibit state=%d.", + _E("%d process does not exist, delete the REQ" + " - prohibit state %d ", t->pid, prohibit_state); if (t->pid == custom_change_pid) { get_lcd_timeout_from_settings(); @@ -1091,6 +1546,7 @@ int check_processes(enum state_t prohibit_state) custom_change_pid = -1; } ret = 1; + set_unlock_time(t->pid, prohibit_state); del_node(prohibit_state, t); } } @@ -1101,7 +1557,7 @@ int check_processes(enum state_t prohibit_state) int check_holdkey_block(enum state_t state) { dd_list *elem; - PmLockNode *t; + PmLockNode *t = NULL; int ret = 0; _I("Check holdkey block: state of %s", states[state].name); @@ -1126,11 +1582,9 @@ int check_holdkey_block(enum state_t state) int delete_condition(enum state_t state) { dd_list *elem, *next; - PmLockNode *t; - pid_t pid; - char pname[PATH_MAX]; + PmLockNode *t = NULL; - _I("Delete condition: state of %s", states[state].name); + _I("delete condition : state of %s", states[state].name); if (!cond_head[state]) return 0; @@ -1140,13 +1594,11 @@ int delete_condition(enum state_t state) g_source_remove(t->timeout_id); t->timeout_id = 0; } - pid = t->pid; if (state == S_LCDOFF) - set_process_active(FALSE, pid); - _I("Delete node of pid(%d).", pid); + set_process_active(false, t->pid); + _I("delete node of pid(%d)", t->pid); + set_unlock_time(t->pid, state); del_node(state, t); - get_pname(pid, pname); - set_unlock_time(pname, state-1); } DD_LIST_FREE_LIST(cond_head[state]); @@ -1188,8 +1640,9 @@ static pm_history pm_history_log[MAX_LOG_COUNT] = {{0, }, }; static int history_count = 0; static const char history_string[PM_LOG_MAX][15] = { - "PRESS", "LONG PRESS", "RELEASE", "LCD ON", "LCD ON FAIL", - "LCD DIM", "LCD DIM FAIL", "LCD OFF", "LCD OFF FAIL", "SLEEP"}; + "PRESS", "LONG PRESS", "RELEASE", "LCD ON", "LCD ON COMPL", "LCD ON FAIL", + "LCD DIM", "LCD DIM FAIL", "LCD OFF", "LCD OFF COMPL", "LCD OFF FAIL", + "LCD FAIL", "SLEEP"}; void pm_history_init() { @@ -1242,7 +1695,7 @@ void pm_history_print(int fd, int count) time_buf); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); } } #endif @@ -1266,13 +1719,13 @@ void print_info(int fd) "===========================\n"); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Timeout Info: Run[%dms] Dim[%dms] Off[%dms]\n", states[S_NORMAL].timeout, states[S_LCDDIM].timeout, states[S_LCDOFF].timeout); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Tran. Locked : %s %s %s\n", (trans_condition & MASK_NORMAL) ? states[S_NORMAL].name : "-", @@ -1280,18 +1733,18 @@ void print_info(int fd) (trans_condition & MASK_OFF) ? states[S_LCDOFF].name : "-"); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Current State: %s\n", states[pm_cur_state].name); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Current Lock Conditions: \n"); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); for (s_index = S_NORMAL; s_index < S_END; s_index++) { DD_LIST_FOREACH(cond_head[s_index], elem, t) { @@ -1302,7 +1755,7 @@ void print_info(int fd) i++, states[s_index].name, t->pid, pname, time_buf); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); } } @@ -1313,37 +1766,39 @@ void print_info(int fd) #endif } -void save_display_log(void) +void save_display_log(char *path) { int fd, ret; char buf[255]; time_t now_time; char time_buf[30]; - _D("Internal state is saved."); + _D("internal state is saved!"); time(&now_time); ctime_r(&now_time, time_buf); - fd = open(PM_STATE_LOG_FILE, O_CREAT | O_TRUNC | O_WRONLY, 0644); + fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0644); if (fd != -1) { snprintf(buf, sizeof(buf), "\npm_state_log now-time : %d(s) %s\n\n", (int)now_time, time_buf); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("write() failed (%d)", errno); snprintf(buf, sizeof(buf), "pm_status_flag: %x\n", pm_status_flag); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("write() failed (%d)", errno); - snprintf(buf, sizeof(buf), "screen lock status : %d\n", - __get_lock_screen_state()); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed: %d", errno); + if (disp_plgn.get_lock_screen_state ) { + snprintf(buf, sizeof(buf), "screen lock status : %d\n", + disp_plgn.get_lock_screen_state()); + ret = write(fd, buf, strlen(buf)); + if (ret < 0) + _E("write() failed (%d)", errno); + } print_info(fd); close(fd); } @@ -1360,7 +1815,9 @@ void save_display_log(void) */ static void sig_hup(int signo) { - save_display_log(); + _I("received sig hub %d", signo); + + pm_save_logdump(); } int check_lcdoff_direct(void) @@ -1374,6 +1831,9 @@ int check_lcdoff_direct(void) if (pm_cur_state != S_LCDDIM) return false; + if (!display_conf.dimming) + return true; + lock = __get_lock_screen_state(); if (lock != VCONFKEY_IDLE_LOCK && hallic_open) return false; @@ -1388,7 +1848,7 @@ int check_lcdoff_direct(void) else if (ret < 0) _E("Failed to get vconf value for cradle status: %d", vconf_get_ext_errno()); - _D("Goto LCDOFF direct(lock=%d hdmi=%d cradle=%d).", lock, hdmi_state, cradle); + _D("Goto LCDOFF direct: lock(%d) hdmi(%d) cradle(%d).", lock, hdmi_state, cradle); return true; } @@ -1482,22 +1942,10 @@ static inline void stop_lock_timer(void) static void check_lock_screen(void) { - int lock_setting, lock_state, app_state, ret; + int lock_state, ret; stop_lock_timer(); - ret = vconf_get_int(VCONFKEY_CALL_STATE, &app_state); - if (ret >= 0 && app_state != VCONFKEY_CALL_OFF) - goto lcd_on; - else if (ret < 0) - _E("Failed to get vconf value for call state: %d", vconf_get_ext_errno()); - - /* check setting of lock screen is enabled. */ - ret = vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, - &lock_setting); - if (ret < 0) - _E("Failed to get vconf value for screen lock type: %d", vconf_get_ext_errno()); - /* check state of lock */ ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); if (ret < 0 || lock_state == VCONFKEY_IDLE_LOCK) { @@ -1552,10 +2000,12 @@ static int default_action(int timeout) } if (pm_cur_state != pm_old_state && pm_cur_state != S_SLEEP) { - if (power_ops.get_power_lock_support()) + if (power_ops.get_power_lock_support()) { + broadcast_pm_wakeup(); power_ops.power_lock(); + } set_setting_pmstate(pm_cur_state); - device_notify(DEVICE_NOTIFIER_LCD, &pm_cur_state); + device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); } if (pm_old_state == S_NORMAL && pm_cur_state != S_NORMAL) { @@ -1595,11 +2045,11 @@ static int default_action(int timeout) if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) { stop_lock_timer(); /* lcd off state : turn off the backlight */ - if (backlight_ops.get_lcd_power() != DPMS_OFF) + if (backlight_ops.get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); } - if (backlight_ops.get_lcd_power() != DPMS_OFF + if (backlight_ops.get_lcd_power() == DPMS_ON || lcd_paneloff_mode) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); break; @@ -1608,7 +2058,7 @@ static int default_action(int timeout) if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) stop_lock_timer(); - if (backlight_ops.get_lcd_power() != DPMS_OFF) + if (backlight_ops.get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); if (!power_ops.get_power_lock_support()) { @@ -1635,6 +2085,7 @@ go_suspend: #ifdef ENABLE_PM_LOG pm_history_save(PM_LOG_SLEEP, pm_cur_state); #endif + broadcast_pm_suspend(); if (power_ops.get_power_lock_support()) { if (power_ops.enable_autosleep) power_ops.enable_autosleep(); @@ -1642,24 +2093,9 @@ go_suspend: if (power_ops.power_unlock() < 0) _E("Power unlock state error."); } else { - dd_list *elem, *elem_n; - const struct device_ops *dev; - /* Devices Suspend */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->suspend) - dev->suspend(); - } - power_ops.suspend(); - - /* Devices Resume */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->resume) - dev->resume(); - } - - _I("System wakeup."); - disp_plgn.system_wakeup_flag = true; + _I("system wakeup!!"); + system_wakeup_flag = true; /* Resume !! */ if (power_ops.check_wakeup_src() == EVENT_DEVICE) /* system waked up by devices */ @@ -1740,7 +2176,7 @@ static int poll_callback(int condition, PMMsg *data) if (condition == INPUT_POLL_EVENT) { if (pm_cur_state == S_LCDOFF || pm_cur_state == S_SLEEP) - _I("Power key input."); + _I("Input event signal at Display Off"); time(&now); if (last_t != now || pm_cur_state == S_LCDOFF || @@ -1801,11 +2237,13 @@ static int update_setting(int key_idx, int val) } pm_status_flag |= CHRGR_FLAG; } else { - int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; + int bat_state; ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state); - if (ret < 0) + if (ret < 0) { + bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); + } if (low_battery_state(bat_state)) { power_saving_func(true); pm_status_flag |= LOWBT_FLAG; @@ -1878,9 +2316,9 @@ static void check_seed_status(void) { int ret = -1; int tmp = 0; - int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; + int bat_state; int brt = 0; - int lock_state = -1; + int lock_state; /* Charging check */ if ((get_charging_status(&tmp) == 0) && (tmp > 0)) @@ -1899,10 +2337,13 @@ static void check_seed_status(void) } _I("Set brightness(%d) from setting app.", tmp); backlight_ops.set_default_brt(tmp); + backlight_ops.set_brightness(tmp); ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state); - if (ret < 0) + if (ret < 0) { + bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); + } if (low_battery_state(bat_state)) { if (!(pm_status_flag & CHRGR_FLAG)) { power_saving_func(true); @@ -1912,9 +2353,10 @@ static void check_seed_status(void) /* lock screen check */ ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret < 0) + if (ret < 0) { + lock_state = -1; _E("Failed to get vconf value for idle lock state: %d", vconf_get_ext_errno()); - + } set_lock_screen_state(lock_state); if (lock_state == VCONFKEY_IDLE_LOCK) { states[S_NORMAL].timeout = lock_screen_timeout; @@ -2044,36 +2486,20 @@ void reset_lcd_timeout(GDBusConnection *conn, static int booting_done(void *data) { - static int done; - - if (!data) - return done; + static bool done = false; + if (data != NULL) { done = *(int*)data; - if (!done) - return done; - - _I("Booting done. Release display and power lock."); - if (disp_plgn.pm_unlock_internal) { - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, PM_SLEEP_MARGIN); + if (done) + return 0; + _I("booting done, unlock LCD_OFF"); + if (disp_plgn.pm_unlock_internal) { + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, PM_SLEEP_MARGIN); + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); + } } - return done; -} - -int device_poweroff(void *data) -{ - static int off; - - if (!data) - return off; - - off = *(int *)data; - if (off) - _I("Poweroff"); - - return off; + return 0; } static int process_background(void *data) @@ -2086,7 +2512,7 @@ static int process_background(void *data) node = find_node(S_NORMAL, pid); if (node) { node->background = true; - _I("Process(%d) is background, then PM will be unlocked LCD_NORMAL.", pid); + _I("%d pid is background, then PM will be unlocked LCD_NORMAL", pid); } return 0; @@ -2102,7 +2528,7 @@ static int process_foreground(void *data) node = find_node(S_NORMAL, pid); if (node) { node->background = false; - _I("Process(%d) is foreground, then PM will be maintained locked LCD_NORMAL.", pid); + _I("Process(%d) is background, then PM will be unlocked LCD_NORMAL.", pid); } return 0; @@ -2142,49 +2568,58 @@ static int display_load_config(struct parse_result *result, void *user_data) if (MATCH(result->name, "LockScreenWaitingTime")) { SET_CONF(c->lock_wait_time, atof(result->value)); - _D("'lock wait time' is %.3f.", c->lock_wait_time); + _D("lock wait time is %.3f", c->lock_wait_time); } else if (MATCH(result->name, "LongPressInterval")) { SET_CONF(c->longpress_interval, atof(result->value)); - _D("'long press interval' is %.3f.", c->longpress_interval); + _D("long press interval is %.3f", c->longpress_interval); } else if (MATCH(result->name, "LightSensorSamplingInterval")) { SET_CONF(c->lightsensor_interval, atof(result->value)); - _D("'lightsensor interval' is %.3f.", c->lightsensor_interval); + _D("lightsensor interval is %.3f", c->lightsensor_interval); } else if (MATCH(result->name, "LCDOffTimeout")) { SET_CONF(c->lcdoff_timeout, atoi(result->value)); - _D("'lcdoff timeout' is %d ms.", c->lcdoff_timeout); + _D("lcdoff timeout is %d ms", c->lcdoff_timeout); } else if (MATCH(result->name, "BrightnessChangeStep")) { SET_CONF(c->brightness_change_step, atoi(result->value)); - _D("'brightness change step' is %d.", c->brightness_change_step); + _D("brightness change step is %d", c->brightness_change_step); } else if (MATCH(result->name, "LCDAlwaysOn")) { c->lcd_always_on = (MATCH(result->value, "yes") ? 1 : 0); - _D("'LCD always on' is %d.", c->lcd_always_on); + _D("LCD always on is %d", c->lcd_always_on); + } else if (MATCH(result->name, "Dimming")) { + c->dimming = (MATCH(result->value, "yes") ? 1 : 0); + _D("Dimming is %d", c->dimming); } else if (MATCH(result->name, "ChangedFrameRateAllowed")) { if (strstr(result->value, "setting")) { c->framerate_app[REFRESH_SETTING] = 1; - _D("'framerate app' is setting"); + _D("framerate app is Setting"); } if (strstr(result->value, "all")) { memset(c->framerate_app, 1, sizeof(c->framerate_app)); - _D("'framerate app' is all"); + _D("framerate app is All"); } } else if (MATCH(result->name, "ControlDisplay")) { c->control_display = (MATCH(result->value, "yes") ? 1 : 0); - _D("'ControlDisplay' is %d.", c->control_display); + _D("ControlDisplay is %d", c->control_display); } else if (MATCH(result->name, "PowerKeyDoublePressSupport")) { c->powerkey_doublepress = (MATCH(result->value, "yes") ? 1 : 0); - _D("'PowerKeyDoublePressSupport' is %d.", c->powerkey_doublepress); + _D("PowerKeyDoublePressSupport is %d", c->powerkey_doublepress); } else if (MATCH(result->name, "AccelSensorOn")) { c->accel_sensor_on = (MATCH(result->value, "yes") ? 1 : 0); - _D("'AccelSensorOn' is %d.", c->accel_sensor_on); + _D("AccelSensorOn is %d", c->accel_sensor_on); } else if (MATCH(result->name, "ContinuousSampling")) { c->continuous_sampling = (MATCH(result->value, "yes") ? 1 : 0); - _D("'ContinuousSampling' is %d.", c->continuous_sampling); + _D("ContinuousSampling is %d", c->continuous_sampling); } else if (MATCH(result->name, "TimeoutEnable")) { c->timeout_enable = (MATCH(result->value, "yes") ? true : false); - _D("'Timeout' is %s.", c->timeout_enable ? "enalbed" : "disabled"); + _D("Timeout is %s", c->timeout_enable ? "enalbed" : "disabled"); } else if (MATCH(result->name, "InputSupport")) { c->input_support = (MATCH(result->value, "yes") ? true : false); - _D("'Input' is %s.", c->input_support ? "supported" : "NOT supported"); + _D("Input is %s", c->input_support ? "supported" : "NOT supported"); + } else if (MATCH(result->name, "LockCheckTimeout")) { + SET_CONF(c->lockcheck_timeout, atoi(result->value)); + _D("LockCheckTimeout is %d", c->lockcheck_timeout); + } else if (MATCH(result->name, "AODTSP")) { + c->aod_tsp = (MATCH(result->value, "yes") ? true : false); + _D("TSP control at is %d at aod", c->aod_tsp); } return 0; @@ -2247,9 +2682,58 @@ static int display_probe(void *data) return 0; } +static int input_init_handler(void) +{ + if (!display_conf.input_support) + return 0; + + g_idle_add(init_input, NULL); + + return 0; +} + +static void esd_action(void) +{ + const struct device_ops *touchscreen_ops = NULL; + + _I("ESD on"); + + touchscreen_ops = find_device("touchscreen"); + + if (!check_default(touchscreen_ops)) + touchscreen_ops->stop(NORMAL_MODE); + backlight_ops.off(NORMAL_MODE); + backlight_ops.on(NORMAL_MODE); + if (!check_default(touchscreen_ops)) + touchscreen_ops->start(NORMAL_MODE); +} + +static void lcd_uevent_changed(struct udev_device *dev) +{ + const char *devpath; + const char *action; + + devpath = udev_device_get_devpath(dev); + if (!devpath) + return; + + if (!fnmatch(LCD_ESD_PATH, devpath, 0)) { + action = udev_device_get_action(dev); + if (!strcmp(action, UDEV_CHANGE)) + esd_action(); + } +} + +static const struct uevent_handler lcd_uevent_ops = { + .subsystem = LCD_EVENT_SUBSYSTEM, + .uevent_func = lcd_uevent_changed, + .data = NULL, +}; + static void display_init(void *data) { int ret, i; + unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); int timeout = 0; bool wm_ready; @@ -2265,11 +2749,16 @@ static void display_init(void *data) _W("Failed to load '%s', use default value: %d", DISPLAY_CONF_FILE, ret); + register_kernel_uevent_control(&lcd_uevent_ops); + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); register_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); register_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); - register_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); + register_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); + register_notifier(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, display_auto_brightness_sensing); + + init_save_userlock(); for (i = INIT_SETTING; i < INIT_END; i++) { switch (i) { @@ -2279,15 +2768,14 @@ static void display_init(void *data) case INIT_INTERFACE: if (display_conf.timeout_enable) get_lcd_timeout_from_settings(); - ret = init_sysfs(); + ret = init_sysfs(flags); break; case INIT_POLL: - _I("Input init."); + _I("input init"); pm_callback = poll_callback; - if (display_conf.input_support) - ret = init_input(); - else - ret = 0; + ret = input_init_handler(); + + pm_lock_detector_init(); break; case INIT_DBUS: _I("Dbus init."); @@ -2308,6 +2796,13 @@ static void display_init(void *data) init_lcd_operation(); check_seed_status(); + /* In smd test, TSP should be turned off if display panel is not existed. */ + if (backlight_ops.get_lcd_power() == -ENOENT) { + _I("Display panel is not existed."); + lcd_direct_control(DPMS_OFF, NORMAL_MODE); + exit_lcd_operation(); + } + /* wm_ready needs to be checked * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ @@ -2322,33 +2817,35 @@ static void display_init(void *data) trans_table[S_NORMAL][EVENT_TIMEOUT] = S_NORMAL; } - _I("Start Power managing without noti."); - if (power_ops.get_power_lock_support()) - power_ops.power_lock(); - - pm_cur_state = S_NORMAL; - set_setting_pmstate(pm_cur_state); - - if (display_conf.timeout_enable) { - timeout = states[S_NORMAL].timeout; - /* check minimun lcd on time */ - if (timeout < SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT)) - timeout = SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT); + if (flags & WITHOUT_STARTNOTI) { /* start without noti */ + _I("Start Power managing without noti"); + if (power_ops.get_power_lock_support()) { + broadcast_pm_wakeup(); + power_ops.power_lock(); + } + pm_cur_state = S_NORMAL; + vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + + status = DEVICE_OPS_STATUS_START; + if (display_conf.timeout_enable) { + timeout = states[S_NORMAL].timeout; + /* check minimun lcd on time */ + if (timeout < SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT)) + timeout = SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT); + + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, + STAY_CUR_STATE, timeout); + } - reset_timeout(timeout); - } - - status = DEVICE_OPS_STATUS_START; - /* - * Lock lcd off until booting is done. - * deviced guarantees all booting script is executing. - * Last script of booting unlocks this suspend blocking state. - */ - if (disp_plgn.pm_lock_internal) { - disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, - STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); - disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, - STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); + /* + * Lock lcd off until booting is done. + * deviced guarantees all booting script is executing. + * Last script of booting unlocks this suspend blocking state. + */ + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, + STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); } if (display_conf.input_support) @@ -2372,6 +2869,8 @@ static void display_exit(void *data) if (CHECK_OPS(keyfilter_ops, exit)) keyfilter_ops->exit(); + unregister_kernel_uevent_control(&lcd_uevent_ops); + display_ops_exit(NULL); for (i = i - 1; i >= INIT_SETTING; i--) { @@ -2386,8 +2885,8 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); unregister_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); unregister_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); - unregister_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); + unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); exit_input(); break; @@ -2405,6 +2904,9 @@ static void display_exit(void *data) static int display_start(enum device_flags flags) { + const struct display_ops *enhance_ops = NULL; + bool on = true; + /* NORMAL MODE */ if (flags & NORMAL_MODE) { if (flags & LCD_PANEL_OFF_MODE) @@ -2413,6 +2915,9 @@ static int display_start(enum device_flags flags) else /* normal lcd on */ backlight_ops.on(flags); + FIND_DISPLAY(enhance_ops, "enhance"); + if (enhance_ops && enhance_ops->func) + enhance_ops->func(RESTORE_ENHANCE_OUTDOOR, &on); return 0; } @@ -2434,7 +2939,7 @@ static int display_start(enum device_flags flags) static int display_stop(enum device_flags flags) { /* NORMAL MODE */ - if (flags & NORMAL_MODE) { + if (flags & NORMAL_MODE || flags & FORCE_OFF_MODE) { backlight_ops.off(flags); return 0; } @@ -2458,7 +2963,7 @@ static int display_status(void) static const struct device_ops display_device_ops = { .priority = DEVICE_PRIORITY_HIGH, - .name = "display", + DECLARE_NAME_LEN("display"), .probe = display_probe, .init = display_init, .exit = display_exit, diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 01b98ac..37a86cb 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -29,19 +29,21 @@ #include #include #include -#include +#include #include "ambient-mode.h" #include "core/log.h" #include "core/devices.h" -#include "core/list.h" #include "core/common.h" -#include "display/display-dpms.h" +#include "core/device-notifier.h" #include "util.h" #include "device-interface.h" #include "vconf.h" #include "core.h" #include "device-node.h" +#include "display/display-dpms.h" + +#define SET_SUSPEND_TIME 0.5 #define TOUCH_ON 1 #define TOUCH_OFF 0 @@ -49,7 +51,8 @@ #define LCD_PHASED_MIN_BRIGHTNESS 1 #define LCD_PHASED_MAX_BRIGHTNESS 100 #define LCD_PHASED_CHANGE_STEP 5 -#define LCD_PHASED_DELAY 35000 /* microsecond */ +#define LCD_PHASED_DELAY 10000 /* microsecond */ +#define DUMP_MODE_WAITING_TIME 600000 /* microsecond */ #define POWER_AUTOSLEEP_PATH "/sys/power/autosleep" #define POWER_LOCK_PATH "/sys/power/wake_lock" @@ -57,24 +60,57 @@ #define POWER_WAKEUP_PATH "/sys/power/wakeup_count" #define POWER_STATE_PATH "/sys/power/state" -enum { - POWER_UNLOCK = 0, - POWER_LOCK, -}; +#define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" + +#define GESTURE_STR "gesture" +#define POWERKEY_STR "powerkey" +#define EVENT_STR "event" +#define TOUCH_STR "touch" +#define TIMEOUT_STR "timeout" +#define PROXIMITY_STR "proximity" +#define PALM_STR "palm" +#define UNKNOWN_STR "unknown" + +#define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" struct _backlight_ops backlight_ops; struct _power_ops power_ops; +static int mainlock_status = POWER_UNLOCK; static bool custom_status; static int custom_brightness; static int force_brightness; static int default_brightness; - +static int vital_support = -2; +static int vital_service; +static bool vital_sleep; +static int dpms_running_state = DPMS_SETTING_DONE; static struct display_device *display_dev; +static guint release_timer; -static int bl_onoff(int on) +struct display_device *display_dev_get(void) +{ + return display_dev; +} + +void dpms_set_running_state(int val) +{ + dpms_running_state = val; +} + +static int bl_onoff(int on, enum device_flags flags) { dpms_set_state(on); + +#ifdef ENABLE_PM_LOG + if (on == DPMS_ON) + pm_history_save(PM_LOG_LCD_ON_COMPLETE, pm_cur_state); + else if (on == DPMS_OFF || on == DPMS_FORCE_OFF) + pm_history_save(PM_LOG_LCD_OFF_COMPLETE, pm_cur_state); + else + pm_history_save(PM_LOG_LCD_CONTROL_FAIL, on); +#endif + return 0; } @@ -85,12 +121,6 @@ static int bl_brt(int brightness, int delay) if (delay > 0) usleep(delay); - if (force_brightness > 0) { - _I("brightness=%d force brightness=%d", - brightness, force_brightness); - brightness = force_brightness; - } - /* Update device brightness */ ret = backlight_ops.set_brightness(brightness); @@ -115,39 +145,96 @@ static int system_enable_autosleep(void) return sys_set_str(POWER_AUTOSLEEP_PATH, "mem"); } -static int system_power_lock(void) +static int vital_mode_support(void) { - dd_list *elem, *elem_n; - const struct device_ops *dev; - int ret; + if (vital_support < 0) { + FILE *fp; + + fp = fopen(FREEZER_VITAL_WAKEUP_CGROUP, "r"); + if (fp == NULL) { + _E("%s open failed", FREEZER_VITAL_WAKEUP_CGROUP); + /* read max 2 times to check if this file exist */ + vital_support++; + return 0; + } + vital_support = 1; + fclose(fp); + } + return vital_support; +} - _I("system power lock."); - ret = sys_set_str(POWER_LOCK_PATH, "mainlock"); +static int suspend_other_process(int type) +{ + int ret = 0; + char buf[8]; + const char *command[1]; - /* Devices Resume */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->resume) - dev->resume(); - } + if (vital_service == type) + return ret; + + if (type == VITAL_WAKEUP && vital_service > VITAL_SLEEP) + return ret; + + vital_service = type; + + if (!vital_mode_support()) + return ret; + if (type == VITAL_SLEEP) { + snprintf(buf, sizeof(buf), "%s", "sleep"); + command[0] = buf; + dbus_handle_method_sync_timeout(RESOURCED_BUS_NAME, + RESOURCED_PATH_FREEZER, + RESOURCED_INTERFACE_FREEZER, + "SetSuspend", + "s", + command, + SET_SUSPEND_TIME*1000); + vital_sleep = true; + } else if (type == VITAL_WAKEUP) { + snprintf(buf, sizeof(buf), "%s", "wakeup"); + command[0] = buf; + ret = dbus_handle_method_async(RESOURCED_BUS_NAME, + RESOURCED_PATH_FREEZER, + RESOURCED_INTERFACE_FREEZER, + "SetSuspend", + "s", command); + } else if (type == VITAL_EXIT) { + snprintf(buf, sizeof(buf), "%s", "exit"); + command[0] = buf; + ret = dbus_handle_method_async(RESOURCED_BUS_NAME, + RESOURCED_PATH_FREEZER, + RESOURCED_INTERFACE_FREEZER, + "SetSuspend", + "s", command); + vital_sleep = false; + } return ret; } -static int system_power_unlock(void) +static int system_power_lock(void) { - dd_list *elem, *elem_n; - const struct device_ops *dev; + _I("system power lock"); + suspend_other_process(VITAL_WAKEUP); + mainlock_status = POWER_LOCK; - /* Devices Suspend */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->suspend) - dev->suspend(); - } + return sys_set_str(POWER_LOCK_PATH, "mainlock"); +} + +static int system_power_unlock(void) +{ + _I("system power unlock"); + suspend_other_process(VITAL_SLEEP); + mainlock_status = POWER_UNLOCK; - _I("system power unlock."); return sys_set_str(POWER_UNLOCK_PATH, "mainlock"); } +static int system_get_power_lock(void) +{ + return mainlock_status; +} + static int system_get_power_lock_support(void) { static int power_lock_support = -1; @@ -162,7 +249,7 @@ static int system_get_power_lock_support(void) else power_lock_support = true; - _I("system power lock: %s", + _I("System power lock: %s", (power_lock_support ? "support" : "not support")); out: @@ -174,9 +261,6 @@ static int get_lcd_power(void) enum display_state val; int ret; - if (ambient_get_state()) - return DPMS_OFF; - if (!display_dev || !display_dev->get_state) { _E("There is no display device."); return -ENOENT; @@ -186,6 +270,12 @@ static int get_lcd_power(void) if (ret < 0) return ret; + if (val == DISPLAY_ON && ambient_get_state()) + return DPMS_OFF; + + if (dpms_running_state != DPMS_SETTING_DONE) + return dpms_running_state; + switch (val) { case DISPLAY_ON: return DPMS_ON; @@ -202,13 +292,16 @@ static int get_lcd_power(void) bool display_dimstay_check(void) { + if (pm_status_flag & DIM_FLAG) + return true; + if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) return true; return false; } -void change_brightness(int start, int end, int step) +static void change_brightness(int start, int end, int step) { int diff, val; int ret = -1; @@ -226,7 +319,20 @@ void change_brightness(int start, int end, int step) if (prev == end) return; - _D("start=%d end=%d step=%d", start, end, step); + if (pm_status_flag & DIM_MASK) + end = 0; + + _I("start %d end %d step %d", start, end, step); + + if (display_dev && display_dev->set_multi_brightness) { + ret = display_dev->set_multi_brightness(end, step, LCD_PHASED_DELAY); + if (ret < 0) + _E("Failed to set_multi_brightness (%d)", ret); + + backlight_ops.set_brightness(end); + + return; + } diff = end - start; @@ -250,16 +356,15 @@ void change_brightness(int start, int end, int step) static int backlight_on(enum device_flags flags) { int ret = -1; + static int cnt; - _D("LCD on %x", flags); + _I("[DPMS XLIB Backlight] LCD on %x cnt:%d", flags, cnt); - ret = bl_onoff(DPMS_ON); - if (ret < 0) - _E("Failed to turn on backlight."); - - if (flags & LCD_PHASED_TRANSIT_MODE) - change_brightness(LCD_PHASED_MIN_BRIGHTNESS, - default_brightness, LCD_PHASED_CHANGE_STEP); + cnt++; + ret = bl_onoff(DPMS_ON, flags); +#ifdef ENABLE_PM_LOG + pm_history_save(PM_LOG_LCD_ON, pm_cur_state); +#endif return ret; } @@ -267,19 +372,30 @@ static int backlight_on(enum device_flags flags) static int backlight_off(enum device_flags flags) { int ret = -1; + static int cnt, ambient_cnt; + + if (flags & AMBIENT_MODE) { + _I("[DPMS XLIB Backlight] LCD suspend %x cnt:%d", flags, ambient_cnt); + ambient_cnt++; + + return 0; + } - _D("LCD off %x", flags); + _I("[DPMS XLIB Backlight] LCD off %x cnt:%d", flags, cnt); + cnt++; if (flags & LCD_PHASED_TRANSIT_MODE) - change_brightness(default_brightness, + backlight_ops.transit_brt(default_brightness, LCD_PHASED_MIN_BRIGHTNESS, LCD_PHASED_CHANGE_STEP); - if (flags & AMBIENT_MODE) - return 0; + if (flags & FORCE_OFF_MODE) + ret = bl_onoff(DPMS_FORCE_OFF, flags); + else + ret = bl_onoff(DPMS_OFF, flags); - ret = bl_onoff(DPMS_OFF); - if (ret < 0) - _E("Failed to turn off backlight."); +#ifdef ENABLE_PM_LOG + pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); +#endif return ret; } @@ -287,15 +403,8 @@ static int backlight_off(enum device_flags flags) static int backlight_dim(void) { int ret; - int brightness; - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, &brightness); - if (ret < 0) { - _E("Failed to get vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - return -EPERM; - } - - ret = bl_brt(brightness, 0); + ret = backlight_ops.set_brightness(PM_DIM_BRIGHTNESS); #ifdef ENABLE_PM_LOG if (!ret) pm_history_save(PM_LOG_LCD_DIM, pm_cur_state); @@ -335,11 +444,11 @@ static int custom_backlight_update(void) custom_brightness > PM_MAX_BRIGHTNESS) return -EINVAL; - if (display_dimstay_check()) { + if (display_dimstay_check()) ret = backlight_dim(); - } else { - _I("Custom brightness(%d) restored.", custom_brightness); - ret = bl_brt(custom_brightness, 0); + else { + _I("custom brightness restored! %d", custom_brightness); + ret = backlight_ops.set_brightness(custom_brightness); } return ret; @@ -358,16 +467,18 @@ static int set_force_brightness(int level) static int backlight_update(void) { int ret = 0; + int brt; if (get_custom_status()) { - _I("Custom brightness mode. brt no updated."); + _I("custom brightness mode! brt no updated"); return 0; } if (display_dimstay_check()) ret = backlight_dim(); - else - ret = bl_brt(default_brightness, 0); - + else { + brt = backlight_ops.get_default_brt(); + ret = backlight_ops.set_brightness(brt); + } return ret; } @@ -377,7 +488,7 @@ static int backlight_standby(int force) if ((get_lcd_power() == DPMS_ON) || force) { _I("LCD standby"); - ret = bl_onoff(DPMS_STANDBY); + ret = bl_onoff(DPMS_STANDBY, 0); } return ret; @@ -393,6 +504,11 @@ static int set_default_brt(int level) return 0; } +static int get_default_brt(void) +{ + return default_brightness; +} + static int check_wakeup_src(void) { /* TODO if nedded. @@ -470,10 +586,22 @@ static int set_brightness(int val) return max; } + if (force_brightness > 0 && val != PM_DIM_BRIGHTNESS) { + _I("brightness(%d), force brightness(%d)", + val, force_brightness); + val = force_brightness; + } + + if (pm_status_flag & DIM_MASK) + val = 0; + /* Maximum Brightness to users is 100. * Thus real brightness need to be calculated */ val = val * max / 100; + _I("set brightness %d (default:%d)", val, default_brightness); + device_notify(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, (void *)&val); + return display_dev->set_brightness(val); } @@ -544,6 +672,84 @@ static int get_brightness_by_light_sensor(float lmax, float lmin, float light, i return 0; } +static int get_image_effect(enum display_image_effect *effect) +{ + int ret; + enum display_image_effect val; + + if (!display_dev || !display_dev->get_image_effect) { + _E("There is no display device."); + return -ENOENT; + } + + ret = display_dev->get_image_effect(&val); + if (ret < 0) { + _E("Failed to get image effect: %d", ret); + return ret; + } + + *effect = val; + + return 0; +} + +static int set_image_effect(enum display_image_effect effect) +{ + int ret; + + if (!display_dev || !display_dev->set_image_effect) { + _E("There is no display device."); + return -ENOENT; + } + + ret = display_dev->set_image_effect(effect); + if (ret < 0) { + _E("Failed to set image effect: %d", ret); + return ret; + } + + return 0; +} + +static int get_panel_mode(enum display_panel_mode *mode) +{ + int ret; + enum display_panel_mode val; + + if (!display_dev || !display_dev->get_panel_mode) { + _E("there is no display device"); + return -ENOENT; + } + + ret = display_dev->get_panel_mode(&val); + if (ret < 0) { + _E("failed to get panel mode(%d)", ret); + return ret; + } + + *mode = val; + + return 0; +} + +static int set_panel_mode(enum display_panel_mode mode) +{ + int ret; + + if (!display_dev || !display_dev->set_panel_mode) { + _E("there is no display device"); + return -ENOENT; + } + + ret = display_dev->set_panel_mode(mode); + if (ret < 0) { + _E("failed to set panel mode(%d)", ret); + return ret; + } + + return 0; +} + static int get_frame_rate(int *rate) { if (!rate) @@ -595,6 +801,101 @@ static int set_frame_rate(int rate) return display_dev->set_frame_rate(rate); } +/* It was operated only AOD enter & leave */ +static int backlight_transit_state(int state) +{ + int brt, val; + int start, end; + + backlight_ops.get_brightness(&brt); + + if (state == DPMS_OFF) { + start = brt; + end = display_conf.aod_enter_level; + + /* + * The value of backlight_ops.get_brightness is system brightness. + * But when device is LBM, the value is not same with real brightness. + * So it should be read exactly value for transit smooth effect + */ + get_brightness(&val); + + if (val > display_conf.aod_enter_level) + backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + } else { + /* prevent transit effect when another effect is already executed */ + if (brt != display_conf.aod_enter_level) { + _W("effect is already executed brt(%d) aod_level(%d)", + brt, display_conf.aod_enter_level); + return 0; + } + + start = display_conf.aod_enter_level; + end = default_brightness; + backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + } + + return 0; +} + +static gboolean blink_cb(gpointer data) +{ + static bool flag; + + set_brightness(flag ? PM_MAX_BRIGHTNESS : PM_MIN_BRIGHTNESS); + + flag = !flag; + + return G_SOURCE_CONTINUE; +} + +static void blink(int timeout) +{ + static guint timer; + + if (timer) { + g_source_remove(timer); + timer = 0; + } + + if (timeout < 0) { + _E("timeout value is invalid %d", timeout); + return; + } + + if (timeout == 0) { + backlight_update(); + return; + } + + timer = g_timeout_add(timeout, blink_cb, NULL); +} + +static gboolean release_blink_cb(gpointer data) +{ + blink(0); + + release_timer = 0; + return G_SOURCE_REMOVE; +} + +static void release_blink(void) +{ + if (release_timer) { + g_source_remove(release_timer); + release_timer = 0; + } + + release_timer = g_timeout_add(DUMP_MODE_WAITING_TIME, release_blink_cb, NULL); +} + +static void restore_brightness_func(void) +{ + backlight_ops.set_brightness = set_brightness; + backlight_ops.get_brightness = get_brightness; + backlight_ops.transit_brt = change_brightness; +} + static void _init_ops(void) { backlight_ops.off = backlight_off; @@ -603,6 +904,7 @@ static void _init_ops(void) backlight_ops.update = backlight_update; backlight_ops.standby = backlight_standby; backlight_ops.set_default_brt = set_default_brt; + backlight_ops.get_default_brt = get_default_brt; backlight_ops.get_lcd_power = get_lcd_power; backlight_ops.set_custom_status = set_custom_status; backlight_ops.get_custom_status = get_custom_status; @@ -611,14 +913,24 @@ static void _init_ops(void) backlight_ops.set_force_brightness = set_force_brightness; backlight_ops.set_brightness = set_brightness; backlight_ops.get_brightness = get_brightness; + backlight_ops.restore_brightness_func = restore_brightness_func; backlight_ops.get_brightness_by_light_sensor = get_brightness_by_light_sensor; + backlight_ops.get_image_effect = get_image_effect; + backlight_ops.set_image_effect = set_image_effect; + backlight_ops.get_panel_mode = get_panel_mode; + backlight_ops.set_panel_mode = set_panel_mode; backlight_ops.get_frame_rate = get_frame_rate; backlight_ops.set_frame_rate = set_frame_rate; + backlight_ops.transit_state = backlight_transit_state; + backlight_ops.transit_brt = change_brightness; + backlight_ops.blink = blink; + backlight_ops.release_blink = release_blink; power_ops.suspend = system_suspend; power_ops.enable_autosleep = system_enable_autosleep; power_ops.power_lock = system_power_lock; power_ops.power_unlock = system_power_unlock; + power_ops.get_power_lock = system_get_power_lock; power_ops.get_power_lock_support = system_get_power_lock_support; power_ops.check_wakeup_src = check_wakeup_src; power_ops.get_wakeup_count = get_wakeup_count; @@ -636,12 +948,12 @@ int display_service_load(void) r = hw_get_info(DISPLAY_HARDWARE_DEVICE_ID, (const struct hw_info **)&info); if (r < 0) { - _I("Display shared library is not supported: %d", r); - return -ENODEV; + _I("display shared library is not supported: %d", r); + return 0; } if (!info->open) { - _E("Failed to open display device: open(NULL)"); + _E("Failed to open display device: open(NULL)."); return -EPERM; } @@ -672,17 +984,44 @@ int display_service_free(void) return 0; } -int init_sysfs() +bool vital_mode(void) +{ + return vital_sleep; +} + +static int vital_state_changed(void *data) +{ + int type; + + assert(data); + + type = *(int *)data; + if (type == VITAL_EXIT) + suspend_other_process(VITAL_EXIT); + + return 0; +} + +int init_sysfs(unsigned int flags) { _init_ops(); + register_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); + return 0; } int exit_sysfs(void) { + int fd; const struct device_ops *ops = NULL; + fd = open("/tmp/sem.pixmap_1", O_RDONLY); + if (fd == -1) { + _E("X server disable"); + backlight_on(NORMAL_MODE); + } + backlight_update(); disconnect_interface_with_dpms(); @@ -694,5 +1033,10 @@ int exit_sysfs(void) if (!check_default(ops)) ops->start(NORMAL_MODE); + if (fd != -1) + close(fd); + + unregister_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); + return 0; } diff --git a/plugins/mobile/display/display-info.h b/plugins/mobile/display/display-info.h new file mode 100644 index 0000000..bf368da --- /dev/null +++ b/plugins/mobile/display/display-info.h @@ -0,0 +1,50 @@ +/* + * deviced + * + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __DISPLAY_INFO_H__ +#define __DISPLAY_INFO_H__ + +#define DISPLAY_FUNC(a, b) (((a) << 16) | (b)) +#define ENHANCE_CMD(x) DISPLAY_FUNC('E', (x)) +#define HBM_CMD(x) DISPLAY_FUNC('H', (x)) +#define LBM_CMD(x) DISPLAY_FUNC('L', (x)) + +enum hbm_state { + HBM_SET_STATE = HBM_CMD(1), + HBM_GET_STATE, + HBM_TURN_ON, + HBM_TURN_OFF, + HBM_SET_TIMEOUT_STATE, + HBM_TURN_OFF_STATE, +}; + +enum lbm_state { + LBM_TABLE_LOAD = LBM_CMD(1), +}; + +enum enhance_state { + RESTORE_ENHANCE_OUTDOOR = ENHANCE_CMD(1), +}; + +struct hbmsetstate { + int hbm; + int timeout; +}; + +#endif diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index 3462aa7..ddbb287 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "ambient-mode.h" #include "util.h" @@ -36,11 +37,11 @@ #include "core/common.h" #include "core/devices.h" #include "core/device-notifier.h" +#include "shared/common.h" #include "power/power-handler.h" #include "led/touch-key.h" #include "apps/apps.h" -#include #ifndef KEY_SCREENLOCK #define KEY_SCREENLOCK 0x98 #endif @@ -50,21 +51,24 @@ #define PREDEF_LEAVESLEEP "leavesleep" #define POWEROFF_ACT "poweroff" +#define PWROFF_POPUP_ACT "pwroff_popup" #define USEC_PER_SEC 1000000 +#define CSC_CONFIG_MODE_RUNNING 1 #define CAPTURE_COMBINATION_INTERVAL 0.5 /* 0.5 second */ +#define TORCH_COMBINATION_INTERVAL 0.1 /* 0.1 second */ +#define DEFAULT_COMBINATION_INTERVAL 0.1 /* 0.1 second */ -#define KEY_MAX_DELAY_TIME 700 /* ms */ +#define LONGKEY_PRESSED_TIME 4 /* 4 second */ -#define KEY_RELEASED 0 -#define KEY_PRESSED 1 -#define KEY_BEING_PRESSED 2 +#define KEY_MAX_DELAY_TIME 700 /* ms */ #define SIGNAL_CHANGE_HARDKEY "ChangeHardkey" #define SIGNAL_LCDON_BY_POWERKEY "LCDOnByPowerkey" #define SIGNAL_LCDOFF_BY_POWERKEY "LCDOffByPowerkey" -#define TOUCH_RELEASE (-1) +#define NORMAL_POWER 0 +#define KEY_TEST_MODE_POWER 2 #define GLOVE_MODE 1 @@ -72,39 +76,30 @@ enum key_combination_flags { KEY_COMBINATION_STOP = 0, KEY_COMBINATION_POWERKEY = BIT(0), KEY_COMBINATION_MENUKEY = BIT(1), + KEY_COMBINATION_VOLUMEUP = BIT(2), + KEY_COMBINATION_VOLUMEDOWN = BIT(3), }; enum combination_process { COMBINATION_STOP = KEY_COMBINATION_STOP, COMBINATION_SCREENCAPTURE = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_MENUKEY, + COMBINATION_TORCH = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_VOLUMEUP, + COMBINATION_QUICKTALK = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_VOLUMEDOWN, }; -int __WEAK__ get_glove_state(void); -void __WEAK__ switch_glove_key(int val); - static struct timeval pressed_time; static guint longkey_timeout_id = 0; +static guint longkey_restore_id = 0; +static guint displayon_by_powerkey_timeout_id = 0; static int cancel_lcdoff; static int key_combination = KEY_COMBINATION_STOP; static double combination_pressed_time; static bool touch_pressed = false; static int skip_lcd_off = false; static int skip_combination = false; +static int bezel_wakeup = true; static const struct device_ops *touchled; - -static int booting_done(void *data) -{ - static int done = 0; - - if (!data) - return done; - - done = *(int *)data; - - _I("Booting done(%d)", done); - - return done; -} +static int booting_check = true; static inline int current_state_in_on(void) { @@ -128,7 +123,7 @@ static void pwroff_popup(void) _E("Failed to launch power off popup."); } -static void longkey_pressed() +static void longkey_pressed(void) { unsigned int caps; @@ -152,6 +147,14 @@ static void longkey_pressed() pwroff_popup(); } +static gboolean longkey_restore_cb(void *data) +{ + device_notify(DEVICE_NOTIFIER_LONGKEY_RESTORE, (void *)NULL); + longkey_restore_id = 0; + + return G_SOURCE_REMOVE; +} + static gboolean longkey_pressed_cb(void *data) { longkey_pressed(); @@ -196,7 +199,7 @@ static inline void broadcast_lcdoff_by_powerkey(void) NULL); } -static inline bool switch_on_lcd(void) +static inline bool switch_on_lcd(enum device_flags flags) { if (current_state_in_on()) return false; @@ -206,9 +209,12 @@ static inline bool switch_on_lcd(void) return false; } - broadcast_lcdon_by_powerkey(); + if (flags & LCD_ON_BY_POWER_KEY) + broadcast_lcdon_by_powerkey(); + else if (flags & LCD_ON_BY_TOUCH) + _I("Display on by Touch_wakeup event"); - lcd_on_direct(LCD_ON_BY_POWER_KEY); + lcd_on_direct(flags); return true; } @@ -230,15 +236,37 @@ static void check_key_combination(struct input_event *pinput) { double press_time, diff_time; press_time = (pinput->time).tv_sec + USEC_TO_SEC((pinput->time).tv_usec); + diff_time = press_time - combination_pressed_time; switch (key_combination) { case COMBINATION_SCREENCAPTURE: - diff_time = press_time - combination_pressed_time; if (diff_time <= CAPTURE_COMBINATION_INTERVAL) { _I("Combination key : SCREENCAPTURE mode"); skip_combination = true; } break; + case COMBINATION_TORCH: + if (diff_time <= TORCH_COMBINATION_INTERVAL) { + /* When torch combination, display control should be not change. */ + if (displayon_by_powerkey_timeout_id) { + g_source_remove(displayon_by_powerkey_timeout_id); + displayon_by_powerkey_timeout_id = 0; + } + _I("Combination key : TORCH mode"); + skip_combination = true; + } else + key_combination = COMBINATION_STOP; + break; + case COMBINATION_QUICKTALK: + if (diff_time <= DEFAULT_COMBINATION_INTERVAL) { + _I("Combination key : QUICK-TALK mode"); + skip_combination = true; + if (longkey_timeout_id) { + g_source_remove(longkey_timeout_id); + longkey_timeout_id = 0; + } + } + break; default: combination_pressed_time = press_time; return; @@ -255,6 +283,12 @@ static void start_key_combination(struct input_event *pinput) case KEY_MENU: key_combination |= KEY_COMBINATION_MENUKEY; break; + case KEY_VOLUMEUP: + key_combination |= KEY_COMBINATION_VOLUMEUP; + break; + case KEY_VOLUMEDOWN: + key_combination |= KEY_COMBINATION_VOLUMEDOWN; + break; default: return; } @@ -276,8 +310,14 @@ static void stop_key_combination(struct input_event *pinput) case KEY_MENU: key_combination &= ~KEY_COMBINATION_MENUKEY; break; + case KEY_VOLUMEUP: + key_combination &= ~KEY_COMBINATION_VOLUMEUP; + break; + case KEY_VOLUMEDOWN: + key_combination &= ~KEY_COMBINATION_VOLUMEDOWN; + break; default: - _E("Thid code(%d) is not combination type", pinput->code); + _E("This code(%d) is not combination type.", pinput->code); break; } } @@ -301,9 +341,8 @@ static int process_menu_key(struct input_event *pinput) return false; _D("No lcd-on capability!"); return true; - } else if (pinput->value == KEY_PRESSED) { - switch_on_lcd(); - } + } else if (pinput->value == KEY_PRESSED) + switch_on_lcd(LCD_ON_BY_POWER_KEY); return false; } @@ -336,7 +375,7 @@ static int decide_lcdoff(void) return false; /* At booting time, display must do not turn off */ - if (!booting_done(NULL)) + if (booting_check) return false; return true; @@ -370,6 +409,50 @@ static int lcdoff_powerkey(void) return ignore; } +static bool key_check_display_on(void) +{ + if (current_state_in_on()) + return false; + + if (backlight_ops.get_lcd_power() == DPMS_ON) { + _W("display power was on"); + return false; + } + + return true; +} + +static gboolean display_on_cb(void *data) +{ + if (displayon_by_powerkey_timeout_id == 0) + return G_SOURCE_REMOVE; + + displayon_by_powerkey_timeout_id = 0; + if (backlight_ops.get_lcd_power() != DPMS_ON || + current_state_in_on() == false) { + broadcast_lcdon_by_powerkey(); + lcd_on_direct(LCD_ON_BY_POWER_KEY); + + if (pm_callback) + (*pm_callback) (INPUT_POLL_EVENT, NULL); + } + + return G_SOURCE_REMOVE; +} + +static int process_back_key(struct input_event *pinput) +{ + int ignore = true; + + if (pinput->value == KEY_PRESSED) { + switch_on_lcd(LCD_ON_BY_POWER_KEY); + _I("back key pressed"); + ignore = false; + } + + return ignore; +} + static int process_power_key(struct input_event *pinput) { int ignore = true; @@ -387,9 +470,8 @@ static int process_power_key(struct input_event *pinput) lcdoff_powerkey(); else _D("No lcdoff capability!"); - } else if (skip_lcd_off) { + } else if (skip_lcd_off) ignore = false; - } if (!display_has_caps(caps, DISPLAY_CAPA_LCDON)) ignore = true; @@ -399,10 +481,32 @@ static int process_power_key(struct input_event *pinput) longkey_timeout_id = 0; } + if (longkey_restore_id > 0) { + g_source_remove(longkey_restore_id); + longkey_restore_id = 0; + } + break; case KEY_PRESSED: if (display_has_caps(caps, DISPLAY_CAPA_LCDON)) { - skip_lcd_off = switch_on_lcd(); + if (wearable_mode()) + skip_lcd_off = switch_on_lcd(LCD_ON_BY_POWER_KEY); + else { + /* + * LCD does not turn on immediately at mobile. + * It will be turned on after 0.1 second because of torch concept. + */ + skip_lcd_off = key_check_display_on(); + ignore = true; + + if (!displayon_by_powerkey_timeout_id && + backlight_ops.get_lcd_power() != DPMS_ON && + key_combination != COMBINATION_TORCH) { + displayon_by_powerkey_timeout_id = g_timeout_add( + 100, + display_on_cb, NULL); + } + } } else { _D("No lcdon capability!"); skip_lcd_off = false; @@ -416,9 +520,11 @@ static int process_power_key(struct input_event *pinput) longkey_timeout_id = g_timeout_add_seconds( display_conf.longpress_interval, longkey_pressed_cb, NULL); + /* add long key restore timer */ + longkey_restore_id = g_timeout_add_seconds( + LONGKEY_PRESSED_TIME, + longkey_restore_cb, NULL); } - if (skip_lcd_off) - ignore = false; cancel_lcdoff = 0; break; @@ -479,10 +585,12 @@ static void process_hardkey_backlight(struct input_event *pinput) _I("Touch is pressed, then hard key is not working!"); return; } + if (!wearable_mode()) { /* Sound & Vibrate only in unlock state */ if (__get_lock_screen_state() == VCONFKEY_IDLE_UNLOCK || get_lock_screen_bg_state()) sound_vibrate_hardkey(); + } if (touchled && touchled->execute) { opt = TOUCHLED_PRESS; @@ -502,6 +610,23 @@ static void process_hardkey_backlight(struct input_event *pinput) } } +static void update_vital_state(struct input_event *pinput) +{ + int type; + + /* Change vital state to VITAL_EXIT only if vital mode is active */ + if (!vital_mode()) + return; + + /* Touch or Menu Key Release Event */ + if (pinput->type == EV_ABS || (pinput->type == EV_KEY && + pinput->value == KEY_RELEASED && pinput->code == KEY_MENU)) { + /* Enable all services upon receiving user input, else maintain same state */ + type = VITAL_EXIT; + device_notify(DEVICE_NOTIFIER_VITAL_STATE, &type); + } +} + static int check_key(struct input_event *pinput, int fd) { int ignore = true; @@ -520,6 +645,13 @@ static int check_key(struct input_event *pinput, int fd) ignore = process_screenlock_key(pinput); break; case KEY_BACK: + ignore = process_back_key(pinput); + stop_key_combination(NULL); + if (current_state_in_on()) { + process_hardkey_backlight(pinput); + ignore = false; + } + break; case KEY_PHONE: stop_key_combination(NULL); if (current_state_in_on()) { @@ -529,6 +661,9 @@ static int check_key(struct input_event *pinput, int fd) break; case KEY_VOLUMEUP: case KEY_VOLUMEDOWN: + if (current_state_in_on()) + ignore = false; + break; case KEY_CAMERA: case KEY_EXIT: case KEY_CONFIG: @@ -594,34 +729,36 @@ static int check_key_filter(void *data, int fd) code = pinput->code; value = pinput->value; + update_vital_state(pinput); ignore = check_key(pinput, fd); restore_custom_brightness(); break; case EV_REL: - ignore = false; + if (pm_cur_state == S_LCDOFF && bezel_wakeup) { + switch_on_lcd(LCD_ON_BY_BEZEL); + ignore = false; + } else if (pm_cur_state != S_LCDOFF) + ignore = false; break; case EV_ABS: - if (current_state_in_on()) + update_vital_state(pinput); + if (pinput->value == KEY_PRESSED) { + switch_on_lcd(LCD_ON_BY_TOUCH); ignore = false; + } - if (ambient_get_condition() == true) { - switch_on_lcd(); + if (current_state_in_on()) ignore = false; - } restore_custom_brightness(); - touch_pressed = - (pinput->value == TOUCH_RELEASE ? false : true); + if (pinput->value == KEY_PRESSED) + touch_pressed = true; + else if (pinput->value == KEY_RELEASED) + touch_pressed = false; break; case EV_SW: - if (!get_glove_state || !switch_glove_key) - break; - if (pinput->code == SW_GLOVE && - get_glove_state() == GLOVE_MODE) { - switch_glove_key(pinput->value); - } break; } @@ -631,6 +768,20 @@ static int check_key_filter(void *data, int fd) return 0; } +static int booting_done_cb(void *data) +{ + booting_check = 0; + + return 0; +} + +static int bezel_wakeup_cb(void *data) +{ + bezel_wakeup = (int)data; + + return 0; +} + /* * Default capability * powerkey := LCDON | LCDOFF | POWEROFF @@ -655,12 +806,8 @@ static void keyfilter_init(void) touchled = find_device(TOUCHLED_NAME); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); -} - -static void keyfilter_exit(void) -{ - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); + register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb); } static void key_backlight_enable(bool enable) @@ -680,7 +827,6 @@ static void key_backlight_enable(bool enable) static const struct display_keyfilter_ops normal_keyfilter_ops = { .init = keyfilter_init, - .exit = keyfilter_exit, .check = check_key_filter, .set_powerkey_ignore = NULL, .powerkey_lcdoff = NULL, diff --git a/plugins/mobile/display/proximity.c b/plugins/mobile/display/proximity.c new file mode 100644 index 0000000..7c04036 --- /dev/null +++ b/plugins/mobile/display/proximity.c @@ -0,0 +1,47 @@ +/* + * deviced + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "display/core.h" +#include "shared/log-macro.h" + +#include "proximity.h" + +static int proximity_state = SENSOR_PROXIMITY_NONE; + +int set_proximity_state(int val) +{ + switch (val) { + case SENSOR_PROXIMITY_NONE: + case SENSOR_PROXIMITY_NEAR: + case SENSOR_PROXIMITY_FAR: + break; + default: + _E("Invailed proximity value(%d)", val); + return -1; + } + + _D("set proximity value(%d)", val); + proximity_state = val; + return 0; +} + +int get_proximity_state(void) +{ + return proximity_state; +} + diff --git a/plugins/mobile/display/proximity.h b/plugins/mobile/display/proximity.h new file mode 100644 index 0000000..bbe5509 --- /dev/null +++ b/plugins/mobile/display/proximity.h @@ -0,0 +1,35 @@ +/* + * deviced + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * @file proximity.h + * @brief proximity header file + */ +#ifndef __PROXIMITY_H__ +#define __PROXIMITY_H__ + +/* + * @brief define proximity state + */ +#define SENSOR_PROXIMITY_NONE -1 +#define SENSOR_PROXIMITY_NEAR 0 +#define SENSOR_PROXIMITY_FAR 5 + +int get_proximity_state(void); +#endif diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 79bd919..dbd6954 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -35,10 +35,9 @@ #include #include #include +#include #include #include -#include -#include #include "ambient-mode.h" #include "util.h" @@ -53,13 +52,13 @@ #include "core/common.h" #include "core/config-parser.h" #include "core/launch.h" +#include "apps/apps.h" #include "extcon/extcon.h" +#include "battery/power-supply.h" #include "power/power-handler.h" #include "dd-display.h" #include "display/display-dpms.h" -#include "battery/battery.h" -#define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" /** @@ -70,20 +69,28 @@ #define SET_BRIGHTNESS_IN_BOOTLOADER "/usr/bin/save_blenv SLP_LCD_BRIGHT" #define LOCK_SCREEN_INPUT_TIMEOUT 10000 #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 -#define DD_LCDOFF_INPUT_TIMEOUT 3000 -#define ALWAYS_ON_TIMEOUT 3600000 //3600000 = 1 hour +#define ALWAYS_ON_TIMEOUT 3600000 +#define LATE_LCD_TRANSIT 1 + +#define PID_MAX 6 #define GESTURE_STR "gesture" #define POWER_KEY_STR "powerkey" #define TOUCH_STR "touch" #define EVENT_STR "event" #define TIMEOUT_STR "timeout" +#define PROXI_STR "proximity" +#define PALM_STR "palm" #define UNKNOWN_STR "unknown" -extern void state_tv_init(); -extern void state_tv_deinit(); +#define METHOD_APP_STATUS "CheckAppStatus" + +#define PM_WAKEUP 0 +#define PM_SUSPEND 1 + extern void init_pm_internal(); extern int get_charging_status(int *val); +extern void init_save_userlock(void); unsigned int pm_status_flag; static int trans_condition; @@ -94,6 +101,7 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; int pm_cur_state; int pm_old_state; guint timeout_src_id; +int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; static int custom_holdkey_block = false; @@ -101,13 +109,21 @@ static int custom_change_pid = -1; static char *custom_change_name; static bool hallic_open = true; static guint lock_timeout_id; +static guint transit_timer; static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; +static long displayoff_time; static struct timeval lcdon_tv; static int lcd_paneloff_mode = false; static int stay_touchscreen_off = false; +dd_list *lcdon_ops; +/* + * The two variables(lcdon_broadcast, pmstate_suspend) must be set initial + * state because it should be sent from previous state at booting time. + */ static bool lcdon_broadcast = true; +static int pmstate_suspend = PM_SUSPEND; + static bool touch_blocked = false; -dd_list *lcdon_ops; /* default transition, action fuctions */ static int default_trans(int evt); @@ -118,6 +134,10 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); +static gboolean pmlock_normal_check(void *data); +static gboolean pmlock_dim_check(void *data); +static gboolean pmlock_off_check(void *data); + static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; @@ -142,6 +162,10 @@ static int trans_table[S_END][EVENT_END] = { { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */ }; +static GSourceFunc warning_cb[S_END] = { + NULL, pmlock_normal_check, pmlock_dim_check, pmlock_off_check, +}; + enum signal_type { SIGNAL_INVALID = 0, SIGNAL_PRE, @@ -149,6 +173,11 @@ enum signal_type { SIGNAL_MAX, }; +enum platform_control { + PLATFORM_DISPLAY_OFF, + PLATFORM_DISPLAY_ON, +}; + static const char *lcdon_sig_lookup[SIGNAL_MAX] = { [SIGNAL_PRE] = "LCDOn", [SIGNAL_POST] = "LCDOnCompleted", @@ -180,7 +209,7 @@ static const char *lcdoff_sig_lookup[SIGNAL_MAX] = { #define LONG_PRESS_INTERVAL 2 /* 2 seconds */ #define SAMPLING_INTERVAL 1 /* 1 sec */ #define BRIGHTNESS_CHANGE_STEP 10 -#define LCD_ALWAYS_ON 1 +#define LCD_ALWAYS_ON 0 #define ACCEL_SENSOR_ON 1 #define CONTINUOUS_SAMPLING 1 #define LCDOFF_TIMEOUT 500 /* milli second */ @@ -197,13 +226,18 @@ struct display_config display_conf = { .lcdoff_timeout = LCDOFF_TIMEOUT, .brightness_change_step = BRIGHTNESS_CHANGE_STEP, .lcd_always_on = LCD_ALWAYS_ON, - .framerate_app = {1, 0, 0, 0}, - .control_display = 1, + .dimming = 1, + .framerate_app = {0, 0, 0, 0}, + .control_display = 0, .powerkey_doublepress = 0, .accel_sensor_on = ACCEL_SENSOR_ON, .continuous_sampling = CONTINUOUS_SAMPLING, - .timeout_enable = false, + .timeout_enable = true, .input_support = true, + .lockcheck_timeout = 600, + .aod_enter_level = 40, + .aod_tsp = true, + .touch_wakeup = false, }; struct display_function_info display_info = { @@ -216,9 +250,11 @@ struct display_function_info display_info = { typedef struct _pm_lock_node { pid_t pid; guint timeout_id; + guint warning_id; time_t time; bool holdkey_block; bool background; + bool broadcast_warning; } PmLockNode; static dd_list *cond_head[S_END]; @@ -233,9 +269,9 @@ static void set_process_active(bool flag, pid_t pid) /* Send dbug to resourced */ ret = dbus_handle_emit_dbus_signal(NULL, RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - RESOURCED_METHOD_ACTIVE, - g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); + RESOURCED_INTERFACE_PROCESS, + RESOURCED_METHOD_ACTIVE, + g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); if (ret < 0) _E("Failed to send dbus signal to resourced."); } @@ -289,17 +325,64 @@ void change_proc_change_state(int (*func)(unsigned int cond, pid_t pid)) proc_change_state = func; } +static inline long clock_gettime_to_long(void) +{ + struct timespec now; + int ret; + + ret = clock_gettime(CLOCK_REALTIME, &now); + + if (ret < 0) { + _E("Failed to clock gettime!"); + return 0; + } + + return SEC_TO_MSEC(now.tv_sec) + NSEC_TO_MSEC(now.tv_nsec); +} + +static int display_brightness_changed(void *data) +{ + int brt, ret; + + brt = DATA_VALUE_INT(data); + + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "Brightness", + g_variant_new("(i)", brt)); + if (ret < 0) + _E("Failed to send dbus signal Brightness."); + + return 0; +} + +static int display_auto_brightness_sensing(void *data) +{ + if (!transit_timer) + return 0; + + g_source_remove(transit_timer); + transit_timer = 0; + + return 0; +} + static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) { const char *str; const char *signal; int ret; + long diff = 0; if (type <= SIGNAL_INVALID || type >= SIGNAL_MAX) { _E("Invalid signal type(%d).", type); return; } + if (type == SIGNAL_PRE && displayoff_time != 0) + diff = clock_gettime_to_long() - displayoff_time; + if (flags & LCD_ON_BY_GESTURE) str = GESTURE_STR; else if (flags & LCD_ON_BY_POWER_KEY) @@ -317,7 +400,7 @@ static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, - g_variant_new("(s)", str)); + g_variant_new("(si)", str, diff)); if (ret < 0) _E("Failed to send dbus signal(%s)", signal); } @@ -333,6 +416,9 @@ static void broadcast_lcd_off(enum signal_type type, enum device_flags flags) return; } + if (type == SIGNAL_PRE) + displayoff_time = clock_gettime_to_long(); + signal = lcdoff_sig_lookup[type]; if (flags & LCD_OFF_BY_POWER_KEY) @@ -371,9 +457,6 @@ static unsigned long get_lcd_on_flags(void) if (lcd_paneloff_mode) flags |= LCD_PANEL_OFF_MODE; - if (stay_touchscreen_off) - flags |= TOUCH_SCREEN_OFF_MODE; - if (ambient_get_condition() == true) { flags |= AMBIENT_MODE; flags |= LCD_PHASED_TRANSIT_MODE; @@ -387,6 +470,18 @@ bool touch_event_blocked(void) return touch_blocked; } +static gboolean late_transit_on(void *data) +{ + if (!transit_timer) + return G_SOURCE_REMOVE; + + g_source_remove(transit_timer); + transit_timer = 0; + + backlight_ops.transit_state(DPMS_ON); + return G_SOURCE_REMOVE; +} + void lcd_on_procedure(int state, enum device_flags flag) { dd_list *l = NULL; @@ -394,19 +489,29 @@ void lcd_on_procedure(int state, enum device_flags flag) unsigned long flags = get_lcd_on_flags(); flags |= flag; - /* send LCDOn dbus signal */ - if (!lcdon_broadcast) { - broadcast_lcd_on(SIGNAL_PRE, flags); - lcdon_broadcast = true; - } + /* + * Display on procedure + * step 1. broadcast lcd on signal with cause + * step 2. set brightness + * step 3. set pmstate of vconf + * step 4. display on operate + * - a. display on + * - b. TSP(touch screen) and touchkey enable + * step 5. broadcast lcd on complete siganl + * step 6. key backlight enable + */ + _I("[lcdstep] %lu", flags); if (flags & AMBIENT_MODE) { - if (ambient_get_state() == false && - backlight_ops.get_lcd_power() == DPMS_ON) + if (ambient_get_state() == false && backlight_ops.get_lcd_power() == DPMS_ON) return; ambient_set_state(false); } + /* send LCDOn dbus signal */ + if (!lcdon_broadcast) + broadcast_lcd_on(SIGNAL_PRE, flags); + if (!(flags & LCD_PHASED_TRANSIT_MODE)) { /* Update brightness level */ if (state == LCD_DIM) @@ -423,7 +528,13 @@ void lcd_on_procedure(int state, enum device_flags flag) DD_LIST_FOREACH(lcdon_ops, l, ops) ops->start(flags); + if (!lcdon_broadcast) { broadcast_lcd_on(SIGNAL_POST, flags); + if (flags & LCD_PHASED_TRANSIT_MODE) + transit_timer = g_timeout_add_seconds(LATE_LCD_TRANSIT, + late_transit_on, NULL); + lcdon_broadcast = true; + } if (CHECK_OPS(keyfilter_ops, backlight_enable)) keyfilter_ops->backlight_enable(true); @@ -431,7 +542,7 @@ void lcd_on_procedure(int state, enum device_flags flag) touch_blocked = false; } -static inline unsigned long get_lcd_off_flags(void) +static unsigned long get_lcd_off_flags(void) { unsigned long flags = NORMAL_MODE; @@ -440,10 +551,12 @@ static inline unsigned long get_lcd_off_flags(void) flags |= LCD_PHASED_TRANSIT_MODE; } + if (stay_touchscreen_off) + flags |= TOUCH_SCREEN_OFF_MODE; + return flags; } - inline void lcd_off_procedure(enum device_flags flag) { dd_list *l = NULL; @@ -451,6 +564,20 @@ inline void lcd_off_procedure(enum device_flags flag) unsigned long flags = get_lcd_off_flags(); flags |= flag; + /* + * Display off procedure + * step 0. enhance mode off using nofity (e.g mdnie, HBM, LBM) + * step 1. broadcast lcd off signal with cause + * step 2. set pmstate of vconf + * step 3. display off operate + * - a. display off + * - b. TSP(touch screen) and touchkey disable + * step 4. broadcast lcd off complete siganl + */ + _I("[lcdstep] %lu", flags); + + device_notify(DEVICE_NOTIFIER_LCD_OFF, NULL); + touch_blocked = true; if (flags & AMBIENT_MODE) { @@ -463,18 +590,23 @@ inline void lcd_off_procedure(enum device_flags flag) broadcast_lcd_off(SIGNAL_PRE, flags); lcdon_broadcast = false; } + set_setting_pmstate(S_LCDOFF); + if (CHECK_OPS(keyfilter_ops, backlight_enable)) keyfilter_ops->backlight_enable(false); - set_setting_pmstate(S_LCDOFF); + if (transit_timer) { + g_source_remove(transit_timer); + transit_timer = 0; + } + + if (flags & LCD_PHASED_TRANSIT_MODE) + backlight_ops.transit_state(DPMS_OFF); DD_LIST_FOREACH(lcdon_ops, l, ops) ops->stop(flags); if (flags & AMBIENT_MODE) - /* Do not broadcast the post signal here. - * The signal will be broadcasted - * after showing Ambient clock */ broadcast_lcd_off_late(flags); else broadcast_lcd_off(SIGNAL_POST, flags); @@ -482,20 +614,20 @@ inline void lcd_off_procedure(enum device_flags flag) void set_stay_touchscreen_off(int val) { - _D("stay touch screen off: %d", val); + _I("Stay touch screen off: %d", val); stay_touchscreen_off = val; - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - set_setting_pmstate(LCD_NORMAL); + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } void set_lcd_paneloff_mode(int val) { - _D("lcd paneloff mode: %d", val); + _I("Lcd paneloff mode: %d", val); lcd_paneloff_mode = val; - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - set_setting_pmstate(LCD_NORMAL); + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } int low_battery_state(int val) @@ -539,7 +671,7 @@ static void makeup_trans_condition(void) static PmLockNode *find_node(enum state_t s_index, pid_t pid) { dd_list *elem; - PmLockNode *t; + PmLockNode *t = NULL; DD_LIST_FOREACH(cond_head[s_index], elem, t) { if (t->pid == pid) @@ -552,21 +684,28 @@ static PmLockNode *find_node(enum state_t s_index, pid_t pid) static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, bool holdkey_block) { + guint warning_id = 0; PmLockNode *n; time_t now; n = (PmLockNode *) malloc(sizeof(PmLockNode)); if (n == NULL) { - _E("Failed to add cond. Not enough memory."); + _E("Not enough memory, add cond. fail"); return NULL; } + if (pid < INTERNAL_LOCK_BASE) + warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, + warning_cb[s_index], (void *)((intptr_t)pid)); + time(&now); n->pid = pid; n->timeout_id = timeout_id; + n->warning_id = warning_id; n->time = now; n->holdkey_block = holdkey_block; n->background = false; + n->broadcast_warning = true; DD_LIST_APPEND(cond_head[s_index], n); refresh_app_cond(); @@ -585,6 +724,11 @@ static int del_node(enum state_t s_index, PmLockNode *n) g_source_remove(n->timeout_id); n->timeout_id = 0; } + if (n->warning_id) { + g_source_remove(n->warning_id); + n->warning_id = 0; + } + free(n); refresh_app_cond(); return 0; @@ -592,6 +736,7 @@ static int del_node(enum state_t s_index, PmLockNode *n) static void print_node(int next) { + int ret; dd_list *elem; PmLockNode *n; char buf[30]; @@ -606,10 +751,20 @@ static void print_node(int next) diff = difftime(now, n->time); ctime_r(&n->time, buf); - if (diff > LOCK_TIME_WARNING) - _W("over=%.0f s pid=%5d locktime=%s", diff, n->pid, buf); - else - _I("pid=%5d locktime=%s", n->pid, buf); + if (diff > LOCK_TIME_WARNING) { + if (diff > LOCK_TIME_WARNING * 60 && n->pid < INTERNAL_LOCK_BASE && n->broadcast_warning) { + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "pmlock_over", + g_variant_new("(i)", n->pid)); + if (ret < 0) + _E("Failed to send dbus signal pmlock_over."); + n->broadcast_warning = false; + } + _W("Over(%.0f s) pid( %5d) lock time(%s)", diff, n->pid, buf); + } else + _I("Pid(%5d) lock time(%s)", n->pid, buf); } } @@ -642,7 +797,6 @@ void get_pname(pid_t pid, char *pname) static void del_state_cond(void *data, enum state_t state) { PmLockNode *tmp = NULL; - char pname[PATH_MAX]; pid_t pid; if (!data) @@ -650,18 +804,20 @@ static void del_state_cond(void *data, enum state_t state) /* A passed data is a pid_t type data, not a 64bit data. */ pid = (pid_t)((intptr_t)data); - _I("Delete process(%d)'s prohibit dim condition by timeout.", pid); + _I("delete prohibit dim condition by timeout (%d)", pid); + + if (pid == INTERNAL_LOCK_AMBIENT) + ambient_check_invalid_state(pid); tmp = find_node(state, pid); del_node(state, tmp); - get_pname(pid, pname); - set_unlock_time(pname, state); + set_unlock_time(pid, state); if (!timeout_src_id) states[pm_cur_state].trans(EVENT_TIMEOUT); if (state == S_LCDOFF) - set_process_active(FALSE, pid); + set_process_active(false, pid); } static gboolean del_normal_cond(void *data) @@ -682,23 +838,91 @@ static gboolean del_off_cond(void *data) return G_SOURCE_REMOVE; } -/* timeout handler */ -gboolean timeout_handler(void *data) +static void pmlock_check_cb(GVariant *var, void *user_data, GError *err) { - int run_timeout; + pid_t pid; + int ret, state; + char *app_id; - _I("Time out state %s.\n", states[pm_cur_state].name); - /* default setting */ - get_run_timeout(&run_timeout); + if (!var) + return; - /* for sdk - * if the run_timeout is zero, it regards AlwaysOn state + if (!dh_get_param_from_var(var, "(iis)", &pid, &state, &app_id)) { + _E("Failed to notify low: no message(%s)", g_variant_get_type_string(var)); + goto out; + } + + _W("%s(%d) was requested pmlock for a long time.", app_id, pid); + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "pmlock_expired", + g_variant_new("(i)", pid)); + if (ret < 0) + _E("Failed to send dbus pmlock_expired"); + +out: + g_variant_unref(var); +} + +/* + * Any process is possible many time lock, deviced can not know malicious + * or good process. so infinity or more then 1 min lock process, deviced + * will be checked it to resoured. And then, it will be asked quit or maintain to user. */ - if (pm_cur_state == S_NORMAL && (run_timeout == 0 || display_conf.lcd_always_on)) { - _D("'run_timeout' is always on."); - return G_SOURCE_CONTINUE; +static void pmlock_check(void *data, char *st) +{ + const char *arr[2]; + char chr_pid[PID_MAX]; + pid_t pid; + int ret; + + if (!data || !st) + return; + + if (!strncmp(st, "lcdoff", 4) && backlight_ops.get_lcd_power() == DPMS_ON) { + _D("Lcd state is PM_LCD_POWER_ON"); + return; } + pid = (pid_t)((intptr_t)data); + snprintf(chr_pid, sizeof(chr_pid), "%d", pid); + + arr[0] = chr_pid; + arr[1] = st; + + ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, + RESOURCED_PATH_PROCESS, + RESOURCED_INTERFACE_PROCESS, + METHOD_APP_STATUS, + "is", arr, pmlock_check_cb, -1, NULL); + if (ret < 0) + _E("Failed to call dbus method"); +} + +static gboolean pmlock_normal_check(void *data) +{ + pmlock_check(data, "normal"); + return G_SOURCE_CONTINUE; +} + +static gboolean pmlock_dim_check(void *data) +{ + pmlock_check(data, "lcddim"); + return G_SOURCE_CONTINUE; +} + +static gboolean pmlock_off_check(void *data) +{ + pmlock_check(data, "lcdoff"); + return G_SOURCE_CONTINUE; +} + +/* timeout handler */ +gboolean timeout_handler(void *data) +{ + _I("Time out state %s", states[pm_cur_state].name); + if (timeout_src_id) { g_source_remove(timeout_src_id); timeout_src_id = 0; @@ -713,7 +937,7 @@ void reset_timeout(int timeout) if (!display_conf.timeout_enable) return; - _I("Reset timeout(%d ms)", timeout); + _I("Reset timeout(%d ms).", timeout); if (timeout_src_id != 0) { g_source_remove(timeout_src_id); timeout_src_id = 0; @@ -754,7 +978,7 @@ static int get_lcd_timeout_from_settings(void) if (val > 0) states[i].timeout = val; - _I("state=%s timeout=%d ms", states[i].name, + _I("State(%s) timeout(%d) ms", states[i].name, states[i].timeout); } @@ -777,7 +1001,7 @@ static void update_display_time(void) if (custom_normal_timeout > 0) { states[S_NORMAL].timeout = custom_normal_timeout; states[S_LCDDIM].timeout = custom_dim_timeout; - _I("CUSTOM: Timeout(%d ms) and dim(%d ms) are set by normal.", + _I("CUSTOM : timeout is set by normal(%d ms), dim(%d ms)", custom_normal_timeout, custom_dim_timeout); return; } @@ -808,7 +1032,8 @@ static void update_display_time(void) get_dim_timeout(&val); states[S_LCDDIM].timeout = val; - _I("Normal: timeout(%d ms) and dim(%d ms) are set.", states[S_NORMAL].timeout, states[S_LCDDIM].timeout); + _I("Normal: NORMAL timeout is set by %d ms", states[S_NORMAL].timeout); + _I("Normal: DIM timeout is set by %d ms", states[S_LCDDIM].timeout); } static void update_display_locktime(int time) @@ -817,7 +1042,6 @@ static void update_display_locktime(int time) update_display_time(); } - void set_dim_state(bool on) { _I("Dim state is %d.", on); @@ -825,31 +1049,58 @@ void set_dim_state(bool on) states[pm_cur_state].trans(EVENT_INPUT); } +static void broadcast_pm_suspend(void) +{ + int ret; + + if (pmstate_suspend) + return; -void lcd_on_direct(enum device_flags flags) + _D("PM will be changed to sleep."); + + pmstate_suspend = PM_SUSPEND; + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "sleep", + NULL); + if (ret < 0) + _E("Failed to send dbus signal sleep."); +} + +static void broadcast_pm_wakeup(void) { - int ret, call_state; + int ret; + + if (!pmstate_suspend) + return; + + _D("PM is changed to wakeup."); + pmstate_suspend = PM_WAKEUP; + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "wakeup", + NULL); + if (ret < 0) + _E("Failed to send dbus signal wakeup."); + +} + +void lcd_on_direct(enum device_flags flags) +{ if (power_ops.get_power_lock_support() - && pm_cur_state == S_SLEEP) + && pm_cur_state == S_SLEEP) { + broadcast_pm_wakeup(); power_ops.power_lock(); + pm_cur_state = S_NORMAL; + } -#ifdef MICRO_DD - _D("Lcd is on directly."); + _D("lcd is on directly"); gettimeofday(&lcdon_tv, NULL); lcd_on_procedure(LCD_NORMAL, flags); - reset_timeout(DD_LCDOFF_INPUT_TIMEOUT); -#else - ret = vconf_get_int(VCONFKEY_CALL_STATE, &call_state); - if ((ret >= 0 && call_state != VCONFKEY_CALL_OFF) || - (__get_lock_screen_state() == VCONFKEY_IDLE_LOCK)) { - _D("LOCK state, lcd is on directly."); - lcd_on_procedure(LCD_NORMAL, flags); - } else if (ret < 0) - _E("Failed to get vconf value for call state: %d", vconf_get_ext_errno()); - - reset_timeout(display_conf.lcdoff_timeout); -#endif + update_display_locktime(LOCK_SCREEN_INPUT_TIMEOUT); } @@ -861,6 +1112,41 @@ static inline bool check_lcd_is_on(void) return true; } +static int check_lock_condition(enum state_t state) +{ + dd_list *elem; + PmLockNode *t = NULL; + int ret = false; + pid_t owner = getpid(); + + _D("check holdkey block : state of %s", states[state].name); + + DD_LIST_FOREACH(cond_head[state], elem, t) { + if (t->pid != owner && t->background == false) { + ret = true; + _I("state change was blocked by pid(%d)!", t->pid); + break; + } + } + + return ret; +} + +static gboolean timer_refresh_cb(gpointer data) +{ + struct state *st; + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_NORMAL; + st = &states[pm_cur_state]; + + if (st->action) + st->action(st->timeout); + + return 0; +} + int custom_lcdon(int timeout) { struct state *st; @@ -884,9 +1170,157 @@ int custom_lcdon(int timeout) if (st->action) st->action(st->timeout); + g_idle_add(timer_refresh_cb, NULL); + return 0; } +int custom_lcdoff(enum device_flags flag) +{ + struct state *st; + + check_processes(S_NORMAL); + check_processes(S_LCDDIM); + + /* check holdkey block flag in lock node */ + if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + /* + * When another proccess is normal lock, device is received call then, + * call app can be changed to lcd state by proximity. + * If proximity is near then normal lock will be unlocked. + */ + if (flag & LCD_OFF_BY_PROXIMITY) { + _I("custom lcd off by proximity, delete normal lock"); + delete_condition(S_NORMAL); + } else { + _I("skip custom lcd off"); + return -ECANCELED; + } + } + + _I("custom lcd off by flag(%d)", flag); + if (backlight_ops.get_lcd_power() == DPMS_ON) + lcd_off_procedure(flag); + + if (set_custom_lcdon_timeout(0) == true) + update_display_time(); + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_LCDOFF; + st = &states[pm_cur_state]; + + /* enter action */ + if (st->action) + st->action(st->timeout); + + return 0; +} + +static int display_platform_on(char *reason, int timeout) +{ + struct state *st; + int flag; + int str_len; + + str_len = strlen(reason); + + if (!strncmp(reason, GESTURE_STR, str_len)) + flag = LCD_ON_BY_GESTURE; + else if (!strncmp(reason, EVENT_STR, str_len)) + flag = LCD_ON_BY_EVENT; + else { + _E("Reason is unkown(%s)", reason); + return -EINVAL; + } + + if (timeout <= 0) { + _E("Cannot setting timeout %d", timeout); + return -EINVAL; + } + + if (check_lcd_is_on() == false) + lcd_on_direct(flag); + + _I("platform lcd on by %s (%d ms)", reason, timeout); + if (set_custom_lcdon_timeout(timeout) == true) + update_display_time(); + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_NORMAL; + st = &states[pm_cur_state]; + + /* enter action */ + if (st->action) + st->action(st->timeout); + + return 0; +} + +static int display_platform_off(char *reason) +{ + struct state *st; + int flag; + int str_len; + + str_len = strlen(reason); + + if (!strncmp(reason, GESTURE_STR, str_len)) { + check_processes(S_NORMAL); + check_processes(S_LCDDIM); + + /* check holdkey block flag in lock node */ + if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + _I("skip platform lcd off by gesture"); + return -ECANCELED; + } + flag = LCD_OFF_BY_GESTURE; + } else if (!strncmp(reason, PALM_STR, str_len)) { + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); + + flag = LCD_OFF_BY_PALM; + } else { + _E("Reason is unkown(%s)", reason); + return -EINVAL; + } + + _I("platform lcd off by %s", reason); + if (backlight_ops.get_lcd_power() == DPMS_ON) + lcd_off_procedure(flag); + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_LCDOFF; + st = &states[pm_cur_state]; + + /* enter action */ + if (st->action) + st->action(st->timeout); + + return 0; +} + +int display_platform_control(int type, char *reason, int timeout) +{ + int ret; + + switch (type) { + case PLATFORM_DISPLAY_ON: + ret = display_platform_on(reason, timeout); + break; + case PLATFORM_DISPLAY_OFF: + ret = display_platform_off(reason); + break; + default: + _E("Unkown type(%d)", type); + ret = -EINVAL; + } + + return ret; +} + static void default_proc_change_state_action(enum state_t next, int timeout) { struct state *st; @@ -922,7 +1356,7 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) default_proc_change_state_action(next, -1); break; case S_LCDOFF: - if (backlight_ops.get_lcd_power() != DPMS_OFF) + if (backlight_ops.get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_EVENT); if (set_custom_lcdon_timeout(0)) update_display_time(); @@ -933,7 +1367,14 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) /* at first LCD_OFF and then goto sleep */ /* state transition */ default_proc_change_state_action(S_LCDOFF, TIMEOUT_NONE); + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); delete_condition(S_LCDOFF); + if (lcdon_broadcast) { + _I("broadcast lcd off signal at non-lcd device"); + broadcast_lcd_off(SIGNAL_PRE, 0); + broadcast_lcd_off(SIGNAL_POST, 0); + } default_proc_change_state_action(S_SLEEP, TIMEOUT_NONE); break; @@ -968,15 +1409,18 @@ static void proc_condition_lock(PMMsg *data) pid_t pid = data->pid; enum state_t state; int holdkey_block; + bool value = true; + unsigned int flags; state = GET_COND_STATE(data->cond); - if (!state) + if (state == S_START) return; + flags = GET_COND_FLAG(data->cond); get_pname(pid, pname); - if (state == S_LCDOFF && - pm_cur_state == S_SLEEP) + if (state == S_LCDOFF && pm_cur_state == S_SLEEP && + power_ops.get_power_lock() == POWER_UNLOCK) proc_change_state(data->cond, INTERNAL_LOCK_PM); if (data->timeout > 0) { @@ -1002,14 +1446,15 @@ static void proc_condition_lock(PMMsg *data) } if (state == S_LCDOFF) - set_process_active(TRUE, pid); + set_process_active(true, pid); + _I("[%s] locked by %5d with %u ms", states[state].name, pid, data->timeout); /* for debug */ - _SD("[%s] Locked by pid=%d process=%s holdkeyblock=%d\n", - states[state].name, pid, pname, holdkey_block); - set_lock_time(pname, state); + _SD("be requested LOCK info pname(%s), holdkeyblock(%d) flags(%d)", + pname, holdkey_block, flags); + set_lock_time(pid, pname, state); - device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)true); + device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value); } static void proc_condition_unlock(PMMsg *data) @@ -1018,27 +1463,28 @@ static void proc_condition_unlock(PMMsg *data) enum state_t state; PmLockNode *tmp; char pname[PATH_MAX]; + bool value = false; + unsigned int flags; state = GET_COND_STATE(data->cond); if (!state) return; + flags = GET_COND_FLAG(data->cond); get_pname(pid, pname); tmp = find_node(state, pid); del_node(state, tmp); if (state == S_LCDOFF) - set_process_active(FALSE, pid); + set_process_active(false, pid); - if (ambient_get_state()) - ambient_check_invalid_state(pid); - - _SD("[%s] Unlocked by pid=%d process=%s\n", - states[state].name, pid, pname); - set_unlock_time(pname, state); + _I("[%s] unlocked by %5d", states[state].name, pid); + /* for debug */ + _SD("be requested UNLOCK info pname(%s) flag(%d)", pname, flags); + set_unlock_time(pid, state); - device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)false); + device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value); } static int proc_condition(PMMsg *data) @@ -1057,15 +1503,11 @@ static int proc_condition(PMMsg *data) flags = GET_COND_FLAG(data->cond); if (flags == 0) { /* guard time for suspend */ - if (pm_cur_state == S_LCDOFF) { + if (pm_cur_state == S_LCDOFF) reset_timeout(states[S_LCDOFF].timeout); - _I("Margin timeout(%d ms)", states[S_LCDOFF].timeout); - } } else { - if (flags & PM_FLAG_RESET_TIMER) { + if (flags & PM_FLAG_RESET_TIMER) reset_timeout(states[pm_cur_state].timeout); - _I("Reset timeout(%d ms)", states[pm_cur_state].timeout); - } } if (!timeout_src_id) @@ -1078,13 +1520,13 @@ static int proc_condition(PMMsg *data) int check_processes(enum state_t prohibit_state) { dd_list *elem, *next; - PmLockNode *t; + PmLockNode *t = NULL; int ret = 0; DD_LIST_FOREACH_SAFE(cond_head[prohibit_state], elem, next, t) { if (t->pid < INTERNAL_LOCK_BASE && kill(t->pid, 0) == -1) { - _E("Process(%d) does not exist, delete the REQ" - " - prohibit state=%d.", + _E("%d process does not exist, delete the REQ" + " - prohibit state %d ", t->pid, prohibit_state); if (t->pid == custom_change_pid) { get_lcd_timeout_from_settings(); @@ -1092,6 +1534,7 @@ int check_processes(enum state_t prohibit_state) custom_change_pid = -1; } ret = 1; + set_unlock_time(t->pid, prohibit_state); del_node(prohibit_state, t); } } @@ -1102,7 +1545,7 @@ int check_processes(enum state_t prohibit_state) int check_holdkey_block(enum state_t state) { dd_list *elem; - PmLockNode *t; + PmLockNode *t = NULL; int ret = 0; _I("Check holdkey block: state of %s", states[state].name); @@ -1127,11 +1570,9 @@ int check_holdkey_block(enum state_t state) int delete_condition(enum state_t state) { dd_list *elem, *next; - PmLockNode *t; - pid_t pid; - char pname[PATH_MAX]; + PmLockNode *t = NULL; - _I("Delete condition: state of %s", states[state].name); + _I("delete condition : state of %s", states[state].name); if (!cond_head[state]) return 0; @@ -1141,13 +1582,11 @@ int delete_condition(enum state_t state) g_source_remove(t->timeout_id); t->timeout_id = 0; } - pid = t->pid; if (state == S_LCDOFF) - set_process_active(FALSE, pid); - _I("Delete node of pid(%d).", pid); + set_process_active(false, t->pid); + _I("delete node of pid(%d)", t->pid); + set_unlock_time(t->pid, state); del_node(state, t); - get_pname(pid, pname); - set_unlock_time(pname, state-1); } DD_LIST_FREE_LIST(cond_head[state]); @@ -1189,8 +1628,9 @@ static pm_history pm_history_log[MAX_LOG_COUNT] = {{0, }, }; static int history_count = 0; static const char history_string[PM_LOG_MAX][15] = { - "PRESS", "LONG PRESS", "RELEASE", "LCD ON", "LCD ON FAIL", - "LCD DIM", "LCD DIM FAIL", "LCD OFF", "LCD OFF FAIL", "SLEEP"}; + "PRESS", "LONG PRESS", "RELEASE", "LCD ON", "LCD ON COMPL", "LCD ON FAIL", + "LCD DIM", "LCD DIM FAIL", "LCD OFF", "LCD OFF COMPL", "LCD OFF FAIL", + "LCD FAIL", "SLEEP"}; void pm_history_init() { @@ -1243,7 +1683,7 @@ void pm_history_print(int fd, int count) time_buf); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); } } #endif @@ -1267,13 +1707,13 @@ void print_info(int fd) "===========================\n"); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Timeout Info: Run[%dms] Dim[%dms] Off[%dms]\n", states[S_NORMAL].timeout, states[S_LCDDIM].timeout, states[S_LCDOFF].timeout); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Tran. Locked : %s %s %s\n", (trans_condition & MASK_NORMAL) ? states[S_NORMAL].name : "-", @@ -1281,18 +1721,18 @@ void print_info(int fd) (trans_condition & MASK_OFF) ? states[S_LCDOFF].name : "-"); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Current State: %s\n", states[pm_cur_state].name); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Current Lock Conditions: \n"); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); for (s_index = S_NORMAL; s_index < S_END; s_index++) { DD_LIST_FOREACH(cond_head[s_index], elem, t) { @@ -1303,7 +1743,7 @@ void print_info(int fd) i++, states[s_index].name, t->pid, pname, time_buf); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); } } @@ -1314,37 +1754,39 @@ void print_info(int fd) #endif } -void save_display_log(void) +void save_display_log(char *path) { int fd, ret; char buf[255]; time_t now_time; char time_buf[30]; - _D("Internal state is saved."); + _D("internal state is saved!"); time(&now_time); ctime_r(&now_time, time_buf); - fd = open(PM_STATE_LOG_FILE, O_CREAT | O_TRUNC | O_WRONLY, 0644); + fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0644); if (fd != -1) { snprintf(buf, sizeof(buf), "\npm_state_log now-time : %d(s) %s\n\n", (int)now_time, time_buf); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("write() failed (%d)", errno); snprintf(buf, sizeof(buf), "pm_status_flag: %x\n", pm_status_flag); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("write() failed (%d)", errno); - snprintf(buf, sizeof(buf), "screen lock status : %d\n", - __get_lock_screen_state()); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed: %d", errno); + if (disp_plgn.get_lock_screen_state ) { + snprintf(buf, sizeof(buf), "screen lock status : %d\n", + disp_plgn.get_lock_screen_state()); + ret = write(fd, buf, strlen(buf)); + if (ret < 0) + _E("write() failed (%d)", errno); + } print_info(fd); close(fd); } @@ -1361,7 +1803,9 @@ void save_display_log(void) */ static void sig_hup(int signo) { - save_display_log(); + _I("received sig hub %d", signo); + + pm_save_logdump(); } int check_lcdoff_direct(void) @@ -1375,6 +1819,9 @@ int check_lcdoff_direct(void) if (pm_cur_state != S_LCDDIM) return false; + if (!display_conf.dimming) + return true; + lock = __get_lock_screen_state(); if (lock != VCONFKEY_IDLE_LOCK && hallic_open) return false; @@ -1389,7 +1836,7 @@ int check_lcdoff_direct(void) else if (ret < 0) _E("Failed to get vconf value for cradle status: %d", vconf_get_ext_errno()); - _D("Goto LCDOFF direct(lock=%d hdmi=%d cradle=%d).", lock, hdmi_state, cradle); + _D("Goto LCDOFF direct: lock(%d) hdmi(%d) cradle(%d).", lock, hdmi_state, cradle); return true; } @@ -1483,22 +1930,10 @@ static inline void stop_lock_timer(void) static void check_lock_screen(void) { - int lock_setting, lock_state, app_state, ret; + int lock_state, ret; stop_lock_timer(); - ret = vconf_get_int(VCONFKEY_CALL_STATE, &app_state); - if (ret >= 0 && app_state != VCONFKEY_CALL_OFF) - goto lcd_on; - else if (ret < 0) - _E("Failed to get vconf value for call state: %d", vconf_get_ext_errno()); - - /* check setting of lock screen is enabled. */ - ret = vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, - &lock_setting); - if (ret < 0) - _E("Failed to get vconf value for screen lock type: %d", vconf_get_ext_errno()); - /* check state of lock */ ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); if (ret < 0 || lock_state == VCONFKEY_IDLE_LOCK) { @@ -1553,10 +1988,12 @@ static int default_action(int timeout) } if (pm_cur_state != pm_old_state && pm_cur_state != S_SLEEP) { - if (power_ops.get_power_lock_support()) + if (power_ops.get_power_lock_support()) { + broadcast_pm_wakeup(); power_ops.power_lock(); + } set_setting_pmstate(pm_cur_state); - device_notify(DEVICE_NOTIFIER_LCD, &pm_cur_state); + device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); } if (pm_old_state == S_NORMAL && pm_cur_state != S_NORMAL) { @@ -1596,11 +2033,11 @@ static int default_action(int timeout) if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) { stop_lock_timer(); /* lcd off state : turn off the backlight */ - if (backlight_ops.get_lcd_power() != DPMS_OFF) + if (backlight_ops.get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); } - if (backlight_ops.get_lcd_power() != DPMS_OFF + if (backlight_ops.get_lcd_power() == DPMS_ON || lcd_paneloff_mode) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); break; @@ -1609,7 +2046,7 @@ static int default_action(int timeout) if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) stop_lock_timer(); - if (backlight_ops.get_lcd_power() != DPMS_OFF) + if (backlight_ops.get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); if (!power_ops.get_power_lock_support()) { @@ -1636,6 +2073,7 @@ go_suspend: #ifdef ENABLE_PM_LOG pm_history_save(PM_LOG_SLEEP, pm_cur_state); #endif + broadcast_pm_suspend(); if (power_ops.get_power_lock_support()) { if (power_ops.enable_autosleep) power_ops.enable_autosleep(); @@ -1643,24 +2081,9 @@ go_suspend: if (power_ops.power_unlock() < 0) _E("Power unlock state error."); } else { - dd_list *elem, *elem_n; - const struct device_ops *dev; - /* Devices Suspend */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->suspend) - dev->suspend(); - } - power_ops.suspend(); - - /* Devices Resume */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->resume) - dev->resume(); - } - - _I("System wakeup."); - disp_plgn.system_wakeup_flag = true; + _I("system wakeup!!"); + system_wakeup_flag = true; /* Resume !! */ if (power_ops.check_wakeup_src() == EVENT_DEVICE) /* system waked up by devices */ @@ -1741,7 +2164,7 @@ static int poll_callback(int condition, PMMsg *data) if (condition == INPUT_POLL_EVENT) { if (pm_cur_state == S_LCDOFF || pm_cur_state == S_SLEEP) - _I("Power key input."); + _I("Input event signal at Display Off"); time(&now); if (last_t != now || pm_cur_state == S_LCDOFF || @@ -1802,11 +2225,13 @@ static int update_setting(int key_idx, int val) } pm_status_flag |= CHRGR_FLAG; } else { - int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; + int bat_state; ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state); - if (ret < 0) + if (ret < 0) { + bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); + } if (low_battery_state(bat_state)) { power_saving_func(true); pm_status_flag |= LOWBT_FLAG; @@ -1879,9 +2304,9 @@ static void check_seed_status(void) { int ret = -1; int tmp = 0; - int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; + int bat_state; int brt = 0; - int lock_state = -1; + int lock_state; /* Charging check */ if ((get_charging_status(&tmp) == 0) && (tmp > 0)) @@ -1900,10 +2325,13 @@ static void check_seed_status(void) } _I("Set brightness(%d) from setting app.", tmp); backlight_ops.set_default_brt(tmp); + backlight_ops.set_brightness(tmp); ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state); - if (ret < 0) + if (ret < 0) { + bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); + } if (low_battery_state(bat_state)) { if (!(pm_status_flag & CHRGR_FLAG)) { power_saving_func(true); @@ -1913,9 +2341,10 @@ static void check_seed_status(void) /* lock screen check */ ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret < 0) + if (ret < 0) { + lock_state = -1; _E("Failed to get vconf value for idle lock state: %d", vconf_get_ext_errno()); - + } set_lock_screen_state(lock_state); if (lock_state == VCONFKEY_IDLE_LOCK) { states[S_NORMAL].timeout = lock_screen_timeout; @@ -2045,36 +2474,20 @@ void reset_lcd_timeout(GDBusConnection *conn, static int booting_done(void *data) { - static int done; - - if (!data) - return done; + static bool done = false; + if (data != NULL) { done = *(int*)data; - if (!done) - return done; - - _I("Booting done. Release display and power lock."); - if (disp_plgn.pm_unlock_internal) { - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, PM_SLEEP_MARGIN); + if (done) + return 0; + _I("booting done, unlock LCD_OFF"); + if (disp_plgn.pm_unlock_internal) { + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, PM_SLEEP_MARGIN); + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); + } } - return done; -} - -int device_poweroff(void *data) -{ - static int off; - - if (!data) - return off; - - off = *(int *)data; - if (off) - _I("Poweroff"); - - return off; + return 0; } static int process_background(void *data) @@ -2087,7 +2500,7 @@ static int process_background(void *data) node = find_node(S_NORMAL, pid); if (node) { node->background = true; - _I("Process(%d) is background, then PM will be unlocked LCD_NORMAL.", pid); + _I("%d pid is background, then PM will be unlocked LCD_NORMAL", pid); } return 0; @@ -2103,9 +2516,29 @@ static int process_foreground(void *data) node = find_node(S_NORMAL, pid); if (node) { node->background = false; - _I("Process(%d) is foreground, then PM will be maintained locked LCD_NORMAL.", pid); + _I("Process(%d) is background, then PM will be unlocked LCD_NORMAL.", pid); + } + + return 0; +} + +static int battery_health_changed(void *data) +{ + int health = DATA_VALUE_INT(data); + + _I("battery health change %d", health); + + if (health == HEALTH_GOOD) { + pm_status_flag &= ~BATTERY_FLAG; + pm_status_flag &= ~DIMSTAY_FLAG; + } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) { + pm_status_flag |= BATTERY_FLAG; + pm_status_flag |= DIMSTAY_FLAG; } + if (backlight_ops.get_lcd_power() == DPMS_ON) + backlight_ops.update(); + return 0; } @@ -2123,49 +2556,58 @@ static int display_load_config(struct parse_result *result, void *user_data) if (MATCH(result->name, "LockScreenWaitingTime")) { SET_CONF(c->lock_wait_time, atof(result->value)); - _D("'lock wait time' is %.3f.", c->lock_wait_time); + _D("lock wait time is %.3f", c->lock_wait_time); } else if (MATCH(result->name, "LongPressInterval")) { SET_CONF(c->longpress_interval, atof(result->value)); - _D("'long press interval' is %.3f.", c->longpress_interval); + _D("long press interval is %.3f", c->longpress_interval); } else if (MATCH(result->name, "LightSensorSamplingInterval")) { SET_CONF(c->lightsensor_interval, atof(result->value)); - _D("'lightsensor interval' is %.3f.", c->lightsensor_interval); + _D("lightsensor interval is %.3f", c->lightsensor_interval); } else if (MATCH(result->name, "LCDOffTimeout")) { SET_CONF(c->lcdoff_timeout, atoi(result->value)); - _D("'lcdoff timeout' is %d ms.", c->lcdoff_timeout); + _D("lcdoff timeout is %d ms", c->lcdoff_timeout); } else if (MATCH(result->name, "BrightnessChangeStep")) { SET_CONF(c->brightness_change_step, atoi(result->value)); - _D("'brightness change step' is %d.", c->brightness_change_step); + _D("brightness change step is %d", c->brightness_change_step); } else if (MATCH(result->name, "LCDAlwaysOn")) { c->lcd_always_on = (MATCH(result->value, "yes") ? 1 : 0); - _D("'LCD always on' is %d.", c->lcd_always_on); + _D("LCD always on is %d", c->lcd_always_on); + } else if (MATCH(result->name, "Dimming")) { + c->dimming = (MATCH(result->value, "yes") ? 1 : 0); + _D("Dimming is %d", c->dimming); } else if (MATCH(result->name, "ChangedFrameRateAllowed")) { if (strstr(result->value, "setting")) { c->framerate_app[REFRESH_SETTING] = 1; - _D("'framerate app' is setting"); + _D("framerate app is Setting"); } if (strstr(result->value, "all")) { memset(c->framerate_app, 1, sizeof(c->framerate_app)); - _D("'framerate app' is all"); + _D("framerate app is All"); } } else if (MATCH(result->name, "ControlDisplay")) { c->control_display = (MATCH(result->value, "yes") ? 1 : 0); - _D("'ControlDisplay' is %d.", c->control_display); + _D("ControlDisplay is %d", c->control_display); } else if (MATCH(result->name, "PowerKeyDoublePressSupport")) { c->powerkey_doublepress = (MATCH(result->value, "yes") ? 1 : 0); - _D("'PowerKeyDoublePressSupport' is %d.", c->powerkey_doublepress); + _D("PowerKeyDoublePressSupport is %d", c->powerkey_doublepress); } else if (MATCH(result->name, "AccelSensorOn")) { c->accel_sensor_on = (MATCH(result->value, "yes") ? 1 : 0); - _D("'AccelSensorOn' is %d.", c->accel_sensor_on); + _D("AccelSensorOn is %d", c->accel_sensor_on); } else if (MATCH(result->name, "ContinuousSampling")) { c->continuous_sampling = (MATCH(result->value, "yes") ? 1 : 0); - _D("'ContinuousSampling' is %d.", c->continuous_sampling); + _D("ContinuousSampling is %d", c->continuous_sampling); } else if (MATCH(result->name, "TimeoutEnable")) { c->timeout_enable = (MATCH(result->value, "yes") ? true : false); - _D("'Timeout' is %s.", c->timeout_enable ? "enalbed" : "disabled"); + _D("Timeout is %s", c->timeout_enable ? "enalbed" : "disabled"); } else if (MATCH(result->name, "InputSupport")) { c->input_support = (MATCH(result->value, "yes") ? true : false); - _D("'Input' is %s.", c->input_support ? "supported" : "NOT supported"); + _D("Input is %s", c->input_support ? "supported" : "NOT supported"); + } else if (MATCH(result->name, "LockCheckTimeout")) { + SET_CONF(c->lockcheck_timeout, atoi(result->value)); + _D("LockCheckTimeout is %d", c->lockcheck_timeout); + } else if (MATCH(result->name, "AODTSP")) { + c->aod_tsp = (MATCH(result->value, "yes") ? true : false); + _D("TSP control at is %d at aod", c->aod_tsp); } return 0; @@ -2228,9 +2670,58 @@ static int display_probe(void *data) return 0; } +static int input_init_handler(void) +{ + if (!display_conf.input_support) + return 0; + + g_idle_add(init_input, NULL); + + return 0; +} + +static void esd_action(void) +{ + const struct device_ops *touchscreen_ops = NULL; + + _I("ESD on"); + + touchscreen_ops = find_device("touchscreen"); + + if (!check_default(touchscreen_ops)) + touchscreen_ops->stop(NORMAL_MODE); + backlight_ops.off(NORMAL_MODE); + backlight_ops.on(NORMAL_MODE); + if (!check_default(touchscreen_ops)) + touchscreen_ops->start(NORMAL_MODE); +} + +static void lcd_uevent_changed(struct udev_device *dev) +{ + const char *devpath; + const char *action; + + devpath = udev_device_get_devpath(dev); + if (!devpath) + return; + + if (!fnmatch(LCD_ESD_PATH, devpath, 0)) { + action = udev_device_get_action(dev); + if (!strcmp(action, UDEV_CHANGE)) + esd_action(); + } +} + +static const struct uevent_handler lcd_uevent_ops = { + .subsystem = LCD_EVENT_SUBSYSTEM, + .uevent_func = lcd_uevent_changed, + .data = NULL, +}; + static void display_init(void *data) { int ret, i; + unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); int timeout = 0; bool wm_ready; @@ -2246,10 +2737,16 @@ static void display_init(void *data) _W("Failed to load '%s', use default value: %d", DISPLAY_CONF_FILE, ret); + register_kernel_uevent_control(&lcd_uevent_ops); + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); register_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); register_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); - register_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); + register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); + register_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); + register_notifier(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, display_auto_brightness_sensing); + + init_save_userlock(); for (i = INIT_SETTING; i < INIT_END; i++) { switch (i) { @@ -2259,15 +2756,14 @@ static void display_init(void *data) case INIT_INTERFACE: if (display_conf.timeout_enable) get_lcd_timeout_from_settings(); - ret = init_sysfs(); + ret = init_sysfs(flags); break; case INIT_POLL: - _I("Input init."); + _I("input init"); pm_callback = poll_callback; - if (display_conf.input_support) - ret = init_input(); - else - ret = 0; + ret = input_init_handler(); + + pm_lock_detector_init(); break; case INIT_DBUS: _I("Dbus init."); @@ -2288,6 +2784,13 @@ static void display_init(void *data) init_lcd_operation(); check_seed_status(); + /* In smd test, TSP should be turned off if display panel is not existed. */ + if (backlight_ops.get_lcd_power() == -ENOENT) { + _I("Display panel is not existed."); + lcd_direct_control(DPMS_OFF, NORMAL_MODE); + exit_lcd_operation(); + } + /* wm_ready needs to be checked * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ @@ -2302,49 +2805,47 @@ static void display_init(void *data) trans_table[S_NORMAL][EVENT_TIMEOUT] = S_NORMAL; } - _I("Start Power managing without noti."); - if (power_ops.get_power_lock_support()) - power_ops.power_lock(); - - pm_cur_state = S_NORMAL; - set_setting_pmstate(pm_cur_state); - - if (display_conf.timeout_enable) { - timeout = states[S_NORMAL].timeout; - /* check minimun lcd on time */ - if (timeout < SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT)) - timeout = SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT); - - reset_timeout(timeout); - } + if (flags & WITHOUT_STARTNOTI) { /* start without noti */ + _I("Start Power managing without noti"); + if (power_ops.get_power_lock_support()) { + broadcast_pm_wakeup(); + power_ops.power_lock(); + } + pm_cur_state = S_NORMAL; + vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + + status = DEVICE_OPS_STATUS_START; + if (display_conf.timeout_enable) { + timeout = states[S_NORMAL].timeout; + /* check minimun lcd on time */ + if (timeout < SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT)) + timeout = SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT); + + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, + STAY_CUR_STATE, timeout); + } - status = DEVICE_OPS_STATUS_START; - /* - * Lock lcd off until booting is done. - * deviced guarantees all booting script is executing. - * Last script of booting unlocks this suspend blocking state. - */ - if (disp_plgn.pm_lock_internal) { - disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, - STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); - disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, - STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); + /* + * Lock lcd off until booting is done. + * deviced guarantees all booting script is executing. + * Last script of booting unlocks this suspend blocking state. + */ + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, + STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); } if (display_conf.input_support) if (CHECK_OPS(keyfilter_ops, init)) keyfilter_ops->init(); } - - state_tv_init(); } static void display_exit(void *data) { int i = INIT_END; - state_tv_deinit(); - status = DEVICE_OPS_STATUS_STOP; /* Set current state to S_NORMAL */ @@ -2356,6 +2857,8 @@ static void display_exit(void *data) if (CHECK_OPS(keyfilter_ops, exit)) keyfilter_ops->exit(); + unregister_kernel_uevent_control(&lcd_uevent_ops); + display_ops_exit(NULL); for (i = i - 1; i >= INIT_SETTING; i--) { @@ -2370,7 +2873,8 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); unregister_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); unregister_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); - unregister_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); + unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); + unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); exit_input(); break; @@ -2396,6 +2900,7 @@ static int display_start(enum device_flags flags) else /* normal lcd on */ backlight_ops.on(flags); + return 0; } @@ -2417,7 +2922,7 @@ static int display_start(enum device_flags flags) static int display_stop(enum device_flags flags) { /* NORMAL MODE */ - if (flags & NORMAL_MODE) { + if (flags & NORMAL_MODE || flags & FORCE_OFF_MODE) { backlight_ops.off(flags); return 0; } @@ -2441,7 +2946,7 @@ static int display_status(void) static const struct device_ops display_device_ops = { .priority = DEVICE_PRIORITY_HIGH, - .name = "display", + DECLARE_NAME_LEN("display"), .probe = display_probe, .init = display_init, .exit = display_exit, diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 01b98ac..37a86cb 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -29,19 +29,21 @@ #include #include #include -#include +#include #include "ambient-mode.h" #include "core/log.h" #include "core/devices.h" -#include "core/list.h" #include "core/common.h" -#include "display/display-dpms.h" +#include "core/device-notifier.h" #include "util.h" #include "device-interface.h" #include "vconf.h" #include "core.h" #include "device-node.h" +#include "display/display-dpms.h" + +#define SET_SUSPEND_TIME 0.5 #define TOUCH_ON 1 #define TOUCH_OFF 0 @@ -49,7 +51,8 @@ #define LCD_PHASED_MIN_BRIGHTNESS 1 #define LCD_PHASED_MAX_BRIGHTNESS 100 #define LCD_PHASED_CHANGE_STEP 5 -#define LCD_PHASED_DELAY 35000 /* microsecond */ +#define LCD_PHASED_DELAY 10000 /* microsecond */ +#define DUMP_MODE_WAITING_TIME 600000 /* microsecond */ #define POWER_AUTOSLEEP_PATH "/sys/power/autosleep" #define POWER_LOCK_PATH "/sys/power/wake_lock" @@ -57,24 +60,57 @@ #define POWER_WAKEUP_PATH "/sys/power/wakeup_count" #define POWER_STATE_PATH "/sys/power/state" -enum { - POWER_UNLOCK = 0, - POWER_LOCK, -}; +#define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" + +#define GESTURE_STR "gesture" +#define POWERKEY_STR "powerkey" +#define EVENT_STR "event" +#define TOUCH_STR "touch" +#define TIMEOUT_STR "timeout" +#define PROXIMITY_STR "proximity" +#define PALM_STR "palm" +#define UNKNOWN_STR "unknown" + +#define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" struct _backlight_ops backlight_ops; struct _power_ops power_ops; +static int mainlock_status = POWER_UNLOCK; static bool custom_status; static int custom_brightness; static int force_brightness; static int default_brightness; - +static int vital_support = -2; +static int vital_service; +static bool vital_sleep; +static int dpms_running_state = DPMS_SETTING_DONE; static struct display_device *display_dev; +static guint release_timer; -static int bl_onoff(int on) +struct display_device *display_dev_get(void) +{ + return display_dev; +} + +void dpms_set_running_state(int val) +{ + dpms_running_state = val; +} + +static int bl_onoff(int on, enum device_flags flags) { dpms_set_state(on); + +#ifdef ENABLE_PM_LOG + if (on == DPMS_ON) + pm_history_save(PM_LOG_LCD_ON_COMPLETE, pm_cur_state); + else if (on == DPMS_OFF || on == DPMS_FORCE_OFF) + pm_history_save(PM_LOG_LCD_OFF_COMPLETE, pm_cur_state); + else + pm_history_save(PM_LOG_LCD_CONTROL_FAIL, on); +#endif + return 0; } @@ -85,12 +121,6 @@ static int bl_brt(int brightness, int delay) if (delay > 0) usleep(delay); - if (force_brightness > 0) { - _I("brightness=%d force brightness=%d", - brightness, force_brightness); - brightness = force_brightness; - } - /* Update device brightness */ ret = backlight_ops.set_brightness(brightness); @@ -115,39 +145,96 @@ static int system_enable_autosleep(void) return sys_set_str(POWER_AUTOSLEEP_PATH, "mem"); } -static int system_power_lock(void) +static int vital_mode_support(void) { - dd_list *elem, *elem_n; - const struct device_ops *dev; - int ret; + if (vital_support < 0) { + FILE *fp; + + fp = fopen(FREEZER_VITAL_WAKEUP_CGROUP, "r"); + if (fp == NULL) { + _E("%s open failed", FREEZER_VITAL_WAKEUP_CGROUP); + /* read max 2 times to check if this file exist */ + vital_support++; + return 0; + } + vital_support = 1; + fclose(fp); + } + return vital_support; +} - _I("system power lock."); - ret = sys_set_str(POWER_LOCK_PATH, "mainlock"); +static int suspend_other_process(int type) +{ + int ret = 0; + char buf[8]; + const char *command[1]; - /* Devices Resume */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->resume) - dev->resume(); - } + if (vital_service == type) + return ret; + + if (type == VITAL_WAKEUP && vital_service > VITAL_SLEEP) + return ret; + + vital_service = type; + + if (!vital_mode_support()) + return ret; + if (type == VITAL_SLEEP) { + snprintf(buf, sizeof(buf), "%s", "sleep"); + command[0] = buf; + dbus_handle_method_sync_timeout(RESOURCED_BUS_NAME, + RESOURCED_PATH_FREEZER, + RESOURCED_INTERFACE_FREEZER, + "SetSuspend", + "s", + command, + SET_SUSPEND_TIME*1000); + vital_sleep = true; + } else if (type == VITAL_WAKEUP) { + snprintf(buf, sizeof(buf), "%s", "wakeup"); + command[0] = buf; + ret = dbus_handle_method_async(RESOURCED_BUS_NAME, + RESOURCED_PATH_FREEZER, + RESOURCED_INTERFACE_FREEZER, + "SetSuspend", + "s", command); + } else if (type == VITAL_EXIT) { + snprintf(buf, sizeof(buf), "%s", "exit"); + command[0] = buf; + ret = dbus_handle_method_async(RESOURCED_BUS_NAME, + RESOURCED_PATH_FREEZER, + RESOURCED_INTERFACE_FREEZER, + "SetSuspend", + "s", command); + vital_sleep = false; + } return ret; } -static int system_power_unlock(void) +static int system_power_lock(void) { - dd_list *elem, *elem_n; - const struct device_ops *dev; + _I("system power lock"); + suspend_other_process(VITAL_WAKEUP); + mainlock_status = POWER_LOCK; - /* Devices Suspend */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->suspend) - dev->suspend(); - } + return sys_set_str(POWER_LOCK_PATH, "mainlock"); +} + +static int system_power_unlock(void) +{ + _I("system power unlock"); + suspend_other_process(VITAL_SLEEP); + mainlock_status = POWER_UNLOCK; - _I("system power unlock."); return sys_set_str(POWER_UNLOCK_PATH, "mainlock"); } +static int system_get_power_lock(void) +{ + return mainlock_status; +} + static int system_get_power_lock_support(void) { static int power_lock_support = -1; @@ -162,7 +249,7 @@ static int system_get_power_lock_support(void) else power_lock_support = true; - _I("system power lock: %s", + _I("System power lock: %s", (power_lock_support ? "support" : "not support")); out: @@ -174,9 +261,6 @@ static int get_lcd_power(void) enum display_state val; int ret; - if (ambient_get_state()) - return DPMS_OFF; - if (!display_dev || !display_dev->get_state) { _E("There is no display device."); return -ENOENT; @@ -186,6 +270,12 @@ static int get_lcd_power(void) if (ret < 0) return ret; + if (val == DISPLAY_ON && ambient_get_state()) + return DPMS_OFF; + + if (dpms_running_state != DPMS_SETTING_DONE) + return dpms_running_state; + switch (val) { case DISPLAY_ON: return DPMS_ON; @@ -202,13 +292,16 @@ static int get_lcd_power(void) bool display_dimstay_check(void) { + if (pm_status_flag & DIM_FLAG) + return true; + if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) return true; return false; } -void change_brightness(int start, int end, int step) +static void change_brightness(int start, int end, int step) { int diff, val; int ret = -1; @@ -226,7 +319,20 @@ void change_brightness(int start, int end, int step) if (prev == end) return; - _D("start=%d end=%d step=%d", start, end, step); + if (pm_status_flag & DIM_MASK) + end = 0; + + _I("start %d end %d step %d", start, end, step); + + if (display_dev && display_dev->set_multi_brightness) { + ret = display_dev->set_multi_brightness(end, step, LCD_PHASED_DELAY); + if (ret < 0) + _E("Failed to set_multi_brightness (%d)", ret); + + backlight_ops.set_brightness(end); + + return; + } diff = end - start; @@ -250,16 +356,15 @@ void change_brightness(int start, int end, int step) static int backlight_on(enum device_flags flags) { int ret = -1; + static int cnt; - _D("LCD on %x", flags); + _I("[DPMS XLIB Backlight] LCD on %x cnt:%d", flags, cnt); - ret = bl_onoff(DPMS_ON); - if (ret < 0) - _E("Failed to turn on backlight."); - - if (flags & LCD_PHASED_TRANSIT_MODE) - change_brightness(LCD_PHASED_MIN_BRIGHTNESS, - default_brightness, LCD_PHASED_CHANGE_STEP); + cnt++; + ret = bl_onoff(DPMS_ON, flags); +#ifdef ENABLE_PM_LOG + pm_history_save(PM_LOG_LCD_ON, pm_cur_state); +#endif return ret; } @@ -267,19 +372,30 @@ static int backlight_on(enum device_flags flags) static int backlight_off(enum device_flags flags) { int ret = -1; + static int cnt, ambient_cnt; + + if (flags & AMBIENT_MODE) { + _I("[DPMS XLIB Backlight] LCD suspend %x cnt:%d", flags, ambient_cnt); + ambient_cnt++; + + return 0; + } - _D("LCD off %x", flags); + _I("[DPMS XLIB Backlight] LCD off %x cnt:%d", flags, cnt); + cnt++; if (flags & LCD_PHASED_TRANSIT_MODE) - change_brightness(default_brightness, + backlight_ops.transit_brt(default_brightness, LCD_PHASED_MIN_BRIGHTNESS, LCD_PHASED_CHANGE_STEP); - if (flags & AMBIENT_MODE) - return 0; + if (flags & FORCE_OFF_MODE) + ret = bl_onoff(DPMS_FORCE_OFF, flags); + else + ret = bl_onoff(DPMS_OFF, flags); - ret = bl_onoff(DPMS_OFF); - if (ret < 0) - _E("Failed to turn off backlight."); +#ifdef ENABLE_PM_LOG + pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); +#endif return ret; } @@ -287,15 +403,8 @@ static int backlight_off(enum device_flags flags) static int backlight_dim(void) { int ret; - int brightness; - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, &brightness); - if (ret < 0) { - _E("Failed to get vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - return -EPERM; - } - - ret = bl_brt(brightness, 0); + ret = backlight_ops.set_brightness(PM_DIM_BRIGHTNESS); #ifdef ENABLE_PM_LOG if (!ret) pm_history_save(PM_LOG_LCD_DIM, pm_cur_state); @@ -335,11 +444,11 @@ static int custom_backlight_update(void) custom_brightness > PM_MAX_BRIGHTNESS) return -EINVAL; - if (display_dimstay_check()) { + if (display_dimstay_check()) ret = backlight_dim(); - } else { - _I("Custom brightness(%d) restored.", custom_brightness); - ret = bl_brt(custom_brightness, 0); + else { + _I("custom brightness restored! %d", custom_brightness); + ret = backlight_ops.set_brightness(custom_brightness); } return ret; @@ -358,16 +467,18 @@ static int set_force_brightness(int level) static int backlight_update(void) { int ret = 0; + int brt; if (get_custom_status()) { - _I("Custom brightness mode. brt no updated."); + _I("custom brightness mode! brt no updated"); return 0; } if (display_dimstay_check()) ret = backlight_dim(); - else - ret = bl_brt(default_brightness, 0); - + else { + brt = backlight_ops.get_default_brt(); + ret = backlight_ops.set_brightness(brt); + } return ret; } @@ -377,7 +488,7 @@ static int backlight_standby(int force) if ((get_lcd_power() == DPMS_ON) || force) { _I("LCD standby"); - ret = bl_onoff(DPMS_STANDBY); + ret = bl_onoff(DPMS_STANDBY, 0); } return ret; @@ -393,6 +504,11 @@ static int set_default_brt(int level) return 0; } +static int get_default_brt(void) +{ + return default_brightness; +} + static int check_wakeup_src(void) { /* TODO if nedded. @@ -470,10 +586,22 @@ static int set_brightness(int val) return max; } + if (force_brightness > 0 && val != PM_DIM_BRIGHTNESS) { + _I("brightness(%d), force brightness(%d)", + val, force_brightness); + val = force_brightness; + } + + if (pm_status_flag & DIM_MASK) + val = 0; + /* Maximum Brightness to users is 100. * Thus real brightness need to be calculated */ val = val * max / 100; + _I("set brightness %d (default:%d)", val, default_brightness); + device_notify(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, (void *)&val); + return display_dev->set_brightness(val); } @@ -544,6 +672,84 @@ static int get_brightness_by_light_sensor(float lmax, float lmin, float light, i return 0; } +static int get_image_effect(enum display_image_effect *effect) +{ + int ret; + enum display_image_effect val; + + if (!display_dev || !display_dev->get_image_effect) { + _E("There is no display device."); + return -ENOENT; + } + + ret = display_dev->get_image_effect(&val); + if (ret < 0) { + _E("Failed to get image effect: %d", ret); + return ret; + } + + *effect = val; + + return 0; +} + +static int set_image_effect(enum display_image_effect effect) +{ + int ret; + + if (!display_dev || !display_dev->set_image_effect) { + _E("There is no display device."); + return -ENOENT; + } + + ret = display_dev->set_image_effect(effect); + if (ret < 0) { + _E("Failed to set image effect: %d", ret); + return ret; + } + + return 0; +} + +static int get_panel_mode(enum display_panel_mode *mode) +{ + int ret; + enum display_panel_mode val; + + if (!display_dev || !display_dev->get_panel_mode) { + _E("there is no display device"); + return -ENOENT; + } + + ret = display_dev->get_panel_mode(&val); + if (ret < 0) { + _E("failed to get panel mode(%d)", ret); + return ret; + } + + *mode = val; + + return 0; +} + +static int set_panel_mode(enum display_panel_mode mode) +{ + int ret; + + if (!display_dev || !display_dev->set_panel_mode) { + _E("there is no display device"); + return -ENOENT; + } + + ret = display_dev->set_panel_mode(mode); + if (ret < 0) { + _E("failed to set panel mode(%d)", ret); + return ret; + } + + return 0; +} + static int get_frame_rate(int *rate) { if (!rate) @@ -595,6 +801,101 @@ static int set_frame_rate(int rate) return display_dev->set_frame_rate(rate); } +/* It was operated only AOD enter & leave */ +static int backlight_transit_state(int state) +{ + int brt, val; + int start, end; + + backlight_ops.get_brightness(&brt); + + if (state == DPMS_OFF) { + start = brt; + end = display_conf.aod_enter_level; + + /* + * The value of backlight_ops.get_brightness is system brightness. + * But when device is LBM, the value is not same with real brightness. + * So it should be read exactly value for transit smooth effect + */ + get_brightness(&val); + + if (val > display_conf.aod_enter_level) + backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + } else { + /* prevent transit effect when another effect is already executed */ + if (brt != display_conf.aod_enter_level) { + _W("effect is already executed brt(%d) aod_level(%d)", + brt, display_conf.aod_enter_level); + return 0; + } + + start = display_conf.aod_enter_level; + end = default_brightness; + backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + } + + return 0; +} + +static gboolean blink_cb(gpointer data) +{ + static bool flag; + + set_brightness(flag ? PM_MAX_BRIGHTNESS : PM_MIN_BRIGHTNESS); + + flag = !flag; + + return G_SOURCE_CONTINUE; +} + +static void blink(int timeout) +{ + static guint timer; + + if (timer) { + g_source_remove(timer); + timer = 0; + } + + if (timeout < 0) { + _E("timeout value is invalid %d", timeout); + return; + } + + if (timeout == 0) { + backlight_update(); + return; + } + + timer = g_timeout_add(timeout, blink_cb, NULL); +} + +static gboolean release_blink_cb(gpointer data) +{ + blink(0); + + release_timer = 0; + return G_SOURCE_REMOVE; +} + +static void release_blink(void) +{ + if (release_timer) { + g_source_remove(release_timer); + release_timer = 0; + } + + release_timer = g_timeout_add(DUMP_MODE_WAITING_TIME, release_blink_cb, NULL); +} + +static void restore_brightness_func(void) +{ + backlight_ops.set_brightness = set_brightness; + backlight_ops.get_brightness = get_brightness; + backlight_ops.transit_brt = change_brightness; +} + static void _init_ops(void) { backlight_ops.off = backlight_off; @@ -603,6 +904,7 @@ static void _init_ops(void) backlight_ops.update = backlight_update; backlight_ops.standby = backlight_standby; backlight_ops.set_default_brt = set_default_brt; + backlight_ops.get_default_brt = get_default_brt; backlight_ops.get_lcd_power = get_lcd_power; backlight_ops.set_custom_status = set_custom_status; backlight_ops.get_custom_status = get_custom_status; @@ -611,14 +913,24 @@ static void _init_ops(void) backlight_ops.set_force_brightness = set_force_brightness; backlight_ops.set_brightness = set_brightness; backlight_ops.get_brightness = get_brightness; + backlight_ops.restore_brightness_func = restore_brightness_func; backlight_ops.get_brightness_by_light_sensor = get_brightness_by_light_sensor; + backlight_ops.get_image_effect = get_image_effect; + backlight_ops.set_image_effect = set_image_effect; + backlight_ops.get_panel_mode = get_panel_mode; + backlight_ops.set_panel_mode = set_panel_mode; backlight_ops.get_frame_rate = get_frame_rate; backlight_ops.set_frame_rate = set_frame_rate; + backlight_ops.transit_state = backlight_transit_state; + backlight_ops.transit_brt = change_brightness; + backlight_ops.blink = blink; + backlight_ops.release_blink = release_blink; power_ops.suspend = system_suspend; power_ops.enable_autosleep = system_enable_autosleep; power_ops.power_lock = system_power_lock; power_ops.power_unlock = system_power_unlock; + power_ops.get_power_lock = system_get_power_lock; power_ops.get_power_lock_support = system_get_power_lock_support; power_ops.check_wakeup_src = check_wakeup_src; power_ops.get_wakeup_count = get_wakeup_count; @@ -636,12 +948,12 @@ int display_service_load(void) r = hw_get_info(DISPLAY_HARDWARE_DEVICE_ID, (const struct hw_info **)&info); if (r < 0) { - _I("Display shared library is not supported: %d", r); - return -ENODEV; + _I("display shared library is not supported: %d", r); + return 0; } if (!info->open) { - _E("Failed to open display device: open(NULL)"); + _E("Failed to open display device: open(NULL)."); return -EPERM; } @@ -672,17 +984,44 @@ int display_service_free(void) return 0; } -int init_sysfs() +bool vital_mode(void) +{ + return vital_sleep; +} + +static int vital_state_changed(void *data) +{ + int type; + + assert(data); + + type = *(int *)data; + if (type == VITAL_EXIT) + suspend_other_process(VITAL_EXIT); + + return 0; +} + +int init_sysfs(unsigned int flags) { _init_ops(); + register_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); + return 0; } int exit_sysfs(void) { + int fd; const struct device_ops *ops = NULL; + fd = open("/tmp/sem.pixmap_1", O_RDONLY); + if (fd == -1) { + _E("X server disable"); + backlight_on(NORMAL_MODE); + } + backlight_update(); disconnect_interface_with_dpms(); @@ -694,5 +1033,10 @@ int exit_sysfs(void) if (!check_default(ops)) ops->start(NORMAL_MODE); + if (fd != -1) + close(fd); + + unregister_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); + return 0; } diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 8b35f7c..ddbb287 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "ambient-mode.h" #include "util.h" @@ -36,11 +37,11 @@ #include "core/common.h" #include "core/devices.h" #include "core/device-notifier.h" +#include "shared/common.h" #include "power/power-handler.h" #include "led/touch-key.h" #include "apps/apps.h" -#include #ifndef KEY_SCREENLOCK #define KEY_SCREENLOCK 0x98 #endif @@ -50,21 +51,24 @@ #define PREDEF_LEAVESLEEP "leavesleep" #define POWEROFF_ACT "poweroff" +#define PWROFF_POPUP_ACT "pwroff_popup" #define USEC_PER_SEC 1000000 +#define CSC_CONFIG_MODE_RUNNING 1 #define CAPTURE_COMBINATION_INTERVAL 0.5 /* 0.5 second */ +#define TORCH_COMBINATION_INTERVAL 0.1 /* 0.1 second */ +#define DEFAULT_COMBINATION_INTERVAL 0.1 /* 0.1 second */ -#define KEY_MAX_DELAY_TIME 700 /* ms */ +#define LONGKEY_PRESSED_TIME 4 /* 4 second */ -#define KEY_RELEASED 0 -#define KEY_PRESSED 1 -#define KEY_BEING_PRESSED 2 +#define KEY_MAX_DELAY_TIME 700 /* ms */ #define SIGNAL_CHANGE_HARDKEY "ChangeHardkey" #define SIGNAL_LCDON_BY_POWERKEY "LCDOnByPowerkey" #define SIGNAL_LCDOFF_BY_POWERKEY "LCDOffByPowerkey" -#define TOUCH_RELEASE (-1) +#define NORMAL_POWER 0 +#define KEY_TEST_MODE_POWER 2 #define GLOVE_MODE 1 @@ -72,39 +76,30 @@ enum key_combination_flags { KEY_COMBINATION_STOP = 0, KEY_COMBINATION_POWERKEY = BIT(0), KEY_COMBINATION_MENUKEY = BIT(1), + KEY_COMBINATION_VOLUMEUP = BIT(2), + KEY_COMBINATION_VOLUMEDOWN = BIT(3), }; enum combination_process { COMBINATION_STOP = KEY_COMBINATION_STOP, COMBINATION_SCREENCAPTURE = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_MENUKEY, + COMBINATION_TORCH = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_VOLUMEUP, + COMBINATION_QUICKTALK = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_VOLUMEDOWN, }; -int __WEAK__ get_glove_state(void); -void __WEAK__ switch_glove_key(int val); - static struct timeval pressed_time; static guint longkey_timeout_id = 0; +static guint longkey_restore_id = 0; +static guint displayon_by_powerkey_timeout_id = 0; static int cancel_lcdoff; static int key_combination = KEY_COMBINATION_STOP; static double combination_pressed_time; static bool touch_pressed = false; static int skip_lcd_off = false; static int skip_combination = false; +static int bezel_wakeup = true; static const struct device_ops *touchled; - -static int booting_done(void *data) -{ - static int done = 0; - - if (!data) - return done; - - done = *(int *)data; - - _I("Booting done(%d)", done); - - return done; -} +static int booting_check = true; static inline int current_state_in_on(void) { @@ -128,7 +123,7 @@ static void pwroff_popup(void) _E("Failed to launch power off popup."); } -static void longkey_pressed() +static void longkey_pressed(void) { unsigned int caps; @@ -152,6 +147,14 @@ static void longkey_pressed() pwroff_popup(); } +static gboolean longkey_restore_cb(void *data) +{ + device_notify(DEVICE_NOTIFIER_LONGKEY_RESTORE, (void *)NULL); + longkey_restore_id = 0; + + return G_SOURCE_REMOVE; +} + static gboolean longkey_pressed_cb(void *data) { longkey_pressed(); @@ -196,7 +199,7 @@ static inline void broadcast_lcdoff_by_powerkey(void) NULL); } -static inline bool switch_on_lcd(void) +static inline bool switch_on_lcd(enum device_flags flags) { if (current_state_in_on()) return false; @@ -206,9 +209,12 @@ static inline bool switch_on_lcd(void) return false; } - broadcast_lcdon_by_powerkey(); + if (flags & LCD_ON_BY_POWER_KEY) + broadcast_lcdon_by_powerkey(); + else if (flags & LCD_ON_BY_TOUCH) + _I("Display on by Touch_wakeup event"); - lcd_on_direct(LCD_ON_BY_POWER_KEY); + lcd_on_direct(flags); return true; } @@ -230,15 +236,37 @@ static void check_key_combination(struct input_event *pinput) { double press_time, diff_time; press_time = (pinput->time).tv_sec + USEC_TO_SEC((pinput->time).tv_usec); + diff_time = press_time - combination_pressed_time; switch (key_combination) { case COMBINATION_SCREENCAPTURE: - diff_time = press_time - combination_pressed_time; if (diff_time <= CAPTURE_COMBINATION_INTERVAL) { _I("Combination key : SCREENCAPTURE mode"); skip_combination = true; } break; + case COMBINATION_TORCH: + if (diff_time <= TORCH_COMBINATION_INTERVAL) { + /* When torch combination, display control should be not change. */ + if (displayon_by_powerkey_timeout_id) { + g_source_remove(displayon_by_powerkey_timeout_id); + displayon_by_powerkey_timeout_id = 0; + } + _I("Combination key : TORCH mode"); + skip_combination = true; + } else + key_combination = COMBINATION_STOP; + break; + case COMBINATION_QUICKTALK: + if (diff_time <= DEFAULT_COMBINATION_INTERVAL) { + _I("Combination key : QUICK-TALK mode"); + skip_combination = true; + if (longkey_timeout_id) { + g_source_remove(longkey_timeout_id); + longkey_timeout_id = 0; + } + } + break; default: combination_pressed_time = press_time; return; @@ -255,6 +283,12 @@ static void start_key_combination(struct input_event *pinput) case KEY_MENU: key_combination |= KEY_COMBINATION_MENUKEY; break; + case KEY_VOLUMEUP: + key_combination |= KEY_COMBINATION_VOLUMEUP; + break; + case KEY_VOLUMEDOWN: + key_combination |= KEY_COMBINATION_VOLUMEDOWN; + break; default: return; } @@ -276,8 +310,14 @@ static void stop_key_combination(struct input_event *pinput) case KEY_MENU: key_combination &= ~KEY_COMBINATION_MENUKEY; break; + case KEY_VOLUMEUP: + key_combination &= ~KEY_COMBINATION_VOLUMEUP; + break; + case KEY_VOLUMEDOWN: + key_combination &= ~KEY_COMBINATION_VOLUMEDOWN; + break; default: - _E("Thid code(%d) is not combination type", pinput->code); + _E("This code(%d) is not combination type.", pinput->code); break; } } @@ -301,24 +341,118 @@ static int process_menu_key(struct input_event *pinput) return false; _D("No lcd-on capability!"); return true; - } else if (pinput->value == KEY_PRESSED) { - switch_on_lcd(); - } + } else if (pinput->value == KEY_PRESSED) + switch_on_lcd(LCD_ON_BY_POWER_KEY); return false; } -static bool release_short_powerkey(void) +static int decide_lcdoff(void) { -// tv d - no, a - yes - if (!display_conf.powerkey_doublepress && display_conf.lcd_always_on) { - longkey_pressed(); + /* It's not needed if it's already LCD off state */ + if (!current_state_in_on() && + backlight_ops.get_lcd_power() != DPMS_ON) + return false; + + /* + * This flag is set at the moment + * that LCD is turned on by power key + * LCD has not to turned off in the situation. + */ + if (skip_lcd_off) + return false; + + /* LCD is not turned off when powerkey is pressed,not released */ + if (key_combination == KEY_COMBINATION_POWERKEY) + return false; + + /* LCD-off is blocked at the moment poweroff popup shows */ + if (cancel_lcdoff) + return false; + + /* LCD-off is blocked when powerkey and volmedown key are pressed */ + if (skip_combination) + return false; + + /* At booting time, display must do not turn off */ + if (booting_check) + return false; + + return true; +} + +static int lcdoff_powerkey(void) +{ + int ignore = true; + + if (decide_lcdoff() == true) { + check_processes(S_NORMAL); + check_processes(S_LCDDIM); + + if (!check_holdkey_block(S_NORMAL) && + !check_holdkey_block(S_LCDDIM)) { + if (display_info.update_auto_brightness) + display_info.update_auto_brightness(false); + switch_off_lcd(); + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); + update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY); + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); + } + } else { + ignore = false; + skip_combination = false; + } + cancel_lcdoff = 0; + + return ignore; +} + +static bool key_check_display_on(void) +{ + if (current_state_in_on()) + return false; + + if (backlight_ops.get_lcd_power() == DPMS_ON) { + _W("display power was on"); return false; } return true; } +static gboolean display_on_cb(void *data) +{ + if (displayon_by_powerkey_timeout_id == 0) + return G_SOURCE_REMOVE; + + displayon_by_powerkey_timeout_id = 0; + if (backlight_ops.get_lcd_power() != DPMS_ON || + current_state_in_on() == false) { + broadcast_lcdon_by_powerkey(); + lcd_on_direct(LCD_ON_BY_POWER_KEY); + + if (pm_callback) + (*pm_callback) (INPUT_POLL_EVENT, NULL); + } + + return G_SOURCE_REMOVE; +} + +static int process_back_key(struct input_event *pinput) +{ + int ignore = true; + + if (pinput->value == KEY_PRESSED) { + switch_on_lcd(LCD_ON_BY_POWER_KEY); + _I("back key pressed"); + ignore = false; + } + + return ignore; +} + static int process_power_key(struct input_event *pinput) { int ignore = true; @@ -331,7 +465,13 @@ static int process_power_key(struct input_event *pinput) case KEY_RELEASED: check_key_pair(pinput->code, pinput->value, &value); - ignore = release_short_powerkey(); + if (!display_conf.powerkey_doublepress) { + if (display_has_caps(caps, DISPLAY_CAPA_LCDOFF)) + lcdoff_powerkey(); + else + _D("No lcdoff capability!"); + } else if (skip_lcd_off) + ignore = false; if (!display_has_caps(caps, DISPLAY_CAPA_LCDON)) ignore = true; @@ -341,10 +481,32 @@ static int process_power_key(struct input_event *pinput) longkey_timeout_id = 0; } + if (longkey_restore_id > 0) { + g_source_remove(longkey_restore_id); + longkey_restore_id = 0; + } + break; case KEY_PRESSED: if (display_has_caps(caps, DISPLAY_CAPA_LCDON)) { - skip_lcd_off = switch_on_lcd(); + if (wearable_mode()) + skip_lcd_off = switch_on_lcd(LCD_ON_BY_POWER_KEY); + else { + /* + * LCD does not turn on immediately at mobile. + * It will be turned on after 0.1 second because of torch concept. + */ + skip_lcd_off = key_check_display_on(); + ignore = true; + + if (!displayon_by_powerkey_timeout_id && + backlight_ops.get_lcd_power() != DPMS_ON && + key_combination != COMBINATION_TORCH) { + displayon_by_powerkey_timeout_id = g_timeout_add( + 100, + display_on_cb, NULL); + } + } } else { _D("No lcdon capability!"); skip_lcd_off = false; @@ -358,9 +520,11 @@ static int process_power_key(struct input_event *pinput) longkey_timeout_id = g_timeout_add_seconds( display_conf.longpress_interval, longkey_pressed_cb, NULL); + /* add long key restore timer */ + longkey_restore_id = g_timeout_add_seconds( + LONGKEY_PRESSED_TIME, + longkey_restore_cb, NULL); } - if (skip_lcd_off) - ignore = false; cancel_lcdoff = 0; break; @@ -421,10 +585,12 @@ static void process_hardkey_backlight(struct input_event *pinput) _I("Touch is pressed, then hard key is not working!"); return; } + if (!wearable_mode()) { /* Sound & Vibrate only in unlock state */ if (__get_lock_screen_state() == VCONFKEY_IDLE_UNLOCK || get_lock_screen_bg_state()) sound_vibrate_hardkey(); + } if (touchled && touchled->execute) { opt = TOUCHLED_PRESS; @@ -444,6 +610,23 @@ static void process_hardkey_backlight(struct input_event *pinput) } } +static void update_vital_state(struct input_event *pinput) +{ + int type; + + /* Change vital state to VITAL_EXIT only if vital mode is active */ + if (!vital_mode()) + return; + + /* Touch or Menu Key Release Event */ + if (pinput->type == EV_ABS || (pinput->type == EV_KEY && + pinput->value == KEY_RELEASED && pinput->code == KEY_MENU)) { + /* Enable all services upon receiving user input, else maintain same state */ + type = VITAL_EXIT; + device_notify(DEVICE_NOTIFIER_VITAL_STATE, &type); + } +} + static int check_key(struct input_event *pinput, int fd) { int ignore = true; @@ -462,6 +645,13 @@ static int check_key(struct input_event *pinput, int fd) ignore = process_screenlock_key(pinput); break; case KEY_BACK: + ignore = process_back_key(pinput); + stop_key_combination(NULL); + if (current_state_in_on()) { + process_hardkey_backlight(pinput); + ignore = false; + } + break; case KEY_PHONE: stop_key_combination(NULL); if (current_state_in_on()) { @@ -471,6 +661,9 @@ static int check_key(struct input_event *pinput, int fd) break; case KEY_VOLUMEUP: case KEY_VOLUMEDOWN: + if (current_state_in_on()) + ignore = false; + break; case KEY_CAMERA: case KEY_EXIT: case KEY_CONFIG: @@ -536,34 +729,36 @@ static int check_key_filter(void *data, int fd) code = pinput->code; value = pinput->value; + update_vital_state(pinput); ignore = check_key(pinput, fd); restore_custom_brightness(); break; case EV_REL: - ignore = false; + if (pm_cur_state == S_LCDOFF && bezel_wakeup) { + switch_on_lcd(LCD_ON_BY_BEZEL); + ignore = false; + } else if (pm_cur_state != S_LCDOFF) + ignore = false; break; case EV_ABS: - if (current_state_in_on()) + update_vital_state(pinput); + if (pinput->value == KEY_PRESSED) { + switch_on_lcd(LCD_ON_BY_TOUCH); ignore = false; + } - if (ambient_get_condition() == true) { - switch_on_lcd(); + if (current_state_in_on()) ignore = false; - } restore_custom_brightness(); - touch_pressed = - (pinput->value == TOUCH_RELEASE ? false : true); + if (pinput->value == KEY_PRESSED) + touch_pressed = true; + else if (pinput->value == KEY_RELEASED) + touch_pressed = false; break; case EV_SW: - if (!get_glove_state || !switch_glove_key) - break; - if (pinput->code == SW_GLOVE && - get_glove_state() == GLOVE_MODE) { - switch_glove_key(pinput->value); - } break; } @@ -573,6 +768,20 @@ static int check_key_filter(void *data, int fd) return 0; } +static int booting_done_cb(void *data) +{ + booting_check = 0; + + return 0; +} + +static int bezel_wakeup_cb(void *data) +{ + bezel_wakeup = (int)data; + + return 0; +} + /* * Default capability * powerkey := LCDON | LCDOFF | POWEROFF @@ -597,12 +806,8 @@ static void keyfilter_init(void) touchled = find_device(TOUCHLED_NAME); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); -} - -static void keyfilter_exit(void) -{ - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); + register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb); } static void key_backlight_enable(bool enable) @@ -622,7 +827,6 @@ static void key_backlight_enable(bool enable) static const struct display_keyfilter_ops normal_keyfilter_ops = { .init = keyfilter_init, - .exit = keyfilter_exit, .check = check_key_filter, .set_powerkey_ignore = NULL, .powerkey_lcdoff = NULL, diff --git a/plugins/wearable/display/bezel.c b/plugins/wearable/display/bezel.c index 47f09b1..2ea3622 100644 --- a/plugins/wearable/display/bezel.c +++ b/plugins/wearable/display/bezel.c @@ -123,7 +123,7 @@ static int bezel_stop(enum device_flags flags) */ static const struct device_ops bezel_device_ops = { .priority = DEVICE_PRIORITY_HIGH, - .name = "bezel", + DECLARE_NAME_LEN("bezel"), .init = bezel_init, .exit = bezel_exit, .start = bezel_start, diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 3f8c686..f65f2a1 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -35,10 +35,9 @@ #include #include #include +#include #include #include -#include -#include #include "ambient-mode.h" #include "util.h" @@ -53,14 +52,14 @@ #include "core/common.h" #include "core/config-parser.h" #include "core/launch.h" +#include "apps/apps.h" #include "extcon/extcon.h" +#include "battery/power-supply.h" #include "power/power-handler.h" #include "dd-display.h" #include "display/display-dpms.h" -#include "battery/battery.h" -#include "battery/power-supply.h" +#include "display-info.h" -#define PM_STATE_LOG_FILE tzplatform_mkpath(TZ_SYS_ALLLOGS, "pm_state.log") #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" /** @@ -71,18 +70,28 @@ #define SET_BRIGHTNESS_IN_BOOTLOADER "/usr/bin/save_blenv SLP_LCD_BRIGHT" #define LOCK_SCREEN_INPUT_TIMEOUT 10000 #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 -#define DD_LCDOFF_INPUT_TIMEOUT 3000 -#define ALWAYS_ON_TIMEOUT 3600000 //3600000 = 1 hour +#define ALWAYS_ON_TIMEOUT 3600000 +#define LATE_LCD_TRANSIT 1 + +#define PID_MAX 6 #define GESTURE_STR "gesture" #define POWER_KEY_STR "powerkey" #define TOUCH_STR "touch" #define EVENT_STR "event" #define TIMEOUT_STR "timeout" +#define PROXI_STR "proximity" +#define PALM_STR "palm" #define UNKNOWN_STR "unknown" +#define METHOD_APP_STATUS "CheckAppStatus" + +#define PM_WAKEUP 0 +#define PM_SUSPEND 1 + extern void init_pm_internal(); extern int get_charging_status(int *val); +extern void init_save_userlock(void); unsigned int pm_status_flag; static int trans_condition; @@ -93,6 +102,7 @@ static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; int pm_cur_state; int pm_old_state; guint timeout_src_id; +int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; static int custom_holdkey_block = false; @@ -100,13 +110,21 @@ static int custom_change_pid = -1; static char *custom_change_name; static bool hallic_open = true; static guint lock_timeout_id; +static guint transit_timer; static int lock_screen_timeout = LOCK_SCREEN_INPUT_TIMEOUT; +static long displayoff_time; static struct timeval lcdon_tv; static int lcd_paneloff_mode = false; static int stay_touchscreen_off = false; +dd_list *lcdon_ops; +/* + * The two variables(lcdon_broadcast, pmstate_suspend) must be set initial + * state because it should be sent from previous state at booting time. + */ static bool lcdon_broadcast = true; +static int pmstate_suspend = PM_SUSPEND; + static bool touch_blocked = false; -dd_list *lcdon_ops; /* default transition, action fuctions */ static int default_trans(int evt); @@ -117,6 +135,10 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); +static gboolean pmlock_normal_check(void *data); +static gboolean pmlock_dim_check(void *data); +static gboolean pmlock_off_check(void *data); + static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; @@ -141,6 +163,10 @@ static int trans_table[S_END][EVENT_END] = { { S_POWEROFF, S_POWEROFF }, /* S_POWEROFF */ }; +static GSourceFunc warning_cb[S_END] = { + NULL, pmlock_normal_check, pmlock_dim_check, pmlock_off_check, +}; + enum signal_type { SIGNAL_INVALID = 0, SIGNAL_PRE, @@ -148,6 +174,11 @@ enum signal_type { SIGNAL_MAX, }; +enum platform_control { + PLATFORM_DISPLAY_OFF, + PLATFORM_DISPLAY_ON, +}; + static const char *lcdon_sig_lookup[SIGNAL_MAX] = { [SIGNAL_PRE] = "LCDOn", [SIGNAL_POST] = "LCDOnCompleted", @@ -179,7 +210,7 @@ static const char *lcdoff_sig_lookup[SIGNAL_MAX] = { #define LONG_PRESS_INTERVAL 2 /* 2 seconds */ #define SAMPLING_INTERVAL 1 /* 1 sec */ #define BRIGHTNESS_CHANGE_STEP 10 -#define LCD_ALWAYS_ON 1 +#define LCD_ALWAYS_ON 0 #define ACCEL_SENSOR_ON 1 #define CONTINUOUS_SAMPLING 1 #define LCDOFF_TIMEOUT 500 /* milli second */ @@ -196,13 +227,18 @@ struct display_config display_conf = { .lcdoff_timeout = LCDOFF_TIMEOUT, .brightness_change_step = BRIGHTNESS_CHANGE_STEP, .lcd_always_on = LCD_ALWAYS_ON, - .framerate_app = {1, 0, 0, 0}, - .control_display = 1, + .dimming = 1, + .framerate_app = {0, 0, 0, 0}, + .control_display = 0, .powerkey_doublepress = 0, .accel_sensor_on = ACCEL_SENSOR_ON, .continuous_sampling = CONTINUOUS_SAMPLING, - .timeout_enable = false, + .timeout_enable = true, .input_support = true, + .lockcheck_timeout = 600, + .aod_enter_level = 40, + .aod_tsp = true, + .touch_wakeup = false, }; struct display_function_info display_info = { @@ -215,9 +251,11 @@ struct display_function_info display_info = { typedef struct _pm_lock_node { pid_t pid; guint timeout_id; + guint warning_id; time_t time; bool holdkey_block; bool background; + bool broadcast_warning; } PmLockNode; static dd_list *cond_head[S_END]; @@ -232,9 +270,9 @@ static void set_process_active(bool flag, pid_t pid) /* Send dbug to resourced */ ret = dbus_handle_emit_dbus_signal(NULL, RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - RESOURCED_METHOD_ACTIVE, - g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); + RESOURCED_INTERFACE_PROCESS, + RESOURCED_METHOD_ACTIVE, + g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); if (ret < 0) _E("Failed to send dbus signal to resourced."); } @@ -288,17 +326,64 @@ void change_proc_change_state(int (*func)(unsigned int cond, pid_t pid)) proc_change_state = func; } +static inline long clock_gettime_to_long(void) +{ + struct timespec now; + int ret; + + ret = clock_gettime(CLOCK_REALTIME, &now); + + if (ret < 0) { + _E("Failed to clock gettime!"); + return 0; + } + + return SEC_TO_MSEC(now.tv_sec) + NSEC_TO_MSEC(now.tv_nsec); +} + +static int display_brightness_changed(void *data) +{ + int brt, ret; + + brt = DATA_VALUE_INT(data); + + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "Brightness", + g_variant_new("(i)", brt)); + if (ret < 0) + _E("Failed to send dbus signal Brightness."); + + return 0; +} + +static int display_auto_brightness_sensing(void *data) +{ + if (!transit_timer) + return 0; + + g_source_remove(transit_timer); + transit_timer = 0; + + return 0; +} + static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) { const char *str; const char *signal; int ret; + long diff = 0; if (type <= SIGNAL_INVALID || type >= SIGNAL_MAX) { _E("Invalid signal type(%d).", type); return; } + if (type == SIGNAL_PRE && displayoff_time != 0) + diff = clock_gettime_to_long() - displayoff_time; + if (flags & LCD_ON_BY_GESTURE) str = GESTURE_STR; else if (flags & LCD_ON_BY_POWER_KEY) @@ -316,7 +401,7 @@ static void broadcast_lcd_on(enum signal_type type, enum device_flags flags) DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, signal, - g_variant_new("(s)", str)); + g_variant_new("(si)", str, diff)); if (ret < 0) _E("Failed to send dbus signal(%s)", signal); } @@ -332,6 +417,9 @@ static void broadcast_lcd_off(enum signal_type type, enum device_flags flags) return; } + if (type == SIGNAL_PRE) + displayoff_time = clock_gettime_to_long(); + signal = lcdoff_sig_lookup[type]; if (flags & LCD_OFF_BY_POWER_KEY) @@ -340,6 +428,12 @@ static void broadcast_lcd_off(enum signal_type type, enum device_flags flags) str = TIMEOUT_STR; else if (flags & LCD_OFF_BY_EVENT) str = EVENT_STR; + else if (flags & LCD_OFF_BY_PROXIMITY) + str = PROXI_STR; + else if (flags & LCD_OFF_BY_PALM) + str = PALM_STR; + else if (flags & LCD_OFF_BY_GESTURE) + str = GESTURE_STR; else str = UNKNOWN_STR; @@ -370,9 +464,6 @@ static unsigned long get_lcd_on_flags(void) if (lcd_paneloff_mode) flags |= LCD_PANEL_OFF_MODE; - if (stay_touchscreen_off) - flags |= TOUCH_SCREEN_OFF_MODE; - if (ambient_get_condition() == true) { flags |= AMBIENT_MODE; flags |= LCD_PHASED_TRANSIT_MODE; @@ -386,6 +477,18 @@ bool touch_event_blocked(void) return touch_blocked; } +static gboolean late_transit_on(void *data) +{ + if (!transit_timer) + return G_SOURCE_REMOVE; + + g_source_remove(transit_timer); + transit_timer = 0; + + backlight_ops.transit_state(DPMS_ON); + return G_SOURCE_REMOVE; +} + void lcd_on_procedure(int state, enum device_flags flag) { dd_list *l = NULL; @@ -393,19 +496,29 @@ void lcd_on_procedure(int state, enum device_flags flag) unsigned long flags = get_lcd_on_flags(); flags |= flag; - /* send LCDOn dbus signal */ - if (!lcdon_broadcast) { - broadcast_lcd_on(SIGNAL_PRE, flags); - lcdon_broadcast = true; - } + /* + * Display on procedure + * step 1. broadcast lcd on signal with cause + * step 2. set brightness + * step 3. set pmstate of vconf + * step 4. display on operate + * - a. display on + * - b. TSP(touch screen) and touchkey enable + * step 5. broadcast lcd on complete siganl + * step 6. key backlight enable + */ + _I("[lcdstep] %lu", flags); if (flags & AMBIENT_MODE) { - if (ambient_get_state() == false && - backlight_ops.get_lcd_power() == DPMS_ON) + if (ambient_get_state() == false && backlight_ops.get_lcd_power() == DPMS_ON) return; ambient_set_state(false); } + /* send LCDOn dbus signal */ + if (!lcdon_broadcast) + broadcast_lcd_on(SIGNAL_PRE, flags); + if (!(flags & LCD_PHASED_TRANSIT_MODE)) { /* Update brightness level */ if (state == LCD_DIM) @@ -422,7 +535,13 @@ void lcd_on_procedure(int state, enum device_flags flag) DD_LIST_FOREACH(lcdon_ops, l, ops) ops->start(flags); - broadcast_lcd_on(SIGNAL_POST, flags); + if (!lcdon_broadcast) { + broadcast_lcd_on(SIGNAL_POST, flags); + if (flags & LCD_PHASED_TRANSIT_MODE) + transit_timer = g_timeout_add_seconds(LATE_LCD_TRANSIT, + late_transit_on, NULL); + lcdon_broadcast = true; + } if (CHECK_OPS(keyfilter_ops, backlight_enable)) keyfilter_ops->backlight_enable(true); @@ -430,7 +549,7 @@ void lcd_on_procedure(int state, enum device_flags flag) touch_blocked = false; } -static inline unsigned long get_lcd_off_flags(void) +static unsigned long get_lcd_off_flags(void) { unsigned long flags = NORMAL_MODE; @@ -439,10 +558,12 @@ static inline unsigned long get_lcd_off_flags(void) flags |= LCD_PHASED_TRANSIT_MODE; } + if (stay_touchscreen_off) + flags |= TOUCH_SCREEN_OFF_MODE; + return flags; } - inline void lcd_off_procedure(enum device_flags flag) { dd_list *l = NULL; @@ -450,6 +571,20 @@ inline void lcd_off_procedure(enum device_flags flag) unsigned long flags = get_lcd_off_flags(); flags |= flag; + /* + * Display off procedure + * step 0. enhance mode off using nofity (e.g mdnie, HBM, LBM) + * step 1. broadcast lcd off signal with cause + * step 2. set pmstate of vconf + * step 3. display off operate + * - a. display off + * - b. TSP(touch screen) and touchkey disable + * step 4. broadcast lcd off complete siganl + */ + _I("[lcdstep] %lu", flags); + + device_notify(DEVICE_NOTIFIER_LCD_OFF, NULL); + touch_blocked = true; if (flags & AMBIENT_MODE) { @@ -462,18 +597,23 @@ inline void lcd_off_procedure(enum device_flags flag) broadcast_lcd_off(SIGNAL_PRE, flags); lcdon_broadcast = false; } + set_setting_pmstate(S_LCDOFF); + if (CHECK_OPS(keyfilter_ops, backlight_enable)) keyfilter_ops->backlight_enable(false); - set_setting_pmstate(S_LCDOFF); + if (transit_timer) { + g_source_remove(transit_timer); + transit_timer = 0; + } + + if (flags & LCD_PHASED_TRANSIT_MODE) + backlight_ops.transit_state(DPMS_OFF); DD_LIST_FOREACH(lcdon_ops, l, ops) ops->stop(flags); if (flags & AMBIENT_MODE) - /* Do not broadcast the post signal here. - * The signal will be broadcasted - * after showing Ambient clock */ broadcast_lcd_off_late(flags); else broadcast_lcd_off(SIGNAL_POST, flags); @@ -481,20 +621,20 @@ inline void lcd_off_procedure(enum device_flags flag) void set_stay_touchscreen_off(int val) { - _D("stay touch screen off: %d", val); + _I("Stay touch screen off: %d", val); stay_touchscreen_off = val; - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - set_setting_pmstate(LCD_NORMAL); + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } void set_lcd_paneloff_mode(int val) { - _D("lcd paneloff mode: %d", val); + _I("Lcd paneloff mode: %d", val); lcd_paneloff_mode = val; - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - set_setting_pmstate(LCD_NORMAL); + if (disp_plgn.pm_change_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } int low_battery_state(int val) @@ -538,7 +678,7 @@ static void makeup_trans_condition(void) static PmLockNode *find_node(enum state_t s_index, pid_t pid) { dd_list *elem; - PmLockNode *t; + PmLockNode *t = NULL; DD_LIST_FOREACH(cond_head[s_index], elem, t) { if (t->pid == pid) @@ -551,21 +691,28 @@ static PmLockNode *find_node(enum state_t s_index, pid_t pid) static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, bool holdkey_block) { + guint warning_id = 0; PmLockNode *n; time_t now; n = (PmLockNode *) malloc(sizeof(PmLockNode)); if (n == NULL) { - _E("Failed to add cond. Not enough memory."); + _E("Not enough memory, add cond. fail"); return NULL; } + if (pid < INTERNAL_LOCK_BASE) + warning_id = g_timeout_add_seconds(display_conf.lightsensor_interval, + warning_cb[s_index], (void *)((intptr_t)pid)); + time(&now); n->pid = pid; n->timeout_id = timeout_id; + n->warning_id = warning_id; n->time = now; n->holdkey_block = holdkey_block; n->background = false; + n->broadcast_warning = true; DD_LIST_APPEND(cond_head[s_index], n); refresh_app_cond(); @@ -584,6 +731,11 @@ static int del_node(enum state_t s_index, PmLockNode *n) g_source_remove(n->timeout_id); n->timeout_id = 0; } + if (n->warning_id) { + g_source_remove(n->warning_id); + n->warning_id = 0; + } + free(n); refresh_app_cond(); return 0; @@ -591,6 +743,7 @@ static int del_node(enum state_t s_index, PmLockNode *n) static void print_node(int next) { + int ret; dd_list *elem; PmLockNode *n; char buf[30]; @@ -605,10 +758,20 @@ static void print_node(int next) diff = difftime(now, n->time); ctime_r(&n->time, buf); - if (diff > LOCK_TIME_WARNING) - _W("over=%.0f s pid=%5d locktime=%s", diff, n->pid, buf); - else - _I("pid=%5d locktime=%s", n->pid, buf); + if (diff > LOCK_TIME_WARNING) { + if (diff > LOCK_TIME_WARNING * 60 && n->pid < INTERNAL_LOCK_BASE && n->broadcast_warning) { + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "pmlock_over", + g_variant_new("(i)", n->pid)); + if (ret < 0) + _E("Failed to send dbus signal pmlock_over."); + n->broadcast_warning = false; + } + _W("Over(%.0f s) pid( %5d) lock time(%s)", diff, n->pid, buf); + } else + _I("Pid(%5d) lock time(%s)", n->pid, buf); } } @@ -641,7 +804,6 @@ void get_pname(pid_t pid, char *pname) static void del_state_cond(void *data, enum state_t state) { PmLockNode *tmp = NULL; - char pname[PATH_MAX]; pid_t pid; if (!data) @@ -649,21 +811,20 @@ static void del_state_cond(void *data, enum state_t state) /* A passed data is a pid_t type data, not a 64bit data. */ pid = (pid_t)((intptr_t)data); - _I("Delete process(%d)'s prohibit dim condition by timeout.", pid); + _I("delete prohibit dim condition by timeout (%d)", pid); if (pid == INTERNAL_LOCK_AMBIENT) ambient_check_invalid_state(pid); tmp = find_node(state, pid); del_node(state, tmp); - get_pname(pid, pname); - set_unlock_time(pname, state); + set_unlock_time(pid, state); if (!timeout_src_id) states[pm_cur_state].trans(EVENT_TIMEOUT); if (state == S_LCDOFF) - set_process_active(FALSE, pid); + set_process_active(false, pid); } static gboolean del_normal_cond(void *data) @@ -684,23 +845,91 @@ static gboolean del_off_cond(void *data) return G_SOURCE_REMOVE; } -/* timeout handler */ -gboolean timeout_handler(void *data) +static void pmlock_check_cb(GVariant *var, void *user_data, GError *err) { - int run_timeout; + pid_t pid; + int ret, state; + char *app_id; - _I("Time out state %s.\n", states[pm_cur_state].name); - /* default setting */ - get_run_timeout(&run_timeout); + if (!var) + return; - /* for sdk - * if the run_timeout is zero, it regards AlwaysOn state - */ - if (pm_cur_state == S_NORMAL && (run_timeout == 0 || display_conf.lcd_always_on)) { - _D("'run_timeout' is always on."); - return G_SOURCE_CONTINUE; + if (!dh_get_param_from_var(var, "(iis)", &pid, &state, &app_id)) { + _E("Failed to notify low: no message(%s)", g_variant_get_type_string(var)); + goto out; } + _W("%s(%d) was requested pmlock for a long time.", app_id, pid); + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "pmlock_expired", + g_variant_new("(i)", pid)); + if (ret < 0) + _E("Failed to send dbus pmlock_expired"); + +out: + g_variant_unref(var); +} + +/* + * Any process is possible many time lock, deviced can not know malicious + * or good process. so infinity or more then 1 min lock process, deviced + * will be checked it to resoured. And then, it will be asked quit or maintain to user. + */ +static void pmlock_check(void *data, char *st) +{ + const char *arr[2]; + char chr_pid[PID_MAX]; + pid_t pid; + int ret; + + if (!data || !st) + return; + + if (!strncmp(st, "lcdoff", 4) && backlight_ops.get_lcd_power() == DPMS_ON) { + _D("Lcd state is PM_LCD_POWER_ON"); + return; + } + + pid = (pid_t)((intptr_t)data); + snprintf(chr_pid, sizeof(chr_pid), "%d", pid); + + arr[0] = chr_pid; + arr[1] = st; + + ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, + RESOURCED_PATH_PROCESS, + RESOURCED_INTERFACE_PROCESS, + METHOD_APP_STATUS, + "is", arr, pmlock_check_cb, -1, NULL); + if (ret < 0) + _E("Failed to call dbus method"); +} + +static gboolean pmlock_normal_check(void *data) +{ + pmlock_check(data, "normal"); + return G_SOURCE_CONTINUE; +} + +static gboolean pmlock_dim_check(void *data) +{ + pmlock_check(data, "lcddim"); + return G_SOURCE_CONTINUE; +} + +static gboolean pmlock_off_check(void *data) +{ + pmlock_check(data, "lcdoff"); + return G_SOURCE_CONTINUE; +} + +/* timeout handler */ +gboolean timeout_handler(void *data) +{ + _I("Time out state %s", states[pm_cur_state].name); + if (timeout_src_id) { g_source_remove(timeout_src_id); timeout_src_id = 0; @@ -715,7 +944,7 @@ void reset_timeout(int timeout) if (!display_conf.timeout_enable) return; - _I("Reset timeout(%d ms)", timeout); + _I("Reset timeout(%d ms).", timeout); if (timeout_src_id != 0) { g_source_remove(timeout_src_id); timeout_src_id = 0; @@ -756,7 +985,7 @@ static int get_lcd_timeout_from_settings(void) if (val > 0) states[i].timeout = val; - _I("state=%s timeout=%d ms", states[i].name, + _I("State(%s) timeout(%d) ms", states[i].name, states[i].timeout); } @@ -779,7 +1008,7 @@ static void update_display_time(void) if (custom_normal_timeout > 0) { states[S_NORMAL].timeout = custom_normal_timeout; states[S_LCDDIM].timeout = custom_dim_timeout; - _I("CUSTOM: Timeout(%d ms) and dim(%d ms) are set by normal.", + _I("CUSTOM : timeout is set by normal(%d ms), dim(%d ms)", custom_normal_timeout, custom_dim_timeout); return; } @@ -810,7 +1039,8 @@ static void update_display_time(void) get_dim_timeout(&val); states[S_LCDDIM].timeout = val; - _I("Normal: timeout(%d ms) and dim(%d ms) are set.", states[S_NORMAL].timeout, states[S_LCDDIM].timeout); + _I("Normal: NORMAL timeout is set by %d ms", states[S_NORMAL].timeout); + _I("Normal: DIM timeout is set by %d ms", states[S_LCDDIM].timeout); } static void update_display_locktime(int time) @@ -819,7 +1049,6 @@ static void update_display_locktime(int time) update_display_time(); } - void set_dim_state(bool on) { _I("Dim state is %d.", on); @@ -827,31 +1056,58 @@ void set_dim_state(bool on) states[pm_cur_state].trans(EVENT_INPUT); } +static void broadcast_pm_suspend(void) +{ + int ret; -void lcd_on_direct(enum device_flags flags) + if (pmstate_suspend) + return; + + _D("PM will be changed to sleep."); + + pmstate_suspend = PM_SUSPEND; + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "sleep", + NULL); + if (ret < 0) + _E("Failed to send dbus signal sleep."); +} + +static void broadcast_pm_wakeup(void) { - int ret, call_state; + int ret; + + if (!pmstate_suspend) + return; + + _D("PM is changed to wakeup."); + + pmstate_suspend = PM_WAKEUP; + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "wakeup", + NULL); + if (ret < 0) + _E("Failed to send dbus signal wakeup."); +} + +void lcd_on_direct(enum device_flags flags) +{ if (power_ops.get_power_lock_support() - && pm_cur_state == S_SLEEP) + && pm_cur_state == S_SLEEP) { + broadcast_pm_wakeup(); power_ops.power_lock(); + pm_cur_state = S_NORMAL; + } -#ifdef MICRO_DD - _D("Lcd is on directly."); + _D("lcd is on directly"); gettimeofday(&lcdon_tv, NULL); lcd_on_procedure(LCD_NORMAL, flags); - reset_timeout(DD_LCDOFF_INPUT_TIMEOUT); -#else - ret = vconf_get_int(VCONFKEY_CALL_STATE, &call_state); - if ((ret >= 0 && call_state != VCONFKEY_CALL_OFF) || - (__get_lock_screen_state() == VCONFKEY_IDLE_LOCK)) { - _D("LOCK state, lcd is on directly."); - lcd_on_procedure(LCD_NORMAL, flags); - } else if (ret < 0) - _E("Failed to get vconf value for call state: %d", vconf_get_ext_errno()); - - reset_timeout(display_conf.lcdoff_timeout); -#endif + update_display_locktime(LOCK_SCREEN_INPUT_TIMEOUT); } @@ -863,6 +1119,56 @@ static inline bool check_lcd_is_on(void) return true; } +static int check_lock_condition(enum state_t state) +{ + dd_list *elem; + PmLockNode *t = NULL; + int ret = false; + pid_t owner = getpid(); + + _D("check holdkey block : state of %s", states[state].name); + + DD_LIST_FOREACH(cond_head[state], elem, t) { + if (t->pid != owner && t->background == false) { + ret = true; + _I("state change was blocked by pid(%d)!", t->pid); + break; + } + } + + return ret; +} + +static gboolean timer_refresh_cb(gpointer data) +{ + struct state *st; + int v, ret; + + ret = vconf_get_int(VCONFKEY_HOMESCREEN_WATCHFACE_VISIBILITY, &v); + if (ret < 0) + _E("Failed to get homescreen watchface visibility"); + + if (!v) + return 0; + + /** + * In watchface, it will be applied at 5 seconds for reduce power-supply. + * When the device's screen is another app, it will do turn off after 7 seconds. + */ + if (set_custom_lcdon_timeout(5000) == true) + update_display_time(); + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_NORMAL; + st = &states[pm_cur_state]; + + if (st->action) + st->action(st->timeout); + + return 0; +} + int custom_lcdon(int timeout) { struct state *st; @@ -886,9 +1192,157 @@ int custom_lcdon(int timeout) if (st->action) st->action(st->timeout); + g_idle_add(timer_refresh_cb, NULL); + return 0; } +int custom_lcdoff(enum device_flags flag) +{ + struct state *st; + + check_processes(S_NORMAL); + check_processes(S_LCDDIM); + + /* check holdkey block flag in lock node */ + if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + /* + * When another proccess is normal lock, device is received call then, + * call app can be changed to lcd state by proximity. + * If proximity is near then normal lock will be unlocked. + */ + if (flag & LCD_OFF_BY_PROXIMITY) { + _I("custom lcd off by proximity, delete normal lock"); + delete_condition(S_NORMAL); + } else { + _I("skip custom lcd off"); + return -ECANCELED; + } + } + + _I("custom lcd off by flag(%d)", flag); + if (backlight_ops.get_lcd_power() == DPMS_ON) + lcd_off_procedure(flag); + + if (set_custom_lcdon_timeout(0) == true) + update_display_time(); + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_LCDOFF; + st = &states[pm_cur_state]; + + /* enter action */ + if (st->action) + st->action(st->timeout); + + return 0; +} + +static int display_platform_on(char *reason, int timeout) +{ + struct state *st; + int flag; + int str_len; + + str_len = strlen(reason); + + if (!strncmp(reason, GESTURE_STR, str_len)) + flag = LCD_ON_BY_GESTURE; + else if (!strncmp(reason, EVENT_STR, str_len)) + flag = LCD_ON_BY_EVENT; + else { + _E("Reason is unkown(%s)", reason); + return -EINVAL; + } + + if (timeout <= 0) { + _E("Cannot setting timeout %d", timeout); + return -EINVAL; + } + + if (check_lcd_is_on() == false) + lcd_on_direct(flag); + + _I("platform lcd on by %s (%d ms)", reason, timeout); + if (set_custom_lcdon_timeout(timeout) == true) + update_display_time(); + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_NORMAL; + st = &states[pm_cur_state]; + + /* enter action */ + if (st->action) + st->action(st->timeout); + + return 0; +} + +static int display_platform_off(char *reason) +{ + struct state *st; + int flag; + int str_len; + + str_len = strlen(reason); + + if (!strncmp(reason, GESTURE_STR, str_len)) { + check_processes(S_NORMAL); + check_processes(S_LCDDIM); + + /* check holdkey block flag in lock node */ + if (check_lock_condition(S_NORMAL) || check_lock_condition(S_LCDDIM)) { + _I("skip platform lcd off by gesture"); + return -ECANCELED; + } + flag = LCD_OFF_BY_GESTURE; + } else if (!strncmp(reason, PALM_STR, str_len)) { + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); + + flag = LCD_OFF_BY_PALM; + } else { + _E("Reason is unkown(%s)", reason); + return -EINVAL; + } + + _I("platform lcd off by %s", reason); + if (backlight_ops.get_lcd_power() == DPMS_ON) + lcd_off_procedure(flag); + + /* state transition */ + pm_old_state = pm_cur_state; + pm_cur_state = S_LCDOFF; + st = &states[pm_cur_state]; + + /* enter action */ + if (st->action) + st->action(st->timeout); + + return 0; +} + +int display_platform_control(int type, char *reason, int timeout) +{ + int ret; + + switch (type) { + case PLATFORM_DISPLAY_ON: + ret = display_platform_on(reason, timeout); + break; + case PLATFORM_DISPLAY_OFF: + ret = display_platform_off(reason); + break; + default: + _E("Unkown type(%d)", type); + ret = -EINVAL; + } + + return ret; +} + static void default_proc_change_state_action(enum state_t next, int timeout) { struct state *st; @@ -924,7 +1378,7 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) default_proc_change_state_action(next, -1); break; case S_LCDOFF: - if (backlight_ops.get_lcd_power() != DPMS_OFF) + if (backlight_ops.get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_EVENT); if (set_custom_lcdon_timeout(0)) update_display_time(); @@ -935,7 +1389,14 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) /* at first LCD_OFF and then goto sleep */ /* state transition */ default_proc_change_state_action(S_LCDOFF, TIMEOUT_NONE); + delete_condition(S_NORMAL); + delete_condition(S_LCDDIM); delete_condition(S_LCDOFF); + if (lcdon_broadcast) { + _I("broadcast lcd off signal at non-lcd device"); + broadcast_lcd_off(SIGNAL_PRE, 0); + broadcast_lcd_off(SIGNAL_POST, 0); + } default_proc_change_state_action(S_SLEEP, TIMEOUT_NONE); break; @@ -970,15 +1431,18 @@ static void proc_condition_lock(PMMsg *data) pid_t pid = data->pid; enum state_t state; int holdkey_block; + bool value = true; + unsigned int flags; state = GET_COND_STATE(data->cond); - if (!state) + if (state == S_START) return; + flags = GET_COND_FLAG(data->cond); get_pname(pid, pname); - if (state == S_LCDOFF && - pm_cur_state == S_SLEEP) + if (state == S_LCDOFF && pm_cur_state == S_SLEEP && + power_ops.get_power_lock() == POWER_UNLOCK) proc_change_state(data->cond, INTERNAL_LOCK_PM); if (data->timeout > 0) { @@ -1004,14 +1468,15 @@ static void proc_condition_lock(PMMsg *data) } if (state == S_LCDOFF) - set_process_active(TRUE, pid); + set_process_active(true, pid); + _I("[%s] locked by %5d with %u ms", states[state].name, pid, data->timeout); /* for debug */ - _SD("[%s] Locked by pid=%d process=%s holdkeyblock=%d\n", - states[state].name, pid, pname, holdkey_block); - set_lock_time(pname, state); + _SD("be requested LOCK info pname(%s), holdkeyblock(%d) flags(%d)", + pname, holdkey_block, flags); + set_lock_time(pid, pname, state); - device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)true); + device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value); } static void proc_condition_unlock(PMMsg *data) @@ -1020,24 +1485,28 @@ static void proc_condition_unlock(PMMsg *data) enum state_t state; PmLockNode *tmp; char pname[PATH_MAX]; + bool value = false; + unsigned int flags; state = GET_COND_STATE(data->cond); if (!state) return; + flags = GET_COND_FLAG(data->cond); get_pname(pid, pname); tmp = find_node(state, pid); del_node(state, tmp); if (state == S_LCDOFF) - set_process_active(FALSE, pid); + set_process_active(false, pid); - _SD("[%s] Unlocked by pid=%d process=%s\n", - states[state].name, pid, pname); - set_unlock_time(pname, state); + _I("[%s] unlocked by %5d", states[state].name, pid); + /* for debug */ + _SD("be requested UNLOCK info pname(%s) flag(%d)", pname, flags); + set_unlock_time(pid, state); - device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)false); + device_notify(DEVICE_NOTIFIER_DISPLAY_LOCK, (void *)&value); } static int proc_condition(PMMsg *data) @@ -1056,15 +1525,11 @@ static int proc_condition(PMMsg *data) flags = GET_COND_FLAG(data->cond); if (flags == 0) { /* guard time for suspend */ - if (pm_cur_state == S_LCDOFF) { + if (pm_cur_state == S_LCDOFF) reset_timeout(states[S_LCDOFF].timeout); - _I("Margin timeout(%d ms)", states[S_LCDOFF].timeout); - } } else { - if (flags & PM_FLAG_RESET_TIMER) { + if (flags & PM_FLAG_RESET_TIMER) reset_timeout(states[pm_cur_state].timeout); - _I("Reset timeout(%d ms)", states[pm_cur_state].timeout); - } } if (!timeout_src_id) @@ -1077,13 +1542,13 @@ static int proc_condition(PMMsg *data) int check_processes(enum state_t prohibit_state) { dd_list *elem, *next; - PmLockNode *t; + PmLockNode *t = NULL; int ret = 0; DD_LIST_FOREACH_SAFE(cond_head[prohibit_state], elem, next, t) { if (t->pid < INTERNAL_LOCK_BASE && kill(t->pid, 0) == -1) { - _E("Process(%d) does not exist, delete the REQ" - " - prohibit state=%d.", + _E("%d process does not exist, delete the REQ" + " - prohibit state %d ", t->pid, prohibit_state); if (t->pid == custom_change_pid) { get_lcd_timeout_from_settings(); @@ -1091,6 +1556,7 @@ int check_processes(enum state_t prohibit_state) custom_change_pid = -1; } ret = 1; + set_unlock_time(t->pid, prohibit_state); del_node(prohibit_state, t); } } @@ -1101,7 +1567,7 @@ int check_processes(enum state_t prohibit_state) int check_holdkey_block(enum state_t state) { dd_list *elem; - PmLockNode *t; + PmLockNode *t = NULL; int ret = 0; _I("Check holdkey block: state of %s", states[state].name); @@ -1126,11 +1592,9 @@ int check_holdkey_block(enum state_t state) int delete_condition(enum state_t state) { dd_list *elem, *next; - PmLockNode *t; - pid_t pid; - char pname[PATH_MAX]; + PmLockNode *t = NULL; - _I("Delete condition: state of %s", states[state].name); + _I("delete condition : state of %s", states[state].name); if (!cond_head[state]) return 0; @@ -1140,13 +1604,11 @@ int delete_condition(enum state_t state) g_source_remove(t->timeout_id); t->timeout_id = 0; } - pid = t->pid; if (state == S_LCDOFF) - set_process_active(FALSE, pid); - _I("Delete node of pid(%d).", pid); + set_process_active(false, t->pid); + _I("delete node of pid(%d)", t->pid); + set_unlock_time(t->pid, state); del_node(state, t); - get_pname(pid, pname); - set_unlock_time(pname, state-1); } DD_LIST_FREE_LIST(cond_head[state]); @@ -1188,8 +1650,9 @@ static pm_history pm_history_log[MAX_LOG_COUNT] = {{0, }, }; static int history_count = 0; static const char history_string[PM_LOG_MAX][15] = { - "PRESS", "LONG PRESS", "RELEASE", "LCD ON", "LCD ON FAIL", - "LCD DIM", "LCD DIM FAIL", "LCD OFF", "LCD OFF FAIL", "SLEEP"}; + "PRESS", "LONG PRESS", "RELEASE", "LCD ON", "LCD ON COMPL", "LCD ON FAIL", + "LCD DIM", "LCD DIM FAIL", "LCD OFF", "LCD OFF COMPL", "LCD OFF FAIL", + "LCD FAIL", "SLEEP"}; void pm_history_init() { @@ -1242,7 +1705,7 @@ void pm_history_print(int fd, int count) time_buf); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); } } #endif @@ -1266,13 +1729,13 @@ void print_info(int fd) "===========================\n"); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Timeout Info: Run[%dms] Dim[%dms] Off[%dms]\n", states[S_NORMAL].timeout, states[S_LCDDIM].timeout, states[S_LCDOFF].timeout); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Tran. Locked : %s %s %s\n", (trans_condition & MASK_NORMAL) ? states[S_NORMAL].name : "-", @@ -1280,18 +1743,18 @@ void print_info(int fd) (trans_condition & MASK_OFF) ? states[S_LCDOFF].name : "-"); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Current State: %s\n", states[pm_cur_state].name); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Current Lock Conditions: \n"); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); for (s_index = S_NORMAL; s_index < S_END; s_index++) { DD_LIST_FOREACH(cond_head[s_index], elem, t) { @@ -1302,7 +1765,7 @@ void print_info(int fd) i++, states[s_index].name, t->pid, pname, time_buf); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("Write() failed: %d", errno); } } @@ -1313,37 +1776,39 @@ void print_info(int fd) #endif } -void save_display_log(void) +void save_display_log(char *path) { int fd, ret; char buf[255]; time_t now_time; char time_buf[30]; - _D("Internal state is saved."); + _D("internal state is saved!"); time(&now_time); ctime_r(&now_time, time_buf); - fd = open(PM_STATE_LOG_FILE, O_CREAT | O_TRUNC | O_WRONLY, 0644); + fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0644); if (fd != -1) { snprintf(buf, sizeof(buf), "\npm_state_log now-time : %d(s) %s\n\n", (int)now_time, time_buf); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("write() failed (%d)", errno); snprintf(buf, sizeof(buf), "pm_status_flag: %x\n", pm_status_flag); ret = write(fd, buf, strlen(buf)); if (ret < 0) - _E("write() failed: %d", errno); + _E("write() failed (%d)", errno); - snprintf(buf, sizeof(buf), "screen lock status : %d\n", - __get_lock_screen_state()); - ret = write(fd, buf, strlen(buf)); - if (ret < 0) - _E("write() failed: %d", errno); + if (disp_plgn.get_lock_screen_state ) { + snprintf(buf, sizeof(buf), "screen lock status : %d\n", + disp_plgn.get_lock_screen_state()); + ret = write(fd, buf, strlen(buf)); + if (ret < 0) + _E("write() failed (%d)", errno); + } print_info(fd); close(fd); } @@ -1360,7 +1825,9 @@ void save_display_log(void) */ static void sig_hup(int signo) { - save_display_log(); + _I("received sig hub %d", signo); + + pm_save_logdump(); } int check_lcdoff_direct(void) @@ -1374,6 +1841,9 @@ int check_lcdoff_direct(void) if (pm_cur_state != S_LCDDIM) return false; + if (!display_conf.dimming) + return true; + lock = __get_lock_screen_state(); if (lock != VCONFKEY_IDLE_LOCK && hallic_open) return false; @@ -1388,7 +1858,7 @@ int check_lcdoff_direct(void) else if (ret < 0) _E("Failed to get vconf value for cradle status: %d", vconf_get_ext_errno()); - _D("Goto LCDOFF direct(lock=%d hdmi=%d cradle=%d).", lock, hdmi_state, cradle); + _D("Goto LCDOFF direct: lock(%d) hdmi(%d) cradle(%d).", lock, hdmi_state, cradle); return true; } @@ -1482,22 +1952,10 @@ static inline void stop_lock_timer(void) static void check_lock_screen(void) { - int lock_setting, lock_state, app_state, ret; + int lock_state, ret; stop_lock_timer(); - ret = vconf_get_int(VCONFKEY_CALL_STATE, &app_state); - if (ret >= 0 && app_state != VCONFKEY_CALL_OFF) - goto lcd_on; - else if (ret < 0) - _E("Failed to get vconf value for call state: %d", vconf_get_ext_errno()); - - /* check setting of lock screen is enabled. */ - ret = vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, - &lock_setting); - if (ret < 0) - _E("Failed to get vconf value for screen lock type: %d", vconf_get_ext_errno()); - /* check state of lock */ ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); if (ret < 0 || lock_state == VCONFKEY_IDLE_LOCK) { @@ -1552,10 +2010,12 @@ static int default_action(int timeout) } if (pm_cur_state != pm_old_state && pm_cur_state != S_SLEEP) { - if (power_ops.get_power_lock_support()) + if (power_ops.get_power_lock_support()) { + broadcast_pm_wakeup(); power_ops.power_lock(); + } set_setting_pmstate(pm_cur_state); - device_notify(DEVICE_NOTIFIER_LCD, &pm_cur_state); + device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); } if (pm_old_state == S_NORMAL && pm_cur_state != S_NORMAL) { @@ -1595,11 +2055,11 @@ static int default_action(int timeout) if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) { stop_lock_timer(); /* lcd off state : turn off the backlight */ - if (backlight_ops.get_lcd_power() != DPMS_OFF) + if (backlight_ops.get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); } - if (backlight_ops.get_lcd_power() != DPMS_OFF + if (backlight_ops.get_lcd_power() == DPMS_ON || lcd_paneloff_mode) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); break; @@ -1608,7 +2068,7 @@ static int default_action(int timeout) if (pm_old_state != S_SLEEP && pm_old_state != S_LCDOFF) stop_lock_timer(); - if (backlight_ops.get_lcd_power() != DPMS_OFF) + if (backlight_ops.get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); if (!power_ops.get_power_lock_support()) { @@ -1635,6 +2095,7 @@ go_suspend: #ifdef ENABLE_PM_LOG pm_history_save(PM_LOG_SLEEP, pm_cur_state); #endif + broadcast_pm_suspend(); if (power_ops.get_power_lock_support()) { if (power_ops.enable_autosleep) power_ops.enable_autosleep(); @@ -1642,24 +2103,9 @@ go_suspend: if (power_ops.power_unlock() < 0) _E("Power unlock state error."); } else { - dd_list *elem, *elem_n; - const struct device_ops *dev; - /* Devices Suspend */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->suspend) - dev->suspend(); - } - power_ops.suspend(); - - /* Devices Resume */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->resume) - dev->resume(); - } - - _I("System wakeup."); - disp_plgn.system_wakeup_flag = true; + _I("system wakeup!!"); + system_wakeup_flag = true; /* Resume !! */ if (power_ops.check_wakeup_src() == EVENT_DEVICE) /* system waked up by devices */ @@ -1740,7 +2186,7 @@ static int poll_callback(int condition, PMMsg *data) if (condition == INPUT_POLL_EVENT) { if (pm_cur_state == S_LCDOFF || pm_cur_state == S_SLEEP) - _I("Power key input."); + _I("Input event signal at Display Off"); time(&now); if (last_t != now || pm_cur_state == S_LCDOFF || @@ -1801,11 +2247,13 @@ static int update_setting(int key_idx, int val) } pm_status_flag |= CHRGR_FLAG; } else { - int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; + int bat_state; ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state); - if (ret < 0) + if (ret < 0) { + bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); + } if (low_battery_state(bat_state)) { power_saving_func(true); pm_status_flag |= LOWBT_FLAG; @@ -1878,9 +2326,9 @@ static void check_seed_status(void) { int ret = -1; int tmp = 0; - int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; + int bat_state; int brt = 0; - int lock_state = -1; + int lock_state; /* Charging check */ if ((get_charging_status(&tmp) == 0) && (tmp > 0)) @@ -1899,10 +2347,13 @@ static void check_seed_status(void) } _I("Set brightness(%d) from setting app.", tmp); backlight_ops.set_default_brt(tmp); + backlight_ops.set_brightness(tmp); ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat_state); - if (ret < 0) + if (ret < 0) { + bat_state = VCONFKEY_SYSMAN_BAT_NORMAL; _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); + } if (low_battery_state(bat_state)) { if (!(pm_status_flag & CHRGR_FLAG)) { power_saving_func(true); @@ -1912,9 +2363,10 @@ static void check_seed_status(void) /* lock screen check */ ret = vconf_get_int(VCONFKEY_IDLE_LOCK_STATE, &lock_state); - if (ret < 0) + if (ret < 0) { + lock_state = -1; _E("Failed to get vconf value for idle lock state: %d", vconf_get_ext_errno()); - + } set_lock_screen_state(lock_state); if (lock_state == VCONFKEY_IDLE_LOCK) { states[S_NORMAL].timeout = lock_screen_timeout; @@ -2048,39 +2500,39 @@ void reset_lcd_timeout(GDBusConnection *conn, static int booting_done(void *data) { - static int done; - - if (!data) - return done; + static bool done = false; + if (data != NULL) { done = *(int*)data; - if (!done) - return done; - - _I("Booting done. Release display and power lock."); - if (disp_plgn.pm_unlock_internal) { - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, PM_SLEEP_MARGIN); + if (done) + return 0; + _I("booting done, unlock LCD_OFF"); + if (disp_plgn.pm_unlock_internal) { + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, PM_SLEEP_MARGIN); + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); + } } - return done; + return 0; } -int device_poweroff(void *data) +static int process_background(void *data) { - static int off; + pid_t pid; + PmLockNode *node; - if (!data) - return off; + pid = *(pid_t *)data; - off = *(int *)data; - if (off) - _I("Poweroff"); + node = find_node(S_NORMAL, pid); + if (node) { + node->background = true; + _I("%d pid is background, then PM will be unlocked LCD_NORMAL", pid); + } - return off; + return 0; } -static int process_background(void *data) +static int process_foreground(void *data) { pid_t pid; PmLockNode *node; @@ -2089,7 +2541,7 @@ static int process_background(void *data) node = find_node(S_NORMAL, pid); if (node) { - node->background = true; + node->background = false; _I("Process(%d) is background, then PM will be unlocked LCD_NORMAL.", pid); } @@ -2116,22 +2568,6 @@ static int battery_health_changed(void *data) return 0; } -static int process_foreground(void *data) -{ - pid_t pid; - PmLockNode *node; - - pid = *(pid_t *)data; - - node = find_node(S_NORMAL, pid); - if (node) { - node->background = false; - _I("Process(%d) is foreground, then PM will be maintained locked LCD_NORMAL.", pid); - } - - return 0; -} - static int display_load_config(struct parse_result *result, void *user_data) { struct display_config *c = user_data; @@ -2146,49 +2582,58 @@ static int display_load_config(struct parse_result *result, void *user_data) if (MATCH(result->name, "LockScreenWaitingTime")) { SET_CONF(c->lock_wait_time, atof(result->value)); - _D("'lock wait time' is %.3f.", c->lock_wait_time); + _D("lock wait time is %.3f", c->lock_wait_time); } else if (MATCH(result->name, "LongPressInterval")) { SET_CONF(c->longpress_interval, atof(result->value)); - _D("'long press interval' is %.3f.", c->longpress_interval); + _D("long press interval is %.3f", c->longpress_interval); } else if (MATCH(result->name, "LightSensorSamplingInterval")) { SET_CONF(c->lightsensor_interval, atof(result->value)); - _D("'lightsensor interval' is %.3f.", c->lightsensor_interval); + _D("lightsensor interval is %.3f", c->lightsensor_interval); } else if (MATCH(result->name, "LCDOffTimeout")) { SET_CONF(c->lcdoff_timeout, atoi(result->value)); - _D("'lcdoff timeout' is %d ms.", c->lcdoff_timeout); + _D("lcdoff timeout is %d ms", c->lcdoff_timeout); } else if (MATCH(result->name, "BrightnessChangeStep")) { SET_CONF(c->brightness_change_step, atoi(result->value)); - _D("'brightness change step' is %d.", c->brightness_change_step); + _D("brightness change step is %d", c->brightness_change_step); } else if (MATCH(result->name, "LCDAlwaysOn")) { c->lcd_always_on = (MATCH(result->value, "yes") ? 1 : 0); - _D("'LCD always on' is %d.", c->lcd_always_on); + _D("LCD always on is %d", c->lcd_always_on); + } else if (MATCH(result->name, "Dimming")) { + c->dimming = (MATCH(result->value, "yes") ? 1 : 0); + _D("Dimming is %d", c->dimming); } else if (MATCH(result->name, "ChangedFrameRateAllowed")) { if (strstr(result->value, "setting")) { c->framerate_app[REFRESH_SETTING] = 1; - _D("'framerate app' is setting"); + _D("framerate app is Setting"); } if (strstr(result->value, "all")) { memset(c->framerate_app, 1, sizeof(c->framerate_app)); - _D("'framerate app' is all"); + _D("framerate app is All"); } } else if (MATCH(result->name, "ControlDisplay")) { c->control_display = (MATCH(result->value, "yes") ? 1 : 0); - _D("'ControlDisplay' is %d.", c->control_display); + _D("ControlDisplay is %d", c->control_display); } else if (MATCH(result->name, "PowerKeyDoublePressSupport")) { c->powerkey_doublepress = (MATCH(result->value, "yes") ? 1 : 0); - _D("'PowerKeyDoublePressSupport' is %d.", c->powerkey_doublepress); + _D("PowerKeyDoublePressSupport is %d", c->powerkey_doublepress); } else if (MATCH(result->name, "AccelSensorOn")) { c->accel_sensor_on = (MATCH(result->value, "yes") ? 1 : 0); - _D("'AccelSensorOn' is %d.", c->accel_sensor_on); + _D("AccelSensorOn is %d", c->accel_sensor_on); } else if (MATCH(result->name, "ContinuousSampling")) { c->continuous_sampling = (MATCH(result->value, "yes") ? 1 : 0); - _D("'ContinuousSampling' is %d.", c->continuous_sampling); + _D("ContinuousSampling is %d", c->continuous_sampling); } else if (MATCH(result->name, "TimeoutEnable")) { c->timeout_enable = (MATCH(result->value, "yes") ? true : false); - _D("'Timeout' is %s.", c->timeout_enable ? "enalbed" : "disabled"); + _D("Timeout is %s", c->timeout_enable ? "enalbed" : "disabled"); } else if (MATCH(result->name, "InputSupport")) { c->input_support = (MATCH(result->value, "yes") ? true : false); - _D("'Input' is %s.", c->input_support ? "supported" : "NOT supported"); + _D("Input is %s", c->input_support ? "supported" : "NOT supported"); + } else if (MATCH(result->name, "LockCheckTimeout")) { + SET_CONF(c->lockcheck_timeout, atoi(result->value)); + _D("LockCheckTimeout is %d", c->lockcheck_timeout); + } else if (MATCH(result->name, "AODTSP")) { + c->aod_tsp = (MATCH(result->value, "yes") ? true : false); + _D("TSP control at is %d at aod", c->aod_tsp); } return 0; @@ -2251,9 +2696,58 @@ static int display_probe(void *data) return 0; } +static int input_init_handler(void) +{ + if (!display_conf.input_support) + return 0; + + g_idle_add(init_input, NULL); + + return 0; +} + +static void esd_action(void) +{ + const struct device_ops *touchscreen_ops = NULL; + + _I("ESD on"); + + touchscreen_ops = find_device("touchscreen"); + + if (!check_default(touchscreen_ops)) + touchscreen_ops->stop(NORMAL_MODE); + backlight_ops.off(NORMAL_MODE); + backlight_ops.on(NORMAL_MODE); + if (!check_default(touchscreen_ops)) + touchscreen_ops->start(NORMAL_MODE); +} + +static void lcd_uevent_changed(struct udev_device *dev) +{ + const char *devpath; + const char *action; + + devpath = udev_device_get_devpath(dev); + if (!devpath) + return; + + if (!fnmatch(LCD_ESD_PATH, devpath, 0)) { + action = udev_device_get_action(dev); + if (!strcmp(action, UDEV_CHANGE)) + esd_action(); + } +} + +static const struct uevent_handler lcd_uevent_ops = { + .subsystem = LCD_EVENT_SUBSYSTEM, + .uevent_func = lcd_uevent_changed, + .data = NULL, +}; + static void display_init(void *data) { int ret, i; + unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); int timeout = 0; bool wm_ready; @@ -2269,11 +2763,16 @@ static void display_init(void *data) _W("Failed to load '%s', use default value: %d", DISPLAY_CONF_FILE, ret); + register_kernel_uevent_control(&lcd_uevent_ops); + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); register_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); register_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); - register_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); + register_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); + register_notifier(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, display_auto_brightness_sensing); + + init_save_userlock(); for (i = INIT_SETTING; i < INIT_END; i++) { switch (i) { @@ -2283,15 +2782,14 @@ static void display_init(void *data) case INIT_INTERFACE: if (display_conf.timeout_enable) get_lcd_timeout_from_settings(); - ret = init_sysfs(); + ret = init_sysfs(flags); break; case INIT_POLL: - _I("Input init."); + _I("input init"); pm_callback = poll_callback; - if (display_conf.input_support) - ret = init_input(); - else - ret = 0; + ret = input_init_handler(); + + pm_lock_detector_init(); break; case INIT_DBUS: _I("Dbus init."); @@ -2312,6 +2810,13 @@ static void display_init(void *data) init_lcd_operation(); check_seed_status(); + /* In smd test, TSP should be turned off if display panel is not existed. */ + if (backlight_ops.get_lcd_power() == -ENOENT) { + _I("Display panel is not existed."); + lcd_direct_control(DPMS_OFF, NORMAL_MODE); + exit_lcd_operation(); + } + /* wm_ready needs to be checked * since display manager can be launched later than deviced. * In the case, display cannot be turned on at the first booting */ @@ -2326,33 +2831,35 @@ static void display_init(void *data) trans_table[S_NORMAL][EVENT_TIMEOUT] = S_NORMAL; } - _I("Start Power managing without noti."); - if (power_ops.get_power_lock_support()) - power_ops.power_lock(); - - pm_cur_state = S_NORMAL; - set_setting_pmstate(pm_cur_state); - - if (display_conf.timeout_enable) { - timeout = states[S_NORMAL].timeout; - /* check minimun lcd on time */ - if (timeout < SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT)) - timeout = SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT); - - reset_timeout(timeout); - } + if (flags & WITHOUT_STARTNOTI) { /* start without noti */ + _I("Start Power managing without noti"); + if (power_ops.get_power_lock_support()) { + broadcast_pm_wakeup(); + power_ops.power_lock(); + } + pm_cur_state = S_NORMAL; + vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + + status = DEVICE_OPS_STATUS_START; + if (display_conf.timeout_enable) { + timeout = states[S_NORMAL].timeout; + /* check minimun lcd on time */ + if (timeout < SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT)) + timeout = SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT); + + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, + STAY_CUR_STATE, timeout); + } - status = DEVICE_OPS_STATUS_START; - /* - * Lock lcd off until booting is done. - * deviced guarantees all booting script is executing. - * Last script of booting unlocks this suspend blocking state. - */ - if (disp_plgn.pm_lock_internal) { - disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, - STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); - disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, - STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); + /* + * Lock lcd off until booting is done. + * deviced guarantees all booting script is executing. + * Last script of booting unlocks this suspend blocking state. + */ + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, + STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); } if (display_conf.input_support) @@ -2376,6 +2883,8 @@ static void display_exit(void *data) if (CHECK_OPS(keyfilter_ops, exit)) keyfilter_ops->exit(); + unregister_kernel_uevent_control(&lcd_uevent_ops); + display_ops_exit(NULL); for (i = i - 1; i >= INIT_SETTING; i--) { @@ -2390,8 +2899,8 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); unregister_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); unregister_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); - unregister_notifier(DEVICE_NOTIFIER_POWEROFF, device_poweroff); unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); + unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); exit_input(); break; @@ -2409,6 +2918,8 @@ static void display_exit(void *data) static int display_start(enum device_flags flags) { + const struct display_ops *enhance_ops = NULL; + bool on = true; /* NORMAL MODE */ if (flags & NORMAL_MODE) { if (flags & LCD_PANEL_OFF_MODE) @@ -2417,6 +2928,9 @@ static int display_start(enum device_flags flags) else /* normal lcd on */ backlight_ops.on(flags); + FIND_DISPLAY(enhance_ops, "enhance"); + if (enhance_ops && enhance_ops->func) + enhance_ops->func(RESTORE_ENHANCE_OUTDOOR, &on); return 0; } @@ -2438,7 +2952,7 @@ static int display_start(enum device_flags flags) static int display_stop(enum device_flags flags) { /* NORMAL MODE */ - if (flags & NORMAL_MODE) { + if (flags & NORMAL_MODE || flags & FORCE_OFF_MODE) { backlight_ops.off(flags); return 0; } @@ -2462,7 +2976,7 @@ static int display_status(void) static const struct device_ops display_device_ops = { .priority = DEVICE_PRIORITY_HIGH, - .name = "display", + DECLARE_NAME_LEN("display"), .probe = display_probe, .init = display_init, .exit = display_exit, diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index f44c51a..06e101d 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -29,19 +29,21 @@ #include #include #include -#include +#include #include "ambient-mode.h" #include "core/log.h" #include "core/devices.h" -#include "core/list.h" #include "core/common.h" -#include "display/display-dpms.h" +#include "core/device-notifier.h" #include "util.h" #include "device-interface.h" #include "vconf.h" #include "core.h" #include "device-node.h" +#include "display/display-dpms.h" + +#define SET_SUSPEND_TIME 0.5 #define TOUCH_ON 1 #define TOUCH_OFF 0 @@ -49,7 +51,8 @@ #define LCD_PHASED_MIN_BRIGHTNESS 1 #define LCD_PHASED_MAX_BRIGHTNESS 100 #define LCD_PHASED_CHANGE_STEP 5 -#define LCD_PHASED_DELAY 35000 /* microsecond */ +#define LCD_PHASED_DELAY 10000 /* microsecond */ +#define DUMP_MODE_WAITING_TIME 600000 /* microsecond */ #define POWER_AUTOSLEEP_PATH "/sys/power/autosleep" #define POWER_LOCK_PATH "/sys/power/wake_lock" @@ -57,24 +60,58 @@ #define POWER_WAKEUP_PATH "/sys/power/wakeup_count" #define POWER_STATE_PATH "/sys/power/state" -enum { - POWER_UNLOCK = 0, - POWER_LOCK, -}; +#define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" + +#define GESTURE_STR "gesture" +#define POWERKEY_STR "powerkey" +#define EVENT_STR "event" +#define TOUCH_STR "touch" +#define BEZEL_STR "bezel" +#define TIMEOUT_STR "timeout" +#define PROXIMITY_STR "proximity" +#define PALM_STR "palm" +#define UNKNOWN_STR "unknown" + +#define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" struct _backlight_ops backlight_ops; struct _power_ops power_ops; +static int mainlock_status = POWER_UNLOCK; static bool custom_status; static int custom_brightness; static int force_brightness; static int default_brightness; - +static int vital_support = -2; +static int vital_service; +static bool vital_sleep; +static int dpms_running_state = DPMS_SETTING_DONE; static struct display_device *display_dev; +static guint release_timer; + +struct display_device *display_dev_get(void) +{ + return display_dev; +} + +void dpms_set_running_state(int val) +{ + dpms_running_state = val; +} -static int bl_onoff(int on) +static int bl_onoff(int on, enum device_flags flags) { dpms_set_state(on); + +#ifdef ENABLE_PM_LOG + if (on == DPMS_ON) + pm_history_save(PM_LOG_LCD_ON_COMPLETE, pm_cur_state); + else if (on == DPMS_OFF || on == DPMS_FORCE_OFF) + pm_history_save(PM_LOG_LCD_OFF_COMPLETE, pm_cur_state); + else + pm_history_save(PM_LOG_LCD_CONTROL_FAIL, on); +#endif + return 0; } @@ -85,12 +122,6 @@ static int bl_brt(int brightness, int delay) if (delay > 0) usleep(delay); - if (force_brightness > 0) { - _I("brightness=%d force brightness=%d", - brightness, force_brightness); - brightness = force_brightness; - } - /* Update device brightness */ ret = backlight_ops.set_brightness(brightness); @@ -115,39 +146,96 @@ static int system_enable_autosleep(void) return sys_set_str(POWER_AUTOSLEEP_PATH, "mem"); } -static int system_power_lock(void) +static int vital_mode_support(void) { - dd_list *elem, *elem_n; - const struct device_ops *dev; - int ret; + if (vital_support < 0) { + FILE *fp; + + fp = fopen(FREEZER_VITAL_WAKEUP_CGROUP, "r"); + if (fp == NULL) { + _E("%s open failed", FREEZER_VITAL_WAKEUP_CGROUP); + /* read max 2 times to check if this file exist */ + vital_support++; + return 0; + } + vital_support = 1; + fclose(fp); + } + return vital_support; +} - _I("system power lock."); - ret = sys_set_str(POWER_LOCK_PATH, "mainlock"); +static int suspend_other_process(int type) +{ + int ret = 0; + char buf[8]; + const char *command[1]; - /* Devices Resume */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->resume) - dev->resume(); - } + if (vital_service == type) + return ret; + if (type == VITAL_WAKEUP && vital_service > VITAL_SLEEP) + return ret; + + vital_service = type; + + if (!vital_mode_support()) + return ret; + + if (type == VITAL_SLEEP) { + snprintf(buf, sizeof(buf), "%s", "sleep"); + command[0] = buf; + dbus_handle_method_sync_timeout(RESOURCED_BUS_NAME, + RESOURCED_PATH_FREEZER, + RESOURCED_INTERFACE_FREEZER, + "SetSuspend", + "s", + command, + SET_SUSPEND_TIME*1000); + vital_sleep = true; + } else if (type == VITAL_WAKEUP) { + snprintf(buf, sizeof(buf), "%s", "wakeup"); + command[0] = buf; + ret = dbus_handle_method_async(RESOURCED_BUS_NAME, + RESOURCED_PATH_FREEZER, + RESOURCED_INTERFACE_FREEZER, + "SetSuspend", + "s", command); + } else if (type == VITAL_EXIT) { + snprintf(buf, sizeof(buf), "%s", "exit"); + command[0] = buf; + ret = dbus_handle_method_async(RESOURCED_BUS_NAME, + RESOURCED_PATH_FREEZER, + RESOURCED_INTERFACE_FREEZER, + "SetSuspend", + "s", command); + vital_sleep = false; + } return ret; } -static int system_power_unlock(void) +static int system_power_lock(void) { - dd_list *elem, *elem_n; - const struct device_ops *dev; + _I("system power lock"); + suspend_other_process(VITAL_WAKEUP); + mainlock_status = POWER_LOCK; - /* Devices Suspend */ - DD_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - if (dev->suspend) - dev->suspend(); - } + return sys_set_str(POWER_LOCK_PATH, "mainlock"); +} + +static int system_power_unlock(void) +{ + _I("system power unlock"); + suspend_other_process(VITAL_SLEEP); + mainlock_status = POWER_UNLOCK; - _I("system power unlock."); return sys_set_str(POWER_UNLOCK_PATH, "mainlock"); } +static int system_get_power_lock(void) +{ + return mainlock_status; +} + static int system_get_power_lock_support(void) { static int power_lock_support = -1; @@ -162,7 +250,7 @@ static int system_get_power_lock_support(void) else power_lock_support = true; - _I("system power lock: %s", + _I("System power lock: %s", (power_lock_support ? "support" : "not support")); out: @@ -174,9 +262,6 @@ static int get_lcd_power(void) enum display_state val; int ret; - if (ambient_get_state()) - return DPMS_OFF; - if (!display_dev || !display_dev->get_state) { _E("There is no display device."); return -ENOENT; @@ -186,6 +271,12 @@ static int get_lcd_power(void) if (ret < 0) return ret; + if (val == DISPLAY_ON && ambient_get_state()) + return DPMS_OFF; + + if (dpms_running_state != DPMS_SETTING_DONE) + return dpms_running_state; + switch (val) { case DISPLAY_ON: return DPMS_ON; @@ -202,13 +293,16 @@ static int get_lcd_power(void) bool display_dimstay_check(void) { + if (pm_status_flag & DIM_FLAG) + return true; + if ((pm_status_flag & PWRSV_FLAG) && !(pm_status_flag & BRTCH_FLAG)) return true; return false; } -void change_brightness(int start, int end, int step) +static void change_brightness(int start, int end, int step) { int diff, val; int ret = -1; @@ -226,7 +320,20 @@ void change_brightness(int start, int end, int step) if (prev == end) return; - _D("start=%d end=%d step=%d", start, end, step); + if (pm_status_flag & DIM_MASK) + end = 0; + + _I("start %d end %d step %d", start, end, step); + + if (display_dev && display_dev->set_multi_brightness) { + ret = display_dev->set_multi_brightness(end, step, LCD_PHASED_DELAY); + if (ret < 0) + _E("Failed to set_multi_brightness (%d)", ret); + + backlight_ops.set_brightness(end); + + return; + } diff = end - start; @@ -250,16 +357,15 @@ void change_brightness(int start, int end, int step) static int backlight_on(enum device_flags flags) { int ret = -1; + static int cnt; - _D("LCD on %x", flags); - - ret = bl_onoff(DPMS_ON); - if (ret < 0) - _E("Failed to turn on backlight."); + _I("[DPMS XLIB Backlight] LCD on %x cnt:%d", flags, cnt); - if (flags & LCD_PHASED_TRANSIT_MODE) - change_brightness(LCD_PHASED_MIN_BRIGHTNESS, - default_brightness, LCD_PHASED_CHANGE_STEP); + cnt++; + ret = bl_onoff(DPMS_ON, flags); +#ifdef ENABLE_PM_LOG + pm_history_save(PM_LOG_LCD_ON, pm_cur_state); +#endif return ret; } @@ -267,19 +373,30 @@ static int backlight_on(enum device_flags flags) static int backlight_off(enum device_flags flags) { int ret = -1; + static int cnt, ambient_cnt; - _D("LCD off %x", flags); + if (flags & AMBIENT_MODE) { + _I("[DPMS XLIB Backlight] LCD suspend %x cnt:%d", flags, ambient_cnt); + ambient_cnt++; + + return 0; + } + + _I("[DPMS XLIB Backlight] LCD off %x cnt:%d", flags, cnt); + cnt++; if (flags & LCD_PHASED_TRANSIT_MODE) - change_brightness(default_brightness, + backlight_ops.transit_brt(default_brightness, LCD_PHASED_MIN_BRIGHTNESS, LCD_PHASED_CHANGE_STEP); - if (flags & AMBIENT_MODE) - return 0; + if (flags & FORCE_OFF_MODE) + ret = bl_onoff(DPMS_FORCE_OFF, flags); + else + ret = bl_onoff(DPMS_OFF, flags); - ret = bl_onoff(DPMS_OFF); - if (ret < 0) - _E("Failed to turn off backlight."); +#ifdef ENABLE_PM_LOG + pm_history_save(PM_LOG_LCD_OFF, pm_cur_state); +#endif return ret; } @@ -287,15 +404,8 @@ static int backlight_off(enum device_flags flags) static int backlight_dim(void) { int ret; - int brightness; - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, &brightness); - if (ret < 0) { - _E("Failed to get vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - return -EPERM; - } - - ret = bl_brt(brightness, 0); + ret = backlight_ops.set_brightness(PM_DIM_BRIGHTNESS); #ifdef ENABLE_PM_LOG if (!ret) pm_history_save(PM_LOG_LCD_DIM, pm_cur_state); @@ -335,11 +445,11 @@ static int custom_backlight_update(void) custom_brightness > PM_MAX_BRIGHTNESS) return -EINVAL; - if (display_dimstay_check()) { + if (display_dimstay_check()) ret = backlight_dim(); - } else { - _I("Custom brightness(%d) restored.", custom_brightness); - ret = bl_brt(custom_brightness, 0); + else { + _I("custom brightness restored! %d", custom_brightness); + ret = backlight_ops.set_brightness(custom_brightness); } return ret; @@ -358,16 +468,18 @@ static int set_force_brightness(int level) static int backlight_update(void) { int ret = 0; + int brt; if (get_custom_status()) { - _I("Custom brightness mode. brt no updated."); + _I("custom brightness mode! brt no updated"); return 0; } if (display_dimstay_check()) ret = backlight_dim(); - else - ret = bl_brt(default_brightness, 0); - + else { + brt = backlight_ops.get_default_brt(); + ret = backlight_ops.set_brightness(brt); + } return ret; } @@ -377,7 +489,7 @@ static int backlight_standby(int force) if ((get_lcd_power() == DPMS_ON) || force) { _I("LCD standby"); - ret = bl_onoff(DPMS_STANDBY); + ret = bl_onoff(DPMS_STANDBY, 0); } return ret; @@ -393,6 +505,11 @@ static int set_default_brt(int level) return 0; } +static int get_default_brt(void) +{ + return default_brightness; +} + static int check_wakeup_src(void) { /* TODO if nedded. @@ -470,10 +587,22 @@ static int set_brightness(int val) return max; } + if (force_brightness > 0 && val != PM_DIM_BRIGHTNESS) { + _I("brightness(%d), force brightness(%d)", + val, force_brightness); + val = force_brightness; + } + + if (pm_status_flag & DIM_MASK) + val = 0; + /* Maximum Brightness to users is 100. * Thus real brightness need to be calculated */ val = val * max / 100; + _I("set brightness %d (default:%d)", val, default_brightness); + device_notify(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, (void *)&val); + return display_dev->set_brightness(val); } @@ -550,7 +679,7 @@ static int get_image_effect(enum display_image_effect *effect) enum display_image_effect val; if (!display_dev || !display_dev->get_image_effect) { - _E("There is no display device"); + _E("There is no display device."); return -ENOENT; } @@ -570,7 +699,7 @@ static int set_image_effect(enum display_image_effect effect) int ret; if (!display_dev || !display_dev->set_image_effect) { - _E("There is no display device"); + _E("There is no display device."); return -ENOENT; } @@ -583,6 +712,45 @@ static int set_image_effect(enum display_image_effect effect) return 0; } +static int get_panel_mode(enum display_panel_mode *mode) +{ + int ret; + enum display_panel_mode val; + + if (!display_dev || !display_dev->get_panel_mode) { + _E("there is no display device"); + return -ENOENT; + } + + ret = display_dev->get_panel_mode(&val); + if (ret < 0) { + _E("failed to get panel mode(%d)", ret); + return ret; + } + + *mode = val; + + return 0; +} + +static int set_panel_mode(enum display_panel_mode mode) +{ + int ret; + + if (!display_dev || !display_dev->set_panel_mode) { + _E("there is no display device"); + return -ENOENT; + } + + ret = display_dev->set_panel_mode(mode); + if (ret < 0) { + _E("failed to set panel mode(%d)", ret); + return ret; + } + + return 0; +} + static int get_frame_rate(int *rate) { if (!rate) @@ -634,6 +802,101 @@ static int set_frame_rate(int rate) return display_dev->set_frame_rate(rate); } +/* It was operated only AOD enter & leave */ +static int backlight_transit_state(int state) +{ + int brt, val; + int start, end; + + backlight_ops.get_brightness(&brt); + + if (state == DPMS_OFF) { + start = brt; + end = display_conf.aod_enter_level; + + /* + * The value of backlight_ops.get_brightness is system brightness. + * But when device is LBM, the value is not same with real brightness. + * So it should be read exactly value for transit smooth effect + */ + get_brightness(&val); + + if (val > display_conf.aod_enter_level) + backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + } else { + /* prevent transit effect when another effect is already executed */ + if (brt != display_conf.aod_enter_level) { + _W("effect is already executed brt(%d) aod_level(%d)", + brt, display_conf.aod_enter_level); + return 0; + } + + start = display_conf.aod_enter_level; + end = default_brightness; + backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + } + + return 0; +} + +static gboolean blink_cb(gpointer data) +{ + static bool flag; + + set_brightness(flag ? PM_MAX_BRIGHTNESS : PM_MIN_BRIGHTNESS); + + flag = !flag; + + return G_SOURCE_CONTINUE; +} + +static void blink(int timeout) +{ + static guint timer; + + if (timer) { + g_source_remove(timer); + timer = 0; + } + + if (timeout < 0) { + _E("timeout value is invalid %d", timeout); + return; + } + + if (timeout == 0) { + backlight_update(); + return; + } + + timer = g_timeout_add(timeout, blink_cb, NULL); +} + +static gboolean release_blink_cb(gpointer data) +{ + blink(0); + + release_timer = 0; + return G_SOURCE_REMOVE; +} + +static void release_blink(void) +{ + if (release_timer) { + g_source_remove(release_timer); + release_timer = 0; + } + + release_timer = g_timeout_add(DUMP_MODE_WAITING_TIME, release_blink_cb, NULL); +} + +static void restore_brightness_func(void) +{ + backlight_ops.set_brightness = set_brightness; + backlight_ops.get_brightness = get_brightness; + backlight_ops.transit_brt = change_brightness; +} + static void _init_ops(void) { backlight_ops.off = backlight_off; @@ -642,6 +905,7 @@ static void _init_ops(void) backlight_ops.update = backlight_update; backlight_ops.standby = backlight_standby; backlight_ops.set_default_brt = set_default_brt; + backlight_ops.get_default_brt = get_default_brt; backlight_ops.get_lcd_power = get_lcd_power; backlight_ops.set_custom_status = set_custom_status; backlight_ops.get_custom_status = get_custom_status; @@ -650,16 +914,24 @@ static void _init_ops(void) backlight_ops.set_force_brightness = set_force_brightness; backlight_ops.set_brightness = set_brightness; backlight_ops.get_brightness = get_brightness; + backlight_ops.restore_brightness_func = restore_brightness_func; backlight_ops.get_brightness_by_light_sensor = get_brightness_by_light_sensor; backlight_ops.get_image_effect = get_image_effect; backlight_ops.set_image_effect = set_image_effect; + backlight_ops.get_panel_mode = get_panel_mode; + backlight_ops.set_panel_mode = set_panel_mode; backlight_ops.get_frame_rate = get_frame_rate; backlight_ops.set_frame_rate = set_frame_rate; + backlight_ops.transit_state = backlight_transit_state; + backlight_ops.transit_brt = change_brightness; + backlight_ops.blink = blink; + backlight_ops.release_blink = release_blink; power_ops.suspend = system_suspend; power_ops.enable_autosleep = system_enable_autosleep; power_ops.power_lock = system_power_lock; power_ops.power_unlock = system_power_unlock; + power_ops.get_power_lock = system_get_power_lock; power_ops.get_power_lock_support = system_get_power_lock_support; power_ops.check_wakeup_src = check_wakeup_src; power_ops.get_wakeup_count = get_wakeup_count; @@ -677,12 +949,12 @@ int display_service_load(void) r = hw_get_info(DISPLAY_HARDWARE_DEVICE_ID, (const struct hw_info **)&info); if (r < 0) { - _I("Display shared library is not supported: %d", r); - return -ENODEV; + _I("display shared library is not supported: %d", r); + return 0; } if (!info->open) { - _E("Failed to open display device: open(NULL)"); + _E("Failed to open display device: open(NULL)."); return -EPERM; } @@ -713,17 +985,44 @@ int display_service_free(void) return 0; } -int init_sysfs() +bool vital_mode(void) +{ + return vital_sleep; +} + +static int vital_state_changed(void *data) +{ + int type; + + assert(data); + + type = *(int *)data; + if (type == VITAL_EXIT) + suspend_other_process(VITAL_EXIT); + + return 0; +} + +int init_sysfs(unsigned int flags) { _init_ops(); + register_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); + return 0; } int exit_sysfs(void) { + int fd; const struct device_ops *ops = NULL; + fd = open("/tmp/sem.pixmap_1", O_RDONLY); + if (fd == -1) { + _E("X server disable"); + backlight_on(NORMAL_MODE); + } + backlight_update(); disconnect_interface_with_dpms(); @@ -735,5 +1034,10 @@ int exit_sysfs(void) if (!check_default(ops)) ops->start(NORMAL_MODE); + if (fd != -1) + close(fd); + + unregister_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); + return 0; } diff --git a/plugins/wearable/display/display-info.h b/plugins/wearable/display/display-info.h new file mode 100644 index 0000000..bf368da --- /dev/null +++ b/plugins/wearable/display/display-info.h @@ -0,0 +1,50 @@ +/* + * deviced + * + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __DISPLAY_INFO_H__ +#define __DISPLAY_INFO_H__ + +#define DISPLAY_FUNC(a, b) (((a) << 16) | (b)) +#define ENHANCE_CMD(x) DISPLAY_FUNC('E', (x)) +#define HBM_CMD(x) DISPLAY_FUNC('H', (x)) +#define LBM_CMD(x) DISPLAY_FUNC('L', (x)) + +enum hbm_state { + HBM_SET_STATE = HBM_CMD(1), + HBM_GET_STATE, + HBM_TURN_ON, + HBM_TURN_OFF, + HBM_SET_TIMEOUT_STATE, + HBM_TURN_OFF_STATE, +}; + +enum lbm_state { + LBM_TABLE_LOAD = LBM_CMD(1), +}; + +enum enhance_state { + RESTORE_ENHANCE_OUTDOOR = ENHANCE_CMD(1), +}; + +struct hbmsetstate { + int hbm; + int timeout; +}; + +#endif diff --git a/plugins/wearable/display/enhance.c b/plugins/wearable/display/enhance.c index 4b60807..d799711 100644 --- a/plugins/wearable/display/enhance.c +++ b/plugins/wearable/display/enhance.c @@ -36,6 +36,7 @@ static bool negative_status; static bool greyscale_status; +static bool greysacle_setting; static int enhance_update_state(void) { @@ -70,6 +71,7 @@ static void enhance_greyscale_cb(keynode_t *in_key, void *data) _I("Set greyscale scenario (%d)", val); greyscale_status = val; + greysacle_setting = val; enhance_update_state(); } @@ -108,13 +110,13 @@ static int enhance_ultrapowersaving_changed(void *data) mode = DATA_VALUE_BOOL(data); - greyscale_status = mode; + if (!greysacle_setting) + greyscale_status = mode; enhance_update_state(); _I("Set ultra power saving mode."); return 0; - } static void enhance_init(void *data) @@ -151,6 +153,7 @@ static void enhance_init(void *data) return; } greyscale_status = val; + greysacle_setting = val; state = enhance_update_state(); diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 01e43ff..7835a17 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "ambient-mode.h" #include "util.h" @@ -36,11 +37,11 @@ #include "core/common.h" #include "core/devices.h" #include "core/device-notifier.h" +#include "shared/common.h" #include "power/power-handler.h" #include "led/touch-key.h" #include "apps/apps.h" -#include #ifndef KEY_SCREENLOCK #define KEY_SCREENLOCK 0x98 #endif @@ -50,23 +51,24 @@ #define PREDEF_LEAVESLEEP "leavesleep" #define POWEROFF_ACT "poweroff" +#define PWROFF_POPUP_ACT "pwroff_popup" #define USEC_PER_SEC 1000000 +#define CSC_CONFIG_MODE_RUNNING 1 #define CAPTURE_COMBINATION_INTERVAL 0.5 /* 0.5 second */ - -#define KEY_MAX_DELAY_TIME 700 /* ms */ - -#define KEY_RELEASED 0 -#define KEY_PRESSED 1 -#define KEY_BEING_PRESSED 2 +#define TORCH_COMBINATION_INTERVAL 0.1 /* 0.1 second */ +#define DEFAULT_COMBINATION_INTERVAL 0.1 /* 0.1 second */ #define LONGKEY_PRESSED_TIME 4 /* 4 second */ +#define KEY_MAX_DELAY_TIME 700 /* ms */ + #define SIGNAL_CHANGE_HARDKEY "ChangeHardkey" #define SIGNAL_LCDON_BY_POWERKEY "LCDOnByPowerkey" #define SIGNAL_LCDOFF_BY_POWERKEY "LCDOffByPowerkey" -#define TOUCH_RELEASE (-1) +#define NORMAL_POWER 0 +#define KEY_TEST_MODE_POWER 2 #define GLOVE_MODE 1 @@ -74,19 +76,21 @@ enum key_combination_flags { KEY_COMBINATION_STOP = 0, KEY_COMBINATION_POWERKEY = BIT(0), KEY_COMBINATION_MENUKEY = BIT(1), + KEY_COMBINATION_VOLUMEUP = BIT(2), + KEY_COMBINATION_VOLUMEDOWN = BIT(3), }; enum combination_process { COMBINATION_STOP = KEY_COMBINATION_STOP, COMBINATION_SCREENCAPTURE = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_MENUKEY, + COMBINATION_TORCH = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_VOLUMEUP, + COMBINATION_QUICKTALK = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_VOLUMEDOWN, }; -int __WEAK__ get_glove_state(void); -void __WEAK__ switch_glove_key(int val); - static struct timeval pressed_time; static guint longkey_timeout_id = 0; static guint longkey_restore_id = 0; +static guint displayon_by_powerkey_timeout_id = 0; static int cancel_lcdoff; static int key_combination = KEY_COMBINATION_STOP; static double combination_pressed_time; @@ -95,27 +99,7 @@ static int skip_lcd_off = false; static int skip_combination = false; static int bezel_wakeup = true; static const struct device_ops *touchled; - -static int bezel_wakeup_cb(void *data) -{ - bezel_wakeup = (int)data; - - return 0; -} - -static int booting_done(void *data) -{ - static int done = 0; - - if (!data) - return done; - - done = *(int *)data; - - _I("Booting done(%d)", done); - - return done; -} +static int booting_check = true; static inline int current_state_in_on(void) { @@ -139,7 +123,7 @@ static void pwroff_popup(void) _E("Failed to launch power off popup."); } -static void longkey_pressed() +static void longkey_pressed(void) { unsigned int caps; @@ -225,7 +209,10 @@ static inline bool switch_on_lcd(enum device_flags flags) return false; } - broadcast_lcdon_by_powerkey(); + if (flags & LCD_ON_BY_POWER_KEY) + broadcast_lcdon_by_powerkey(); + else if (flags & LCD_ON_BY_TOUCH) + _I("Display on by Touch_wakeup event"); lcd_on_direct(flags); @@ -249,15 +236,37 @@ static void check_key_combination(struct input_event *pinput) { double press_time, diff_time; press_time = (pinput->time).tv_sec + USEC_TO_SEC((pinput->time).tv_usec); + diff_time = press_time - combination_pressed_time; switch (key_combination) { case COMBINATION_SCREENCAPTURE: - diff_time = press_time - combination_pressed_time; if (diff_time <= CAPTURE_COMBINATION_INTERVAL) { _I("Combination key : SCREENCAPTURE mode"); skip_combination = true; } break; + case COMBINATION_TORCH: + if (diff_time <= TORCH_COMBINATION_INTERVAL) { + /* When torch combination, display control should be not change. */ + if (displayon_by_powerkey_timeout_id) { + g_source_remove(displayon_by_powerkey_timeout_id); + displayon_by_powerkey_timeout_id = 0; + } + _I("Combination key : TORCH mode"); + skip_combination = true; + } else + key_combination = COMBINATION_STOP; + break; + case COMBINATION_QUICKTALK: + if (diff_time <= DEFAULT_COMBINATION_INTERVAL) { + _I("Combination key : QUICK-TALK mode"); + skip_combination = true; + if (longkey_timeout_id) { + g_source_remove(longkey_timeout_id); + longkey_timeout_id = 0; + } + } + break; default: combination_pressed_time = press_time; return; @@ -274,6 +283,12 @@ static void start_key_combination(struct input_event *pinput) case KEY_MENU: key_combination |= KEY_COMBINATION_MENUKEY; break; + case KEY_VOLUMEUP: + key_combination |= KEY_COMBINATION_VOLUMEUP; + break; + case KEY_VOLUMEDOWN: + key_combination |= KEY_COMBINATION_VOLUMEDOWN; + break; default: return; } @@ -295,8 +310,14 @@ static void stop_key_combination(struct input_event *pinput) case KEY_MENU: key_combination &= ~KEY_COMBINATION_MENUKEY; break; + case KEY_VOLUMEUP: + key_combination &= ~KEY_COMBINATION_VOLUMEUP; + break; + case KEY_VOLUMEDOWN: + key_combination &= ~KEY_COMBINATION_VOLUMEDOWN; + break; default: - _E("Thid code(%d) is not combination type", pinput->code); + _E("This code(%d) is not combination type.", pinput->code); break; } } @@ -320,9 +341,8 @@ static int process_menu_key(struct input_event *pinput) return false; _D("No lcd-on capability!"); return true; - } else if (pinput->value == KEY_PRESSED) { + } else if (pinput->value == KEY_PRESSED) switch_on_lcd(LCD_ON_BY_POWER_KEY); - } return false; } @@ -355,7 +375,7 @@ static int decide_lcdoff(void) return false; /* At booting time, display must do not turn off */ - if (!booting_done(NULL)) + if (booting_check) return false; return true; @@ -389,6 +409,37 @@ static int lcdoff_powerkey(void) return ignore; } +static bool key_check_display_on(void) +{ + if (current_state_in_on()) + return false; + + if (backlight_ops.get_lcd_power() == DPMS_ON) { + _W("display power was on"); + return false; + } + + return true; +} + +static gboolean display_on_cb(void *data) +{ + if (displayon_by_powerkey_timeout_id == 0) + return G_SOURCE_REMOVE; + + displayon_by_powerkey_timeout_id = 0; + if (backlight_ops.get_lcd_power() != DPMS_ON || + current_state_in_on() == false) { + broadcast_lcdon_by_powerkey(); + lcd_on_direct(LCD_ON_BY_POWER_KEY); + + if (pm_callback) + (*pm_callback) (INPUT_POLL_EVENT, NULL); + } + + return G_SOURCE_REMOVE; +} + static int process_back_key(struct input_event *pinput) { int ignore = true; @@ -419,9 +470,8 @@ static int process_power_key(struct input_event *pinput) lcdoff_powerkey(); else _D("No lcdoff capability!"); - } else if (skip_lcd_off) { + } else if (skip_lcd_off) ignore = false; - } if (!display_has_caps(caps, DISPLAY_CAPA_LCDON)) ignore = true; @@ -439,7 +489,24 @@ static int process_power_key(struct input_event *pinput) break; case KEY_PRESSED: if (display_has_caps(caps, DISPLAY_CAPA_LCDON)) { - skip_lcd_off = switch_on_lcd(LCD_ON_BY_POWER_KEY); + if (wearable_mode()) + skip_lcd_off = switch_on_lcd(LCD_ON_BY_POWER_KEY); + else { + /* + * LCD does not turn on immediately at mobile. + * It will be turned on after 0.1 second because of torch concept. + */ + skip_lcd_off = key_check_display_on(); + ignore = true; + + if (!displayon_by_powerkey_timeout_id && + backlight_ops.get_lcd_power() != DPMS_ON && + key_combination != COMBINATION_TORCH) { + displayon_by_powerkey_timeout_id = g_timeout_add( + 100, + display_on_cb, NULL); + } + } } else { _D("No lcdon capability!"); skip_lcd_off = false; @@ -458,8 +525,6 @@ static int process_power_key(struct input_event *pinput) LONGKEY_PRESSED_TIME, longkey_restore_cb, NULL); } - if (skip_lcd_off) - ignore = false; cancel_lcdoff = 0; break; @@ -520,10 +585,12 @@ static void process_hardkey_backlight(struct input_event *pinput) _I("Touch is pressed, then hard key is not working!"); return; } - /* Sound & Vibrate only in unlock state */ - if (__get_lock_screen_state() == VCONFKEY_IDLE_UNLOCK - || get_lock_screen_bg_state()) - sound_vibrate_hardkey(); + if (!wearable_mode()) { + /* Sound & Vibrate only in unlock state */ + if (__get_lock_screen_state() == VCONFKEY_IDLE_UNLOCK + || get_lock_screen_bg_state()) + sound_vibrate_hardkey(); + } if (touchled && touchled->execute) { opt = TOUCHLED_PRESS; @@ -543,6 +610,23 @@ static void process_hardkey_backlight(struct input_event *pinput) } } +static void update_vital_state(struct input_event *pinput) +{ + int type; + + /* Change vital state to VITAL_EXIT only if vital mode is active */ + if (!vital_mode()) + return; + + /* Touch or Menu Key Release Event */ + if (pinput->type == EV_ABS || (pinput->type == EV_KEY && + pinput->value == KEY_RELEASED && pinput->code == KEY_MENU)) { + /* Enable all services upon receiving user input, else maintain same state */ + type = VITAL_EXIT; + device_notify(DEVICE_NOTIFIER_VITAL_STATE, &type); + } +} + static int check_key(struct input_event *pinput, int fd) { int ignore = true; @@ -577,6 +661,9 @@ static int check_key(struct input_event *pinput, int fd) break; case KEY_VOLUMEUP: case KEY_VOLUMEDOWN: + if (current_state_in_on()) + ignore = false; + break; case KEY_CAMERA: case KEY_EXIT: case KEY_CONFIG: @@ -642,6 +729,7 @@ static int check_key_filter(void *data, int fd) code = pinput->code; value = pinput->value; + update_vital_state(pinput); ignore = check_key(pinput, fd); restore_custom_brightness(); @@ -650,31 +738,27 @@ static int check_key_filter(void *data, int fd) if (pm_cur_state == S_LCDOFF && bezel_wakeup) { switch_on_lcd(LCD_ON_BY_BEZEL); ignore = false; - } else if (pm_cur_state != S_LCDOFF) { + } else if (pm_cur_state != S_LCDOFF) ignore = false; - } break; case EV_ABS: - if (current_state_in_on()) - ignore = false; - - if (ambient_get_condition() && pinput->value == KEY_PRESSED) { + update_vital_state(pinput); + if (pinput->value == KEY_PRESSED) { switch_on_lcd(LCD_ON_BY_TOUCH); ignore = false; } + if (current_state_in_on()) + ignore = false; + restore_custom_brightness(); - touch_pressed = - (pinput->value == TOUCH_RELEASE ? false : true); + if (pinput->value == KEY_PRESSED) + touch_pressed = true; + else if (pinput->value == KEY_RELEASED) + touch_pressed = false; break; case EV_SW: - if (!get_glove_state || !switch_glove_key) - break; - if (pinput->code == SW_GLOVE && - get_glove_state() == GLOVE_MODE) { - switch_glove_key(pinput->value); - } break; } @@ -684,6 +768,20 @@ static int check_key_filter(void *data, int fd) return 0; } +static int booting_done_cb(void *data) +{ + booting_check = 0; + + return 0; +} + +static int bezel_wakeup_cb(void *data) +{ + bezel_wakeup = (int)data; + + return 0; +} + /* * Default capability * powerkey := LCDON | LCDOFF | POWEROFF @@ -708,15 +806,10 @@ static void keyfilter_init(void) touchled = find_device(TOUCHLED_NAME); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb); } -static void keyfilter_exit(void) -{ - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); -} - static void key_backlight_enable(bool enable) { int opt; @@ -734,7 +827,6 @@ static void key_backlight_enable(bool enable) static const struct display_keyfilter_ops normal_keyfilter_ops = { .init = keyfilter_init, - .exit = keyfilter_exit, .check = check_key_filter, .set_powerkey_ignore = NULL, .powerkey_lcdoff = NULL, diff --git a/plugins/wearable/display/swim.c b/plugins/wearable/display/swim.c index 3c98ed3..2cbb1e7 100644 --- a/plugins/wearable/display/swim.c +++ b/plugins/wearable/display/swim.c @@ -25,38 +25,41 @@ #include "display/display-ops.h" #include -/* CoreApps */ -#define COREAPPS_PATH_HOME "/Org/Tizen/Coreapps/home" -#define COREAPPS_INTERFACE_HOME "org.tizen.coreapps.home" - -#define COREAPPS_PATH_SWIMMODE COREAPPS_PATH_HOME"/swimmode" -#define COREAPPS_INTERFACE_SWIMMODE COREAPPS_INTERFACE_HOME".swimmode" -#define COREAPPS_SIGNAL_STATUS "status" +#define DBUS_COREAPPS_SWIMMODE_PATH "/Org/Tizen/Coreapps/home/swimmode" +#define DBUS_COREAPPS_SWIMMODE_INTERFACE "org.tizen.coreapps.home.swimmode" +#define DBUS_SWIMMODE_MEMBER_STATUS "status" static const struct device_ops *touchscreen_ops; +static int swimmode_status; static int swim_execute(void *data) { - int state, ret; - static int old_state = -1; + int state; if (check_default(touchscreen_ops)) return 0; state = (int) data; - if (old_state == state) + if (swimmode_status == state) return 0; - if (state) { - _D("Stop touchscreen"); - ret = touchscreen_ops->stop(NORMAL_MODE); + swimmode_status = state; + + /** + * When it is enable, TSP have to change to off and it must not control. + * So if this signal is received, tsp mode would be stopped. + * After that, module would be changed to suspend(execute(STATUS_STOP)). + * The opposite case, the module should be enabled first. + */ + if (swimmode_status) { + touchscreen_ops->stop(TOUCH_SCREEN_OFF_MODE); + touchscreen_ops->execute((void *)DEVICE_OPS_STATUS_STOP); } else { - _D("Start touchscreen"); - ret = touchscreen_ops->start(NORMAL_MODE); + touchscreen_ops->execute((void *)DEVICE_OPS_STATUS_START); + touchscreen_ops->start(NORMAL_MODE); } - old_state = state; - return ret; + return 0; } static void swimmode_signal_handler(GDBusConnection *conn, @@ -69,7 +72,7 @@ static void swimmode_signal_handler(GDBusConnection *conn, { int val; pid_t pid; - bool lcd_on = false; + bool lcd_state = false; g_variant_get(param, "(i)", &val); pid = dbus_connection_get_sender_pid(conn, sender); @@ -78,12 +81,12 @@ static void swimmode_signal_handler(GDBusConnection *conn, if (backlight_ops.get_lcd_power != DPMS_ON) { if (disp_plgn.pm_change_internal) disp_plgn.pm_change_internal(INTERNAL_LOCK_SWIM, S_NORMAL); - lcd_on = true; + lcd_state = true; } swim_execute((void *)val); - if (lcd_on) { + if (lcd_state) { if (disp_plgn.pm_change_internal) disp_plgn.pm_change_internal(INTERNAL_LOCK_SWIM, S_LCDOFF); } @@ -91,7 +94,7 @@ static void swimmode_signal_handler(GDBusConnection *conn, static int swim_restore_cb(void *data) { - _I("Restore swim mode"); + _I("Swim mode is restored."); swim_execute((void *)0); return 0; @@ -104,9 +107,9 @@ static void swim_init(void *data) touchscreen_ops = find_device("touchscreen"); ret = subscribe_dbus_signal(NULL, - COREAPPS_PATH_SWIMMODE, - COREAPPS_INTERFACE_SWIMMODE, - COREAPPS_SIGNAL_STATUS, + DBUS_COREAPPS_SWIMMODE_PATH, + DBUS_COREAPPS_SWIMMODE_INTERFACE, + DBUS_SWIMMODE_MEMBER_STATUS, swimmode_signal_handler, NULL, NULL); if (ret <= 0) @@ -116,7 +119,7 @@ static void swim_init(void *data) } static const struct device_ops swim_device_ops = { - .name = "swim", + DECLARE_NAME_LEN("swim"), .init = swim_init, .execute = swim_execute, }; diff --git a/src/battery/battery-time.c b/src/battery/battery-time.c index d7bc170..7966247 100644 --- a/src/battery/battery-time.c +++ b/src/battery/battery-time.c @@ -29,7 +29,6 @@ #include "core/devices.h" #include "core/log.h" #include "core/udev.h" -#include "display/setting.h" #include "display/display-ops.h" #include "power-supply.h" diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index b2a491a..4a2934b 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -160,8 +160,6 @@ static int power_execute(void *data) static const struct device_ops *ops; FIND_DEVICE_INT(ops, POWER_OPS_NAME); - if (NOT_SUPPORT_OPS(ops)) - return -EINVAL; return ops->execute(data); } @@ -910,9 +908,6 @@ static int lowbat_probe(void *data) int ret = -EINVAL; FIND_DEVICE_INT(ops, "power_supply"); - if (NOT_SUPPORT_OPS(ops)) - return ret; - ret = ops->probe(data); if (ret == 0) _I("Support lowbat handler."); @@ -945,7 +940,7 @@ static int lowbat_execute(void *data) } static const struct device_ops lowbat_device_ops = { - .name = "lowbat", + DECLARE_NAME_LEN("lowbat"), .probe = lowbat_probe, .init = lowbat_init, .execute = lowbat_execute, diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 2bf2db1..33e170f 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -1720,7 +1720,7 @@ static void power_supply_exit(void *data) } static const struct device_ops power_supply_ops = { - .name = "power_supply", + DECLARE_NAME_LEN("power_supply"), .probe = power_supply_probe, .init = power_supply_init, .exit = power_supply_exit, diff --git a/src/board/board-info.c b/src/board/board-info.c index 6f72ca8..c8d630c 100644 --- a/src/board/board-info.c +++ b/src/board/board-info.c @@ -99,10 +99,9 @@ static GVariant *dbus_num_handler(GDBusConnection *conn, } p = strchr(info.num, ','); - if (p) { - ++p; - strcpy(info.num, p); - } + if (p) + *p = '\0'; + _D("Num(%s) len(%zu).", info.num, strlen(info.num)); num_out: @@ -162,7 +161,7 @@ static void board_init(void *data) } static const struct device_ops board_device_ops = { - .name = "board", + DECLARE_NAME_LEN("board"), .probe = board_probe, .init = board_init, }; diff --git a/src/control/control.c b/src/control/control.c index 6112898..6aa82cd 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -200,7 +200,7 @@ static void control_init(void *data) } static const struct device_ops control_device_ops = { - .name = "control", + DECLARE_NAME_LEN("control"), .init = control_init, }; diff --git a/src/core/common.c b/src/core/common.c index 0208c5e..fbfa480 100644 --- a/src/core/common.c +++ b/src/core/common.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -110,6 +111,70 @@ int is_vip(int pid) return 0; } +static int remove_dir_internal(int fd) +{ + DIR *dir; + struct dirent *de = NULL; + int subfd, ret = 0; + + dir = fdopendir(fd); + if (!dir) + return -1; + while (1) { + de = readdir(dir); + if (ret != 0 || de == NULL) + break; + if (de->d_type == DT_DIR) { + if (!strncmp(de->d_name, ".", 2) || !strncmp(de->d_name, "..", 3)) + continue; + subfd = openat(fd, de->d_name, O_RDONLY | O_DIRECTORY); + if (subfd < 0) { + _SE("Couldn't openat %s: %d\n", de->d_name, errno); + ret = -1; + continue; + } + if (remove_dir_internal(subfd)) + ret = -1; + + close(subfd); + if (unlinkat(fd, de->d_name, AT_REMOVEDIR) < 0) { + _SE("Couldn't unlinkat %s: %d\n", de->d_name, errno); + ret = -1; + } + } else { + if (unlinkat(fd, de->d_name, 0) < 0) { + _SE("Couldn't unlinkat %s: %d\n", de->d_name, errno); + ret = -1; + } + } + } + closedir(dir); + return ret; +} + +int remove_dir(const char *path, int del_dir) +{ + int fd, ret = 0; + + if (!path) + return -1; + fd = open(path, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW); + if (fd < 0) { + _SE("Couldn't opendir %s: %d\n", path, errno); + return -errno; + } + ret = remove_dir_internal(fd); + close(fd); + + if (del_dir) { + if (rmdir(path)) { + _SE("Couldn't rmdir %s: %d\n", path, errno); + ret = -1; + } + } + return ret; +} + /* * Helper function * - Read from sysfs entry @@ -127,7 +192,7 @@ int sys_check_node(char *path) return 0; } -static int sys_read_buf(char *file, char *buf) +static int sys_read_buf(char *file, char *buf, int len) { int fd; int r; @@ -137,11 +202,13 @@ static int sys_read_buf(char *file, char *buf) if (fd == -1) return -ENOENT; - r = read(fd, buf, BUFF_MAX); - if ((r >= 0) && (r < BUFF_MAX)) + r = read(fd, buf, len); + if ((r >= 0) && (r < len)) buf[r] = '\0'; - else + else { + buf[0] = '\0'; ret = -EIO; + } close(fd); @@ -172,7 +239,10 @@ int sys_get_int(char *fname, int *val) char buf[BUFF_MAX]; int ret = 0; - if (sys_read_buf(fname, buf) == 0) { + if (!fname || !val) + return -EINVAL; + + if (sys_read_buf(fname, buf, sizeof(buf)) == 0) { *val = atoi(buf); } else { *val = -1; @@ -195,16 +265,17 @@ int sys_set_int(char *fname, int val) return ret; } -int sys_get_str(char *fname, char *str) +int sys_get_str(char *fname, char *str, int len) { - char buf[BUFF_MAX] = {0}; + int ret; - if (sys_read_buf(fname, buf) == 0) { - strncpy(str, buf, strlen(buf)+1); - return 0; - } + if (!fname || !str || len < 0) + return -EINVAL; - return -1; + ret = sys_read_buf(fname, str, len); + if (ret < 0) + return ret; + return 0; } int sys_set_str(char *fname, char *val) @@ -336,6 +407,7 @@ void umount_partition_by_kill(const char *path, const int max_retry) retry++; } while (remain > 0 && retry < max_retry); + sync(); pclose(fp); return; @@ -514,7 +586,7 @@ int get_privilege(pid_t pid, char *name, size_t len) attr_len = fread(attr, 1, sizeof(attr) - 1, fp); fclose(fp); - if (attr_len == 0) + if (attr_len <= 0) return -ENOENT; attr[attr_len] = '\0'; @@ -551,6 +623,79 @@ bool is_emulator(void) return emul; } +int do_mkdir(const char *path, mode_t mode) +{ + char d[PATH_MAX]; + size_t s, l; + int r, p; + + assert(path); + + l = strlen(path); + + for (p = 0, s = 0; p < l; p += s + 1) { + s = strcspn(path + p, "/"); + if (!s) + continue; + + assert(PATH_MAX > p + s + 1); + + r = snprintf(d, p + s + 1, "%s", path); + if (r < 0) + return r; + + r = mkdir(d, mode); + if (r < 0 && errno != EEXIST) + return -errno; + } + + return 0; +} + +static int do_copy_internal(const char *src, const char *dst, mode_t mode, bool force) +{ + _cleanup_close_ int rfd = -1, wfd = -1; + char buf[1024]; + ssize_t red; + int r; + + assert(src); + assert(dst); + + if (!force) { + r = access(dst, F_OK); + if (r == 0) + return -EALREADY; + else if (errno != ENOENT) + return -errno; + } + + wfd = open(dst, O_CREAT | O_WRONLY | O_TRUNC, mode); + if (wfd < 0) + return -errno; + + rfd = open(src, O_RDONLY); + if (rfd < 0) + return -errno; + + while ((red = read(rfd, buf, 1024)) > 0) + if (write(wfd, buf, red) != red) + return -errno; + + if (red < 0) + return -errno; + + return 0; +} + +int do_copy_force(const char *src, const char *dst) +{ + assert(src); + assert(dst); + + return do_copy_internal(src, dst, 0644, true); +} + #if 0 int print_open_files(const char *mount_point) { diff --git a/src/core/common.h b/src/core/common.h index 749b6f8..7f471e0 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -25,6 +25,7 @@ #include #include #include +#include #define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) #define BITS_PER_LONG (sizeof(long) * 8) @@ -138,23 +139,55 @@ static inline void safe_free_memory(void** mem) } \ } while (0) +#ifndef _cleanup_ +#define _cleanup_(x) __attribute__((cleanup(x))) +#endif + +#ifndef _cleanup_close_ +static inline void __cleanup_close_func(int *fd) { + if (*fd >= 0) + close(*fd); +} +#define _cleanup_close_ _cleanup_(__cleanup_close_func) +#endif + +#ifndef _cleanup_closedir_ +static inline void __cleanup_closedir_func(DIR **d) { + if (*d) + closedir(*d); +} +#define _cleanup_closedir_ _cleanup_(__cleanup_closedir_func) +#endif + +#ifndef _cleanup_fclose_ +static inline void __cleanup_fclose_func(FILE **f) { + if (*f) + fclose(*f); +} +#define _cleanup_fclose_ _cleanup_(__cleanup_fclose_func) +#endif + FILE * open_proc_oom_score_adj_file(int pid, const char *mode); int get_exec_pid(const char *execpath); int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size); int is_vip(int pid); int run_child(int argc, const char *argv[]); +int remove_dir(const char *path, int del_dir); int sys_check_node(char *path); int sys_get_int(char *fname, int *val); int sys_set_int(char *fname, int val); -int sys_get_str(char *fname, char *str); +int sys_get_str(char *fname, char *str, int len); int sys_set_str(char *fname, char *val); -void umount_partition_by_kill(const char *path, const int max_retry); +int terminate_process(const char *partition, bool force); int mount_check(const char* path); void suspend_path(const char *frz_name, const char *path, const int max_retry); void resume_path(const char *frz_name, const char *path); void print_time(const char *prefix); +void umount_partition_by_kill(const char *path, const int max_retry); int get_privilege(pid_t pid, char *name, size_t len); bool is_emulator(void); +int do_mkdir(const char *path, mode_t mode); +int do_copy_force(const char *src, const char *dst); void watchdog_notify(void); int print_open_files(const char *mount_point); diff --git a/src/core/config-parser.c b/src/core/config-parser.c index 070f2ba..02f07d0 100644 --- a/src/core/config-parser.c +++ b/src/core/config-parser.c @@ -91,8 +91,11 @@ int config_parse(const char *file_name, int cb(struct parse_result *result, /* parse name & value */ end = strchr(start, '='); if (!end || *end != '=') { - ret = -EBADMSG; - goto error; + end = strchr(start, ':'); + if (!end || *end != ':') { + ret = -EBADMSG; + goto error; + } } *end = '\0'; name = trim_str(start); diff --git a/src/core/device-notifier.c b/src/core/device-notifier.c index 6da2212..778a707 100644 --- a/src/core/device-notifier.c +++ b/src/core/device-notifier.c @@ -26,7 +26,7 @@ struct device_notifier { bool deleted; - enum device_notifier_type status; + enum device_notifier_type type; int (*func)(void *data); }; @@ -34,36 +34,77 @@ static dd_list *device_notifier_list; static guint idl; static guint late_init_timer; -#define LATE_INIT_TIME 30 +#define LATE_INIT_WAIT_TIME 30 +#define DEFAULT_LATE_INIT_VALUE (guint)0x0DEF0DEF + #define FIND_NOTIFIER(a, b, d, e, f) \ DD_LIST_FOREACH(a, b, d) \ if (e == d->e && f == (d->f)) -int register_notifier(enum device_notifier_type status, int (*func)(void *data)) +#define NOTIFY_STR(x) [(x)] = __stringify((x)) + +static const char *device_notifier_type_str[DEVICE_NOTIFIER_MAX] = { + NOTIFY_STR(DEVICE_NOTIFIER_DAEMON_RESTARTED), + NOTIFY_STR(DEVICE_NOTIFIER_BOOTING_DONE), + NOTIFY_STR(DEVICE_NOTIFIER_LCD), + NOTIFY_STR(DEVICE_NOTIFIER_LCD_OFF), + NOTIFY_STR(DEVICE_NOTIFIER_LOWBAT), + NOTIFY_STR(DEVICE_NOTIFIER_FULLBAT), + NOTIFY_STR(DEVICE_NOTIFIER_POWER_SUPPLY), + NOTIFY_STR(DEVICE_NOTIFIER_BATTERY_HEALTH), + NOTIFY_STR(DEVICE_NOTIFIER_BATTERY_PRESENT), + NOTIFY_STR(DEVICE_NOTIFIER_BATTERY_OVP), + NOTIFY_STR(DEVICE_NOTIFIER_BATTERY_CHARGING), + NOTIFY_STR(DEVICE_NOTIFIER_DISPLAY_AMBIENT_CONDITION), + NOTIFY_STR(DEVICE_NOTIFIER_DISPLAY_AMBIENT_STATE), + NOTIFY_STR(DEVICE_NOTIFIER_DISPLAY_LOCK), + NOTIFY_STR(DEVICE_NOTIFIER_POWER_RESUME), + NOTIFY_STR(DEVICE_NOTIFIER_POWEROFF), + NOTIFY_STR(DEVICE_NOTIFIER_PROCESS_BACKGROUND), + NOTIFY_STR(DEVICE_NOTIFIER_PROCESS_FOREGROUND), + NOTIFY_STR(DEVICE_NOTIFIER_USB_DEBUG_MODE), + NOTIFY_STR(DEVICE_NOTIFIER_USB_TETHERING_MODE), + NOTIFY_STR(DEVICE_NOTIFIER_EVENT_HANDLER), + NOTIFY_STR(DEVICE_NOTIFIER_EARLY_BOOTING_DONE), + NOTIFY_STR(DEVICE_NOTIFIER_PMQOS), + NOTIFY_STR(DEVICE_NOTIFIER_PMQOS_ULTRAPOWERSAVING), + NOTIFY_STR(DEVICE_NOTIFIER_PMQOS_POWERSAVING), + NOTIFY_STR(DEVICE_NOTIFIER_COOL_DOWN), + NOTIFY_STR(DEVICE_NOTIFIER_VITAL_STATE), + NOTIFY_STR(DEVICE_NOTIFIER_LONGKEY_RESTORE), + NOTIFY_STR(DEVICE_NOTIFIER_UPSM), + NOTIFY_STR(DEVICE_NOTIFIER_UPSM_OFF), + NOTIFY_STR(DEVICE_NOTIFIER_BEZEL_WAKEUP), + NOTIFY_STR(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS), + NOTIFY_STR(DEVICE_NOTIFIER_CRITICAL_LOG), + NOTIFY_STR(DEVICE_NOTIFIER_ULTRAPOWERSAVING), +}; + +int __register_notifier(enum device_notifier_type type, notify_cb func, const char *caller) { dd_list *n; struct device_notifier *notifier; - _I("notifier type=%d func=%p", status, func); + _I("%s, %p by %s", device_notifier_type_str[type], func, caller); if (!func) { - _E("Invalid func address."); + _E("invalid func address! by %s", caller); return -EINVAL; } - FIND_NOTIFIER(device_notifier_list, n, notifier, status, func) { - _E("Function is already registered. type=%d func=%p", - status, func); + FIND_NOTIFIER(device_notifier_list, n, notifier, type, func) { + _E("function is already registered! [%s, %p] by %s", + device_notifier_type_str[type], func, caller); return -EINVAL; } notifier = calloc(1, sizeof(struct device_notifier)); if (!notifier) { - _E("Failed to malloc for notifier."); + _E("Fail to malloc for %s notifier! by %s", device_notifier_type_str[type], caller); return -ENOMEM; } - notifier->status = status; + notifier->type = type; notifier->func = func; DD_LIST_APPEND(device_notifier_list, notifier); @@ -71,18 +112,18 @@ int register_notifier(enum device_notifier_type status, int (*func)(void *data)) return 0; } -int unregister_notifier(enum device_notifier_type status, int (*func)(void *data)) +int __unregister_notifier(enum device_notifier_type type, notify_cb func, const char *caller) { dd_list *n; struct device_notifier *notifier; if (!func) { - _E("Invalid func address."); + _E("invalid func address of %s! by %s", device_notifier_type_str[type], caller); return -EINVAL; } - FIND_NOTIFIER(device_notifier_list, n, notifier, status, func) { - _I("notifier type=%d func=%p", status, func); + FIND_NOTIFIER(device_notifier_list, n, notifier, type, func) { + _I("[%s, %p] by %s", device_notifier_type_str[type], func, caller); notifier->deleted = true; } @@ -106,13 +147,13 @@ static gboolean delete_unused_notifier_cb(void *data) return G_SOURCE_REMOVE; } -void device_notify(enum device_notifier_type status, void *data) +void device_notify(enum device_notifier_type type, void *data) { dd_list *n; struct device_notifier *notifier; DD_LIST_FOREACH(device_notifier_list, n, notifier) { - if (!notifier->deleted && status == notifier->status) { + if (!notifier->deleted && type == notifier->type) { if (notifier->func) notifier->func(data); } @@ -122,13 +163,13 @@ void device_notify(enum device_notifier_type status, void *data) idl = g_idle_add(delete_unused_notifier_cb, NULL); } -void device_notify_once(enum device_notifier_type status, void *data) +void device_notify_once(enum device_notifier_type type, void *data) { dd_list *n; struct device_notifier *notifier; DD_LIST_FOREACH(device_notifier_list, n, notifier) { - if (!notifier->deleted && status == notifier->status) { + if (!notifier->deleted && type == notifier->type) { if (notifier->func) notifier->func(data); @@ -142,7 +183,7 @@ void device_notify_once(enum device_notifier_type status, void *data) static void late_init_stop(void) { - if (!late_init_timer) + if (late_init_timer == 0 || late_init_timer == DEFAULT_LATE_INIT_VALUE) return; g_source_remove(late_init_timer); @@ -157,10 +198,21 @@ static int booting_done(void *data) goto out; done = *(int *)data; - if (!late_init_timer) + if (late_init_timer == 0) return done; late_init_stop(); +out: + return done; +} +static int early_booting_done(void *data) +{ + static int done; + + if (data == NULL) + goto out; + + done = *(int *)data; out: return done; } @@ -170,13 +222,16 @@ static gboolean late_init_timer_cb(void *data) int done; late_init_stop(); + done = early_booting_done(NULL); + if (!done) + device_notify(DEVICE_NOTIFIER_EARLY_BOOTING_DONE, (void *)&done); done = booting_done(NULL); + late_init_timer = 0; if (done) return G_SOURCE_REMOVE; - _I("Late booting done."); + _I("late booting done"); done = TRUE; - device_notify_once(DEVICE_NOTIFIER_BOOTING_DONE, (void *)&done); - + device_notify(DEVICE_NOTIFIER_BOOTING_DONE, (void *)&done); return G_SOURCE_REMOVE; } @@ -186,15 +241,16 @@ static void device_notifier_init(void *data) ret = check_systemd_active(); if (ret == TRUE) { - _I("Restart booting done."); + _I("restart booting done"); return; } register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_EARLY_BOOTING_DONE, early_booting_done); + late_init_timer = g_timeout_add(LATE_INIT_WAIT_TIME, + late_init_timer_cb, NULL); - late_init_timer = g_timeout_add_seconds(LATE_INIT_TIME, - late_init_timer_cb, NULL); if (!late_init_timer) - _E("Failed to set 'late_init_timer'."); + late_init_timer = DEFAULT_LATE_INIT_VALUE; } static void device_notifier_exit(void *data) @@ -203,7 +259,7 @@ static void device_notifier_exit(void *data) } static const struct device_ops notifier_device_ops = { - .name = "notifier", + DECLARE_NAME_LEN("notifier"), .init = device_notifier_init, .exit = device_notifier_exit, }; diff --git a/src/core/device-notifier.h b/src/core/device-notifier.h index fe89950..e1f7b65 100644 --- a/src/core/device-notifier.h +++ b/src/core/device-notifier.h @@ -21,13 +21,14 @@ #define __DEVICE_NOTIFIER_H__ enum device_notifier_type { + DEVICE_NOTIFIER_DAEMON_RESTARTED, DEVICE_NOTIFIER_BOOTING_DONE, DEVICE_NOTIFIER_LCD, - DEVICE_NOTIFIER_TA, + DEVICE_NOTIFIER_LCD_OFF, + DEVICE_NOTIFIER_LCD_OFF_COMPLETE, + DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, DEVICE_NOTIFIER_LOWBAT, DEVICE_NOTIFIER_FULLBAT, - DEVICE_NOTIFIER_TOUCH_HARDKEY, - DEVICE_NOTIFIER_PROCESS_TERMINATED, DEVICE_NOTIFIER_POWER_SUPPLY, DEVICE_NOTIFIER_BATTERY_HEALTH, DEVICE_NOTIFIER_BATTERY_PRESENT, @@ -38,39 +39,25 @@ enum device_notifier_type { DEVICE_NOTIFIER_DISPLAY_LOCK, DEVICE_NOTIFIER_POWER_RESUME, DEVICE_NOTIFIER_POWEROFF, - DEVICE_NOTIFIER_POWEROFF_HAPTIC, DEVICE_NOTIFIER_PROCESS_BACKGROUND, DEVICE_NOTIFIER_PROCESS_FOREGROUND, DEVICE_NOTIFIER_USB_DEBUG_MODE, DEVICE_NOTIFIER_USB_TETHERING_MODE, DEVICE_NOTIFIER_EVENT_HANDLER, - DEVICE_NOTIFIER_CPU_BOOST, DEVICE_NOTIFIER_CPU_BOOST_LOWBAT, DEVICE_NOTIFIER_CPU_BOOST_POWEROFF, /* Experimental for Specific device - contact to deviced owner */ DEVICE_NOTIFIER_EARLY_BOOTING_DONE, - DEVICE_NOTIFIER_SETTING_BRT_CHANGED, - DEVICE_NOTIFIER_HALLIC_OPEN, - DEVICE_NOTIFIER_BATTERY_CRITICAL_POPUP, DEVICE_NOTIFIER_PMQOS, DEVICE_NOTIFIER_PMQOS_ULTRAPOWERSAVING, DEVICE_NOTIFIER_PMQOS_POWERSAVING, - DEVICE_NOTIFIER_PMQOS_LOWBAT, - DEVICE_NOTIFIER_PMQOS_EMERGENCY, - DEVICE_NOTIFIER_PMQOS_POWEROFF, - DEVICE_NOTIFIER_PMQOS_OOM, - DEVICE_NOTIFIER_PMQOS_HALL, DEVICE_NOTIFIER_COOL_DOWN, - DEVICE_NOTIFIER_FLIGHT_MODE, - DEVICE_NOTIFIER_MOBILE_HOTSPOT_MODE, DEVICE_NOTIFIER_VITAL_STATE, - DEVICE_NOTIFIER_LED, - DEVICE_NOTIFIER_SLUGGISH, - DEVICE_NOTIFIER_MONOTONE_HAPTIC, + DEVICE_NOTIFIER_LONGKEY_RESTORE, DEVICE_NOTIFIER_UPSM, - DEVICE_NOTIFIER_UDEV, + DEVICE_NOTIFIER_UPSM_OFF, DEVICE_NOTIFIER_BEZEL_WAKEUP, - DEVICE_NOTIFIER_LONGKEY_RESTORE, + DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, DEVICE_NOTIFIER_ULTRAPOWERSAVING, DEVICE_NOTIFIER_CRITICAL_LOG, DEVICE_NOTIFIER_MAX, @@ -83,12 +70,15 @@ typedef enum _device_notifier_state { /* add more states here */ } device_notifier_state_e; +typedef int (*notify_cb)(void *data); /* * This is for internal callback method. */ -int register_notifier(enum device_notifier_type status, int (*func)(void *data)); -int unregister_notifier(enum device_notifier_type status, int (*func)(void *data)); -void device_notify(enum device_notifier_type status, void *value); +int __register_notifier(enum device_notifier_type type, notify_cb func, const char *caller); +#define register_notifier(type, func) __register_notifier(type, func, __func__) +int __unregister_notifier(enum device_notifier_type type, notify_cb func, const char *caller); +#define unregister_notifier(type, func) __unregister_notifier(type, func, __func__) +void device_notify(enum device_notifier_type type, void *value); void device_notify_once(enum device_notifier_type status, void *data); #endif /* __DEVICE_NOTIFIER_H__ */ diff --git a/src/core/devices.c b/src/core/devices.c index e19f524..6d5480d 100644 --- a/src/core/devices.c +++ b/src/core/devices.c @@ -26,21 +26,16 @@ #include "devices.h" static const struct device_ops default_ops = { - .name = "default-ops", + DECLARE_NAME_LEN("default-ops"), }; -dd_list *dev_head; +static dd_list *dev_head; dd_list *get_device_list_head(void) { return dev_head; } -void remove_device(const struct device_ops *dev) -{ - DD_LIST_REMOVE(dev_head, dev); -} - void add_device(const struct device_ops *dev) { const struct device_ops *ops; @@ -55,13 +50,30 @@ void add_device(const struct device_ops *dev) DD_LIST_APPEND(dev_head, dev); } +void remove_device(const struct device_ops *dev) +{ + DD_LIST_REMOVE(dev_head, dev); +} + const struct device_ops *find_device(const char *name) { dd_list *elem; const struct device_ops *dev; + int len; + + if (!name) { + _E("there is no name"); + return NULL; + } + + len = strlen(name); DD_LIST_FOREACH(dev_head, elem, dev) { - if (!strcmp(dev->name, name)) + if (dev->len != len) + continue; + if (dev->len == 0) + _E("%s len is not defined", dev->name); + if (!strncmp(dev->name, name, len)) return dev; } diff --git a/src/core/devices.h b/src/core/devices.h index 5ee2713..8a8f4cd 100644 --- a/src/core/devices.h +++ b/src/core/devices.h @@ -32,6 +32,7 @@ enum device_priority { enum device_flags { NORMAL_MODE = 0x00000001, AMBIENT_MODE = 0x00000002, + FORCE_OFF_MODE = 0x00000004, CORE_LOGIC_MODE = 0x00010000, TOUCH_SCREEN_OFF_MODE = 0x00020000, LCD_PANEL_OFF_MODE = 0x00040000, @@ -45,11 +46,15 @@ enum device_flags { LCD_OFF_BY_TIMEOUT = 0x04000000, LCD_OFF_BY_EVENT = 0x08000000, LCD_OFF_LATE_MODE = 0x10000000, + LCD_OFF_BY_PROXIMITY = 0x20000000, + LCD_OFF_BY_GESTURE = 0x40000000, + LCD_OFF_BY_PALM = 0x80000000, }; struct device_ops { enum device_priority priority; char *name; + int len; int (*probe) (void *data); void (*init) (void *data); void (*exit) (void *data); @@ -70,8 +75,6 @@ enum device_ops_status { DEVICE_OPS_STATUS_MAX, }; -extern dd_list *dev_head; - void devices_init(void *data); void devices_exit(void *data); @@ -155,4 +158,7 @@ int check_default(const struct device_ops *dev); ret = dev->status ? dev->status() : defaults; \ } while (0) +#define DECLARE_NAME_LEN(x) \ + .name = (x), \ + .len = __builtin_strlen(x) #endif diff --git a/src/core/event-handler.c b/src/core/event-handler.c index 844ceea..a4871b7 100644 --- a/src/core/event-handler.c +++ b/src/core/event-handler.c @@ -99,7 +99,7 @@ static void event_handler_init(void *data) } static const struct device_ops event_handler_device_ops = { - .name = "event-handler", + DECLARE_NAME_LEN("event-handler"), .init = event_handler_init, }; diff --git a/src/core/launch.c b/src/core/launch.c index 136ed47..68007ae 100644 --- a/src/core/launch.c +++ b/src/core/launch.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "log.h" #include "launch.h" @@ -138,13 +139,22 @@ int launch_app_with_nice(const char *file, char *const argv[], pid_t *pid, int _ { int ret; int _pid; + int fd; - if (file == NULL || access(file, X_OK) != 0) { - _E("Launch app error: Invalid input"); + if (file == NULL) { + _E("launch app error: There is no file"); errno = EINVAL; return -1; } + fd = open(file, O_RDONLY); + if (fd == -1) { + _E("launch app error: Invalid file"); + errno = EIO; + return -1; + } + close(fd); + if (pid && (*pid > 0 && kill(*pid, 0) != -1)) return *pid; diff --git a/src/core/log.h b/src/core/log.h index 915e4a9..60c363e 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -32,6 +32,13 @@ #include "shared/log-macro.h" #endif +/* Indirect stringification. Doing two levels allows the parameter to be a + * macro itself. For example, compile with -DFOO=bar, __stringify(FOO) + * converts to "bar". + */ +#define __stringify_1(x...) #x +#define __stringify(x...) __stringify_1(x) + void critical_log_internal(const char *caller, const char *fmt, ...); #define critical_log(fmt, arg...) critical_log_internal(__func__, fmt, ##arg) diff --git a/src/core/sig-handler.c b/src/core/sig-handler.c index e48f1ec..527e6f5 100644 --- a/src/core/sig-handler.c +++ b/src/core/sig-handler.c @@ -68,7 +68,7 @@ static void signal_init(void *data) } static const struct device_ops signal_device_ops = { - .name = "signal", + DECLARE_NAME_LEN("signal"), .init = signal_init, }; diff --git a/src/core/udev.c b/src/core/udev.c index edb630e..40571e0 100644 --- a/src/core/udev.c +++ b/src/core/udev.c @@ -312,7 +312,7 @@ static void udev_exit(void *data) static const struct device_ops udev_device_ops = { .priority = DEVICE_PRIORITY_NORMAL, - .name = "udev", + DECLARE_NAME_LEN("udev"), .init = udev_init, .exit = udev_exit, }; diff --git a/src/core/udev.h b/src/core/udev.h index d432766..267a892 100644 --- a/src/core/udev.h +++ b/src/core/udev.h @@ -59,6 +59,10 @@ #define BLOCK_DEVTYPE_DISK "disk" #define BLOCK_DEVTYPE_PARTITION "partition" +/* lcd esd device */ +#define LCD_EVENT_SUBSYSTEM "lcd_event" +#define LCD_ESD_PATH "*/lcd_event/esd" + /* power supply status */ enum { POWER_SUPPLY_STATUS_UNKNOWN = 0, @@ -76,6 +80,11 @@ enum { POWER_SUPPLY_TYPE_USB, }; +enum dock_type { + DOCK_NONE = 0, + DOCK_SOUND = 7, +}; + struct uevent_handler { char *subsystem; void (*uevent_func)(struct udev_device *dev); diff --git a/src/cpu/pmqos.c b/src/cpu/pmqos.c index 49b93ee..421e1bd 100644 --- a/src/cpu/pmqos.c +++ b/src/cpu/pmqos.c @@ -524,7 +524,7 @@ static void pmqos_exit(void *data) } static const struct device_ops pmqos_device_ops = { - .name = "pmqos", + DECLARE_NAME_LEN("pmqos"), .probe = pmqos_probe, .init = pmqos_init, .exit = pmqos_exit, diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index 7192f44..1469d5c 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -37,12 +37,13 @@ #define CLOCK_START "clockstart" #define CLOCK_END "clockend" +#define CLOCK_CHANGED "clockchanged" #define TIMEOUT_NONE (-1) #define AMBIENT_CLOCK_WAITING_TIME 5000 /* ms */ static int ambient_state; +static int ambient_condition; /* Setting Value */ static pid_t ambient_pid; /* Ambient Clock pid */ -static int ambient_condition; static unsigned int update_count; void broadcast_ambient_state(int state) @@ -57,7 +58,7 @@ void broadcast_ambient_state(int state) signal, NULL); if (ret < 0) - _E("Failed to send dbus signal(%s)", signal); + _E("Failed to send dbus signal(%s).", signal); } int ambient_get_condition(void) @@ -82,7 +83,8 @@ static void ambient_set_condition(keynode_t *key_nodes, void *data) val = vconf_keynode_get_bool(key_nodes); if (val != ambient_condition) { if (backlight_ops.get_lcd_power() != DPMS_ON) - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } ambient_condition = val; @@ -144,7 +146,8 @@ void ambient_check_invalid_state(pid_t pid) /* If lcd_power is on and ambient state is true * when pm state is changed to sleep, * deviced doesn't get the clock signal. - * deviced just turns off lcd in this case. */ + * deviced just turns off lcd in this case. + */ reset_timeout(TIMEOUT_NONE); ambient_set_state(false); @@ -212,14 +215,14 @@ static void ambient_lcdoff_signal_handler(GDBusConnection *conn, gpointer data) { if (ambient_state == false) { - _E("It is not alpm mode"); + _E("It is not alpm mode."); return; } if (disp_plgn.pm_lock_internal) disp_plgn.pm_lock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, GOTO_STATE_NOW, 0); - _I("Display off in suspend state"); + _I("Display off in suspend state."); ambient_set_state(false); lcd_direct_control(DPMS_OFF, NORMAL_MODE); @@ -233,8 +236,7 @@ static void ambient_init(void *data) { int ret; - ret = vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, - &ambient_condition); + ret = vconf_get_bool(VCONFKEY_SETAPPL_AMBIENT_MODE_BOOL, &ambient_condition); if (ret < 0) { _E("Failed to get vconf value for ambient mode: %d", vconf_get_ext_errno()); ambient_condition = false; @@ -268,4 +270,3 @@ static const struct display_ops ambient_ops = { }; DISPLAY_OPS_REGISTER(&ambient_ops) - diff --git a/src/display/auto-brightness.c b/src/display/auto-brightness.c index a9d4100..c2207db 100644 --- a/src/display/auto-brightness.c +++ b/src/display/auto-brightness.c @@ -521,7 +521,7 @@ static void update_auto_brightness(bool update) static int prepare_lsensor(void *data) { int status, ret; - int brt = -1; + int brt; ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); @@ -535,9 +535,10 @@ static int prepare_lsensor(void *data) set_alc_function, NULL); ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_AUTOMATIC_BRIGHTNESS, &brt); - if (ret < 0) + if (ret < 0) { + brt = -1; _E("Failed to get vconf value for automatic lcd brightness: %d", vconf_get_ext_errno()); - + } if (brt < PM_MIN_BRIGHTNESS || brt > PM_MAX_BRIGHTNESS) { _E("Failed to get automatic brightness."); } else { diff --git a/src/display/core.h b/src/display/core.h index 1bb77df..166eb2a 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -28,6 +28,7 @@ #include "device-interface.h" #include "setting.h" +#define WITHOUT_STARTNOTI 0x1 #define MASK_BIT 0x7 /* 111 */ #define MASK_NORMAL 0x1 /* 001 */ #define MASK_DIM 0x2 /* 010 */ @@ -40,10 +41,13 @@ #define BRTCH_FLAG 0x00002000 #define PWROFF_FLAG 0x00004000 #define DIMSTAY_FLAG 0x00008000 +#define DIM_FLAG 0x00010000 #define BATTERY_FLAG 0x00020000 +#define COOLDOWN_FLAG 0x00040000 #define DEFAULT_NORMAL_TIMEOUT 30 +#define DIM_MASK 0x000f0000 #define MASK32 0xffffffff #define CHECK_OPS(d, op) (d != NULL && d->op != NULL) @@ -57,11 +61,14 @@ enum pm_log_type { PM_LOG_KEY_LONG_PRESS, PM_LOG_KEY_RELEASE, PM_LOG_LCD_ON, /* lcd log */ + PM_LOG_LCD_ON_COMPLETE, PM_LOG_LCD_ON_FAIL, PM_LOG_LCD_DIM, PM_LOG_LCD_DIM_FAIL, PM_LOG_LCD_OFF, + PM_LOG_LCD_OFF_COMPLETE, PM_LOG_LCD_OFF_FAIL, + PM_LOG_LCD_CONTROL_FAIL, PM_LOG_SLEEP, PM_LOG_MAX }; @@ -120,14 +127,19 @@ struct display_config { int lcdoff_timeout; int brightness_change_step; int lcd_always_on; + int dimming; int framerate_app[4]; int control_display; int powerkey_doublepress; int alpm_on; int accel_sensor_on; int continuous_sampling; + int lockcheck_timeout; + int aod_enter_level; + bool aod_tsp; bool timeout_enable; bool input_support; + bool touch_wakeup; }; /* @@ -144,6 +156,7 @@ struct display_function_info { int (*set_autobrightness_min)(int, char *); GBusNameAppearedCallback reset_autobrightness_min; int (*face_detection)(int, int, int); + void (*set_brightness_level)(int); }; extern struct display_function_info display_info; @@ -168,6 +181,7 @@ void reset_lcd_timeout(GDBusConnection *conn, const gchar *sender, const gchar *unique_name, gpointer data); +int check_lcdoff_lock_state(void); /* setting.c */ int get_lock_screen_bg_state(void); @@ -186,29 +200,37 @@ void change_proc_change_state(int (*func)(unsigned int cond, pid_t pid)); bool check_lock_state(int state); int delete_condition(enum state_t state); +int custom_lcdoff(enum device_flags flag); +int display_platform_control(int type, char *reason, int timeout); void update_lcdoff_source(int source); int low_battery_state(int val); int set_lcd_timeout(int on, int dim, int holdkey_block, const char *name); -void save_display_log(void); +void save_display_log(char *path); int custom_lcdon(int timeout); void set_stay_touchscreen_off(int val); void set_lcd_paneloff_mode(int val); void lcd_on_direct(enum device_flags flags); void lcd_on_procedure(int state, enum device_flags flag); void lcd_off_procedure(enum device_flags flag); +void lcd_direct_control(enum dpms_state state, int flags); int check_holdkey_block(enum state_t state); bool touch_event_blocked(void); -int device_poweroff(void *data); void broadcast_lcd_off_late(enum device_flags flags); void set_dim_state(bool on); void reset_timeout(int timeout); +/* auto-brightness.c */ +void set_brightness_changed_state(void); + /* poll.c */ int check_dimstay(int next_state, int flag); /* display-dbus.c */ int init_pm_dbus(void); +/* slave-logging.c */ +int save_pmlock(enum state_t state, bool on, pid_t pid); + /** * @} */ diff --git a/src/display/device-interface.h b/src/display/device-interface.h index 81e8150..2806bc0 100644 --- a/src/display/device-interface.h +++ b/src/display/device-interface.h @@ -28,11 +28,14 @@ #include #include "core/devices.h" +#define FLAG_X_DPMS 0x2 + #define DEFAULT_DISPLAY 0 #define PM_MAX_BRIGHTNESS 100 #define PM_MIN_BRIGHTNESS 1 -#define PM_DEFAULT_BRIGHTNESS 60 +#define PM_DEFAULT_BRIGHTNESS 80 +#define PM_DIM_BRIGHTNESS 0 #define DISP_INDEX_SHIFT 16 #define DISP_CMD(prop, index) ((index << DISP_INDEX_SHIFT) | prop) @@ -41,6 +44,8 @@ #define DEFAULT_DISPLAY_MAX_BRIGHTNESS 100 #define DEFAULT_DISPLAY_MAX_DIM_BRIGHTNESS 50 +#define DPMS_SETTING_DONE -1 + /* * Event type enumeration */ @@ -51,10 +56,22 @@ enum { EVENT_END, }; -int init_sysfs(void); + +/* + * Vital state enumeration + */ +enum vital_state { + VITAL_SLEEP, /* suspend state */ + VITAL_WAKEUP, /* resume state */ + VITAL_DISPLAY_WAKEUP, + VITAL_EXIT, +}; + +int init_sysfs(unsigned int); int exit_sysfs(void); int display_service_load(void); int display_service_free(void); +bool vital_mode(void); struct _backlight_ops { int (*off)(enum device_flags); @@ -63,6 +80,7 @@ struct _backlight_ops { int (*update)(void); int (*standby)(int); int (*set_default_brt)(int level); + int (*get_default_brt)(void); int (*get_lcd_power)(void); int (*set_custom_status)(bool on); bool (*get_custom_status)(void); @@ -71,11 +89,18 @@ struct _backlight_ops { int (*set_force_brightness)(int level); int (*set_brightness)(int val); int (*get_brightness)(int *val); + void (*restore_brightness_func)(void); int (*get_brightness_by_light_sensor)(float lmax, float lmin, float light, int *brt); int (*get_image_effect)(enum display_image_effect *effect); int (*set_image_effect)(enum display_image_effect effect); + int (*get_panel_mode)(enum display_panel_mode *mode); + int (*set_panel_mode)(enum display_panel_mode mode); int (*get_frame_rate)(int *rate); int (*set_frame_rate)(int rate); + int (*transit_state)(int state); + void (*transit_brt)(int start, int end, int step); + void (*blink)(int timeout); + void (*release_blink)(void); }; struct _power_ops { @@ -83,6 +108,7 @@ struct _power_ops { int (*enable_autosleep)(void); int (*power_lock)(void); int (*power_unlock)(void); + int (*get_power_lock)(void); int (*get_power_lock_support)(void); int (*check_wakeup_src)(void); int (*get_wakeup_count)(int *cnt); @@ -97,6 +123,17 @@ enum dpms_state { DPMS_STANDBY, /* Blanked, low power */ DPMS_SUSPEND, /* Blanked, lower power */ DPMS_OFF, /* Shut off, awaiting activity */ + DPMS_FORCE_OFF,/* Force Shut off */ +}; + +enum mainlock_state { + POWER_UNLOCK = 0, + POWER_LOCK, }; + +struct display_device *display_dev_get(void); +bool display_dimstay_check(void); +void dpms_set_running_state(int val); + #endif diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 8e1a2eb..773825f 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -25,50 +25,56 @@ #include #include -#include -#include #include #include +#include #include "ambient-mode.h" #include "core/log.h" #include "util.h" #include "core.h" +#include "lock-detector.h" #include "core/common.h" #include "core/devices.h" #include "core/device-idler.h" +#include "core/device-notifier.h" #include "apps/apps.h" #include "dd-display.h" #include "display-actor.h" #include "display-ops.h" -#include #define SIGNAL_HOMESCREEN "HomeScreen" +#define AUL_APPSTATUS_PATH "/Org/Tizen/Aul/AppStatus" +#define AUL_APPSTATUS_INTERFACE "org.tizen.aul.AppStatus" +#define APP_CHANGE_STATE "AppStatusChange" + +#define TELEPHONY_PATH "/org/tizen/telephony" +#define TELEPHONY_INTERFACE_SIM "org.tizen.telephony.Manager" +#define SIGNAL_SIM_STATUS "SimInserted" +#define SIM_CARD_NOT_PRESENT (0x0) + +#ifndef VCONFKEY_LCD_BRIGHTNESS_INIT +#define VCONFKEY_LCD_BRIGHTNESS_INIT "db/private/deviced/lcd_brightness_init" +#endif + +#define DISPLAY_DIM_BRIGHTNESS 0 #define DUMP_MODE_WATING_TIME 600000 +#define LCDOFF_PROXI_STR "proximity" +#define LCDOFF_GESTURE_STR "gesture" + #define EXPIRED_POPUP_TYPE_POWER "power_lock_expired" #define EXPIRED_POPUP_PID "_APP_PID_" #define EXPIRED_POPUP_COMM "_APP_COMM_" #define EXPIRED_POPUP_ID "_REQUEST_ID_" -#define CHECK_POWEROFF() \ - do { \ - if (device_poweroff(NULL)) { \ - _E("Ignore requests for display during power off"); \ - return g_variant_new("(i)", -EBUSY); \ - } \ - } while (0) - GVariant *dbus_start(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) { static const struct device_ops *display_device_ops = NULL; - if (device_poweroff(NULL)) - goto out; - if (!display_device_ops) display_device_ops = find_device("display"); if (NOT_SUPPORT_OPS(display_device_ops)) @@ -85,9 +91,6 @@ GVariant *dbus_stop(GDBusConnection *conn, { static const struct device_ops *display_device_ops = NULL; - if (device_poweroff(NULL)) - goto out; - if (!display_device_ops) display_device_ops = find_device("display"); if (NOT_SUPPORT_OPS(display_device_ops)) @@ -112,8 +115,6 @@ GVariant *dbus_lockstate(GDBusConnection *conn, int ret = 0; unsigned int caps; - CHECK_POWEROFF(); - g_variant_get(param, "(sssi)", &state_str, &option1_str, &option2_str, &timeout); if (!state_str || timeout < 0) { @@ -139,7 +140,7 @@ GVariant *dbus_lockstate(GDBusConnection *conn, else if (!strcmp(state_str, PM_LCDOFF_STR)) state = LCD_OFF; else { - _E("%s state is invalid, dbus ignored!", state_str); + _E("%s state is invalid, dbus ignored.", state_str); ret = -EINVAL; goto out; } @@ -199,8 +200,6 @@ GVariant *dbus_unlockstate(GDBusConnection *conn, int flag; int ret = 0; - CHECK_POWEROFF(); - g_variant_get(param, "(ss)", &state_str, &option_str); if (!state_str) { @@ -221,8 +220,6 @@ GVariant *dbus_unlockstate(GDBusConnection *conn, if (!strcmp(state_str, PM_LCDON_STR)) state = LCD_NORMAL; - else if (!strcmp(state_str, PM_LCDDIM_STR)) - state = LCD_DIM; else if (!strcmp(state_str, PM_LCDOFF_STR)) state = LCD_OFF; else { @@ -257,11 +254,9 @@ GVariant *dbus_changestate(GDBusConnection *conn, char *state_str; pid_t pid; int state; - int ret = 0; + int ret = 0, len; unsigned int caps; - CHECK_POWEROFF(); - g_variant_get(param, "(s)", &state_str); if (!state_str) { @@ -280,6 +275,12 @@ GVariant *dbus_changestate(GDBusConnection *conn, goto out; } + len = strlen(state_str); + if (len == 0) { + ret = -EINVAL; + goto out; + } + if (!strcmp(state_str, PM_LCDON_STR)) state = LCD_NORMAL; else if (!strcmp(state_str, PM_LCDDIM_STR)) @@ -312,7 +313,7 @@ GVariant *dbus_changestate(GDBusConnection *conn, } if (check_dimstay(state, GOTO_STATE_NOW) == true) { - _E("LCD state can not be changed to OFF state!"); + _E("LCD state can not be changed to OFF state! by %d", pid); ret = -EBUSY; goto out; } @@ -333,8 +334,6 @@ GVariant *dbus_getdisplaycount(GDBusConnection *conn, { int ret; - CHECK_POWEROFF(); - ret = DEFAULT_DISPLAY_COUNT; return g_variant_new("(i)", ret); @@ -346,8 +345,6 @@ GVariant *dbus_getmaxbrightness(GDBusConnection *conn, { int ret, state; - CHECK_POWEROFF(); - g_variant_get(param, "(i)", &state); if (state == DISPLAY_STATE_NORMAL) ret = DEFAULT_DISPLAY_MAX_BRIGHTNESS; @@ -365,8 +362,6 @@ GVariant *dbus_setmaxbrightness(GDBusConnection *conn, { int ret; - CHECK_POWEROFF(); - ret = -ENOTSUP; return g_variant_new("(i)", ret); @@ -378,8 +373,6 @@ GVariant *dbus_getbrightness(GDBusConnection *conn, { int brt = -1, state, ret; - CHECK_POWEROFF(); - g_variant_get(param, "(i)", &state); if (state == DISPLAY_STATE_NORMAL) @@ -388,8 +381,10 @@ GVariant *dbus_getbrightness(GDBusConnection *conn, ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_DIM_BRIGHTNESS, &brt); if (ret < 0) _E("Failed to get vconf value for lcd dim brightness: %d", vconf_get_ext_errno()); - } else - ret = -EINVAL; + } else { + ret = backlight_ops.get_default_brt(); + brt = 0; + } if (ret >= 0) ret = brt; @@ -405,8 +400,6 @@ GVariant *dbus_setbrightness(GDBusConnection *conn, { int state, brt, autobrt, ret = 0, caps; - CHECK_POWEROFF(); - caps = display_get_caps(DISPLAY_ACTOR_API); if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { @@ -418,7 +411,7 @@ GVariant *dbus_setbrightness(GDBusConnection *conn, g_variant_get(param, "(ii)", &state, &brt); //Check if brt is same with DIM - if (brt == 0) { + if (brt == DISPLAY_DIM_BRIGHTNESS) { _E("application can not set this value(DIM VALUE:%d)", brt); ret = -EPERM; goto error; @@ -436,6 +429,9 @@ GVariant *dbus_setbrightness(GDBusConnection *conn, goto error; } + pm_status_flag &= ~DIM_MASK; + + backlight_ops.set_default_brt(brt); if (state == DISPLAY_STATE_NORMAL) { ret = backlight_ops.set_brightness(brt); if (ret < 0) @@ -469,8 +465,6 @@ GVariant *dbus_holdbrightness(GDBusConnection *conn, { int brt, autobrt, ret, caps; - CHECK_POWEROFF(); - caps = display_get_caps(DISPLAY_ACTOR_API); if (!display_has_caps(caps, DISPLAY_CAPA_BRIGHTNESS)) { @@ -481,6 +475,12 @@ GVariant *dbus_holdbrightness(GDBusConnection *conn, g_variant_get(param, "(i)", &brt); + if (brt == DISPLAY_DIM_BRIGHTNESS) { + _E("application can not set this value(DIM VALUE:%d)", brt); + ret = -EPERM; + goto error; + } + ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &autobrt); if (ret < 0) { _E("Failed to get vconf value for automatic brightness: %d", vconf_get_ext_errno()); @@ -514,8 +514,6 @@ GVariant *dbus_releasebrightness(GDBusConnection *conn, { int bat, charger, changed, setting, brt, autobrt, ret = 0; - CHECK_POWEROFF(); - ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &bat); if (ret < 0) { _E("Failed to get vconf value for battery status low: %d", vconf_get_ext_errno()); @@ -588,8 +586,6 @@ GVariant *dbus_setrefreshrate(GDBusConnection *conn, { int app, val, ret, control; - CHECK_POWEROFF(); - g_variant_get(param, "(ii)", &app, &val); if (app < 0 || app >= ARRAY_SIZE(display_conf.framerate_app) || val < 0) { @@ -628,8 +624,6 @@ GVariant *dbus_setautobrightnessmin(GDBusConnection *conn, pid_t pid; int id = 0; - CHECK_POWEROFF(); - if (!display_info.set_autobrightness_min) { ret = -EIO; goto error; @@ -662,8 +656,6 @@ GVariant *dbus_setlcdtimeout(GDBusConnection *conn, pid_t pid; int id = 0; - CHECK_POWEROFF(); - g_variant_get(param, "(iii)", &on, &dim, &holdkey_block); pid = dbus_connection_get_sender_pid(conn, sender); @@ -690,8 +682,6 @@ GVariant *dbus_lockscreenbgon(GDBusConnection *conn, int ret = 0; char *on = NULL; - CHECK_POWEROFF(); - g_variant_get(param, "(s)", &on); if (!strcmp(on, "true")) { @@ -714,8 +704,6 @@ GVariant *dbus_dumpmode(GDBusConnection *conn, int ret = 0; char *on; - CHECK_POWEROFF(); - g_variant_get(param, "(s)", &on); if (!strcmp(on, "on")) { @@ -736,8 +724,7 @@ GVariant *dbus_savelog(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) { - if (!device_poweroff(NULL)) - save_display_log(); + pm_save_logdump(); return dbus_handle_new_g_variant_tuple(); } @@ -748,8 +735,6 @@ GVariant *dbus_powerkeyignore(GDBusConnection *conn, int ret = 0; int on; - CHECK_POWEROFF(); - g_variant_get(param, "(i)", &on); if (CHECK_OPS(keyfilter_ops, set_powerkey_ignore)) @@ -764,8 +749,6 @@ GVariant *dbus_powerkeylcdoff(GDBusConnection *conn, { int ret; - CHECK_POWEROFF(); - if (CHECK_OPS(keyfilter_ops, powerkey_lcdoff)) ret = keyfilter_ops->powerkey_lcdoff(); else @@ -781,8 +764,6 @@ GVariant *dbus_customlcdon(GDBusConnection *conn, int ret = 0; int timeout; - CHECK_POWEROFF(); - g_variant_get(param, "(i)", &timeout); ret = custom_lcdon(timeout); @@ -790,6 +771,47 @@ GVariant *dbus_customlcdon(GDBusConnection *conn, return g_variant_new("(i)", ret); } +GVariant *dbus_customlcdoff(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + int ret = 0; + enum device_flags flag; + char *reason_str; + + g_variant_get(param, "(s)", &reason_str); + + if (!strcmp(reason_str, LCDOFF_PROXI_STR)) + flag = LCD_OFF_BY_PROXIMITY; + else if (!strcmp(reason_str, LCDOFF_GESTURE_STR)) + flag = LCD_OFF_BY_GESTURE; + else { + _E("%s resean is invalid, dbus ignored!", reason_str); + ret = -EINVAL; + goto out; + } + + ret = custom_lcdoff(flag); + +out: + return g_variant_new("(i)", ret); +} + +GVariant *dbus_platformlcdcontrol(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + int ret = 0; + int type, timeout; + char *reason; + + g_variant_get(param, "(isi)", &type, &reason, &timeout); + + ret = display_platform_control(type, reason, timeout); + + return g_variant_new("(i)", ret); +} + GVariant *dbus_staytouchscreenoff(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) @@ -797,8 +819,6 @@ GVariant *dbus_staytouchscreenoff(GDBusConnection *conn, int ret = 0; int val; - CHECK_POWEROFF(); - g_variant_get(param, "(i)", &val); set_stay_touchscreen_off(val); @@ -813,8 +833,6 @@ GVariant *dbus_lcdpaneloffmode(GDBusConnection *conn, int ret = 0; int val; - CHECK_POWEROFF(); - g_variant_get(param, "(i)", &val); set_lcd_paneloff_mode(val); @@ -829,8 +847,6 @@ GVariant *dbus_actorcontrol(GDBusConnection *conn, int ret = 0, val, actor; char *op; - CHECK_POWEROFF(); - g_variant_get(param, "(sii)", &op, &actor, &val); if (!strcmp(op, "set")) @@ -850,8 +866,6 @@ GVariant *dbus_getcustombrightness(GDBusConnection *conn, { int status = 0; - CHECK_POWEROFF(); - status = backlight_ops.get_custom_status(); return g_variant_new("(i)", status); @@ -913,8 +927,6 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, struct pmlock_expired_s *ex = NULL; GVariant *gvar = NULL; - CHECK_POWEROFF(); - g_variant_get(param, "(s)", &req_id); pid = dbus_connection_get_sender_pid(conn, sender); @@ -1036,8 +1048,6 @@ GVariant *dbus_locktimeout_input(GDBusConnection *conn, struct pmlock_expired_s *ex; int value; - CHECK_POWEROFF(); - g_variant_get(param, "(si)", &req_id, &value); ex = calloc(1, sizeof(struct pmlock_expired_s)); @@ -1087,6 +1097,8 @@ static const dbus_method_s dbus_methods[] = { { "PowerKeyIgnore", "i", "i", dbus_powerkeyignore }, { "PowerKeyLCDOff", NULL, "i", dbus_powerkeylcdoff }, { "CustomLCDOn", "i", "i", dbus_customlcdon }, + { "CustomLCDOff", "s", "i", dbus_customlcdoff }, + { "PlatformLCDControl", "isi", "i", dbus_platformlcdcontrol }, { "StayTouchScreenOff", "i", "i", dbus_staytouchscreenoff }, { "LCDPanelOffMode", "i", "i", dbus_lcdpaneloffmode }, { "ActorControl", "sii", "i", dbus_actorcontrol }, @@ -1124,6 +1136,63 @@ static void homescreen_signal_handler(GDBusConnection *conn, g_free(screen); } +static void sim_signal_handler(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *name, + GVariant *param, + gpointer data) +{ + int ret, val; + static int state = false; + + ret = vconf_get_bool(VCONFKEY_LCD_BRIGHTNESS_INIT, &state); + if (ret < 0 || state) { + _E("Failed to get %s", VCONFKEY_LCD_BRIGHTNESS_INIT); + return; + } + + g_variant_get(param, "(i)", &val); + + if (val != SIM_CARD_NOT_PRESENT) { + state = true; + vconf_set_bool(VCONFKEY_LCD_BRIGHTNESS_INIT, state); + vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, PM_DEFAULT_BRIGHTNESS); + backlight_ops.set_brightness(PM_DEFAULT_BRIGHTNESS); + _I("SIM card is inserted at first."); + } +} + +static void changestate_signal_handler(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *name, + GVariant *param, + gpointer data) +{ + int val; + char *appid, *pkgid, *state, *type; + pid_t pid; + + g_variant_get(param, "(issss)", &val, &appid, &pkgid, &state, &type); + + pid = (pid_t)val; + + if (!strcmp(state, "bg")) { + _D("process(%d) was going background.", pid); + device_notify(DEVICE_NOTIFIER_PROCESS_BACKGROUND, &pid); + } else if (!strcmp(state, "fg")) { + _D("process(%d) was going foreground.", pid); + device_notify(DEVICE_NOTIFIER_PROCESS_FOREGROUND, &pid); + } + g_free(appid); + g_free(pkgid); + g_free(state); + g_free(type); +} + /* * Default capability * api := LCDON | LCDOFF | BRIGHTNESS @@ -1152,16 +1221,34 @@ int init_pm_dbus(void) if (ret < 0) _E("fail to init dbus method(%d)", ret); +#ifndef MICRO_DD + ret = subscribe_dbus_signal(NULL, + TELEPHONY_PATH, + TELEPHONY_INTERFACE_SIM, + SIGNAL_SIM_STATUS, + sim_signal_handler, + NULL, NULL); + if (ret <= 0) + _E("Failed to register signal handler: %d", ret); +#endif + ret = subscribe_dbus_signal(NULL, DEVICED_OBJECT_PATH, DEVICED_INTERFACE_NAME, SIGNAL_HOMESCREEN, homescreen_signal_handler, NULL, NULL); - if (ret <= 0) { - _E("Failed to register signal handler! %d", ret); - return ret; - } + if (ret <= 0) + _E("Failed to register signal handler: %d", ret); + + ret = subscribe_dbus_signal(NULL, + AUL_APPSTATUS_PATH, + AUL_APPSTATUS_INTERFACE, + APP_CHANGE_STATE, + changestate_signal_handler, + NULL, NULL); + if (ret <= 0) + _E("Failed to register signal handler: %d", ret); return 0; } diff --git a/src/display/display-ops.h b/src/display/display-ops.h index 93f8abe..ee60d5f 100644 --- a/src/display/display-ops.h +++ b/src/display/display-ops.h @@ -27,6 +27,7 @@ struct display_ops { char *name; void (*init) (void *data); void (*exit) (void *data); + int (*func) (unsigned int cmd, void *arg); }; void display_ops_init(void *data); @@ -46,6 +47,16 @@ void add_display(const struct display_ops *disp); void remove_display(const struct display_ops *disp); const struct display_ops *find_display_feature(const char *name); +#define FIND_DISPLAY(dev, name) do { \ + if (!dev) dev = find_display_feature(name); \ +} while (0) + +#define FIND_DISPLAY_INT(dev, name)do { \ + if (!dev) dev = find_display_feature(name); if (!dev) return -ENODEV; \ +} while (0) + +#define DISPLAY_FUNC(a, b) (((a) << 16) | (b)) + struct display_plugin { void *handle; int (*pm_lock_internal) (pid_t pid, int s_bits, int flag, int timeout); diff --git a/src/display/input.c b/src/display/input.c index a986504..a55d05b 100644 --- a/src/display/input.c +++ b/src/display/input.c @@ -26,6 +26,7 @@ #include "util.h" #include "core.h" #include "poll.h" +#include "ambient-mode.h" #define SEAT_NAME "seat0" @@ -42,7 +43,7 @@ static inline void process_event(struct libinput_event *ev) struct libinput *li; struct libinput_event_keyboard *k; unsigned int time; - int fd; + int fd = 0; if (!pm_callback) return; @@ -61,8 +62,6 @@ static inline void process_event(struct libinput_event *ev) } switch (libinput_event_get_type(ev)) { - case LIBINPUT_EVENT_DEVICE_ADDED: - return; case LIBINPUT_EVENT_KEYBOARD_KEY: k = libinput_event_get_keyboard_event(ev); time = libinput_event_keyboard_get_time(k); @@ -78,35 +77,34 @@ static inline void process_event(struct libinput_event *ev) _D("time %ld.%06ld type %d code %d value %d fd %d", input.time.tv_sec, input.time.tv_usec, input.type, input.code, input.value, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; break; case LIBINPUT_EVENT_POINTER_MOTION: case LIBINPUT_EVENT_POINTER_BUTTON: - case LIBINPUT_EVENT_POINTER_AXIS: - li = libinput_event_get_context(ev); input.type = EV_REL; - - fd = libinput_get_fd(li); - _D("type %d fd %d", input.type, fd); - - if (CHECK_OPS(keyfilter_ops, check) && - keyfilter_ops->check(&input, fd) != 0) - return; break; case LIBINPUT_EVENT_TOUCH_DOWN: + input.type = EV_ABS; + input.value = KEY_PRESSED; + break; case LIBINPUT_EVENT_TOUCH_UP: + input.type = EV_ABS; + input.value = KEY_RELEASED; + break; case LIBINPUT_EVENT_TOUCH_MOTION: case LIBINPUT_EVENT_TOUCH_FRAME: - if (touch_event_blocked()) - return ; + if (touch_event_blocked() && !ambient_get_state() && !display_conf.touch_wakeup) + return; + input.type = EV_ABS; + input.value = KEY_BEING_PRESSED; break; default: - break; + return; } + if (CHECK_OPS(keyfilter_ops, check) && + keyfilter_ops->check(&input, fd) != 0) + return; + /* lcd on or update lcd timeout */ (*pm_callback) (INPUT_POLL_EVENT, NULL); } @@ -116,10 +114,6 @@ static gboolean input_handler(gint fd, GIOCondition cond, void *data) struct libinput_event *ev; struct libinput *input = (struct libinput *)data; - /* Ignore input during poweroff */ - if (device_poweroff(NULL)) - return G_SOURCE_CONTINUE; - if (!input) return G_SOURCE_CONTINUE; @@ -163,7 +157,7 @@ static const struct libinput_interface interface = { .close_restricted = close_restricted, }; -int init_input(void) +gboolean init_input(gpointer data) { int ret; int fd; @@ -171,25 +165,25 @@ int init_input(void) udev = udev_new(); if (!udev) { _E("fail to create udev library context"); - return -EPERM; + return G_SOURCE_REMOVE; } li = libinput_udev_create_context(&interface, NULL, udev); if (!li) { _E("fail to create a new libinput context from udev"); - return -EPERM; + return G_SOURCE_REMOVE; } ret = libinput_udev_assign_seat(li, SEAT_NAME); if (ret < 0) { _E("fail to assign a seat"); - return -EPERM; + return G_SOURCE_REMOVE; } fd = libinput_get_fd(li); if (fd < 0) { _E("fail to get file descriptor from libinput context"); - return -EPERM; + return G_SOURCE_REMOVE; } /* add to poll handler */ @@ -200,10 +194,10 @@ int init_input(void) _E("fail to g_unix_fd_add"); /* TODO Does it really need close()? */ close(fd); - return -EPERM; + return G_SOURCE_REMOVE; } - return 0; + return G_SOURCE_REMOVE; } int exit_input(void) diff --git a/src/display/lock-detector.c b/src/display/lock-detector.c index 0560ef4..b2fa365 100644 --- a/src/display/lock-detector.c +++ b/src/display/lock-detector.c @@ -34,26 +34,42 @@ #include "util.h" #include "core.h" #include "core/list.h" +#include "core/device-notifier.h" struct lock_info { unsigned long hash; char *name; int state; + int pid; int count; - long locktime; - long unlocktime; - long time; + time_t locktime; + time_t unlocktime; + time_t time; }; +#define DEVICED_RUN_PATH "/run/deviced" +#define PMLOCK_HISTORY_RUN_PATH "/run/deviced/pmlock_detail.log" +#define PMLOCK_HISTORY_GHOST_PATH "/var/log/ghost/boot/current/pmlock_detail.log" +#define PMLOCK_HISTORY_FILE "/var/log/pmlock_detail.log" + +#define PM_STATE_LOG_GHOST_PATH "/var/log/ghost/boot/current/pm_state.log" +#define PM_STATE_LOG_FILE "/var/log/pm_state.log" + +#define SAVE_PMLOCK_OVER_TIME 60 /* seconds */ #define LIMIT_COUNT 128 static dd_list *lock_info_list; +static const char state_string[5][8] = { + "START", "NORMAL", "LCDDIM", "LCDOFF", "SLEEP" +}; -static long get_time(void) +static time_t get_time(void) { - struct timeval now; - gettimeofday(&now, NULL); - return (long)(now.tv_sec * 1000 + now.tv_usec / 1000); + struct timespec tspec; + + clock_gettime(CLOCK_REALTIME, &tspec); + + return (time_t)tspec.tv_sec; } static void shrink_lock_info_list(void) @@ -69,7 +85,7 @@ static void shrink_lock_info_list(void) DD_LIST_REVERSE_FOREACH_SAFE(lock_info_list, l, l_prev, info) { if (info->locktime == 0) { - DD_LIST_REMOVE_LIST(lock_info_list, l); + DD_LIST_REMOVE(lock_info_list, info); if (info->name) free(info->name); free(info); @@ -80,11 +96,12 @@ static void shrink_lock_info_list(void) } } -int set_lock_time(const char *pname, int state) +int set_lock_time(pid_t pid, const char *pname, int state) { struct lock_info *info; dd_list *l; unsigned long val; + char ht[15]; if (!pname) return -EINVAL; @@ -92,20 +109,23 @@ int set_lock_time(const char *pname, int state) if (state < S_NORMAL || state > S_SLEEP) return -EINVAL; - val = g_str_hash(pname); + save_pmlock(state, true, pid); + snprintf(ht, sizeof(ht), "[%d]%d", state, pid); + val = g_str_hash(ht); - DD_LIST_FOREACH(lock_info_list, l, info) - if (info->hash == val && - !strncmp(info->name, pname, strlen(pname)+1) && - info->state == state) { - info->count += 1; - if (info->locktime == 0) - info->locktime = get_time(); - info->unlocktime = 0; - DD_LIST_REMOVE(lock_info_list, info); - DD_LIST_PREPEND(lock_info_list, info); - return 0; - } + DD_LIST_FOREACH(lock_info_list, l, info) { + if (!(info->hash == val) || !(info->state == state)) + continue; + + info->count += 1; + if (info->locktime == 0) + info->locktime = get_time(); + info->unlocktime = 0; + DD_LIST_REMOVE(lock_info_list, info); + DD_LIST_PREPEND(lock_info_list, info); + + return 0; + } info = malloc(sizeof(struct lock_info)); if (!info) { @@ -114,7 +134,15 @@ int set_lock_time(const char *pname, int state) } info->hash = val; - info->name = strndup(pname, strlen(pname)); + if (pid < INTERNAL_LOCK_BASE) + info->name = strndup(pname, strlen(pname)); + else { + char internal_case[25]; + + snprintf(internal_case, sizeof(internal_case), "%s(%d)", pname, pid); + info->name = strndup(internal_case, strlen(internal_case)); + } + info->pid = pid; info->state = state; info->count = 1; info->locktime = get_time(); @@ -126,31 +154,63 @@ int set_lock_time(const char *pname, int state) return 0; } -int set_unlock_time(const char *pname, int state) +static void pmlock_info_detail(char *pname, pid_t pid, time_t locktime, + time_t unlocktime, long diff) +{ + _cleanup_fclose_ FILE *fp = NULL; + char *lock, *unlock, *tmp; + int ret; + + fp = fopen(PMLOCK_HISTORY_RUN_PATH, "a"); + if (fp == NULL) { + _E("Can not open detail path"); + return; + } + + lock = ctime(&locktime); + tmp = strchr(lock, '\n'); + if (tmp) + *tmp = '\0'; + + if (unlocktime != 0) { + unlock = ctime(&unlocktime); + tmp = strchr(unlock, '\n'); + if (tmp) + *tmp = '\0'; + } else + unlock = "continue.."; + + ret = fprintf(fp, "%6d [%24s] ~ [%24s] %5lu sec %s \n", + pid, lock, unlock, diff, pname); + if (ret < 0) + _E("write failed %d", ret); +} + +int set_unlock_time(pid_t pid, int state) { bool find = false; long diff; struct lock_info *info; dd_list *l; unsigned long val; - - if (!pname) - return -EINVAL; + char ht[15]; if (state < S_NORMAL || state > S_SLEEP) return -EINVAL; - val = g_str_hash(pname); + save_pmlock(state, false, pid); + + snprintf(ht, sizeof(ht), "[%d]%d", state, pid); + val = g_str_hash(ht); - DD_LIST_FOREACH(lock_info_list, l, info) - if (info->hash == val && - !strncmp(info->name, pname, strlen(pname)+1) && - info->state == state) { + DD_LIST_FOREACH(lock_info_list, l, info) { + if (info->hash == val && info->state == state) { DD_LIST_REMOVE(lock_info_list, info); DD_LIST_PREPEND(lock_info_list, info); find = true; break; } + } if (!find) return -EINVAL; @@ -163,6 +223,9 @@ int set_unlock_time(const char *pname, int state) diff = info->unlocktime - info->locktime; if (diff > 0) info->time += diff; + if (diff > SAVE_PMLOCK_OVER_TIME) + pmlock_info_detail(info->name, info->pid, info->locktime, info->unlocktime, diff); + info->locktime = 0; if (DD_LIST_LENGTH(lock_info_list) > LIMIT_COUNT) @@ -191,42 +254,124 @@ void free_lock_info_list(void) void print_lock_info_list(int fd) { struct lock_info *info; + time_t cur_time; dd_list *l; - char buf[255]; + long time; + char cur_buf[30], lock_buf[30], unlock_buf[30], buf[255]; + char *tmp; int ret; if (!lock_info_list) return; - snprintf(buf, sizeof(buf), - "current time : %ld ms\n", get_time()); + cur_time = get_time(); + ctime_r(&cur_time, cur_buf); + snprintf(buf, sizeof(buf), "current time : %s\n", cur_buf); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("write() failed (%d)", errno); snprintf(buf, sizeof(buf), - "[%10s %6s] %6s %10s %10s %10s %s\n", "hash", "state", - "count", "locktime", "unlocktime", "time", "process name"); + "[%10s %6s] %6s %-20s %-20s %10s %15s\n", "hash", "state", + "count", "last locktime", "last unlocktime", "time(s)", "process name"); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("write() failed (%d)", errno); DD_LIST_FOREACH(lock_info_list, l, info) { - long time = 0; + time = 0; if (info->locktime != 0 && info->unlocktime == 0) time = get_time() - info->locktime; + + *lock_buf = '\0'; + *unlock_buf = '\0'; + + if (info->locktime) { + ctime_r(&info->locktime, lock_buf); + tmp = strchr(lock_buf, '\n'); + if (!tmp) + continue; + *tmp = '\0'; + } + if (info->unlocktime) { + ctime_r(&info->unlocktime, unlock_buf); + tmp = strchr(unlock_buf, '\n'); + if (!tmp) + continue; + *tmp = '\0'; + } + snprintf(buf, sizeof(buf), - "[%10lu %6d] %6d %10ld %10ld %10ld %s\n", - info->hash, - info->state, - info->count, - info->locktime, - info->unlocktime, - info->time + time, - info->name); + "[%10lu %6s] %6d %25s %25s %10ld %s\n", + info->hash, + state_string[info->state], + info->count, + lock_buf, + unlock_buf, + info->time + time, + info->name); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("write() failed (%d)", errno); } } +static void cleanup_pmlock_statistics(void) +{ + struct lock_info *info; + GList *n; + time_t time; + long diff; + + time = get_time(); + + DD_LIST_FOREACH(lock_info_list, n, info) { + if (info->unlocktime != 0) + continue; + + diff = time - info->locktime; + if (diff > SAVE_PMLOCK_OVER_TIME) + pmlock_info_detail(info->name, info->pid, info->locktime, 0, diff); + } +} + +int pm_save_logdump(void) +{ + int ret; + + cleanup_pmlock_statistics(); + ret = do_copy_force(PMLOCK_HISTORY_RUN_PATH, PMLOCK_HISTORY_FILE); + if (ret < 0) + _W("Can not move(%d)", ret); + + save_display_log(PM_STATE_LOG_FILE); + + return ret; +} + +static int pmlock_detector_poweroff_cb(void *data) +{ + int ret; + + cleanup_pmlock_statistics(); + ret = do_copy_force(PMLOCK_HISTORY_RUN_PATH, PMLOCK_HISTORY_GHOST_PATH); + if (ret < 0) + _W("Can not move(%d)", ret); + + save_display_log(PM_STATE_LOG_GHOST_PATH); + + return 0; +} + +void pm_lock_detector_init(void) +{ + int ret; + + ret = do_mkdir(DEVICED_RUN_PATH, 0770); + if (ret < 0) { + _E("Fail to make directory %d", ret); + return; + } + + register_notifier(DEVICE_NOTIFIER_POWEROFF, pmlock_detector_poweroff_cb); +} diff --git a/src/display/lock-detector.h b/src/display/lock-detector.h index 681b896..d7305e0 100644 --- a/src/display/lock-detector.h +++ b/src/display/lock-detector.h @@ -26,10 +26,15 @@ #ifndef _LOCK_DETECTOR_H_ #define _LOCK_DETECTOR_H_ -int set_lock_time(const char *pname, int state); -int set_unlock_time(const char *pname, int state); +int set_lock_time(pid_t pid, const char *pname, int state); +int set_unlock_time(pid_t pid, int state); void free_lock_info_list(void); void print_lock_info_list(int fd); +int pm_save_logdump(void); +void pm_lock_detector_init(void); + +#define PM_STATE_LOG_FILE "/var/log/pm_state.log" + #endif //_LOCK_DETECTOR_H_ diff --git a/src/display/poll.h b/src/display/poll.h index 93afe57..9815191 100644 --- a/src/display/poll.h +++ b/src/display/poll.h @@ -26,7 +26,7 @@ #ifndef __PM_POLL_H__ #define __PM_POLL_H__ - +#include #include /** * @addtogroup POWER_MANAGER @@ -63,8 +63,14 @@ enum { INTERNAL_LOCK_PM, INTERNAL_LOCK_HALLIC, INTERNAL_LOCK_SWIM, + INTERNAL_LOCK_OVERHEAT, + INTERNAL_LOCK_OVERCOOL, }; +#define KEY_RELEASED 0 +#define KEY_PRESSED 1 +#define KEY_BEING_PRESSED 2 + #define SIGNAL_NAME_LCD_CONTROL "lcdcontol" #define LCD_NORMAL 0x01 /**< NORMAL state */ @@ -145,7 +151,7 @@ typedef struct { extern int (*pm_callback) (int, PMMsg *); -int init_input(void); +gboolean init_input(gpointer data); int exit_input(void); /** diff --git a/src/display/setting.c b/src/display/setting.c index b109d8c..f5a1cb3 100644 --- a/src/display/setting.c +++ b/src/display/setting.c @@ -21,14 +21,13 @@ #include #include #include -#include -#include #include "ambient-mode.h" #include "core.h" #include "util.h" #include "setting.h" #include "display-ops.h" +#include "shared/eventsystem.h" #define LCD_DIM_RATIO 0.3 #define LCD_MAX_DIM_TIMEOUT 7000 @@ -48,10 +47,12 @@ static int custom_on_timeout = 0; static int custom_normal_timeout = 0; static int custom_dim_timeout = 0; -static void display_state_send_system_event(int state) +int (*update_pm_setting) (int key_idx, int val); + +static gboolean display_state_send_system_event(gpointer data) { - bundle *b; const char *str; + int state = (int)data; if (state == S_NORMAL) str = EVT_VAL_DISPLAY_NORMAL; @@ -60,14 +61,13 @@ static void display_state_send_system_event(int state) else if (state == S_LCDOFF) str = EVT_VAL_DISPLAY_OFF; else - return; + return G_SOURCE_REMOVE; + + _I("Set pmstate of eventsystem : [%s]", str); - _I("eventsystem (%s)", str); + event_system_send(SYS_EVENT_DISPLAY_STATE, EVT_KEY_DISPLAY_STATE, str); - b = bundle_create(); - bundle_add_str(b, EVT_KEY_DISPLAY_STATE, str); - eventsystem_send_system_event(SYS_EVENT_DISPLAY_STATE, b); - bundle_free(b); + return G_SOURCE_REMOVE; } int set_force_lcdtimeout(int timeout) @@ -108,32 +108,32 @@ void set_lock_screen_bg_state(bool state) lock_screen_bg_state = state; } +int get_lowbatt_status(int *val) +{ + return vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, val); +} + +int get_usb_status(int *val) +{ + return vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, val); +} + int set_setting_pmstate(int val) { - static int old = -1; - int ret; + static int prev = S_NORMAL; - if (old == val) + if (prev == val) return 0; - old = val; - display_state_send_system_event(val); - ret = vconf_set_int(VCONFKEY_PM_STATE, val); - if (ret < 0) - _E("Failed to set vconf value for pm state: %d", vconf_get_ext_errno()); + prev = val; - return ret; + g_idle_add(display_state_send_system_event, (gpointer)val); + return vconf_set_int(VCONFKEY_PM_STATE, val); } int get_setting_brightness(int *level) { - int ret; - - ret = vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level); - if (ret < 0) - _E("Failed to get vconf value for lcd brightness: %d", vconf_get_ext_errno()); - - return ret; + return vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, level); } void get_dim_timeout(int *dim_timeout) @@ -145,14 +145,14 @@ void get_dim_timeout(int *dim_timeout) return; } - if (ambient_get_condition() == true) { + if (!display_conf.dimming || ambient_get_condition()) { *dim_timeout = LCD_MIN_DIM_TIMEOUT; return; } ret = vconf_get_int(setting_keys[SETTING_TO_NORMAL], &vconf_timeout); - if (ret < 0) { - _E("Failed to get vconf value for setting timeout: %d", vconf_get_ext_errno()); + if (ret != 0) { + _E("Failed ro get setting timeout!"); vconf_timeout = DEFAULT_NORMAL_TIMEOUT; } @@ -212,7 +212,11 @@ int set_custom_lcdon_timeout(int timeout) return changed; } - custom_dim_timeout = (double)timeout * LCD_DIM_RATIO; + if (display_conf.dimming) + custom_dim_timeout = (double)timeout * LCD_DIM_RATIO; + else + custom_dim_timeout = LCD_MIN_DIM_TIMEOUT; + custom_normal_timeout = timeout - custom_dim_timeout; _I("custom normal(%d), dim(%d)", custom_normal_timeout, diff --git a/src/display/setting.h b/src/display/setting.h index 31dc03d..b34b21c 100644 --- a/src/display/setting.h +++ b/src/display/setting.h @@ -47,6 +47,8 @@ enum { SETTING_END }; +extern int (*update_pm_setting) (int key_idx, int val); + int get_setting_brightness(int *level); /* @@ -96,6 +98,15 @@ extern int get_usb_status(int *val); */ extern int set_setting_pmstate(int val); +/* + * get current battery low status at SLP-setting "memory/Battery/Status/Low" + * + * @internal + * @param[in] val current low battery status + * @return 0 : success, -1 : error + */ +extern int get_lowbatt_status(int *val); + //FIXME int __get_lock_screen_state(void); diff --git a/src/display/slave-logging.c b/src/display/slave-logging.c new file mode 100644 index 0000000..f02bcd0 --- /dev/null +++ b/src/display/slave-logging.c @@ -0,0 +1,94 @@ +/* + * deviced + * + * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include + +#include "core/common.h" +#include "core/log.h" +#include "display/core.h" +#include "display/poll.h" + +#define BUFF_MAX 255 +#define LOCK_STR_MAX 20 +#define DISP_LOCK_STR "displock" +#define MAIN_LOCK_STR "mainlock" +#define DIM_LOCK_STR "dimlock" + +#define USER_WAKELOCK_NODE "/sys/power/slave_wake_lock" +#define USER_WAKEUNLOCK_NODE "/sys/power/slave_wake_unlock" + +static bool userlock_saving_support; + +int save_pmlock(enum state_t state, bool on, pid_t pid) +{ + int ret = 0; + char *node, *state_str; + char str[LOCK_STR_MAX]; + + if (!userlock_saving_support) + return -ENOSYS; + + switch (state) { + case S_NORMAL: + state_str = DISP_LOCK_STR; + break; + case S_LCDDIM: + state_str = DIM_LOCK_STR; + break; + case S_LCDOFF: + state_str = MAIN_LOCK_STR; + break; + default: + return -EINVAL; + } + + node = (on ? USER_WAKELOCK_NODE : USER_WAKEUNLOCK_NODE); + + snprintf(str, LOCK_STR_MAX, "%s %d", state_str, pid); + + ret = sys_set_str(node, str); + if (ret < 0) + _E("Failed to set disp userlock state!"); + + return ret; +} + +void init_save_userlock(void) +{ + int ret; + char str[BUFF_MAX]; + + userlock_saving_support = false; + + ret = sys_get_str(USER_WAKELOCK_NODE, str, sizeof(str)); + if (ret < 0) { + _E("Failed to load userlock(lock)!"); + return; + } + + ret = sys_get_str(USER_WAKEUNLOCK_NODE, str, sizeof(str)); + if (ret < 0) { + _E("Failed to load userlock(unlock)!"); + return; + } + + userlock_saving_support = true; + _I("userlock-saving is enabled!"); +} + diff --git a/src/dump/dump.c b/src/dump/dump.c index 1695628..7a0e69d 100644 --- a/src/dump/dump.c +++ b/src/dump/dump.c @@ -121,7 +121,7 @@ static void dump_init(void *data) } static const struct device_ops dump_device_ops = { - .name = "dump", + DECLARE_NAME_LEN("dump"), .init = dump_init, }; diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index 145eeda..5bdfc45 100644 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -512,7 +512,7 @@ static void extcon_exit(void *data) } static const struct device_ops extcon_device_ops = { - .name = "extcon", + DECLARE_NAME_LEN("extcon"), .probe = extcon_probe, .init = extcon_init, .exit = extcon_exit, diff --git a/src/extcon/extcon.h b/src/extcon/extcon.h index 23505e6..e6b3ab9 100644 --- a/src/extcon/extcon.h +++ b/src/extcon/extcon.h @@ -56,11 +56,6 @@ typedef enum { } extcon_hdmi_state_e; typedef enum { - DOCK_NONE = 0, - DOCK_SOUND = 7 -} extcon_dock_state_e; - -typedef enum { USBHOST_DISCONNECTED, USBHOST_CONNECTED } extcon_usbhost_state_e; diff --git a/src/ir/ir.c b/src/ir/ir.c index 2b8d37d..3f69d31 100644 --- a/src/ir/ir.c +++ b/src/ir/ir.c @@ -189,7 +189,7 @@ static void ir_exit(void *data) } static const struct device_ops ir_device_ops = { - .name = "ir", + DECLARE_NAME_LEN("ir"), .probe = ir_probe, .init = ir_init, .exit = ir_exit, diff --git a/src/led/rgb.c b/src/led/rgb.c index 5b115da..0386ab6 100644 --- a/src/led/rgb.c +++ b/src/led/rgb.c @@ -404,7 +404,7 @@ static int rgb_probe(void *data) } static const struct device_ops rgbled_device_ops = { - .name = "rgbled", + DECLARE_NAME_LEN("rgbled"), .probe = rgb_probe, .init = rgb_init, .exit = rgb_exit, diff --git a/src/led/torch.c b/src/led/torch.c index 2024ebd..ca0a0df 100644 --- a/src/led/torch.c +++ b/src/led/torch.c @@ -216,7 +216,7 @@ static void torch_exit(void *data) } static const struct device_ops torchled_device_ops = { - .name = "torchled", + DECLARE_NAME_LEN("torchled"), .probe = torch_probe, .init = torch_init, .exit = torch_exit, diff --git a/src/led/touch-key.c b/src/led/touch-key.c index 2852ac2..281f0a8 100644 --- a/src/led/touch-key.c +++ b/src/led/touch-key.c @@ -317,7 +317,7 @@ static int touchled_execute(void *data) } static const struct device_ops touchled_device_ops = { - .name = TOUCHLED_NAME, + DECLARE_NAME_LEN(TOUCHLED_NAME), .probe = touchled_probe, .init = touchled_init, .exit = touchled_exit, diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 4303a4d..8bdba86 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -753,7 +753,7 @@ static void power_init(void *data) } static const struct device_ops power_device_ops = { - .name = POWER_OPS_NAME, + DECLARE_NAME_LEN(POWER_OPS_NAME), .init = power_init, .execute = power_execute, }; diff --git a/src/shared/common.h b/src/shared/common.h index 5a3ef23..f505204 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -26,6 +26,12 @@ extern "C" { #endif +#ifdef MICRO_DD +#define wearable_mode() 1 +#else +#define wearable_mode() 0 +#endif + #ifndef API #define API __attribute__ ((visibility("default"))) #endif diff --git a/src/shared/deviced-systemd.c b/src/shared/deviced-systemd.c index fe65226..df10e1c 100644 --- a/src/shared/deviced-systemd.c +++ b/src/shared/deviced-systemd.c @@ -31,7 +31,6 @@ #include "core/log.h" - #define SYSTEMD_UNIT_ESCAPE_CHAR ".-" typedef unsigned int uint; @@ -295,6 +294,48 @@ GVariant * deviced_systemd_get_service_property(const char *unit, return val; } +int check_systemd_active(void) +{ + GVariant *msg, inner; + int ret = FALSE; + const char *state; + char *pa[2]; + + pa[0] = "org.freedesktop.systemd1.Unit"; + pa[1] = "ActiveState"; + + _I("%s %s", pa[0], pa[1]); + + msg = dbus_handle_method_sync_with_reply_var("org.freedesktop.systemd1", + "/org/freedesktop/systemd1/unit/default_2etarget", + "org.freedesktop.DBus.Properties", + "Get", g_variant_new("(ss)", pa[0], pa[1])); + + if (!msg) + return -EBADMSG; + + if (!dh_get_param_from_var(msg, "(v)", &inner)) { + _E("Failed to get signature(%s): no message", g_variant_get_type_string(msg)); + ret = -EBADMSG; + goto out2; + } + + if (!dh_get_param_from_var(inner, "s", &state)) { + _E("Failed to get signature(%s): no message", g_variant_get_type_string(inner)); + ret = -EBADMSG; + goto out1; + } + + if (strncmp(state, "active", 6) == 0) + ret = TRUE; +out1: + g_variant_unref(inner); + +out2: + g_variant_unref(msg); + return ret; +} + #if 0 #define DEFINE_SYSTEMD_GET_PROPERTY(iface, type, value) \ int deviced_systemd_get_##iface##_property_as_##type( \ diff --git a/src/shared/deviced-systemd.h b/src/shared/deviced-systemd.h index 715bb46..5a6f44f 100644 --- a/src/shared/deviced-systemd.h +++ b/src/shared/deviced-systemd.h @@ -35,12 +35,13 @@ int deviced_systemd_start_unit(char *name); int deviced_systemd_stop_unit(char *name); +int check_systemd_active(void); GVariant * deviced_systemd_get_manager_property(const char *property); GVariant * deviced_systemd_get_unit_property(const char *unit, const char *property); GVariant * deviced_systemd_get_service_property(const char* unit, const char* property); -#if 0 +#if 0 int deviced_systemd_get_manager_property_as_int32(const char *iface, const char *property, int *result); int deviced_systemd_get_manager_property_as_uint32(const char *iface, const char *property, unsigned int *result); int deviced_systemd_get_manager_property_as_int64(const char *iface, const char *property, long long *result); diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index 3de70b9..8b5bdea 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -142,7 +142,7 @@ static int thermal_probe(void *data) } static const struct device_ops thermal_ops = { - .name = "thermal", + DECLARE_NAME_LEN("thermal"), .probe = thermal_probe, .init = thermal_init, .exit = thermal_exit, diff --git a/src/touchscreen/sensitivity.c b/src/touchscreen/sensitivity.c index e9830a4..d3d14d6 100644 --- a/src/touchscreen/sensitivity.c +++ b/src/touchscreen/sensitivity.c @@ -218,7 +218,7 @@ static void sensitivity_init(void *data) } static const struct device_ops sensitivity_device_ops = { - .name = "sensitivity", + DECLARE_NAME_LEN("sensitivity"), .init = sensitivity_init, }; diff --git a/src/touchscreen/touchscreen.c b/src/touchscreen/touchscreen.c index 5d696c2..45caf74 100644 --- a/src/touchscreen/touchscreen.c +++ b/src/touchscreen/touchscreen.c @@ -133,7 +133,7 @@ static int touchscreen_dump(FILE *fp, int mode, void *dump_data) } static const struct device_ops touchscreen_device_ops = { - .name = "touchscreen", + DECLARE_NAME_LEN("touchscreen"), .probe = touchscreen_probe, .exit = touchscreen_exit, .start = touchscreen_start, diff --git a/src/tzip/tzip.c b/src/tzip/tzip.c index f66aa76..3887537 100644 --- a/src/tzip/tzip.c +++ b/src/tzip/tzip.c @@ -1086,7 +1086,7 @@ static void tzip_resume(void) } static const struct device_ops tzip_device_ops = { - .name = "tzip", + DECLARE_NAME_LEN("tzip"), .init = tzip_init, .exit = tzip_exit, .suspend = tzip_suspend, diff --git a/src/usb-host-test/usb-host-test.c b/src/usb-host-test/usb-host-test.c index 5ba6d91..45b2797 100644 --- a/src/usb-host-test/usb-host-test.c +++ b/src/usb-host-test/usb-host-test.c @@ -597,7 +597,7 @@ static int usb_host_test_status(void) } static const struct device_ops usb_host_test_device_ops = { - .name = "usb-host-test", + DECLARE_NAME_LEN("usb-host-test"), .init = usb_host_test_init, .exit = usb_host_test_exit, .start = usb_host_test_start, -- 2.7.4 From d510890a2268fbe18e74f1eccfc5c199fb93ef6f Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 30 Aug 2019 10:56:27 +0900 Subject: [PATCH 07/16] Add Dimming=no to disable dim in wearable target Change-Id: Ia848a6c20008fcd681785d808ef70bd8015ff552 Signed-off-by: lokilee73 --- conf/wearable-display.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/wearable-display.conf b/conf/wearable-display.conf index 3c190ae..f17b4ca 100644 --- a/conf/wearable-display.conf +++ b/conf/wearable-display.conf @@ -40,3 +40,4 @@ ControlDisplay=no PowerKeyDoublePressSupport=yes AccelSensorOn=no ContinuousSampling=no +Dimming=no \ No newline at end of file -- 2.7.4 From 2eb281abdf2a2da87fd9735e70dc8e6b483f67fb Mon Sep 17 00:00:00 2001 From: Baumann Date: Fri, 30 Aug 2019 15:50:30 +0200 Subject: [PATCH 08/16] Restrict signal policy Change-Id: I2864bd37fe36e58207d04ffd23ea1de22fd59556 Signed-off-by: Hyotaek Shim --- conf/org.tizen.system.deviced.conf | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index 53535a8..0fa137a 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -4,6 +4,15 @@ + + + @@ -61,5 +70,15 @@ + + + + -- 2.7.4 From 3a26f10960b1c174df4e2c573792142760270099 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Mon, 2 Sep 2019 15:30:48 +0900 Subject: [PATCH 09/16] usb-host-test: wait for /sys/kernel/config to mount after modprobe usb_f_fs Workaround: "modprobe usb_f_fs" doesn't guarantee that /sys/kernel/config is mounted. So, deviced must wait for /sys/kernel/config to be mounted. Change-Id: Ibf047e2261b786b57dd63f1f831936e8312567f1 --- src/usb-host-test/usb-host-test.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/usb-host-test/usb-host-test.c b/src/usb-host-test/usb-host-test.c index 45b2797..a5ed283 100644 --- a/src/usb-host-test/usb-host-test.c +++ b/src/usb-host-test/usb-host-test.c @@ -373,8 +373,9 @@ out1: int start() { - struct stat st; + int i; int ret; + struct stat st; ret = load_module("dummy_hcd", NULL); if (ret < 0) { @@ -408,6 +409,18 @@ int start() } } + /* Workaround: "modprobe usb_f_fs" doesn't guarantee that /sys/kernel/config is mounted */ + for (i = 0; i < 10; i++) { + if (mount_check(CONFIGFS_PATH)) + break; + + sleep (1); + } + if (i == 10) { + _E("Error mounting /sys/kernel/config"); + goto out; + } + ret = load_gadget(); if (ret < 0) { _E("Error loading gadget: %d", ret); -- 2.7.4 From d7bae4e2de2ca058b681b882466539af876988f9 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Tue, 3 Sep 2019 14:17:21 +0900 Subject: [PATCH 10/16] coverity fix Change-Id: Ic355e6fb4419394a443e995875cd818850a4a2c5 Signed-off-by: sanghyeok.oh --- plugins/iot/display/core.c | 6 ++++-- plugins/mobile/display/core.c | 4 +++- plugins/tv/display/core.c | 4 +++- plugins/wearable/display/core.c | 4 +++- src/display/display-dbus.c | 8 ++++++-- src/ir/ir.c | 7 ++++++- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 87ceda1..a93cf4b 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -2809,10 +2809,12 @@ static void display_init(void *data) _I("Start Power managing without noti"); if (power_ops.get_power_lock_support()) { broadcast_pm_wakeup(); - power_ops.power_lock(); + power_ops.power_lock(); } pm_cur_state = S_NORMAL; - vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + ret = vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + if (ret < 0) + _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); status = DEVICE_OPS_STATUS_START; if (display_conf.timeout_enable) { diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 30ca2bd..820aa9e 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -2824,7 +2824,9 @@ static void display_init(void *data) power_ops.power_lock(); } pm_cur_state = S_NORMAL; - vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + ret = vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + if (ret < 0) + _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); status = DEVICE_OPS_STATUS_START; if (display_conf.timeout_enable) { diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index dbd6954..0fa9df0 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -2812,7 +2812,9 @@ static void display_init(void *data) power_ops.power_lock(); } pm_cur_state = S_NORMAL; - vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + ret = vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + if (ret < 0) + _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); status = DEVICE_OPS_STATUS_START; if (display_conf.timeout_enable) { diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index f65f2a1..a72733c 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -2838,7 +2838,9 @@ static void display_init(void *data) power_ops.power_lock(); } pm_cur_state = S_NORMAL; - vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + ret = vconf_set_int(VCONFKEY_PM_STATE, pm_cur_state); + if (ret < 0) + _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); status = DEVICE_OPS_STATUS_START; if (display_conf.timeout_enable) { diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 773825f..d95e557 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -1157,8 +1157,12 @@ static void sim_signal_handler(GDBusConnection *conn, if (val != SIM_CARD_NOT_PRESENT) { state = true; - vconf_set_bool(VCONFKEY_LCD_BRIGHTNESS_INIT, state); - vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, PM_DEFAULT_BRIGHTNESS); + ret = vconf_set_bool(VCONFKEY_LCD_BRIGHTNESS_INIT, state); + if (ret < 0) + _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); + ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, PM_DEFAULT_BRIGHTNESS); + if (ret < 0) + _E("Failed to set vconf value for lcd brightness: %d", vconf_get_ext_errno()); backlight_ops.set_brightness(PM_DEFAULT_BRIGHTNESS); _I("SIM card is inserted at first."); } diff --git a/src/ir/ir.c b/src/ir/ir.c index 3f69d31..1346ac5 100644 --- a/src/ir/ir.c +++ b/src/ir/ir.c @@ -75,6 +75,10 @@ static GVariant *dbus_ir_transmit(GDBusConnection *conn, size = g_variant_iter_n_children(iter); freq_pattern = (int*)malloc(sizeof(int) * size); + if (!freq_pattern) { + ret = -ENOMEM; + goto exit; + } while (g_variant_iter_next(iter, "i", &freq_pattern[i++])) ; @@ -86,7 +90,8 @@ static GVariant *dbus_ir_transmit(GDBusConnection *conn, ret = ir_dev->transmit(freq_pattern, size); exit: - free(freq_pattern); + if (freq_pattern) + free(freq_pattern); return g_variant_new("(i)", ret); } -- 2.7.4 From 969f118ba47bac5443fd048a278c72636148ce90 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Tue, 3 Sep 2019 15:14:36 +0900 Subject: [PATCH 11/16] usb-host-test: / remove at end of path CONFIGFS_PATH mount_check does not work properly with / at the end of path. Change-Id: I77700ff4074ce48b047851f7f5f5026ed20ee092 --- src/usb-host-test/usb-host-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usb-host-test/usb-host-test.c b/src/usb-host-test/usb-host-test.c index a5ed283..256fd3f 100644 --- a/src/usb-host-test/usb-host-test.c +++ b/src/usb-host-test/usb-host-test.c @@ -41,7 +41,7 @@ #define SYSTEMD_UNIT_NAME "usb-host-test.socket" #define SYSTEMD_SERVICE_NAME "usb-host-ffs-test-daemon.service" #define UDC_NAME "dummy_udc.0" -#define CONFIGFS_PATH "/sys/kernel/config/" +#define CONFIGFS_PATH "/sys/kernel/config" #define SYSTEMD_DBUS_PATH "/org/freedesktop/systemd1" #define JOB_MANAGER_INTERFACE "org.freedesktop.systemd1.Manager" -- 2.7.4 From 4918525509e25f6e2e2f174f3fce465f4f9611d6 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 5 Sep 2019 21:25:51 +0900 Subject: [PATCH 12/16] Add SleepSupport field in display.conf Change-Id: I86f09c9fcfe0e1da0ab798242777c8fc5469c702 Signed-off-by: Hyotaek Shim --- plugins/iot/display/core.c | 10 +++++++--- plugins/mobile/display/core.c | 10 +++++++--- plugins/tv/display/core.c | 10 +++++++--- plugins/wearable/display/core.c | 10 +++++++--- src/display/core.h | 1 + 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index a93cf4b..260327d 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -226,7 +226,7 @@ struct display_config display_conf = { .lcdoff_timeout = LCDOFF_TIMEOUT, .brightness_change_step = BRIGHTNESS_CHANGE_STEP, .lcd_always_on = LCD_ALWAYS_ON, - .dimming = 1, + .dimming = 1, .framerate_app = {0, 0, 0, 0}, .control_display = 0, .powerkey_doublepress = 0, @@ -236,8 +236,9 @@ struct display_config display_conf = { .input_support = true, .lockcheck_timeout = 600, .aod_enter_level = 40, - .aod_tsp = true, + .aod_tsp = true, .touch_wakeup = false, + .sleep_support = true, }; struct display_function_info display_info = { @@ -1968,7 +1969,7 @@ static int default_action(int timeout) return -EINVAL; } - if (pm_cur_state != S_SLEEP) { + if (pm_cur_state != S_SLEEP && !(pm_cur_state == S_LCDOFF && display_conf.sleep_support == false)) { if (pm_cur_state == S_NORMAL && lcdon_tv.tv_sec != 0) { gettimeofday(&now_tv, NULL); @@ -2608,6 +2609,9 @@ static int display_load_config(struct parse_result *result, void *user_data) } else if (MATCH(result->name, "AODTSP")) { c->aod_tsp = (MATCH(result->value, "yes") ? true : false); _D("TSP control at is %d at aod", c->aod_tsp); + } else if (MATCH(result->name, "SleepSupport")) { + c->sleep_support = (MATCH(result->value, "yes") ? true : false); + _D("SleepSupport is %d", c->sleep_support); } return 0; diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 820aa9e..af2a4af 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -228,7 +228,7 @@ struct display_config display_conf = { .lcdoff_timeout = LCDOFF_TIMEOUT, .brightness_change_step = BRIGHTNESS_CHANGE_STEP, .lcd_always_on = LCD_ALWAYS_ON, - .dimming = 1, + .dimming = 1, .framerate_app = {0, 0, 0, 0}, .control_display = 0, .powerkey_doublepress = 0, @@ -238,8 +238,9 @@ struct display_config display_conf = { .input_support = true, .lockcheck_timeout = 600, .aod_enter_level = 40, - .aod_tsp = true, + .aod_tsp = true, .touch_wakeup = false, + .sleep_support = true, }; struct display_function_info display_info = { @@ -1980,7 +1981,7 @@ static int default_action(int timeout) return -EINVAL; } - if (pm_cur_state != S_SLEEP) { + if (pm_cur_state != S_SLEEP && !(pm_cur_state == S_LCDOFF && display_conf.sleep_support == false)) { if (pm_cur_state == S_NORMAL && lcdon_tv.tv_sec != 0) { gettimeofday(&now_tv, NULL); @@ -2620,6 +2621,9 @@ static int display_load_config(struct parse_result *result, void *user_data) } else if (MATCH(result->name, "AODTSP")) { c->aod_tsp = (MATCH(result->value, "yes") ? true : false); _D("TSP control at is %d at aod", c->aod_tsp); + } else if (MATCH(result->name, "SleepSupport")) { + c->sleep_support = (MATCH(result->value, "yes") ? true : false); + _D("SleepSupport is %d", c->sleep_support); } return 0; diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 0fa9df0..24bcb4b 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -226,7 +226,7 @@ struct display_config display_conf = { .lcdoff_timeout = LCDOFF_TIMEOUT, .brightness_change_step = BRIGHTNESS_CHANGE_STEP, .lcd_always_on = LCD_ALWAYS_ON, - .dimming = 1, + .dimming = 1, .framerate_app = {0, 0, 0, 0}, .control_display = 0, .powerkey_doublepress = 0, @@ -236,8 +236,9 @@ struct display_config display_conf = { .input_support = true, .lockcheck_timeout = 600, .aod_enter_level = 40, - .aod_tsp = true, + .aod_tsp = true, .touch_wakeup = false, + .sleep_support = true, }; struct display_function_info display_info = { @@ -1968,7 +1969,7 @@ static int default_action(int timeout) return -EINVAL; } - if (pm_cur_state != S_SLEEP) { + if (pm_cur_state != S_SLEEP && !(pm_cur_state == S_LCDOFF && display_conf.sleep_support == false)) { if (pm_cur_state == S_NORMAL && lcdon_tv.tv_sec != 0) { gettimeofday(&now_tv, NULL); @@ -2608,6 +2609,9 @@ static int display_load_config(struct parse_result *result, void *user_data) } else if (MATCH(result->name, "AODTSP")) { c->aod_tsp = (MATCH(result->value, "yes") ? true : false); _D("TSP control at is %d at aod", c->aod_tsp); + } else if (MATCH(result->name, "SleepSupport")) { + c->sleep_support = (MATCH(result->value, "yes") ? true : false); + _D("SleepSupport is %d", c->sleep_support); } return 0; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index a72733c..1273f43 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -227,7 +227,7 @@ struct display_config display_conf = { .lcdoff_timeout = LCDOFF_TIMEOUT, .brightness_change_step = BRIGHTNESS_CHANGE_STEP, .lcd_always_on = LCD_ALWAYS_ON, - .dimming = 1, + .dimming = 1, .framerate_app = {0, 0, 0, 0}, .control_display = 0, .powerkey_doublepress = 0, @@ -237,8 +237,9 @@ struct display_config display_conf = { .input_support = true, .lockcheck_timeout = 600, .aod_enter_level = 40, - .aod_tsp = true, + .aod_tsp = true, .touch_wakeup = false, + .sleep_support = true, }; struct display_function_info display_info = { @@ -1990,7 +1991,7 @@ static int default_action(int timeout) return -EINVAL; } - if (pm_cur_state != S_SLEEP) { + if (pm_cur_state != S_SLEEP && !(pm_cur_state == S_LCDOFF && display_conf.sleep_support == false)) { if (pm_cur_state == S_NORMAL && lcdon_tv.tv_sec != 0) { gettimeofday(&now_tv, NULL); @@ -2634,6 +2635,9 @@ static int display_load_config(struct parse_result *result, void *user_data) } else if (MATCH(result->name, "AODTSP")) { c->aod_tsp = (MATCH(result->value, "yes") ? true : false); _D("TSP control at is %d at aod", c->aod_tsp); + } else if (MATCH(result->name, "SleepSupport")) { + c->sleep_support = (MATCH(result->value, "yes") ? true : false); + _D("SleepSupport is %d", c->sleep_support); } return 0; diff --git a/src/display/core.h b/src/display/core.h index 166eb2a..6ab0f09 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -140,6 +140,7 @@ struct display_config { bool timeout_enable; bool input_support; bool touch_wakeup; + bool sleep_support; }; /* -- 2.7.4 From 969526a490022ebd78a5013d6c89670e43c18b53 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 9 Sep 2019 11:04:28 +0900 Subject: [PATCH 13/16] Add SleepSupport=no for TV profile Change-Id: I3a637a43ce0aba64b50093b24d4e8a13a7b91f33 Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 1 + conf/tv-display.conf | 37 +++++++++++++++++++++++++++++++++++++ packaging/deviced.spec | 2 ++ 3 files changed, 40 insertions(+) create mode 100644 conf/tv-display.conf diff --git a/CMakeLists.txt b/CMakeLists.txt index e68f5bb..cb7cecf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -309,3 +309,4 @@ ADD_SUBDIRECTORY(plugins/iot/display) INSTALL_CONF(conf display) INSTALL_CONF(conf mobile-display) INSTALL_CONF(conf wearable-display) +INSTALL_CONF(conf tv-display) diff --git a/conf/tv-display.conf b/conf/tv-display.conf new file mode 100644 index 0000000..b289403 --- /dev/null +++ b/conf/tv-display.conf @@ -0,0 +1,37 @@ +[Display] +# deviced is pending lcd on until lock screen shows. +# This is the maximum pending time. +# LockScreenWaitingTime=0.3 (second) + +# Power-off popup is launched when power key is long pressed. +# This is duration of pressing power key. +# LongPressInterval=2 (second) + +# This is polling time of auto brightness. +# LightSensorSamplingInterval=1 (second) + +# display state is changed to SLEEP state after this time. +# If this value is large, it causes power consumption problem. +# LCDOffTimeout=500 (milli second) + +# This is n step of auto brightness. +# If brightness is change from a to b, brightness's changed n times from a to b. +# BrightnessChangeStep=10 + +# Just below application only allow to change display frame rate. +# refer to enum refresh_app +# ChangedFrameRateAllowed=setting (setting or all) +# ControlDisplay=(yes or no) + +# LCD is not turned off when this value is yes and key double pressed +# PowerKeyDoublePressSupport=(yes or no) + +# If this value is yes, LCD is always on except pressing power key. +# Default value is no, LCD is turned off by lcd timeout. +# LCDAlwaysOn=(yes or no) + +# If this value is yes, LCD is turned off by lcd timeout. +# If this value is no, LCD is turned off just by external requests. +# TimeoutEnable=(yes or no) + +SleepSupport=no diff --git a/packaging/deviced.spec b/packaging/deviced.spec index ea01b19..31adc79 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -226,6 +226,7 @@ mkdir -p %{_libdir}/deviced mv %{_libdir}/tv-display.so %{_libdir}/deviced/display.so %post plugin-profile-iot +mv %{_sysconfdir}/deviced/tv-display.conf %{_sysconfdir}/deviced/display.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so @@ -302,6 +303,7 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %manifest deviced.manifest %license LICENSE.Apache-2.0 %defattr(-,root,root,-) +%config %{_sysconfdir}/deviced/tv-display.conf %config %{_sysconfdir}/deviced/display.conf %{_libdir}/tv-display.so -- 2.7.4 From bd18592a61029923b321e4464fa8cf3263c8cc20 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 6 Sep 2019 13:15:49 +0900 Subject: [PATCH 14/16] Increase ALWAYS_ON_TIMEOUT from 1 hour to 100 hours Change-Id: I453debda0b4b1b344e0ca491ae0dea43bb089ac5 Signed-off-by: Hyotaek Shim --- plugins/iot/display/core.c | 4 ++-- plugins/mobile/display/core.c | 6 +++--- plugins/tv/display/core.c | 6 +++--- plugins/wearable/display/core.c | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 260327d..9850915 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -69,7 +69,7 @@ #define SET_BRIGHTNESS_IN_BOOTLOADER "/usr/bin/save_blenv SLP_LCD_BRIGHT" #define LOCK_SCREEN_INPUT_TIMEOUT 10000 #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 -#define ALWAYS_ON_TIMEOUT 3600000 +#define ALWAYS_ON_TIMEOUT 360000000 #define LATE_LCD_TRANSIT 1 #define PID_MAX 6 @@ -83,7 +83,7 @@ #define PALM_STR "palm" #define UNKNOWN_STR "unknown" -#define METHOD_APP_STATUS "CheckAppStatus" +#define METHOD_APP_STATUS "CheckAppStatus" #define PM_WAKEUP 0 #define PM_SUSPEND 1 diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index af2a4af..4a54229 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -71,8 +71,8 @@ #define SET_BRIGHTNESS_IN_BOOTLOADER "/usr/bin/save_blenv SLP_LCD_BRIGHT" #define LOCK_SCREEN_INPUT_TIMEOUT 10000 #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 -#define ALWAYS_ON_TIMEOUT 3600000 -#define LATE_LCD_TRANSIT 1 +#define ALWAYS_ON_TIMEOUT 360000000 +#define LATE_LCD_TRANSIT 1 #define PID_MAX 6 @@ -85,7 +85,7 @@ #define PALM_STR "palm" #define UNKNOWN_STR "unknown" -#define METHOD_APP_STATUS "CheckAppStatus" +#define METHOD_APP_STATUS "CheckAppStatus" #define PM_WAKEUP 0 #define PM_SUSPEND 1 diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 24bcb4b..4730754 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -69,8 +69,8 @@ #define SET_BRIGHTNESS_IN_BOOTLOADER "/usr/bin/save_blenv SLP_LCD_BRIGHT" #define LOCK_SCREEN_INPUT_TIMEOUT 10000 #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 -#define ALWAYS_ON_TIMEOUT 3600000 -#define LATE_LCD_TRANSIT 1 +#define ALWAYS_ON_TIMEOUT 360000000 +#define LATE_LCD_TRANSIT 1 #define PID_MAX 6 @@ -83,7 +83,7 @@ #define PALM_STR "palm" #define UNKNOWN_STR "unknown" -#define METHOD_APP_STATUS "CheckAppStatus" +#define METHOD_APP_STATUS "CheckAppStatus" #define PM_WAKEUP 0 #define PM_SUSPEND 1 diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 1273f43..c098a56 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -70,8 +70,8 @@ #define SET_BRIGHTNESS_IN_BOOTLOADER "/usr/bin/save_blenv SLP_LCD_BRIGHT" #define LOCK_SCREEN_INPUT_TIMEOUT 10000 #define LOCK_SCREEN_CONTROL_TIMEOUT 5000 -#define ALWAYS_ON_TIMEOUT 3600000 -#define LATE_LCD_TRANSIT 1 +#define ALWAYS_ON_TIMEOUT 360000000 +#define LATE_LCD_TRANSIT 1 #define PID_MAX 6 @@ -84,7 +84,7 @@ #define PALM_STR "palm" #define UNKNOWN_STR "unknown" -#define METHOD_APP_STATUS "CheckAppStatus" +#define METHOD_APP_STATUS "CheckAppStatus" #define PM_WAKEUP 0 #define PM_SUSPEND 1 -- 2.7.4 From c1468c6d717784703b5ae1affa79995f376a97e6 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 9 Sep 2019 11:36:01 +0900 Subject: [PATCH 15/16] Minor fix to add SleepSupport=no for TV profile Change-Id: If8ec6b89f95de701778fca751cca28a2996eae64 Signed-off-by: Hyotaek Shim --- packaging/deviced.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 31adc79..83c8165 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -222,11 +222,11 @@ mkdir -p %{_libdir}/deviced mv %{_libdir}/wearable-display.so %{_libdir}/deviced/display.so %post plugin-profile-tv +mv %{_sysconfdir}/deviced/tv-display.conf %{_sysconfdir}/deviced/display.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/tv-display.so %{_libdir}/deviced/display.so %post plugin-profile-iot -mv %{_sysconfdir}/deviced/tv-display.conf %{_sysconfdir}/deviced/display.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so -- 2.7.4 From 2599a3645f7550b10cc6f0c0a1c7408c2309b148 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 4 Sep 2019 21:16:36 +0900 Subject: [PATCH 16/16] Add HBM, LBM module Change-Id: I64a3090092f622f879d2c754e71b5354682936c6 Signed-off-by: Youngjae Cho --- conf/org.tizen.system.deviced.conf | 1 + conf/wearable-display.conf | 7 +- .../wearable/display/auto-brightness-sensorhub.c | 202 ++++++++ .../wearable/display/auto-brightness-sensorhub.h | 30 ++ plugins/wearable/display/display-handler.c | 110 +++++ plugins/wearable/display/hbm.c | 510 +++++++++++++++++++++ plugins/wearable/display/hbm.h | 50 ++ plugins/wearable/display/lbm.c | 376 +++++++++++++++ plugins/wearable/display/lbm.h | 50 ++ plugins/wearable/display/weaks.h | 29 ++ 10 files changed, 1364 insertions(+), 1 deletion(-) create mode 100644 plugins/wearable/display/auto-brightness-sensorhub.c create mode 100644 plugins/wearable/display/auto-brightness-sensorhub.h create mode 100644 plugins/wearable/display/display-handler.c create mode 100644 plugins/wearable/display/hbm.c create mode 100644 plugins/wearable/display/hbm.h create mode 100644 plugins/wearable/display/lbm.c create mode 100644 plugins/wearable/display/lbm.h create mode 100644 plugins/wearable/display/weaks.h diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index 0fa137a..5ef074e 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -18,6 +18,7 @@ + diff --git a/conf/wearable-display.conf b/conf/wearable-display.conf index f17b4ca..a3393ea 100644 --- a/conf/wearable-display.conf +++ b/conf/wearable-display.conf @@ -40,4 +40,9 @@ ControlDisplay=no PowerKeyDoublePressSupport=yes AccelSensorOn=no ContinuousSampling=no -Dimming=no \ No newline at end of file +Dimming=no +LBMsupport=yes +Level=4 +BrtTable=1,20,40,50,60,70,80,90,95,100 +AodBrightnessLevel=40 + diff --git a/plugins/wearable/display/auto-brightness-sensorhub.c b/plugins/wearable/display/auto-brightness-sensorhub.c new file mode 100644 index 0000000..6e96daf --- /dev/null +++ b/plugins/wearable/display/auto-brightness-sensorhub.c @@ -0,0 +1,202 @@ +/* + * deviced + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "hbm.h" +#include "lbm.h" +#include "auto-brightness-sensorhub.h" +#include "display/util.h" +#include "display/core.h" +#include "display/display-ops.h" +#include "core/device-notifier.h" +#include "battery/power-supply.h" + +#define SPECIFIC_MODE_OFF 0 +#define LBM_LEVEL 110 +#define HBM_LEVEL 120 + +#define LOWBATCAPACITY 5 + +static int auto_brightness_state = SETTING_BRIGHTNESS_AUTOMATIC_OFF; + +static void change_brightness_transit(int start, int end) +{ + backlight_ops.transit_brt(start, end, + display_conf.brightness_change_step); +} + +static void set_brightness_level(int level) +{ + int old_level = 0; + if (pm_cur_state != S_NORMAL) + return; +/* + if (battery.capacity <= LOWBATCAPACITY && battery.charge_now != CHARGER_CHARGING) + return; +*/ + _I("level changed! %d", level); + + if ((level > PM_MAX_BRIGHTNESS || level < PM_MIN_BRIGHTNESS) && + (level != LBM_LEVEL && level != HBM_LEVEL && level != SPECIFIC_MODE_OFF)) { + _E("Invalid level %d", level); + return; + } + + backlight_ops.get_brightness(&old_level); + + switch (level) { + case LBM_LEVEL: + /* + * received LBM enable + * change brightness to under LBM_BRIGHTNESS_LOW and set lbm state + */ + if (hbm_get_state()) { + hbm_set_state(false); + _I("HBM mode disabled."); + } + if (!lbm_get_state()) { + lbm_set_state(true); + _I("LBM mode enabled."); + } + break; + case HBM_LEVEL: + /* HBM must do not turn on at DIM_STY state. */ + if (pm_status_flag & DIM_MASK) + break; + + /* + * received HBM enable + * change brightness to MAX value and set hbm state + */ + if (lbm_get_state()) { + lbm_set_state(false); + _I("Disabling LBM before enabling HBM."); + } + + change_brightness_transit(old_level, PM_MAX_BRIGHTNESS); + hbm_set_state(true); + _I("HBM mode enabled."); + + break; + case SPECIFIC_MODE_OFF: + /* + * received HBM disable + * unset hbm state and change brightness to setting value + */ + + level = backlight_ops.get_default_brt(); + + if (hbm_get_state()) + hbm_set_state(false); + + if (lbm_get_state()) + lbm_set_state(false); + + change_brightness_transit(old_level, level); + + break; + default: + /* + * received automatic brightness by the light sensor + */ + if (auto_brightness_state != SETTING_BRIGHTNESS_AUTOMATIC_ON) + return; + + if (hbm_get_state()) + hbm_set_state(false); + + if (lbm_get_state()) + lbm_set_state(false); + + if (old_level != level) { + change_brightness_transit(old_level, level); + backlight_ops.set_default_brt(level); + } + + break; + } + + device_notify(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, NULL); +} + +static void set_default_brightness(void) +{ + int default_brt; + + default_brt = backlight_ops.get_default_brt(); + backlight_ops.set_default_brt(default_brt); + backlight_ops.update(); +} + +static void set_automatic_state_cb(keynode_t *key_nodes, void *data) +{ + if (key_nodes == NULL) { + _E("Wrong parameter, key_nodes is null."); + return; + } + auto_brightness_state = vconf_keynode_get_int(key_nodes); + + switch (auto_brightness_state) { + case SETTING_BRIGHTNESS_AUTOMATIC_OFF: + if (hbm_get_state()) + hbm_set_state(false); + /* escape dim state if it's in low battery.*/ + set_brightness_changed_state(); + set_default_brightness(); + break; + case SETTING_BRIGHTNESS_AUTOMATIC_PAUSE: + if (hbm_get_state()) + hbm_set_state(false); + break; + case SETTING_BRIGHTNESS_AUTOMATIC_ON: + set_brightness_changed_state(); + break; + default: + _E("Invalid value %d.", auto_brightness_state); + } +} + +int prepare_level_handler(void) +{ + int status, ret; + + display_info.set_brightness_level = set_brightness_level; + + ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); + if (ret >= 0) + auto_brightness_state = status; + + vconf_notify_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, + set_automatic_state_cb, NULL); + + return 0; +} + +void exit_level_handler(void) +{ + vconf_ignore_key_changed(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, + set_automatic_state_cb); + set_default_brightness(); +} diff --git a/plugins/wearable/display/auto-brightness-sensorhub.h b/plugins/wearable/display/auto-brightness-sensorhub.h new file mode 100644 index 0000000..56243fb --- /dev/null +++ b/plugins/wearable/display/auto-brightness-sensorhub.h @@ -0,0 +1,30 @@ +/* + * deviced + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * @file auto-brightness-sensorhub.h + * @brief auto-brightness-sensorhub header file + */ +#ifndef __AUTO_BRT_SENSORHUB_H__ +#define __AUTO_BRT_SENSORHUB_H__ + +int prepare_level_handler(void); +void exit_level_handler(void); + +#endif diff --git a/plugins/wearable/display/display-handler.c b/plugins/wearable/display/display-handler.c new file mode 100644 index 0000000..11226c6 --- /dev/null +++ b/plugins/wearable/display/display-handler.c @@ -0,0 +1,110 @@ +/* + * deviced + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include "auto-brightness-sensorhub.h" +#include "core/device-notifier.h" +#include "display/util.h" +#include "display/core.h" +#include "display/poll.h" +#include "core/common.h" +#include "core/devices.h" +#include "display/display-actor.h" +#include "display/display-ops.h" +#include "display-info.h" + +#define CHARGER_LCD_NODE "/sys/class/power_supply/battery/lcd" + +enum charging_lcd_state { + CHARGING_LCD_OFF = 0, + CHARGING_LCD_ON = 1, +}; + +static GVariant *dbus_autobrightnesschanged(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + int ret = 0; + int level; + + g_variant_get(param, "(i)", &level); + + if (display_info.set_brightness_level) + display_info.set_brightness_level(level); + else + ret = -ENOTSUP; + + return g_variant_new("(i)", ret); +} + +static const dbus_method_s dbus_methods[] = { + { "AutoBrightnessChanged", "i", "i", dbus_autobrightnesschanged }, +}; + +static const dbus_interface_u dbus_interface = { + .oh = NULL, + .name = DEVICED_INTERFACE_DISPLAY, + .methods = dbus_methods, + .nr_methods = ARRAY_SIZE(dbus_methods), +}; + +static int display_state_changed(void *data) +{ + enum state_t state; + int ret = 0; + + state = DATA_VALUE_INT(data); + + if (state == S_LCDON) + ret = sys_set_int(CHARGER_LCD_NODE, CHARGING_LCD_ON); + else + ret = sys_set_int(CHARGER_LCD_NODE, CHARGING_LCD_OFF); + + if (ret < 0) + _E("Can't write %s node %d.", CHARGER_LCD_NODE, state); + + return 0; +} + +static void display_handler_init(void *data) +{ + int ret; + + prepare_level_handler(); + register_notifier(DEVICE_NOTIFIER_LCD, display_state_changed); + + ret = sys_set_int(CHARGER_LCD_NODE, CHARGING_LCD_ON); + if (ret < 0) + _E("Can't write %s node.", CHARGER_LCD_NODE); + + ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_DISPLAY, &dbus_interface); + if (ret < 0) + _E("Failed to register dbus object."); +} + +static const struct display_ops display_handler_ops = { + .name = "dislay-handler", + .init = display_handler_init, +}; + +DISPLAY_OPS_REGISTER(&display_handler_ops) diff --git a/plugins/wearable/display/hbm.c b/plugins/wearable/display/hbm.c new file mode 100644 index 0000000..4d0fde5 --- /dev/null +++ b/plugins/wearable/display/hbm.c @@ -0,0 +1,510 @@ +/* + * deviced + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "weaks.h" +#include "display-info.h" +#include "display/util.h" +#include "display/core.h" +#include "display/display-ops.h" +#include "core/common.h" +#include "core/device-notifier.h" +#include "core/config-parser.h" + +#define BOARD_CONF_FILE "/etc/deviced/display.conf" + +#define ON "on" +#define OFF "off" + +#define SIGNAL_HBM_ON "HBMOn" +#define SIGNAL_HBM_OFF "HBMOff" + +#define HBM_LEVEL 120 +#define DEFAULT_BRIGHTNESS_LEVEL 80 + +#define LCD_PATH "sys/class/lcd/" +#define HBM_PATH "/hbm" +#define DEVICE_PATH "/device" +#define PATH_BUFFER_MAX 256 + +static guint timer; +static struct timespec offtime; +static char *hbm_path; + +static void broadcast_hbm_state(char *state) +{ + dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + state, + NULL); +} + +static void hbm_set_offtime(int timeout) +{ + struct timespec now; + + if (timeout <= 0) { + offtime.tv_sec = 0; + return; + } + + clock_gettime(CLOCK_REALTIME, &now); + offtime.tv_sec = now.tv_sec + timeout; +} + +static gboolean hbm_off_cb(void *data) +{ + int ret; + + timer = 0; + + if (pm_cur_state != S_NORMAL) { + _D("Hbm timeout, but it's not display normal."); + return G_SOURCE_REMOVE; + } + hbm_set_offtime(0); + + ret = sys_set_str(hbm_path, OFF); + if (ret < 0) + _E("Failed to off hbm."); + + ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, + DEFAULT_BRIGHTNESS_LEVEL); + if (ret < 0) { + _E("Failed to set vconf value lcd brightness, %d.", ret); + return G_SOURCE_REMOVE; + } + backlight_ops.set_default_brt(DEFAULT_BRIGHTNESS_LEVEL); + backlight_ops.update(); + broadcast_hbm_state(SIGNAL_HBM_OFF); + + return G_SOURCE_REMOVE; +} + +static void hbm_start_timer(int timeout) +{ + if (timer) { + g_source_remove(timer); + timer = 0; + } + if (!timer) { + timer = g_timeout_add_seconds(timeout, hbm_off_cb, NULL); + } +} + +static void hbm_end_timer(void) +{ + if (timer) { + g_source_remove(timer); + timer = 0; + } +} + +int hbm_get_state(void) +{ + char state[5]; + int ret, hbm; + + if (!hbm_path) + return -ENODEV; + + ret = sys_get_str(hbm_path, state, sizeof(state)); + if (ret < 0) + return ret; + + if (!strncmp(state, ON, strlen(ON))) + hbm = true; + else if (!strncmp(state, OFF, strlen(OFF))) + hbm = false; + else + hbm = -EINVAL; + + return hbm; +} + +int hbm_set_state(int hbm) +{ + if (!hbm_path) + return -ENODEV; + + if (hbm) + broadcast_hbm_state(SIGNAL_HBM_ON); + else + broadcast_hbm_state(SIGNAL_HBM_OFF); + + return sys_set_str(hbm_path, (hbm ? ON : OFF)); +} + +static void hbm_turn_on(void) +{ + if (!hbm_get_state()) + hbm_set_state(true); +} + +static void hbm_turn_off(void) +{ + if (hbm_get_state()) + hbm_set_state(false); +} + +static int hbm_set_state_with_timeout(int hbm, int timeout) +{ + int ret; + + if (hbm && (timeout <= 0)) + return -EINVAL; + + ret = hbm_set_state(hbm); + if (ret < 0) + return ret; + + _D("timeout is %d", timeout); + + if (hbm) { + /* + * hbm is turned off after timeout. + */ + hbm_set_offtime(timeout); + hbm_start_timer(timeout); + } else { + hbm_set_offtime(0); + hbm_end_timer(); + broadcast_hbm_state(SIGNAL_HBM_OFF); + } + + return 0; +} + +void hbm_check_timeout(void) +{ + struct timespec now; + int ret; + + if (timer) { + g_source_remove(timer); + timer = 0; + } + + if (offtime.tv_sec == 0) { + if (hbm_get_state() == true) { + _E("It's invalid state. HBM is turned off."); + hbm_set_state(false); + } + return; + } + + clock_gettime(CLOCK_REALTIME, &now); + _D("now %ld, offtime %ld", now.tv_sec, offtime.tv_sec); + + /* check it's timeout */ + if (now.tv_sec >= offtime.tv_sec) { + hbm_set_offtime(0); + + ret = sys_set_str(hbm_path, OFF); + if (ret < 0) + _E("Failed to off HBM."); + backlight_ops.update(); + broadcast_hbm_state(SIGNAL_HBM_OFF); + } else { + _D("HBM state is restored."); + hbm_set_state(true); + hbm_start_timer(offtime.tv_sec - now.tv_sec); + } +} + +static void hbm_get_level(GVariant *var, void *user_data, GError *err) +{ + int level, brt; + + if (!var) { + _D("Invalid parameter."); + return; + } + + if (!dh_get_param_from_var(var, "(i)", &level)) { + _E("Failed to get message, %s.", g_variant_get_type_string(var)); + goto out; + } + + if (level == HBM_LEVEL && hbm_get_state() == false) { + _I("Lux was high already, HBM enable"); + backlight_ops.get_brightness(&brt); + backlight_ops.transit_brt(brt, PM_MAX_BRIGHTNESS, + display_conf.brightness_change_step); + hbm_set_state(true); + } +out: + g_variant_unref(var); +} + +static gboolean hbm_check_handler(gpointer data) +{ + int ret; + + ret = dbus_handle_method_async_with_reply(COORD_BUS_NAME, + COORD_PATH_AUTOBRIGHTNESS, + COORD_INTERFACE_AUTOBRIGHTNESS, + "GetLevel", + NULL, + NULL, + hbm_get_level, + -1, + NULL); + + if (ret < 0) + _D("Failed to call coord.autobrightness.GetLevel method, %d", ret); + + return G_SOURCE_REMOVE; +} + +static int display_state_changed(void *data) +{ + int state; + int ret; + + state = DATA_VALUE_INT(data); + + if (get_outdoor_setting) + if (get_outdoor_setting()) + return 0; + + switch (state) { + case S_NORMAL: + /* + * outdoor-enhance-mode not supported + * : check & restore hbm always. + * outdoor-enhance-mode supported + * : check & restore hbm when old state is dim only. + */ + if (!get_outdoor_setting || pm_old_state == S_LCDDIM) + hbm_check_timeout(); + + (void) g_timeout_add(300, hbm_check_handler, NULL); + break; + case S_LCDDIM: + case S_LCDOFF: + case S_SLEEP: + if (hbm_get_state() == true) { + ret = hbm_set_state(false); + if (ret < 0) + _E("Failed to off hbm."); + } + hbm_end_timer(); + break; + } + + return 0; +} + +static int display_off_changed(void *data) +{ + int brt; + + if (hbm_get_state() == false) + return 0; + + hbm_turn_off(); + + brt = backlight_ops.get_default_brt(); + if (pm_status_flag & DIMSTAY_FLAG) + _D("skip auto change brightness"); + else + backlight_ops.transit_brt(PM_MAX_BRIGHTNESS, brt, display_conf.brightness_change_step); + + return 0; +} + +static GVariant *dbus_gethbm(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + return g_variant_new("(i)", hbm_get_state()); +} + +static GVariant *dbus_sethbm_timeout(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + int hbm, timeout, ret; + + g_variant_get(param, "(ii)", &hbm, &timeout); + + if (timeout <= 0) { + _E("Timeout can not be setting(%d).", timeout); + ret = -EINVAL; + goto out; + } + + ret = hbm_set_state_with_timeout(hbm, timeout); + + if (ret < 0) + _E("Failed to set HBM (ret=%d, hbm=%d, time=%d).", ret, hbm, timeout); + else + _I("Set hbm (ret=%d, hbm=%d, time=%d).", ret, hbm, timeout); + +out: + return g_variant_new("(i)", ret); +} + +static const dbus_method_s dbus_methods[] = { + { "GetHBM", NULL, "i", dbus_gethbm }, + { "SetHBMTimeout", "ii", "i", dbus_sethbm_timeout }, +}; + +static const dbus_interface_u dbus_interface = { + .oh = NULL, + .name = DEVICED_INTERFACE_DISPLAY, + .methods = dbus_methods, + .nr_methods = ARRAY_SIZE(dbus_methods), +}; + +static int hbm_func(unsigned int cmd, void *arg) +{ + int ret = 0; + int *on; + struct hbmsetstate *hss; + + switch (cmd) { + case HBM_GET_STATE: + ret = hbm_get_state(); + break; + case HBM_SET_STATE: + on = (int *)arg; + ret = hbm_set_state(*on); + break; + case HBM_TURN_ON: + hbm_turn_on(); + break; + case HBM_TURN_OFF: + hbm_turn_off(); + break; + case HBM_SET_TIMEOUT_STATE: + hss = (struct hbmsetstate *)arg; + ret = hbm_set_state_with_timeout(hss->hbm, hss->timeout); + break; + case HBM_TURN_OFF_STATE: + hbm_turn_off(); + break; + default: + ret = -EINVAL; + break; + } + + return ret; +} + +static char *check_and_copy_path(char *path) +{ + int fd; + char *buf = NULL; + + fd = open(path, O_RDONLY); + if (fd >= 0) { + buf = strndup(path, strlen(path)); + close(fd); + } else { + _E("Failed to open HBM node."); + } + + return buf; +} + +static char *find_hbm_node() +{ + DIR *d; + struct dirent *dir; + char buf[PATH_BUFFER_MAX]; + char *result = NULL; + + d = opendir(LCD_PATH); + if (!d) + return NULL; + + while ((dir = readdir(d))) { + if (dir->d_name[0] == '.') + continue; + + snprintf(buf, sizeof(buf), "%s%s%s", LCD_PATH, + dir->d_name, HBM_PATH); + + result = check_and_copy_path(buf); + if (result) + break; + + snprintf(buf, sizeof(buf), "%s%s%s%s", LCD_PATH, + dir->d_name, DEVICE_PATH, HBM_PATH); + + result = check_and_copy_path(buf); + if (result) + break; + } + closedir(d); + + return result; +} + +static void hbm_init(void *data) +{ + int ret; + + hbm_path = find_hbm_node(); + + if (!hbm_path) { + _E("Failed to find HBM node."); + return; + } else { + _I("HBM node: %s.", hbm_path); + } + + ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_DISPLAY, &dbus_interface); + if (ret < 0) + _E("Failed to register dbus object."); + + /* register notifier */ + register_notifier(DEVICE_NOTIFIER_LCD, display_state_changed); + register_notifier(DEVICE_NOTIFIER_LCD_OFF, display_off_changed); +} + +static void hbm_exit(void *data) +{ + /* unregister notifier */ + unregister_notifier(DEVICE_NOTIFIER_LCD_OFF, display_off_changed); + unregister_notifier(DEVICE_NOTIFIER_LCD, display_state_changed); + + /* + * set default brightness + * if display logic is stopped in hbm state. + */ + if (hbm_get_state() == true) { + hbm_set_offtime(0); + _I("set brightness to default value!"); + } +} + +static const struct display_ops display_hbm_ops = { + .name = "hbm", + .init = hbm_init, + .exit = hbm_exit, + .func = hbm_func, +}; + +DISPLAY_OPS_REGISTER(&display_hbm_ops) + diff --git a/plugins/wearable/display/hbm.h b/plugins/wearable/display/hbm.h new file mode 100644 index 0000000..d555152 --- /dev/null +++ b/plugins/wearable/display/hbm.h @@ -0,0 +1,50 @@ +/* + * deviced + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +/** + * @file hbm.h + * @brief High Brightness Mode header file + */ +#ifndef __HBM_H__ +#define __HBM_H__ + +/* + * @brief Configuration structure + */ +struct hbm_config { + int on; + int off; + int on_count; + int off_count; +}; + +int hbm_get_state(void); +int hbm_set_state(int hbm); + +/* + * Global variables + * hbm_conf : configuration of hbm + */ +extern struct hbm_config hbm_conf; + +/** + * @} + */ + +#endif diff --git a/plugins/wearable/display/lbm.c b/plugins/wearable/display/lbm.c new file mode 100644 index 0000000..c098efd --- /dev/null +++ b/plugins/wearable/display/lbm.c @@ -0,0 +1,376 @@ +/* + * deviced + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "lbm.h" +#include "display-info.h" +#include "display/util.h" +#include "display/core.h" +#include "display/display-ops.h" +#include "core/common.h" +#include "core/config-parser.h" +#include "core/device-notifier.h" + +#define DISPLAY_CONF_FILE "/etc/deviced/display.conf" + +#define SIGNAL_LBM_ON "LBMOn" +#define SIGNAL_LBM_OFF "LBMOff" + +#define LCD_PHASED_DELAY 10000 /* microsecond */ + +#define LBM_TRANSIT_STEP 20 + +struct lbm_config lbm_conf = { + .support = 0, + .down_level = 0, + .brt_table_size = 0, + .brt_table = NULL, + .aod_brightness_level = 0, +}; + +static bool lbm_state; +static int lbm_setting_mode; +static int system_brightness; +static struct display_device *display_dev; + +static void broadcast_lbm_state(int state) +{ + char *str; + + if (state == 1) + str = SIGNAL_LBM_ON; + else + str = SIGNAL_LBM_OFF; + + dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + str, + NULL); +} + +static int get_level_by_brt(int brt) +{ + int iter; + for (iter = 0; iter < lbm_conf.brt_table_size; iter++) { + if (lbm_conf.brt_table[iter] == brt) + return iter; + } + return -EINVAL; +} + +static int lbm_down_brt(int brt) +{ + int level; + int down_level; + + if (lbm_conf.down_level == 0) { + _I("LBM down level setting is 0."); + return brt; + } + + if (lbm_conf.brt_table == NULL || lbm_setting_mode == 0) { + _I("LBM setting mode is %d.", lbm_setting_mode); + return brt; + } + + level = get_level_by_brt(brt); + down_level = level - lbm_conf.down_level; + + if (down_level < 0) + down_level = 0; + + return lbm_conf.brt_table[down_level]; +} + +int lbm_get_state(void) +{ + if (!lbm_conf.support) + return -ENODEV; + + return lbm_state; +} + +static int lbm_get_brightness(int *val) +{ + if (system_brightness == 0) + _E("Failed to get brightness."); + + *val = system_brightness; + + return 0; +} + +static int lbm_set_brightness(int val) +{ + int brt = 0; + + if (!display_dev || !display_dev->set_brightness) { + _E("There is no display device."); + return -ENOENT; + } + + if (pm_status_flag & DIM_MASK) + val = 0; + else + brt = lbm_down_brt(val); + + system_brightness = val; + + _I("Set brightness(LBM on) system=%d, real=%d.", val, brt); + device_notify(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, (void *)&val); + + return display_dev->set_brightness(brt); +} + +static void lbm_change_brightness(int start, int end, int step) +{ + int diff, val; + int ret = -1; + int prev; + + if (display_dimstay_check()) + return; + + ret = backlight_ops.get_brightness(&prev); + + if (ret < 0) { + _E("Failed to get brightness, %d.", ret); + return; + } + + if (prev == end) + return; + + if (pm_status_flag & DIM_MASK) + end = 0; + + _I("Start %d, end %d, step %d.", start, end, step); + + if (display_dev && display_dev->set_multi_brightness) { + diff = lbm_down_brt(end); + + ret = display_dev->set_multi_brightness(diff, step, LCD_PHASED_DELAY); + if (ret < 0) + _E("Failed to set_multi_brightness, %d.", ret); + + backlight_ops.set_brightness(end); + + return; + } + + diff = end - start; + + if (abs(diff) < step) + val = (diff > 0 ? 1 : -1); + else + val = (int)ceil((double)diff / step); + + while (start != end) { + if (val == 0) + break; + + start += val; + if ((val > 0 && start > end) || + (val < 0 && start < end)) + start = end; + + usleep(LCD_PHASED_DELAY); + backlight_ops.set_brightness(start); + } +} + +int lbm_set_state(int lbm) +{ + int brt; + _I("lbm_set_state"); + + if (lbm == lbm_state) { + _W("already lbm %s", (lbm_state ? "on" : "off")); + return 0; + } + + if (!lbm || lbm_setting_mode) { + lbm_state = lbm; + broadcast_lbm_state(lbm_state); + } + + brt = backlight_ops.get_default_brt(); + _I("Default brightness: %d", brt); + if (lbm && lbm_setting_mode) { + _I("Lowering Brightness."); + backlight_ops.transit_brt(brt, lbm_down_brt(brt), LBM_TRANSIT_STEP); + backlight_ops.get_brightness(&system_brightness); + backlight_ops.set_brightness = lbm_set_brightness; + backlight_ops.get_brightness = lbm_get_brightness; + backlight_ops.transit_brt = lbm_change_brightness; + } else { + system_brightness = 0; + backlight_ops.restore_brightness_func(); + backlight_ops.transit_brt(lbm_down_brt(brt), brt, display_conf.brightness_change_step); + } + + backlight_ops.set_brightness(brt); + + return 0; +} + +static void lbm_table_load(char *value, struct lbm_config *c) +{ + char *p, *saveptr; + int level_count = 1; + int i; + + if (value == '\0') + return; + + for (i = 0; *(value + i) != '\0'; i++) { + if (*(value + i) == ',') + level_count++; + } + + c->brt_table = malloc(sizeof(int) * level_count); + if (!c->brt_table) { + _E("Failed to allocate memory."); + return; + } + c->brt_table_size = level_count; + + i = 0; + p = strtok_r(value, ",", &saveptr); + if (p) + c->brt_table[i++] = atoi(p); + + while (p != NULL) { + p = strtok_r(NULL, ",", &saveptr); + if (p) + c->brt_table[i++] = atoi(p); + } +} + +static int lbm_load_config(struct parse_result *result, void *user_data) +{ + struct lbm_config *c = user_data; + + _D("%s,%s,%s.", result->section, result->name, result->value); + + if (!c) + return -EINVAL; + + if (!MATCH(result->section, "Display")) + return 0; + + if (MATCH(result->name, "LBMsupport")) { + c->support = (MATCH(result->value, "yes") ? 1 : 0); + _D("lbm support is %d", c->support); + } else if (MATCH(result->name, "Level")) { + SET_CONF(c->down_level, atoi(result->value)); + _D("lbm down level is %d", c->down_level); + } else if (MATCH(result->name, "BrtTable")) { + lbm_table_load(result->value, c); + _D("LBM table loaded."); + } + + return 0; +} + +static void lbm_mode_changed(keynode_t *key_nodes, void *data) +{ + int mode = vconf_keynode_get_bool(key_nodes); + + _I("LBM setting value is %s.", mode ? "enable" : "disable"); + + lbm_setting_mode = mode; + + if (lbm_get_state()) + lbm_set_state(false); +} + +static int display_off_changed(void *data) +{ + int brt; + + backlight_ops.get_brightness(&brt); + backlight_ops.restore_brightness_func(); + backlight_ops.set_brightness(brt); + + lbm_state = 0; + + return 0; +} + +static GVariant *dbus_getlbm(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + int lbm; + + lbm = lbm_get_state(); + if (lbm < 0) + _E("Failed to get low brightness mode %d.", lbm); + else + _D("Get low brightness mode %d.", lbm); + + return g_variant_new("(i)", lbm); +} + +static const dbus_method_s dbus_methods[] = { + { "GetLBM", NULL, "i", dbus_getlbm }, +}; + +static const dbus_interface_u dbus_interface = { + .oh = NULL, + .name = DEVICED_INTERFACE_DISPLAY, + .methods = dbus_methods, + .nr_methods = ARRAY_SIZE(dbus_methods), +}; +static void lbm_init(void *data) +{ + int ret; + + /* load configutation */ + ret = config_parse(DISPLAY_CONF_FILE, lbm_load_config, &lbm_conf); + if (ret < 0) + _W("Failed to load %s, %d. Use default value.", DISPLAY_CONF_FILE, ret); + + ret = vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_AUTOMATIC_LOW_BRIGHTNESS, &lbm_setting_mode); + if (ret < 0) + _E("Failed to get VCONFKEY_SETAPPL_ACCESSIBILITY_AUTOMATIC_LOW_BRIGHTNESS, %d.", ret); + + vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_AUTOMATIC_LOW_BRIGHTNESS, lbm_mode_changed, NULL); + + ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_DISPLAY, &dbus_interface); + if (ret < 0) + _E("Failed to init dbus method, %d.", ret); + + display_dev = display_dev_get(); + + _I("LBM setting value is %d.", lbm_setting_mode); + + /* register notifier */ + register_notifier(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, display_off_changed); +} + +static const struct display_ops display_lbm_ops = { + .name = "lbm", + .init = lbm_init, +}; + +DISPLAY_OPS_REGISTER(&display_lbm_ops) diff --git a/plugins/wearable/display/lbm.h b/plugins/wearable/display/lbm.h new file mode 100644 index 0000000..5b1e319 --- /dev/null +++ b/plugins/wearable/display/lbm.h @@ -0,0 +1,50 @@ +/* + * deviced + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file lbm.h + * @brief Low Brightness Mode header file + */ +#ifndef __LBM_H__ +#define __LBM_H__ + +/* + * @brief Configuration structure + */ +struct lbm_config { + int support; + int down_level; + int brt_table_size; + int *brt_table; + int aod_brightness_level; +}; + +/* + * Global variables + * lbm_conf : configuration of lbm + */ +struct lbm_config lbm_conf; + +int lbm_get_state(void); +int lbm_set_state(int lbm); + +/** + * @} + */ + +#endif diff --git a/plugins/wearable/display/weaks.h b/plugins/wearable/display/weaks.h new file mode 100644 index 0000000..e8c764e --- /dev/null +++ b/plugins/wearable/display/weaks.h @@ -0,0 +1,29 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __DISPLAY_WEAKS_H__ +#define __DISPLAY_WEAKS_H__ + +#include "core/common.h" +#include "display/core.h" + +bool __WEAK__ get_outdoor_setting(void); + +#endif + -- 2.7.4