From 9eb172cee4e9ed33ccd508868213721d11336412 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 4 Aug 2020 13:27:39 +0900 Subject: [PATCH 01/16] Add doze_pmqos_request for cpu throttling Request for cpu throttling is sent from DEVICED to PASS, when LCD is ON or OFF ex) LCD OFF : 1 to enter doze mode LCD ON : 0 to leave doze mode Change-Id: I4a655be04dd5bbd5198e452bda85cbd9df8f06e7 Signed-off-by: lokilee73 --- src/power/doze.c | 17 +++++++++++++++++ src/power/doze.h | 6 +++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/power/doze.c b/src/power/doze.c index 743e44e..a866c84 100644 --- a/src/power/doze.c +++ b/src/power/doze.c @@ -35,6 +35,21 @@ static enum doze_level doze_level; static int display_state; static bool doze_initialized = false; +int doze_pmqos_request(int req) +{ + int ret = 0; + + ret = dbus_handle_method_async_var(PASS_BUS_NAME, + PASS_PATH_PMQOS, + PASS_INTERFACE_PMQOS, + PASS_METHOD_DOZE, + g_variant_new("(si)", "Doze", req)); + if (ret < 0) + _E("Failed to request pmqos: %d", ret); + + return ret; +} + static int change_doze_level(enum doze_level level) { int ret; @@ -67,6 +82,7 @@ static void _enter_doze(void) _D("Entering doze mode."); change_doze_level(DOZE_LEVEL_1); + doze_pmqos_request(DOZE_PMQOS_START); } static void _leave_doze(void) @@ -77,6 +93,7 @@ static void _leave_doze(void) _D("Leaving doze mode."); change_doze_level(DOZE_LEVEL_0); + doze_pmqos_request(DOZE_PMQOS_STOP); } void enter_doze(void) diff --git a/src/power/doze.h b/src/power/doze.h index 435fdd9..e6236e9 100644 --- a/src/power/doze.h +++ b/src/power/doze.h @@ -19,9 +19,13 @@ #ifndef __DOZE_H__ #define __DOZE_H__ +/* To request pmqos start and stop for Doze */ +#define DOZE_PMQOS_START 1 +#define DOZE_PMQOS_STOP 0 + void enter_doze(void); void leave_doze(void); int doze_init(void); int doze_exit(void); - +int doze_pmqos_request(int req); #endif -- 2.7.4 From f9ed02da14800197ef4d42b9fdaea9935b5ac323 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 16 Jul 2020 16:02:11 +0900 Subject: [PATCH 02/16] Change display_plgn, battery_plgn static Change-Id: I3933a70a3f197cf6955b378429aa99c6e1f69150 Signed-off-by: Youngjae Cho --- plugins/iot/display/core.c | 44 ++++++++---- plugins/iot/display/key-filter.c | 18 +++-- plugins/mobile/battery/battery-notification.c | 22 +++--- plugins/mobile/display/core.c | 43 +++++++---- plugins/mobile/display/key-filter.c | 18 +++-- plugins/tv/display/core.c | 43 +++++++---- plugins/tv/display/key-filter.c | 18 +++-- plugins/tv/display/state-tv.c | 10 ++- .../wearable/display/auto-brightness-sensorhub.c | 10 ++- plugins/wearable/display/bezel.c | 20 ++++-- plugins/wearable/display/core.c | 43 +++++++---- plugins/wearable/display/key-filter.c | 18 +++-- plugins/wearable/display/swim.c | 15 ++-- src/apps/apps.c | 16 +++-- src/apps/apps.h | 2 + src/battery/battery-ops.h | 1 - src/battery/battery-time.c | 11 ++- src/battery/lowbat-handler.c | 40 +++++++---- src/battery/power-supply.c | 84 ++++++++++++---------- src/display/ambient-mode.c | 30 ++++---- src/display/display-dbus.c | 55 ++++++++------ src/display/display-ops.h | 1 - src/display/display-signal.c | 14 ++-- src/display/display-signal.h | 7 ++ src/display/display.h | 1 - src/display/poll.c | 14 +++- src/display/setting.c | 16 +++-- src/extcon/cradle.c | 22 +++--- src/extcon/earjack.c | 14 +++- src/extcon/hdmi.c | 22 +++--- src/led/touch-key.c | 8 ++- src/power/boot.c | 15 +++- src/power/power-handler.c | 19 +++-- src/shared/plugin.c | 17 +++-- src/shared/plugin.h | 6 ++ src/time/time-handler.c | 24 ++++--- src/touchscreen/touchscreen.c | 16 +++-- src/usb/usb.c | 16 +++-- src/usbhost/usb-host.c | 22 +++--- 39 files changed, 550 insertions(+), 265 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index bc8cf99..1813c8f 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -62,6 +62,7 @@ #include "display-dpms.h" #include "display-signal.h" #include "display-lock.h" +#include "shared/plugin.h" #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -91,6 +92,8 @@ extern void init_pm_internal(); extern int get_charging_status(int *val); extern void init_save_userlock(void); +static struct display_plugin *disp_plgn; + static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -461,8 +464,8 @@ void set_stay_touchscreen_off(int val) _I("Stay touch screen off: %d", val); stay_touchscreen_off = val; - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, 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) @@ -470,8 +473,8 @@ void set_lcd_paneloff_mode(int val) _I("Lcd paneloff mode: %d", val); lcd_paneloff_mode = val; - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } int low_battery_state(int val) @@ -1317,9 +1320,9 @@ void save_display_log(const char *path) if (ret < 0) _E("write() failed (%d)", errno); - if (disp_plgn.get_lock_screen_state ) { + if (disp_plgn->get_lock_screen_state ) { snprintf(buf, sizeof(buf), "screen lock status : %d\n", - disp_plgn.get_lock_screen_state()); + disp_plgn->get_lock_screen_state()); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("write() failed (%d)", errno); @@ -2006,9 +2009,9 @@ static int booting_done(void *data) return done; _I("Booting done, release booting lock."); - 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); + 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; @@ -2182,6 +2185,16 @@ static void add_timer_for_init_dpms(void) * Power manager Main * */ +static void set_module_display_plugin(void) +{ + disp_plgn = get_display_plugin(); /* self */ + if (!disp_plgn) + _E("Failed to get display plugin."); + + set_apps_display_plugin(disp_plgn); /* apps */ + set_display_signal_display_plugin(disp_plgn); /* display-signal */ +} + static int display_probe(void *data) { int ret; @@ -2197,7 +2210,8 @@ static int display_probe(void *data) /* display_plugin instance initialization */ init_pm_internal(); - disp_plgn.device_flags_to_string = __device_flags_to_string; + set_module_display_plugin(); + disp_plgn->device_flags_to_string = __device_flags_to_string; return 0; } @@ -2258,6 +2272,8 @@ static void display_init(void *data) _I("Start power manager."); + set_module_display_plugin(); + signal(SIGHUP, sig_hup); power_saving_func = default_saving_mode; @@ -2350,8 +2366,8 @@ static void display_init(void *data) * 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, + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); /* Initial display state right after the booting done */ @@ -2370,8 +2386,8 @@ static void display_init(void *data) 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, + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, STAY_CUR_STATE, timeout); } diff --git a/plugins/iot/display/key-filter.c b/plugins/iot/display/key-filter.c index 6de2c63..d838430 100644 --- a/plugins/iot/display/key-filter.c +++ b/plugins/iot/display/key-filter.c @@ -38,6 +38,7 @@ #include "core/devices.h" #include "core/device-notifier.h" #include "shared/common.h" +#include "shared/plugin.h" #include "power/power-handler.h" #include "led/touch-key.h" #include "apps/apps.h" @@ -88,6 +89,7 @@ enum combination_process { COMBINATION_QUICKTALK = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_VOLUMEDOWN, }; +static struct display_plugin *disp_plgn; static struct timeval pressed_time; static guint longkey_timeout_id = 0; static guint longkey_restore_id = 0; @@ -135,8 +137,8 @@ static void longkey_pressed(void) if (display_has_caps(caps, DISPLAY_CAPA_LCDON)) { /* change state - LCD on */ - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); (*pm_callback)(INPUT_POLL_EVENT, NULL); } @@ -398,8 +400,8 @@ static int lcdoff_powerkey(void) 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); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); } } else { ignore = false; @@ -509,8 +511,8 @@ static int process_screenlock_key(struct input_event *pinput) update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(-1, LCD_OFF); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(-1, LCD_OFF); } return true; @@ -754,6 +756,10 @@ static struct display_actor_ops display_menukey_actor = { static void keyfilter_init(void) { + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + display_add_actor(&display_powerkey_actor); display_add_actor(&display_menukey_actor); diff --git a/plugins/mobile/battery/battery-notification.c b/plugins/mobile/battery/battery-notification.c index 5ba04e0..3903c0d 100644 --- a/plugins/mobile/battery/battery-notification.c +++ b/plugins/mobile/battery/battery-notification.c @@ -32,6 +32,7 @@ #include "display/display-ops.h" #include "display/poll.h" #include "shared/eventsystem.h" +#include "shared/plugin.h" #include "core/device-notifier.h" @@ -50,6 +51,7 @@ enum event_noti_type { NOTI_UPDATE = 0, }; +static struct display_plugin *disp_plgn; static guint abnormal_timer; static int noti_low = NOTI_NONE; @@ -157,8 +159,8 @@ static int launch_lowbat_noti(int capacity, int option) noti_type = METHOD_LOW_NOTI_UPDATE; else { noti_type = METHOD_LOW_NOTI_ON; - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_LOWBAT, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_LOWBAT, LCD_NORMAL); } prev_level = battery_info.warning; if (battery.charge_now) @@ -198,8 +200,8 @@ static int launch_lowbat_noti(int capacity, int option) noti_type = METHOD_CRITICAL_NOTI_UPDATE; else { noti_type = METHOD_CRITICAL_NOTI_ON; - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_LOWBAT, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_LOWBAT, LCD_NORMAL); } prev_level = battery_info.critical; if (battery.charge_now) @@ -329,10 +331,10 @@ static gboolean health_timer_cb(void *data) CRITICAL_LOG("Popup: Battery health status is not good, %s.", battery.health_s); device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)&battery.health); battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_DIM); - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); if (battery.health == HEALTH_LOW) battery_charge_err_low_act(NULL); else if (battery.health == HEALTH_HIGH) @@ -379,6 +381,10 @@ static void battery_notification_init(void *data) if (!plugin) return; + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + _D("Add plugins for battery notification."); plugin->lowbat_noti_launch = launch_lowbat_noti; plugin->lowbat_noti_clean = clean_lowbat_noti; diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 8b7142b..78c8892 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -64,6 +64,7 @@ #include "display-info.h" #include "display-signal.h" #include "display-lock.h" +#include "shared/plugin.h" #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -93,6 +94,8 @@ extern void init_pm_internal(); extern int get_charging_status(int *val); extern void init_save_userlock(void); +static struct display_plugin *disp_plgn; + static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -468,8 +471,8 @@ void set_stay_touchscreen_off(int val) _I("Stay touch screen off: %d", val); stay_touchscreen_off = val; - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, 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) @@ -477,8 +480,8 @@ void set_lcd_paneloff_mode(int val) _I("Lcd paneloff mode: %d", val); lcd_paneloff_mode = val; - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } int low_battery_state(int val) @@ -1327,9 +1330,9 @@ void save_display_log(const char *path) if (ret < 0) _E("write() failed (%d)", errno); - if (disp_plgn.get_lock_screen_state ) { + if (disp_plgn->get_lock_screen_state ) { snprintf(buf, sizeof(buf), "screen lock status : %d\n", - disp_plgn.get_lock_screen_state()); + disp_plgn->get_lock_screen_state()); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("write() failed (%d)", errno); @@ -2016,9 +2019,9 @@ static int booting_done(void *data) return done; _I("Booting done, release booting lock."); - 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); + 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; @@ -2192,6 +2195,17 @@ static void add_timer_for_init_dpms(void) * Power manager Main * */ + +static void set_module_display_plugin(void) +{ + disp_plgn = get_display_plugin(); /* self */ + if (!disp_plgn) + _E("Failed to get display plugin."); + + set_apps_display_plugin(disp_plgn); /* apps */ + set_display_signal_display_plugin(disp_plgn); /* display-signal */ +} + static int display_probe(void *data) { int ret; @@ -2207,7 +2221,8 @@ static int display_probe(void *data) /* display_plugin instance initialization */ init_pm_internal(); - disp_plgn.device_flags_to_string = __device_flags_to_string; + set_module_display_plugin(); + disp_plgn->device_flags_to_string = __device_flags_to_string; return 0; } @@ -2360,8 +2375,8 @@ static void display_init(void *data) * 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, + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); /* Initial display state right after the booting done */ @@ -2380,8 +2395,8 @@ static void display_init(void *data) 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, + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, STAY_CUR_STATE, timeout); } diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index 1bd2c08..25905cb 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -38,6 +38,7 @@ #include "core/devices.h" #include "core/device-notifier.h" #include "shared/common.h" +#include "shared/plugin.h" #include "power/power-handler.h" #include "led/touch-key.h" #include "apps/apps.h" @@ -88,6 +89,7 @@ enum combination_process { COMBINATION_QUICKTALK = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_VOLUMEDOWN, }; +static struct display_plugin *disp_plgn; static struct timeval pressed_time; static guint longkey_timeout_id = 0; static guint longkey_restore_id = 0; @@ -125,8 +127,8 @@ static void longkey_pressed(void) if (display_has_caps(caps, DISPLAY_CAPA_LCDON)) { /* change state - LCD on */ - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); (*pm_callback)(INPUT_POLL_EVENT, NULL); } @@ -387,8 +389,8 @@ static int lcdoff_powerkey(void) 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); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); } } else { ignore = false; @@ -542,8 +544,8 @@ static int process_screenlock_key(struct input_event *pinput) update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(-1, LCD_OFF); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(-1, LCD_OFF); } return true; @@ -781,6 +783,10 @@ static struct display_actor_ops display_menukey_actor = { static void keyfilter_init(void) { + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + display_add_actor(&display_powerkey_actor); display_add_actor(&display_menukey_actor); diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index dd0c311..9edae8c 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -62,6 +62,7 @@ #include "display-dpms.h" #include "display-signal.h" #include "display-lock.h" +#include "shared/plugin.h" #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -91,6 +92,8 @@ extern void init_pm_internal(); extern int get_charging_status(int *val); extern void init_save_userlock(void); +static struct display_plugin *disp_plgn; + static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -461,8 +464,8 @@ void set_stay_touchscreen_off(int val) _I("Stay touch screen off: %d", val); stay_touchscreen_off = val; - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, 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) @@ -470,8 +473,8 @@ void set_lcd_paneloff_mode(int val) _I("Lcd paneloff mode: %d", val); lcd_paneloff_mode = val; - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } int low_battery_state(int val) @@ -1317,9 +1320,9 @@ void save_display_log(const char *path) if (ret < 0) _E("write() failed (%d)", errno); - if (disp_plgn.get_lock_screen_state ) { + if (disp_plgn->get_lock_screen_state ) { snprintf(buf, sizeof(buf), "screen lock status : %d\n", - disp_plgn.get_lock_screen_state()); + disp_plgn->get_lock_screen_state()); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("write() failed (%d)", errno); @@ -2006,9 +2009,9 @@ static int booting_done(void *data) return done; _I("Booting done, release booting lock."); - 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); + 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; @@ -2182,6 +2185,17 @@ static void add_timer_for_init_dpms(void) * Power manager Main * */ + +static void set_module_display_plugin(void) +{ + disp_plgn = get_display_plugin(); /* self */ + if (!disp_plgn) + _E("Failed to get display plugin."); + + set_apps_display_plugin(disp_plgn); /* apps */ + set_display_signal_display_plugin(disp_plgn); /* display-signal */ +} + static int display_probe(void *data) { int ret; @@ -2197,7 +2211,8 @@ static int display_probe(void *data) /* display_plugin instance initialization */ init_pm_internal(); - disp_plgn.device_flags_to_string = __device_flags_to_string; + set_module_display_plugin(); + disp_plgn->device_flags_to_string = __device_flags_to_string; return 0; } @@ -2350,8 +2365,8 @@ static void display_init(void *data) * 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, + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); /* Initial display state right after the booting done */ @@ -2370,8 +2385,8 @@ static void display_init(void *data) 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, + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, STAY_CUR_STATE, timeout); } diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index c11aff4..a038caa 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -38,6 +38,7 @@ #include "core/devices.h" #include "core/device-notifier.h" #include "shared/common.h" +#include "shared/plugin.h" #include "power/power-handler.h" #include "led/touch-key.h" #include "apps/apps.h" @@ -88,6 +89,7 @@ enum combination_process { COMBINATION_QUICKTALK = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_VOLUMEDOWN, }; +static struct display_plugin *disp_plgn; static struct timeval pressed_time; static guint longkey_timeout_id = 0; static guint longkey_restore_id = 0; @@ -135,8 +137,8 @@ static void longkey_pressed(void) if (display_has_caps(caps, DISPLAY_CAPA_LCDON)) { /* change state - LCD on */ - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); (*pm_callback)(INPUT_POLL_EVENT, NULL); } @@ -398,8 +400,8 @@ static int lcdoff_powerkey(void) 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); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); } } else { ignore = false; @@ -509,8 +511,8 @@ static int process_screenlock_key(struct input_event *pinput) update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(-1, LCD_OFF); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(-1, LCD_OFF); } return true; @@ -748,6 +750,10 @@ static struct display_actor_ops display_menukey_actor = { static void keyfilter_init(void) { + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + display_add_actor(&display_powerkey_actor); display_add_actor(&display_menukey_actor); diff --git a/plugins/tv/display/state-tv.c b/plugins/tv/display/state-tv.c index 68f6a1e..663b66f 100644 --- a/plugins/tv/display/state-tv.c +++ b/plugins/tv/display/state-tv.c @@ -31,6 +31,7 @@ #include "poll.h" #include "device-interface.h" #include "util.h" +#include "shared/plugin.h" #define PRE_STATE_CHANGE_TIMEOUT 500*1000 /* 500ms */ #define SIGNAL_CHANGE_STATE "ChangeState" @@ -40,6 +41,7 @@ #define SIGNAL_POST_WAKEUP "PostWakeUp" #define SIGNAL_EARLY_WAKEUP "EarlyWakeUp" +static struct display_plugin *disp_plgn; static guint standby_timer; static int change_state(pid_t pid, int type, enum state_t st) @@ -328,8 +330,8 @@ static gboolean standby_go_next_state(void *data) standby_timer = 0; } - if (disp_plgn.pm_change_internal) - ret = disp_plgn.pm_change_internal(INTERNAL_LOCK_SUSPEND, SUSPEND); + if (disp_plgn->pm_change_internal) + ret = disp_plgn->pm_change_internal(INTERNAL_LOCK_SUSPEND, SUSPEND); if (ret < 0) { _E("Failed to change state to S_SUSPEND. Now Power off !!"); poweroff_trans(0); @@ -548,6 +550,10 @@ void state_tv_init(void) _I("TV Profile !!"); + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + for (i = 0 ; i < ARRAY_SIZE(tv_states) ; i++) set_tv_operations(tv_states[i].state, tv_states[i].name, diff --git a/plugins/wearable/display/auto-brightness-sensorhub.c b/plugins/wearable/display/auto-brightness-sensorhub.c index b5c6e47..c096090 100644 --- a/plugins/wearable/display/auto-brightness-sensorhub.c +++ b/plugins/wearable/display/auto-brightness-sensorhub.c @@ -32,9 +32,11 @@ #include "display/display-ops.h" #include "core/device-notifier.h" #include "battery/power-supply.h" +#include "shared/plugin.h" #define LOWBATCAPACITY 5 +static struct display_plugin *disp_plgn; static int auto_brightness_state = SETTING_BRIGHTNESS_AUTOMATIC_OFF; static bool lbm, hbm, hold, lowdim; @@ -331,8 +333,14 @@ int prepare_level_handler(void) { int status, ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + return -1; + } + display_info.set_brightness_level = set_brightness_level; - disp_plgn.auto_brightness_control = auto_brightness_control; + disp_plgn->auto_brightness_control = auto_brightness_control; ret = vconf_get_int(VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, &status); if (ret >= 0) diff --git a/plugins/wearable/display/bezel.c b/plugins/wearable/display/bezel.c index 557baee..6fb927f 100644 --- a/plugins/wearable/display/bezel.c +++ b/plugins/wearable/display/bezel.c @@ -15,6 +15,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include +#include +#include #include "core/devices.h" #include "core/common.h" @@ -23,9 +26,7 @@ #include "display/poll.h" #include "display/core.h" #include "display-ops.h" -#include -#include -#include +#include "shared/plugin.h" #ifndef VCONFKEY_SETAPPL_WAKEUP_BY_BEZEL_ENABLE #define VCONFKEY_SETAPPL_WAKEUP_BY_BEZEL_ENABLE "db/setting/wakeup_by_bezel_enable" @@ -43,6 +44,7 @@ enum bezel_type { static enum bezel_state bezel_wakeup_control(void); +static struct display_plugin *disp_plgn; static struct bezel_device *bezel_dev; static int bezel_wakeup = 0; static int theater_mode = 0; @@ -56,8 +58,8 @@ static void bezel_changed_cb(keynode_t *key_nodes, void *data) bezel_wakeup = vconf_keynode_get_bool(key_nodes); _I("Bezel wakeup condition: %d", bezel_wakeup); - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); device_notify(DEVICE_NOTIFIER_BEZEL_WAKEUP, (void *)((intptr_t)bezel_wakeup)); } @@ -120,8 +122,8 @@ static void bezel_rotary_event_cb(keynode_t *key_nodes, void *data) if (ret == 0) { _I("Bezel rotary event condition is %d", bezel_state); - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } else { _E("Failed to set bezel rotary event condition."); } @@ -192,6 +194,10 @@ static void bezel_init(void *data) if (!bezel_dev) return; + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + if (bezel_dev->get_sw_state && bezel_dev->get_sw_state(&init_bezel_state) == 0) { _I("Init SW bezel, state: %d", init_bezel_state); bezel_type = BEZEL_SOFT; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 094c829..314e0e7 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -65,6 +65,7 @@ #include "battery-monitor.h" #include "display/display-signal.h" #include "display-lock.h" +#include "shared/plugin.h" #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -98,6 +99,8 @@ extern void init_pm_internal(); extern int get_charging_status(int *val); extern void init_save_userlock(void); +static struct display_plugin *disp_plgn; + static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -487,8 +490,8 @@ void set_stay_touchscreen_off(int val) _I("Stay touch screen off: %d", val); stay_touchscreen_off = val; - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, 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) @@ -496,8 +499,8 @@ void set_lcd_paneloff_mode(int val) _I("Lcd paneloff mode: %d", val); lcd_paneloff_mode = val; - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } int low_battery_state(int val) @@ -1384,9 +1387,9 @@ void save_display_log(const char *path) if (ret < 0) _E("write() failed (%d)", errno); - if (disp_plgn.get_lock_screen_state ) { + if (disp_plgn->get_lock_screen_state ) { snprintf(buf, sizeof(buf), "screen lock status : %d\n", - disp_plgn.get_lock_screen_state()); + disp_plgn->get_lock_screen_state()); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("write() failed (%d)", errno); @@ -2097,9 +2100,9 @@ static int booting_done(void *data) return done; _I("Booting done, release booting lock."); - 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); + 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; @@ -2274,6 +2277,17 @@ static void add_timer_for_init_dpms(void) * Power manager Main * */ + +static void set_module_display_plugin(void) +{ + disp_plgn = get_display_plugin(); /* self */ + if (!disp_plgn) + _E("Failed to get display plugin."); + + set_apps_display_plugin(disp_plgn); /* apps */ + set_display_signal_display_plugin(disp_plgn); /* display-signal */ +} + static int display_probe(void *data) { int ret; @@ -2289,7 +2303,8 @@ static int display_probe(void *data) /* display_plugin instance initialization */ init_pm_internal(); - disp_plgn.device_flags_to_string = __device_flags_to_string; + set_module_display_plugin(); + disp_plgn->device_flags_to_string = __device_flags_to_string; return 0; } @@ -2474,8 +2489,8 @@ static void display_init(void *data) * 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, + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); /* Initial display state right after the booting done */ @@ -2494,8 +2509,8 @@ static void display_init(void *data) 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, + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, STAY_CUR_STATE, timeout); } diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 5500a8d..c960efa 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -38,6 +38,7 @@ #include "core/devices.h" #include "core/device-notifier.h" #include "shared/common.h" +#include "shared/plugin.h" #include "power/power-handler.h" #include "led/touch-key.h" #include "apps/apps.h" @@ -88,6 +89,7 @@ enum combination_process { COMBINATION_QUICKTALK = KEY_COMBINATION_POWERKEY | KEY_COMBINATION_VOLUMEDOWN, }; +static struct display_plugin *disp_plgn; static struct timeval pressed_time; static guint longkey_timeout_id = 0; static guint longkey_restore_id = 0; @@ -125,8 +127,8 @@ static void longkey_pressed(void) if (display_has_caps(caps, DISPLAY_CAPA_LCDON)) { /* change state - LCD on */ - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); (*pm_callback)(INPUT_POLL_EVENT, NULL); } @@ -395,8 +397,8 @@ static int lcdoff_powerkey(void) 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); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); } } else { ignore = false; @@ -506,8 +508,8 @@ static int process_screenlock_key(struct input_event *pinput) update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(-1, LCD_OFF); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(-1, LCD_OFF); } return true; @@ -728,6 +730,10 @@ static struct display_actor_ops display_menukey_actor = { static void keyfilter_init(void) { + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + display_add_actor(&display_powerkey_actor); display_add_actor(&display_menukey_actor); diff --git a/plugins/wearable/display/swim.c b/plugins/wearable/display/swim.c index 3ebca55..3e7a28a 100644 --- a/plugins/wearable/display/swim.c +++ b/plugins/wearable/display/swim.c @@ -23,12 +23,15 @@ #include "display/core.h" #include "display/util.h" #include "display/display-ops.h" +#include "shared/plugin.h" + #include #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 struct display_plugin *disp_plgn; static const struct device_ops *touchscreen_ops; static int swimmode_status; @@ -88,16 +91,16 @@ static void swimmode_signal_handler(GDBusConnection *conn, _I("Request swim mode state %d by %d", val, pid); if (backlight_ops.get_lcd_power != DPMS_ON) { - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_SWIM, S_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_SWIM, S_NORMAL); lcd_state = true; } swim_execute((void *)((intptr_t)val)); if (lcd_state) { - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_SWIM, S_LCDOFF); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_SWIM, S_LCDOFF); } } @@ -113,6 +116,10 @@ static void swim_init(void *data) { int ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + touchscreen_ops = find_device("touchscreen"); ret = subscribe_dbus_signal(NULL, diff --git a/src/apps/apps.c b/src/apps/apps.c index 59a9a33..b92e693 100644 --- a/src/apps/apps.c +++ b/src/apps/apps.c @@ -25,6 +25,8 @@ #define POPUP_METHOD "PopupLaunch" #define BUFF_MAX 255 +static struct display_plugin *disp_plgn; + static const struct app_dbus_match { const char *type; const char *bus; @@ -96,8 +98,9 @@ int launch_system_app(char *type, int num, ...) NULL); va_end(args); - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); + + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); return ret; } @@ -116,8 +119,8 @@ int launch_message_post(char *type) g_variant_new("(s)", type), __cb, -1, NULL); - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); return ret; } @@ -169,3 +172,8 @@ int remove_notification(char *type, int id) type, g_variant_new("(i)", id), __cb, -1, NULL); } + +void set_apps_display_plugin(struct display_plugin *dp) +{ + disp_plgn = dp; +} diff --git a/src/apps/apps.h b/src/apps/apps.h index f467ece..d455c8c 100644 --- a/src/apps/apps.h +++ b/src/apps/apps.h @@ -23,6 +23,7 @@ #include #include "core/common.h" #include "display/poll.h" +#include "display/display-ops.h" #define APP_POWERKEY "powerkey" #define APP_OVERHEAT "overheat" @@ -35,6 +36,7 @@ int launch_system_app(char *type, int num, ...); int launch_message_post(char *type); int add_async_notification(char *type, dbus_pending_cb func, char *sig, ...); int remove_notification(char *type, int id); +void set_apps_display_plugin(struct display_plugin *dp); #endif /* __APPS_H__ */ diff --git a/src/battery/battery-ops.h b/src/battery/battery-ops.h index a8397f0..dc30a69 100644 --- a/src/battery/battery-ops.h +++ b/src/battery/battery-ops.h @@ -46,7 +46,6 @@ struct battery_plugin { void (*update_ovp) (enum battery_noti_status status); /* Add plugins here */ }; -extern struct battery_plugin battery_plgn; void add_battery(const struct battery_ops *batt); void remove_battery(const struct battery_ops *batt); diff --git a/src/battery/battery-time.c b/src/battery/battery-time.c index 3fd0959..cc1e20f 100644 --- a/src/battery/battery-time.c +++ b/src/battery/battery-time.c @@ -30,6 +30,7 @@ #include "core/udev.h" #include "display/display-ops.h" #include "power-supply.h" +#include "shared/plugin.h" #define CHARGING_STATE(x) ((x) & CHRGR_FLAG) #define FULL_CAPACITY (100) @@ -61,6 +62,8 @@ enum state_a { A_END = 2 }; +static struct display_plugin *disp_plgn; + static guint timeout_id; static struct Batt_node *batt_head[B_END]; @@ -296,9 +299,9 @@ static int battinfo_calculation(void) update_time(A_TIMETOFULL, estimated_time); } else { del_all_batt_node(B_CHARGING); - if (disp_plgn.system_wakeup_flag == true) { + if (disp_plgn->system_wakeup_flag == true) { del_all_batt_node(B_UNCHARGING); - disp_plgn.system_wakeup_flag = false; + disp_plgn->system_wakeup_flag = false; } if (batt_head[B_UNCHARGING] == NULL) { add_batt_node(B_UNCHARGING, clock, capacity); @@ -408,6 +411,10 @@ static void battery_init(void *data) { int ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_BATTERY, &dbus_interface); if (ret < 0) _E("Failed to init dbus method: %d", ret); diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index dde0e19..d5b5d6b 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -39,6 +39,7 @@ #include "core/list.h" #include "core/udev.h" #include "shared/eventsystem.h" +#include "shared/plugin.h" #include "display/setting.h" #include "display/poll.h" #include "display/display-ops.h" @@ -66,6 +67,9 @@ struct lowbat_process_entry { int (*func) (void *data); }; +static struct display_plugin *disp_plgn; +static struct battery_plugin *battery_plgn; + static int cur_bat_state = BATTERY_UNKNOWN; static int cur_bat_capacity = BATTERY_UNKNOWN; static int custom_warning_level = BATTERY_UNKNOWN; @@ -245,11 +249,11 @@ direct_launch: if (lowbat_popup_option == BAT_OPT_ERR_TEMP_LOW || lowbat_popup_option == BAT_OPT_ERR_TEMP_HIGH || lowbat_popup_option == BAT_OPT_ERR_CF_OPEN) { - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_LOWBAT, LCD_DIM); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_LOWBAT, LCD_DIM); } else { - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_LOWBAT, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_LOWBAT, LCD_NORMAL); } if (lowbat_popup_option == BAT_OPT_ERR_TEMP_LOW || lowbat_popup_option == BAT_OPT_ERR_TEMP_HIGH || @@ -266,8 +270,8 @@ direct_launch: static int battery_warning_low_act(void *data) { - if (battery_plgn.lowbat_noti_launch) - battery_plgn.lowbat_noti_launch(cur_bat_capacity, BAT_OPT_WARNING); + if (battery_plgn->lowbat_noti_launch) + battery_plgn->lowbat_noti_launch(cur_bat_capacity, BAT_OPT_WARNING); (void)lowbat_popup(BAT_OPT_WARNING); return 0; @@ -275,8 +279,8 @@ static int battery_warning_low_act(void *data) static int battery_critical_low_act(void *data) { - if (battery_plgn.lowbat_noti_launch) - battery_plgn.lowbat_noti_launch(cur_bat_capacity, BAT_OPT_CRITICAL); + if (battery_plgn->lowbat_noti_launch) + battery_plgn->lowbat_noti_launch(cur_bat_capacity, BAT_OPT_CRITICAL); (void)lowbat_popup(BAT_OPT_CRITICAL); return 0; @@ -295,13 +299,13 @@ int battery_charge_err_cf_act(void *data) int battery_charge_err_low_act(void *data) { - disp_plgn.pm_lock_internal(INTERNAL_LOCK_OVERCOOL, LCD_OFF, STAY_CUR_STATE, 60000); + disp_plgn->pm_lock_internal(INTERNAL_LOCK_OVERCOOL, LCD_OFF, STAY_CUR_STATE, 60000); return lowbat_popup(BAT_OPT_ERR_TEMP_LOW); } int battery_charge_err_high_act(void *data) { - disp_plgn.pm_lock_internal(INTERNAL_LOCK_OVERHEAT, LCD_OFF, STAY_CUR_STATE, 60000); + disp_plgn->pm_lock_internal(INTERNAL_LOCK_OVERHEAT, LCD_OFF, STAY_CUR_STATE, 60000); return lowbat_popup(BAT_OPT_ERR_TEMP_HIGH); } @@ -347,8 +351,8 @@ static void battery_level_send_system_event(int bat_percent) else str = EVT_VAL_BATTERY_LEVEL_EMPTY; - if (battery_plgn.lowbat_noti_clean && prev) - battery_plgn.lowbat_noti_clean(prev, str); + if (battery_plgn->lowbat_noti_clean && prev) + battery_plgn->lowbat_noti_clean(prev, str); if (prev == str) return; @@ -544,8 +548,8 @@ static int lowbat_process(int bat_percent, void *ad) if (status != -1) { result = status; - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOW_BATT, status); + if (disp_plgn->update_pm_setting) + disp_plgn->update_pm_setting(SETTING_LOW_BATT, status); } else result = vconf_state; @@ -705,6 +709,14 @@ static void lowbat_init(void *data) { int ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + + battery_plgn = get_battery_plugin(); + if (!battery_plgn) + _E("Failed to get battery plugin."); + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); register_notifier(DEVICE_NOTIFIER_POWER_SUPPLY, lowbat_monitor_init); diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 08f4fad..b953207 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -33,6 +33,7 @@ #include "display/poll.h" #include "display/setting.h" #include "shared/eventsystem.h" +#include "shared/plugin.h" #include "display/core.h" #include "display/display-ops.h" #include "apps/apps.h" @@ -81,6 +82,9 @@ #define BATTERY_CHECK_TIMER_INTERVAL 500 /* 0.5 second */ #define LCD_DIM_TIME_IN_BATTERY_HEALTH 10000 /* ms */ +static struct display_plugin *disp_plgn; +static struct battery_plugin *battery_plgn; + static void uevent_power_handler(struct udev_device *dev); static const struct uevent_handler uh = { .subsystem = POWER_SUBSYSTEM, @@ -208,8 +212,8 @@ static int send_full_noti(enum charge_full_type state) int noti = 0; int retry; - if (battery_plgn.check_power_supply_noti) - noti = battery_plgn.check_power_supply_noti(); + if (battery_plgn->check_power_supply_noti) + noti = battery_plgn->check_power_supply_noti(); if (!noti) return ret; @@ -371,7 +375,7 @@ static void noti_batt_full(void) power_supply_noti(DEVICE_NOTI_BATT_FULL, DEVICE_NOTI_ON); bat_full_noti = 1; /* turn on LCD, if battery is fully charged */ - if (battery_plgn.check_power_supply_noti && battery_plgn.check_power_supply_noti()) { + if (battery_plgn->check_power_supply_noti && battery_plgn->check_power_supply_noti()) { battery_pm_change_internal(INTERNAL_LOCK_BATTERY_FULL, LCD_NORMAL); } else _I("Block LCD."); @@ -384,8 +388,8 @@ static void noti_batt_full(void) static void check_power_supply(int state) { pm_check_and_change(state); - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_CHARGING, state); + if (disp_plgn->update_pm_setting) + disp_plgn->update_pm_setting(SETTING_CHARGING, state); } static void charger_state_send_system_event(int state) @@ -430,16 +434,16 @@ static void update_present(enum battery_noti_status status) if (status == DEVICE_NOTI_ON) { battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_DIM); device_notify(DEVICE_NOTIFIER_BATTERY_PRESENT, (void *)&battery.present); - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); } else { battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); device_notify(DEVICE_NOTIFIER_BATTERY_PRESENT, (void *)&battery.present); - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, PM_SLEEP_MARGIN); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, PM_SLEEP_MARGIN); } - if (battery_plgn.changed_battery_cf) - battery_plgn.changed_battery_cf(battery.present); + if (battery_plgn->changed_battery_cf) + battery_plgn->changed_battery_cf(battery.present); } static void launch_health_popup(void) @@ -452,10 +456,10 @@ static void launch_health_popup(void) device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)&battery.health); battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_DIM); - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, LCD_DIM_TIME_IN_BATTERY_HEALTH); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, LCD_DIM_TIME_IN_BATTERY_HEALTH); if (battery.health == HEALTH_LOW) battery_charge_err_low_act(NULL); else if (battery.health == HEALTH_HIGH) @@ -486,9 +490,9 @@ static void update_health(enum battery_noti_status status) } else { battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)&battery.health); - if (disp_plgn.pm_unlock_internal) { - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, PM_SLEEP_MARGIN); - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); + if (disp_plgn->pm_unlock_internal) { + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, PM_SLEEP_MARGIN); + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); } health_status_broadcast(); if (abnormal_health_popup_timer) { @@ -496,8 +500,8 @@ static void update_health(enum battery_noti_status status) g_source_remove(abnormal_health_popup_timer); abnormal_health_popup_timer = 0; } - if (battery_plgn.remove_health_popup) - battery_plgn.remove_health_popup(); + if (battery_plgn->remove_health_popup) + battery_plgn->remove_health_popup(); } } @@ -511,10 +515,10 @@ void relaunch_health_popup(void) if (abnormal_health_popup_timer) g_source_remove(abnormal_health_popup_timer); - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, LCD_DIM_TIME_IN_BATTERY_HEALTH); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, LCD_DIM_TIME_IN_BATTERY_HEALTH); if (battery.health == HEALTH_LOW) battery_charge_err_low_act(NULL); else if (battery.health == HEALTH_HIGH) @@ -540,11 +544,11 @@ static void check_abnormal_status(void) update_present(DEVICE_NOTI_OFF); if (old_battery.health != HEALTH_OVP && battery.health == HEALTH_OVP) { - if (battery_plgn.update_ovp) - battery_plgn.update_ovp(DEVICE_NOTI_ON); + if (battery_plgn->update_ovp) + battery_plgn->update_ovp(DEVICE_NOTI_ON); } else if (battery.health != HEALTH_OVP && old_battery.health == HEALTH_OVP) { - if (battery_plgn.update_ovp) - battery_plgn.update_ovp(DEVICE_NOTI_OFF); + if (battery_plgn->update_ovp) + battery_plgn->update_ovp(DEVICE_NOTI_OFF); } } @@ -747,8 +751,8 @@ static void process_power_supply(void *data) int ret; _D("process_power_supply()"); - if (disp_plgn.pm_lock_internal) { - lock = disp_plgn.pm_lock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, STAY_CUR_STATE, 0); + if (disp_plgn->pm_lock_internal) { + lock = disp_plgn->pm_lock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, STAY_CUR_STATE, 0); if (old_battery.charge_now != battery.charge_now || battery.charge_now == CHARGER_ABNORMAL) { ret = vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, battery.charge_now); if (ret < 0) @@ -854,8 +858,8 @@ static void process_power_supply(void *data) update_capacity_full(); update_battery_cycle(); if (lock == 0) { - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, PM_SLEEP_MARGIN); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, PM_SLEEP_MARGIN); } } @@ -1514,8 +1518,8 @@ bool battery_do_not_disturb(void) int block = 0, theater = 0, night = 0; int r; - if (battery_plgn.display_changed) { - if (battery_plgn.display_changed(NULL) == S_LCDOFF) { + if (battery_plgn->display_changed) { + if (battery_plgn->display_changed(NULL) == S_LCDOFF) { r = vconf_get_bool(VCONFKEY_SETAPPL_BLOCKMODE_WEARABLE_BOOL, &block); if (r < 0) _E("Failed to set vconf value for blockmode wearable: %d", vconf_get_ext_errno()); @@ -1541,8 +1545,8 @@ int battery_pm_change_internal(int pid, int s_bits) if (battery_do_not_disturb()) return 0; - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(pid, s_bits); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(pid, s_bits); return 0; } @@ -1689,6 +1693,14 @@ static void power_supply_init(void *data) { int ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + + battery_plgn = get_battery_plugin(); + if (!battery_plgn) + _E("Failed to get battery plugin."); + memset(&battery, 0, sizeof(struct battery_status)); memset(&old_battery, 0, sizeof(struct battery_status)); battery.charger_charging = CHARGER_ENABLED; diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index 281e9be..05777e3 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -27,6 +27,7 @@ #include "display-ops.h" #include "core/device-notifier.h" #include "core/devices.h" +#include "shared/plugin.h" #define ON "on" #define OFF "off" @@ -43,6 +44,7 @@ #define TIMEOUT_NONE (-1) #define AMBIENT_CLOCK_WAITING_TIME 5000 /* ms */ +static struct display_plugin *disp_plgn; static int ambient_state; static int ambient_condition; /* Setting Value */ static pid_t ambient_pid; /* Ambient Clock pid */ @@ -85,8 +87,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) - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } ambient_condition = val; @@ -114,8 +116,8 @@ int ambient_set_state(int on) * So at that time deviced should turn off display to match the pair. */ if (on) { - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_AMBIENT, + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, STAY_CUR_STATE, AMBIENT_CLOCK_WAITING_TIME); } else ambient_pid = 0; @@ -165,8 +167,8 @@ static void ambient_start_clock(void) (ambient_state == false)) return; - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, STAY_CUR_STATE, + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, STAY_CUR_STATE, AMBIENT_CLOCK_WAITING_TIME); } @@ -182,8 +184,8 @@ static void ambient_end_clock(pid_t pid) backlight_ops.off(NORMAL_MODE); broadcast_lcd_off_late(LCD_OFF_LATE_MODE); - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); } update_count++; @@ -242,8 +244,8 @@ static void ambient_lcdoff_signal_handler(GDBusConnection *conn, return; } - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, GOTO_STATE_NOW, 0); + 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."); @@ -251,14 +253,18 @@ static void ambient_lcdoff_signal_handler(GDBusConnection *conn, lcd_direct_control(DPMS_OFF, NORMAL_MODE); broadcast_lcd_off_late(LCD_OFF_LATE_MODE); - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); } static void ambient_init(void *data) { int ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + ret = vconf_get_bool("db/starter/always_on_display", &ambient_condition); if (ret < 0) { _E("Failed to get initial AOD condition. AOD is not going to work."); diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index b0f7bdf..e66c78e 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -42,6 +42,7 @@ #include "display-actor.h" #include "display-ops.h" #include "display.h" +#include "shared/plugin.h" #define AUL_APPSTATUS_PATH "/Org/Tizen/Aul/AppStatus" #define AUL_APPSTATUS_INTERFACE "org.tizen.aul.AppStatus" @@ -67,6 +68,8 @@ #define EXPIRED_POPUP_COMM "_APP_COMM_" #define EXPIRED_POPUP_ID "_REQUEST_ID_" +static struct display_plugin *disp_plgn; + static GVariant *dbus_start(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) @@ -94,8 +97,8 @@ static GVariant *dbus_stop(GDBusConnection *conn, if (NOT_SUPPORT_OPS(display_device_ops)) goto out; - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); display_device_ops->stop(CORE_LOGIC_MODE); out: @@ -181,8 +184,8 @@ static GVariant *dbus_lockstate(GDBusConnection *conn, flag |= STAY_CUR_STATE; } - if (disp_plgn.pm_lock_internal) - ret = disp_plgn.pm_lock_internal(pid, state, flag, timeout); + if (disp_plgn->pm_lock_internal) + ret = disp_plgn->pm_lock_internal(pid, state, flag, timeout); out: g_free(state_str); g_free(option1_str); @@ -242,8 +245,8 @@ static GVariant *dbus_unlockstate(GDBusConnection *conn, flag = PM_RESET_TIMER; } - if (disp_plgn.pm_unlock_internal) - ret = disp_plgn.pm_unlock_internal(pid, state, flag); + if (disp_plgn->pm_unlock_internal) + ret = disp_plgn->pm_unlock_internal(pid, state, flag); out: g_free(state_str); g_free(option_str); @@ -330,8 +333,8 @@ static GVariant *dbus_changestate(GDBusConnection *conn, goto out; } - if (disp_plgn.pm_change_internal) - ret = disp_plgn.pm_change_internal(pid, state); + if (disp_plgn->pm_change_internal) + ret = disp_plgn->pm_change_internal(pid, state); if (!ret && state == LCD_OFF) update_lcdoff_source(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); @@ -446,8 +449,8 @@ static GVariant *dbus_setbrightness(GDBusConnection *conn, clear_pm_status_flag(DIM_MASK); if (state == DISPLAY_STATE_NORMAL) { - if (disp_plgn.auto_brightness_control) { - ret = disp_plgn.auto_brightness_control(BR_SET_BRIGHTNESS, brt); + if (disp_plgn->auto_brightness_control) { + ret = disp_plgn->auto_brightness_control(BR_SET_BRIGHTNESS, brt); } else { backlight_ops.set_default_brt(brt); ret = backlight_ops.set_brightness(brt); @@ -508,8 +511,8 @@ static GVariant *dbus_holdbrightness(GDBusConnection *conn, if (ret < 0) _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - if (disp_plgn.auto_brightness_control) - ret = disp_plgn.auto_brightness_control(BR_HOLD_BRIGHTNESS, brt); + if (disp_plgn->auto_brightness_control) + ret = disp_plgn->auto_brightness_control(BR_HOLD_BRIGHTNESS, brt); else ret = backlight_ops.set_brightness(brt); @@ -579,7 +582,7 @@ static GVariant *dbus_releasebrightness(GDBusConnection *conn, brt = ret; // check dim state - if (!disp_plgn.auto_brightness_control && low_battery_state(bat) && + if (!disp_plgn->auto_brightness_control && low_battery_state(bat) && charger == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !changed) { _D("batt warning low : brightness is not changed!"); if (brt != 0) @@ -588,8 +591,8 @@ static GVariant *dbus_releasebrightness(GDBusConnection *conn, } if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_OFF) { - if (disp_plgn.auto_brightness_control) { - disp_plgn.auto_brightness_control(BR_RELEASE_BRIGHTNESS, BR_IMPLICIT); + if (disp_plgn->auto_brightness_control) { + disp_plgn->auto_brightness_control(BR_RELEASE_BRIGHTNESS, BR_IMPLICIT); } else { if (brt != setting) backlight_ops.set_brightness(setting); @@ -722,11 +725,11 @@ static GVariant *dbus_lockscreenbgon(GDBusConnection *conn, g_variant_get(param, "(s)", &on); if (!strcmp(on, "true")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, true); + if (disp_plgn->update_pm_setting) + disp_plgn->update_pm_setting(SETTING_LOCK_SCREEN_BG, true); } else if (!strcmp(on, "false")) { - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_LOCK_SCREEN_BG, false); + if (disp_plgn->update_pm_setting) + disp_plgn->update_pm_setting(SETTING_LOCK_SCREEN_BG, false); } else ret = -EINVAL; @@ -745,13 +748,13 @@ static GVariant *dbus_dumpmode(GDBusConnection *conn, if (!strcmp(on, "on")) { pm_save_logdump(); - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, STAY_CUR_STATE, DUMP_MODE_WATING_TIME); backlight_ops.release_blink(); } else if (!strcmp(on, "off")) { - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, PM_SLEEP_MARGIN); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, PM_SLEEP_MARGIN); backlight_ops.blink(0); } else if (!strcmp(on, "blink")) { backlight_ops.blink(500); @@ -1275,6 +1278,12 @@ int init_pm_dbus(void) { int ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + return -1; + } + display_add_actor(&display_api_actor); display_add_actor(&display_gesture_actor); diff --git a/src/display/display-ops.h b/src/display/display-ops.h index 2842837..0c014a8 100644 --- a/src/display/display-ops.h +++ b/src/display/display-ops.h @@ -71,5 +71,4 @@ struct display_plugin { int (*auto_brightness_control) (enum brightness_request_e request, int set_brightness); }; -extern struct display_plugin disp_plgn; #endif diff --git a/src/display/display-signal.c b/src/display/display-signal.c index e6f57e9..0abfb04 100644 --- a/src/display/display-signal.c +++ b/src/display/display-signal.c @@ -32,6 +32,7 @@ static const char *lcdoff_sig_lookup[SIGNAL_MAX] = { [SIGNAL_POST] = "LCDOffCompleted", }; +static struct display_plugin *disp_plgn; static int pmstate_suspend = PM_SUSPEND; static long displayoff_time; @@ -93,12 +94,12 @@ void broadcast_lcd_on(enum signal_type type, enum device_flags flags) if (type == SIGNAL_PRE && displayoff_time != 0) diff = clock_gettime_to_long() - displayoff_time; - if (!disp_plgn.device_flags_to_string) { + if (!disp_plgn->device_flags_to_string) { _E("Cannot convert device_flags to string."); return; } - str = disp_plgn.device_flags_to_string(flags); + str = disp_plgn->device_flags_to_string(flags); signal = lcdon_sig_lookup[type]; _I("lcdstep : Broadcast signal(%s:%s).", signal, str); @@ -127,12 +128,12 @@ void broadcast_lcd_off(enum signal_type type, enum device_flags flags) signal = lcdoff_sig_lookup[type]; - if (!disp_plgn.device_flags_to_string) { + if (!disp_plgn->device_flags_to_string) { _E("Cannot convert device_flags to string."); return; } - str = disp_plgn.device_flags_to_string(flags); + str = disp_plgn->device_flags_to_string(flags); _I("lcdstep : Broadcast signal(%s).", signal); ret = dbus_handle_emit_dbus_signal_sync(NULL, @@ -172,3 +173,8 @@ void set_process_active(bool flag, pid_t pid) if (ret < 0) _E("Failed to send dbus signal to resourced."); } + +void set_display_signal_display_plugin(struct display_plugin *dp) +{ + disp_plgn = dp; +} diff --git a/src/display/display-signal.h b/src/display/display-signal.h index 9001c11..35c367d 100644 --- a/src/display/display-signal.h +++ b/src/display/display-signal.h @@ -16,10 +16,14 @@ * limitations under the License. */ +#ifndef __DISPLAY_SIGNAL_H__ +#define __DISPLAY_SIGNAL_H__ + #include #include #include "util.h" +#include "display-ops.h" #include "core/devices.h" #include "core/device-notifier.h" @@ -54,3 +58,6 @@ void broadcast_lcd_on(enum signal_type type, enum device_flags flags); void broadcast_lcd_off(enum signal_type type, enum device_flags flags); void broadcast_lcd_off_late(enum device_flags flags); void set_process_active(bool flag, pid_t pid); +void set_display_signal_display_plugin(struct display_plugin *dp); + +#endif /* __DISPLAY_SIGNAL_H__ */ diff --git a/src/display/display.h b/src/display/display.h index fe1fe07..4acb2ea 100644 --- a/src/display/display.h +++ b/src/display/display.h @@ -21,7 +21,6 @@ #define __DISPLAY_H__ #include "device-interface.h" -#include "core/common.h" void lcd_direct_control(enum dpms_state state, int flags); int get_pm_cur_state(void); diff --git a/src/display/poll.c b/src/display/poll.c index 19451dd..548f186 100644 --- a/src/display/poll.c +++ b/src/display/poll.c @@ -28,6 +28,7 @@ #include "core.h" #include "poll.h" #include "display/display-ops.h" +#include "shared/plugin.h" #define SHIFT_UNLOCK 4 #define SHIFT_UNLOCK_PARAMETER 12 @@ -37,6 +38,7 @@ #define __HOLDKEY_BLOCK_BIT 0x1 #define HOLDKEY_BLOCK_BIT (__HOLDKEY_BLOCK_BIT << LOCK_FLAG_SHIFT) +static struct display_plugin *disp_plgn; static PMMsg recv_data; int check_dimstay(int next_state, int flag) @@ -175,7 +177,13 @@ static int __pm_change_internal(pid_t pid, int s_bits) void init_pm_internal() { - disp_plgn.pm_lock_internal = __pm_lock_internal; - disp_plgn.pm_unlock_internal = __pm_unlock_internal; - disp_plgn.pm_change_internal = __pm_change_internal; + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + return ; + } + + disp_plgn->pm_lock_internal = __pm_lock_internal; + disp_plgn->pm_unlock_internal = __pm_unlock_internal; + disp_plgn->pm_change_internal = __pm_change_internal; } diff --git a/src/display/setting.c b/src/display/setting.c index 2cfff83..30065cc 100644 --- a/src/display/setting.c +++ b/src/display/setting.c @@ -28,6 +28,7 @@ #include "setting.h" #include "display-ops.h" #include "shared/eventsystem.h" +#include "shared/plugin.h" #define LCD_DIM_RATIO 0.3 #define LCD_MAX_DIM_TIMEOUT 7000 @@ -40,6 +41,7 @@ static const char *setting_keys[SETTING_GET_END] = { [SETTING_POWER_CUSTOM_BRIGHTNESS] = VCONFKEY_PM_CUSTOM_BRIGHTNESS_STATUS, }; +static struct display_plugin *disp_plgn; static int lock_screen_state = VCONFKEY_IDLE_UNLOCK; static bool lock_screen_bg_state = false; static int force_lcdtimeout = 0; @@ -236,8 +238,8 @@ static int setting_cb(keynode_t *key_nodes, void *data) vconf_keynode_get_name(tmp), index); return -1; } - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(index, vconf_keynode_get_int(tmp)); + if (disp_plgn->update_pm_setting) + disp_plgn->update_pm_setting(index, vconf_keynode_get_int(tmp)); return 0; } @@ -246,8 +248,14 @@ int init_setting(int (*func) (int key_idx, int val)) { int i; + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + return -1; + } + if (func != NULL) - disp_plgn.update_pm_setting = func; + disp_plgn->update_pm_setting = func; for (i = SETTING_BEGIN; i < SETTING_GET_END; i++) { /* @@ -259,7 +267,7 @@ int init_setting(int (*func) (int key_idx, int val)) (void *)((intptr_t)i)); } - disp_plgn.get_lock_screen_state = __get_lock_screen_state; + disp_plgn->get_lock_screen_state = __get_lock_screen_state; return 0; } diff --git a/src/extcon/cradle.c b/src/extcon/cradle.c index 06c9152..9bc51d7 100644 --- a/src/extcon/cradle.c +++ b/src/extcon/cradle.c @@ -27,10 +27,12 @@ #include "display/core.h" #include "display/display-ops.h" #include "extcon/extcon.h" +#include "shared/plugin.h" #define METHOD_GET_CRADLE "GetCradle" #define SIGNAL_CRADLE_STATE "ChangedCradle" +static struct display_plugin *disp_plgn; static struct extcon_ops cradle_extcon_ops; static void cradle_send_broadcast(int status) @@ -58,8 +60,8 @@ static int cradle_update(int status) int ret; _I("Cradle changed. status=%d", status); - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_CRADLE, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_CRADLE, LCD_NORMAL); cradle_send_broadcast(status); ret = vconf_set_int(VCONFKEY_SYSMAN_CRADLE_STATUS, status); if (ret < 0) { @@ -68,11 +70,11 @@ static int cradle_update(int status) } if (status == DOCK_SOUND) { - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_CRADLE, LCD_DIM, STAY_CUR_STATE, 0); + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_CRADLE, LCD_DIM, STAY_CUR_STATE, 0); } else if (status == DOCK_NONE) { - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_CRADLE, LCD_DIM, PM_SLEEP_MARGIN); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_CRADLE, LCD_DIM, PM_SLEEP_MARGIN); } return 0; @@ -92,8 +94,8 @@ static int display_changed(void *data) cradle = cradle_extcon_ops.status; if (cradle == DOCK_SOUND) { - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_CRADLE, LCD_DIM, STAY_CUR_STATE, 0); + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_CRADLE, LCD_DIM, STAY_CUR_STATE, 0); _I("Sound dock is connected. Dim lock is on."); } @@ -123,6 +125,10 @@ static void cradle_init(void *data) { int ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + register_notifier(DEVICE_NOTIFIER_LCD, display_changed); ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_SYSNOTI, &dbus_interface); diff --git a/src/extcon/earjack.c b/src/extcon/earjack.c index e639b9a..fe8e5f9 100644 --- a/src/extcon/earjack.c +++ b/src/extcon/earjack.c @@ -26,10 +26,12 @@ #include "display/poll.h" #include "display/display-ops.h" #include "extcon/extcon.h" +#include "shared/plugin.h" #define SIGNAL_EARJACK_STATE "ChangedEarjack" #define GET_EARJACK_STATE "Earjack" +static struct display_plugin *disp_plgn; static void earjack_send_broadcast(int status) { static int old = 0; @@ -77,8 +79,8 @@ static int earjack_update(int status) earjack_send_broadcast(status); earjack_send_system_event(status); if (status != EARJACK_DICONNECTED) { - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_EARJACK, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_EARJACK, LCD_NORMAL); extcon_update_count(EXTCON_EARJACK, 1); } @@ -86,8 +88,16 @@ static int earjack_update(int status) return 0; } +static void earjack_init(void *data) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); +} + static struct extcon_ops earjack_extcon_ops = { .name = EXTCON_CABLE_HEADPHONE_OUT, + .init = earjack_init, .update = earjack_update, }; diff --git a/src/extcon/hdmi.c b/src/extcon/hdmi.c index 08c89e9..a94e200 100644 --- a/src/extcon/hdmi.c +++ b/src/extcon/hdmi.c @@ -24,10 +24,12 @@ #include "display/core.h" #include "display/display-ops.h" #include "extcon.h" +#include "shared/plugin.h" #define METHOD_GET_HDMI "GetHDMI" #define SIGNAL_HDMI_STATE "ChangedHDMI" +static struct display_plugin *disp_plgn; static struct extcon_ops hdmi_extcon_ops; static void hdmi_send_broadcast(int status) @@ -55,8 +57,8 @@ static int hdmi_update(int status) int ret; _I("Hdmi changed. status=%d", status); - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_HDMI, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_HDMI, LCD_NORMAL); ret = vconf_set_int(VCONFKEY_SYSMAN_HDMI, status); if (ret < 0) _E("Failed to set vconf value for hdmi: %d", vconf_get_ext_errno()); @@ -64,11 +66,11 @@ static int hdmi_update(int status) hdmi_send_broadcast(status); if (status == HDMI_CONNECTED) { - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_HDMI, LCD_DIM, STAY_CUR_STATE, 0); + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_HDMI, LCD_DIM, STAY_CUR_STATE, 0); } else { - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_HDMI, LCD_DIM, PM_SLEEP_MARGIN); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_HDMI, LCD_DIM, PM_SLEEP_MARGIN); } return 0; @@ -88,8 +90,8 @@ static int display_changed(void *data) hdmi = hdmi_extcon_ops.status; if (hdmi == 0) { - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_HDMI, LCD_DIM, STAY_CUR_STATE, 0); + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_HDMI, LCD_DIM, STAY_CUR_STATE, 0); _I("Hdmi is connected. Dim lock is on."); } return 0; @@ -118,6 +120,10 @@ static void hdmi_init(void *data) { int ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + register_notifier(DEVICE_NOTIFIER_LCD, display_changed); ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_SYSNOTI, &dbus_interface); diff --git a/src/led/touch-key.c b/src/led/touch-key.c index b1dc8f2..402b8ac 100644 --- a/src/led/touch-key.c +++ b/src/led/touch-key.c @@ -29,6 +29,7 @@ #include "display/setting.h" #include "display/display-ops.h" #include "touch-key.h" +#include "shared/plugin.h" #define KEYBACKLIGHT_TIME_90 90 /* 1.5 second */ #define KEYBACKLIGHT_TIME_360 360 /* 6 second */ @@ -44,6 +45,7 @@ #define GET_BRIGHTNESS(val) (((val) >> 24) & 0xFF) #define SET_BRIGHTNESS(val) (((val) & 0xFF) << 24) +static struct display_plugin *disp_plgn; static struct led_device *touchled_dev; static guint hardkey_timeout_id; static int hardkey_duration; @@ -139,7 +141,7 @@ static void process_touchkey_enable(bool enable) touchled_set_state(true); /* do not create turnoff timer in case of idle lock state */ - if (disp_plgn.get_lock_screen_state && disp_plgn.get_lock_screen_state() == VCONFKEY_IDLE_LOCK) + if (disp_plgn->get_lock_screen_state && disp_plgn->get_lock_screen_state() == VCONFKEY_IDLE_LOCK) return; /* start timer */ @@ -266,6 +268,10 @@ static void touchled_init(void *data) { int ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + /* get touchkey light duration setting */ ret = vconf_get_int(VCONFKEY_SETAPPL_TOUCHKEY_LIGHT_DURATION, &hardkey_duration); if (ret < 0) { diff --git a/src/power/boot.c b/src/power/boot.c index 6595810..feadbd8 100644 --- a/src/power/boot.c +++ b/src/power/boot.c @@ -29,11 +29,13 @@ #include "core/common.h" #include "display/poll.h" #include "display/display-ops.h" +#include "shared/plugin.h" #include "doze.h" #define SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED "StartupFinished" #define SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED "UserSessionStartupFinished" +static struct display_plugin *disp_plgn; static guint sig_id[2] = {0, 0}; void remove_booting_done_handler(void *data) @@ -77,9 +79,16 @@ static void booting_done_received(GDBusConnection *conn, remove_booting_done_handler(NULL); - _I("Real booting done. Unlock LCD_OFF."); - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); + if (!disp_plgn) + disp_plgn = get_display_plugin(); + + if (!disp_plgn) + _E("Failed to get display plugin."); + else { + _I("Real booting done. Unlock LCD_OFF."); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); + } _I("Signal booting done."); diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 4867525..ac14773 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -52,6 +52,7 @@ #include "power-handler.h" #include "apps/apps.h" #include "boot.h" +#include "shared/plugin.h" #define POWEROFF_DURATION 4 #define POWEROFF_WAIT_RESOURCED (0.5*1000) /* 0.5 seconds */ @@ -60,6 +61,8 @@ #define SIGNAL_POWEROFF_STATE "ChangeState" #define POWER_CONF_FILE "/etc/deviced/power.conf" +static struct display_plugin *disp_plgn; + static struct timeval tv_start_poweroff; static dd_list *poweroff_options; static struct power_option poweroff_opt; @@ -133,8 +136,8 @@ static void disable_display(void) { const struct device_ops *display_device_ops = NULL; FIND_DEVICE_VOID(display_device_ops, "display"); - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_POWEROFF, LCD_OFF); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POWEROFF, LCD_OFF); display_device_ops->exit(NULL); } @@ -337,14 +340,14 @@ static gboolean poweroff_wait_timeout_cb(void *data) make_power_flag(poweroff_opt.type, poweroff_opt.option); - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_POWEROFF, LCD_OFF, STAY_CUR_STATE, 0); + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_POWEROFF, LCD_OFF, STAY_CUR_STATE, 0); poweroff_prepare(); poweroff_request_shutdown(); - if (disp_plgn.update_pm_setting) - disp_plgn.update_pm_setting(SETTING_POWEROFF, poweroff_opt.type); + if (disp_plgn->update_pm_setting) + disp_plgn->update_pm_setting(SETTING_POWEROFF, poweroff_opt.type); } else { _D("Poweroff wait timer for pid %d is expired, but keep waiting for others...", pid); } @@ -751,6 +754,10 @@ static void power_init(void *data) { int ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + /* init dbus interface */ ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_POWEROFF, &dbus_interface); if (ret < 0) diff --git a/src/shared/plugin.c b/src/shared/plugin.c index d90315f..d93087c 100644 --- a/src/shared/plugin.c +++ b/src/shared/plugin.c @@ -30,8 +30,7 @@ #include #include -#include "battery/battery-ops.h" -#include "display/display-ops.h" +#include "plugin.h" #include "common.h" #include "core/log.h" @@ -40,10 +39,20 @@ #endif #define MODULE_PATH LIBPATH"/deviced/" -struct display_plugin disp_plgn; -struct battery_plugin battery_plgn; +static struct display_plugin disp_plgn; +static struct battery_plugin battery_plgn; static GList *plgn_list; +inline struct display_plugin *get_display_plugin(void) +{ + return &disp_plgn; +} + +inline struct battery_plugin *get_battery_plugin(void) +{ + return &battery_plgn; +} + int load_plugin(const char *id, void **h) { char path[PATH_MAX]; diff --git a/src/shared/plugin.h b/src/shared/plugin.h index 488589c..6eeb9d7 100644 --- a/src/shared/plugin.h +++ b/src/shared/plugin.h @@ -19,6 +19,12 @@ #ifndef __DD_PLUGIN_H__ #define __DD_PLUGIN_H__ +#include "display/display-ops.h" +#include "battery/battery-ops.h" + +struct display_plugin *get_display_plugin(void); +struct battery_plugin *get_battery_plugin(void); + int load_plugin(const char *id, void **h); int unload_plugin(void *h); void load_plugins(); diff --git a/src/time/time-handler.c b/src/time/time-handler.c index 5dc56c8..c53a801 100644 --- a/src/time/time-handler.c +++ b/src/time/time-handler.c @@ -40,6 +40,7 @@ #include "display/display-ops.h" #include "core/common.h" #include "core/device-notifier.h" +#include "shared/plugin.h" #define PREDEF_SET_DATETIME "set_datetime" #define PREDEF_SET_TIMEZONE "set_timezone" @@ -65,6 +66,7 @@ #define TIME_CHANGE_SIGNAL "STimeChanged" +static struct display_plugin *disp_plgn; static const time_t default_time = 2147483645; /* max(32bit) -3sec */ static guint tfdh; /* tfd change noti */ static int tfd = -1; @@ -189,13 +191,13 @@ int set_datetime_action(int argc, char **argv) else pm_state = 0x4; - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE, 0); + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE, 0); ret = handle_date(argv[0]); - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE); return ret; } @@ -218,13 +220,13 @@ int set_timezone_action(int argc, char **argv) else pm_state = 0x4; - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE, 0); + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE, 0); ret = handle_timezone(argv[0]); - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE); return ret; } @@ -389,6 +391,10 @@ static void time_init(void *data) { int ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_SYSNOTI, &dbus_interface); if (ret < 0) _E("Failed to init dbus method: %d", ret); @@ -397,7 +403,7 @@ static void time_init(void *data) _E("Failed system time change detector init."); register_notifier(DEVICE_NOTIFIER_LCD, time_lcd_changed_cb); - get_cond_head = dlsym(disp_plgn.handle, "get_cond_head"); + get_cond_head = dlsym(disp_plgn->handle, "get_cond_head"); if (!get_cond_head) _E("Failed to load symbol get_cond_head(), %s.", dlerror()); } diff --git a/src/touchscreen/touchscreen.c b/src/touchscreen/touchscreen.c index 9bbd93b..65269b1 100644 --- a/src/touchscreen/touchscreen.c +++ b/src/touchscreen/touchscreen.c @@ -30,12 +30,14 @@ #include "display/core.h" #include "display/display-ops.h" #include "power/boot.h" +#include "shared/plugin.h" enum ps_mode { POWERSAVING_OFF, POWERSAVING_ON, }; +static struct display_plugin *disp_plgn; static struct touchscreen_device *touchscreen_dev; static int touchscreen_enable = DEVICE_OPS_STATUS_START; static int powersaving_support = true; @@ -312,11 +314,17 @@ static void touchscreen_init(void *data) { int ret, val; - _display_conf = dlsym(disp_plgn.handle, "display_conf"); - if (!_display_conf) - _E("Failed to obtain address of display_conf."); + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + return ; + } + + _display_conf = dlsym(disp_plgn->handle, "display_conf"); + if (!_display_conf) + _E("Failed to obtain address of display_conf, %s.", dlerror()); - _backlight_ops = dlsym(disp_plgn.handle, "backlight_ops"); + _backlight_ops = dlsym(disp_plgn->handle, "backlight_ops"); if (!_backlight_ops) _E("Failed to obtain address of backlight_ops."); diff --git a/src/usb/usb.c b/src/usb/usb.c index 8bff078..b82534d 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -26,6 +26,7 @@ #include "core/udev.h" #include "display/poll.h" #include "display/display-ops.h" +#include "shared/plugin.h" #include "usb.h" #include "usb-debug.h" @@ -33,6 +34,7 @@ static int usb_change_gadget(unsigned mode); +static struct display_plugin *disp_plgn; static struct usb_client *usb_client; static struct usb_gadget_translator *gadget_translator; @@ -285,8 +287,8 @@ static int usb_connected(void) int ret; unsigned int mode = usb_state_get_selected_mode(); - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_USB, LCD_OFF, STAY_CUR_STATE, 0); + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_USB, LCD_OFF, STAY_CUR_STATE, 0); usb_state_set_connection(USB_CONNECTED); send_usb_state_changed_event(VCONFKEY_SYSMAN_USB_CONNECTED); @@ -311,11 +313,11 @@ static int usb_disconnected(void) ret = usb_disable(); if(ret < 0) { _E("Failed to disable USB gadget: %d", ret); - /* Important: You have to keep going to unlock disp_plgn.pm_unlock_internal */ + /* Important: You have to keep going to unlock disp_plgn->pm_unlock_internal */ } - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_USB, LCD_OFF, STAY_CUR_STATE); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_USB, LCD_OFF, STAY_CUR_STATE); return ret; } @@ -448,6 +450,10 @@ static void usb_init(void *data) { int ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + usb_state_retrieve_selected_mode(); ret = usb_probe(); diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 48cabf0..c4cd801 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -34,6 +34,7 @@ #include "extcon/extcon.h" #include "display/display-ops.h" #include "dd-usbhost.h" +#include "shared/plugin.h" #define USB_INTERFACE_CLASS "bInterfaceClass" #define USB_INTERFACE_SUBCLASS "bInterfaceSubClass" @@ -52,6 +53,7 @@ #define ROOTPATH tzplatform_getenv(TZ_SYS_VAR) #define POLICY_FILENAME "usbhost-policy" +static struct display_plugin *disp_plgn; static char *POLICY_FILEPATH; /** @@ -239,8 +241,8 @@ static int add_usbhost_list(struct udev_device *dev, const char *devpath) broadcast_usbhost_signal(USB_HOST_ADDED, usbhost); - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_USB_HOST, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_USB_HOST, LCD_NORMAL); /* for debugging */ _I("USB HOST Added."); @@ -268,8 +270,8 @@ static int remove_usbhost_list(const char *devpath) broadcast_usbhost_signal(USB_HOST_REMOVED, usbhost); - if (disp_plgn.pm_change_internal) - disp_plgn.pm_change_internal(INTERNAL_LOCK_USB_HOST, LCD_NORMAL); + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_USB_HOST, LCD_NORMAL); /* for debugging */ _I("USB HOST Removed."); @@ -1130,6 +1132,10 @@ static void usbhost_init(void *data) { int ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin."); + /* register usbhost uevent */ ret = register_kernel_uevent_control(&uh); if (ret < 0) @@ -1190,12 +1196,12 @@ static int extcon_usbhost_state_changed(int status) { if (status == USBHOST_DISCONNECTED) { _I("USB host connector disconnected."); - if (disp_plgn.pm_unlock_internal) - disp_plgn.pm_unlock_internal(INTERNAL_LOCK_USB_HOST, LCD_OFF, STAY_CUR_STATE); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_USB_HOST, LCD_OFF, STAY_CUR_STATE); } else { _I("USB host connector connected."); - if (disp_plgn.pm_lock_internal) - disp_plgn.pm_lock_internal(INTERNAL_LOCK_USB_HOST, LCD_OFF, STAY_CUR_STATE, 0); + if (disp_plgn->pm_lock_internal) + disp_plgn->pm_lock_internal(INTERNAL_LOCK_USB_HOST, LCD_OFF, STAY_CUR_STATE, 0); } return 0; } -- 2.7.4 From 68452174d89c4c581e842e0b2a1e02f1256f9507 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 7 Aug 2020 18:18:51 +0900 Subject: [PATCH 03/16] Change power related global variables and functions to static Change-Id: I7a1f14ac7d7ebab5a2cefab8b070b246e62dd866 Signed-off-by: lokilee73 --- plugins/iot/display/core.c | 34 ++--- plugins/iot/display/device-interface.c | 204 +------------------------ plugins/iot/display/key-filter.c | 1 + plugins/mobile/display/core.c | 34 ++--- plugins/mobile/display/device-interface.c | 206 +------------------------ plugins/mobile/display/key-filter.c | 1 + plugins/tv/display/core.c | 34 ++--- plugins/tv/display/device-interface.c | 203 +----------------------- plugins/tv/display/key-filter.c | 1 + plugins/tv/display/state-tv.c | 3 +- plugins/wearable/display/core.c | 34 ++--- plugins/wearable/display/device-interface.c | 205 +------------------------ plugins/wearable/display/key-filter.c | 1 + src/display/device-interface.h | 30 ---- src/power/power-control.c | 229 ++++++++++++++++++++++++++++ src/power/power-control.h | 59 +++++++ 16 files changed, 366 insertions(+), 913 deletions(-) mode change 100755 => 100644 plugins/wearable/display/device-interface.c create mode 100755 src/power/power-control.c create mode 100644 src/power/power-control.h diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 1813c8f..2696eaf 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -56,6 +56,7 @@ #include "extcon/extcon.h" #include "battery/power-supply.h" #include "power/power-handler.h" +#include "power/power-control.h" #include "power/boot.h" #include "power/doze.h" #include "dd-display.h" @@ -700,10 +701,10 @@ void set_dim_state(bool on) void lcd_on_direct(enum device_flags flags) { - if (power_ops.get_power_lock_support() + if (pm_get_power_lock_support() && (get_pm_cur_state() == S_SLEEP)) { broadcast_pm_wakeup(); - power_ops.power_lock(); + pm_power_lock(); set_pm_cur_state(S_NORMAL); } @@ -992,7 +993,7 @@ static void proc_condition_lock(PMMsg *data) get_pname(pid, pname); if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) && - (power_ops.get_power_lock() == POWER_UNLOCK)) + (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); if (data->timeout > 0) { @@ -1515,9 +1516,9 @@ static int default_action(int timeout) } if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { - if (power_ops.get_power_lock_support()) { + if (pm_get_power_lock_support()) { broadcast_pm_wakeup(); - power_ops.power_lock(); + pm_power_lock(); } set_setting_pmstate(get_pm_cur_state()); pm_cur_state = get_pm_cur_state(); @@ -1577,9 +1578,9 @@ static int default_action(int timeout) if (backlight_ops.get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - if (!power_ops.get_power_lock_support()) { + if (!pm_get_power_lock_support()) { /* sleep state : set system mode to SUSPEND */ - if (power_ops.get_wakeup_count(&wakeup_count) < 0) + if (get_wakeup_count(&wakeup_count) < 0) _E("Wakeup count read error."); if (wakeup_count < 0) { @@ -1587,7 +1588,7 @@ static int default_action(int timeout) goto go_lcd_off; } - if (power_ops.set_wakeup_count(wakeup_count) < 0) { + if (set_wakeup_count(wakeup_count) < 0) { _E("Wakeup count write error."); goto go_lcd_off; } @@ -1602,18 +1603,17 @@ go_suspend: pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); #endif broadcast_pm_suspend(); - if (power_ops.get_power_lock_support()) { - if (power_ops.enable_autosleep) - power_ops.enable_autosleep(); + if (pm_get_power_lock_support()) { + pm_enable_autosleep(); - if (power_ops.power_unlock() < 0) + if (pm_power_unlock() < 0) _E("Power unlock state error."); } else { - power_ops.suspend(); + pm_suspend(); _I("system wakeup!!"); system_wakeup_flag = true; /* Resume !! */ - if (power_ops.check_wakeup_src() == EVENT_DEVICE) + if (check_wakeup_src() == EVENT_DEVICE) /* system waked up by devices */ states[get_pm_cur_state()].trans(EVENT_DEVICE); else @@ -1623,7 +1623,7 @@ go_suspend: return 0; go_lcd_off: - if (!power_ops.get_power_lock_support()) { + if (!pm_get_power_lock_support()) { /* Resume !! */ states[get_pm_cur_state()].trans(EVENT_DEVICE); } @@ -2357,9 +2357,9 @@ static void display_init(void *data) if (flags & WITHOUT_STARTNOTI) { /* start without noti */ _I("Start Power managing without noti"); - if (power_ops.get_power_lock_support()) { + if (pm_get_power_lock_support()) { broadcast_pm_wakeup(); - power_ops.power_lock(); + pm_power_lock(); } /* * Lock lcd off until booting is done. diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index 03abf73..db92d76 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -32,6 +32,7 @@ #include #include "ambient-mode.h" +#include "power/power-control.h" #include "core/log.h" #include "core/devices.h" #include "core/common.h" @@ -44,8 +45,6 @@ #include "display/display-dpms.h" #include "display/display.h" -#define SET_SUSPEND_TIME 0.5 - #define TOUCH_ON 1 #define TOUCH_OFF 0 @@ -55,12 +54,6 @@ #define LCD_PHASED_DELAY 10000 /* microsecond */ #define DUMP_MODE_WAITING_TIME 600000 /* milisecond */ -#define POWER_AUTOSLEEP_PATH "/sys/power/autosleep" -#define POWER_LOCK_PATH "/sys/power/wake_lock" -#define POWER_UNLOCK_PATH "/sys/power/wake_unlock" -#define POWER_WAKEUP_PATH "/sys/power/wakeup_count" -#define POWER_STATE_PATH "/sys/power/state" - #define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" #define GESTURE_STR "gesture" @@ -75,16 +68,11 @@ #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; @@ -130,133 +118,6 @@ static int bl_brt(int brightness, int delay) return ret; } -static int system_suspend(void) -{ - int ret; - - _I("system suspend"); - ret = sys_set_str(POWER_STATE_PATH, "mem"); - _I("System resume: %d", ret); - return 0; -} - -static int system_enable_autosleep(void) -{ - _I("System autosleep enabled."); - return sys_set_str(POWER_AUTOSLEEP_PATH, "mem"); -} - -static int vital_mode_support(void) -{ - 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; -} - -static int suspend_other_process(int type) -{ - int ret = 0; - char buf[8]; - const char *command[1]; - - 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_lock(void) -{ - _I("system power lock"); - suspend_other_process(VITAL_WAKEUP); - mainlock_status = POWER_LOCK; - - 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; - - 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; - int ret; - - if (power_lock_support >= 0) - goto out; - - ret = sys_check_node(POWER_LOCK_PATH); - if (ret < 0) - power_lock_support = false; - else - power_lock_support = true; - - _I("System power lock: %s", - (power_lock_support ? "support" : "not support")); - -out: - return power_lock_support; -} - static int get_lcd_power(void) { enum display_state val; @@ -509,41 +370,6 @@ static int get_default_brt(void) return default_brightness; } -static int check_wakeup_src(void) -{ - /* TODO if nedded. - * return wackeup source. user input or device interrupts? (EVENT_DEVICE or EVENT_INPUT) - */ - return EVENT_DEVICE; -} - -static int get_wakeup_count(int *cnt) -{ - int ret; - int wakeup_count; - - if (!cnt) - return -EINVAL; - - ret = sys_get_int(POWER_WAKEUP_PATH, &wakeup_count); - if (ret < 0) - return ret; - - *cnt = wakeup_count; - return 0; -} - -static int set_wakeup_count(int cnt) -{ - int ret; - - ret = sys_set_int(POWER_WAKEUP_PATH, cnt); - if (ret < 0) - return ret; - - return 0; -} - static int get_max_brightness(void) { static int max = -1; @@ -925,16 +751,6 @@ static void _init_ops(void) 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; - power_ops.set_wakeup_count = set_wakeup_count; } int display_service_load(void) @@ -984,24 +800,6 @@ int display_service_free(void) return 0; } -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; -} - /* Dummy. Do not consider detached display state */ int is_lcdon_blocked(void) { diff --git a/plugins/iot/display/key-filter.c b/plugins/iot/display/key-filter.c index d838430..66ab61c 100644 --- a/plugins/iot/display/key-filter.c +++ b/plugins/iot/display/key-filter.c @@ -43,6 +43,7 @@ #include "led/touch-key.h" #include "apps/apps.h" #include "display/display-lock.h" +#include "power/power-control.h" #ifndef KEY_SCREENLOCK #define KEY_SCREENLOCK 0x98 diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 78c8892..ec01102 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -56,6 +56,7 @@ #include "extcon/extcon.h" #include "battery/power-supply.h" #include "power/power-handler.h" +#include "power/power-control.h" #include "power/boot.h" #include "power/doze.h" #include "dd-display.h" @@ -707,10 +708,10 @@ void set_dim_state(bool on) void lcd_on_direct(enum device_flags flags) { - if (power_ops.get_power_lock_support() + if (pm_get_power_lock_support() && (get_pm_cur_state() == S_SLEEP)) { broadcast_pm_wakeup(); - power_ops.power_lock(); + pm_power_lock(); set_pm_cur_state(S_NORMAL); } @@ -1003,7 +1004,7 @@ static void proc_condition_lock(PMMsg *data) get_pname(pid, pname); if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) && - (power_ops.get_power_lock() == POWER_UNLOCK)) + (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); if (data->timeout > 0) { @@ -1525,9 +1526,9 @@ static int default_action(int timeout) } if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { - if (power_ops.get_power_lock_support()) { + if (pm_get_power_lock_support()) { broadcast_pm_wakeup(); - power_ops.power_lock(); + pm_power_lock(); } set_setting_pmstate(get_pm_cur_state()); pm_cur_state = get_pm_cur_state(); @@ -1587,9 +1588,9 @@ static int default_action(int timeout) if (backlight_ops.get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - if (!power_ops.get_power_lock_support()) { + if (!pm_get_power_lock_support()) { /* sleep state : set system mode to SUSPEND */ - if (power_ops.get_wakeup_count(&wakeup_count) < 0) + if (get_wakeup_count(&wakeup_count) < 0) _E("Wakeup count read error."); if (wakeup_count < 0) { @@ -1597,7 +1598,7 @@ static int default_action(int timeout) goto go_lcd_off; } - if (power_ops.set_wakeup_count(wakeup_count) < 0) { + if (set_wakeup_count(wakeup_count) < 0) { _E("Wakeup count write error."); goto go_lcd_off; } @@ -1612,18 +1613,17 @@ go_suspend: pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); #endif broadcast_pm_suspend(); - if (power_ops.get_power_lock_support()) { - if (power_ops.enable_autosleep) - power_ops.enable_autosleep(); + if (pm_get_power_lock_support()) { + pm_enable_autosleep(); - if (power_ops.power_unlock() < 0) + if (pm_power_unlock() < 0) _E("Power unlock state error."); } else { - power_ops.suspend(); + pm_suspend(); _I("system wakeup!!"); system_wakeup_flag = true; /* Resume !! */ - if (power_ops.check_wakeup_src() == EVENT_DEVICE) + if (check_wakeup_src() == EVENT_DEVICE) /* system waked up by devices */ states[get_pm_cur_state()].trans(EVENT_DEVICE); else @@ -1633,7 +1633,7 @@ go_suspend: return 0; go_lcd_off: - if (!power_ops.get_power_lock_support()) { + if (!pm_get_power_lock_support()) { /* Resume !! */ states[get_pm_cur_state()].trans(EVENT_DEVICE); } @@ -2366,9 +2366,9 @@ static void display_init(void *data) if (flags & WITHOUT_STARTNOTI) { /* start without noti */ _I("Start Power managing without noti"); - if (power_ops.get_power_lock_support()) { + if (pm_get_power_lock_support()) { broadcast_pm_wakeup(); - power_ops.power_lock(); + pm_power_lock(); } /* * Lock lcd off until booting is done. diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 2f259d1..8d53e2e 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -44,8 +44,7 @@ #include "display/display-dpms.h" #include "display/display.h" #include "power/boot.h" - -#define SET_SUSPEND_TIME 0.5 +#include "power/power-control.h" #define TOUCH_ON 1 #define TOUCH_OFF 0 @@ -56,12 +55,6 @@ #define LCD_PHASED_DELAY 10000 /* microsecond */ #define DUMP_MODE_WAITING_TIME 600000 /* milisecond */ -#define POWER_AUTOSLEEP_PATH "/sys/power/autosleep" -#define POWER_LOCK_PATH "/sys/power/wake_lock" -#define POWER_UNLOCK_PATH "/sys/power/wake_unlock" -#define POWER_WAKEUP_PATH "/sys/power/wakeup_count" -#define POWER_STATE_PATH "/sys/power/state" - #define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" #define GESTURE_STR "gesture" @@ -73,19 +66,12 @@ #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; @@ -131,133 +117,6 @@ static int bl_brt(int brightness, int delay) return ret; } -static int system_suspend(void) -{ - int ret; - - _I("system suspend"); - ret = sys_set_str(POWER_STATE_PATH, "mem"); - _I("System resume: %d", ret); - return 0; -} - -static int system_enable_autosleep(void) -{ - _I("System autosleep enabled."); - return sys_set_str(POWER_AUTOSLEEP_PATH, "mem"); -} - -static int vital_mode_support(void) -{ - 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; -} - -static int suspend_other_process(int type) -{ - int ret = 0; - char buf[8]; - const char *command[1]; - - 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_lock(void) -{ - _I("system power lock"); - suspend_other_process(VITAL_WAKEUP); - mainlock_status = POWER_LOCK; - - 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; - - 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; - int ret; - - if (power_lock_support >= 0) - goto out; - - ret = sys_check_node(POWER_LOCK_PATH); - if (ret < 0) - power_lock_support = false; - else - power_lock_support = true; - - _I("System power lock: %s", - (power_lock_support ? "support" : "not support")); - -out: - return power_lock_support; -} - static int get_lcd_power(void) { enum display_state val; @@ -510,41 +369,6 @@ static int get_default_brt(void) return default_brightness; } -static int check_wakeup_src(void) -{ - /* TODO if nedded. - * return wackeup source. user input or device interrupts? (EVENT_DEVICE or EVENT_INPUT) - */ - return EVENT_DEVICE; -} - -static int get_wakeup_count(int *cnt) -{ - int ret; - int wakeup_count; - - if (!cnt) - return -EINVAL; - - ret = sys_get_int(POWER_WAKEUP_PATH, &wakeup_count); - if (ret < 0) - return ret; - - *cnt = wakeup_count; - return 0; -} - -static int set_wakeup_count(int cnt) -{ - int ret; - - ret = sys_set_int(POWER_WAKEUP_PATH, cnt); - if (ret < 0) - return ret; - - return 0; -} - static int get_max_brightness(void) { static int max = -1; @@ -926,16 +750,6 @@ static void _init_ops(void) 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; - power_ops.set_wakeup_count = set_wakeup_count; } int display_service_load(void) @@ -985,24 +799,6 @@ int display_service_free(void) return 0; } -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; -} - static int booting_done(void *data) { static int done = false; diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index 25905cb..546d4e1 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -40,6 +40,7 @@ #include "shared/common.h" #include "shared/plugin.h" #include "power/power-handler.h" +#include "power/power-control.h" #include "led/touch-key.h" #include "apps/apps.h" #include "display/display-lock.h" diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 9edae8c..058fa83 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -56,6 +56,7 @@ #include "extcon/extcon.h" #include "battery/power-supply.h" #include "power/power-handler.h" +#include "power/power-control.h" #include "power/boot.h" #include "power/doze.h" #include "dd-display.h" @@ -700,10 +701,10 @@ void set_dim_state(bool on) void lcd_on_direct(enum device_flags flags) { - if (power_ops.get_power_lock_support() + if (pm_get_power_lock_support() && (get_pm_cur_state() == S_SLEEP)) { broadcast_pm_wakeup(); - power_ops.power_lock(); + pm_power_lock(); set_pm_cur_state(S_NORMAL); } @@ -992,7 +993,7 @@ static void proc_condition_lock(PMMsg *data) get_pname(pid, pname); if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) && - (power_ops.get_power_lock() == POWER_UNLOCK)) + (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); if (data->timeout > 0) { @@ -1515,9 +1516,9 @@ static int default_action(int timeout) } if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { - if (power_ops.get_power_lock_support()) { + if (pm_get_power_lock_support()) { broadcast_pm_wakeup(); - power_ops.power_lock(); + pm_power_lock(); } set_setting_pmstate(get_pm_cur_state()); pm_cur_state = get_pm_cur_state(); @@ -1577,9 +1578,9 @@ static int default_action(int timeout) if (backlight_ops.get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - if (!power_ops.get_power_lock_support()) { + if (!pm_get_power_lock_support()) { /* sleep state : set system mode to SUSPEND */ - if (power_ops.get_wakeup_count(&wakeup_count) < 0) + if (get_wakeup_count(&wakeup_count) < 0) _E("Wakeup count read error."); if (wakeup_count < 0) { @@ -1587,7 +1588,7 @@ static int default_action(int timeout) goto go_lcd_off; } - if (power_ops.set_wakeup_count(wakeup_count) < 0) { + if (set_wakeup_count(wakeup_count) < 0) { _E("Wakeup count write error."); goto go_lcd_off; } @@ -1602,18 +1603,17 @@ go_suspend: pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); #endif broadcast_pm_suspend(); - if (power_ops.get_power_lock_support()) { - if (power_ops.enable_autosleep) - power_ops.enable_autosleep(); + if (pm_get_power_lock_support()) { + pm_enable_autosleep(); - if (power_ops.power_unlock() < 0) + if (pm_power_unlock() < 0) _E("Power unlock state error."); } else { - power_ops.suspend(); + pm_suspend(); _I("system wakeup!!"); system_wakeup_flag = true; /* Resume !! */ - if (power_ops.check_wakeup_src() == EVENT_DEVICE) + if (check_wakeup_src() == EVENT_DEVICE) /* system waked up by devices */ states[get_pm_cur_state()].trans(EVENT_DEVICE); else @@ -1623,7 +1623,7 @@ go_suspend: return 0; go_lcd_off: - if (!power_ops.get_power_lock_support()) { + if (!pm_get_power_lock_support()) { /* Resume !! */ states[get_pm_cur_state()].trans(EVENT_DEVICE); } @@ -2356,9 +2356,9 @@ static void display_init(void *data) if (flags & WITHOUT_STARTNOTI) { /* start without noti */ _I("Start Power managing without noti"); - if (power_ops.get_power_lock_support()) { + if (pm_get_power_lock_support()) { broadcast_pm_wakeup(); - power_ops.power_lock(); + pm_power_lock(); } /* * Lock lcd off until booting is done. diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 03abf73..ebaf569 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -43,8 +43,7 @@ #include "device-node.h" #include "display/display-dpms.h" #include "display/display.h" - -#define SET_SUSPEND_TIME 0.5 +#include "power/power-control.h" #define TOUCH_ON 1 #define TOUCH_OFF 0 @@ -55,12 +54,6 @@ #define LCD_PHASED_DELAY 10000 /* microsecond */ #define DUMP_MODE_WAITING_TIME 600000 /* milisecond */ -#define POWER_AUTOSLEEP_PATH "/sys/power/autosleep" -#define POWER_LOCK_PATH "/sys/power/wake_lock" -#define POWER_UNLOCK_PATH "/sys/power/wake_unlock" -#define POWER_WAKEUP_PATH "/sys/power/wakeup_count" -#define POWER_STATE_PATH "/sys/power/state" - #define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" #define GESTURE_STR "gesture" @@ -75,16 +68,11 @@ #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; @@ -130,133 +118,6 @@ static int bl_brt(int brightness, int delay) return ret; } -static int system_suspend(void) -{ - int ret; - - _I("system suspend"); - ret = sys_set_str(POWER_STATE_PATH, "mem"); - _I("System resume: %d", ret); - return 0; -} - -static int system_enable_autosleep(void) -{ - _I("System autosleep enabled."); - return sys_set_str(POWER_AUTOSLEEP_PATH, "mem"); -} - -static int vital_mode_support(void) -{ - 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; -} - -static int suspend_other_process(int type) -{ - int ret = 0; - char buf[8]; - const char *command[1]; - - 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_lock(void) -{ - _I("system power lock"); - suspend_other_process(VITAL_WAKEUP); - mainlock_status = POWER_LOCK; - - 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; - - 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; - int ret; - - if (power_lock_support >= 0) - goto out; - - ret = sys_check_node(POWER_LOCK_PATH); - if (ret < 0) - power_lock_support = false; - else - power_lock_support = true; - - _I("System power lock: %s", - (power_lock_support ? "support" : "not support")); - -out: - return power_lock_support; -} - static int get_lcd_power(void) { enum display_state val; @@ -509,41 +370,6 @@ static int get_default_brt(void) return default_brightness; } -static int check_wakeup_src(void) -{ - /* TODO if nedded. - * return wackeup source. user input or device interrupts? (EVENT_DEVICE or EVENT_INPUT) - */ - return EVENT_DEVICE; -} - -static int get_wakeup_count(int *cnt) -{ - int ret; - int wakeup_count; - - if (!cnt) - return -EINVAL; - - ret = sys_get_int(POWER_WAKEUP_PATH, &wakeup_count); - if (ret < 0) - return ret; - - *cnt = wakeup_count; - return 0; -} - -static int set_wakeup_count(int cnt) -{ - int ret; - - ret = sys_set_int(POWER_WAKEUP_PATH, cnt); - if (ret < 0) - return ret; - - return 0; -} - static int get_max_brightness(void) { static int max = -1; @@ -925,16 +751,6 @@ static void _init_ops(void) 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; - power_ops.set_wakeup_count = set_wakeup_count; } int display_service_load(void) @@ -984,23 +800,6 @@ int display_service_free(void) return 0; } -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; -} /* Dummy. Do not consider detached display state */ int is_lcdon_blocked(void) diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index a038caa..d88ff6b 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -40,6 +40,7 @@ #include "shared/common.h" #include "shared/plugin.h" #include "power/power-handler.h" +#include "power/power-control.h" #include "led/touch-key.h" #include "apps/apps.h" #include "display/display-lock.h" diff --git a/plugins/tv/display/state-tv.c b/plugins/tv/display/state-tv.c index 663b66f..fdf48c6 100644 --- a/plugins/tv/display/state-tv.c +++ b/plugins/tv/display/state-tv.c @@ -27,6 +27,7 @@ #include "display/display-ops.h" #include "display/display-lock.h" #include "power/power-handler.h" +#include "power/power-control.h" #include "core.h" #include "poll.h" #include "device-interface.h" @@ -431,7 +432,7 @@ static int suspend_action(int timeout) /* TODO: set wakeup count */ /* sleep state : set system mode to SUSPEND */ - power_ops.suspend(); + pm_suspend(); _I("system wakeup!!"); diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 314e0e7..dda1739 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -57,6 +57,7 @@ #include "extcon/extcon.h" #include "battery/power-supply.h" #include "power/power-handler.h" +#include "power/power-control.h" #include "power/boot.h" #include "power/doze.h" #include "dd-display.h" @@ -728,10 +729,10 @@ void lcd_on_direct(enum device_flags flags) { int ret; - if (power_ops.get_power_lock_support() + if (pm_get_power_lock_support() && (get_pm_cur_state() == S_SLEEP)) { broadcast_pm_wakeup(); - power_ops.power_lock(); + pm_power_lock(); set_pm_cur_state(S_NORMAL); } @@ -1059,7 +1060,7 @@ static void proc_condition_lock(PMMsg *data) get_pname(pid, pname); if ((state == S_LCDOFF) && (get_pm_cur_state() == S_SLEEP) && - (power_ops.get_power_lock() == POWER_UNLOCK)) + (pm_get_power_lock() == POWER_UNLOCK)) proc_change_state(data->cond, INTERNAL_LOCK_PM); if (data->timeout > 0) { @@ -1599,9 +1600,9 @@ static int default_action(int timeout) } if ((get_pm_cur_state() != get_pm_old_state()) && (get_pm_cur_state() != S_SLEEP)) { - if (power_ops.get_power_lock_support()) { + if (pm_get_power_lock_support()) { broadcast_pm_wakeup(); - power_ops.power_lock(); + pm_power_lock(); } set_setting_pmstate(get_pm_cur_state()); pm_cur_state = get_pm_cur_state(); @@ -1664,9 +1665,9 @@ static int default_action(int timeout) if (backlight_ops.get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); - if (!power_ops.get_power_lock_support()) { + if (!pm_get_power_lock_support()) { /* sleep state : set system mode to SUSPEND */ - if (power_ops.get_wakeup_count(&wakeup_count) < 0) + if (get_wakeup_count(&wakeup_count) < 0) _E("Wakeup count read error."); if (wakeup_count < 0) { @@ -1674,7 +1675,7 @@ static int default_action(int timeout) goto go_lcd_off; } - if (power_ops.set_wakeup_count(wakeup_count) < 0) { + if (set_wakeup_count(wakeup_count) < 0) { _E("Wakeup count write error."); goto go_lcd_off; } @@ -1689,18 +1690,17 @@ go_suspend: pm_history_save(PM_LOG_SLEEP, get_pm_cur_state()); #endif broadcast_pm_suspend(); - if (power_ops.get_power_lock_support()) { - if (power_ops.enable_autosleep) - power_ops.enable_autosleep(); + if (pm_get_power_lock_support()) { + pm_enable_autosleep(); - if (power_ops.power_unlock() < 0) + if (pm_power_unlock() < 0) _E("Power unlock state error."); } else { - power_ops.suspend(); + pm_suspend(); _I("system wakeup!!"); system_wakeup_flag = true; /* Resume !! */ - if (power_ops.check_wakeup_src() == EVENT_DEVICE) + if (check_wakeup_src() == EVENT_DEVICE) /* system waked up by devices */ states[get_pm_cur_state()].trans(EVENT_DEVICE); else @@ -1710,7 +1710,7 @@ go_suspend: return 0; go_lcd_off: - if (!power_ops.get_power_lock_support()) { + if (!pm_get_power_lock_support()) { /* Resume !! */ states[get_pm_cur_state()].trans(EVENT_DEVICE); } @@ -2480,9 +2480,9 @@ static void display_init(void *data) if (flags & WITHOUT_STARTNOTI) { /* start without noti */ _I("Start Power managing without noti"); - if (power_ops.get_power_lock_support()) { + if (pm_get_power_lock_support()) { broadcast_pm_wakeup(); - power_ops.power_lock(); + pm_power_lock(); } /* * Lock lcd off until booting is done. diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c old mode 100755 new mode 100644 index 7a5fd39..224ba65 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -45,8 +45,7 @@ #include "display/display.h" #include "battery-monitor.h" #include "battery/power-supply.h" - -#define SET_SUSPEND_TIME 0.5 +#include "power/power-control.h" #define TOUCH_ON 1 #define TOUCH_OFF 0 @@ -57,12 +56,6 @@ #define LCD_PHASED_DELAY 10000 /* microsecond */ #define DUMP_MODE_WAITING_TIME 600000 /* milisecond */ -#define POWER_AUTOSLEEP_PATH "/sys/power/autosleep" -#define POWER_LOCK_PATH "/sys/power/wake_lock" -#define POWER_UNLOCK_PATH "/sys/power/wake_unlock" -#define POWER_WAKEUP_PATH "/sys/power/wakeup_count" -#define POWER_STATE_PATH "/sys/power/state" - #define DISPLAY_HAL_LIB_PATH "/usr/lib/libdisplay-hal.so" #define GESTURE_STR "gesture" @@ -79,16 +72,10 @@ 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; @@ -138,133 +125,6 @@ static int bl_brt(int brightness, int delay) return ret; } -static int system_suspend(void) -{ - int ret; - - _I("system suspend"); - ret = sys_set_str(POWER_STATE_PATH, "mem"); - _I("System resume: %d", ret); - return 0; -} - -static int system_enable_autosleep(void) -{ - _I("System autosleep enabled."); - return sys_set_str(POWER_AUTOSLEEP_PATH, "mem"); -} - -static int vital_mode_support(void) -{ - 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; -} - -static int suspend_other_process(int type) -{ - int ret = 0; - char buf[8]; - const char *command[1]; - - 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_lock(void) -{ - _I("system power lock"); - suspend_other_process(VITAL_WAKEUP); - mainlock_status = POWER_LOCK; - - 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; - - 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; - int ret; - - if (power_lock_support >= 0) - goto out; - - ret = sys_check_node(POWER_LOCK_PATH); - if (ret < 0) - power_lock_support = false; - else - power_lock_support = true; - - _I("System power lock: %s", - (power_lock_support ? "support" : "not support")); - -out: - return power_lock_support; -} - static int get_lcd_power(void) { enum display_state val; @@ -516,41 +376,6 @@ static int get_default_brt(void) return default_brightness; } -static int check_wakeup_src(void) -{ - /* TODO if nedded. - * return wackeup source. user input or device interrupts? (EVENT_DEVICE or EVENT_INPUT) - */ - return EVENT_DEVICE; -} - -static int get_wakeup_count(int *cnt) -{ - int ret; - int wakeup_count; - - if (!cnt) - return -EINVAL; - - ret = sys_get_int(POWER_WAKEUP_PATH, &wakeup_count); - if (ret < 0) - return ret; - - *cnt = wakeup_count; - return 0; -} - -static int set_wakeup_count(int cnt) -{ - int ret; - - ret = sys_set_int(POWER_WAKEUP_PATH, cnt); - if (ret < 0) - return ret; - - return 0; -} - static int get_max_brightness(void) { static int max = -1; @@ -989,16 +814,6 @@ static void _init_ops(void) /* auto-test only function */ backlight_ops.get_brightness_raw = get_brightness; /* always fetch brightness from node even LBM mode */ - - 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; - power_ops.set_wakeup_count = set_wakeup_count; } int display_service_load(void) @@ -1055,11 +870,6 @@ int display_service_free(void) return 0; } -bool vital_mode(void) -{ - return vital_sleep; -} - int is_lcdon_blocked(void) { int state = backlight_ops.get_lcd_power(); @@ -1070,19 +880,6 @@ int is_lcdon_blocked(void) return LCDON_BLOCK_NONE; } -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(); diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index c960efa..a609cd1 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -40,6 +40,7 @@ #include "shared/common.h" #include "shared/plugin.h" #include "power/power-handler.h" +#include "power/power-control.h" #include "led/touch-key.h" #include "apps/apps.h" #include "display/display-lock.h" diff --git a/src/display/device-interface.h b/src/display/device-interface.h index b02a997..078637b 100644 --- a/src/display/device-interface.h +++ b/src/display/device-interface.h @@ -55,22 +55,10 @@ enum { EVENT_END, }; - -/* - * 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); @@ -103,20 +91,7 @@ struct _backlight_ops { void (*release_blink)(void); }; -struct _power_ops { - int (*suspend)(void); - 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); - int (*set_wakeup_count)(int cnt); -}; - extern struct _backlight_ops backlight_ops; -extern struct _power_ops power_ops; enum dpms_state { DPMS_ON, /* In use */ @@ -127,11 +102,6 @@ enum dpms_state { DPMS_DETACH, /* Display detached */ }; -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); diff --git a/src/power/power-control.c b/src/power/power-control.c new file mode 100755 index 0000000..ccef818 --- /dev/null +++ b/src/power/power-control.c @@ -0,0 +1,229 @@ +/* + * deviced + * + * Copyright (c) 2020 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 +#include +#include +#include +#include +#include +#include + +#include "core/log.h" +#include "core/devices.h" +#include "core/common.h" +#include "core/device-notifier.h" +#include "vconf.h" +#include "device-node.h" +#include "display/display-dpms.h" +#include "display/display.h" +#include "power/boot.h" +#include "power-control.h" + +static int mainlock_status = POWER_UNLOCK; +static int vital_service; +static bool vital_sleep; +static int vital_support = -2; + +bool vital_mode(void) +{ + return vital_sleep; +} + +static int vital_mode_support(void) +{ + 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; +} + +int suspend_other_process(int type) +{ + int ret = 0; + char buf[8]; + const char *command[1]; + + 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; +} + +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 pm_suspend(void) +{ + int ret; + + _I("system suspend"); + ret = sys_set_str(POWER_STATE_PATH, "mem"); + _I("System resume: %d", ret); + return 0; +} + +int pm_enable_autosleep(void) +{ + _I("System autosleep enabled."); + return sys_set_str(POWER_AUTOSLEEP_PATH, "mem"); +} + +int pm_power_lock(void) +{ + _I("system power lock"); + suspend_other_process(VITAL_WAKEUP); + mainlock_status = POWER_LOCK; + + return sys_set_str(POWER_LOCK_PATH, "mainlock"); +} + +int pm_get_power_lock(void) +{ + return mainlock_status; +} + +int pm_get_power_lock_support(void) +{ + static int power_lock_support = -1; + int ret; + + if (power_lock_support >= 0) + goto out; + + ret = sys_check_node(POWER_LOCK_PATH); + if (ret < 0) + power_lock_support = false; + else + power_lock_support = true; + + _I("System power lock: %s", + (power_lock_support ? "support" : "not support")); + +out: + return power_lock_support; +} + +int pm_power_unlock(void) +{ + _I("system power unlock"); + suspend_other_process(VITAL_SLEEP); + mainlock_status = POWER_UNLOCK; + + return sys_set_str(POWER_UNLOCK_PATH, "mainlock"); +} + +int check_wakeup_src(void) +{ + /* TODO if nedded. + * return wackeup source. user input or device interrupts? (EVENT_DEVICE or EVENT_INPUT) + */ + return EVENT_DEVICE; +} + +int get_wakeup_count(int *cnt) +{ + int ret; + int wakeup_count; + + if (!cnt) + return -EINVAL; + + ret = sys_get_int(POWER_WAKEUP_PATH, &wakeup_count); + if (ret < 0) + return ret; + + *cnt = wakeup_count; + return 0; +} + +int set_wakeup_count(int cnt) +{ + int ret; + + ret = sys_set_int(POWER_WAKEUP_PATH, cnt); + if (ret < 0) + return ret; + + return 0; +} diff --git a/src/power/power-control.h b/src/power/power-control.h new file mode 100644 index 0000000..f1016b4 --- /dev/null +++ b/src/power/power-control.h @@ -0,0 +1,59 @@ +/* + * deviced + * + * Copyright (c) 2020 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 __POWER_CONTROL_H__ +#define __POWER_CONTROL_H__ + +#define POWER_AUTOSLEEP_PATH "/sys/power/autosleep" +#define POWER_LOCK_PATH "/sys/power/wake_lock" +#define POWER_UNLOCK_PATH "/sys/power/wake_unlock" +#define POWER_WAKEUP_PATH "/sys/power/wakeup_count" +#define POWER_STATE_PATH "/sys/power/state" + +#define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" + +#define SET_SUSPEND_TIME 0.5 + +enum mainlock_state { + POWER_UNLOCK = 0, + POWER_LOCK, +}; + +/* + * Vital state enumeration + */ +enum vital_state { + VITAL_SLEEP, /* suspend state */ + VITAL_WAKEUP, /* resume state */ + VITAL_DISPLAY_WAKEUP, + VITAL_EXIT, +}; + +bool vital_mode(void); +int vital_state_changed(void *data); +int pm_suspend(void); +int pm_enable_autosleep(void); +int pm_power_lock(void); +int pm_power_unlock(void); +int pm_get_power_lock(void); +int pm_get_power_lock_support(void); +int check_wakeup_src(void); +int get_wakeup_count(int *cnt); +int set_wakeup_count(int cnt); +int suspend_other_process(int type); +#endif /* __POWER_CONTROL_H__ */ -- 2.7.4 From c7b71b28fb7faa251c54187502627c24ad0be0d7 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 6 Aug 2020 11:12:06 +0900 Subject: [PATCH 04/16] Guarantee to restore brightness to default on LCDON AutoBrightnessChanged with level 0 on LCDON will check brightness. If the current brightnes is different to default brightness, restore the brightness to the default brightness. This is especially important for turning on LCD from AOD clock as the deferred brightness effect is applied at this point. Change-Id: Ia82a058c5d462d7739d51d161e2740586d990247 Signed-off-by: Youngjae Cho --- .../wearable/display/auto-brightness-sensorhub.c | 66 ++++++++++++---------- plugins/wearable/display/display-handler.c | 5 ++ 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/plugins/wearable/display/auto-brightness-sensorhub.c b/plugins/wearable/display/auto-brightness-sensorhub.c index c096090..2d10285 100644 --- a/plugins/wearable/display/auto-brightness-sensorhub.c +++ b/plugins/wearable/display/auto-brightness-sensorhub.c @@ -38,7 +38,7 @@ static struct display_plugin *disp_plgn; static int auto_brightness_state = SETTING_BRIGHTNESS_AUTOMATIC_OFF; -static bool lbm, hbm, hold, lowdim; +static bool lbm, hbm, hold_brt, lowdim; static void change_brightness_transit(int start, int end) { @@ -48,6 +48,9 @@ static void change_brightness_transit(int start, int end) static void set_brightness_level(int level) { + int default_brightness; + int current_brightness; + if (get_pm_cur_state() != S_NORMAL) return; /* @@ -83,16 +86,19 @@ static void set_brightness_level(int level) auto_brightness_control(BR_HBM_ON, BR_IMPLICIT); break; case SPECIFIC_MODE_OFF: - /* - * Disable LBM or HBM. - * If the flag hold is set when disabling LBM, brightness remains - * held brightness. (FYI. HBM and Hold cannot be both enabled, so - * no need to consider hold flag when disabling HBM) - * Otherwise, brightness changes to default or dim brightness - * depending on flag lowdim. - */ + default_brightness = backlight_ops.get_default_brt(); + backlight_ops.get_brightness(¤t_brightness); + + /* Disable HBM, LBM */ auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); auto_brightness_control(BR_LBM_OFF, BR_IMPLICIT); + + /* For AOD -> LCDON, brightness effect is deferred to this point */ + if (current_brightness != default_brightness && !hold_brt && !lowdim) { + change_brightness_transit(current_brightness, default_brightness); + auto_brightness_control(BR_SET_BRIGHTNESS, default_brightness); + } + break; default: /* @@ -148,10 +154,10 @@ static void change_flag(bool *flag, bool value) // previous int plbm = lbm; int phbm = hbm; - int phold = hold; + int phold = hold_brt; int pld = lowdim; - if (flag != &lbm && flag != &hbm && flag != &hold && flag != &lowdim) { + if (flag != &lbm && flag != &hbm && flag != &hold_brt && flag != &lowdim) { _E("Invalid flag setting."); return; } @@ -164,7 +170,7 @@ static void change_flag(bool *flag, bool value) _D("Change flag LBM/HBM/Hold/LowDim: %d%d%d%d -> %d%d%d%d", plbm, phbm, phold, pld, - lbm, hbm, hold, lowdim); + lbm, hbm, hold_brt, lowdim); } int auto_brightness_control(enum brightness_request_e request, int set_brightness) @@ -179,28 +185,28 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes if (request == BR_LBM_ON) { if (!get_lbm_setting()) return 0; - if (!lbm && !hbm && !hold && !lowdim) { + if (!lbm && !hbm && !hold_brt && !lowdim) { change_brightness_transit(default_brightness, lbm_down_brt(default_brightness)); lbm_set_state(true); backlight_ops.set_brightness(default_brightness); change_flag(&lbm, 1); - } else if (!lbm && !hbm && !hold && lowdim) { + } else if (!lbm && !hbm && !hold_brt && lowdim) { change_brightness_transit(current_brightness, lbm_down_brt(current_brightness)); lbm_set_state(true); backlight_ops.set_brightness(current_brightness); change_flag(&lbm, 1); - } else if (!lbm && !hbm && hold) { + } else if (!lbm && !hbm && hold_brt) { change_flag(&lbm, 1); } } else if (request == BR_HBM_ON) { - if (!lbm && !hbm && !hold) { + if (!lbm && !hbm && !hold_brt) { if (!lowdim) change_brightness_transit(default_brightness, PM_MAX_BRIGHTNESS); else change_brightness_transit(current_brightness, PM_MAX_BRIGHTNESS); hbm_set_state(true); change_flag(&hbm, 1); - } else if (!lbm && !hbm && hold) { + } else if (!lbm && !hbm && hold_brt) { _E("Someone holds brightness, HBM is ignored."); return -EBUSY; } @@ -209,21 +215,21 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes _E("HBM state. Hold brightness is ignored."); return -EBUSY; } - if (lbm && !hold) { + if (lbm && !hold_brt) { lbm_set_state(false); change_brightness_transit(lbm_down_brt(current_brightness), set_brightness); } else { backlight_ops.set_brightness(set_brightness); } - change_flag(&hold, 1); + change_flag(&hold_brt, 1); } else if (request == BR_LOWDIM_ON) { if (!lowdim) { - if (!hbm && !hold && (get_pm_cur_state() == S_NORMAL)) + if (!hbm && !hold_brt && (get_pm_cur_state() == S_NORMAL)) backlight_ops.dim(); change_flag(&lowdim, 1); } } else if (request == BR_LBM_OFF) { - if (lbm && !hold) { + if (lbm && !hold_brt) { lbm_set_state(false); change_flag(&lbm, 0); @@ -237,7 +243,7 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes } else { backlight_ops.dim(); } - } else if (lbm && hold) { + } else if (lbm && hold_brt) { change_flag(&lbm, 0); } } else if (request == BR_HBM_OFF) { @@ -250,8 +256,8 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes change_flag(&hbm, 0); } } else if (request == BR_RELEASE_BRIGHTNESS) { - if (!lbm && hold) { - change_flag(&hold, 0); + if (!lbm && hold_brt) { + change_flag(&hold_brt, 0); /* called by DEVICE_NOTIFIER_LCD_OFF_COMPLETE, no need to change brightness */ if (get_pm_cur_state() != S_NORMAL) @@ -261,8 +267,8 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes backlight_ops.set_brightness(default_brightness); else backlight_ops.dim(); - } else if (lbm && hold) { - change_flag(&hold, 0); + } else if (lbm && hold_brt) { + change_flag(&hold_brt, 0); if (!lowdim) { change_brightness_transit(current_brightness, lbm_down_brt(default_brightness)); lbm_set_state(true); @@ -275,15 +281,15 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes } } else if (request == BR_LOWDIM_OFF) { if (lowdim) { - if (!hbm && !hold && (get_pm_cur_state() == S_NORMAL)) + if (!hbm && !hold_brt && (get_pm_cur_state() == S_NORMAL)) backlight_ops.update(); change_flag(&lowdim, 0); } } else if (request == BR_SET_BRIGHTNESS) { - if (lbm && hold) + if (lbm && hold_brt) lbm_set_state(true); change_flag(&lowdim, 0); - change_flag(&hold, 0); + change_flag(&hold_brt, 0); backlight_ops.set_default_brt(set_brightness); if (!hbm) { ret = backlight_ops.set_brightness(set_brightness); @@ -322,7 +328,7 @@ static int display_off_complete_changed(void *data) int auto_brightness_restore(void) { /* maintain hold brightness */ - if (hold) + if (hold_brt) return 0; /* update to the default brightness */ diff --git a/plugins/wearable/display/display-handler.c b/plugins/wearable/display/display-handler.c index 1c5dd09..ddb25cd 100644 --- a/plugins/wearable/display/display-handler.c +++ b/plugins/wearable/display/display-handler.c @@ -53,6 +53,11 @@ static gboolean lcdon_from_aod_cb(gpointer data) int level = (int) data; autobrt_timer = 0; + + /* If it is still not turned on, do not apply auto brightness */ + if (backlight_ops.get_lcd_power() != DPMS_ON) + return G_SOURCE_REMOVE; + backlight_ops.transit_state(DPMS_ON); display_info.set_brightness_level(level); -- 2.7.4 From 4c3620774074c963a5bc5495c5363a76d39606c4 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Wed, 12 Aug 2020 11:38:58 +0900 Subject: [PATCH 05/16] Fix initializtion for extcon_usbhost Change-Id: I98e67b10b0f3790b70ee77bbd3d41cb6ee99dc39 Signed-off-by: Hyotaek Shim --- src/usbhost/usb-host.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index c4cd801..2d5ded1 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -1132,7 +1132,9 @@ static void usbhost_init(void *data) { int ret; - disp_plgn = get_display_plugin(); + if (!disp_plgn) + disp_plgn = get_display_plugin(); + if (!disp_plgn) _E("Failed to get display plugin."); @@ -1192,6 +1194,15 @@ static const struct device_ops usbhost_device_ops = { DEVICE_OPS_REGISTER(&usbhost_device_ops) +static void extcon_usbhost_init() +{ + if (!disp_plgn) + disp_plgn = get_display_plugin(); + + if (!disp_plgn) + _E("Failed to get display plugin."); +} + static int extcon_usbhost_state_changed(int status) { if (status == USBHOST_DISCONNECTED) { @@ -1208,6 +1219,7 @@ static int extcon_usbhost_state_changed(int status) static struct extcon_ops extcon_usbhost_ops = { .name = EXTCON_CABLE_USB_HOST, + .init = extcon_usbhost_init, .update = extcon_usbhost_state_changed, }; -- 2.7.4 From c6f528f7c97ebe58dbecc983435816795e828be2 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Wed, 12 Aug 2020 14:35:11 +0900 Subject: [PATCH 06/16] Fix battery_plgn memory corruption Change-Id: Ib20a86452e669873cd7b0f1a0ae3ef21f077ac0a Signed-off-by: Yunmi Ha --- src/battery/power-supply.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index b953207..93835c8 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -1720,7 +1720,7 @@ static void power_supply_init(void *data) if (ret < 0) _E("Failed to init dbus method: %d", ret); - battery_ops_init((void *)&battery_plgn); + battery_ops_init((void *)battery_plgn); } static void power_supply_exit(void *data) -- 2.7.4 From db75fef04accc5a5ea41eb203c00d10224d7b506 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Wed, 12 Aug 2020 15:21:35 +0900 Subject: [PATCH 07/16] Move variable initialization code to probe function Change-Id: Ieafb6b73e6a64da572d79b401937cc495bb8fa16 Signed-off-by: Yunmi Ha --- plugins/iot/display/core.c | 2 -- plugins/wearable/display/bezel.c | 10 ++++++---- plugins/wearable/display/swim.c | 16 ++++++++++++---- src/battery/battery-time.c | 10 ++++++---- src/battery/lowbat-handler.c | 20 ++++++++++++-------- src/battery/power-supply.c | 20 ++++++++++++-------- src/led/touch-key.c | 10 ++++++---- src/power/power-handler.c | 12 ++++++++++++ src/time/time-handler.c | 15 +++++++++++---- src/touchscreen/touchscreen.c | 12 ++++++------ src/usbhost/usb-host.c | 16 ++++++++++++---- 11 files changed, 95 insertions(+), 48 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 2696eaf..2b5880a 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -2272,8 +2272,6 @@ static void display_init(void *data) _I("Start power manager."); - set_module_display_plugin(); - signal(SIGHUP, sig_hup); power_saving_func = default_saving_mode; diff --git a/plugins/wearable/display/bezel.c b/plugins/wearable/display/bezel.c index 6fb927f..5c96a3e 100644 --- a/plugins/wearable/display/bezel.c +++ b/plugins/wearable/display/bezel.c @@ -161,6 +161,12 @@ static int bezel_probe(void *data) struct hw_info *info; int ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + return -1; + } + if (bezel_dev) return 0; @@ -194,10 +200,6 @@ static void bezel_init(void *data) if (!bezel_dev) return; - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - if (bezel_dev->get_sw_state && bezel_dev->get_sw_state(&init_bezel_state) == 0) { _I("Init SW bezel, state: %d", init_bezel_state); bezel_type = BEZEL_SOFT; diff --git a/plugins/wearable/display/swim.c b/plugins/wearable/display/swim.c index 3e7a28a..3407fc0 100644 --- a/plugins/wearable/display/swim.c +++ b/plugins/wearable/display/swim.c @@ -112,13 +112,20 @@ static int swim_restore_cb(void *data) return 0; } -static void swim_init(void *data) +static int swim_probe(void *data) { - int ret; - disp_plgn = get_display_plugin(); - if (!disp_plgn) + if (!disp_plgn) { _E("Failed to get display plugin."); + return -1; + } + + return 0; +} + +static void swim_init(void *data) +{ + int ret; touchscreen_ops = find_device("touchscreen"); @@ -136,6 +143,7 @@ static void swim_init(void *data) static const struct device_ops swim_device_ops = { DECLARE_NAME_LEN("swim"), + .probe = swim_probe, .init = swim_init, .execute = swim_execute, }; diff --git a/src/battery/battery-time.c b/src/battery/battery-time.c index cc1e20f..92bd6d7 100644 --- a/src/battery/battery-time.c +++ b/src/battery/battery-time.c @@ -398,6 +398,12 @@ static int battery_probe(void *data) struct hw_info *info; int ret; + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + return -1; + } + ret = hw_get_info(BATTERY_HARDWARE_DEVICE_ID, (const struct hw_info **)&info); @@ -411,10 +417,6 @@ static void battery_init(void *data) { int ret; - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_BATTERY, &dbus_interface); if (ret < 0) _E("Failed to init dbus method: %d", ret); diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index d5b5d6b..b80d8ac 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -697,6 +697,18 @@ static int lowbat_probe(void *data) static const struct device_ops *ops; int ret = -EINVAL; + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + return ret; + } + + battery_plgn = get_battery_plugin(); + if (!battery_plgn) { + _E("Failed to get battery plugin."); + return ret; + } + FIND_DEVICE_INT(ops, "power_supply"); ret = ops->probe(data); if (ret == 0) @@ -709,14 +721,6 @@ static void lowbat_init(void *data) { int ret; - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - - battery_plgn = get_battery_plugin(); - if (!battery_plgn) - _E("Failed to get battery plugin."); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); register_notifier(DEVICE_NOTIFIER_POWER_SUPPLY, lowbat_monitor_init); diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 93835c8..e91a853 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -1597,6 +1597,18 @@ static int power_supply_probe(void *data) struct hw_info *info; int ret, r; + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + return -1; + } + + battery_plgn = get_battery_plugin(); + if (!battery_plgn) { + _E("Failed to get battery plugin."); + return -1; + } + if (battery_dev) return 0; @@ -1693,14 +1705,6 @@ static void power_supply_init(void *data) { int ret; - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - - battery_plgn = get_battery_plugin(); - if (!battery_plgn) - _E("Failed to get battery plugin."); - memset(&battery, 0, sizeof(struct battery_status)); memset(&old_battery, 0, sizeof(struct battery_status)); battery.charger_charging = CHARGER_ENABLED; diff --git a/src/led/touch-key.c b/src/led/touch-key.c index 402b8ac..0e67716 100644 --- a/src/led/touch-key.c +++ b/src/led/touch-key.c @@ -260,6 +260,12 @@ static int touchled_service_free(void) static int touchled_probe(void *data) { + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + return -1; + } + /* load led device */ return touchled_service_load(); } @@ -268,10 +274,6 @@ static void touchled_init(void *data) { int ret; - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - /* get touchkey light duration setting */ ret = vconf_get_int(VCONFKEY_SETAPPL_TOUCHKEY_LIGHT_DURATION, &hardkey_duration); if (ret < 0) { diff --git a/src/power/power-handler.c b/src/power/power-handler.c index ac14773..6300c84 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -750,6 +750,17 @@ out: return done; } +static int power_probe(void *data) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + return -1; + } + + return 0; +} + static void power_init(void *data) { int ret; @@ -780,6 +791,7 @@ static void power_init(void *data) static const struct device_ops power_device_ops = { DECLARE_NAME_LEN(POWER_OPS_NAME), + .probe = power_probe, .init = power_init, .execute = power_execute, }; diff --git a/src/time/time-handler.c b/src/time/time-handler.c index c53a801..0d8d2ff 100644 --- a/src/time/time-handler.c +++ b/src/time/time-handler.c @@ -387,13 +387,19 @@ out: return 0; } -static void time_init(void *data) +static int time_probe(void *data) { - int ret; - disp_plgn = get_display_plugin(); - if (!disp_plgn) + if (!disp_plgn) { _E("Failed to get display plugin."); + return -1; + } + return 0; +} + +static void time_init(void *data) +{ + int ret; ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_SYSNOTI, &dbus_interface); if (ret < 0) @@ -410,6 +416,7 @@ static void time_init(void *data) static const struct device_ops time_device_ops = { .name = "time", + .probe = time_probe, .init = time_init, }; diff --git a/src/touchscreen/touchscreen.c b/src/touchscreen/touchscreen.c index 65269b1..2be7c1c 100644 --- a/src/touchscreen/touchscreen.c +++ b/src/touchscreen/touchscreen.c @@ -103,6 +103,12 @@ static int touchscreen_probe(void *data) int ret; struct hw_info *info; + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + return -1; + } + if (touchscreen_dev) return 0; @@ -314,12 +320,6 @@ static void touchscreen_init(void *data) { int ret, val; - disp_plgn = get_display_plugin(); - if (!disp_plgn) { - _E("Failed to get display plugin."); - return ; - } - _display_conf = dlsym(disp_plgn->handle, "display_conf"); if (!_display_conf) _E("Failed to obtain address of display_conf, %s.", dlerror()); diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 2d5ded1..12f8d06 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -1128,15 +1128,22 @@ static int booting_done(void *data) return 0; } -static void usbhost_init(void *data) +static int usbhost_probe(void *data) { - int ret; - if (!disp_plgn) disp_plgn = get_display_plugin(); - if (!disp_plgn) + if (!disp_plgn) { _E("Failed to get display plugin."); + return -1; + } + + return 0; +} + +static void usbhost_init(void *data) +{ + int ret; /* register usbhost uevent */ ret = register_kernel_uevent_control(&uh); @@ -1188,6 +1195,7 @@ static void usbhost_exit(void *data) static const struct device_ops usbhost_device_ops = { .name = "usbhost", + .probe = usbhost_probe, .init = usbhost_init, .exit = usbhost_exit, }; -- 2.7.4 From 23a4276cef9262f0d072c982e7ff18915c717ac9 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Thu, 13 Aug 2020 15:17:59 +0900 Subject: [PATCH 08/16] Add initialize constructor for variable init. Change-Id: I0c469e3609f4c99a36531d1a2a9adbcea48aab50 Signed-off-by: Yunmi Ha --- plugins/iot/display/core.c | 18 +++++------- plugins/iot/display/key-filter.c | 11 +++++--- plugins/mobile/battery/battery-notification.c | 12 +++++--- plugins/mobile/display/core.c | 19 +++++-------- plugins/mobile/display/key-filter.c | 11 +++++--- plugins/tv/display/core.c | 18 +++++------- plugins/tv/display/key-filter.c | 11 +++++--- plugins/tv/display/state-tv.c | 12 +++++--- .../wearable/display/auto-brightness-sensorhub.c | 14 ++++++---- plugins/wearable/display/bezel.c | 14 ++++++---- plugins/wearable/display/core.c | 19 +++++-------- plugins/wearable/display/key-filter.c | 11 +++++--- plugins/wearable/display/swim.c | 20 ++++++-------- src/apps/apps.c | 7 +++-- src/apps/apps.h | 1 - src/battery/battery-time.c | 13 +++++---- src/battery/lowbat-handler.c | 25 +++++++++-------- src/battery/power-supply.c | 26 ++++++++++-------- src/display/ambient-mode.c | 12 +++++--- src/display/display-dbus.c | 13 +++++---- src/display/display-signal.c | 7 +++-- src/display/display-signal.h | 2 -- src/display/poll.c | 12 ++++---- src/display/setting.c | 13 +++++---- src/extcon/cradle.c | 12 +++++--- src/extcon/earjack.c | 16 +++++------ src/extcon/hdmi.c | 12 +++++--- src/led/touch-key.c | 14 ++++++---- src/power/boot.c | 21 +++++++------- src/power/power-handler.c | 24 ++++++---------- src/time/time-handler.c | 19 ++++++------- src/touchscreen/touchscreen.c | 13 +++++---- src/usb/usb.c | 12 +++++--- src/usbhost/usb-host.c | 32 ++++++---------------- 34 files changed, 251 insertions(+), 245 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 2b5880a..0fe3a8a 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -2185,16 +2185,6 @@ static void add_timer_for_init_dpms(void) * Power manager Main * */ -static void set_module_display_plugin(void) -{ - disp_plgn = get_display_plugin(); /* self */ - if (!disp_plgn) - _E("Failed to get display plugin."); - - set_apps_display_plugin(disp_plgn); /* apps */ - set_display_signal_display_plugin(disp_plgn); /* display-signal */ -} - static int display_probe(void *data) { int ret; @@ -2210,7 +2200,6 @@ static int display_probe(void *data) /* display_plugin instance initialization */ init_pm_internal(); - set_module_display_plugin(); disp_plgn->device_flags_to_string = __device_flags_to_string; return 0; @@ -2512,6 +2501,13 @@ static const struct device_ops display_device_ops = { DEVICE_OPS_REGISTER(&display_device_ops) +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} /** * @} */ diff --git a/plugins/iot/display/key-filter.c b/plugins/iot/display/key-filter.c index 66ab61c..186a115 100644 --- a/plugins/iot/display/key-filter.c +++ b/plugins/iot/display/key-filter.c @@ -757,10 +757,6 @@ static struct display_actor_ops display_menukey_actor = { static void keyfilter_init(void) { - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - display_add_actor(&display_powerkey_actor); display_add_actor(&display_menukey_actor); @@ -795,3 +791,10 @@ static const struct display_keyfilter_ops normal_keyfilter_ops = { const struct display_keyfilter_ops *keyfilter_ops = &normal_keyfilter_ops; +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/plugins/mobile/battery/battery-notification.c b/plugins/mobile/battery/battery-notification.c index 3903c0d..d72c287 100644 --- a/plugins/mobile/battery/battery-notification.c +++ b/plugins/mobile/battery/battery-notification.c @@ -381,10 +381,6 @@ static void battery_notification_init(void *data) if (!plugin) return; - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - _D("Add plugins for battery notification."); plugin->lowbat_noti_launch = launch_lowbat_noti; plugin->lowbat_noti_clean = clean_lowbat_noti; @@ -410,3 +406,11 @@ static const struct battery_ops battery_notification_ops = { }; BATTERY_OPS_REGISTER(&battery_notification_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index ec01102..80cef01 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -2195,17 +2195,6 @@ static void add_timer_for_init_dpms(void) * Power manager Main * */ - -static void set_module_display_plugin(void) -{ - disp_plgn = get_display_plugin(); /* self */ - if (!disp_plgn) - _E("Failed to get display plugin."); - - set_apps_display_plugin(disp_plgn); /* apps */ - set_display_signal_display_plugin(disp_plgn); /* display-signal */ -} - static int display_probe(void *data) { int ret; @@ -2221,7 +2210,6 @@ static int display_probe(void *data) /* display_plugin instance initialization */ init_pm_internal(); - set_module_display_plugin(); disp_plgn->device_flags_to_string = __device_flags_to_string; return 0; @@ -2528,6 +2516,13 @@ static const struct device_ops display_device_ops = { DEVICE_OPS_REGISTER(&display_device_ops) +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} /** * @} */ diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index 546d4e1..bd939ff 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -784,10 +784,6 @@ static struct display_actor_ops display_menukey_actor = { static void keyfilter_init(void) { - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - display_add_actor(&display_powerkey_actor); display_add_actor(&display_menukey_actor); @@ -822,3 +818,10 @@ static const struct display_keyfilter_ops normal_keyfilter_ops = { const struct display_keyfilter_ops *keyfilter_ops = &normal_keyfilter_ops; +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 058fa83..f997dd1 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -2186,16 +2186,6 @@ static void add_timer_for_init_dpms(void) * */ -static void set_module_display_plugin(void) -{ - disp_plgn = get_display_plugin(); /* self */ - if (!disp_plgn) - _E("Failed to get display plugin."); - - set_apps_display_plugin(disp_plgn); /* apps */ - set_display_signal_display_plugin(disp_plgn); /* display-signal */ -} - static int display_probe(void *data) { int ret; @@ -2211,7 +2201,6 @@ static int display_probe(void *data) /* display_plugin instance initialization */ init_pm_internal(); - set_module_display_plugin(); disp_plgn->device_flags_to_string = __device_flags_to_string; return 0; @@ -2513,6 +2502,13 @@ static const struct device_ops display_device_ops = { DEVICE_OPS_REGISTER(&display_device_ops) +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} /** * @} */ diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index d88ff6b..3874dba 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -751,10 +751,6 @@ static struct display_actor_ops display_menukey_actor = { static void keyfilter_init(void) { - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - display_add_actor(&display_powerkey_actor); display_add_actor(&display_menukey_actor); @@ -789,3 +785,10 @@ static const struct display_keyfilter_ops normal_keyfilter_ops = { const struct display_keyfilter_ops *keyfilter_ops = &normal_keyfilter_ops; +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/plugins/tv/display/state-tv.c b/plugins/tv/display/state-tv.c index fdf48c6..f8f1df1 100644 --- a/plugins/tv/display/state-tv.c +++ b/plugins/tv/display/state-tv.c @@ -551,10 +551,6 @@ void state_tv_init(void) _I("TV Profile !!"); - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - for (i = 0 ; i < ARRAY_SIZE(tv_states) ; i++) set_tv_operations(tv_states[i].state, tv_states[i].name, @@ -571,3 +567,11 @@ void state_tv_deinit(void) { unregister_notifier(DEVICE_NOTIFIER_DISPLAY_LOCK, display_lock_changed); } + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/plugins/wearable/display/auto-brightness-sensorhub.c b/plugins/wearable/display/auto-brightness-sensorhub.c index 2d10285..502c86f 100644 --- a/plugins/wearable/display/auto-brightness-sensorhub.c +++ b/plugins/wearable/display/auto-brightness-sensorhub.c @@ -339,12 +339,6 @@ int prepare_level_handler(void) { int status, ret; - disp_plgn = get_display_plugin(); - if (!disp_plgn) { - _E("Failed to get display plugin."); - return -1; - } - display_info.set_brightness_level = set_brightness_level; disp_plgn->auto_brightness_control = auto_brightness_control; @@ -370,3 +364,11 @@ void exit_level_handler(void) unregister_notifier(DEVICE_NOTIFIER_LCD_OFF, display_off_changed); unregister_notifier(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, display_off_complete_changed); } + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/plugins/wearable/display/bezel.c b/plugins/wearable/display/bezel.c index 5c96a3e..bb22d8f 100644 --- a/plugins/wearable/display/bezel.c +++ b/plugins/wearable/display/bezel.c @@ -161,12 +161,6 @@ static int bezel_probe(void *data) struct hw_info *info; int ret; - disp_plgn = get_display_plugin(); - if (!disp_plgn) { - _E("Failed to get display plugin."); - return -1; - } - if (bezel_dev) return 0; @@ -321,3 +315,11 @@ static const struct device_ops bezel_device_ops = { }; DEVICE_OPS_REGISTER(&bezel_device_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index dda1739..60d1db2 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -2277,17 +2277,6 @@ static void add_timer_for_init_dpms(void) * Power manager Main * */ - -static void set_module_display_plugin(void) -{ - disp_plgn = get_display_plugin(); /* self */ - if (!disp_plgn) - _E("Failed to get display plugin."); - - set_apps_display_plugin(disp_plgn); /* apps */ - set_display_signal_display_plugin(disp_plgn); /* display-signal */ -} - static int display_probe(void *data) { int ret; @@ -2303,7 +2292,6 @@ static int display_probe(void *data) /* display_plugin instance initialization */ init_pm_internal(); - set_module_display_plugin(); disp_plgn->device_flags_to_string = __device_flags_to_string; return 0; @@ -2642,6 +2630,13 @@ static const struct device_ops display_device_ops = { DEVICE_OPS_REGISTER(&display_device_ops) +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} /** * @} */ diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index a609cd1..b543a8a 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -731,10 +731,6 @@ static struct display_actor_ops display_menukey_actor = { static void keyfilter_init(void) { - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - display_add_actor(&display_powerkey_actor); display_add_actor(&display_menukey_actor); @@ -769,3 +765,10 @@ static const struct display_keyfilter_ops normal_keyfilter_ops = { const struct display_keyfilter_ops *keyfilter_ops = &normal_keyfilter_ops; +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/plugins/wearable/display/swim.c b/plugins/wearable/display/swim.c index 3407fc0..3651456 100644 --- a/plugins/wearable/display/swim.c +++ b/plugins/wearable/display/swim.c @@ -112,17 +112,6 @@ static int swim_restore_cb(void *data) return 0; } -static int swim_probe(void *data) -{ - disp_plgn = get_display_plugin(); - if (!disp_plgn) { - _E("Failed to get display plugin."); - return -1; - } - - return 0; -} - static void swim_init(void *data) { int ret; @@ -143,9 +132,16 @@ static void swim_init(void *data) static const struct device_ops swim_device_ops = { DECLARE_NAME_LEN("swim"), - .probe = swim_probe, .init = swim_init, .execute = swim_execute, }; DEVICE_OPS_REGISTER(&swim_device_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/src/apps/apps.c b/src/apps/apps.c index b92e693..72deb24 100644 --- a/src/apps/apps.c +++ b/src/apps/apps.c @@ -173,7 +173,10 @@ int remove_notification(char *type, int id) __cb, -1, NULL); } -void set_apps_display_plugin(struct display_plugin *dp) +static void __CONSTRUCTOR__ initialize(void) { - disp_plgn = dp; + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } } diff --git a/src/apps/apps.h b/src/apps/apps.h index d455c8c..5e1b393 100644 --- a/src/apps/apps.h +++ b/src/apps/apps.h @@ -36,7 +36,6 @@ int launch_system_app(char *type, int num, ...); int launch_message_post(char *type); int add_async_notification(char *type, dbus_pending_cb func, char *sig, ...); int remove_notification(char *type, int id); -void set_apps_display_plugin(struct display_plugin *dp); #endif /* __APPS_H__ */ diff --git a/src/battery/battery-time.c b/src/battery/battery-time.c index 92bd6d7..154be9a 100644 --- a/src/battery/battery-time.c +++ b/src/battery/battery-time.c @@ -398,12 +398,6 @@ static int battery_probe(void *data) struct hw_info *info; int ret; - disp_plgn = get_display_plugin(); - if (!disp_plgn) { - _E("Failed to get display plugin."); - return -1; - } - ret = hw_get_info(BATTERY_HARDWARE_DEVICE_ID, (const struct hw_info **)&info); @@ -438,3 +432,10 @@ static const struct device_ops battery_time_device_ops = { DEVICE_OPS_REGISTER(&battery_time_device_ops) +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index b80d8ac..e8e32a2 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -697,18 +697,6 @@ static int lowbat_probe(void *data) static const struct device_ops *ops; int ret = -EINVAL; - disp_plgn = get_display_plugin(); - if (!disp_plgn) { - _E("Failed to get display plugin."); - return ret; - } - - battery_plgn = get_battery_plugin(); - if (!battery_plgn) { - _E("Failed to get battery plugin."); - return ret; - } - FIND_DEVICE_INT(ops, "power_supply"); ret = ops->probe(data); if (ret == 0) @@ -787,3 +775,16 @@ static const struct device_ops lowbat_device_ops = { }; DEVICE_OPS_REGISTER(&lowbat_device_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } + + battery_plgn = get_battery_plugin(); + if (!battery_plgn) { + _E("Failed to get battery plugin."); + } +} diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index e91a853..44f0711 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -1597,18 +1597,6 @@ static int power_supply_probe(void *data) struct hw_info *info; int ret, r; - disp_plgn = get_display_plugin(); - if (!disp_plgn) { - _E("Failed to get display plugin."); - return -1; - } - - battery_plgn = get_battery_plugin(); - if (!battery_plgn) { - _E("Failed to get battery plugin."); - return -1; - } - if (battery_dev) return 0; @@ -1746,3 +1734,17 @@ static const struct device_ops power_supply_ops = { }; DEVICE_OPS_REGISTER(&power_supply_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } + + battery_plgn = get_battery_plugin(); + if (!battery_plgn) { + _E("Failed to get battery plugin."); + } +} + diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index 05777e3..fb8809b 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -261,10 +261,6 @@ static void ambient_init(void *data) { int ret; - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - ret = vconf_get_bool("db/starter/always_on_display", &ambient_condition); if (ret < 0) { _E("Failed to get initial AOD condition. AOD is not going to work."); @@ -307,3 +303,11 @@ static const struct display_ops ambient_ops = { }; DISPLAY_OPS_REGISTER(&ambient_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index e66c78e..3cd7f20 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -1278,12 +1278,6 @@ int init_pm_dbus(void) { int ret; - disp_plgn = get_display_plugin(); - if (!disp_plgn) { - _E("Failed to get display plugin."); - return -1; - } - display_add_actor(&display_api_actor); display_add_actor(&display_gesture_actor); @@ -1304,3 +1298,10 @@ int init_pm_dbus(void) return 0; } +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/src/display/display-signal.c b/src/display/display-signal.c index 0abfb04..e695e99 100644 --- a/src/display/display-signal.c +++ b/src/display/display-signal.c @@ -174,7 +174,10 @@ void set_process_active(bool flag, pid_t pid) _E("Failed to send dbus signal to resourced."); } -void set_display_signal_display_plugin(struct display_plugin *dp) +static void __CONSTRUCTOR__ initialize(void) { - disp_plgn = dp; + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } } diff --git a/src/display/display-signal.h b/src/display/display-signal.h index 35c367d..f68b0b2 100644 --- a/src/display/display-signal.h +++ b/src/display/display-signal.h @@ -23,7 +23,6 @@ #include #include "util.h" -#include "display-ops.h" #include "core/devices.h" #include "core/device-notifier.h" @@ -58,6 +57,5 @@ void broadcast_lcd_on(enum signal_type type, enum device_flags flags); void broadcast_lcd_off(enum signal_type type, enum device_flags flags); void broadcast_lcd_off_late(enum device_flags flags); void set_process_active(bool flag, pid_t pid); -void set_display_signal_display_plugin(struct display_plugin *dp); #endif /* __DISPLAY_SIGNAL_H__ */ diff --git a/src/display/poll.c b/src/display/poll.c index 548f186..279675c 100644 --- a/src/display/poll.c +++ b/src/display/poll.c @@ -177,13 +177,15 @@ static int __pm_change_internal(pid_t pid, int s_bits) void init_pm_internal() { + disp_plgn->pm_lock_internal = __pm_lock_internal; + disp_plgn->pm_unlock_internal = __pm_unlock_internal; + disp_plgn->pm_change_internal = __pm_change_internal; +} + +static void __CONSTRUCTOR__ initialize(void) +{ disp_plgn = get_display_plugin(); if (!disp_plgn) { _E("Failed to get display plugin."); - return ; } - - disp_plgn->pm_lock_internal = __pm_lock_internal; - disp_plgn->pm_unlock_internal = __pm_unlock_internal; - disp_plgn->pm_change_internal = __pm_change_internal; } diff --git a/src/display/setting.c b/src/display/setting.c index 30065cc..0552001 100644 --- a/src/display/setting.c +++ b/src/display/setting.c @@ -248,12 +248,6 @@ int init_setting(int (*func) (int key_idx, int val)) { int i; - disp_plgn = get_display_plugin(); - if (!disp_plgn) { - _E("Failed to get display plugin."); - return -1; - } - if (func != NULL) disp_plgn->update_pm_setting = func; @@ -281,3 +275,10 @@ int exit_setting(void) return 0; } +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/src/extcon/cradle.c b/src/extcon/cradle.c index 9bc51d7..72e368c 100644 --- a/src/extcon/cradle.c +++ b/src/extcon/cradle.c @@ -125,10 +125,6 @@ static void cradle_init(void *data) { int ret; - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - register_notifier(DEVICE_NOTIFIER_LCD, display_changed); ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_SYSNOTI, &dbus_interface); @@ -149,3 +145,11 @@ static struct extcon_ops cradle_extcon_ops = { }; EXTCON_OPS_REGISTER(cradle_extcon_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/src/extcon/earjack.c b/src/extcon/earjack.c index fe8e5f9..003b7bb 100644 --- a/src/extcon/earjack.c +++ b/src/extcon/earjack.c @@ -88,17 +88,17 @@ static int earjack_update(int status) return 0; } -static void earjack_init(void *data) -{ - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); -} - static struct extcon_ops earjack_extcon_ops = { .name = EXTCON_CABLE_HEADPHONE_OUT, - .init = earjack_init, .update = earjack_update, }; EXTCON_OPS_REGISTER(earjack_extcon_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/src/extcon/hdmi.c b/src/extcon/hdmi.c index a94e200..9eac710 100644 --- a/src/extcon/hdmi.c +++ b/src/extcon/hdmi.c @@ -120,10 +120,6 @@ static void hdmi_init(void *data) { int ret; - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - register_notifier(DEVICE_NOTIFIER_LCD, display_changed); ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_SYSNOTI, &dbus_interface); @@ -144,3 +140,11 @@ static struct extcon_ops hdmi_extcon_ops = { }; EXTCON_OPS_REGISTER(hdmi_extcon_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/src/led/touch-key.c b/src/led/touch-key.c index 0e67716..6f679be 100644 --- a/src/led/touch-key.c +++ b/src/led/touch-key.c @@ -260,12 +260,6 @@ static int touchled_service_free(void) static int touchled_probe(void *data) { - disp_plgn = get_display_plugin(); - if (!disp_plgn) { - _E("Failed to get display plugin."); - return -1; - } - /* load led device */ return touchled_service_load(); } @@ -333,3 +327,11 @@ static const struct device_ops touchled_device_ops = { }; DEVICE_OPS_REGISTER(&touchled_device_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/src/power/boot.c b/src/power/boot.c index feadbd8..24fc3ea 100644 --- a/src/power/boot.c +++ b/src/power/boot.c @@ -79,16 +79,9 @@ static void booting_done_received(GDBusConnection *conn, remove_booting_done_handler(NULL); - if (!disp_plgn) - disp_plgn = get_display_plugin(); - - if (!disp_plgn) - _E("Failed to get display plugin."); - else { - _I("Real booting done. Unlock LCD_OFF."); - if (disp_plgn->pm_unlock_internal) - disp_plgn->pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); - } + _I("Real booting done. Unlock LCD_OFF."); + if (disp_plgn->pm_unlock_internal) + disp_plgn->pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); _I("Signal booting done."); @@ -120,3 +113,11 @@ void add_booting_done_handler(void *data) if (sig_id[1] <= 0) _E("Failed to init dbus signal(%s).", SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED); } + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 6300c84..4376b57 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -750,25 +750,10 @@ out: return done; } -static int power_probe(void *data) -{ - disp_plgn = get_display_plugin(); - if (!disp_plgn) { - _E("Failed to get display plugin."); - return -1; - } - - return 0; -} - static void power_init(void *data) { int ret; - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - /* init dbus interface */ ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_POWEROFF, &dbus_interface); if (ret < 0) @@ -791,9 +776,16 @@ static void power_init(void *data) static const struct device_ops power_device_ops = { DECLARE_NAME_LEN(POWER_OPS_NAME), - .probe = power_probe, .init = power_init, .execute = power_execute, }; DEVICE_OPS_REGISTER(&power_device_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/src/time/time-handler.c b/src/time/time-handler.c index 0d8d2ff..bac2374 100644 --- a/src/time/time-handler.c +++ b/src/time/time-handler.c @@ -387,16 +387,6 @@ out: return 0; } -static int time_probe(void *data) -{ - disp_plgn = get_display_plugin(); - if (!disp_plgn) { - _E("Failed to get display plugin."); - return -1; - } - return 0; -} - static void time_init(void *data) { int ret; @@ -416,8 +406,15 @@ static void time_init(void *data) static const struct device_ops time_device_ops = { .name = "time", - .probe = time_probe, .init = time_init, }; DEVICE_OPS_REGISTER(&time_device_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/src/touchscreen/touchscreen.c b/src/touchscreen/touchscreen.c index 2be7c1c..295503b 100644 --- a/src/touchscreen/touchscreen.c +++ b/src/touchscreen/touchscreen.c @@ -103,12 +103,6 @@ static int touchscreen_probe(void *data) int ret; struct hw_info *info; - disp_plgn = get_display_plugin(); - if (!disp_plgn) { - _E("Failed to get display plugin."); - return -1; - } - if (touchscreen_dev) return 0; @@ -366,3 +360,10 @@ static const struct device_ops touchscreen_device_ops = { DEVICE_OPS_REGISTER(&touchscreen_device_ops) +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/src/usb/usb.c b/src/usb/usb.c index b82534d..691d0c3 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -450,10 +450,6 @@ static void usb_init(void *data) { int ret; - disp_plgn = get_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin."); - usb_state_retrieve_selected_mode(); ret = usb_probe(); @@ -501,3 +497,11 @@ static struct extcon_ops extcon_usb_ops = { }; EXTCON_OPS_REGISTER(extcon_usb_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 12f8d06..fd076fe 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -1128,19 +1128,6 @@ static int booting_done(void *data) return 0; } -static int usbhost_probe(void *data) -{ - if (!disp_plgn) - disp_plgn = get_display_plugin(); - - if (!disp_plgn) { - _E("Failed to get display plugin."); - return -1; - } - - return 0; -} - static void usbhost_init(void *data) { int ret; @@ -1195,22 +1182,12 @@ static void usbhost_exit(void *data) static const struct device_ops usbhost_device_ops = { .name = "usbhost", - .probe = usbhost_probe, .init = usbhost_init, .exit = usbhost_exit, }; DEVICE_OPS_REGISTER(&usbhost_device_ops) -static void extcon_usbhost_init() -{ - if (!disp_plgn) - disp_plgn = get_display_plugin(); - - if (!disp_plgn) - _E("Failed to get display plugin."); -} - static int extcon_usbhost_state_changed(int status) { if (status == USBHOST_DISCONNECTED) { @@ -1227,8 +1204,15 @@ static int extcon_usbhost_state_changed(int status) static struct extcon_ops extcon_usbhost_ops = { .name = EXTCON_CABLE_USB_HOST, - .init = extcon_usbhost_init, .update = extcon_usbhost_state_changed, }; EXTCON_OPS_REGISTER(extcon_usbhost_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_display_plugin(); + if (!disp_plgn) { + _E("Failed to get display plugin."); + } +} -- 2.7.4 From 2d618a9afdf5910ff640fcd5c0dcb94bb3233e82 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 15 Jul 2020 18:22:28 +0900 Subject: [PATCH 09/16] Change backlight_ops static Change-Id: I8d958fc084a74e6272f470bf81a7f1a342c10492 Signed-off-by: Youngjae Cho --- plugins/iot/display/core.c | 73 ++++++++++++---------- plugins/iot/display/device-interface.c | 70 +++++++++++---------- plugins/iot/display/key-filter.c | 15 +++-- plugins/mobile/display/core.c | 67 +++++++++++--------- plugins/mobile/display/device-interface.c | 70 +++++++++++---------- plugins/mobile/display/key-filter.c | 21 ++++--- plugins/tv/display/core.c | 67 +++++++++++--------- plugins/tv/display/device-interface.c | 70 +++++++++++---------- plugins/tv/display/key-filter.c | 15 +++-- plugins/tv/display/state-tv.c | 13 ++-- .../wearable/display/auto-brightness-sensorhub.c | 49 ++++++++------- plugins/wearable/display/core.c | 68 +++++++++++--------- plugins/wearable/display/device-interface.c | 72 ++++++++++----------- plugins/wearable/display/display-handler.c | 14 ++++- plugins/wearable/display/enhance.c | 10 ++- plugins/wearable/display/key-filter.c | 15 +++-- plugins/wearable/display/lbm.c | 24 ++++--- plugins/wearable/display/powersaver.c | 13 +++- plugins/wearable/display/swim.c | 7 ++- src/display/ambient-mode.c | 11 +++- src/display/auto-brightness.c | 17 +++-- src/display/device-interface.h | 2 +- src/display/display-dbus.c | 43 +++++++------ src/display/display-lock.c | 10 ++- src/touchscreen/touchscreen.c | 18 ++++-- 25 files changed, 494 insertions(+), 360 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 0fe3a8a..2ed514c 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -94,7 +94,7 @@ extern int get_charging_status(int *val); extern void init_save_userlock(void); static struct display_plugin *disp_plgn; - +static struct _backlight_ops *backlight_ops; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -319,7 +319,7 @@ static gboolean late_transit_on(void *data) g_source_remove(transit_timer); transit_timer = 0; - backlight_ops.transit_state(DPMS_ON); + backlight_ops->transit_state(DPMS_ON); return G_SOURCE_REMOVE; } @@ -346,7 +346,7 @@ void lcd_on_procedure(int state, enum device_flags flag) _I("[lcdstep] 0x%lx", 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); } @@ -358,9 +358,9 @@ void lcd_on_procedure(int state, enum device_flags flag) if (!(flags & LCD_PHASED_TRANSIT_MODE)) { /* Update brightness level */ if (state == LCD_DIM) - backlight_ops.dim(); + backlight_ops->dim(); else if (state == LCD_NORMAL) - backlight_ops.update(); + backlight_ops->update(); } if (state == LCD_NORMAL) @@ -445,7 +445,7 @@ inline void lcd_off_procedure(enum device_flags flag) } if (flags & LCD_PHASED_TRANSIT_MODE) - backlight_ops.transit_state(DPMS_OFF); + backlight_ops->transit_state(DPMS_OFF); DD_LIST_FOREACH(lcdon_ops, l, ops) ops->stop(flags); @@ -717,7 +717,7 @@ void lcd_on_direct(enum device_flags flags) static inline bool check_lcd_is_on(void) { - if (backlight_ops.get_lcd_power() != DPMS_ON) + if (backlight_ops->get_lcd_power() != DPMS_ON) return false; return true; @@ -790,7 +790,7 @@ int custom_lcdoff(enum device_flags flag) } _I("custom lcd off by flag(%d)", flag); - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(flag); if (set_custom_lcdon_timeout(0) == true) @@ -878,7 +878,7 @@ int display_off_by_reason(const char *reason) } _I("platform lcd off by %s", reason); - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(flag); /* state transition */ @@ -928,7 +928,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_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_EVENT); if (set_custom_lcdon_timeout(0)) update_display_time(); @@ -1541,7 +1541,7 @@ static int default_action(int timeout) if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) check_lock_screen(); else if (get_pm_old_state() == S_LCDDIM) - backlight_ops.update(); + backlight_ops->update(); if (check_lcd_is_on() == false) lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); @@ -1549,10 +1549,10 @@ static int default_action(int timeout) case S_LCDDIM: if ((get_pm_old_state() == S_NORMAL) && - backlight_ops.get_custom_status()) - backlight_ops.save_custom_brightness(); + backlight_ops->get_custom_status()) + backlight_ops->save_custom_brightness(); /* lcd dim state : dim the brightness */ - backlight_ops.dim(); + backlight_ops->dim(); if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) lcd_on_procedure(LCD_DIM, NORMAL_MODE); @@ -1562,11 +1562,11 @@ static int default_action(int timeout) if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { stop_lock_timer(); /* lcd off state : turn off the backlight */ - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); } - if (backlight_ops.get_lcd_power() == DPMS_ON + if (backlight_ops->get_lcd_power() == DPMS_ON || lcd_paneloff_mode) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); break; @@ -1575,7 +1575,7 @@ static int default_action(int timeout) if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) stop_lock_timer(); - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); if (!pm_get_power_lock_support()) { @@ -1677,7 +1677,7 @@ static void default_saving_mode(int onoff) clear_pm_status_flag(PWRSV_FLAG); if (get_pm_cur_state() == S_NORMAL) - backlight_ops.update(); + backlight_ops->update(); } static int poll_callback(int condition, PMMsg *data) @@ -1775,7 +1775,7 @@ static int update_setting(int key_idx, int val) _I("Brightness changed in low battery," "escape dim state."); } - backlight_ops.set_default_brt(val); + backlight_ops->set_default_brt(val); break; case SETTING_LOCK_SCREEN: set_lock_screen_state(val); @@ -1787,7 +1787,7 @@ static int update_setting(int key_idx, int val) /* LCD on if lock screen show before waiting time */ if ((get_pm_cur_state() == S_NORMAL) && val == VCONFKEY_IDLE_LOCK && - backlight_ops.get_lcd_power() != DPMS_ON && + backlight_ops->get_lcd_power() != DPMS_ON && is_lcdon_blocked() == LCDON_BLOCK_NONE) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); stop_lock_timer(); @@ -1814,9 +1814,9 @@ static int update_setting(int key_idx, int val) break; case SETTING_POWER_CUSTOM_BRIGHTNESS: if (val == VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON) - backlight_ops.set_custom_status(true); + backlight_ops->set_custom_status(true); else - backlight_ops.set_custom_status(false); + backlight_ops->set_custom_status(false); break; default: @@ -1849,8 +1849,8 @@ static void check_seed_status(void) tmp = brt; } _I("Set brightness(%d) from setting app.", tmp); - backlight_ops.set_default_brt(tmp); - backlight_ops.set_brightness(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) { @@ -2063,8 +2063,8 @@ static int battery_health_changed(void *data) set_pm_status_flag(DIMSTAY_FLAG); } - if (backlight_ops.get_lcd_power() == DPMS_ON) - backlight_ops.update(); + if (backlight_ops->get_lcd_power() == DPMS_ON) + backlight_ops->update(); return 0; } @@ -2225,8 +2225,8 @@ static void esd_action(void) if (!check_default(touchscreen_ops)) touchscreen_ops->stop(NORMAL_MODE); - backlight_ops.off(NORMAL_MODE); - backlight_ops.on(NORMAL_MODE); + backlight_ops->off(NORMAL_MODE); + backlight_ops->on(NORMAL_MODE); if (!check_default(touchscreen_ops)) touchscreen_ops->start(NORMAL_MODE); } @@ -2291,6 +2291,11 @@ static void display_init(void *data) if (display_conf.timeout_enable) get_lcd_timeout_from_settings(); ret = init_sysfs(flags); + backlight_ops = get_backlight_ops(); + if (!backlight_ops) { + _E("Failed to get backlight operator."); + ret = -1; + } break; case INIT_POLL: _I("input init"); @@ -2319,7 +2324,7 @@ static void display_init(void *data) check_seed_status(); /* In smd test, TSP should be turned off if display panel is not existed. */ - if (backlight_ops.get_lcd_power() == -ENOENT) { + if (backlight_ops->get_lcd_power() == -ENOENT) { _I("Display panel is not existed."); lcd_direct_control(DPMS_OFF, NORMAL_MODE); exit_lcd_operation(); @@ -2440,10 +2445,10 @@ static int display_start(enum device_flags flags) if (flags & NORMAL_MODE) { if (flags & LCD_PANEL_OFF_MODE) /* standby on */ - backlight_ops.standby(true); + backlight_ops->standby(true); else /* normal lcd on */ - backlight_ops.on(flags); + backlight_ops->on(flags); return 0; } @@ -2467,7 +2472,7 @@ static int display_stop(enum device_flags flags) { /* NORMAL MODE */ if (flags & NORMAL_MODE || flags & FORCE_OFF_MODE) { - backlight_ops.off(flags); + backlight_ops->off(flags); return 0; } @@ -2507,6 +2512,10 @@ static void __CONSTRUCTOR__ initialize(void) if (!disp_plgn) { _E("Failed to get display plugin."); } + + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); } /** * @} diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index db92d76..49c9172 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -44,6 +44,7 @@ #include "device-node.h" #include "display/display-dpms.h" #include "display/display.h" +#include "display/display-lock.h" #define TOUCH_ON 1 #define TOUCH_OFF 0 @@ -67,8 +68,7 @@ #define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" -struct _backlight_ops backlight_ops; - +static struct _backlight_ops backlight_ops; static bool custom_status; static int custom_brightness; static int force_brightness; @@ -77,6 +77,11 @@ static int dpms_running_state = DPMS_SETTING_DONE; static struct display_device *display_dev; static guint release_timer; +inline struct _backlight_ops *get_backlight_ops(void) +{ + return &backlight_ops; +} + struct display_device *display_dev_get(void) { return display_dev; @@ -722,36 +727,35 @@ static void restore_brightness_func(void) backlight_ops.transit_brt = change_brightness; } -static void _init_ops(void) -{ - backlight_ops.off = backlight_off; - backlight_ops.dim = backlight_dim; - backlight_ops.on = backlight_on; - 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; - backlight_ops.save_custom_brightness = save_custom_brightness; - backlight_ops.custom_update = custom_backlight_update; - 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; -} +static struct _backlight_ops backlight_ops = { + .off = backlight_off, + .dim = backlight_dim, + .on = backlight_on, + .update = backlight_update, + .standby = backlight_standby, + .set_default_brt = set_default_brt, + .get_default_brt = get_default_brt, + .get_lcd_power = get_lcd_power, + .set_custom_status = set_custom_status, + .get_custom_status = get_custom_status, + .save_custom_brightness = save_custom_brightness, + .custom_update = custom_backlight_update, + .set_force_brightness = set_force_brightness, + .set_brightness = set_brightness, + .get_brightness = get_brightness, + .restore_brightness_func = restore_brightness_func, + .get_brightness_by_light_sensor = get_brightness_by_light_sensor, + .get_image_effect = get_image_effect, + .set_image_effect = set_image_effect, + .get_panel_mode = get_panel_mode, + .set_panel_mode = set_panel_mode, + .get_frame_rate = get_frame_rate, + .set_frame_rate = set_frame_rate, + .transit_state = backlight_transit_state, + .transit_brt = change_brightness, + .blink = blink, + .release_blink = release_blink, +}; int display_service_load(void) { @@ -808,8 +812,6 @@ int is_lcdon_blocked(void) int init_sysfs(unsigned int flags) { - _init_ops(); - register_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 186a115..d8d4df3 100644 --- a/plugins/iot/display/key-filter.c +++ b/plugins/iot/display/key-filter.c @@ -91,6 +91,7 @@ enum combination_process { }; static struct display_plugin *disp_plgn; +static struct _backlight_ops *backlight_ops; static struct timeval pressed_time; static guint longkey_timeout_id = 0; static guint longkey_restore_id = 0; @@ -113,8 +114,8 @@ static inline int current_state_in_on(void) static inline void restore_custom_brightness(void) { if ((get_pm_cur_state() == S_LCDDIM) && - backlight_ops.get_custom_status()) - backlight_ops.custom_update(); + backlight_ops->get_custom_status()) + backlight_ops->custom_update(); } static void pwroff_popup(void) @@ -208,7 +209,7 @@ static inline bool switch_on_lcd(enum device_flags flags) if (current_state_in_on()) return false; - if (backlight_ops.get_lcd_power() == DPMS_ON) { + if (backlight_ops->get_lcd_power() == DPMS_ON) { if (ambient_get_state() == false) return false; } @@ -228,7 +229,7 @@ static inline void switch_off_lcd(void) if (!current_state_in_on()) return; - if (backlight_ops.get_lcd_power() == DPMS_OFF) + if (backlight_ops->get_lcd_power() == DPMS_OFF) return; broadcast_lcdoff_by_powerkey(); @@ -355,7 +356,7 @@ static int decide_lcdoff(void) { /* It's not needed if it's already LCD off state */ if (!current_state_in_on() && - backlight_ops.get_lcd_power() != DPMS_ON) + backlight_ops->get_lcd_power() != DPMS_ON) return false; /* @@ -797,4 +798,8 @@ static void __CONSTRUCTOR__ initialize(void) if (!disp_plgn) { _E("Failed to get display plugin."); } + + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); } diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 80cef01..e9cc44c 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -96,6 +96,7 @@ extern int get_charging_status(int *val); extern void init_save_userlock(void); static struct display_plugin *disp_plgn; +static struct _backlight_ops *backlight_ops; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -326,7 +327,7 @@ static gboolean late_transit_on(void *data) g_source_remove(transit_timer); transit_timer = 0; - backlight_ops.transit_state(DPMS_ON); + backlight_ops->transit_state(DPMS_ON); return G_SOURCE_REMOVE; } @@ -353,7 +354,7 @@ void lcd_on_procedure(int state, enum device_flags flag) _I("[lcdstep] 0x%lx", 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); } @@ -365,9 +366,9 @@ void lcd_on_procedure(int state, enum device_flags flag) if (!(flags & LCD_PHASED_TRANSIT_MODE)) { /* Update brightness level */ if (state == LCD_DIM) - backlight_ops.dim(); + backlight_ops->dim(); else if (state == LCD_NORMAL) - backlight_ops.update(); + backlight_ops->update(); } if (state == LCD_NORMAL) @@ -452,7 +453,7 @@ inline void lcd_off_procedure(enum device_flags flag) } if (flags & LCD_PHASED_TRANSIT_MODE) - backlight_ops.transit_state(DPMS_OFF); + backlight_ops->transit_state(DPMS_OFF); DD_LIST_FOREACH(lcdon_ops, l, ops) ops->stop(flags); @@ -724,7 +725,7 @@ void lcd_on_direct(enum device_flags flags) static inline bool check_lcd_is_on(void) { - if (backlight_ops.get_lcd_power() != DPMS_ON) + if (backlight_ops->get_lcd_power() != DPMS_ON) return false; return true; @@ -797,7 +798,7 @@ int custom_lcdoff(enum device_flags flag) } _I("custom lcd off by flag(%d)", flag); - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(flag); if (set_custom_lcdon_timeout(0) == true) @@ -885,7 +886,7 @@ int display_off_by_reason(const char *reason) } _I("platform lcd off by %s", reason); - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(flag); /* state transition */ @@ -935,7 +936,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_ON) { + if (backlight_ops->get_lcd_power() == DPMS_ON) { if (get_proximity_state() == SENSOR_PROXIMITY_NEAR) lcd_off_procedure(LCD_OFF_BY_PROXIMITY); else @@ -1551,7 +1552,7 @@ static int default_action(int timeout) if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) check_lock_screen(); else if (get_pm_old_state() == S_LCDDIM) - backlight_ops.update(); + backlight_ops->update(); if (check_lcd_is_on() == false) lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); @@ -1559,10 +1560,10 @@ static int default_action(int timeout) case S_LCDDIM: if ((get_pm_old_state() == S_NORMAL) && - backlight_ops.get_custom_status()) - backlight_ops.save_custom_brightness(); + backlight_ops->get_custom_status()) + backlight_ops->save_custom_brightness(); /* lcd dim state : dim the brightness */ - backlight_ops.dim(); + backlight_ops->dim(); if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) lcd_on_procedure(LCD_DIM, NORMAL_MODE); @@ -1572,11 +1573,11 @@ static int default_action(int timeout) if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { stop_lock_timer(); /* lcd off state : turn off the backlight */ - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); } - if (backlight_ops.get_lcd_power() == DPMS_ON + if (backlight_ops->get_lcd_power() == DPMS_ON || lcd_paneloff_mode) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); break; @@ -1585,7 +1586,7 @@ static int default_action(int timeout) if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) stop_lock_timer(); - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); if (!pm_get_power_lock_support()) { @@ -1687,7 +1688,7 @@ static void default_saving_mode(int onoff) clear_pm_status_flag(PWRSV_FLAG); if (get_pm_cur_state() == S_NORMAL) - backlight_ops.update(); + backlight_ops->update(); } static int poll_callback(int condition, PMMsg *data) @@ -1785,7 +1786,7 @@ static int update_setting(int key_idx, int val) _I("Brightness changed in low battery," "escape dim state."); } - backlight_ops.set_default_brt(val); + backlight_ops->set_default_brt(val); break; case SETTING_LOCK_SCREEN: set_lock_screen_state(val); @@ -1797,7 +1798,7 @@ static int update_setting(int key_idx, int val) /* LCD on if lock screen show before waiting time */ if ((get_pm_cur_state() == S_NORMAL) && val == VCONFKEY_IDLE_LOCK && - backlight_ops.get_lcd_power() != DPMS_ON && + backlight_ops->get_lcd_power() != DPMS_ON && is_lcdon_blocked() == LCDON_BLOCK_NONE) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); stop_lock_timer(); @@ -1824,9 +1825,9 @@ static int update_setting(int key_idx, int val) break; case SETTING_POWER_CUSTOM_BRIGHTNESS: if (val == VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON) - backlight_ops.set_custom_status(true); + backlight_ops->set_custom_status(true); else - backlight_ops.set_custom_status(false); + backlight_ops->set_custom_status(false); break; default: @@ -1859,8 +1860,8 @@ static void check_seed_status(void) tmp = brt; } _I("Set brightness(%d) from setting app.", tmp); - backlight_ops.set_default_brt(tmp); - backlight_ops.set_brightness(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) { @@ -2073,8 +2074,8 @@ static int battery_health_changed(void *data) set_pm_status_flag(DIMSTAY_FLAG); } - if (backlight_ops.get_lcd_power() == DPMS_ON) - backlight_ops.update(); + if (backlight_ops->get_lcd_power() == DPMS_ON) + backlight_ops->update(); return 0; } @@ -2235,8 +2236,8 @@ static void esd_action(void) if (!check_default(touchscreen_ops)) touchscreen_ops->stop(NORMAL_MODE); - backlight_ops.off(NORMAL_MODE); - backlight_ops.on(NORMAL_MODE); + backlight_ops->off(NORMAL_MODE); + backlight_ops->on(NORMAL_MODE); if (!check_default(touchscreen_ops)) touchscreen_ops->start(NORMAL_MODE); } @@ -2329,7 +2330,7 @@ static void display_init(void *data) check_seed_status(); /* In smd test, TSP should be turned off if display panel is not existed. */ - if (backlight_ops.get_lcd_power() == -ENOENT) { + if (backlight_ops->get_lcd_power() == -ENOENT) { _I("Display panel is not existed."); lcd_direct_control(DPMS_OFF, NORMAL_MODE); exit_lcd_operation(); @@ -2453,10 +2454,10 @@ static int display_start(enum device_flags flags) if (flags & NORMAL_MODE) { if (flags & LCD_PANEL_OFF_MODE) /* standby on */ - backlight_ops.standby(true); + backlight_ops->standby(true); else /* normal lcd on */ - backlight_ops.on(flags); + backlight_ops->on(flags); FIND_DISPLAY(enhance_ops, "enhance"); if (enhance_ops && enhance_ops->func) enhance_ops->func(RESTORE_ENHANCE_OUTDOOR, &on); @@ -2482,7 +2483,7 @@ static int display_stop(enum device_flags flags) { /* NORMAL MODE */ if (flags & NORMAL_MODE || flags & FORCE_OFF_MODE) { - backlight_ops.off(flags); + backlight_ops->off(flags); return 0; } @@ -2522,6 +2523,10 @@ static void __CONSTRUCTOR__ initialize(void) if (!disp_plgn) { _E("Failed to get display plugin."); } + + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); } /** * @} diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 8d53e2e..054e181 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -43,6 +43,7 @@ #include "device-node.h" #include "display/display-dpms.h" #include "display/display.h" +#include "display/display-lock.h" #include "power/boot.h" #include "power/power-control.h" @@ -66,8 +67,7 @@ #define PALM_STR "palm" #define UNKNOWN_STR "unknown" -struct _backlight_ops backlight_ops; - +static struct _backlight_ops backlight_ops; static bool custom_status; static int custom_brightness; static int force_brightness; @@ -76,6 +76,11 @@ static int dpms_running_state = DPMS_SETTING_DONE; static struct display_device *display_dev; static guint release_timer; +inline struct _backlight_ops *get_backlight_ops(void) +{ + return &backlight_ops; +} + struct display_device *display_dev_get(void) { return display_dev; @@ -721,36 +726,35 @@ static void restore_brightness_func(void) backlight_ops.transit_brt = change_brightness; } -static void _init_ops(void) -{ - backlight_ops.off = backlight_off; - backlight_ops.dim = backlight_dim; - backlight_ops.on = backlight_on; - 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; - backlight_ops.save_custom_brightness = save_custom_brightness; - backlight_ops.custom_update = custom_backlight_update; - 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; -} +static struct _backlight_ops backlight_ops = { + .off = backlight_off, + .dim = backlight_dim, + .on = backlight_on, + .update = backlight_update, + .standby = backlight_standby, + .set_default_brt = set_default_brt, + .get_default_brt = get_default_brt, + .get_lcd_power = get_lcd_power, + .set_custom_status = set_custom_status, + .get_custom_status = get_custom_status, + .save_custom_brightness = save_custom_brightness, + .custom_update = custom_backlight_update, + .set_force_brightness = set_force_brightness, + .set_brightness = set_brightness, + .get_brightness = get_brightness, + .restore_brightness_func = restore_brightness_func, + .get_brightness_by_light_sensor = get_brightness_by_light_sensor, + .get_image_effect = get_image_effect, + .set_image_effect = set_image_effect, + .get_panel_mode = get_panel_mode, + .set_panel_mode = set_panel_mode, + .get_frame_rate = get_frame_rate, + .set_frame_rate = set_frame_rate, + .transit_state = backlight_transit_state, + .transit_brt = change_brightness, + .blink = blink, + .release_blink = release_blink, +}; int display_service_load(void) { @@ -822,8 +826,6 @@ int is_lcdon_blocked(void) int init_sysfs(unsigned int flags) { - _init_ops(); - register_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index bd939ff..b5fdf71 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -91,6 +91,7 @@ enum combination_process { }; static struct display_plugin *disp_plgn; +static struct _backlight_ops *backlight_ops; static struct timeval pressed_time; static guint longkey_timeout_id = 0; static guint longkey_restore_id = 0; @@ -113,8 +114,8 @@ static inline int current_state_in_on(void) static inline void restore_custom_brightness(void) { if ((get_pm_cur_state() == S_LCDDIM) && - backlight_ops.get_custom_status()) - backlight_ops.custom_update(); + backlight_ops->get_custom_status()) + backlight_ops->custom_update(); } static void longkey_pressed(void) @@ -197,7 +198,7 @@ static inline bool switch_on_lcd(enum device_flags flags) if (current_state_in_on()) return false; - if (backlight_ops.get_lcd_power() == DPMS_ON) { + if (backlight_ops->get_lcd_power() == DPMS_ON) { if (ambient_get_state() == false) return false; } @@ -217,7 +218,7 @@ static inline void switch_off_lcd(void) if (!current_state_in_on()) return; - if (backlight_ops.get_lcd_power() == DPMS_OFF) + if (backlight_ops->get_lcd_power() == DPMS_OFF) return; broadcast_lcdoff_by_powerkey(); @@ -344,7 +345,7 @@ static int decide_lcdoff(void) { /* It's not needed if it's already LCD off state */ if (!current_state_in_on() && - backlight_ops.get_lcd_power() != DPMS_ON) + backlight_ops->get_lcd_power() != DPMS_ON) return false; /* @@ -407,7 +408,7 @@ static bool key_check_display_on(void) if (current_state_in_on()) return false; - if (backlight_ops.get_lcd_power() == DPMS_ON) { + if (backlight_ops->get_lcd_power() == DPMS_ON) { _W("display power was on"); return false; } @@ -421,7 +422,7 @@ static gboolean display_on_cb(void *data) return G_SOURCE_REMOVE; displayon_by_powerkey_timeout_id = 0; - if (backlight_ops.get_lcd_power() != DPMS_ON || + 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); @@ -490,7 +491,7 @@ static int process_power_key(struct input_event *pinput) ignore = true; if (!displayon_by_powerkey_timeout_id && - backlight_ops.get_lcd_power() != DPMS_ON && + backlight_ops->get_lcd_power() != DPMS_ON && key_combination != COMBINATION_TORCH) { displayon_by_powerkey_timeout_id = g_timeout_add( 100, @@ -824,4 +825,8 @@ static void __CONSTRUCTOR__ initialize(void) if (!disp_plgn) { _E("Failed to get display plugin."); } + + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); } diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index f997dd1..fbf58d0 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -94,6 +94,7 @@ extern int get_charging_status(int *val); extern void init_save_userlock(void); static struct display_plugin *disp_plgn; +static struct _backlight_ops *backlight_ops; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -319,7 +320,7 @@ static gboolean late_transit_on(void *data) g_source_remove(transit_timer); transit_timer = 0; - backlight_ops.transit_state(DPMS_ON); + backlight_ops->transit_state(DPMS_ON); return G_SOURCE_REMOVE; } @@ -346,7 +347,7 @@ void lcd_on_procedure(int state, enum device_flags flag) _I("[lcdstep] 0x%lx", 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); } @@ -358,9 +359,9 @@ void lcd_on_procedure(int state, enum device_flags flag) if (!(flags & LCD_PHASED_TRANSIT_MODE)) { /* Update brightness level */ if (state == LCD_DIM) - backlight_ops.dim(); + backlight_ops->dim(); else if (state == LCD_NORMAL) - backlight_ops.update(); + backlight_ops->update(); } if (state == LCD_NORMAL) @@ -445,7 +446,7 @@ inline void lcd_off_procedure(enum device_flags flag) } if (flags & LCD_PHASED_TRANSIT_MODE) - backlight_ops.transit_state(DPMS_OFF); + backlight_ops->transit_state(DPMS_OFF); DD_LIST_FOREACH(lcdon_ops, l, ops) ops->stop(flags); @@ -717,7 +718,7 @@ void lcd_on_direct(enum device_flags flags) static inline bool check_lcd_is_on(void) { - if (backlight_ops.get_lcd_power() != DPMS_ON) + if (backlight_ops->get_lcd_power() != DPMS_ON) return false; return true; @@ -790,7 +791,7 @@ int custom_lcdoff(enum device_flags flag) } _I("custom lcd off by flag(%d)", flag); - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(flag); if (set_custom_lcdon_timeout(0) == true) @@ -878,7 +879,7 @@ int display_off_by_reason(const char *reason) } _I("platform lcd off by %s", reason); - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(flag); /* state transition */ @@ -928,7 +929,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_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_EVENT); if (set_custom_lcdon_timeout(0)) update_display_time(); @@ -1541,7 +1542,7 @@ static int default_action(int timeout) if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) check_lock_screen(); else if (get_pm_old_state() == S_LCDDIM) - backlight_ops.update(); + backlight_ops->update(); if (check_lcd_is_on() == false) lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); @@ -1549,10 +1550,10 @@ static int default_action(int timeout) case S_LCDDIM: if ((get_pm_old_state() == S_NORMAL) && - backlight_ops.get_custom_status()) - backlight_ops.save_custom_brightness(); + backlight_ops->get_custom_status()) + backlight_ops->save_custom_brightness(); /* lcd dim state : dim the brightness */ - backlight_ops.dim(); + backlight_ops->dim(); if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) lcd_on_procedure(LCD_DIM, NORMAL_MODE); @@ -1562,11 +1563,11 @@ static int default_action(int timeout) if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { stop_lock_timer(); /* lcd off state : turn off the backlight */ - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); } - if (backlight_ops.get_lcd_power() == DPMS_ON + if (backlight_ops->get_lcd_power() == DPMS_ON || lcd_paneloff_mode) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); break; @@ -1575,7 +1576,7 @@ static int default_action(int timeout) if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) stop_lock_timer(); - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); if (!pm_get_power_lock_support()) { @@ -1677,7 +1678,7 @@ static void default_saving_mode(int onoff) clear_pm_status_flag(PWRSV_FLAG); if (get_pm_cur_state() == S_NORMAL) - backlight_ops.update(); + backlight_ops->update(); } static int poll_callback(int condition, PMMsg *data) @@ -1775,7 +1776,7 @@ static int update_setting(int key_idx, int val) _I("Brightness changed in low battery," "escape dim state."); } - backlight_ops.set_default_brt(val); + backlight_ops->set_default_brt(val); break; case SETTING_LOCK_SCREEN: set_lock_screen_state(val); @@ -1787,7 +1788,7 @@ static int update_setting(int key_idx, int val) /* LCD on if lock screen show before waiting time */ if ((get_pm_cur_state() == S_NORMAL) && val == VCONFKEY_IDLE_LOCK && - backlight_ops.get_lcd_power() != DPMS_ON && + backlight_ops->get_lcd_power() != DPMS_ON && is_lcdon_blocked() == LCDON_BLOCK_NONE) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); stop_lock_timer(); @@ -1814,9 +1815,9 @@ static int update_setting(int key_idx, int val) break; case SETTING_POWER_CUSTOM_BRIGHTNESS: if (val == VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON) - backlight_ops.set_custom_status(true); + backlight_ops->set_custom_status(true); else - backlight_ops.set_custom_status(false); + backlight_ops->set_custom_status(false); break; default: @@ -1849,8 +1850,8 @@ static void check_seed_status(void) tmp = brt; } _I("Set brightness(%d) from setting app.", tmp); - backlight_ops.set_default_brt(tmp); - backlight_ops.set_brightness(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) { @@ -2063,8 +2064,8 @@ static int battery_health_changed(void *data) set_pm_status_flag(DIMSTAY_FLAG); } - if (backlight_ops.get_lcd_power() == DPMS_ON) - backlight_ops.update(); + if (backlight_ops->get_lcd_power() == DPMS_ON) + backlight_ops->update(); return 0; } @@ -2226,8 +2227,8 @@ static void esd_action(void) if (!check_default(touchscreen_ops)) touchscreen_ops->stop(NORMAL_MODE); - backlight_ops.off(NORMAL_MODE); - backlight_ops.on(NORMAL_MODE); + backlight_ops->off(NORMAL_MODE); + backlight_ops->on(NORMAL_MODE); if (!check_default(touchscreen_ops)) touchscreen_ops->start(NORMAL_MODE); } @@ -2320,7 +2321,7 @@ static void display_init(void *data) check_seed_status(); /* In smd test, TSP should be turned off if display panel is not existed. */ - if (backlight_ops.get_lcd_power() == -ENOENT) { + if (backlight_ops->get_lcd_power() == -ENOENT) { _I("Display panel is not existed."); lcd_direct_control(DPMS_OFF, NORMAL_MODE); exit_lcd_operation(); @@ -2441,10 +2442,10 @@ static int display_start(enum device_flags flags) if (flags & NORMAL_MODE) { if (flags & LCD_PANEL_OFF_MODE) /* standby on */ - backlight_ops.standby(true); + backlight_ops->standby(true); else /* normal lcd on */ - backlight_ops.on(flags); + backlight_ops->on(flags); return 0; } @@ -2468,7 +2469,7 @@ static int display_stop(enum device_flags flags) { /* NORMAL MODE */ if (flags & NORMAL_MODE || flags & FORCE_OFF_MODE) { - backlight_ops.off(flags); + backlight_ops->off(flags); return 0; } @@ -2508,6 +2509,10 @@ static void __CONSTRUCTOR__ initialize(void) if (!disp_plgn) { _E("Failed to get display plugin."); } + + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); } /** * @} diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index ebaf569..28c4075 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -44,6 +44,7 @@ #include "display/display-dpms.h" #include "display/display.h" #include "power/power-control.h" +#include "display/display-lock.h" #define TOUCH_ON 1 #define TOUCH_OFF 0 @@ -67,8 +68,7 @@ #define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" -struct _backlight_ops backlight_ops; - +static struct _backlight_ops backlight_ops; static bool custom_status; static int custom_brightness; static int force_brightness; @@ -77,6 +77,11 @@ static int dpms_running_state = DPMS_SETTING_DONE; static struct display_device *display_dev; static guint release_timer; +inline struct _backlight_ops *get_backlight_ops(void) +{ + return &backlight_ops; +} + struct display_device *display_dev_get(void) { return display_dev; @@ -722,36 +727,35 @@ static void restore_brightness_func(void) backlight_ops.transit_brt = change_brightness; } -static void _init_ops(void) -{ - backlight_ops.off = backlight_off; - backlight_ops.dim = backlight_dim; - backlight_ops.on = backlight_on; - 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; - backlight_ops.save_custom_brightness = save_custom_brightness; - backlight_ops.custom_update = custom_backlight_update; - 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; -} +static struct _backlight_ops backlight_ops = { + .off = backlight_off, + .dim = backlight_dim, + .on = backlight_on, + .update = backlight_update, + .standby = backlight_standby, + .set_default_brt = set_default_brt, + .get_default_brt = get_default_brt, + .get_lcd_power = get_lcd_power, + .set_custom_status = set_custom_status, + .get_custom_status = get_custom_status, + .save_custom_brightness = save_custom_brightness, + .custom_update = custom_backlight_update, + .set_force_brightness = set_force_brightness, + .set_brightness = set_brightness, + .get_brightness = get_brightness, + .restore_brightness_func = restore_brightness_func, + .get_brightness_by_light_sensor = get_brightness_by_light_sensor, + .get_image_effect = get_image_effect, + .set_image_effect = set_image_effect, + .get_panel_mode = get_panel_mode, + .set_panel_mode = set_panel_mode, + .get_frame_rate = get_frame_rate, + .set_frame_rate = set_frame_rate, + .transit_state = backlight_transit_state, + .transit_brt = change_brightness, + .blink = blink, + .release_blink = release_blink, +}; int display_service_load(void) { @@ -809,8 +813,6 @@ int is_lcdon_blocked(void) int init_sysfs(unsigned int flags) { - _init_ops(); - register_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 3874dba..7abfd2f 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -91,6 +91,7 @@ enum combination_process { }; static struct display_plugin *disp_plgn; +static struct _backlight_ops *backlight_ops; static struct timeval pressed_time; static guint longkey_timeout_id = 0; static guint longkey_restore_id = 0; @@ -113,8 +114,8 @@ static inline int current_state_in_on(void) static inline void restore_custom_brightness(void) { if ((get_pm_cur_state() == S_LCDDIM) && - backlight_ops.get_custom_status()) - backlight_ops.custom_update(); + backlight_ops->get_custom_status()) + backlight_ops->custom_update(); } static void pwroff_popup(void) @@ -208,7 +209,7 @@ static inline bool switch_on_lcd(enum device_flags flags) if (current_state_in_on()) return false; - if (backlight_ops.get_lcd_power() == DPMS_ON) { + if (backlight_ops->get_lcd_power() == DPMS_ON) { if (ambient_get_state() == false) return false; } @@ -228,7 +229,7 @@ static inline void switch_off_lcd(void) if (!current_state_in_on()) return; - if (backlight_ops.get_lcd_power() == DPMS_OFF) + if (backlight_ops->get_lcd_power() == DPMS_OFF) return; broadcast_lcdoff_by_powerkey(); @@ -355,7 +356,7 @@ static int decide_lcdoff(void) { /* It's not needed if it's already LCD off state */ if (!current_state_in_on() && - backlight_ops.get_lcd_power() != DPMS_ON) + backlight_ops->get_lcd_power() != DPMS_ON) return false; /* @@ -791,4 +792,8 @@ static void __CONSTRUCTOR__ initialize(void) if (!disp_plgn) { _E("Failed to get display plugin."); } + + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); } diff --git a/plugins/tv/display/state-tv.c b/plugins/tv/display/state-tv.c index f8f1df1..0a86fde 100644 --- a/plugins/tv/display/state-tv.c +++ b/plugins/tv/display/state-tv.c @@ -43,6 +43,7 @@ #define SIGNAL_EARLY_WAKEUP "EarlyWakeUp" static struct display_plugin *disp_plgn; +static struct _backlight_ops *backlight_ops; static guint standby_timer; static int change_state(pid_t pid, int type, enum state_t st) @@ -178,7 +179,7 @@ static int lcdon_action(int timeout) /* TODO: post resume */ - backlight_ops.on(0); + backlight_ops->on(0); return 0; } @@ -246,7 +247,7 @@ static int lcdoff_action(int timeout) (get_pm_old_state() == S_LCDOFF)) return 0; - backlight_ops.off(0); + backlight_ops->off(0); return 0; } @@ -313,7 +314,7 @@ static int standby_post(void *data) if (ret < 0) _E("Failed to send dbus signal(%s)", SIGNAL_CHANGE_STATE); - backlight_ops.off(0); + backlight_ops->off(0); /* Set power */ @@ -347,7 +348,7 @@ static int standby_action(int timeout) (get_pm_cur_state() != S_SLEEP)) set_setting_pmstate(get_pm_cur_state()); - backlight_ops.off(0); + backlight_ops->off(0); standby_timer = g_timeout_add_seconds(0, standby_go_next_state, NULL); @@ -574,4 +575,8 @@ static void __CONSTRUCTOR__ initialize(void) if (!disp_plgn) { _E("Failed to get display plugin."); } + + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); } diff --git a/plugins/wearable/display/auto-brightness-sensorhub.c b/plugins/wearable/display/auto-brightness-sensorhub.c index 502c86f..c2e1773 100644 --- a/plugins/wearable/display/auto-brightness-sensorhub.c +++ b/plugins/wearable/display/auto-brightness-sensorhub.c @@ -37,12 +37,13 @@ #define LOWBATCAPACITY 5 static struct display_plugin *disp_plgn; +static struct _backlight_ops *backlight_ops; static int auto_brightness_state = SETTING_BRIGHTNESS_AUTOMATIC_OFF; static bool lbm, hbm, hold_brt, lowdim; static void change_brightness_transit(int start, int end) { - backlight_ops.transit_brt(start, end, + backlight_ops->transit_brt(start, end, display_conf.brightness_change_step); } @@ -86,8 +87,8 @@ static void set_brightness_level(int level) auto_brightness_control(BR_HBM_ON, BR_IMPLICIT); break; case SPECIFIC_MODE_OFF: - default_brightness = backlight_ops.get_default_brt(); - backlight_ops.get_brightness(¤t_brightness); + default_brightness = backlight_ops->get_default_brt(); + backlight_ops->get_brightness(¤t_brightness); /* Disable HBM, LBM */ auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); @@ -118,9 +119,9 @@ 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(); + 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) @@ -179,8 +180,8 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes int current_brightness; int ret; - default_brightness = backlight_ops.get_default_brt(); - backlight_ops.get_brightness(¤t_brightness); + default_brightness = backlight_ops->get_default_brt(); + backlight_ops->get_brightness(¤t_brightness); if (request == BR_LBM_ON) { if (!get_lbm_setting()) @@ -188,12 +189,12 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes if (!lbm && !hbm && !hold_brt && !lowdim) { change_brightness_transit(default_brightness, lbm_down_brt(default_brightness)); lbm_set_state(true); - backlight_ops.set_brightness(default_brightness); + backlight_ops->set_brightness(default_brightness); change_flag(&lbm, 1); } else if (!lbm && !hbm && !hold_brt && lowdim) { change_brightness_transit(current_brightness, lbm_down_brt(current_brightness)); lbm_set_state(true); - backlight_ops.set_brightness(current_brightness); + backlight_ops->set_brightness(current_brightness); change_flag(&lbm, 1); } else if (!lbm && !hbm && hold_brt) { change_flag(&lbm, 1); @@ -219,13 +220,13 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes lbm_set_state(false); change_brightness_transit(lbm_down_brt(current_brightness), set_brightness); } else { - backlight_ops.set_brightness(set_brightness); + backlight_ops->set_brightness(set_brightness); } change_flag(&hold_brt, 1); } else if (request == BR_LOWDIM_ON) { if (!lowdim) { if (!hbm && !hold_brt && (get_pm_cur_state() == S_NORMAL)) - backlight_ops.dim(); + backlight_ops->dim(); change_flag(&lowdim, 1); } } else if (request == BR_LBM_OFF) { @@ -239,9 +240,9 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes if (!lowdim) { change_brightness_transit(lbm_down_brt(default_brightness), default_brightness); - backlight_ops.set_brightness(default_brightness); + backlight_ops->set_brightness(default_brightness); } else { - backlight_ops.dim(); + backlight_ops->dim(); } } else if (lbm && hold_brt) { change_flag(&lbm, 0); @@ -264,25 +265,25 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes return 0; if (!lowdim) - backlight_ops.set_brightness(default_brightness); + backlight_ops->set_brightness(default_brightness); else - backlight_ops.dim(); + backlight_ops->dim(); } else if (lbm && hold_brt) { change_flag(&hold_brt, 0); if (!lowdim) { change_brightness_transit(current_brightness, lbm_down_brt(default_brightness)); lbm_set_state(true); - backlight_ops.set_brightness(default_brightness); + backlight_ops->set_brightness(default_brightness); } else { change_brightness_transit(current_brightness, lbm_down_brt(PM_DIM_BRIGHTNESS)); lbm_set_state(true); - backlight_ops.set_brightness(PM_DIM_BRIGHTNESS); + backlight_ops->set_brightness(PM_DIM_BRIGHTNESS); } } } else if (request == BR_LOWDIM_OFF) { if (lowdim) { if (!hbm && !hold_brt && (get_pm_cur_state() == S_NORMAL)) - backlight_ops.update(); + backlight_ops->update(); change_flag(&lowdim, 0); } } else if (request == BR_SET_BRIGHTNESS) { @@ -290,9 +291,9 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes lbm_set_state(true); change_flag(&lowdim, 0); change_flag(&hold_brt, 0); - backlight_ops.set_default_brt(set_brightness); + backlight_ops->set_default_brt(set_brightness); if (!hbm) { - ret = backlight_ops.set_brightness(set_brightness); + ret = backlight_ops->set_brightness(set_brightness); if (ret < 0) { _E("Failed to set brightness to %d.", set_brightness); return ret; @@ -332,7 +333,7 @@ int auto_brightness_restore(void) return 0; /* update to the default brightness */ - return backlight_ops.update(); + return backlight_ops->update(); } int prepare_level_handler(void) @@ -371,4 +372,8 @@ static void __CONSTRUCTOR__ initialize(void) if (!disp_plgn) { _E("Failed to get display plugin."); } + + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); } diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 60d1db2..ab576e4 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -101,6 +101,7 @@ extern int get_charging_status(int *val); extern void init_save_userlock(void); static struct display_plugin *disp_plgn; +static struct _backlight_ops *backlight_ops; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -336,7 +337,7 @@ static gboolean late_transit_on(void *data) g_source_remove(transit_timer); transit_timer = 0; - backlight_ops.transit_state(DPMS_ON); + backlight_ops->transit_state(DPMS_ON); return G_SOURCE_REMOVE; } @@ -372,7 +373,7 @@ void lcd_on_procedure(int state, enum device_flags flag) _I("[lcdstep] 0x%lx", 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); } @@ -384,9 +385,9 @@ void lcd_on_procedure(int state, enum device_flags flag) if (!(flags & LCD_PHASED_TRANSIT_MODE)) { /* Update brightness level */ if (state == LCD_DIM) - backlight_ops.dim(); + backlight_ops->dim(); else if (state == LCD_NORMAL) - backlight_ops.update(); + backlight_ops->update(); } if (state == LCD_NORMAL) @@ -471,7 +472,7 @@ inline void lcd_off_procedure(enum device_flags flag) } if (flags & LCD_PHASED_TRANSIT_MODE) - backlight_ops.transit_state(DPMS_OFF); + backlight_ops->transit_state(DPMS_OFF); DD_LIST_FOREACH(lcdon_ops, l, ops) ops->stop(flags); @@ -751,7 +752,7 @@ void lcd_on_direct(enum device_flags flags) static inline bool check_lcd_is_on(void) { - if (backlight_ops.get_lcd_power() != DPMS_ON) + if (backlight_ops->get_lcd_power() != DPMS_ON) return false; return true; @@ -852,7 +853,7 @@ int custom_lcdoff(enum device_flags flag) } _I("custom lcd off by flag(%d)", flag); - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(flag); if (set_custom_lcdon_timeout(0) == true) @@ -945,7 +946,7 @@ int display_off_by_reason(const char *reason) } _I("platform lcd off by %s", reason); - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(flag); /* state transition */ @@ -995,7 +996,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_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_EVENT); if (set_custom_lcdon_timeout(0)) update_display_time(); @@ -1628,7 +1629,7 @@ static int default_action(int timeout) if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) check_lock_screen(); else if (get_pm_old_state() == S_LCDDIM) - backlight_ops.update(); + backlight_ops->update(); if (check_lcd_is_on() == false) lcd_on_procedure(LCD_NORMAL, NORMAL_MODE); @@ -1636,10 +1637,10 @@ static int default_action(int timeout) case S_LCDDIM: if ((get_pm_old_state() == S_NORMAL) && - backlight_ops.get_custom_status()) - backlight_ops.save_custom_brightness(); + backlight_ops->get_custom_status()) + backlight_ops->save_custom_brightness(); /* lcd dim state : dim the brightness */ - backlight_ops.dim(); + backlight_ops->dim(); if ((get_pm_old_state() == S_LCDOFF) || (get_pm_old_state() == S_SLEEP)) lcd_on_procedure(LCD_DIM, NORMAL_MODE); @@ -1649,11 +1650,11 @@ static int default_action(int timeout) if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) { stop_lock_timer(); /* lcd off state : turn off the backlight */ - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); } - if (backlight_ops.get_lcd_power() == DPMS_ON + if (backlight_ops->get_lcd_power() == DPMS_ON || lcd_paneloff_mode) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); break; @@ -1662,7 +1663,7 @@ static int default_action(int timeout) if ((get_pm_old_state() != S_SLEEP) && (get_pm_old_state() != S_LCDOFF)) stop_lock_timer(); - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) lcd_off_procedure(LCD_OFF_BY_TIMEOUT); if (!pm_get_power_lock_support()) { @@ -1862,7 +1863,7 @@ static int update_setting(int key_idx, int val) _I("Brightness changed in low battery," "escape dim state."); } - backlight_ops.set_default_brt(val); + backlight_ops->set_default_brt(val); break; case SETTING_LOCK_SCREEN: set_lock_screen_state(val); @@ -1874,7 +1875,7 @@ static int update_setting(int key_idx, int val) /* LCD on if lock screen show before waiting time */ if ((get_pm_cur_state() == S_NORMAL) && val == VCONFKEY_IDLE_LOCK && - backlight_ops.get_lcd_power() != DPMS_ON && + backlight_ops->get_lcd_power() != DPMS_ON && is_lcdon_blocked() == LCDON_BLOCK_NONE) lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); stop_lock_timer(); @@ -1901,9 +1902,9 @@ static int update_setting(int key_idx, int val) break; case SETTING_POWER_CUSTOM_BRIGHTNESS: if (val == VCONFKEY_PM_CUSTOM_BRIGHTNESS_ON) - backlight_ops.set_custom_status(true); + backlight_ops->set_custom_status(true); else - backlight_ops.set_custom_status(false); + backlight_ops->set_custom_status(false); break; default: @@ -1936,8 +1937,8 @@ static void check_seed_status(void) tmp = brt; } _I("Set brightness(%d) from setting app.", tmp); - backlight_ops.set_default_brt(tmp); - backlight_ops.set_brightness(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) { @@ -2149,13 +2150,13 @@ static int battery_health_changed(void *data) if (health == HEALTH_GOOD) { clear_pm_status_flag(BATTERY_FLAG); clear_pm_status_flag(DIMSTAY_FLAG); - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) auto_brightness_restore(); } else if (health == HEALTH_LOW || health == HEALTH_HIGH || health == HEALTH_OVP) { set_pm_status_flag(BATTERY_FLAG); set_pm_status_flag(DIMSTAY_FLAG); - if (backlight_ops.get_lcd_power() == DPMS_ON) - backlight_ops.update(); + if (backlight_ops->get_lcd_power() == DPMS_ON) + backlight_ops->update(); } return 0; @@ -2317,8 +2318,8 @@ static void esd_action(void) if (!check_default(touchscreen_ops)) touchscreen_ops->stop(NORMAL_MODE); - backlight_ops.off(NORMAL_MODE); - backlight_ops.on(NORMAL_MODE); + backlight_ops->off(NORMAL_MODE); + backlight_ops->on(NORMAL_MODE); if (!check_default(touchscreen_ops)) touchscreen_ops->start(NORMAL_MODE); } @@ -2443,7 +2444,7 @@ static void display_init(void *data) check_seed_status(); /* In smd test, TSP should be turned off if display panel is not existed. */ - if (backlight_ops.get_lcd_power() == -ENOENT) { + if (backlight_ops->get_lcd_power() == -ENOENT) { _I("Display panel is not existed."); lcd_direct_control(DPMS_OFF, NORMAL_MODE); exit_lcd_operation(); @@ -2567,10 +2568,10 @@ static int display_start(enum device_flags flags) if (flags & NORMAL_MODE) { if (flags & LCD_PANEL_OFF_MODE) /* standby on */ - backlight_ops.standby(true); + backlight_ops->standby(true); else /* normal lcd on */ - backlight_ops.on(flags); + backlight_ops->on(flags); FIND_DISPLAY(enhance_ops, "enhance"); if (enhance_ops && enhance_ops->func) enhance_ops->func(RESTORE_ENHANCE_OUTDOOR, &on); @@ -2596,7 +2597,7 @@ static int display_stop(enum device_flags flags) { /* NORMAL MODE */ if (flags & NORMAL_MODE || flags & FORCE_OFF_MODE) { - backlight_ops.off(flags); + backlight_ops->off(flags); return 0; } @@ -2636,7 +2637,12 @@ static void __CONSTRUCTOR__ initialize(void) if (!disp_plgn) { _E("Failed to get display plugin."); } + + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); } + /** * @} */ diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 224ba65..c26937e 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -43,6 +43,7 @@ #include "device-node.h" #include "display/display-dpms.h" #include "display/display.h" +#include "display/display-lock.h" #include "battery-monitor.h" #include "battery/power-supply.h" #include "power/power-control.h" @@ -70,8 +71,8 @@ #define FREEZER_VITAL_WAKEUP_CGROUP "/sys/fs/cgroup/freezer/vital_wakeup/freezer.state" -struct _backlight_ops backlight_ops; +static struct _backlight_ops backlight_ops; static bool custom_status; static int custom_brightness; static int force_brightness; @@ -84,6 +85,11 @@ static int aod_normal_level = -1; static int aod_min_level = -1; static int aod_charging_level = -1; +inline struct _backlight_ops *get_backlight_ops(void) +{ + return &backlight_ops; +} + struct display_device *display_dev_get(void) { return display_dev; @@ -782,39 +788,37 @@ static void restore_brightness_func(void) backlight_ops.transit_brt = change_brightness; } -static void _init_ops(void) -{ - backlight_ops.off = backlight_off; - backlight_ops.dim = backlight_dim; - backlight_ops.on = backlight_on; - 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; - backlight_ops.save_custom_brightness = save_custom_brightness; - backlight_ops.custom_update = custom_backlight_update; - 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; - +static struct _backlight_ops backlight_ops = { + .off = backlight_off, + .dim = backlight_dim, + .on = backlight_on, + .update = backlight_update, + .standby = backlight_standby, + .set_default_brt = set_default_brt, + .get_default_brt = get_default_brt, + .get_lcd_power = get_lcd_power, + .set_custom_status = set_custom_status, + .get_custom_status = get_custom_status, + .save_custom_brightness = save_custom_brightness, + .custom_update = custom_backlight_update, + .set_force_brightness = set_force_brightness, + .set_brightness = set_brightness, + .get_brightness = get_brightness, + .restore_brightness_func = restore_brightness_func, + .get_brightness_by_light_sensor = get_brightness_by_light_sensor, + .get_image_effect = get_image_effect, + .set_image_effect = set_image_effect, + .get_panel_mode = get_panel_mode, + .set_panel_mode = set_panel_mode, + .get_frame_rate = get_frame_rate, + .set_frame_rate = set_frame_rate, + .transit_state = backlight_transit_state, + .transit_brt = change_brightness, + .blink = blink, + .release_blink = release_blink, /* auto-test only function */ - backlight_ops.get_brightness_raw = get_brightness; /* always fetch brightness from node even LBM mode */ -} + .get_brightness_raw = get_brightness, /* always fetch brightness from node even LBM mode */ +}; int display_service_load(void) { @@ -882,8 +886,6 @@ int is_lcdon_blocked(void) int init_sysfs(unsigned int flags) { - _init_ops(); - register_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); return 0; diff --git a/plugins/wearable/display/display-handler.c b/plugins/wearable/display/display-handler.c index ddb25cd..1c2f778 100644 --- a/plugins/wearable/display/display-handler.c +++ b/plugins/wearable/display/display-handler.c @@ -43,6 +43,7 @@ enum charging_lcd_state { CHARGING_LCD_ON = 1, }; +static struct _backlight_ops *backlight_ops; static guint autobrt_timer; static int autobrtlevel; @@ -55,10 +56,10 @@ static gboolean lcdon_from_aod_cb(gpointer data) autobrt_timer = 0; /* If it is still not turned on, do not apply auto brightness */ - if (backlight_ops.get_lcd_power() != DPMS_ON) + if (backlight_ops->get_lcd_power() != DPMS_ON) return G_SOURCE_REMOVE; - backlight_ops.transit_state(DPMS_ON); + backlight_ops->transit_state(DPMS_ON); display_info.set_brightness_level(level); /* lcdon is completed, aod disappered */ @@ -141,7 +142,7 @@ static void aod_change_signal(GDBusConnection *conn, if (!aod_clock_displayed) return; - backlight_ops.transit_state(DPMS_ON); + backlight_ops->transit_state(DPMS_ON); if (autobrt_timer) { /* if there is reserved level, apply it */ g_source_remove(autobrt_timer); autobrt_timer = 0; @@ -220,3 +221,10 @@ static const struct display_ops display_handler_ops = { }; DISPLAY_OPS_REGISTER(&display_handler_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); +} diff --git a/plugins/wearable/display/enhance.c b/plugins/wearable/display/enhance.c index 1675d7b..9fb32ea 100644 --- a/plugins/wearable/display/enhance.c +++ b/plugins/wearable/display/enhance.c @@ -34,6 +34,7 @@ #define VCONF_HIGH_CONTRAST VCONFKEY_SETAPPL_ACCESSIBILITY_HIGH_CONTRAST #define VCONF_GREYSCALE VCONFKEY_SETAPPL_ACCESSIBILITY_GREYSCALE +static struct _backlight_ops *backlight_ops; static bool negative_status; static bool greyscale_status; static bool greysacle_setting; @@ -54,7 +55,7 @@ static int enhance_update_state(void) else state = DISPLAY_IMAGE_EFFECT_STANDARD; - backlight_ops.set_image_effect(state); + backlight_ops->set_image_effect(state); return state; } @@ -165,3 +166,10 @@ static const struct display_ops display_enhance_ops = { }; DISPLAY_OPS_REGISTER(&display_enhance_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); +} diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index b543a8a..26ecf11 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -91,6 +91,7 @@ enum combination_process { }; static struct display_plugin *disp_plgn; +static struct _backlight_ops *backlight_ops; static struct timeval pressed_time; static guint longkey_timeout_id = 0; static guint longkey_restore_id = 0; @@ -113,8 +114,8 @@ static inline int current_state_in_on(void) static inline void restore_custom_brightness(void) { if ((get_pm_cur_state() == S_LCDDIM) && - backlight_ops.get_custom_status()) - backlight_ops.custom_update(); + backlight_ops->get_custom_status()) + backlight_ops->custom_update(); } static void longkey_pressed(void) @@ -205,7 +206,7 @@ static inline bool switch_on_lcd(enum device_flags flags) if (current_state_in_on()) return false; - if (backlight_ops.get_lcd_power() == DPMS_ON) { + if (backlight_ops->get_lcd_power() == DPMS_ON) { if (ambient_get_state() == false) return false; } @@ -225,7 +226,7 @@ static inline void switch_off_lcd(void) if (!current_state_in_on()) return; - if (backlight_ops.get_lcd_power() == DPMS_OFF) + if (backlight_ops->get_lcd_power() == DPMS_OFF) return; broadcast_lcdoff_by_powerkey(); @@ -352,7 +353,7 @@ static int decide_lcdoff(void) { /* It's not needed if it's already LCD off state */ if (!current_state_in_on() && - backlight_ops.get_lcd_power() != DPMS_ON) + backlight_ops->get_lcd_power() != DPMS_ON) return false; /* @@ -771,4 +772,8 @@ static void __CONSTRUCTOR__ initialize(void) if (!disp_plgn) { _E("Failed to get display plugin."); } + + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); } diff --git a/plugins/wearable/display/lbm.c b/plugins/wearable/display/lbm.c index 41a5bb2..79ec7cd 100644 --- a/plugins/wearable/display/lbm.c +++ b/plugins/wearable/display/lbm.c @@ -46,6 +46,7 @@ static struct lbm_config lbm_conf = { .aod_brightness_level = 0, }; +static struct _backlight_ops *backlight_ops; static int lbm_setting_mode; static int system_brightness; static struct display_device *display_dev; @@ -138,7 +139,7 @@ static void lbm_change_brightness(int start, int end, int step) if (display_dimstay_check()) return; - ret = backlight_ops.get_brightness(&prev); + ret = backlight_ops->get_brightness(&prev); if (ret < 0) { _E("Failed to get brightness, %d.", ret); @@ -160,7 +161,7 @@ static void lbm_change_brightness(int start, int end, int step) if (ret < 0) _E("Failed to set_multi_brightness, %d.", ret); - backlight_ops.set_brightness(end); + backlight_ops->set_brightness(end); return; } @@ -182,7 +183,7 @@ static void lbm_change_brightness(int start, int end, int step) start = end; usleep(LCD_PHASED_DELAY); - backlight_ops.set_brightness(start); + backlight_ops->set_brightness(start); } } @@ -192,11 +193,11 @@ int lbm_set_state(int lbm) broadcast_lbm_state(lbm); if (lbm) { - backlight_ops.set_brightness = lbm_set_brightness; - backlight_ops.get_brightness = lbm_get_brightness; - backlight_ops.transit_brt = lbm_change_brightness; + backlight_ops->set_brightness = lbm_set_brightness; + backlight_ops->get_brightness = lbm_get_brightness; + backlight_ops->transit_brt = lbm_change_brightness; } else { - backlight_ops.restore_brightness_func(); + backlight_ops->restore_brightness_func(); } return 0; @@ -207,7 +208,7 @@ int lbm_get_state(void) if (!lbm_conf.support) return -ENODEV; - return backlight_ops.set_brightness == lbm_set_brightness; + return backlight_ops->set_brightness == lbm_set_brightness; } static void lbm_table_load(char *value, struct lbm_config *c) @@ -340,3 +341,10 @@ static const struct display_ops display_lbm_ops = { }; DISPLAY_OPS_REGISTER(&display_lbm_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); +} diff --git a/plugins/wearable/display/powersaver.c b/plugins/wearable/display/powersaver.c index 8177e49..6c1de14 100644 --- a/plugins/wearable/display/powersaver.c +++ b/plugins/wearable/display/powersaver.c @@ -30,6 +30,8 @@ #include "powersaver.h" #include "setting.h" +static struct _backlight_ops *backlight_ops; + static int set_powersaver_mode(int mode) { int timeout; @@ -42,7 +44,7 @@ static int set_powersaver_mode(int mode) _D("Powersaver mode %d pmqos %d.", mode, pmqos); device_notify(DEVICE_NOTIFIER_ULTRAPOWERSAVING, (void *)&pmqos); - backlight_ops.set_force_brightness(0); + backlight_ops->set_force_brightness(0); set_force_lcdtimeout(0); FIND_DISPLAY(hbm_ops, "hbm"); @@ -52,7 +54,7 @@ static int set_powersaver_mode(int mode) hbm_ops->func(HBM_SET_TIMEOUT_STATE, &hss); } - backlight_ops.update(); + backlight_ops->update(); get_run_timeout(&timeout); states[S_NORMAL].timeout = timeout; states[get_pm_cur_state()].trans(EVENT_INPUT); @@ -153,3 +155,10 @@ static const struct device_ops powersaver_device_ops = { }; DEVICE_OPS_REGISTER(&powersaver_device_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); +} diff --git a/plugins/wearable/display/swim.c b/plugins/wearable/display/swim.c index 3651456..0361d62 100644 --- a/plugins/wearable/display/swim.c +++ b/plugins/wearable/display/swim.c @@ -32,6 +32,7 @@ #define DBUS_SWIMMODE_MEMBER_STATUS "status" static struct display_plugin *disp_plgn; +static struct _backlight_ops *backlight_ops; static const struct device_ops *touchscreen_ops; static int swimmode_status; @@ -90,7 +91,7 @@ static void swimmode_signal_handler(GDBusConnection *conn, _I("Request swim mode state %d by %d", val, pid); - if (backlight_ops.get_lcd_power != DPMS_ON) { + 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_state = true; @@ -144,4 +145,8 @@ static void __CONSTRUCTOR__ initialize(void) if (!disp_plgn) { _E("Failed to get display plugin."); } + + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); } diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index fb8809b..a0bb2bc 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -45,6 +45,7 @@ #define AMBIENT_CLOCK_WAITING_TIME 5000 /* ms */ static struct display_plugin *disp_plgn; +static struct _backlight_ops *backlight_ops; static int ambient_state; static int ambient_condition; /* Setting Value */ static pid_t ambient_pid; /* Ambient Clock pid */ @@ -86,7 +87,7 @@ 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) + if (backlight_ops->get_lcd_power() != DPMS_ON) if (disp_plgn->pm_lock_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); } @@ -138,7 +139,7 @@ void ambient_check_invalid_state(pid_t pid) if (is_emulator()) { /* In emulator, deviced does not turn off the display. */ - if (backlight_ops.get_lcd_power() == DPMS_ON) + if (backlight_ops->get_lcd_power() == DPMS_ON) return; } @@ -182,7 +183,7 @@ static void ambient_end_clock(pid_t pid) if (update_count == 0) { _D("lcd off"); - backlight_ops.off(NORMAL_MODE); + backlight_ops->off(NORMAL_MODE); broadcast_lcd_off_late(LCD_OFF_LATE_MODE); if (disp_plgn->pm_unlock_internal) disp_plgn->pm_unlock_internal(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); @@ -310,4 +311,8 @@ static void __CONSTRUCTOR__ initialize(void) if (!disp_plgn) { _E("Failed to get display plugin."); } + + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); } diff --git a/src/display/auto-brightness.c b/src/display/auto-brightness.c index fd3f2df..fe8fb16 100644 --- a/src/display/auto-brightness.c +++ b/src/display/auto-brightness.c @@ -60,6 +60,7 @@ #define ON_COUNT 1 #define OFF_COUNT 1 +static struct _backlight_ops *backlight_ops; static int (*_default_action) (int); static guint alc_timeout_id = 0; static guint update_timeout; @@ -107,7 +108,7 @@ static void alc_set_brightness(int setting, int value, float light) static float old; int position, tmp_value = 0, ret; - ret = backlight_ops.get_brightness(&tmp_value); + ret = backlight_ops->get_brightness(&tmp_value); if (ret < 0) { _E("Failed to get display brightness."); return; @@ -144,8 +145,8 @@ static void alc_set_brightness(int setting, int value, float light) (step < 0 && tmp_value < value)) tmp_value = value; - backlight_ops.set_default_brt(tmp_value); - backlight_ops.update(); + backlight_ops->set_default_brt(tmp_value); + backlight_ops->update(); } _I("Load light data(%f) auto brt=%d min brightness=%d " "brightness=%d", light, automatic_brt, min_brightness, value); @@ -190,7 +191,7 @@ static bool alc_update_brt(bool setting) } light = light_data.values[index]; - ret = backlight_ops.get_brightness_by_light_sensor( + ret = backlight_ops->get_brightness_by_light_sensor( lmax, lmin, light, &value); if (ret == -ENOTSUP) { _E("Not supported to handle the light data."); @@ -440,8 +441,8 @@ static int set_autobrightness_state(int status) default_brt = brt; } - backlight_ops.set_default_brt(default_brt); - backlight_ops.update(); + backlight_ops->set_default_brt(default_brt); + backlight_ops->update(); } return 0; @@ -656,6 +657,10 @@ static void exit_lsensor(void) static void auto_brightness_init(void *data) { + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); + display_info.update_auto_brightness = update_auto_brightness; display_info.set_autobrightness_min = set_autobrightness_min; display_info.reset_autobrightness_min = reset_autobrightness_min; diff --git a/src/display/device-interface.h b/src/display/device-interface.h index 078637b..dec91c9 100644 --- a/src/display/device-interface.h +++ b/src/display/device-interface.h @@ -91,7 +91,7 @@ struct _backlight_ops { void (*release_blink)(void); }; -extern struct _backlight_ops backlight_ops; +struct _backlight_ops *get_backlight_ops(void); enum dpms_state { DPMS_ON, /* In use */ diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 3cd7f20..a808ca0 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -69,6 +69,7 @@ #define EXPIRED_POPUP_ID "_REQUEST_ID_" static struct display_plugin *disp_plgn; +static struct _backlight_ops *backlight_ops; static GVariant *dbus_start(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, @@ -389,7 +390,7 @@ static GVariant *dbus_getbrightness(GDBusConnection *conn, int brt = -1, ret, result; if (get_pm_cur_state() == S_NORMAL) { - ret = backlight_ops.get_brightness(&brt); + ret = backlight_ops->get_brightness(&brt); if (ret < 0) result = 0; else @@ -403,7 +404,7 @@ static GVariant *dbus_getbrightness(GDBusConnection *conn, result = brt; } } else { - result = backlight_ops.get_default_brt(); + result = backlight_ops->get_default_brt(); brt = 0; } @@ -452,8 +453,8 @@ static GVariant *dbus_setbrightness(GDBusConnection *conn, if (disp_plgn->auto_brightness_control) { ret = disp_plgn->auto_brightness_control(BR_SET_BRIGHTNESS, brt); } else { - backlight_ops.set_default_brt(brt); - ret = backlight_ops.set_brightness(brt); + backlight_ops->set_default_brt(brt); + ret = backlight_ops->set_brightness(brt); if (ret < 0) goto error; ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); @@ -462,7 +463,7 @@ static GVariant *dbus_setbrightness(GDBusConnection *conn, } } else if (state == DISPLAY_STATE_SCREEN_DIM) { if (get_pm_cur_state() == S_LCDDIM) { - ret = backlight_ops.set_brightness(brt); + ret = backlight_ops->set_brightness(brt); if (ret < 0) goto error; } @@ -514,7 +515,7 @@ static GVariant *dbus_holdbrightness(GDBusConnection *conn, if (disp_plgn->auto_brightness_control) ret = disp_plgn->auto_brightness_control(BR_HOLD_BRIGHTNESS, brt); else - ret = backlight_ops.set_brightness(brt); + ret = backlight_ops->set_brightness(brt); if (ret < 0) goto error; @@ -577,7 +578,7 @@ static GVariant *dbus_releasebrightness(GDBusConnection *conn, if (ret < 0) _E("Failed to set vconf value for custom brightness status: %d", vconf_get_ext_errno()); - ret = backlight_ops.get_brightness(&brt); + ret = backlight_ops->get_brightness(&brt); if (ret < 0) brt = ret; @@ -586,7 +587,7 @@ static GVariant *dbus_releasebrightness(GDBusConnection *conn, charger == VCONFKEY_SYSMAN_CHARGER_DISCONNECTED && !changed) { _D("batt warning low : brightness is not changed!"); if (brt != 0) - backlight_ops.set_brightness(0); + backlight_ops->set_brightness(0); goto error; } @@ -595,7 +596,7 @@ static GVariant *dbus_releasebrightness(GDBusConnection *conn, disp_plgn->auto_brightness_control(BR_RELEASE_BRIGHTNESS, BR_IMPLICIT); } else { if (brt != setting) - backlight_ops.set_brightness(setting); + backlight_ops->set_brightness(setting); } } else if (autobrt == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { _D("Auto brightness will be enable"); @@ -630,15 +631,15 @@ static GVariant *dbus_setrefreshrate(GDBusConnection *conn, control = display_conf.control_display; if (control) - backlight_ops.off(NORMAL_MODE); + backlight_ops->off(NORMAL_MODE); _D("app : %d, value : %d", app, val); - ret = backlight_ops.set_frame_rate(val); + ret = backlight_ops->set_frame_rate(val); if (ret < 0) _E("Failed to set frame rate (%d)", ret); if (control) - backlight_ops.on(NORMAL_MODE); + backlight_ops->on(NORMAL_MODE); error: return g_variant_new("(i)", ret); @@ -751,13 +752,13 @@ static GVariant *dbus_dumpmode(GDBusConnection *conn, if (disp_plgn->pm_lock_internal) disp_plgn->pm_lock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, STAY_CUR_STATE, DUMP_MODE_WATING_TIME); - backlight_ops.release_blink(); + backlight_ops->release_blink(); } else if (!strcmp(on, "off")) { if (disp_plgn->pm_unlock_internal) disp_plgn->pm_unlock_internal(INTERNAL_LOCK_DUMPMODE, LCD_OFF, PM_SLEEP_MARGIN); - backlight_ops.blink(0); + backlight_ops->blink(0); } else if (!strcmp(on, "blink")) { - backlight_ops.blink(500); + backlight_ops->blink(500); } else { ret = -EINVAL; } @@ -926,7 +927,7 @@ static GVariant *dbus_getcustombrightness(GDBusConnection *conn, { int status = 0; - status = backlight_ops.get_custom_status(); + status = backlight_ops->get_custom_status(); return g_variant_new("(i)", status); } @@ -1156,7 +1157,7 @@ static GVariant *dbus_dimstay_control(GDBusConnection *conn, } if (get_pm_cur_state() == S_NORMAL) - backlight_ops.update(); + backlight_ops->update(); return g_variant_new("(i)", 0); } @@ -1168,8 +1169,8 @@ static GVariant *dbus_getbrightnessinfo(GDBusConnection *conn, int default_brightness; int current_brightness; - default_brightness = backlight_ops.get_default_brt(); - backlight_ops.get_brightness_raw(¤t_brightness); + default_brightness = backlight_ops->get_default_brt(); + backlight_ops->get_brightness_raw(¤t_brightness); return g_variant_new("(ii)", default_brightness, current_brightness); } @@ -1304,4 +1305,8 @@ static void __CONSTRUCTOR__ initialize(void) if (!disp_plgn) { _E("Failed to get display plugin."); } + + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); } diff --git a/src/display/display-lock.c b/src/display/display-lock.c index b34ab61..088b924 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -33,6 +33,7 @@ #define PID_MAX 6 #define LOCK_TIME_WARNING 60 /* 60 seconds */ +static struct _backlight_ops *backlight_ops; static dd_list *cond_head[S_END]; static int trans_condition; @@ -124,7 +125,7 @@ static gboolean pmlock_check(void *data) v = (GVariant*)data; g_variant_get(v, "(ii)", &state, &pid); - if (state == S_LCDOFF && backlight_ops.get_lcd_power() == DPMS_ON) { + if (state == S_LCDOFF && backlight_ops->get_lcd_power() == DPMS_ON) { _D("Lcd state is PM_LCD_POWER_ON"); return G_SOURCE_CONTINUE; } @@ -391,3 +392,10 @@ dd_list *get_cond_head(enum state_t s_index) { return cond_head[s_index]; } + +static void __CONSTRUCTOR__ initialize(void) +{ + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); +} diff --git a/src/touchscreen/touchscreen.c b/src/touchscreen/touchscreen.c index 295503b..dff61ce 100644 --- a/src/touchscreen/touchscreen.c +++ b/src/touchscreen/touchscreen.c @@ -50,6 +50,8 @@ static int booting_done(void *data); static struct display_config *_display_conf; static struct _backlight_ops *_backlight_ops; +static struct _backlight_ops* (*_get_backlight_ops)(void); + static void touchscreen_wakeup_status(keynode_t *key, void *data) { if (!key) @@ -315,12 +317,20 @@ static void touchscreen_init(void *data) int ret, val; _display_conf = dlsym(disp_plgn->handle, "display_conf"); - if (!_display_conf) + if (!_display_conf) _E("Failed to obtain address of display_conf, %s.", dlerror()); - _backlight_ops = dlsym(disp_plgn->handle, "backlight_ops"); - if (!_backlight_ops) - _E("Failed to obtain address of backlight_ops."); + /* 'backlight_ops' is declared static and used a lot of places with same name. + * So it fails that fetching symbol directly with name 'backlight_ops'. + * To avoid this, fetches getter function 'get_backlight_ops' instead, and + * retrieve the 'backlight_ops' by using it */ + _get_backlight_ops = dlsym(disp_plgn->handle, "get_backlight_ops"); + if (_get_backlight_ops) { + _backlight_ops = _get_backlight_ops(); + if (!_backlight_ops) + _E("Failed to get backlight operator."); + } else + _E("Failed to obtain address of get_backlight_ops, %s.", dlerror()); if (touchscreen_dev && touchscreen_dev->set_powersaving) { ret = touchscreen_dev->set_powersaving(0); -- 2.7.4 From b7a482d52801434d55137f8cc3765e26d72fb407 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Fri, 14 Aug 2020 16:33:47 +0900 Subject: [PATCH 10/16] Add initialize constructor for backlight init. Change-Id: I592367573b0550d6841b1440ba7e2ea47849471f Signed-off-by: Yunmi Ha --- plugins/iot/display/core.c | 5 ----- src/display/auto-brightness.c | 10 ++++++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 2ed514c..ba2fb8a 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -2291,11 +2291,6 @@ static void display_init(void *data) if (display_conf.timeout_enable) get_lcd_timeout_from_settings(); ret = init_sysfs(flags); - backlight_ops = get_backlight_ops(); - if (!backlight_ops) { - _E("Failed to get backlight operator."); - ret = -1; - } break; case INIT_POLL: _I("input init"); diff --git a/src/display/auto-brightness.c b/src/display/auto-brightness.c index fe8fb16..1afc48d 100644 --- a/src/display/auto-brightness.c +++ b/src/display/auto-brightness.c @@ -657,10 +657,6 @@ static void exit_lsensor(void) static void auto_brightness_init(void *data) { - backlight_ops = get_backlight_ops(); - if (!backlight_ops) - _E("Failed to get backlight operator."); - display_info.update_auto_brightness = update_auto_brightness; display_info.set_autobrightness_min = set_autobrightness_min; display_info.reset_autobrightness_min = reset_autobrightness_min; @@ -685,3 +681,9 @@ static const struct display_ops display_autobrightness_ops = { DISPLAY_OPS_REGISTER(&display_autobrightness_ops) +static void __CONSTRUCTOR__ initialize(void) +{ + backlight_ops = get_backlight_ops(); + if (!backlight_ops) + _E("Failed to get backlight operator."); +} -- 2.7.4 From 24adb6e1e27a8b3916ef57d30721aca7c9003592 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Tue, 18 Aug 2020 14:00:00 +0900 Subject: [PATCH 11/16] Fix build warnings Change-Id: Ibcc05e48990655e0d62e08dc43fa7fe448c1cb9c Signed-off-by: Hyotaek Shim --- src/apps/apps.c | 1 + src/display/display-signal.c | 1 + 2 files changed, 2 insertions(+) diff --git a/src/apps/apps.c b/src/apps/apps.c index 72deb24..13ccf7e 100644 --- a/src/apps/apps.c +++ b/src/apps/apps.c @@ -21,6 +21,7 @@ #include "core/common.h" #include "display/display-ops.h" #include "apps.h" +#include "shared/plugin.h" #define POPUP_METHOD "PopupLaunch" #define BUFF_MAX 255 diff --git a/src/display/display-signal.c b/src/display/display-signal.c index e695e99..0b64ff0 100644 --- a/src/display/display-signal.c +++ b/src/display/display-signal.c @@ -19,6 +19,7 @@ #include "display-signal.h" #include "display-ops.h" #include "poll.h" +#include "shared/plugin.h" #define ACTIVE_ACT "active" #define INACTIVE_ACT "inactive" -- 2.7.4 From 1fd766c1aca88ec15bfd4bf56ebdc57dae6fbb5d Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Fri, 7 Aug 2020 16:23:17 +0900 Subject: [PATCH 12/16] Change battery global variable to static Change-Id: I2d2b3e024e0518bf9f442ec4820c12546085160f Signed-off-by: Yunmi Ha --- plugins/mobile/battery/battery-notification.c | 34 +++++++------ plugins/wearable/battery/battery-notification.c | 18 +++++-- plugins/wearable/display/device-interface.c | 7 ++- src/apps/apps.c | 1 - src/battery/battery-time.c | 11 ++++- src/battery/lowbat-handler.c | 64 +++++++++++++------------ src/battery/power-supply.c | 7 ++- src/battery/power-supply.h | 2 +- src/display/display-signal.c | 1 - src/touchscreen/touchscreen.c | 8 ++-- 10 files changed, 93 insertions(+), 60 deletions(-) diff --git a/plugins/mobile/battery/battery-notification.c b/plugins/mobile/battery/battery-notification.c index d72c287..c3fe9f1 100644 --- a/plugins/mobile/battery/battery-notification.c +++ b/plugins/mobile/battery/battery-notification.c @@ -52,6 +52,7 @@ enum event_noti_type { }; static struct display_plugin *disp_plgn; +static struct battery_status *battery; static guint abnormal_timer; static int noti_low = NOTI_NONE; @@ -163,7 +164,7 @@ static int launch_lowbat_noti(int capacity, int option) disp_plgn->pm_change_internal(INTERNAL_LOCK_LOWBAT, LCD_NORMAL); } prev_level = battery_info.warning; - if (battery.charge_now) + if (battery->charge_now) ret = dbus_handle_method_async_var(POPUP_BUS_NAME, POPUP_PATH_BATTERY, POPUP_INTERFACE_BATTERY, @@ -204,7 +205,7 @@ static int launch_lowbat_noti(int capacity, int option) disp_plgn->pm_change_internal(INTERNAL_LOCK_LOWBAT, LCD_NORMAL); } prev_level = battery_info.critical; - if (battery.charge_now) + if (battery->charge_now) ret = dbus_handle_method_async_var(POPUP_BUS_NAME, POPUP_PATH_BATTERY, POPUP_INTERFACE_BATTERY, @@ -237,13 +238,13 @@ static void clean_lowbat_noti(const char *prev, const char *str) return; } - if (prev == str && !battery.charge_now) + if (prev == str && !battery->charge_now) return; condition = check_remove_condition(prev, str); _D("Condition: %d", condition); - if (condition || battery.charge_now) { + if (condition || battery->charge_now) { if (noti_crit > 1) { /* remove critical notiid */ noti_id = noti_crit; @@ -306,14 +307,14 @@ static int check_power_supply_noti(void) static void update_ovp(enum battery_noti_status status) { - _I("charge %d ovp %d(old %d)", battery.charge_now, battery.health, old_battery.health); + _I("charge %d ovp %d(old %d)", battery->charge_now, battery->health, old_battery.health); - old_battery.health = battery.health; + old_battery.health = battery->health; if (status == DEVICE_NOTI_ON) battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_DIM); else battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); - device_notify(DEVICE_NOTIFIER_BATTERY_OVP, (void *)&battery.health); + device_notify(DEVICE_NOTIFIER_BATTERY_OVP, (void *)&battery->health); } static void health_timer_reset(void) @@ -325,19 +326,19 @@ static gboolean health_timer_cb(void *data) { health_timer_reset(); - if (battery.health != HEALTH_LOW && battery.health != HEALTH_HIGH) + if (battery->health != HEALTH_LOW && battery->health != HEALTH_HIGH) return G_SOURCE_REMOVE; - CRITICAL_LOG("Popup: Battery health status is not good, %s.", battery.health_s); - device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)&battery.health); + CRITICAL_LOG("Popup: Battery health status is not good, %s.", battery->health_s); + device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)&battery->health); battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_DIM); if (disp_plgn->pm_unlock_internal) disp_plgn->pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); if (disp_plgn->pm_lock_internal) disp_plgn->pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); - if (battery.health == HEALTH_LOW) + if (battery->health == HEALTH_LOW) battery_charge_err_low_act(NULL); - else if (battery.health == HEALTH_HIGH) + else if (battery->health == HEALTH_HIGH) battery_charge_err_high_act(NULL); return G_SOURCE_REMOVE; } @@ -351,7 +352,7 @@ static void abnormal_popup_dbus_signal_handler(GDBusConnection *conn, gpointer user_data) { - if (battery.health == HEALTH_GOOD) + if (battery->health == HEALTH_GOOD) return; _I("Restart health timer."); @@ -410,7 +411,10 @@ BATTERY_OPS_REGISTER(&battery_notification_ops) static void __CONSTRUCTOR__ initialize(void) { disp_plgn = get_display_plugin(); - if (!disp_plgn) { + if (!disp_plgn) _E("Failed to get display plugin."); - } + + battery = get_battery_status(); + if (!battery) + _E("Failed to get battery status structure."); } diff --git a/plugins/wearable/battery/battery-notification.c b/plugins/wearable/battery/battery-notification.c index 8ab24f4..0d8e1e0 100644 --- a/plugins/wearable/battery/battery-notification.c +++ b/plugins/wearable/battery/battery-notification.c @@ -27,6 +27,8 @@ #include "battery.h" #include "dd-display.h" +static struct battery_status *battery; + static int display_changed(void *data) { static enum state_t old; @@ -38,7 +40,7 @@ static int display_changed(void *data) old = state; state = *(int *)data; - if (battery.health != HEALTH_LOW && battery.health != HEALTH_HIGH) + if (battery->health != HEALTH_LOW && battery->health != HEALTH_HIGH) return state; /* relaunch health popup on LCDON */ @@ -68,11 +70,11 @@ static void update_ovp(enum battery_noti_status status) return; old = status; - _I("Charge(%d) ovp(%d, old: %d) with lcd(%s)", battery.charge_now, battery.health, + _I("Charge(%d) ovp(%d, old: %d) with lcd(%s)", battery->charge_now, battery->health, old_battery.health, (status == DEVICE_NOTI_ON) ? "dim" : "normal"); - old_battery.health = battery.health; - device_notify(DEVICE_NOTIFIER_BATTERY_OVP, (void *)&battery.health); + old_battery.health = battery->health; + device_notify(DEVICE_NOTIFIER_BATTERY_OVP, (void *)&battery->health); battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); } @@ -86,7 +88,6 @@ static void battery_notification_init(void *data) _D("Add plugins for battery notification."); plugin->check_power_supply_noti = check_power_supply_noti; plugin->update_ovp = update_ovp; - plugin->display_changed = display_changed; register_notifier(DEVICE_NOTIFIER_LCD, display_changed); @@ -98,3 +99,10 @@ static const struct battery_ops battery_notification_ops = { }; BATTERY_OPS_REGISTER(&battery_notification_ops) + +static void __CONSTRUCTOR__ initialize(void) +{ + battery = get_battery_status(); + if (!battery) + _E("Failed to get battery status structure."); +} diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index c26937e..dd1a03f 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -646,6 +646,11 @@ static int backlight_transit_state(int state) int brt, val; int start, end; static int aod_brightness_level; + struct battery_status *battery = get_battery_status(); + if (!battery) { + _E("Failed to get battery status structure."); + return -EINVAL; + } backlight_ops.get_brightness(&brt); @@ -691,7 +696,7 @@ static int backlight_transit_state(int state) return 0; } - if (battery.charge_now == CHARGER_CHARGING) { + if (battery->charge_now == CHARGER_CHARGING) { if (aod_charging_level > 0 && val >= aod_charging_level) aod_brightness_level = aod_charging_level; else if (aod_min_level > 0 && val >= aod_min_level) diff --git a/src/apps/apps.c b/src/apps/apps.c index 13ccf7e..744e3af 100644 --- a/src/apps/apps.c +++ b/src/apps/apps.c @@ -19,7 +19,6 @@ #include #include "core/log.h" #include "core/common.h" -#include "display/display-ops.h" #include "apps.h" #include "shared/plugin.h" diff --git a/src/battery/battery-time.c b/src/battery/battery-time.c index 154be9a..f557448 100644 --- a/src/battery/battery-time.c +++ b/src/battery/battery-time.c @@ -263,8 +263,15 @@ static int battinfo_calculation(void) int capacity = 0; int estimated_time = 0; int tmp = 0; + struct battery_status *battery; - capacity = battery.capacity; + battery = get_battery_status(); + if (!battery) { + _E("Failed to get battery status structure."); + return -EINVAL; + } + + capacity = battery->capacity; if (capacity <= 0) return -1; @@ -281,7 +288,7 @@ static int battinfo_calculation(void) del_all_batt_node(B_UNCHARGING); if ((capacity * 100 / FULL_CAPACITY) >= BATTERY_FULL_THRESHOLD) { - if (battery.charge_full == CHARGING_FULL) { + if (battery->charge_full == CHARGING_FULL) { del_all_batt_node(B_CHARGING); _I("Battery fully charged."); update_time(A_TIMETOFULL, 0); diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index e8e32a2..c25523c 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -70,6 +70,8 @@ struct lowbat_process_entry { static struct display_plugin *disp_plgn; static struct battery_plugin *battery_plgn; +static struct battery_status *battery; + static int cur_bat_state = BATTERY_UNKNOWN; static int cur_bat_capacity = BATTERY_UNKNOWN; static int custom_warning_level = BATTERY_UNKNOWN; @@ -107,7 +109,7 @@ static int lowbat_scenario(int old, int now, void *data) struct lowbat_process_entry *scenario; int found = 0; - if (old == now && battery.charge_now) + if (old == now && battery->charge_now) return found; DD_LIST_FOREACH(lpe, n, scenario) { if (old != scenario->old || now != scenario->now) @@ -178,8 +180,8 @@ static int booting_done(void *data) _I("Booting done."); if (popup) { popup = 0; - if (battery.charge_now != CHARGER_CHARGING && - battery.charge_full != CHARGING_FULL) + if (battery->charge_now != CHARGER_CHARGING && + battery->charge_full != CHARGING_FULL) lowbat_popup(BAT_OPT_NONE); else _I("Skip low battery popup during charging."); @@ -340,7 +342,7 @@ static void battery_level_send_system_event(int bat_percent) const char *str; static const char *prev; - if (bat_percent >= battery_info.normal && battery.charge_full == CHARGING_FULL) + if (bat_percent >= battery_info.normal && battery->charge_full == CHARGING_FULL) str = EVT_VAL_BATTERY_LEVEL_FULL; else if (bat_percent > battery_info.warning) str = EVT_VAL_BATTERY_LEVEL_HIGH; @@ -376,7 +378,7 @@ static void change_lowbat_level(int bat_percent) } if (bat_percent >= battery_info.normal) { - if (battery.charge_full == CHARGING_FULL) + if (battery->charge_full == CHARGING_FULL) now = VCONFKEY_SYSMAN_BAT_LEVEL_FULL; else now = VCONFKEY_SYSMAN_BAT_LEVEL_HIGH; @@ -427,13 +429,13 @@ static void lowbat_custom_popup(int online, int capacity) custom_warning_launch = false; return; } - if (online == battery.online && custom_warning_launch) + if (online == battery->online && custom_warning_launch) return; - if (battery.online > POWER_SUPPLY_TYPE_BATTERY && custom_warning_launch) + if (battery->online > POWER_SUPPLY_TYPE_BATTERY && custom_warning_launch) return; custom_warning_launch = true; - _I("Launch custom lowbattery warning popup. online(%d, %d), capacity(%d, %d)", online, battery.online, capacity, custom_warning_level); + _I("Launch custom lowbattery warning popup. online(%d, %d), capacity(%d, %d)", online, battery->online, capacity, custom_warning_level); (void)battery_warning_low_act(NULL); } @@ -489,9 +491,9 @@ static int lowbat_process(int bat_percent, void *ad) } if (new_bat_capacity <= battery_info.realoff) { - if (battery.charge_now == CHARGER_CHARGING || battery.charger_charging == CHARGER_DISABLED) { + if (battery->charge_now == CHARGER_CHARGING || battery->charger_charging == CHARGER_DISABLED) { _I("Skip lowbat poweroff during test (c:%d charge:%d online:%d charger_charging:%d)", - battery.capacity, battery.charge_now, battery.online, battery.charger_charging); + battery->capacity, battery->charge_now, battery->online, battery->charger_charging); new_bat_state = battery_info.poweroff; if (vconf_state != VCONFKEY_SYSMAN_BAT_POWER_OFF) status = VCONFKEY_SYSMAN_BAT_POWER_OFF; @@ -515,7 +517,7 @@ static int lowbat_process(int bat_percent, void *ad) } else { new_bat_state = battery_info.normal; if (new_bat_capacity == BATTERY_FULL) { - if (battery.charge_full) { + if (battery->charge_full) { if (vconf_state != VCONFKEY_SYSMAN_BAT_FULL) status = VCONFKEY_SYSMAN_BAT_FULL; } else { @@ -530,14 +532,14 @@ static int lowbat_process(int bat_percent, void *ad) /* If the battery continues to run out even though it is being charged * for a certain period of time, turn off the device. */ - if (new_bat_capacity <= battery_info.realoff && battery.charge_now == CHARGER_CHARGING) { + if (new_bat_capacity <= battery_info.realoff && battery->charge_now == CHARGER_CHARGING) { if (low_bat_skip_cnt >= RETRY_MAX) { new_bat_state = battery_info.realoff; status = VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF; _I("Go to real poweroff inspite of charging (c:%d charge:%d online:%d charger_charging %d current now %d)", - battery.capacity, battery.charge_now, battery.online, battery.charger_charging, battery.current_now); + battery->capacity, battery->charge_now, battery->online, battery->charger_charging, battery->current_now); low_bat_skip_cnt = 0; - } else if (battery.current_now <= MIN_INOW_VALUE) { + } else if (battery->current_now <= MIN_INOW_VALUE) { low_bat_skip_cnt++; } else { low_bat_skip_cnt = 0; @@ -563,12 +565,12 @@ static int lowbat_process(int bat_percent, void *ad) low_bat_old = low_bat; } - if (battery.online == POWER_SUPPLY_TYPE_UNKNOWN) + if (battery->online == POWER_SUPPLY_TYPE_UNKNOWN) return result; - if (cur_bat_state == new_bat_state && online == battery.online) + if (cur_bat_state == new_bat_state && online == battery->online) return result; - online = battery.online; + online = battery->online; if (cur_bat_state == BATTERY_UNKNOWN) cur_bat_state = battery_info.normal; if (lowbat_scenario(cur_bat_state, new_bat_state, NULL)) @@ -582,7 +584,7 @@ static int check_lowbat_percent(int *pct) { int bat_percent; - bat_percent = battery.capacity; + bat_percent = battery->capacity; if (bat_percent < 0) return -ENODEV; if (bat_percent > 100) @@ -599,12 +601,12 @@ static int lowbat_monitor(void *data) r = lowbat_initialized(NULL); if (r != BATTERY_ENABLED) - return battery.charging_level; + return battery->charging_level; if (data == NULL) { r = check_lowbat_percent(&bat_percent); if (r < 0) - return battery.charging_level; + return battery->charging_level; } else bat_percent = *(int *)data; return lowbat_process(bat_percent, NULL); @@ -630,8 +632,8 @@ static int lowbat_monitor_init(void *data) battery_info.critical, battery_info.poweroff, battery_info.realoff); lowbat_scenario_init(); - check_lowbat_percent(&battery.capacity); - lowbat_process(battery.capacity, NULL); + check_lowbat_percent(&battery->capacity); + lowbat_process(battery->capacity, NULL); return 0; } @@ -731,11 +733,11 @@ static void lowbat_exit(void *data) static gboolean low_battery_charge_status(void *data) { low_batt_sig_timer = 0; - battery.charging_level = lowbat_monitor(data); - if (battery.charging_level > 0 && old_battery.charging_level != battery.charging_level) { - if (vconf_set_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery.charging_level) < 0) + battery->charging_level = lowbat_monitor(data); + if (battery->charging_level > 0 && old_battery.charging_level != battery->charging_level) { + if (vconf_set_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, battery->charging_level) < 0) _E("Fail to set level."); - if (power_supply_broadcast(CHARGE_LEVEL_SIGNAL, battery.charging_level) < 0) + if (power_supply_broadcast(CHARGE_LEVEL_SIGNAL, battery->charging_level) < 0) _E("power_supply_broadcast failed"); } return G_SOURCE_REMOVE; @@ -779,12 +781,14 @@ DEVICE_OPS_REGISTER(&lowbat_device_ops) static void __CONSTRUCTOR__ initialize(void) { disp_plgn = get_display_plugin(); - if (!disp_plgn) { + if (!disp_plgn) _E("Failed to get display plugin."); - } battery_plgn = get_battery_plugin(); - if (!battery_plgn) { + if (!battery_plgn) _E("Failed to get battery plugin."); - } + + battery = get_battery_status(); + if (!battery) + _E("Failed to get battery status structure."); } diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 44f0711..c7e3203 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -91,7 +91,7 @@ static const struct uevent_handler uh = { .uevent_func = uevent_power_handler, }; -struct battery_status battery; +static struct battery_status battery; struct battery_status old_battery; static int noti_id; static int online_status; @@ -113,6 +113,11 @@ static struct battery_device *battery_dev; static int load_uevent(struct parse_result *result, void *user_data); static int event_handler_state_changed(void *data); +inline struct battery_status *get_battery_status() +{ + return &battery; +} + static int lowbat_execute(void *data) { static const struct device_ops *lowbat_ops; diff --git a/src/battery/power-supply.h b/src/battery/power-supply.h index 1a2dfee..ebc050b 100644 --- a/src/battery/power-supply.h +++ b/src/battery/power-supply.h @@ -118,7 +118,7 @@ struct battery_status { char power_source_s[32]; }; -extern struct battery_status battery; +struct battery_status *get_battery_status(); extern struct battery_status old_battery; extern bool battery_initialized; diff --git a/src/display/display-signal.c b/src/display/display-signal.c index 0b64ff0..cf2cf83 100644 --- a/src/display/display-signal.c +++ b/src/display/display-signal.c @@ -17,7 +17,6 @@ */ #include "display-signal.h" -#include "display-ops.h" #include "poll.h" #include "shared/plugin.h" diff --git a/src/touchscreen/touchscreen.c b/src/touchscreen/touchscreen.c index dff61ce..adc244c 100644 --- a/src/touchscreen/touchscreen.c +++ b/src/touchscreen/touchscreen.c @@ -212,7 +212,9 @@ static int touchscreen_start(enum device_flags flags) static int touchscreen_stop(enum device_flags flags) { - if (!_display_conf || !_backlight_ops) { + struct battery_status *battery = get_battery_status(); + + if (!_display_conf || !_backlight_ops || !battery) { _I("Touchscreen is not initialized."); goto exit; } @@ -232,8 +234,8 @@ static int touchscreen_stop(enum device_flags flags) return touchscreen_set_state(TOUCHSCREEN_OFF); } - if (battery.online_type >= CHARGER_TYPE_WIRE) { - _I("Battery charging one %d %d.", battery.online, battery.online_type); + if (battery && battery->online_type >= CHARGER_TYPE_WIRE) { + _I("Battery charging one %d %d.", battery->online, battery->online_type); return touchscreen_powersaving(POWERSAVING_ON); } -- 2.7.4 From eeb12e2e8ddddeb04631d2242e08925d67e0cc48 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Fri, 7 Aug 2020 17:51:23 +0900 Subject: [PATCH 13/16] Change states global variable to static Change-Id: I86483d65ad63f6ceca0c12111f994ffaf95669eb Signed-off-by: Yunmi Ha --- plugins/iot/display/core.c | 7 +++++- plugins/mobile/display/core.c | 7 +++++- plugins/tv/display/core.c | 7 +++++- plugins/tv/display/state-tv.c | 42 +++++++++++++++++------------------ plugins/wearable/display/core.c | 7 +++++- plugins/wearable/display/powersaver.c | 4 ++-- src/display/auto-brightness.c | 6 ++--- src/display/core.h | 3 ++- src/display/display-lock.c | 8 +++---- src/display/poll.c | 2 +- 10 files changed, 57 insertions(+), 36 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index ba2fb8a..a2e4ae7 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -132,7 +132,7 @@ static gboolean del_off_cond(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; -struct state states[S_END] = { +static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, { S_NORMAL, "S_NORMAL", default_trans, default_action, default_check, del_normal_cond }, { S_LCDDIM, "S_LCDDIM", default_trans, default_action, default_check, del_dim_cond }, @@ -211,6 +211,11 @@ struct display_function_info display_info = { .face_detection = NULL, }; +inline struct state* state_st(enum state_t state) +{ + return &states[state]; +} + void change_state_action(enum state_t state, int (*func)(int timeout)) { _I("[%s] 'action' is changed.", states[state].name); diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index e9cc44c..13f219f 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -135,7 +135,7 @@ static gboolean del_off_cond(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; -struct state states[S_END] = { +static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, { S_NORMAL, "S_NORMAL", default_trans, default_action, default_check, del_normal_cond }, { S_LCDDIM, "S_LCDDIM", default_trans, default_action, default_check, del_dim_cond }, @@ -214,6 +214,11 @@ struct display_function_info display_info = { .face_detection = NULL, }; +inline struct state* state_st(enum state_t state) +{ + return &states[state]; +} + void change_state_action(enum state_t state, int (*func)(int timeout)) { _I("[%s] 'action' is changed.", states[state].name); diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index fbf58d0..6220f09 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -133,7 +133,7 @@ static gboolean del_off_cond(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; -struct state states[S_END] = { +static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, { S_NORMAL, "S_NORMAL", default_trans, default_action, default_check, del_normal_cond }, { S_LCDDIM, "S_LCDDIM", default_trans, default_action, default_check, del_dim_cond }, @@ -212,6 +212,11 @@ struct display_function_info display_info = { .face_detection = NULL, }; +inline struct state* state_st(enum state_t state) +{ + return &states[state]; +} + void change_state_action(enum state_t state, int (*func)(int timeout)) { _I("[%s] 'action' is changed.", states[state].name); diff --git a/plugins/tv/display/state-tv.c b/plugins/tv/display/state-tv.c index 0a86fde..3ce57d6 100644 --- a/plugins/tv/display/state-tv.c +++ b/plugins/tv/display/state-tv.c @@ -50,24 +50,24 @@ static int change_state(pid_t pid, int type, enum state_t st) { int ret; - if (type == PM_CONTROL_EVENT && states[st].check) { - ret = states[get_pm_cur_state()].check(get_pm_cur_state(), st); + if (type == PM_CONTROL_EVENT && state_st(st)->check) { + ret = state_st(get_pm_cur_state())->check(get_pm_cur_state(), st); if (ret != 0) { _E("(%s) State Locked. Cannot be changed to (%s)", - states[get_pm_cur_state()].name, states[st].name); + state_st(get_pm_cur_state())->name, state_st(st)->name); return ret; } } - if (states[st].trans) { - ret = states[st].trans(type); + if (state_st(st)->trans) { + ret = state_st(st)->trans(type); if (ret < 0) { - _E("Failed to trans state (%s, ret:%d)", states[st].name, ret); + _E("Failed to trans state (%s, ret:%d)", state_st(st)->name, ret); return ret; } } - _I("Success to change state (%s) requested by pid(%d)", states[st].name, pid); + _I("Success to change state (%s) requested by pid(%d)", state_st(st)->name, pid); return 0; } @@ -90,7 +90,7 @@ static int tv_proc_change_state(unsigned int cond, pid_t pid) } } - _I("Change State to %s (%d)", states[next].name, pid); + _I("Change State to %s (%d)", state_st(next)->name, pid); ret = change_state(pid, PM_CONTROL_EVENT, next); if (ret != 0) { @@ -138,7 +138,7 @@ static int lcdon_pre(void *data) DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_PRE_CHANGE_STATE, - g_variant_new("(s)", states[S_LCDON].name)); + g_variant_new("(s)", state_st(S_LCDON)->name)); if (ret < 0) _E("Failed to send dbus signal(%s)", SIGNAL_PRE_CHANGE_STATE); /*Give time to process callback */ @@ -156,7 +156,7 @@ static int lcdon_post(void *data) DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_CHANGE_STATE, - g_variant_new("(s)", states[S_LCDON].name)); + g_variant_new("(s)", state_st(S_LCDON)->name)); if (ret < 0) _E("Failed to send dbus signal(%s)", SIGNAL_CHANGE_STATE); @@ -173,7 +173,7 @@ static int lcdon_action(int timeout) if ((get_pm_old_state() != S_LCDOFF) && (get_pm_old_state() != S_SLEEP)) { - _I("pm_old_state (%s). Skip lcd on", states[get_pm_old_state()].name); + _I("pm_old_state (%s). Skip lcd on", state_st(get_pm_old_state())->name); return 0; } @@ -198,7 +198,7 @@ static int lcdon_trans(int evt) /* state transition */ set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDON); - st = &states[get_pm_cur_state()]; + st = state_st(get_pm_cur_state()); if (st->action) st->action(0); @@ -230,7 +230,7 @@ static int lcdoff_post(void *data) DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_CHANGE_STATE, - g_variant_new("(s)", states[S_LCDOFF].name)); + g_variant_new("(s)", state_st(S_LCDOFF)->name)); if (ret < 0) _E("Failed to send dbus signal(%s)", SIGNAL_CHANGE_STATE); @@ -266,7 +266,7 @@ static int lcdoff_trans(int evt) /* state transition */ set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDOFF); - st = &states[get_pm_cur_state()]; + st = state_st(get_pm_cur_state()); if (st->action) st->action(0); @@ -310,7 +310,7 @@ static int standby_post(void *data) DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, SIGNAL_CHANGE_STATE, - g_variant_new("(s)", states[S_STANDBY].name)); + g_variant_new("(s)", state_st(S_STANDBY)->name)); if (ret < 0) _E("Failed to send dbus signal(%s)", SIGNAL_CHANGE_STATE); @@ -372,7 +372,7 @@ static int standby_trans(int evt) /* state transition */ set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_STANDBY); - st = &states[get_pm_cur_state()]; + st = state_st(get_pm_cur_state()); if (st->action) st->action(0); @@ -405,7 +405,7 @@ static int suspend_post(void *data) cond = S_LCDON; ret = tv_proc_change_state(cond, INTERNAL_LOCK_SUSPEND); if (ret < 0) - _E("Fail to change state to next_state(%s)", states[cond].name); + _E("Fail to change state to next_state(%s)", state_st(cond)->name); /* Broadcast pre-wakeup signal */ ret = dbus_handle_emit_dbus_signal(NULL, @@ -441,7 +441,7 @@ static int suspend_action(int timeout) /* system waked up by devices */ set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDOFF); - st = &states[get_pm_cur_state()]; + st = state_st(get_pm_cur_state()); if (st->action) st->action(0); @@ -463,14 +463,14 @@ static int suspend_trans(int evt) /* state transition */ set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_LCDOFF); - st = &states[get_pm_cur_state()]; + st = state_st(get_pm_cur_state()); if (st->action) st->action(0); set_pm_old_state(get_pm_cur_state()); set_pm_cur_state(S_SUSPEND); - st = &states[get_pm_cur_state()]; + st = state_st(get_pm_cur_state()); if (st->action) st->action(0); @@ -500,7 +500,7 @@ static int poweroff_action(int timeout) static int poweroff_trans(int evt) { struct state *st; - st = &states[S_POWEROFF]; + st = state_st(S_POWEROFF); if (st->action) st->action(0); return 0; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index ab576e4..3637314 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -140,7 +140,7 @@ static gboolean del_off_cond(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; -struct state states[S_END] = { +static struct state states[S_END] = { { S_START, "S_START", NULL, NULL, NULL, NULL }, { S_NORMAL, "S_NORMAL", default_trans, default_action, default_check, del_normal_cond }, { S_LCDDIM, "S_LCDDIM", default_trans, default_action, default_check, del_dim_cond }, @@ -219,6 +219,11 @@ struct display_function_info display_info = { .face_detection = NULL, }; +inline struct state *state_st(enum state_t state) +{ + return &states[state]; +} + void change_state_action(enum state_t state, int (*func)(int timeout)) { _I("[%s] 'action' is changed.", states[state].name); diff --git a/plugins/wearable/display/powersaver.c b/plugins/wearable/display/powersaver.c index 6c1de14..785acfa 100644 --- a/plugins/wearable/display/powersaver.c +++ b/plugins/wearable/display/powersaver.c @@ -56,8 +56,8 @@ static int set_powersaver_mode(int mode) backlight_ops->update(); get_run_timeout(&timeout); - states[S_NORMAL].timeout = timeout; - states[get_pm_cur_state()].trans(EVENT_INPUT); + state_st(S_NORMAL)->timeout = timeout; + state_st(get_pm_cur_state())->trans(EVENT_INPUT); return 0; } diff --git a/src/display/auto-brightness.c b/src/display/auto-brightness.c index 1afc48d..e220ec0 100644 --- a/src/display/auto-brightness.c +++ b/src/display/auto-brightness.c @@ -378,7 +378,7 @@ static int disconnect_sensor(void) } if (_default_action != NULL) { - states[S_NORMAL].action = _default_action; + state_st(S_NORMAL)->action = _default_action; _default_action = NULL; } if (alc_timeout_id > 0) { @@ -413,8 +413,8 @@ static int set_autobrightness_state(int status) /* change alc action func */ if (_default_action == NULL) - _default_action = states[S_NORMAL].action; - states[S_NORMAL].action = alc_action; + _default_action = state_st(S_NORMAL)->action; + state_st(S_NORMAL)->action = alc_action; display_info.update_auto_brightness(true); diff --git a/src/display/core.h b/src/display/core.h index d3fded2..712d2cc 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -104,7 +104,8 @@ struct state { GSourceFunc timeout_cb; int timeout; }; -extern struct state states[S_END]; + +struct state *state_st(enum state_t state); /* * @brief Configuration structure diff --git a/src/display/display-lock.c b/src/display/display-lock.c index 088b924..2facaac 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -91,7 +91,7 @@ static void pmlock_check_cb(GVariant *var, void *user_data, GError *err) diff = difftime(now, node->time); CRITICAL_LOG("%s(%d) has held %s lock for a long time(%.0f s).", - app_id, pid, states[state].name + 2, diff); + app_id, pid, state_st(state)->name + 2, diff); ret = dbus_handle_emit_dbus_signal(NULL, DEVICED_PATH_DISPLAY, @@ -253,7 +253,7 @@ int check_lock_condition(enum state_t state) int ret = false; pid_t owner = getpid(); - _D("check holdkey block : state of %s", states[state].name); + _D("check holdkey block : state of %s", state_st(state)->name); DD_LIST_FOREACH(cond_head[state], elem, t) { if (t->pid != owner && t->background == false) { @@ -272,7 +272,7 @@ int check_holdkey_block(enum state_t state) PmLockNode *t = NULL; int ret = 0; - _I("Check holdkey block: state of %s", states[state].name); + _I("Check holdkey block: state of %s", state_st(state)->name); if (custom_holdkey_block == true) { _I("Custom hold key blocked"); @@ -295,7 +295,7 @@ int delete_condition(enum state_t state) dd_list *elem, *next; PmLockNode *t = NULL; - _I("delete condition : state of %s", states[state].name); + _I("delete condition : state of %s", state_st(state)->name); if (!cond_head[state]) return 0; diff --git a/src/display/poll.c b/src/display/poll.c index 279675c..c8a4a59 100644 --- a/src/display/poll.c +++ b/src/display/poll.c @@ -75,7 +75,7 @@ static enum state_t get_state(int s_bits) static bool state_supported(enum state_t st) { - if (states[st].trans) + if (state_st(st)->trans) return true; return false; } -- 2.7.4 From 55b1ce1b1f9c17b672b7f477264cb68af805e5e1 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Fri, 7 Aug 2020 18:29:07 +0900 Subject: [PATCH 14/16] Change display_conf to static Change-Id: I64cc875bd0fb554f297bf95ba6994ffe429c52ef Signed-off-by: Yunmi Ha --- plugins/iot/display/core.c | 7 +++++- plugins/iot/display/device-interface.c | 25 +++++++++++++------- plugins/iot/display/key-filter.c | 11 ++++++--- plugins/mobile/display/core.c | 7 +++++- plugins/mobile/display/device-interface.c | 25 +++++++++++++------- plugins/mobile/display/key-filter.c | 11 ++++++--- plugins/tv/display/core.c | 7 +++++- plugins/tv/display/device-interface.c | 25 +++++++++++++------- plugins/tv/display/key-filter.c | 11 ++++++--- .../wearable/display/auto-brightness-sensorhub.c | 7 +++++- plugins/wearable/display/core.c | 7 +++++- plugins/wearable/display/device-interface.c | 19 +++++++++++---- plugins/wearable/display/key-filter.c | 11 ++++++--- src/display/auto-brightness.c | 27 +++++++++++++--------- src/display/core.h | 2 +- src/display/display-dbus.c | 12 +++++++--- src/display/display-lock.c | 7 +++++- src/display/input.c | 7 +++++- src/display/setting.c | 9 ++++++-- 19 files changed, 172 insertions(+), 65 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index a2e4ae7..6d842c7 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -181,7 +181,7 @@ static int trans_table[S_END][EVENT_END] = { (b.tv_sec * 1000000 + b.tv_usec)) \ / 1000) -struct display_config display_conf = { +static struct display_config display_conf = { .lock_wait_time = LOCK_SCREEN_WATING_TIME, .longpress_interval = LONG_PRESS_INTERVAL, .lightsensor_interval = SAMPLING_INTERVAL, @@ -211,6 +211,11 @@ struct display_function_info display_info = { .face_detection = NULL, }; +inline struct display_config* get_display_config() +{ + return &display_conf; +} + inline struct state* state_st(enum state_t state) { return &states[state]; diff --git a/plugins/iot/display/device-interface.c b/plugins/iot/display/device-interface.c index 49c9172..64e4f1e 100644 --- a/plugins/iot/display/device-interface.c +++ b/plugins/iot/display/device-interface.c @@ -76,6 +76,7 @@ static int default_brightness; static int dpms_running_state = DPMS_SETTING_DONE; static struct display_device *display_dev; static guint release_timer; +static struct display_config *display_conf; inline struct _backlight_ops *get_backlight_ops(void) { @@ -363,7 +364,7 @@ static int backlight_standby(int force) static int set_default_brt(int level) { if (level < PM_MIN_BRIGHTNESS || level > PM_MAX_BRIGHTNESS) - level = display_conf.pm_default_brightness; + level = display_conf->pm_default_brightness; default_brightness = level; @@ -642,7 +643,7 @@ static int backlight_transit_state(int state) if (state == DPMS_OFF) { start = brt; - end = display_conf.aod_enter_level; + end = display_conf->aod_enter_level; /* * The value of backlight_ops.get_brightness is system brightness. @@ -651,19 +652,19 @@ static int backlight_transit_state(int state) */ get_brightness(&val); - if (val > display_conf.aod_enter_level) - backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + 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) { + if (brt != display_conf->aod_enter_level) { _W("effect is already executed brt(%d) aod_level(%d)", - brt, display_conf.aod_enter_level); + brt, display_conf->aod_enter_level); return 0; } - start = display_conf.aod_enter_level; + start = display_conf->aod_enter_level; end = default_brightness; - backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + backlight_ops.transit_brt(start, end, display_conf->brightness_change_step); } return 0; @@ -837,3 +838,11 @@ int exit_sysfs(void) return 0; } + +static void __CONSTRUCTOR__ initialize(void) +{ + display_conf = get_display_config(); + if (!display_conf) + _E("Failed to get display configuration."); +} + diff --git a/plugins/iot/display/key-filter.c b/plugins/iot/display/key-filter.c index d8d4df3..29d7de2 100644 --- a/plugins/iot/display/key-filter.c +++ b/plugins/iot/display/key-filter.c @@ -432,6 +432,11 @@ static int process_power_key(struct input_event *pinput) int ignore = true; static int value = KEY_RELEASED; unsigned int caps; + struct display_config *display_conf = get_display_config(); + if (!display_conf) { + _E("Failed to get display configuration."); + return ignore; + } caps = display_get_caps(DISPLAY_ACTOR_POWER_KEY); @@ -439,7 +444,7 @@ static int process_power_key(struct input_event *pinput) case KEY_RELEASED: check_key_pair(pinput->code, pinput->value, &value); - if (!display_conf.powerkey_doublepress) { + if (!display_conf->powerkey_doublepress) { if (display_has_caps(caps, DISPLAY_CAPA_LCDOFF)) lcdoff_powerkey(); else @@ -475,7 +480,7 @@ static int process_power_key(struct input_event *pinput) if (key_combination == KEY_COMBINATION_POWERKEY) { /* add long key timer */ longkey_timeout_id = g_timeout_add_seconds( - display_conf.longpress_interval, + display_conf->longpress_interval, longkey_pressed_cb, NULL); /* add long key restore timer */ longkey_restore_id = g_timeout_add_seconds( @@ -487,7 +492,7 @@ static int process_power_key(struct input_event *pinput) break; case KEY_BEING_PRESSED: if (timediff_usec(pressed_time, pinput->time) > - (display_conf.longpress_interval * USEC_PER_SEC)) + (display_conf->longpress_interval * USEC_PER_SEC)) longkey_pressed(); break; } diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 13f219f..604135c 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -184,7 +184,7 @@ static int trans_table[S_END][EVENT_END] = { (b.tv_sec * 1000000 + b.tv_usec)) \ / 1000) -struct display_config display_conf = { +static struct display_config display_conf = { .lock_wait_time = LOCK_SCREEN_WATING_TIME, .longpress_interval = LONG_PRESS_INTERVAL, .lightsensor_interval = SAMPLING_INTERVAL, @@ -214,6 +214,11 @@ struct display_function_info display_info = { .face_detection = NULL, }; +inline struct display_config* get_display_config() +{ + return &display_conf; +} + inline struct state* state_st(enum state_t state) { return &states[state]; diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 054e181..9b37f8b 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -75,6 +75,7 @@ static int default_brightness; static int dpms_running_state = DPMS_SETTING_DONE; static struct display_device *display_dev; static guint release_timer; +static struct display_config *display_conf; inline struct _backlight_ops *get_backlight_ops(void) { @@ -362,7 +363,7 @@ static int backlight_standby(int force) static int set_default_brt(int level) { if (level < PM_MIN_BRIGHTNESS || level > PM_MAX_BRIGHTNESS) - level = display_conf.pm_default_brightness; + level = display_conf->pm_default_brightness; default_brightness = level; @@ -641,7 +642,7 @@ static int backlight_transit_state(int state) if (state == DPMS_OFF) { start = brt; - end = display_conf.aod_enter_level; + end = display_conf->aod_enter_level; /* * The value of backlight_ops.get_brightness is system brightness. @@ -650,19 +651,19 @@ static int backlight_transit_state(int state) */ get_brightness(&val); - if (val > display_conf.aod_enter_level) - backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + 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) { + if (brt != display_conf->aod_enter_level) { _W("effect is already executed brt(%d) aod_level(%d)", - brt, display_conf.aod_enter_level); + brt, display_conf->aod_enter_level); return 0; } - start = display_conf.aod_enter_level; + start = display_conf->aod_enter_level; end = default_brightness; - backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + backlight_ops.transit_brt(start, end, display_conf->brightness_change_step); } return 0; @@ -852,3 +853,11 @@ int exit_sysfs(void) return 0; } + +static void __CONSTRUCTOR__ initialize(void) +{ + display_conf = get_display_config(); + if (!display_conf) + _E("Failed to get display configuration."); +} + diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index b5fdf71..4aead39 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -452,6 +452,11 @@ static int process_power_key(struct input_event *pinput) int ignore = true; static int value = KEY_RELEASED; unsigned int caps; + struct display_config *display_conf = get_display_config(); + if (!display_conf) { + _E("Failed to get display configuration."); + return ignore; + } caps = display_get_caps(DISPLAY_ACTOR_POWER_KEY); @@ -459,7 +464,7 @@ static int process_power_key(struct input_event *pinput) case KEY_RELEASED: check_key_pair(pinput->code, pinput->value, &value); - if (!display_conf.powerkey_doublepress) { + if (!display_conf->powerkey_doublepress) { if (display_has_caps(caps, DISPLAY_CAPA_LCDOFF)) lcdoff_powerkey(); else @@ -508,7 +513,7 @@ static int process_power_key(struct input_event *pinput) if (key_combination == KEY_COMBINATION_POWERKEY) { /* add long key timer */ longkey_timeout_id = g_timeout_add( - display_conf.longpress_interval, + display_conf->longpress_interval, longkey_pressed_cb, NULL); /* add long key restore timer */ longkey_restore_id = g_timeout_add_seconds( @@ -520,7 +525,7 @@ static int process_power_key(struct input_event *pinput) break; case KEY_BEING_PRESSED: if (timediff_usec(pressed_time, pinput->time) > - (display_conf.longpress_interval * USEC_PER_MSEC)) + (display_conf->longpress_interval * USEC_PER_MSEC)) longkey_pressed(); break; } diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 6220f09..4d85fcd 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -182,7 +182,7 @@ static int trans_table[S_END][EVENT_END] = { (b.tv_sec * 1000000 + b.tv_usec)) \ / 1000) -struct display_config display_conf = { +static struct display_config display_conf = { .lock_wait_time = LOCK_SCREEN_WATING_TIME, .longpress_interval = LONG_PRESS_INTERVAL, .lightsensor_interval = SAMPLING_INTERVAL, @@ -212,6 +212,11 @@ struct display_function_info display_info = { .face_detection = NULL, }; +inline struct display_config* get_display_config() +{ + return &display_conf; +} + inline struct state* state_st(enum state_t state) { return &states[state]; diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 28c4075..469b793 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -76,6 +76,7 @@ static int default_brightness; static int dpms_running_state = DPMS_SETTING_DONE; static struct display_device *display_dev; static guint release_timer; +static struct display_config *display_conf; inline struct _backlight_ops *get_backlight_ops(void) { @@ -363,7 +364,7 @@ static int backlight_standby(int force) static int set_default_brt(int level) { if (level < PM_MIN_BRIGHTNESS || level > PM_MAX_BRIGHTNESS) - level = display_conf.pm_default_brightness; + level = display_conf->pm_default_brightness; default_brightness = level; @@ -642,7 +643,7 @@ static int backlight_transit_state(int state) if (state == DPMS_OFF) { start = brt; - end = display_conf.aod_enter_level; + end = display_conf->aod_enter_level; /* * The value of backlight_ops.get_brightness is system brightness. @@ -651,19 +652,19 @@ static int backlight_transit_state(int state) */ get_brightness(&val); - if (val > display_conf.aod_enter_level) - backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + 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) { + if (brt != display_conf->aod_enter_level) { _W("effect is already executed brt(%d) aod_level(%d)", - brt, display_conf.aod_enter_level); + brt, display_conf->aod_enter_level); return 0; } - start = display_conf.aod_enter_level; + start = display_conf->aod_enter_level; end = default_brightness; - backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + backlight_ops.transit_brt(start, end, display_conf->brightness_change_step); } return 0; @@ -838,3 +839,11 @@ int exit_sysfs(void) return 0; } + +static void __CONSTRUCTOR__ initialize(void) +{ + display_conf = get_display_config(); + if (!display_conf) + _E("Failed to get display configuration."); +} + diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 7abfd2f..24757b2 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -432,6 +432,11 @@ static int process_power_key(struct input_event *pinput) int ignore = true; static int value = KEY_RELEASED; unsigned int caps; + struct display_config *display_conf = get_display_config(); + if(!display_conf) { + _E("Failed to get display configuration."); + return ignore; + } caps = display_get_caps(DISPLAY_ACTOR_POWER_KEY); @@ -439,7 +444,7 @@ static int process_power_key(struct input_event *pinput) case KEY_RELEASED: check_key_pair(pinput->code, pinput->value, &value); - if (!display_conf.powerkey_doublepress) { + if (!display_conf->powerkey_doublepress) { if (display_has_caps(caps, DISPLAY_CAPA_LCDOFF)) lcdoff_powerkey(); else @@ -475,7 +480,7 @@ static int process_power_key(struct input_event *pinput) if (key_combination == KEY_COMBINATION_POWERKEY) { /* add long key timer */ longkey_timeout_id = g_timeout_add_seconds( - display_conf.longpress_interval, + display_conf->longpress_interval, longkey_pressed_cb, NULL); /* add long key restore timer */ longkey_restore_id = g_timeout_add_seconds( @@ -487,7 +492,7 @@ static int process_power_key(struct input_event *pinput) break; case KEY_BEING_PRESSED: if (timediff_usec(pressed_time, pinput->time) > - (display_conf.longpress_interval * USEC_PER_SEC)) + (display_conf->longpress_interval * USEC_PER_SEC)) longkey_pressed(); break; } diff --git a/plugins/wearable/display/auto-brightness-sensorhub.c b/plugins/wearable/display/auto-brightness-sensorhub.c index c2e1773..e5a5004 100644 --- a/plugins/wearable/display/auto-brightness-sensorhub.c +++ b/plugins/wearable/display/auto-brightness-sensorhub.c @@ -43,8 +43,13 @@ static bool lbm, hbm, hold_brt, lowdim; static void change_brightness_transit(int start, int end) { + struct display_config *display_conf = get_display_config(); + if(!display_conf) { + _E("Failed to get display configuration."); + return ; + } backlight_ops->transit_brt(start, end, - display_conf.brightness_change_step); + display_conf->brightness_change_step); } static void set_brightness_level(int level) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 3637314..9cf31dd 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -189,7 +189,7 @@ static int trans_table[S_END][EVENT_END] = { (b.tv_sec * 1000000 + b.tv_usec)) \ / 1000) -struct display_config display_conf = { +static struct display_config display_conf = { .lock_wait_time = LOCK_SCREEN_WATING_TIME, .longpress_interval = LONG_PRESS_INTERVAL, .lightsensor_interval = SAMPLING_INTERVAL, @@ -219,6 +219,11 @@ struct display_function_info display_info = { .face_detection = NULL, }; +inline struct display_config *get_display_config() +{ + return &display_conf; +} + inline struct state *state_st(enum state_t state) { return &states[state]; diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index dd1a03f..83dcb2c 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -84,6 +84,7 @@ static int aod_max_level = -1; static int aod_normal_level = -1; static int aod_min_level = -1; static int aod_charging_level = -1; +static struct display_config *display_conf; inline struct _backlight_ops *get_backlight_ops(void) { @@ -370,7 +371,7 @@ static int backlight_standby(int force) static int set_default_brt(int level) { if (level < PM_MIN_BRIGHTNESS || level > PM_MAX_BRIGHTNESS) - level = display_conf.pm_default_brightness; + level = display_conf->pm_default_brightness; default_brightness = level; @@ -702,7 +703,7 @@ static int backlight_transit_state(int state) else if (aod_min_level > 0 && val >= aod_min_level) aod_brightness_level = aod_min_level; else - aod_brightness_level = display_conf.aod_enter_level; + aod_brightness_level = display_conf->aod_enter_level; } else { if (aod_max_level > 0 && val >= aod_max_level) aod_brightness_level = aod_max_level; @@ -711,12 +712,12 @@ static int backlight_transit_state(int state) else if (aod_min_level > 0 && val >= aod_min_level) aod_brightness_level = aod_min_level; else - aod_brightness_level = display_conf.aod_enter_level; + aod_brightness_level = display_conf->aod_enter_level; } if (val > aod_brightness_level) { _D("backlight transit start %d end %d DPMS OFF", start, aod_brightness_level); - backlight_ops.transit_brt(start, aod_brightness_level, display_conf.brightness_change_step); + backlight_ops.transit_brt(start, aod_brightness_level, display_conf->brightness_change_step); } } else { /* prevent transit effect when another effect is already executed */ @@ -729,7 +730,7 @@ static int backlight_transit_state(int state) start = aod_brightness_level; end = default_brightness; _D("backlight transit start %d end %d DPMS ON", start, end); - backlight_ops.transit_brt(start, end, display_conf.brightness_change_step); + backlight_ops.transit_brt(start, end, display_conf->brightness_change_step); } return 0; @@ -916,3 +917,11 @@ int exit_sysfs(void) return 0; } + +static void __CONSTRUCTOR__ initialize(void) +{ + display_conf = get_display_config(); + if (!display_conf) + _E("Failed to get display configuration."); +} + diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 26ecf11..3cf379f 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -429,6 +429,11 @@ static int process_power_key(struct input_event *pinput) int ignore = true; static int value = KEY_RELEASED; unsigned int caps; + struct display_config *display_conf = get_display_config(); + if (!display_conf) { + _E("Failed to get display configuration."); + return ignore; + } caps = display_get_caps(DISPLAY_ACTOR_POWER_KEY); @@ -436,7 +441,7 @@ static int process_power_key(struct input_event *pinput) case KEY_RELEASED: check_key_pair(pinput->code, pinput->value, &value); - if (!display_conf.powerkey_doublepress) { + if (!display_conf->powerkey_doublepress) { if (display_has_caps(caps, DISPLAY_CAPA_LCDOFF)) lcdoff_powerkey(); else @@ -472,7 +477,7 @@ static int process_power_key(struct input_event *pinput) if (key_combination == KEY_COMBINATION_POWERKEY) { /* add long key timer */ longkey_timeout_id = g_timeout_add( - display_conf.longpress_interval, + display_conf->longpress_interval, longkey_pressed_cb, NULL); /* add long key restore timer */ longkey_restore_id = g_timeout_add_seconds( @@ -484,7 +489,7 @@ static int process_power_key(struct input_event *pinput) break; case KEY_BEING_PRESSED: if (timediff_usec(pressed_time, pinput->time) > - (display_conf.longpress_interval * USEC_PER_MSEC)) + (display_conf->longpress_interval * USEC_PER_MSEC)) longkey_pressed(); break; } diff --git a/src/display/auto-brightness.c b/src/display/auto-brightness.c index e220ec0..e8b1621 100644 --- a/src/display/auto-brightness.c +++ b/src/display/auto-brightness.c @@ -73,6 +73,7 @@ static char *min_brightness_name = 0; /* light sensor */ static float lmax, lmin; +static struct display_config *display_conf; static bool update_working_position(void) { @@ -80,7 +81,7 @@ static bool update_working_position(void) int ret; float x, y, z, pitch, realg; - if (!display_conf.accel_sensor_on) + if (!display_conf->accel_sensor_on) return false; ret = sensor_listener_read_data(accel_listener, &data); @@ -119,7 +120,7 @@ static void alc_set_brightness(int setting, int value, float light) if (tmp_value != value) { if (!setting && min_brightness == PM_MIN_BRIGHTNESS && - display_conf.accel_sensor_on == true) { + display_conf->accel_sensor_on == true) { position = update_working_position(); if (!position && (old > light)) { _D("It's not working position, " @@ -130,11 +131,11 @@ static void alc_set_brightness(int setting, int value, float light) int diff, step; diff = value - tmp_value; - if (abs(diff) < display_conf.brightness_change_step) + if (abs(diff) < display_conf->brightness_change_step) step = (diff > 0 ? 1 : -1); else step = (int)ceil(diff / - (float)display_conf.brightness_change_step); + (float)display_conf->brightness_change_step); _D("%d", step); while (tmp_value != value) { @@ -205,7 +206,7 @@ static bool alc_update_brt(bool setting) fault_count = 0; - if (display_conf.continuous_sampling && + if (display_conf->continuous_sampling && !check_brightness_changed(value) && !setting) return true; @@ -257,7 +258,7 @@ static int alc_action(int timeout) display_info.update_auto_brightness(true); alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, + g_timeout_add_seconds(display_conf->lightsensor_interval, alc_handler, NULL); } @@ -319,7 +320,7 @@ static int connect_sensor(void) goto error; } - if (!display_conf.accel_sensor_on) + if (!display_conf->accel_sensor_on) goto success; /* accelerometer sensor */ @@ -352,7 +353,7 @@ error: sensor_destroy_listener(light_listener); light_listener = 0; } - if (display_conf.accel_sensor_on && accel_listener > 0) { + if (display_conf->accel_sensor_on && accel_listener > 0) { sensor_listener_stop(accel_listener); sensor_destroy_listener(accel_listener); accel_listener = 0; @@ -371,7 +372,7 @@ static int disconnect_sensor(void) } /* accelerometer sensor*/ - if (display_conf.accel_sensor_on && accel_listener > 0) { + if (display_conf->accel_sensor_on && accel_listener > 0) { sensor_listener_stop(accel_listener); sensor_destroy_listener(accel_listener); accel_listener = 0; @@ -419,7 +420,7 @@ static int set_autobrightness_state(int status) display_info.update_auto_brightness(true); alc_timeout_id = - g_timeout_add_seconds(display_conf.lightsensor_interval, + g_timeout_add_seconds(display_conf->lightsensor_interval, alc_handler, NULL); } else if (status == SETTING_BRIGHTNESS_AUTOMATIC_PAUSE) { _I("Auto brightness paused."); @@ -432,7 +433,7 @@ static int set_autobrightness_state(int status) ret = get_setting_brightness(&default_brt); if (ret != 0 || (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS)) { _I("Failed to read vconf value for brightness."); - brt = display_conf.pm_default_brightness; + brt = display_conf->pm_default_brightness; if (default_brt < PM_MIN_BRIGHTNESS || default_brt > PM_MAX_BRIGHTNESS) { ret = vconf_set_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, brt); if (ret < 0) @@ -686,4 +687,8 @@ static void __CONSTRUCTOR__ initialize(void) backlight_ops = get_backlight_ops(); if (!backlight_ops) _E("Failed to get backlight operator."); + + display_conf = get_display_config(); + if (!display_conf) + _E("Failed to get display configuration."); } diff --git a/src/display/core.h b/src/display/core.h index 712d2cc..caa97dc 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -138,7 +138,7 @@ struct display_config { * Global variables * display_conf : configuration of display */ -extern struct display_config display_conf; +struct display_config* get_display_config(); /* * @brief Display Extension features diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index a808ca0..7dbb69a 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -614,21 +614,27 @@ static GVariant *dbus_setrefreshrate(GDBusConnection *conn, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) { int app, val, ret, control; + struct display_config *display_conf = get_display_config(); + if (!display_conf) { + _E("Failed to get display configuration."); + ret = -EINVAL; + goto error; + } g_variant_get(param, "(ii)", &app, &val); - if (app < 0 || app >= ARRAY_SIZE(display_conf.framerate_app) || val < 0) { + if (app < 0 || app >= ARRAY_SIZE(display_conf->framerate_app) || val < 0) { ret = -EINVAL; goto error; } - if (!display_conf.framerate_app[app]) { + if (!display_conf->framerate_app[app]) { _I("This case(%d) is not support in this target", app); ret = -EPERM; goto error; } - control = display_conf.control_display; + control = display_conf->control_display; if (control) backlight_ops->off(NORMAL_MODE); diff --git a/src/display/display-lock.c b/src/display/display-lock.c index 2facaac..4450a76 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -188,6 +188,11 @@ PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, PmLockNode *n; GVariant *v = NULL; time_t now; + struct display_config *display_conf = get_display_config(); + if (!display_conf) { + _E("Failed to get display configuration."); + return NULL; + } n = (PmLockNode *) malloc(sizeof(PmLockNode)); if (n == NULL) { @@ -198,7 +203,7 @@ PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, if (pid < INTERNAL_LOCK_BASE) { v = g_variant_new("(ii)", s_index, pid); if (v) { - warning_id = g_timeout_add_seconds(display_conf.lockcheck_timeout, + warning_id = g_timeout_add_seconds(display_conf->lockcheck_timeout, pmlock_check, (void *)v); } else { _E("Failed to make GVariant."); diff --git a/src/display/input.c b/src/display/input.c index a55d05b..b985652 100644 --- a/src/display/input.c +++ b/src/display/input.c @@ -44,6 +44,11 @@ static inline void process_event(struct libinput_event *ev) struct libinput_event_keyboard *k; unsigned int time; int fd = 0; + struct display_config *display_conf = get_display_config(); + if(!display_conf) { + _E("Failed to get display configuration."); + return; + } if (!pm_callback) return; @@ -92,7 +97,7 @@ static inline void process_event(struct libinput_event *ev) break; case LIBINPUT_EVENT_TOUCH_MOTION: case LIBINPUT_EVENT_TOUCH_FRAME: - if (touch_event_blocked() && !ambient_get_state() && !display_conf.touch_wakeup) + if (touch_event_blocked() && !ambient_get_state() && !display_conf->touch_wakeup) return; input.type = EV_ABS; input.value = KEY_BEING_PRESSED; diff --git a/src/display/setting.c b/src/display/setting.c index 0552001..e493c7f 100644 --- a/src/display/setting.c +++ b/src/display/setting.c @@ -48,6 +48,7 @@ static int force_lcdtimeout = 0; static int custom_on_timeout = 0; static int custom_normal_timeout = 0; static int custom_dim_timeout = 0; +static struct display_config *display_conf; int (*update_pm_setting) (int key_idx, int val); @@ -147,7 +148,7 @@ void get_dim_timeout(int *dim_timeout) return; } - if (!display_conf.dimming || ambient_get_condition()) { + if (!display_conf->dimming || ambient_get_condition()) { *dim_timeout = LCD_MIN_DIM_TIMEOUT; return; } @@ -214,7 +215,7 @@ int set_custom_lcdon_timeout(int timeout) return changed; } - if (display_conf.dimming) + if (display_conf->dimming) custom_dim_timeout = (double)timeout * LCD_DIM_RATIO; else custom_dim_timeout = LCD_MIN_DIM_TIMEOUT; @@ -281,4 +282,8 @@ static void __CONSTRUCTOR__ initialize(void) if (!disp_plgn) { _E("Failed to get display plugin."); } + + display_conf = get_display_config(); + if (!display_conf) + _E("Failed to get display configuration."); } -- 2.7.4 From 1d73ac2e0003a531a7014337a246c192f40f6447 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 20 Aug 2020 13:45:08 +0900 Subject: [PATCH 15/16] Fix display not to go into AOD when poweroff Change-Id: Ie57cc79a23eb20b948e8bdf54ce6acadcd1474b6 Signed-off-by: Youngjae Cho --- src/power/power-handler.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 4376b57..c00b17f 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -136,9 +136,7 @@ static void disable_display(void) { const struct device_ops *display_device_ops = NULL; FIND_DEVICE_VOID(display_device_ops, "display"); - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(INTERNAL_LOCK_POWEROFF, LCD_OFF); - display_device_ops->exit(NULL); + display_device_ops->stop(NORMAL_MODE); } static int disable_systemd_journald(void) -- 2.7.4 From fdd07fc33a1cfd218f4a069589d4b5f25095ce5a Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 21 Aug 2020 15:48:51 +0900 Subject: [PATCH 16/16] Add internal CAPIs to auto test ex) device_touchscreen_disable device_touchscreen_enable device_display_get_brightness_state device_display_get_max_brightness_state device_display_set_brightness_state device_display_change_state_by_reason device_multi_led_get_number device_multi_led_control device_battery_get_info_direct device_pmqos_app_launch_home device_pmqos_homescreen device_get_reboot_mode Change-Id: I3f45437591ed29c9477851b138d51d9fd5864295 Signed-off-by: lokilee73 --- src/auto-test/CMakeLists.txt | 7 ++ src/auto-test/auto-test.conf | 12 ++++ src/auto-test/battery.c | 16 +++++ src/auto-test/boot.c | 86 +++++++++++++++++++++++++ src/auto-test/display.c | 150 ++++++++++++++++++++++--------------------- src/auto-test/led.c | 30 +++++++++ src/auto-test/pmqos.c | 99 ++++++++++++++++++++++++++++ src/auto-test/test.c | 53 +++++++++++++++ src/auto-test/test.h | 5 ++ src/auto-test/touchscreen.c | 99 ++++++++++++++++++++++++++++ 10 files changed, 484 insertions(+), 73 deletions(-) create mode 100644 src/auto-test/boot.c create mode 100644 src/auto-test/pmqos.c create mode 100644 src/auto-test/touchscreen.c diff --git a/src/auto-test/CMakeLists.txt b/src/auto-test/CMakeLists.txt index 5623865..3631df5 100644 --- a/src/auto-test/CMakeLists.txt +++ b/src/auto-test/CMakeLists.txt @@ -25,8 +25,15 @@ SET(SRCS battery-monitor-test.c udev.c brightness.c + boot.c + touchscreen.c + pmqos.c ) +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED + capi-system-device) + FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) diff --git a/src/auto-test/auto-test.conf b/src/auto-test/auto-test.conf index 6ae9444..c7fa510 100644 --- a/src/auto-test/auto-test.conf +++ b/src/auto-test/auto-test.conf @@ -1,4 +1,5 @@ [mobile] +booting=1 battery-monitor=0 battery=1 display=1 @@ -9,8 +10,11 @@ extcon=1 ir=1 time=1 udev=1 +touchscreen=1 +pmqos=1 [wearable] +booting=1 battery-monitor=1 battery=1 display=1 @@ -22,8 +26,11 @@ extcon=1 ir=0 time=1 udev=1 +touchscreen=1 +pmqos=1 [tv] +booting=0 battery-monitor=0 battery=0 display=1 @@ -34,8 +41,11 @@ extcon=1 ir=0 time=1 udev=1 +touchscreen=0 +pmqos=0 [common] +booting=1 battery-monitor=0 battery=0 display=1 @@ -46,3 +56,5 @@ extcon=1 ir=0 time=1 udev=1 +touchscreen=1 +pmqos=1 \ No newline at end of file diff --git a/src/auto-test/battery.c b/src/auto-test/battery.c index ebb3bd2..4ebf33e 100644 --- a/src/auto-test/battery.c +++ b/src/auto-test/battery.c @@ -18,6 +18,7 @@ #include #include "test.h" #include +#include #define METHOD_BATTERY_TIMETOFULL "TimeToFull" #define METHOD_BATTERY_TIMETOEMPTY "TimeToEmpty" @@ -31,6 +32,7 @@ #define METHOD_BATTERY_ISFULL "IsFull" #define METHOD_BATTERY_HEALTH "GetHealth" #define METHOD_BATTERY_GETINFO "GetBatteryInfo" +#define METHOD_BATTERY_GETINFO_DIRECT "GetBatteryInfoDirect" #define METHOD_BATTERY_POWERSUPPLY "power_supply" #define METHOD_BATTERY_GET_POWERSUPPLY "get_power_supply" @@ -441,6 +443,15 @@ static bool get_battery_info() return ret; } +static bool get_battery_info_direct(struct device_battery_info *info) +{ + int ret; + + ret = device_battery_get_info_direct(info); + + return capi_result(METHOD_BATTERY_GETINFO_DIRECT, ret); +} + static int change_charge_status_to_enum(const char *env_value) { int len, ret; @@ -846,6 +857,7 @@ void battery_test_all(int *success, int *fail) int f = 0; int rsp[12]; char *power_source = NULL; + struct device_battery_info info; (get_battery_time_to_full()) ? s++ : f++; (get_battery_time_to_empty()) ? s++ : f++; @@ -860,6 +872,7 @@ void battery_test_all(int *success, int *fail) (get_battery_is_full()) ? s++ : f++; (get_battery_health()) ? s++ : f++; (get_battery_info()) ? s++ : f++; + (get_battery_info_direct(&info)) ? s++ : f++; for (int index = 0; index < ARRAY_SIZE(power_supply_types); index++) { (set_battery_power_supply(index) && @@ -894,6 +907,7 @@ static int battery_unit(int argc, char **argv) { int rsp[12]; char *power_source = NULL; + struct device_battery_info info; if (argc < 4) { int success = 0; @@ -925,6 +939,8 @@ static int battery_unit(int argc, char **argv) get_battery_health(); } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_GETINFO)) { get_battery_info(); + } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_GETINFO_DIRECT)) { + get_battery_info_direct(&info); } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_POWERSUPPLY)) { for (int index = 0; index < ARRAY_SIZE(power_supply_types); index++) { set_battery_power_supply(index); diff --git a/src/auto-test/boot.c b/src/auto-test/boot.c new file mode 100644 index 0000000..d589f8c --- /dev/null +++ b/src/auto-test/boot.c @@ -0,0 +1,86 @@ +/* + * test + * + * Copyright (c) 2020 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 "test.h" +#include + +#define METHOD_GET_REBOOT_MODE "GetRebootMode" + +static bool get_reboot_mode(void) +{ + int ret; + + ret = device_get_reboot_mode(); + + return capi_reboot_result(METHOD_GET_REBOOT_MODE, ret); +} + +static void booting_test_all(int *success, int *fail) +{ + int s = 0; + int f = 0; + + (get_reboot_mode()) ? s++ : f++; + + if (NULL != success) *success = s; + if (NULL != fail) *fail = f; +} + +static void booting_init(void *data) +{ + int success = 0; + int fail = 0; + + _I("start test"); + + booting_test_all(&success, &fail); + + _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail); +} + +static void booting_exit(void *data) +{ + _I("end test"); +} + +static int booting_unit(int argc, char **argv) +{ + if (argc < 4) { + int success = 0; + int fail = 0; + + _I("start test"); + booting_test_all(&success, &fail); + _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail); + } else if (0 == strcasecmp(argv[3], METHOD_GET_REBOOT_MODE)) { + get_reboot_mode(); + } else { + _E("Unknown test case!!!"); + } + + return 0; +} + +static const struct test_ops booting_test_ops = { + .priority = TEST_PRIORITY_NORMAL, + .name = "booting", + .init = booting_init, + .exit = booting_exit, + .unit = booting_unit, +}; + +TEST_OPS_REGISTER(&booting_test_ops) diff --git a/src/auto-test/display.c b/src/auto-test/display.c index 9b5e2f3..c2494f5 100644 --- a/src/auto-test/display.c +++ b/src/auto-test/display.c @@ -18,7 +18,7 @@ #include #include #include - +#include #include "test.h" @@ -49,8 +49,10 @@ #define METHOD_DISPLAY_ACTORCONTROL "ActorControl" #define METHOD_DISPLAY_START "start" #define METHOD_DISPLAY_STOP "stop" +#define METHOD_CHANGE_STATE_BY_REASON "ChangeStateByReason" #define PM_STATE_LOG_FILE "/var/log/pm_state.log" +#define PALM_STR "palm" static bool get_display_method(const char *method, GVariant *param, int *value) { @@ -129,70 +131,6 @@ static bool set_display_method_noreply(const char *method, GVariant *var) return TRUE; } -static bool get_display_brightness(int *brightness) -{ - return get_display_method(METHOD_DISPLAY_GETBRIGHTNESS, g_variant_new("(i)", 0), brightness); -} - -static bool set_display_brightness(int brightness) -{ - GVariant *msg; - int getbrightness = -1; - int val = 0; - bool ret = FALSE; - - msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, - DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - METHOD_DISPLAY_SETBRIGHTNESS, - g_variant_new("(ii)", 0, brightness)); - if (!msg) { - _E("fail : no reply"); - return ret; - } - - if (!dh_get_param_from_var(msg, "(i)", &val)) { - _E("fail : no message"); - goto out; - } - - if (0 != val) { //setbrightness fail - if ((brightness <= 0) && (val == -EPERM)) { - _I("success : can't set brightness (%d) lower than zero", brightness); - ret = TRUE; - } else if (val == -EPERM) { - _E("fail : please check display api capability or brightness_automatic setting."); - } else { - _E("fail : return fail %d", val); - } - goto out; - } else { - if (brightness <= 0) { - _E("fail : can't set brightness (%d) lower than zero, but returned success", brightness); - goto out; - } - } - - if (!get_display_brightness(&getbrightness)) { - _E("fail : can't get brightness"); - } else { - if (brightness == getbrightness) { - _I("success : %d", getbrightness); - ret = TRUE; - } else { - _E("fail : set brightness %d, but current brightness is %d", brightness, getbrightness); - } - } -out: - g_variant_unref(msg); - return ret; -} - -static bool get_display_maxbrightness() -{ - return get_display_method(METHOD_DISPLAY_GETMAXBRIGHTNESS, g_variant_new("(i)", 0), NULL); -} - static bool set_display_maxbrightness(int brightness) { return set_display_method(METHOD_DISPLAY_SETMAXBRIGHTNESS, g_variant_new("(i)", brightness)); @@ -414,6 +352,61 @@ static bool set_display_actorcontrol(char *command, int actor, int caps) return set_display_method(METHOD_DISPLAY_ACTORCONTROL, g_variant_new("(sii)", command, actor, caps)); } +static bool get_display_brightness_state(display_state_e state, int *brightness) +{ + int ret; + + ret = device_display_get_brightness_state(0, state, brightness); + + return capi_result(METHOD_DISPLAY_GETBRIGHTNESS, ret); +} + +static bool get_display_max_brightness_state(display_state_e state, int *brightness) +{ + int ret; + + ret = device_display_get_max_brightness_state(0, state, brightness); + + return capi_result(METHOD_DISPLAY_GETMAXBRIGHTNESS, ret); +} + +static bool set_display_brightness_state(display_state_e state, int brightness) +{ + int ret; + int getbrightness; + + ret = device_display_set_brightness_state(0, state, brightness); + if (!capi_result(METHOD_DISPLAY_SETBRIGHTNESS, ret)) + return FALSE; + + if (state == DISPLAY_STATE_NORMAL) + set_display_changestate("lcdon"); + else if (state == DISPLAY_STATE_SCREEN_DIM) + set_display_changestate("lcddim"); + else { + _E("fail: unknown state(%d)", state); + return FALSE; + } + + ret = device_display_get_brightness_state(0, state, &getbrightness); + if (!capi_result(METHOD_DISPLAY_SETBRIGHTNESS, ret)) + return FALSE; + + if (brightness != getbrightness) + return FALSE; + + return TRUE; +} + +static bool set_display_state_by_reason(display_state_e type, const char *reason, int timeout, device_dbus_pending_cb cb) +{ + int ret; + + ret = device_display_change_state_by_reason(type, reason, timeout, cb); + + return capi_result(METHOD_CHANGE_STATE_BY_REASON, ret); +} + static bool set_display_start() { return set_display_method_noreply(METHOD_DISPLAY_START, NULL); @@ -428,11 +421,14 @@ void display_test_all(int *success, int *fail) { int s = 0; int f = 0; - - (get_display_brightness(NULL)) ? s++ : f++; - (set_display_brightness(67)) ? s++ : f++; - (set_display_brightness(0)) ? s++ : f++; - (get_display_maxbrightness()) ? s++ : f++; + int brt = 0; + + (get_display_brightness_state(DISPLAY_STATE_NORMAL, &brt)) ? s++ : f++; + (get_display_brightness_state(DISPLAY_STATE_SCREEN_DIM, &brt)) ? s++ : f++; + (set_display_brightness_state(DISPLAY_STATE_NORMAL, 100)) ? s++ : f++; + (set_display_brightness_state(DISPLAY_STATE_SCREEN_DIM, 1)) ? s++ : f++; + (get_display_max_brightness_state(DISPLAY_STATE_NORMAL, &brt)) ? s++ : f++; + (get_display_max_brightness_state(DISPLAY_STATE_SCREEN_DIM, &brt)) ? s++ : f++; (set_display_maxbrightness(80)) ? s++ : f++; //not support, always success. (set_display_holdbrightness(30)) ? s++ : f++; (set_display_releasebrightness()) ? s++ : f++; @@ -462,6 +458,7 @@ void display_test_all(int *success, int *fail) (set_display_actorcontrol("reset", 4, 1<<3)) ? s++ : f++; (set_display_stop()) ? s++ : f++; (set_display_start()) ? s++ : f++; + (set_display_state_by_reason(DISPLAY_STATE_SCREEN_OFF, PALM_STR, 0, __cb)) ? s++ : f++; if (NULL != success) *success = s; if (NULL != fail) *fail = f; @@ -487,6 +484,8 @@ static void display_exit(void *data) static int display_unit(int argc, char **argv) { + int brt = 0; + if (argc < 4) { int success = 0; int fail = 0; @@ -494,11 +493,14 @@ static int display_unit(int argc, char **argv) display_test_all(&success, &fail); _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail); } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_GETBRIGHTNESS)) { - get_display_brightness(NULL); + get_display_brightness_state(DISPLAY_STATE_NORMAL, &brt); + get_display_brightness_state(DISPLAY_STATE_SCREEN_DIM, &brt); } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_SETBRIGHTNESS)) { - set_display_brightness(atoi(argv[4])); + set_display_brightness_state(DISPLAY_STATE_NORMAL, 100); + set_display_brightness_state(DISPLAY_STATE_SCREEN_DIM, 1); } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_GETMAXBRIGHTNESS)) { - get_display_maxbrightness(); + get_display_max_brightness_state(DISPLAY_STATE_NORMAL, &brt); + get_display_max_brightness_state(DISPLAY_STATE_SCREEN_DIM, &brt); } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_SETMAXBRIGHTNESS)) { set_display_maxbrightness(atoi(argv[4])); } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_HOLDBRIGHTNESS)) { @@ -519,6 +521,8 @@ static int display_unit(int argc, char **argv) // set_display_lockstate_nopt(argv[4], argv[5], argv[6], atoi(argv[7])); // } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_UNLOCKSTATE)) { // set_display_lockstate_nopt(argv[4], argv[5]); + } else if (0 == strcasecmp(argv[3], METHOD_CHANGE_STATE_BY_REASON)) { + set_display_state_by_reason(DISPLAY_STATE_SCREEN_OFF, PALM_STR, 0, __cb); } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_SETLCDTIMEOUT)) { set_display_lcdtimeout(atoi(argv[4]), atoi(argv[5]), atoi(argv[6])); } else if (0 == strcasecmp(argv[3], METHOD_DISPLAY_CUSTOMLCDON)) { diff --git a/src/auto-test/led.c b/src/auto-test/led.c index 79cfae3..7e4356d 100644 --- a/src/auto-test/led.c +++ b/src/auto-test/led.c @@ -19,6 +19,7 @@ #include "test.h" #include +#include #define METHOD_LED_PLAYCUSTOM "playcustom" #define METHOD_LED_STOPCUSTOM "stopcustom" @@ -26,12 +27,16 @@ #define METHOD_LED_GETBRIGHTNESS "GetBrightness" #define METHOD_LED_GETMAXBRIGHTNESS "GetMaxBrightness" #define METHOD_LED_SETBRIGHTNESS "SetBrightness" +#define METHOD_MULTI_LED_GETNUMBER "GetNumOfLeds" +#define METHOD_MULTI_LED_CONTROL "MultiLedControl" #define RED 0xff0000 #define GREEN 0x00ff00 #define BLUE 0x0000ff #define DEFAULT_FLAG (1 << 0) +static unsigned int color[] = {BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE}; + static bool get_led_method(const char *method) { GVariant *msg; @@ -116,6 +121,25 @@ static bool set_led_stopcustom() return set_led_method(METHOD_LED_STOPCUSTOM, NULL); } +static bool get_multi_led_number(void) +{ + int ret; + int number_of_led; + + ret = device_multi_led_get_number(&number_of_led); + + return capi_result(METHOD_MULTI_LED_GETNUMBER, ret); +} + +static bool set_multi_led_control(unsigned int color[]) +{ + int ret; + + ret = device_multi_led_control(color); + + return capi_result(METHOD_MULTI_LED_CONTROL, ret); +} + void led_test_all(int *success, int *fail) { int s = 0; @@ -127,6 +151,8 @@ void led_test_all(int *success, int *fail) (get_led_brightness()) ? s++ : f++; (set_led_playcustom(1, 0, RED, DEFAULT_FLAG)) ? s++ : f++; (set_led_stopcustom()) ? s++ : f++; + (get_multi_led_number()) ? s++ : f++; + (set_multi_led_control(color)) ? s++ : f++; if (NULL != success) *success = s; if (NULL != fail) *fail = f; @@ -165,6 +191,10 @@ static int led_unit(int argc, char **argv) set_led_brightness(atoi(argv[4]), atoi(argv[5])); } else if (0 == strcasecmp(argv[3], METHOD_LED_PLAYCUSTOM)) { set_led_playcustom(atoi(argv[4]), atoi(argv[5]), strtoul(argv[6], NULL, 16), DEFAULT_FLAG); + } else if (0 == strcasecmp(argv[3], METHOD_MULTI_LED_GETNUMBER)) { + get_multi_led_number(); + } else if (0 == strcasecmp(argv[3], METHOD_MULTI_LED_CONTROL)) { + set_multi_led_control(color); } else if (0 == strcasecmp(argv[3], METHOD_LED_STOPCUSTOM)) { set_led_stopcustom(); } else { diff --git a/src/auto-test/pmqos.c b/src/auto-test/pmqos.c new file mode 100644 index 0000000..de871b3 --- /dev/null +++ b/src/auto-test/pmqos.c @@ -0,0 +1,99 @@ +/* + * test + * + * Copyright (c) 2020 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 "test.h" +#include + +#define METHOD_APP_LAUNCH_HOME "AppLaunchHome" +#define METHOD_HOMESCREEN "HomeScreen" + +static bool pmqos_app_launch_home(void) +{ + int ret; + + ret = device_pmqos_app_launch_home(3000); + + return capi_result(METHOD_APP_LAUNCH_HOME, ret); +} + +static bool pmqos_homescreen(void) +{ + int ret; + + ret = device_pmqos_homescreen(3000); + + return capi_result(METHOD_HOMESCREEN, ret); +} + +static void pmqos_test_all(int *success, int *fail) +{ + int s = 0; + int f = 0; + + (pmqos_app_launch_home()) ? s++ : f++; + (pmqos_homescreen()) ? s++ : f++; + + if (NULL != success) *success = s; + if (NULL != fail) *fail = f; +} + +static void pmqos_init(void *data) +{ + int success = 0; + int fail = 0; + + _I("start test"); + + pmqos_test_all(&success, &fail); + + _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail); +} + +static void pmqos_exit(void *data) +{ + _I("end test"); +} + +static int pmqos_unit(int argc, char **argv) +{ + if (argc < 4) { + int success = 0; + int fail = 0; + + _I("start test"); + pmqos_test_all(&success, &fail); + _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail); + } else if (0 == strcasecmp(argv[3], METHOD_APP_LAUNCH_HOME)) { + pmqos_app_launch_home(); + } else if (0 == strcasecmp(argv[3], METHOD_HOMESCREEN)) { + pmqos_homescreen(); + } else { + _E("Unknown test case!!!"); + } + + return 0; +} + +static const struct test_ops pmqos_test_ops = { + .priority = TEST_PRIORITY_NORMAL, + .name = "pmqos", + .init = pmqos_init, + .exit = pmqos_exit, + .unit = pmqos_unit, +}; + +TEST_OPS_REGISTER(&pmqos_test_ops) diff --git a/src/auto-test/test.c b/src/auto-test/test.c index 57106d8..794bb74 100644 --- a/src/auto-test/test.c +++ b/src/auto-test/test.c @@ -81,3 +81,56 @@ void test_exit(void *data) d->exit(data); } } + +void __cb(void *data, GVariant *result, GError *err) +{ + int temp = 0; + + if (!result) + { + _E("Can't get result of touchscreen request.:%s", err->message); + return; + } + + if (!dh_get_param_from_var(result, "(i)", &temp)) { + _E("Failed to get variant(%s): no call back message", g_variant_get_type_string(result)); + goto out; + } + _I("replay message(%d)", temp); + +out: + g_variant_unref(result); +} + +bool capi_result(const char *method, int val) +{ + bool ret; + + if (val == DEVICE_ERROR_NOT_SUPPORTED) { + _I("Not supported feature! (%s): %d", method, val); + ret = TRUE; + } else if (val < 0) { + _E("fail (%s): returned fail (%d)", method, val); + ret = FALSE; + } else { + _I("success (%s): %d", method, val); + ret = TRUE; + } + + return ret; +} + +bool capi_reboot_result(const char *method, int val) +{ + bool ret = FALSE; + + if (val == NORMAL_BOOT || val == SILENT_BOOT) { + _I("success (%s): %d", method, val); + ret = TRUE; + } else { + _E("fail (%s): returned fail (%d)", method, val); + ret = FALSE; + } + + return ret; +} diff --git a/src/auto-test/test.h b/src/auto-test/test.h index b324511..65dbd44 100644 --- a/src/auto-test/test.h +++ b/src/auto-test/test.h @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include "core/list.h" #include "core/common.h" @@ -103,4 +105,7 @@ void remove_test(const struct test_ops *c); const struct test_ops *find_test(const char *name); void config_test(); void _R(const char *format, ...); +void __cb(void *data, GVariant *result, GError *err); +bool capi_result(const char *method, int val); +bool capi_reboot_result(const char *method, int val); #endif diff --git a/src/auto-test/touchscreen.c b/src/auto-test/touchscreen.c new file mode 100644 index 0000000..88e370e --- /dev/null +++ b/src/auto-test/touchscreen.c @@ -0,0 +1,99 @@ +/* + * test + * + * Copyright (c) 2020 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 "test.h" +#include + +#define METHOD_TOUCHSCREEN_ENABLE "Enable" +#define METHOD_TOUCHSCREEN_DISABLE "Disable" + +static bool touchscreen_disable(void) +{ + int ret; + + ret = device_touchscreen_disable(__cb); + + return capi_result(METHOD_TOUCHSCREEN_DISABLE, ret); +} + +static bool touchscreen_enable(void) +{ + int ret; + + ret = device_touchscreen_enable(__cb); + + return capi_result(METHOD_TOUCHSCREEN_ENABLE, ret); +} + +static void touchscreen_test_all(int *success, int *fail) +{ + int s = 0; + int f = 0; + + (touchscreen_disable()) ? s++ : f++; + (touchscreen_enable()) ? s++ : f++; + + if (NULL != success) *success = s; + if (NULL != fail) *fail = f; +} + +static void touchscreen_init(void *data) +{ + int success = 0; + int fail = 0; + + _I("start test"); + + touchscreen_test_all(&success, &fail); + + _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail); +} + +static void touchscreen_exit(void *data) +{ + _I("end test"); +} + +static int touchscreen_unit(int argc, char **argv) +{ + if (argc < 4) { + int success = 0; + int fail = 0; + + _I("start test"); + touchscreen_test_all(&success, &fail); + _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail); + } else if (0 == strcasecmp(argv[3], METHOD_TOUCHSCREEN_ENABLE)) { + touchscreen_enable(); + } else if (0 == strcasecmp(argv[3], METHOD_TOUCHSCREEN_DISABLE)) { + touchscreen_disable(); + } else { + _E("Unknown test case!!!"); + } + + return 0; +} + +static const struct test_ops touchscreen_test_ops = { + .priority = TEST_PRIORITY_NORMAL, + .name = "touchscreen", + .init = touchscreen_init, + .exit = touchscreen_exit, + .unit = touchscreen_unit, +}; + +TEST_OPS_REGISTER(&touchscreen_test_ops) -- 2.7.4