From cdcb94fc106f67bc39bee9b2f35d802dbf8cc4d5 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Thu, 29 Jun 2023 14:36:23 +0900 Subject: [PATCH 01/16] display: Relocate display-dbus.c to core As remove dependecies, display-dbus.c is relocated to display core side. Change-Id: Ia46963a15f27e99c0e3cb2402af3a50cb934e96c Signed-off-by: Yunhee Seo --- src/display/{plugin-common => }/display-dbus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/display/{plugin-common => }/display-dbus.c (99%) diff --git a/src/display/plugin-common/display-dbus.c b/src/display/display-dbus.c similarity index 99% rename from src/display/plugin-common/display-dbus.c rename to src/display/display-dbus.c index 3e428c3..393e70e 100644 --- a/src/display/plugin-common/display-dbus.c +++ b/src/display/display-dbus.c @@ -341,7 +341,7 @@ static GVariant *dbus_changestate(GDBusConnection *conn, goto out; } - lcdon_blocked = is_lcdon_blocked(); + lcdon_blocked = display_plugin_is_lcd_on_blocked(); if (lcdon_blocked != LCDON_BLOCK_NONE) { if (state == LCD_NORMAL || state == LCD_DIM) { _W("LCDON is blocked, %d.", lcdon_blocked); @@ -902,7 +902,7 @@ static GVariant *dbus_customlcdon(GDBusConnection *conn, g_variant_get(param, "(i)", &timeout); - lcdon_blocked = is_lcdon_blocked(); + lcdon_blocked = display_plugin_is_lcd_on_blocked(); if (lcdon_blocked != LCDON_BLOCK_NONE) { _W("LCDON is blocked, %d.", lcdon_blocked); return g_variant_new("(i)", -ENOTSUP); -- 2.7.4 From 77417a5e5261a2ab1e2deb0c7f892d4007bb1cd1 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Thu, 29 Jun 2023 15:04:32 +0900 Subject: [PATCH 02/16] display: Fix static analysis issue Fix logical error code Change-Id: I8fe1338ac833385577ea8e515745d8a44c226b63 Signed-off-by: Yunhee Seo --- src/display/display-lock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/display/display-lock.c b/src/display/display-lock.c index 2b2625f..1f32883 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -377,7 +377,7 @@ int display_lock_request_lock(enum state_t state, pid_t pid, unsigned int timeou { struct display_lock *dl; - if (state < S_NORMAL || state > S_LCDOFF || timeout < 0) + if (state < S_NORMAL || state > S_LCDOFF) return -EINVAL; dl = find_lock(state, pid); @@ -408,7 +408,7 @@ int display_lock_update_lock(enum state_t state, pid_t pid, unsigned int timeout { struct display_lock *dl; - if (state < S_NORMAL || state > S_LCDOFF || timeout < 0) + if (state < S_NORMAL || state > S_LCDOFF) return -EINVAL; dl = find_lock(state, pid); -- 2.7.4 From d1cdf39aebe56a6d23a904136661f70b74f09c3e Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Thu, 29 Jun 2023 15:25:15 +0900 Subject: [PATCH 03/16] power: Remove unsafe function To resolve build warning, strncpy is replaced by snprintf. Change-Id: I780b09d61807f889991c89766c3560c097bc509b Signed-off-by: Yunhee Seo --- src/power/power-boot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/power/power-boot.c b/src/power/power-boot.c index ca39916..b9b1fc7 100644 --- a/src/power/power-boot.c +++ b/src/power/power-boot.c @@ -159,9 +159,9 @@ static int parse_matching_boot_condition(const struct parse_result *result, void SYS_G_LIST_FOREACH(result->props, elem, prop) { if (MATCH(prop->key, "BootReason")) - strncpy(config_bc.reason, prop->value, sizeof(prop->value) - 1); + snprintf(config_bc.reason, sizeof(config_bc.reason), "%s", prop->value); else if (MATCH(prop->key, "BootMode")) - strncpy(config_bc.mode, prop->value, sizeof(prop->value) - 1); + snprintf(config_bc.mode, sizeof(config_bc.mode), "%s", prop->value); } if (MATCH(bc.reason, config_bc.reason) && MATCH(bc.mode, config_bc.mode)) -- 2.7.4 From 3b722d9423cee31d2be20a04ac4773d2c9abe2d9 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Mon, 10 Jul 2023 11:40:35 +0900 Subject: [PATCH 04/16] display: Remove util.h/plugin-common util.h is used from display plugins for Power manager logging. The concept of power manager that exist as legacy while refactoring should be eliminated. By deleting util.h, the dependency problem is solved and the plugin-common is also erased. Also, util.h can be replaced by display-util.h and log.h in the display core. Change-Id: Ic9630ff0a8ef50190d1abab9ce5a86956b714c8a Signed-off-by: Yunhee Seo --- CMakeLists.txt | 1 - plugins/iot-headed/display/CMakeLists.txt | 3 -- plugins/iot-headed/display/core.c | 2 +- plugins/iot-headed/display/device-interface.c | 1 - plugins/iot-headed/display/key-filter.c | 3 +- plugins/iot-headless/display/CMakeLists.txt | 1 - plugins/mobile/display/CMakeLists.txt | 3 -- plugins/mobile/display/core.c | 2 +- plugins/mobile/display/device-interface.c | 1 - plugins/mobile/display/key-filter.c | 3 +- plugins/tv/display/CMakeLists.txt | 3 -- plugins/tv/display/core.c | 2 +- plugins/tv/display/device-interface.c | 1 - plugins/tv/display/key-filter.c | 2 +- plugins/wearable/display/CMakeLists.txt | 3 -- .../wearable/display/auto-brightness-sensorhub.c | 2 +- plugins/wearable/display/auto-brightness.c | 2 +- plugins/wearable/display/bezel.c | 2 +- plugins/wearable/display/core.c | 2 +- plugins/wearable/display/device-interface.c | 1 - plugins/wearable/display/display-handler.c | 2 +- plugins/wearable/display/hbm.c | 2 +- plugins/wearable/display/key-filter.c | 2 +- plugins/wearable/display/lbm.c | 2 +- plugins/wearable/display/swim.c | 2 +- src/display/ambient-mode.c | 2 +- src/display/display-actor.c | 1 - src/display/display-dbus.c | 1 - src/display/display-dpms.c | 1 - src/display/display-lock.c | 1 + src/display/display-ops.c | 2 +- src/display/display-signal.c | 1 + src/display/display-signal.h | 1 - src/display/display-util.h | 5 +++ src/display/lock-detector.c | 2 +- src/display/plugin-common/util.h | 50 ---------------------- src/display/poll.c | 2 +- src/display/setting.c | 2 +- 38 files changed, 29 insertions(+), 92 deletions(-) delete mode 100644 src/display/plugin-common/util.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d836395..8a9b3f2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,7 +169,6 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/deviced) # FIXME: Temporary include path for separating display core and plugin INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/display) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/display/plugin-common) SET(PKG_MODULES vconf diff --git a/plugins/iot-headed/display/CMakeLists.txt b/plugins/iot-headed/display/CMakeLists.txt index 2d290d3..532810d 100644 --- a/plugins/iot-headed/display/CMakeLists.txt +++ b/plugins/iot-headed/display/CMakeLists.txt @@ -3,13 +3,10 @@ PROJECT(iot-headed-display C) FILE(GLOB ALL_SRCS "*.c") SET(SRCS ${ALL_SRCS}) -ADD_SOURCE(${CMAKE_SOURCE_DIR}/src/display/plugin-common COMMON_SRCS) -SET(SRCS ${SRCS} ${COMMON_SRCS}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core) # FIXME: Temporary include path for separating display core and plugin INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/display) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/display/plugin-common) INCLUDE(FindPkgConfig) pkg_check_modules(libpkgs REQUIRED diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 3311604..4f4b671 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -43,8 +43,8 @@ #include #include +#include "shared/log.h" #include "ambient-mode.h" -#include "util.h" #include "core.h" #include "poll.h" #include "lock-detector.h" diff --git a/plugins/iot-headed/display/device-interface.c b/plugins/iot-headed/display/device-interface.c index 245b5d0..abb1969 100644 --- a/plugins/iot-headed/display/device-interface.c +++ b/plugins/iot-headed/display/device-interface.c @@ -38,7 +38,6 @@ #include "shared/devices.h" #include "shared/common.h" #include "shared/device-notifier.h" -#include "util.h" #include "device-interface.h" #include "vconf.h" #include "core.h" diff --git a/plugins/iot-headed/display/key-filter.c b/plugins/iot-headed/display/key-filter.c index 4c31753..fec11d9 100644 --- a/plugins/iot-headed/display/key-filter.c +++ b/plugins/iot-headed/display/key-filter.c @@ -28,7 +28,6 @@ #include #include "ambient-mode.h" -#include "util.h" #include "core.h" #include "poll.h" #include "device-interface.h" @@ -39,12 +38,14 @@ #include "display-config.h" #include "display-misc.h" #include "display-state-transition.h" +#include "display-util.h" #include "shared/common.h" #include "shared/devices.h" #include "shared/device-notifier.h" #include "shared/common.h" #include "shared/plugin.h" #include "shared/apps.h" +#include "shared/log.h" #include "power/power-off.h" #include "power/power-suspend.h" #include "led/touch-key.h" diff --git a/plugins/iot-headless/display/CMakeLists.txt b/plugins/iot-headless/display/CMakeLists.txt index 1daab28..20507d2 100644 --- a/plugins/iot-headless/display/CMakeLists.txt +++ b/plugins/iot-headless/display/CMakeLists.txt @@ -6,7 +6,6 @@ FILE(GLOB SRCS "*.c") INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src) # FIXME: Temporary include path for separating display core and plugin INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/display) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/display/plugin-common) INCLUDE(FindPkgConfig) pkg_check_modules(libpkgs REQUIRED diff --git a/plugins/mobile/display/CMakeLists.txt b/plugins/mobile/display/CMakeLists.txt index 1621bd6..eed43f2 100644 --- a/plugins/mobile/display/CMakeLists.txt +++ b/plugins/mobile/display/CMakeLists.txt @@ -3,13 +3,10 @@ PROJECT(mobile-display C) FILE(GLOB ALL_SRCS "*.c") SET(SRCS ${ALL_SRCS}) -ADD_SOURCE(${CMAKE_SOURCE_DIR}/src/display/plugin-common COMMON_SRCS) -SET(SRCS ${SRCS} ${COMMON_SRCS}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core) # FIXME: Temporary include path for separating display core and plugin INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/display) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/display/plugin-common) INCLUDE(FindPkgConfig) pkg_check_modules(libpkgs REQUIRED diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 7abf561..b4c14ae 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -42,8 +42,8 @@ #include #include +#include "shared/log.h" #include "ambient-mode.h" -#include "util.h" #include "core.h" #include "poll.h" #include "lock-detector.h" diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 7900c9e..7c74c83 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -37,7 +37,6 @@ #include "shared/devices.h" #include "shared/common.h" #include "shared/device-notifier.h" -#include "util.h" #include "device-interface.h" #include "vconf.h" #include "core.h" diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index f3914c1..735b30c 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -28,7 +28,6 @@ #include #include "ambient-mode.h" -#include "util.h" #include "core.h" #include "poll.h" #include "device-interface.h" @@ -39,12 +38,14 @@ #include "display-config.h" #include "display-misc.h" #include "display-state-transition.h" +#include "display-util.h" #include "shared/common.h" #include "shared/devices.h" #include "shared/device-notifier.h" #include "shared/common.h" #include "shared/plugin.h" #include "shared/apps.h" +#include "shared/log.h" #include "power/power-off.h" #include "power/power-suspend.h" #include "led/touch-key.h" diff --git a/plugins/tv/display/CMakeLists.txt b/plugins/tv/display/CMakeLists.txt index 300d89b..3267977 100644 --- a/plugins/tv/display/CMakeLists.txt +++ b/plugins/tv/display/CMakeLists.txt @@ -3,13 +3,10 @@ PROJECT(tv-display C) FILE(GLOB ALL_SRCS "*.c") SET(SRCS ${ALL_SRCS}) -ADD_SOURCE(${CMAKE_SOURCE_DIR}/src/display/plugin-common COMMON_SRCS) -SET(SRCS ${SRCS} ${COMMON_SRCS}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core) # FIXME: Temporary include path for separating display core and plugin INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/display) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/display/plugin-common) INCLUDE(FindPkgConfig) pkg_check_modules(libpkgs REQUIRED diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 0f2a7af..6e44cb1 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -42,8 +42,8 @@ #include #include +#include "shared/log.h" #include "ambient-mode.h" -#include "util.h" #include "core.h" #include "poll.h" #include "lock-detector.h" diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 4fc311b..2db6d71 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -37,7 +37,6 @@ #include "shared/devices.h" #include "shared/common.h" #include "shared/device-notifier.h" -#include "util.h" #include "device-interface.h" #include "vconf.h" #include "core.h" diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 149da8f..e699c1c 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -28,7 +28,6 @@ #include #include "ambient-mode.h" -#include "util.h" #include "core.h" #include "poll.h" #include "device-interface.h" @@ -39,6 +38,7 @@ #include "display-config.h" #include "display-misc.h" #include "display-state-transition.h" +#include "display-util.h" #include "shared/common.h" #include "shared/devices.h" #include "shared/device-notifier.h" diff --git a/plugins/wearable/display/CMakeLists.txt b/plugins/wearable/display/CMakeLists.txt index c0c040f..00e456b 100644 --- a/plugins/wearable/display/CMakeLists.txt +++ b/plugins/wearable/display/CMakeLists.txt @@ -3,13 +3,10 @@ PROJECT(wearable-display C) FILE(GLOB ALL_SRCS "*.c") SET(SRCS ${ALL_SRCS}) -ADD_SOURCE(${CMAKE_SOURCE_DIR}/src/display/plugin-common COMMON_SRCS) -SET(SRCS ${SRCS} ${COMMON_SRCS}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/battery-monitor) # FIXME: Temporary include path for separating display core and plugin INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/display) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/display/plugin-common) INCLUDE(FindPkgConfig) pkg_check_modules(libpkgs REQUIRED diff --git a/plugins/wearable/display/auto-brightness-sensorhub.c b/plugins/wearable/display/auto-brightness-sensorhub.c index 04187bb..df03e94 100644 --- a/plugins/wearable/display/auto-brightness-sensorhub.c +++ b/plugins/wearable/display/auto-brightness-sensorhub.c @@ -27,7 +27,6 @@ #include "hbm.h" #include "lbm.h" #include "auto-brightness-sensorhub.h" -#include "util.h" #include "core.h" #include "device-interface.h" #include "display-info.h" @@ -35,6 +34,7 @@ #include "display-backlight.h" #include "display-config.h" #include "shared/device-notifier.h" +#include "shared/log.h" #include "battery/power-supply.h" #include "shared/plugin.h" diff --git a/plugins/wearable/display/auto-brightness.c b/plugins/wearable/display/auto-brightness.c index 4103f72..0f99182 100644 --- a/plugins/wearable/display/auto-brightness.c +++ b/plugins/wearable/display/auto-brightness.c @@ -29,7 +29,6 @@ #include #include -#include "util.h" #include "core.h" #include "device-interface.h" #include "display-info.h" @@ -38,6 +37,7 @@ #include "display-config.h" #include "setting.h" #include "shared/device-notifier.h" +#include "shared/log.h" #include #define MAX_SAMPLING_COUNT 3 diff --git a/plugins/wearable/display/bezel.c b/plugins/wearable/display/bezel.c index 3d4c80b..3f03460 100644 --- a/plugins/wearable/display/bezel.c +++ b/plugins/wearable/display/bezel.c @@ -22,10 +22,10 @@ #include "shared/devices.h" #include "shared/common.h" #include "shared/device-notifier.h" -#include "util.h" #include "poll.h" #include "core.h" #include "display-ops.h" +#include "shared/log.h" #include "shared/plugin.h" #ifndef VCONFKEY_SETAPPL_WAKEUP_BY_BEZEL_ENABLE diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 23551d1..efaf336 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -42,9 +42,9 @@ #include #include +#include "shared/log.h" #include "auto-brightness-sensorhub.h" #include "ambient-mode.h" -#include "util.h" #include "core.h" #include "poll.h" #include "lock-detector.h" diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 018cfe5..d9c404f 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -37,7 +37,6 @@ #include "shared/devices.h" #include "shared/common.h" #include "shared/device-notifier.h" -#include "util.h" #include "device-interface.h" #include "vconf.h" #include "core.h" diff --git a/plugins/wearable/display/display-handler.c b/plugins/wearable/display/display-handler.c index 60cc33e..df34a70 100644 --- a/plugins/wearable/display/display-handler.c +++ b/plugins/wearable/display/display-handler.c @@ -24,12 +24,12 @@ #include "auto-brightness-sensorhub.h" #include "shared/device-notifier.h" -#include "util.h" #include "core.h" #include "device-interface.h" #include "poll.h" #include "shared/common.h" #include "shared/devices.h" +#include "shared/log.h" #include "display-actor.h" #include "display-info.h" #include "display-panel.h" diff --git a/plugins/wearable/display/hbm.c b/plugins/wearable/display/hbm.c index 2c6e9b5..53c9abb 100644 --- a/plugins/wearable/display/hbm.c +++ b/plugins/wearable/display/hbm.c @@ -23,12 +23,12 @@ #include "auto-brightness-sensorhub.h" #include "weaks.h" #include "display-info.h" -#include "util.h" #include "core.h" #include "display-ops.h" #include "display-panel.h" #include "shared/common.h" #include "shared/device-notifier.h" +#include "shared/log.h" #define BOARD_CONF_FILE "/etc/deviced/display.conf" diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index c399df1..55c1f8e 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -28,7 +28,6 @@ #include #include "ambient-mode.h" -#include "util.h" #include "core.h" #include "poll.h" #include "device-interface.h" @@ -40,6 +39,7 @@ #include "display-config.h" #include "display-misc.h" #include "display-state-transition.h" +#include "display-util.h" #include "shared/common.h" #include "shared/devices.h" #include "shared/device-notifier.h" diff --git a/plugins/wearable/display/lbm.c b/plugins/wearable/display/lbm.c index b2c43c2..f94f72e 100644 --- a/plugins/wearable/display/lbm.c +++ b/plugins/wearable/display/lbm.c @@ -24,13 +24,13 @@ #include "auto-brightness-sensorhub.h" #include "lbm.h" #include "display-info.h" -#include "util.h" #include "core.h" #include "device-interface.h" #include "display-backlight.h" #include "display-ops.h" #include "shared/common.h" #include "shared/device-notifier.h" +#include "shared/log.h" #define SIGNAL_LBM_ON "LBMOn" #define SIGNAL_LBM_OFF "LBMOff" diff --git a/plugins/wearable/display/swim.c b/plugins/wearable/display/swim.c index 3e90e8a..25ad0fa 100644 --- a/plugins/wearable/display/swim.c +++ b/plugins/wearable/display/swim.c @@ -21,11 +21,11 @@ #include "shared/device-notifier.h" #include "shared/devices.h" #include "core.h" -#include "util.h" #include "device-interface.h" #include "display-ops.h" #include "display-panel.h" #include "shared/plugin.h" +#include "shared/log.h" #include diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index 79b000a..139b6c7 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -21,13 +21,13 @@ #include #include -#include "util.h" #include "core.h" #include "display.h" #include "display-ops.h" #include "display-panel.h" #include "display-plugin.h" #include "display-state-transition.h" +#include "shared/log.h" #include "shared/device-notifier.h" #include "shared/devices.h" #include "shared/plugin.h" diff --git a/src/display/display-actor.c b/src/display/display-actor.c index 3b9a324..47ecfdc 100644 --- a/src/display/display-actor.c +++ b/src/display/display-actor.c @@ -20,7 +20,6 @@ #include #include -#include "util.h" #include "display-actor.h" #include "shared/common.h" diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 393e70e..de51880 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -32,7 +32,6 @@ #include "ambient-mode.h" #include "core/log.h" -#include "util.h" #include "core.h" #include "lock-detector.h" #include "shared/common.h" diff --git a/src/display/display-dpms.c b/src/display/display-dpms.c index 8e69b9a..4c4f38a 100644 --- a/src/display/display-dpms.c +++ b/src/display/display-dpms.c @@ -29,7 +29,6 @@ #include "core/log.h" #include "shared/device-notifier.h" #include "device-interface.h" -#include "util.h" #include "display-dpms.h" #include "display-plugin.h" #include "device-interface.h" diff --git a/src/display/display-lock.c b/src/display/display-lock.c index 1f32883..85d731e 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -34,6 +34,7 @@ #include "display-config.h" #include "display-misc.h" #include "display-state-transition.h" +#include "shared/log.h" #include "shared/log-macro.h" #include "shared/apps.h" diff --git a/src/display/display-ops.c b/src/display/display-ops.c index d459aec..6497f80 100644 --- a/src/display/display-ops.c +++ b/src/display/display-ops.c @@ -20,8 +20,8 @@ #include #include -#include "util.h" #include "display-ops.h" +#include "shared/log.h" #include "shared/common.h" static GList *disp_head; diff --git a/src/display/display-signal.c b/src/display/display-signal.c index 65b33bd..40b3134 100644 --- a/src/display/display-signal.c +++ b/src/display/display-signal.c @@ -19,6 +19,7 @@ #include "display-signal.h" #include "display-util.h" #include "poll.h" +#include "shared/log.h" #include "shared/plugin.h" #include "shared/time.h" diff --git a/src/display/display-signal.h b/src/display/display-signal.h index 529ae69..f245ea7 100644 --- a/src/display/display-signal.h +++ b/src/display/display-signal.h @@ -21,7 +21,6 @@ #include -#include "util.h" #include "shared/devices.h" #include "shared/device-notifier.h" diff --git a/src/display/display-util.h b/src/display/display-util.h index f201487..333e82f 100644 --- a/src/display/display-util.h +++ b/src/display/display-util.h @@ -20,6 +20,11 @@ #include "shared/devices.h" +#define SEC_TO_MSEC(x) ((x)*1000) +#define MSEC_TO_SEC(x) ((x)/1000) +#define USEC_TO_SEC(x) ((x)/1000000.0) +#define NSEC_TO_SEC(x) ((x)/1000000000.0) + int display_util_get_device_flags_name(enum device_flags flags, const char **flag_name); #endif /* __DISPLAY_UTIL_H__ */ \ No newline at end of file diff --git a/src/display/lock-detector.c b/src/display/lock-detector.c index 593d4f6..ca8fc52 100644 --- a/src/display/lock-detector.c +++ b/src/display/lock-detector.c @@ -32,9 +32,9 @@ #include #include -#include "util.h" #include "core.h" #include "display-misc.h" +#include "shared/log.h" #include "shared/device-notifier.h" struct lock_info { diff --git a/src/display/plugin-common/util.h b/src/display/plugin-common/util.h deleted file mode 100644 index 4bf053a..0000000 --- a/src/display/plugin-common/util.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file util.h - * @brief Utilities header for Power manager - */ -#ifndef __DEF_UTIL_H__ -#define __DEF_UTIL_H__ - -/** - * @addtogroup POWER_MANAGER - * @{ - */ -#ifdef ENABLE_DEVICED_DLOG -#define ENABLE_DLOG -#endif - -#ifdef LOG_TAG -#undef LOG_TAG -#endif - -#define LOG_TAG "POWER_MANAGER" -#include "shared/log-macro.h" - -#define SEC_TO_MSEC(x) ((x)*1000) -#define MSEC_TO_SEC(x) ((x)/1000) -#define USEC_TO_SEC(x) ((x)/1000000.0) -#define NSEC_TO_SEC(x) ((x)/1000000000.0) - -/** - * @} - */ -#endif diff --git a/src/display/poll.c b/src/display/poll.c index 2983f82..8a09447 100644 --- a/src/display/poll.c +++ b/src/display/poll.c @@ -24,13 +24,13 @@ */ #include -#include "util.h" #include "core.h" #include "device-interface.h" #include "poll.h" #include "display-ops.h" #include "display-plugin.h" #include "display-state-transition.h" +#include "shared/log.h" #include "shared/plugin.h" static PMMsg recv_data; diff --git a/src/display/setting.c b/src/display/setting.c index d697d2a..c6509f5 100644 --- a/src/display/setting.c +++ b/src/display/setting.c @@ -25,13 +25,13 @@ #include "ambient-mode.h" #include "core.h" #include "device-interface.h" -#include "util.h" #include "setting.h" #include "display-misc.h" #include "display-ops.h" #include "display-plugin.h" #include "display-state-transition.h" #include "led/touch-key.h" +#include "shared/log.h" #include "shared/eventsystem.h" #include "shared/plugin.h" -- 2.7.4 From e60d90d153b840c08cc677b5448a2e48354fe3cb Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Mon, 10 Jul 2023 15:28:18 +0900 Subject: [PATCH 05/16] display: Relocate delayed_init_done delayed_init_done is used from all plugins with the same logic. This function is used to unlock INTERNAL_LOCK_BOOTING after display initialization. Because INTERNAL_LOCK_BOOTING is caught while display is initialized. Thus, delayed_init_done is moved to display.c Change-Id: Id6e23dd5b10de8d20edce22715972a829c95b49e Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 22 ---------------------- plugins/mobile/display/core.c | 22 ---------------------- plugins/tv/display/core.c | 22 ---------------------- plugins/wearable/display/core.c | 22 ---------------------- src/display/display.c | 20 ++++++++++++++++++++ 5 files changed, 20 insertions(+), 88 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 4f4b671..2c41ed9 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -178,26 +178,6 @@ static const char *errMSG[INIT_END] = { [INIT_DBUS] = "d-bus init error", }; -static int delayed_init_done(void *data) -{ - static bool done = false; - - if (!data) - return done; - - done = *(int*)data; - if (!done) - 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); - } - - return done; -} - static void init_display_states(void *data) { struct display_plugin *dp = (struct display_plugin *) data; @@ -271,7 +251,6 @@ static void display_init(void *data) _W("Failed to load '%s', use default value: %d", DISPLAY_CONF_FILE, ret); - register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); @@ -403,7 +382,6 @@ static void display_exit(void *data) exit_sysfs(); break; case INIT_POLL: - unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index b4c14ae..30cd412 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -231,26 +231,6 @@ static const char *errMSG[INIT_END] = { [INIT_DBUS] = "d-bus init error", }; -static int delayed_init_done(void *data) -{ - static bool done = false; - - if (!data) - return done; - - done = *(int*)data; - if (!done) - 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); - } - - return done; -} - static void init_display_states(void *data) { struct display_plugin *dp = (struct display_plugin *) data; @@ -320,7 +300,6 @@ static void display_init(void *data) _W("Failed to load '%s', use default value: %d", DISPLAY_CONF_FILE, ret); - register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); @@ -453,7 +432,6 @@ static void display_exit(void *data) exit_sysfs(); break; case INIT_POLL: - unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 6e44cb1..16341ec 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -178,26 +178,6 @@ static const char *errMSG[INIT_END] = { [INIT_DBUS] = "d-bus init error", }; -static int delayed_init_done(void *data) -{ - static bool done = false; - - if (!data) - return done; - - done = *(int*)data; - if (!done) - 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); - } - - return done; -} - static void init_display_states(void *data) { struct display_plugin *dp = (struct display_plugin *) data; @@ -268,7 +248,6 @@ static void display_init(void *data) _W("Failed to load '%s', use default value: %d", DISPLAY_CONF_FILE, ret); - register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); @@ -400,7 +379,6 @@ static void display_exit(void *data) exit_sysfs(); break; case INIT_POLL: - unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index efaf336..86be20d 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -936,26 +936,6 @@ static const char *errMSG[INIT_END] = { [INIT_DBUS] = "d-bus init error", }; -static int delayed_init_done(void *data) -{ - static bool done = false; - - if (!data) - return done; - - done = *(int*)data; - if (!done) - 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); - } - - return done; -} - static void init_display_states(void *data) { struct display_plugin *dp = (struct display_plugin *) data; @@ -1058,7 +1038,6 @@ static void display_init(void *data) register_kernel_uevent_control(&sec_dsim_uevent_ops); - register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); @@ -1194,7 +1173,6 @@ static void display_exit(void *data) exit_sysfs(); break; case INIT_POLL: - unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); diff --git a/src/display/display.c b/src/display/display.c index 7d2048c..7b06647 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -418,6 +418,24 @@ static gboolean handle_sighup(gpointer data) return G_SOURCE_REMOVE; } +static int delayed_init_done(void *data) +{ + static bool done = false; + + if (!data) + return done; + + done = *(int*)data; + if (!done) + return done; + + _I("Booting done, release booting lock."); + display_plugin_pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, PM_SLEEP_MARGIN); + display_plugin_pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); + + return done; +} + static int display_probe(void *data) { display_plugin_device_ops = find_device("display-plugin"); @@ -433,6 +451,7 @@ static void display_init(void *data) return; g_unix_signal_add(SIGHUP, handle_sighup, (gpointer) SIGHUP); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); display_plugin_device_ops->init(data); register_kernel_uevent_control(&lcd_uevent_ops); @@ -456,6 +475,7 @@ static void display_exit(void *data) display_misc_unregister_battery_health_notifier(); unregister_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback); unregister_notifier(DEVICE_NOTIFIER_POWEROFF_TRIGGERED, poweroff_triggered_callback); + unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); } static int display_start(enum device_flags flags) -- 2.7.4 From 392f6c775277b115dc080ff1a265fc42e2c2e280 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Tue, 11 Jul 2023 18:30:52 +0900 Subject: [PATCH 06/16] display: Refactor display_plugin_get_device_flags() To make display-plugin independent without any other file dependence, display_plugin_get_device_flags() is refactored. This function is added to display-util - int display_util_get_device_flags(unsigned long *device_flags); -> This function sets display flag value and return. Change-Id: I1ad7f1ebb3838a0bca7aa74623f9e6ee3da4299a Signed-off-by: Yunhee Seo --- src/display/display-panel.c | 5 +++-- src/display/display-plugin.c | 19 +++---------------- src/display/display-util.c | 28 +++++++++++++++++++++++++++- src/display/display-util.h | 1 + 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/display/display-panel.c b/src/display/display-panel.c index fbc615e..ec6706c 100644 --- a/src/display/display-panel.c +++ b/src/display/display-panel.c @@ -29,6 +29,7 @@ #include "display-plugin.h" #include "display-signal.h" #include "display-state-transition.h" +#include "display-util.h" #include "led/touch-key.h" #define MAX_WHITE_BALANCE_GAIN 2047 @@ -218,7 +219,7 @@ void display_panel_get_lcd_paneloff_mode(bool *on) void display_panel_lcd_on_procedure(int state, enum device_flags flag) { unsigned long flags = NORMAL_MODE; - display_plugin_get_device_flags(&flags); + display_util_get_device_flags(&flags); flags |= flag; if (display_plugin_lcd_on_procedure(state, flag) == 0) @@ -269,7 +270,7 @@ void display_panel_lcd_on_procedure(int state, enum device_flags flag) void display_panel_lcd_off_procedure(enum device_flags flag) { unsigned long flags = NORMAL_MODE; - display_plugin_get_device_flags(&flags); + display_util_get_device_flags(&flags); flags |= flag; if (display_plugin_lcd_off_procedure(flag) == 0) diff --git a/src/display/display-plugin.c b/src/display/display-plugin.c index 1e8171a..1328593 100644 --- a/src/display/display-plugin.c +++ b/src/display/display-plugin.c @@ -17,7 +17,6 @@ */ #include -#include "display-misc.h" #include "display-plugin.h" #include "shared/log-macro.h" @@ -382,20 +381,8 @@ int display_plugin_get_device_flags(unsigned long *device_flags) if (!device_flags) return -EINVAL; - if (g_display_plugin.get_device_flags) - return g_display_plugin.get_device_flags(device_flags); - - *device_flags = NORMAL_MODE; - bool lcd_paneloff_mode = false; - bool stay_touchscreen_off = false; - display_panel_get_lcd_paneloff_mode(&lcd_paneloff_mode); - display_misc_get_stay_touchscreen_off(&stay_touchscreen_off); - - if (lcd_paneloff_mode) - *device_flags |= LCD_PANEL_OFF_MODE; - - if (stay_touchscreen_off) - *device_flags |= TOUCH_SCREEN_OFF_MODE; + if (!g_display_plugin.get_device_flags) + return -EOPNOTSUPP; - return 0; + return g_display_plugin.get_device_flags(device_flags); } \ No newline at end of file diff --git a/src/display/display-util.c b/src/display/display-util.c index 2cd8c5e..eb9556a 100644 --- a/src/display/display-util.c +++ b/src/display/display-util.c @@ -15,6 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "display-misc.h" +#include "display-plugin.h" #include "display-util.h" int display_util_get_device_flags_name(enum device_flags flags, const char **flag_name) @@ -46,4 +48,28 @@ int display_util_get_device_flags_name(enum device_flags flags, const char **fla *flag_name = UNKNOWN_STR; return 0; -} \ No newline at end of file +} + +int display_util_get_device_flags(unsigned long *device_flags) +{ + bool lcd_paneloff_mode = false; + bool stay_touchscreen_off = false; + + if (!device_flags) + return -EINVAL; + + if (g_display_plugin.get_device_flags) + return display_plugin_get_device_flags(device_flags); + + *device_flags = NORMAL_MODE; + display_panel_get_lcd_paneloff_mode(&lcd_paneloff_mode); + display_misc_get_stay_touchscreen_off(&stay_touchscreen_off); + + if (lcd_paneloff_mode) + *device_flags |= LCD_PANEL_OFF_MODE; + + if (stay_touchscreen_off) + *device_flags |= TOUCH_SCREEN_OFF_MODE; + + return 0; +} diff --git a/src/display/display-util.h b/src/display/display-util.h index 333e82f..39f7e71 100644 --- a/src/display/display-util.h +++ b/src/display/display-util.h @@ -26,5 +26,6 @@ #define NSEC_TO_SEC(x) ((x)/1000000000.0) int display_util_get_device_flags_name(enum device_flags flags, const char **flag_name); +int display_util_get_device_flags(unsigned long *device_flags); #endif /* __DISPLAY_UTIL_H__ */ \ No newline at end of file -- 2.7.4 From 66b486b87b040e2b01c3d2e7c143b69684ef1154 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Tue, 11 Jul 2023 19:23:49 +0900 Subject: [PATCH 07/16] display: Remove unncessary display_backlight_get_brightness_by_plugin_profile() As display functions are relocated and refactored, this function became unnecessary. Change-Id: Id0ef55c6f116bc8cba3db97c4487c6e67cbeee5c Signed-off-by: Yunhee Seo --- plugins/wearable/display/auto-brightness-sensorhub.c | 4 ++-- plugins/wearable/display/auto-brightness.c | 2 +- plugins/wearable/display/device-interface.c | 2 +- plugins/wearable/display/lbm.c | 2 +- src/display/display-backlight.c | 18 +++++------------- src/display/display-backlight.h | 1 - src/display/display-dbus.c | 4 ++-- 7 files changed, 12 insertions(+), 21 deletions(-) diff --git a/plugins/wearable/display/auto-brightness-sensorhub.c b/plugins/wearable/display/auto-brightness-sensorhub.c index df03e94..321c32e 100644 --- a/plugins/wearable/display/auto-brightness-sensorhub.c +++ b/plugins/wearable/display/auto-brightness-sensorhub.c @@ -97,7 +97,7 @@ void set_brightness_level(int level) break; case SPECIFIC_MODE_OFF: display_backlight_get_default_brightness(&default_brightness); - display_backlight_get_brightness_by_plugin_profile(¤t_brightness); + display_backlight_get_brightness(¤t_brightness); /* Disable HBM, LBM */ auto_brightness_control(BR_HBM_OFF, BR_IMPLICIT); @@ -190,7 +190,7 @@ int auto_brightness_control(enum brightness_request_e request, int set_brightnes int ret; display_backlight_get_default_brightness(&default_brightness); - display_backlight_get_brightness_by_plugin_profile(¤t_brightness); + display_backlight_get_brightness(¤t_brightness); if (request == BR_LBM_ON) { if (!get_lbm_setting()) diff --git a/plugins/wearable/display/auto-brightness.c b/plugins/wearable/display/auto-brightness.c index 0f99182..58ebec4 100644 --- a/plugins/wearable/display/auto-brightness.c +++ b/plugins/wearable/display/auto-brightness.c @@ -102,7 +102,7 @@ static void alc_set_brightness(int setting, int value, float light) assert(g_display_plugin.config); - ret = display_backlight_get_brightness_by_plugin_profile(&tmp_value); + ret = display_backlight_get_brightness(&tmp_value); if (ret < 0) { _E("Failed to get display brightness."); return; diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index d9c404f..3fa8e72 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -119,7 +119,7 @@ static int backlight_transit_state(int state) display_backlight_get_default_brightness(&default_brightness); - display_backlight_get_brightness_by_plugin_profile(&brt); + display_backlight_get_brightness(&brt); if (state == DPMS_OFF) { start = brt; diff --git a/plugins/wearable/display/lbm.c b/plugins/wearable/display/lbm.c index f94f72e..eea8f65 100644 --- a/plugins/wearable/display/lbm.c +++ b/plugins/wearable/display/lbm.c @@ -142,7 +142,7 @@ static void lbm_change_brightness(int start, int end, int step) if (display_dimstay_check()) return; - ret = display_backlight_get_brightness_by_plugin_profile(&prev); + ret = display_backlight_get_brightness(&prev); if (ret < 0) { _E("Failed to get brightness, %d.", ret); diff --git a/src/display/display-backlight.c b/src/display/display-backlight.c index 67bad0d..6146300 100644 --- a/src/display/display-backlight.c +++ b/src/display/display-backlight.c @@ -149,7 +149,11 @@ int display_backlight_set_brightness(int brightness) int display_backlight_get_brightness(int *brightness) { - int brt, ret; + int brt = 0, ret = 0; + + ret = display_plugin_backlight_get_brightness(brightness); + if (ret == 0) + return 0; if (!display_is_hal_backend_available()) { _E("There is no display device."); @@ -175,18 +179,6 @@ int display_backlight_get_brightness(int *brightness) return 0; } -/* FIXME: this function is only for wearable plugin, it should changed or removed after refactoring */ -int display_backlight_get_brightness_by_plugin_profile(int *brightness) -{ - int ret; - - ret = display_plugin_backlight_get_brightness(brightness); - if (ret == 0) - return 0; - - return display_backlight_get_brightness(brightness); -} - void display_backlight_change_brightness(int start, int end, int step) { int diff, val; diff --git a/src/display/display-backlight.h b/src/display/display-backlight.h index 7d35d19..ecf17e6 100644 --- a/src/display/display-backlight.h +++ b/src/display/display-backlight.h @@ -34,7 +34,6 @@ int display_backlight_get_normalized_brightness(int raw_brightness, int *normalized_brightness); int display_backlight_set_brightness(int brightness); int display_backlight_get_brightness(int *brightness); -int display_backlight_get_brightness_by_plugin_profile(int *brightness); void display_backlight_change_brightness(int start, int end, int step); int display_backlight_change_brightness_by_dpms_state(enum dpms_state state); int display_backlight_set_default_brightness(int brightness); diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index de51880..8f37f24 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -411,7 +411,7 @@ static GVariant *dbus_getbrightness(GDBusConnection *conn, int brt = -1, ret, result; if (get_pm_cur_state() == S_NORMAL) { - ret = display_backlight_get_brightness_by_plugin_profile(&brt); + ret = display_backlight_get_brightness(&brt); if (ret < 0) result = 0; else @@ -607,7 +607,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 = display_backlight_get_brightness_by_plugin_profile(&brt); + ret = display_backlight_get_brightness(&brt); if (ret < 0) brt = ret; -- 2.7.4 From 16eace6d221065b66951c59bf73a0083874d4808 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Wed, 12 Jul 2023 19:06:31 +0900 Subject: [PATCH 08/16] display: Remove poll.c poll.c file has legacy functions pm_change_internal/pm_lock_internal/pm_unlock_internal() These functions are usually called from external requests like key-event, dbus method, etc. pm_lock_internal/pm_unlock_internal() gets specific display state lock/unlock. pm_change_internal() requests state transition according to specific condition. This file has to be erased, and then inner functions are relocated. These are new functions to be added. display-lock - int display_lock_request_lock_with_option(pid_t pid, int s_bits, int flag, int timeout); - int display_lock_request_unlock_with_option(pid_t pid, int s_bits, int flag); -> These replace pm_lock_internal/pm_unlock_intenral(). display-state-transition - int display_state_transition_request_state_transition_with_option(pid_t pid, int s_bits); -> This replaces pm_change_internal(). display-util - int display_util_get_display_state(int s_bits); -> This extracts display state from s_bits. Change-Id: Ied90f5a7f132f3bfcba1ecf1eef8faa02c728e31 Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 9 +- plugins/iot-headed/display/key-filter.c | 9 +- plugins/mobile/battery/battery-notification.c | 14 +- plugins/mobile/display/core.c | 9 +- plugins/mobile/display/key-filter.c | 9 +- plugins/tv/display/core.c | 9 +- plugins/tv/display/key-filter.c | 9 +- plugins/wearable/display/bezel.c | 8 +- plugins/wearable/display/core.c | 9 +- plugins/wearable/display/key-filter.c | 9 +- plugins/wearable/display/swim.c | 7 +- src/battery/lowbat-handler.c | 10 +- src/battery/power-supply.c | 24 ++-- src/display/ambient-mode.c | 19 +-- src/display/core.h | 3 - src/display/display-dbus.c | 33 +++-- src/display/display-lock.c | 57 ++++++++ src/display/display-lock.h | 2 + src/display/display-misc.c | 2 +- src/display/display-panel.c | 2 +- src/display/display-plugin.c | 24 ---- src/display/display-plugin.h | 6 - src/display/display-state-transition.c | 31 +++++ src/display/display-state-transition.h | 3 + src/display/display-util.c | 18 +++ src/display/display-util.h | 1 + src/display/display.c | 5 +- src/display/poll.c | 160 ----------------------- src/display/poll.h | 2 - src/extcon/cradle.c | 10 +- src/extcon/earjack.c | 3 +- src/shared/apps.c | 5 +- src/time/time-handler.c | 8 +- src/usb-gadget/usb-gadget.c | 7 +- src/usb-host/usb-host.c | 5 +- tests/deviced-common-private-test/CMakeLists.txt | 2 +- tests/deviced-common-private-test/test-mock.c | 3 +- 37 files changed, 222 insertions(+), 324 deletions(-) delete mode 100644 src/display/poll.c diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 2c41ed9..f1607e6 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -223,9 +223,6 @@ static int display_probe(void *data) if (ret) return ret; - /* display_plugin instance initialization */ - init_pm_internal(data); - return 0; } @@ -328,8 +325,7 @@ 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, + display_lock_request_lock_with_option(INTERNAL_LOCK_BOOTING, LCD_OFF, STAY_CUR_STATE, DELAYED_INIT_WATING_TIME); /* Initial display state right after the booting done */ @@ -348,8 +344,7 @@ 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, + display_lock_request_lock_with_option(INTERNAL_LOCK_BOOTING, LCD_NORMAL, STAY_CUR_STATE, timeout); } diff --git a/plugins/iot-headed/display/key-filter.c b/plugins/iot-headed/display/key-filter.c index fec11d9..2cf5f3b 100644 --- a/plugins/iot-headed/display/key-filter.c +++ b/plugins/iot-headed/display/key-filter.c @@ -135,8 +135,7 @@ 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); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); display_state_transition_do_state_transition_by_input_poll_event(); } @@ -391,8 +390,7 @@ static int lcdoff_powerkey(void) display_lock_release_lock_all(S_NORMAL); display_lock_release_lock_all(S_LCDDIM); display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_POWERKEY, LCD_OFF); } else { ignore = false; skip_combination = false; @@ -502,8 +500,7 @@ static int process_screenlock_key(struct input_event *pinput) display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(-1, LCD_OFF); + display_state_transition_request_state_transition_with_option(-1, LCD_OFF); return true; } diff --git a/plugins/mobile/battery/battery-notification.c b/plugins/mobile/battery/battery-notification.c index b815542..ba6361e 100644 --- a/plugins/mobile/battery/battery-notification.c +++ b/plugins/mobile/battery/battery-notification.c @@ -28,7 +28,9 @@ #include "lowbat-handler.h" #include "battery-ops.h" #include "core.h" +#include "display-lock.h" #include "display-ops.h" +#include "display-state-transition.h" #include "poll.h" #include "shared/eventsystem.h" #include "shared/plugin.h" @@ -160,8 +162,7 @@ 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); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_LOWBAT, LCD_NORMAL); } prev_level = battery_info.warning; if (battery->charge_now) @@ -201,8 +202,7 @@ 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); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_LOWBAT, LCD_NORMAL); } prev_level = battery_info.critical; if (battery->charge_now) @@ -328,10 +328,8 @@ 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); + display_lock_request_unlock_with_option(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); + display_lock_request_lock_with_option(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) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 30cd412..197a39d 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -272,9 +272,6 @@ static int display_probe(void *data) if (ret) return ret; - /* display_plugin instance initialization */ - init_pm_internal(data); - return 0; } @@ -378,8 +375,7 @@ 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, + display_lock_request_lock_with_option(INTERNAL_LOCK_BOOTING, LCD_OFF, STAY_CUR_STATE, DELAYED_INIT_WATING_TIME); /* Initial display state right after the booting done */ @@ -398,8 +394,7 @@ 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, + display_lock_request_lock_with_option(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 735b30c..17092f2 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -127,8 +127,7 @@ 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); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); display_state_transition_do_state_transition_by_input_poll_event(); } @@ -381,8 +380,7 @@ static int lcdoff_powerkey(void) display_lock_release_lock_all(S_NORMAL); display_lock_release_lock_all(S_LCDDIM); display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_POWERKEY, LCD_OFF); } else { ignore = false; skip_combination = false; @@ -534,8 +532,7 @@ static int process_screenlock_key(struct input_event *pinput) display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(-1, LCD_OFF); + display_state_transition_request_state_transition_with_option(-1, LCD_OFF); return true; } diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 16341ec..ba2a191 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -220,9 +220,6 @@ static int display_probe(void *data) if (ret) return ret; - /* display_plugin instance initialization */ - init_pm_internal(data); - return 0; } @@ -325,8 +322,7 @@ 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, + display_lock_request_lock_with_option(INTERNAL_LOCK_BOOTING, LCD_OFF, STAY_CUR_STATE, DELAYED_INIT_WATING_TIME); /* Initial display state right after the booting done */ @@ -345,8 +341,7 @@ 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, + display_lock_request_lock_with_option(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 e699c1c..6b0b940 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -134,8 +134,7 @@ 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); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); display_state_transition_do_state_transition_by_input_poll_event(); } @@ -390,8 +389,7 @@ static int lcdoff_powerkey(void) display_lock_release_lock_all(S_NORMAL); display_lock_release_lock_all(S_LCDDIM); display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_POWERKEY, LCD_OFF); } else { ignore = false; skip_combination = false; @@ -501,8 +499,7 @@ static int process_screenlock_key(struct input_event *pinput) display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(-1, LCD_OFF); + display_state_transition_request_state_transition_with_option(-1, LCD_OFF); return true; } diff --git a/plugins/wearable/display/bezel.c b/plugins/wearable/display/bezel.c index 3f03460..e206aa3 100644 --- a/plugins/wearable/display/bezel.c +++ b/plugins/wearable/display/bezel.c @@ -24,7 +24,9 @@ #include "shared/device-notifier.h" #include "poll.h" #include "core.h" +#include "display-lock.h" #include "display-ops.h" +#include "display-state-transition.h" #include "shared/log.h" #include "shared/plugin.h" @@ -58,8 +60,7 @@ 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); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_PM, LCD_NORMAL); device_notify(DEVICE_NOTIFIER_BEZEL_WAKEUP, (void *)((intptr_t)bezel_wakeup)); } @@ -121,8 +122,7 @@ static void bezel_rotary_event_cb(keynode_t *key_nodes, void *data) ret = hal_device_bezel_set_sw_state(bezel_state); 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); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_PM, LCD_NORMAL); } else { _E("Failed to set bezel rotary event condition."); } diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 86be20d..082e87b 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -977,9 +977,6 @@ static int display_probe(void *data) if (ret) return ret; - /* display_plugin instance initialization */ - init_pm_internal(data); - return 0; } @@ -1117,8 +1114,7 @@ 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, + display_lock_request_lock_with_option(INTERNAL_LOCK_BOOTING, LCD_OFF, STAY_CUR_STATE, DELAYED_INIT_WATING_TIME); /* Initial display state right after the booting done */ @@ -1137,8 +1133,7 @@ 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, + display_lock_request_lock_with_option(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 55c1f8e..13fd03e 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -126,8 +126,7 @@ 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); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); display_state_transition_do_state_transition_by_input_poll_event(); } @@ -389,8 +388,7 @@ static int lcdoff_powerkey(void) display_lock_release_lock_all(S_NORMAL); display_lock_release_lock_all(S_LCDDIM); display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_OFF); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_POWERKEY, LCD_OFF); } else { ignore = false; skip_combination = false; @@ -500,8 +498,7 @@ static int process_screenlock_key(struct input_event *pinput) display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_POWERKEY); /* LCD off forcly */ - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(-1, LCD_OFF); + display_state_transition_request_state_transition_with_option(-1, LCD_OFF); return true; } diff --git a/plugins/wearable/display/swim.c b/plugins/wearable/display/swim.c index 25ad0fa..f75756d 100644 --- a/plugins/wearable/display/swim.c +++ b/plugins/wearable/display/swim.c @@ -24,6 +24,7 @@ #include "device-interface.h" #include "display-ops.h" #include "display-panel.h" +#include "display-state-transition.h" #include "shared/plugin.h" #include "shared/log.h" @@ -94,16 +95,14 @@ static void swimmode_signal_handler(GDBusConnection *conn, _I("Request swim mode state %d by %d", val, pid); if (display_panel_get_dpms_cached_state() != DPMS_ON) { - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(INTERNAL_LOCK_SWIM, S_NORMAL); + display_state_transition_request_state_transition_with_option(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); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_SWIM, S_LCDOFF); } } diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index b67e6dd..0e2bec2 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -41,8 +41,10 @@ #include "shared/plugin.h" #include "setting.h" #include "poll.h" +#include "display-lock.h" #include "display-ops.h" #include "display-plugin.h" +#include "display-state-transition.h" #include "power/power.h" #include "power/power-off.h" #include "power-supply.h" @@ -253,9 +255,9 @@ 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) { - display_plugin_pm_change_internal(INTERNAL_LOCK_LOWBAT, LCD_DIM); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_LOWBAT, LCD_DIM); } else { - display_plugin_pm_change_internal(INTERNAL_LOCK_LOWBAT, LCD_NORMAL); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_LOWBAT, LCD_NORMAL); } if (lowbat_popup_option == BAT_OPT_ERR_TEMP_LOW || lowbat_popup_option == BAT_OPT_ERR_TEMP_HIGH || @@ -301,14 +303,14 @@ int battery_charge_err_cf_act(void *data) int battery_charge_err_low_act(void *data) { - display_plugin_pm_lock_internal(INTERNAL_LOCK_OVERCOOL, LCD_OFF, STAY_CUR_STATE, 60000); + display_lock_request_lock_with_option(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) { - display_plugin_pm_lock_internal(INTERNAL_LOCK_OVERHEAT, LCD_OFF, STAY_CUR_STATE, 60000); + display_lock_request_lock_with_option(INTERNAL_LOCK_OVERHEAT, LCD_OFF, STAY_CUR_STATE, 60000); return lowbat_popup(BAT_OPT_ERR_TEMP_HIGH); } diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index c9c4c21..aa842eb 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -37,7 +37,9 @@ #include "shared/apps.h" #include "shared/event.h" #include "core.h" +#include "display-lock.h" #include "display-ops.h" +#include "display-state-transition.h" #include "power-supply.h" #include "battery.h" #include "battery-ops.h" @@ -413,11 +415,11 @@ 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); - display_plugin_pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); + display_lock_request_lock_with_option(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); - display_plugin_pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, PM_SLEEP_MARGIN); + display_lock_request_unlock_with_option(INTERNAL_LOCK_POPUP, LCD_DIM, PM_SLEEP_MARGIN); } if (battery_plgn->changed_battery_cf) battery_plgn->changed_battery_cf(battery.present); @@ -433,8 +435,8 @@ 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); - display_plugin_pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); - display_plugin_pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, LCD_DIM_TIME_IN_BATTERY_HEALTH); + display_lock_request_unlock_with_option(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); + display_lock_request_lock_with_option(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) @@ -465,8 +467,8 @@ 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); - display_plugin_pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, PM_SLEEP_MARGIN); - display_plugin_pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); + display_lock_request_unlock_with_option(INTERNAL_LOCK_POPUP, LCD_DIM, PM_SLEEP_MARGIN); + display_lock_request_unlock_with_option(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); health_status_broadcast(); if (abnormal_health_popup_timer) { CRITICAL_LOG("Battery health returned to normal. Stop abnormal popup."); @@ -488,8 +490,8 @@ void relaunch_health_popup(void) if (abnormal_health_popup_timer) g_source_remove(abnormal_health_popup_timer); - display_plugin_pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); - display_plugin_pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, LCD_DIM_TIME_IN_BATTERY_HEALTH); + display_lock_request_unlock_with_option(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); + display_lock_request_lock_with_option(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) @@ -674,7 +676,7 @@ static void process_power_supply(void *data) int ret_lock = -1; int ret_val; - ret_lock = display_plugin_pm_lock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, STAY_CUR_STATE, 0); + ret_lock = display_lock_request_lock_with_option(INTERNAL_LOCK_BATTERY, LCD_OFF, STAY_CUR_STATE, 0); if (old_battery.charge_now != battery.charge_now || battery.charge_now == CHARGER_ABNORMAL) { ret_val = vconf_set_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, battery.charge_now); @@ -786,7 +788,7 @@ static void process_power_supply(void *data) } if (ret_lock == 0) { - display_plugin_pm_unlock_internal(INTERNAL_LOCK_BATTERY, LCD_OFF, PM_SLEEP_MARGIN); + display_lock_request_unlock_with_option(INTERNAL_LOCK_BATTERY, LCD_OFF, PM_SLEEP_MARGIN); } } @@ -1378,7 +1380,7 @@ int battery_pm_change_internal(int pid, int s_bits) if (battery_do_not_disturb()) return 0; - display_plugin_pm_change_internal(pid, s_bits); + display_state_transition_request_state_transition_with_option(pid, s_bits); return 0; } diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index 139b6c7..7c56b8a 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -23,6 +23,7 @@ #include "core.h" #include "display.h" +#include "display-lock.h" #include "display-ops.h" #include "display-panel.h" #include "display-plugin.h" @@ -89,8 +90,7 @@ static void ambient_set_condition(keynode_t *key_nodes, void *data) val = vconf_keynode_get_bool(key_nodes); if (val != ambient_condition) { if (display_panel_get_dpms_cached_state() != DPMS_ON) - if (disp_plgn->pm_lock_internal) - disp_plgn->pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_PM, LCD_NORMAL); } ambient_condition = val; @@ -118,8 +118,7 @@ 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, + display_lock_request_lock_with_option(INTERNAL_LOCK_AMBIENT, LCD_OFF, STAY_CUR_STATE, AMBIENT_CLOCK_WAITING_TIME); } else ambient_pid = 0; @@ -168,8 +167,7 @@ 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, + display_lock_request_lock_with_option(INTERNAL_LOCK_AMBIENT, LCD_OFF, STAY_CUR_STATE, AMBIENT_CLOCK_WAITING_TIME); } @@ -185,8 +183,7 @@ static void ambient_end_clock(pid_t pid) display_panel_set_panel_state_by_off_state(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); + display_lock_request_unlock_with_option(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); } update_count++; @@ -245,8 +242,7 @@ 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); + display_lock_request_lock_with_option(INTERNAL_LOCK_AMBIENT, LCD_OFF, GOTO_STATE_NOW, 0); _I("Display off in suspend state."); @@ -254,8 +250,7 @@ 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); + display_lock_request_unlock_with_option(INTERNAL_LOCK_AMBIENT, LCD_OFF, PM_SLEEP_MARGIN); } static void ambient_init(void *data) diff --git a/src/display/core.h b/src/display/core.h index 468fdb1..5b71967 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -109,9 +109,6 @@ void broadcast_lcd_off_late(enum device_flags flags); /* auto-brightness.c */ void set_brightness_changed_state(void); -/* poll.c */ -int check_dimstay(int next_state, int flag); - /* display-dbus.c */ int init_pm_dbus(void); diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 8f37f24..05c9a9d 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -50,6 +50,7 @@ //#include "display/display.h" #include "display-backlight.h" #include "display-misc.h" +#include "display-util.h" #define AUL_APPSTATUS_PATH "/Org/Tizen/Aul/AppStatus" #define AUL_APPSTATUS_INTERFACE "org.tizen.aul.AppStatus" @@ -101,14 +102,27 @@ 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); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_PM, LCD_NORMAL); display_device_ops->stop(CORE_LOGIC_MODE); out: return gdbus_new_g_variant_tuple(); } +static int check_dimstay(int next_state, int flag) +{ + if (next_state != LCD_OFF) + return false; + + if (!(flag & GOTO_STATE_NOW)) + return false; + + if (!(get_pm_status_flag() & DIMSTAY_FLAG)) + return false; + + return true; +} + static GVariant *dbus_lockstate(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) @@ -192,8 +206,7 @@ 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); + display_lock_request_lock_with_option(pid, state, flag, timeout); out: g_free(state_str); g_free(option1_str); @@ -260,8 +273,7 @@ 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); + display_lock_request_unlock_with_option(pid, state, flag); out: g_free(state_str); g_free(option_str); @@ -355,8 +367,7 @@ static GVariant *dbus_changestate(GDBusConnection *conn, goto out; } - if (disp_plgn->pm_change_internal) - ret = disp_plgn->pm_change_internal(pid, state); + display_state_transition_request_state_transition_with_option(pid, state); if (!ret && state == LCD_OFF) display_state_transition_update_lcdoff_reason(VCONFKEY_PM_LCDOFF_BY_TIMEOUT); @@ -848,13 +859,11 @@ 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, + display_lock_request_lock_with_option(INTERNAL_LOCK_DUMPMODE, LCD_OFF, STAY_CUR_STATE, DUMP_MODE_WATING_TIME); display_backlight_unset_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); + display_lock_request_unlock_with_option(INTERNAL_LOCK_DUMPMODE, LCD_OFF, PM_SLEEP_MARGIN); display_backlight_set_blink(0); } else if (!strcmp(on, "blink")) { display_backlight_set_blink(500); diff --git a/src/display/display-lock.c b/src/display/display-lock.c index 85d731e..fe24f75 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -34,6 +34,7 @@ #include "display-config.h" #include "display-misc.h" #include "display-state-transition.h" +#include "display-util.h" #include "shared/log.h" #include "shared/log-macro.h" #include "shared/apps.h" @@ -728,4 +729,60 @@ int display_lock_proc_condition(PMMsg *data) display_state_transition_do_state_transition(get_pm_cur_state(), EVENT_TIMEOUT); return 0; +} + +int display_lock_request_lock_with_option(pid_t pid, int s_bits, int flag, int timeout) +{ + int cond; + PMMsg recv_data; + + cond = display_util_get_display_state(s_bits); + if (cond < 0) + return cond; + + if (!display_state_transition_is_display_state_support_transition(cond)) + return -ENOTSUP; + + cond = SET_COND_REQUEST(cond, PM_REQUEST_LOCK); + + if (flag & GOTO_STATE_NOW) + /* if the flag is true, go to the locking state directly */ + cond = SET_COND_FLAG(cond, PM_REQUEST_CHANGE); + + recv_data.pid = pid; + recv_data.cond = cond; + recv_data.timeout = timeout; + + display_state_transition_do_state_transition_by_pm_control_event(&recv_data); + + return 0; +} + +int display_lock_request_unlock_with_option(pid_t pid, int s_bits, int flag) +{ + int cond; + PMMsg recv_data; + + cond = display_util_get_display_state(s_bits); + if (cond < 0) + return cond; + + if (!display_state_transition_is_display_state_support_transition(cond)) + return -ENOTSUP; + + cond = SET_COND_REQUEST(cond, PM_REQUEST_UNLOCK); + + if (flag & PM_KEEP_TIMER) + cond = SET_COND_FLAG(cond, PM_FLAG_KEEP_TIMER); + + if (flag & PM_RESET_TIMER) + cond = SET_COND_FLAG(cond, PM_FLAG_RESET_TIMER); + + recv_data.pid = pid; + recv_data.cond = cond; + recv_data.timeout = 0; + + display_state_transition_do_state_transition_by_pm_control_event(&recv_data); + + return 0; } \ No newline at end of file diff --git a/src/display/display-lock.h b/src/display/display-lock.h index 7f2679a..ab07a24 100644 --- a/src/display/display-lock.h +++ b/src/display/display-lock.h @@ -42,5 +42,7 @@ int display_lock_is_state_locked(enum state_t state); int display_lock_print_lock_info(int fd); int display_lock_proc_condition(PMMsg *data); +int display_lock_request_lock_with_option(pid_t pid, int s_bits, int flag, int timeout); +int display_lock_request_unlock_with_option(pid_t pid, int s_bits, int flag); #endif /* __DISPLAY_LOCK_H__ */ diff --git a/src/display/display-misc.c b/src/display/display-misc.c index e7ed556..8d812fe 100644 --- a/src/display/display-misc.c +++ b/src/display/display-misc.c @@ -85,7 +85,7 @@ void display_misc_set_stay_touchscreen_off(bool on) _I("Stay touch screen off: %d", on); stay_touchscreen_off = on; - display_plugin_pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_PM, LCD_NORMAL); } void display_misc_get_stay_touchscreen_off(bool *on) diff --git a/src/display/display-panel.c b/src/display/display-panel.c index ec6706c..aa3df63 100644 --- a/src/display/display-panel.c +++ b/src/display/display-panel.c @@ -202,7 +202,7 @@ void display_panel_set_lcd_paneloff_mode(bool on) _I("Lcd paneloff mode: %d", on); lcd_paneloff_mode = on; - display_plugin_pm_change_internal(INTERNAL_LOCK_PM, LCD_NORMAL); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_PM, LCD_NORMAL); } /* FIXME: This function is temporary, it can be redefined or not */ diff --git a/src/display/display-plugin.c b/src/display/display-plugin.c index 1328593..3380401 100644 --- a/src/display/display-plugin.c +++ b/src/display/display-plugin.c @@ -27,30 +27,6 @@ void* display_plugin_handle(void) return g_display_plugin.handle; } -int display_plugin_pm_lock_internal(pid_t pid, int s_bits, int flags, int timeout) -{ - if (g_display_plugin.pm_lock_internal) - return g_display_plugin.pm_lock_internal(pid, s_bits, flags, timeout); - - return 0; -} - -int display_plugin_pm_unlock_internal(pid_t pid, int s_bits, int flags) -{ - if (g_display_plugin.pm_unlock_internal) - return g_display_plugin.pm_unlock_internal(pid, s_bits, flags); - - return 0; -} - -int display_plugin_pm_change_internal(pid_t pid, int s_bits) -{ - if (g_display_plugin.pm_change_internal) - return g_display_plugin.pm_change_internal(pid, s_bits); - - return 0; -} - int display_plugin_update_pm_setting(int key_idx, int val) { if (g_display_plugin.update_pm_setting) diff --git a/src/display/display-plugin.h b/src/display/display-plugin.h index f6d9949..159f956 100644 --- a/src/display/display-plugin.h +++ b/src/display/display-plugin.h @@ -56,9 +56,6 @@ enum brightness_request_e { struct display_plugin { void *handle; - int (*pm_lock_internal) (pid_t pid, int s_bits, int flag, int timeout); - int (*pm_unlock_internal) (pid_t pid, int s_bits, int flag); - int (*pm_change_internal) (pid_t pid, int s_bits); int (*update_pm_setting) (int key_idx, int val); int (*get_lock_screen_state) (void); bool system_wakeup_flag; @@ -86,9 +83,6 @@ struct display_plugin { extern struct display_plugin g_display_plugin; void* display_plugin_handle(void); -int display_plugin_pm_lock_internal(pid_t pid, int s_bits, int flags, int timeout); -int display_plugin_pm_unlock_internal(pid_t pid, int s_bits, int flags); -int display_plugin_pm_change_internal(pid_t pid, int s_bits); int display_plugin_update_pm_setting(int key_idx, int val); bool display_plugin_is_there_update_pm_setting(void); int display_plugin_get_lock_screen_state(void); diff --git a/src/display/display-state-transition.c b/src/display/display-state-transition.c index cfab4fc..83a4c26 100644 --- a/src/display/display-state-transition.c +++ b/src/display/display-state-transition.c @@ -28,6 +28,7 @@ #include "display-lock.h" #include "display-plugin.h" #include "display-signal.h" +#include "display-util.h" #include "extcon/extcon.h" #include "power/power.h" #include "power/power-suspend.h" @@ -633,3 +634,33 @@ int display_state_transition_do_proc_change_state(unsigned int cond, pid_t pid) return 0; } + +int display_state_transition_request_state_transition_with_option(pid_t pid, int s_bits) +{ + int cond, ret; + PMMsg recv_data; + const int display_on = (LCD_NORMAL | LCD_DIM); + + cond = display_util_get_display_state(s_bits); + if (cond < 0) + return cond; + + ret = display_plugin_is_lcd_on_blocked(); + if (ret != LCDON_BLOCK_NONE && (cond & display_on)) { + _W("LCDON is blocked, %d.", ret); + return -ENOTSUP; + } + + if (!display_state_transition_is_display_state_support_transition(cond)) + return -ENOTSUP; + + cond = SET_COND_REQUEST(cond, PM_REQUEST_CHANGE); + + recv_data.pid = pid; + recv_data.cond = cond; + recv_data.timeout = 0; + + display_state_transition_do_state_transition_by_pm_control_event(&recv_data); + + return 0; +} \ No newline at end of file diff --git a/src/display/display-state-transition.h b/src/display/display-state-transition.h index a7d4dd9..9ef1708 100644 --- a/src/display/display-state-transition.h +++ b/src/display/display-state-transition.h @@ -24,6 +24,8 @@ #ifndef __DISPLAY_STATE_TRANSITION_H__ #define __DISPLAY_STATE_TRANSITION_H__ +#include + #include "core.h" #define LOCK_SCREEN_INPUT_TIMEOUT 10000 @@ -48,5 +50,6 @@ int display_state_transition_do_state_transition_by_pm_control_event(PMMsg *data int display_state_transition_do_state_action(int timeout); void display_state_transition_do_proc_change_state_action(enum state_t next, int timeout); int display_state_transition_do_proc_change_state(unsigned int cond, pid_t pid); +int display_state_transition_request_state_transition_with_option(pid_t pid, int s_bits); #endif /* __DISPLAY_STATE_TRANSITION_H__ */ \ No newline at end of file diff --git a/src/display/display-util.c b/src/display/display-util.c index eb9556a..ef7db97 100644 --- a/src/display/display-util.c +++ b/src/display/display-util.c @@ -73,3 +73,21 @@ int display_util_get_device_flags(unsigned long *device_flags) return 0; } + +int display_util_get_display_state(int s_bits) +{ + switch (s_bits) { + case LCD_NORMAL: + return S_NORMAL; + case LCD_DIM: + return S_LCDDIM; + case LCD_OFF: + return S_LCDOFF; + case STANDBY: + return S_STANDBY; + case SUSPEND: + return S_SLEEP; + default: + return -EINVAL; + } +} \ No newline at end of file diff --git a/src/display/display-util.h b/src/display/display-util.h index 39f7e71..9be17f1 100644 --- a/src/display/display-util.h +++ b/src/display/display-util.h @@ -27,5 +27,6 @@ int display_util_get_device_flags_name(enum device_flags flags, const char **flag_name); int display_util_get_device_flags(unsigned long *device_flags); +int display_util_get_display_state(int s_bits); #endif /* __DISPLAY_UTIL_H__ */ \ No newline at end of file diff --git a/src/display/display.c b/src/display/display.c index 7b06647..97e4f27 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -26,6 +26,7 @@ #include "shared/log.h" #include "device-interface.h" #include "display.h" +#include "display-lock.h" #include "display-plugin.h" #include "display-config.h" #include "display-misc.h" @@ -430,8 +431,8 @@ static int delayed_init_done(void *data) return done; _I("Booting done, release booting lock."); - display_plugin_pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_NORMAL, PM_SLEEP_MARGIN); - display_plugin_pm_unlock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); + display_lock_request_unlock_with_option(INTERNAL_LOCK_BOOTING, LCD_NORMAL, PM_SLEEP_MARGIN); + display_lock_request_unlock_with_option(INTERNAL_LOCK_BOOTING, LCD_OFF, PM_SLEEP_MARGIN); return done; } diff --git a/src/display/poll.c b/src/display/poll.c deleted file mode 100644 index 8a09447..0000000 --- a/src/display/poll.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * @file poll.c - * @brief Power Manager poll implementation - * - */ - -#include -#include "core.h" -#include "device-interface.h" -#include "poll.h" -#include "display-ops.h" -#include "display-plugin.h" -#include "display-state-transition.h" -#include "shared/log.h" -#include "shared/plugin.h" - -static PMMsg recv_data; - -int check_dimstay(int next_state, int flag) -{ - if (next_state != LCD_OFF) - return false; - - if (!(flag & GOTO_STATE_NOW)) - return false; - - if (!(get_pm_status_flag() & DIMSTAY_FLAG)) - return false; - - return true; -} - -static enum state_t get_state(int s_bits) -{ - switch (s_bits) { - case LCD_NORMAL: - return S_NORMAL; - case LCD_DIM: - return S_LCDDIM; - case LCD_OFF: - return S_LCDOFF; - case STANDBY: - return S_STANDBY; - case SUSPEND: - return S_SLEEP; - default: - return -EINVAL; - } -} - -static int __pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout) -{ - int cond; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!display_state_transition_is_display_state_support_transition(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_LOCK); - - if (flag & GOTO_STATE_NOW) - /* if the flag is true, go to the locking state directly */ - cond = SET_COND_FLAG(cond, PM_REQUEST_CHANGE); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = timeout; - - display_state_transition_do_state_transition_by_pm_control_event(&recv_data); - - return 0; -} - -static int __pm_unlock_internal(pid_t pid, int s_bits, int flag) -{ - int cond; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - if (!display_state_transition_is_display_state_support_transition(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_UNLOCK); - - if (flag & PM_KEEP_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_KEEP_TIMER); - - if (flag & PM_RESET_TIMER) - cond = SET_COND_FLAG(cond, PM_FLAG_RESET_TIMER); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - display_state_transition_do_state_transition_by_pm_control_event(&recv_data); - - return 0; -} - -static int __pm_change_internal(pid_t pid, int s_bits) -{ - int cond, ret; - const int display_on = LCD_NORMAL | LCD_DIM; - - cond = get_state(s_bits); - if (cond < 0) - return cond; - - ret = display_plugin_is_lcd_on_blocked(); - if (ret != LCDON_BLOCK_NONE && (cond & display_on)) { - _W("LCDON is blocked, %d.", ret); - return -ENOTSUP; - } - - if (!display_state_transition_is_display_state_support_transition(cond)) - return -ENOTSUP; - - cond = SET_COND_REQUEST(cond, PM_REQUEST_CHANGE); - - recv_data.pid = pid; - recv_data.cond = cond; - recv_data.timeout = 0; - - display_state_transition_do_state_transition_by_pm_control_event(&recv_data); - - return 0; -} - -void init_pm_internal(void *data) -{ - struct display_plugin *dp = (struct display_plugin *) data; - - dp->pm_lock_internal = __pm_lock_internal; - dp->pm_unlock_internal = __pm_unlock_internal; - dp->pm_change_internal = __pm_change_internal; -} diff --git a/src/display/poll.h b/src/display/poll.h index 086f875..262e224 100644 --- a/src/display/poll.h +++ b/src/display/poll.h @@ -134,8 +134,6 @@ enum cond_flags_e { #define RESET_TIMER_STR "resettimer" #define KEEP_TIMER_STR "keeptimer" -void init_pm_internal(void *data); - /** * @} */ diff --git a/src/extcon/cradle.c b/src/extcon/cradle.c index ee1c5f4..93bc398 100644 --- a/src/extcon/cradle.c +++ b/src/extcon/cradle.c @@ -25,8 +25,10 @@ #include "shared/device-notifier.h" #include "core/udev.h" #include "core.h" +#include "display-lock.h" #include "display-ops.h" #include "display-plugin.h" +#include "display-state-transition.h" #include "extcon/extcon.h" #include "shared/plugin.h" @@ -60,7 +62,7 @@ static int cradle_update(const char *index, int status) int ret; _I("Cradle changed. status=%d", status); - display_plugin_pm_change_internal(INTERNAL_LOCK_CRADLE, LCD_NORMAL); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_CRADLE, LCD_NORMAL); cradle_send_broadcast(status); ret = vconf_set_int(VCONFKEY_SYSMAN_CRADLE_STATUS, status); if (ret < 0) { @@ -69,9 +71,9 @@ static int cradle_update(const char *index, int status) } if (status == DOCK_SOUND) { - display_plugin_pm_lock_internal(INTERNAL_LOCK_CRADLE, LCD_DIM, STAY_CUR_STATE, 0); + display_lock_request_lock_with_option(INTERNAL_LOCK_CRADLE, LCD_DIM, STAY_CUR_STATE, 0); } else if (status == DOCK_NONE) { - display_plugin_pm_unlock_internal(INTERNAL_LOCK_CRADLE, LCD_DIM, PM_SLEEP_MARGIN); + display_lock_request_unlock_with_option(INTERNAL_LOCK_CRADLE, LCD_DIM, PM_SLEEP_MARGIN); } return 0; @@ -91,7 +93,7 @@ static int display_changed(void *data) cradle = cradle_extcon_ops.status; if (cradle == DOCK_SOUND) { - display_plugin_pm_lock_internal(INTERNAL_LOCK_CRADLE, LCD_DIM, STAY_CUR_STATE, 0); + display_lock_request_lock_with_option(INTERNAL_LOCK_CRADLE, LCD_DIM, STAY_CUR_STATE, 0); _I("Sound dock is connected. Dim lock is on."); } diff --git a/src/extcon/earjack.c b/src/extcon/earjack.c index 87fcc57..ae9f96d 100644 --- a/src/extcon/earjack.c +++ b/src/extcon/earjack.c @@ -26,6 +26,7 @@ #include "poll.h" #include "display-ops.h" #include "display-plugin.h" +#include "display-state-transition.h" #include "extcon/extcon.h" #include "shared/plugin.h" @@ -96,7 +97,7 @@ static int earjack_update(const char *index, int status) earjack_send_broadcast(status); earjack_send_system_event(status); if (status != EARJACK_DISCONNECTED) { - display_plugin_pm_change_internal(INTERNAL_LOCK_EARJACK, LCD_NORMAL); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_EARJACK, LCD_NORMAL); } old_status = status; diff --git a/src/shared/apps.c b/src/shared/apps.c index caa6155..bb3a9c9 100644 --- a/src/shared/apps.c +++ b/src/shared/apps.c @@ -23,6 +23,7 @@ #include "shared/common.h" #include "apps.h" #include "display-plugin.h" +#include "display-state-transition.h" #include "shared/bitmap.h" #define POPUP_METHOD "PopupLaunch" @@ -103,7 +104,7 @@ int launch_system_app(char *type, int num, ...) va_end(args); - display_plugin_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_POPUP, LCD_NORMAL); return ret; } @@ -122,7 +123,7 @@ int launch_message_post(char *type) g_variant_new("(s)", type), __cb, -1, NULL); - display_plugin_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_POPUP, LCD_NORMAL); return ret; } diff --git a/src/time/time-handler.c b/src/time/time-handler.c index 1d4c377..977697d 100644 --- a/src/time/time-handler.c +++ b/src/time/time-handler.c @@ -191,11 +191,11 @@ int set_datetime_action(int argc, char **argv) else pm_state = 0x4; - display_plugin_pm_lock_internal(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE, 0); + display_lock_request_lock_with_option(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE, 0); ret = handle_date(argv[0]); - display_plugin_pm_unlock_internal(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE); + display_lock_request_unlock_with_option(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE); return ret; } @@ -218,11 +218,11 @@ int set_timezone_action(int argc, char **argv) else pm_state = 0x4; - display_plugin_pm_lock_internal(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE, 0); + display_lock_request_lock_with_option(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE, 0); ret = handle_timezone(argv[0]); - display_plugin_pm_unlock_internal(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE); + display_lock_request_unlock_with_option(INTERNAL_LOCK_TIME, pm_state, STAY_CUR_STATE); return ret; } diff --git a/src/usb-gadget/usb-gadget.c b/src/usb-gadget/usb-gadget.c index 009fa59..0ccfb25 100644 --- a/src/usb-gadget/usb-gadget.c +++ b/src/usb-gadget/usb-gadget.c @@ -23,6 +23,7 @@ #include "core/log.h" #include "core/udev.h" #include "poll.h" +#include "display-lock.h" #include "display-ops.h" #include "display-plugin.h" #include "shared/plugin.h" @@ -104,7 +105,7 @@ static int usb_connected(void) int ret; unsigned int mode = usb_state_get_selected_mode(); - display_plugin_pm_lock_internal(INTERNAL_LOCK_USB, LCD_OFF, STAY_CUR_STATE, 0); + display_lock_request_lock_with_option(INTERNAL_LOCK_USB, LCD_OFF, STAY_CUR_STATE, 0); usb_state_set_connection(USB_CONNECTED); send_usb_state_changed_event(VCONFKEY_SYSMAN_USB_CONNECTED); @@ -129,10 +130,10 @@ 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 display_plugin_pm_unlock_internal */ + /* Important: You have to keep going to unlock display_lock_request_unlock_with_option */ } - display_plugin_pm_unlock_internal(INTERNAL_LOCK_USB, LCD_OFF, STAY_CUR_STATE); + display_lock_request_unlock_with_option(INTERNAL_LOCK_USB, LCD_OFF, STAY_CUR_STATE); return ret; } diff --git a/src/usb-host/usb-host.c b/src/usb-host/usb-host.c index 68a5b8c..15d29d1 100644 --- a/src/usb-host/usb-host.c +++ b/src/usb-host/usb-host.c @@ -34,6 +34,7 @@ #include "display-ops.h" #include "display-plugin.h" #include "display-config.h" +#include "display-state-transition.h" #include "core.h" #include "dd-usbhost.h" #include "shared/plugin.h" @@ -244,7 +245,7 @@ static int add_usbhost_list(struct udev_device *dev, const char *devpath) broadcast_usbhost_signal(USB_HOST_ADDED, usbhost); if (display_on_usb_conn_changed) - display_plugin_pm_change_internal(INTERNAL_LOCK_USB_HOST, LCD_NORMAL); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_USB_HOST, LCD_NORMAL); /* for debugging */ _I("USB HOST Added."); @@ -273,7 +274,7 @@ static int remove_usbhost_list(const char *devpath) broadcast_usbhost_signal(USB_HOST_REMOVED, usbhost); if (display_on_usb_conn_changed) - display_plugin_pm_change_internal(INTERNAL_LOCK_USB_HOST, LCD_NORMAL); + display_state_transition_request_state_transition_with_option(INTERNAL_LOCK_USB_HOST, LCD_NORMAL); /* for debugging */ _I("USB HOST Removed."); diff --git a/tests/deviced-common-private-test/CMakeLists.txt b/tests/deviced-common-private-test/CMakeLists.txt index 212a7f3..c4262d7 100644 --- a/tests/deviced-common-private-test/CMakeLists.txt +++ b/tests/deviced-common-private-test/CMakeLists.txt @@ -14,7 +14,7 @@ PKG_CHECK_MODULES(ORIG_REQUIRED_PKGS REQUIRED SET(WRAP_FLAGS "-Wl,--wrap=dlopen") SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=access") -SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=display_plugin_pm_change_internal") +SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=display_state_transition_request_state_transition_with_option") FILE(GLOB ORIG_SRCS "${CMAKE_SOURCE_DIR}/src/shared/*.c") ADD_LIBRARY(test-shared SHARED ${ORIG_SRCS}) diff --git a/tests/deviced-common-private-test/test-mock.c b/tests/deviced-common-private-test/test-mock.c index c3eba7e..df9d7fe 100644 --- a/tests/deviced-common-private-test/test-mock.c +++ b/tests/deviced-common-private-test/test-mock.c @@ -4,6 +4,7 @@ /* FIXME: This would be replaced to plugin-api-deviced */ #include "display-plugin.h" +#include "display-state-transition.h" #include "test-main.h" #include "test-mock.h" @@ -26,7 +27,7 @@ void *__wrap_dlopen(const char *filename, int flags) return ret; } -int __wrap_display_plugin_pm_change_internal(pid_t pid, int s_bits) +int __wrap_display_state_transition_request_state_transition_with_option(pid_t pid, int s_bits) { return 0; } -- 2.7.4 From 74225792755f9317a32d87e1190664c3d6817d47 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Thu, 13 Jul 2023 12:44:35 +0900 Subject: [PATCH 09/16] display: Relocate display initialization code Except for a specific profile, unnecessarily duplicated codes are erased. And same code is moved to display.c. Change-Id: I35c6e0693fb1e9581ecefa1f03db9fa71681084f Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 156 +------------------------ plugins/iot-headed/display/device-interface.c | 7 -- plugins/mobile/display/core.c | 157 +------------------------- plugins/mobile/display/device-interface.c | 8 -- plugins/tv/display/core.c | 154 +------------------------ plugins/tv/display/device-interface.c | 7 -- plugins/wearable/display/core.c | 149 +----------------------- plugins/wearable/display/device-interface.c | 3 +- src/display/display.c | 138 +++++++++++++++++++++- 9 files changed, 151 insertions(+), 628 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index f1607e6..1a4e4b2 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -78,8 +78,6 @@ * @{ */ -extern void init_save_userlock(void); - static struct display_plugin *disp_plgn; static struct display_backlight_ops *backlight_ops; static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -94,8 +92,6 @@ static struct state states[S_END] = { { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; -#define DELAYED_INIT_WATING_TIME 60000 /* 1 minute */ - #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ #define LONG_PRESS_INTERVAL 2 /* 2 seconds */ #define SAMPLING_INTERVAL 1 /* 1 sec */ @@ -139,28 +135,6 @@ inline struct state* state_st(enum state_t state) return &states[state]; } -static void init_lcd_operation(void) -{ - const struct device_ops *ops = NULL; - - ops = find_device("display"); - if (!check_default(ops)) - display_register_dependent_device(ops); - - ops = find_device("touchkey"); - if (!check_default(ops)) - display_register_dependent_device(ops); - - ops = find_device("touchscreen"); - if (!check_default(ops)) - display_register_dependent_device(ops); -} - -static void exit_lcd_operation(void) -{ - display_unregister_dependent_device(); -} - enum { INIT_SETTING = 0, INIT_INTERFACE, @@ -170,14 +144,6 @@ enum { INIT_END }; -static const char *errMSG[INIT_END] = { - [INIT_SETTING] = "setting init error", - [INIT_INTERFACE] = "lowlevel interface(sysfs or others) init error", - [INIT_POLL] = "input devices poll init error", - [INIT_FIFO] = "FIFO poll init error", - [INIT_DBUS] = "d-bus init error", -}; - static void init_display_states(void *data) { struct display_plugin *dp = (struct display_plugin *) data; @@ -208,7 +174,6 @@ static int display_probe(void *data) dp->default_saving_mode = NULL; dp->is_lcdon_blocked = is_lcdon_blocked; dp->proc_change_state = NULL; - setup_display_plugin_backlight_ops(dp); /* check display feature */ if (!is_feature_display_supported()) @@ -226,132 +191,15 @@ static int display_probe(void *data) return 0; } -static int input_init_handler(void) -{ - if (!display_conf.input_support) - remove_device_by_devname("input"); - - return 0; -} - static void display_init(void *data) { - int ret, i; - unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); - int timeout = 0; - - _I("Start power manager."); + int ret; /* load configutation */ ret = display_load_config(&display_conf); if (ret < 0) _W("Failed to load '%s', use default value: %d", DISPLAY_CONF_FILE, ret); - - register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); - register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); - register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); - - init_save_userlock(); - - for (i = INIT_SETTING; i < INIT_END; i++) { - switch (i) { - case INIT_SETTING: - ret = init_setting(NULL); - break; - case INIT_INTERFACE: - if (display_conf.timeout_enable) - display_initialize_display_state_timeout_from_setting(); - ret = init_sysfs(flags); - break; - case INIT_POLL: - _I("input init"); - ret = input_init_handler(); - - pm_lock_detector_init(); - break; - case INIT_DBUS: - _I("Dbus init."); - ret = init_pm_dbus(); - break; - } - if (ret != 0) { - _E("Failed to init: %s", errMSG[i]); - break; - } - } - - if (i == INIT_END) { - display_ops_init(NULL); -#ifdef ENABLE_PM_LOG - pm_history_init(); -#endif - init_lcd_operation(); - display_set_initial_brightness(); - display_set_initial_battery_flag(); - display_set_initial_lockscreen_status(); - - /* In smd test, TSP should be turned off if display panel is not existed. */ - if (display_panel_get_dpms_cached_state() == -ENOENT) { - _I("Display panel is not existed."); - lcd_direct_control(DPMS_OFF, NORMAL_MODE); - exit_lcd_operation(); - } - - /* wm_ready needs to be checked - * since display manager can be launched later than deviced. - * In the case, display cannot be turned on at the first booting */ - // wm_ready = check_wm_ready(); - if (display_panel_init_dpms()) { - if (is_lcdon_blocked() != LCDON_BLOCK_NONE) - display_panel_lcd_off_procedure(LCD_OFF_BY_EVENT); - else - display_panel_lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - } else { - display_add_timer_for_waiting_dpms_init(); - } - - if (display_conf.lcd_always_on) { - _I("LCD always on."); - display_state_transition_set_transition_table_display_state(S_NORMAL, S_NORMAL, EVENT_TIMEOUT); - } - - if (flags & WITHOUT_STARTNOTI) { /* start without noti */ - _I("Start Power managing without noti"); - power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, - HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN, NULL); - /* - * Lock lcd off until booting is done. - * deviced guarantees all booting script is executing. - * Last script of booting unlocks this suspend blocking state. - */ - display_lock_request_lock_with_option(INTERNAL_LOCK_BOOTING, LCD_OFF, - STAY_CUR_STATE, DELAYED_INIT_WATING_TIME); - - /* Initial display state right after the booting done */ - if (is_lcdon_blocked()) - set_pm_cur_state(S_LCDOFF); - else - set_pm_cur_state(S_NORMAL); - ret = vconf_set_int(VCONFKEY_PM_STATE, get_pm_cur_state()); - if (ret < 0) - _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); - - display_set_display_ops_status(DEVICE_OPS_STATUS_START); - if (display_conf.timeout_enable) { - timeout = states[S_NORMAL].timeout; - /* check minimun lcd on time */ - if (timeout < SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT)) - timeout = SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT); - - display_lock_request_lock_with_option(INTERNAL_LOCK_BOOTING, LCD_NORMAL, - STAY_CUR_STATE, timeout); - } - - } - - set_display_init_direction(display_conf.display_init_direction); - } } static void display_exit(void *data) @@ -385,7 +233,7 @@ static void display_exit(void *data) } } - exit_lcd_operation(); + display_unregister_dependent_device(); free_lock_info_list(); /* free display service */ diff --git a/plugins/iot-headed/display/device-interface.c b/plugins/iot-headed/display/device-interface.c index abb1969..e599fc7 100644 --- a/plugins/iot-headed/display/device-interface.c +++ b/plugins/iot-headed/display/device-interface.c @@ -107,13 +107,6 @@ void setup_display_plugin_backlight_ops(struct display_plugin *dp) dp->backlight = &backlight_ops; } -int init_sysfs(unsigned int flags) -{ - register_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); - - return 0; -} - int exit_sysfs(void) { const struct device_ops *ops = NULL; diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 197a39d..85f378d 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -79,8 +79,6 @@ * @{ */ -extern void init_save_userlock(void); - static struct display_plugin *disp_plgn; static struct display_backlight_ops *backlight_ops; @@ -96,8 +94,6 @@ static struct state states[S_END] = { { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; -#define DELAYED_INIT_WATING_TIME 60000 /* 1 minute */ - #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ #define LONG_PRESS_INTERVAL 400 /* 0.4 seconds */ #define SAMPLING_INTERVAL 1 /* 1 sec */ @@ -192,28 +188,6 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) return 0; } -static void init_lcd_operation(void) -{ - const struct device_ops *ops = NULL; - - ops = find_device("display"); - if (!check_default(ops)) - display_register_dependent_device(ops); - - ops = find_device("touchkey"); - if (!check_default(ops)) - display_register_dependent_device(ops); - - ops = find_device("touchscreen"); - if (!check_default(ops)) - display_register_dependent_device(ops); -} - -static void exit_lcd_operation(void) -{ - display_unregister_dependent_device(); -} - enum { INIT_SETTING = 0, INIT_INTERFACE, @@ -223,14 +197,6 @@ enum { INIT_END }; -static const char *errMSG[INIT_END] = { - [INIT_SETTING] = "setting init error", - [INIT_INTERFACE] = "lowlevel interface(sysfs or others) init error", - [INIT_POLL] = "input devices poll init error", - [INIT_FIFO] = "FIFO poll init error", - [INIT_DBUS] = "d-bus init error", -}; - static void init_display_states(void *data) { struct display_plugin *dp = (struct display_plugin *) data; @@ -261,7 +227,6 @@ static int display_probe(void *data) dp->default_saving_mode = NULL; dp->is_lcdon_blocked = is_lcdon_blocked; dp->proc_change_state = default_proc_change_state; - setup_display_plugin_backlight_ops(dp); /** * load display service @@ -275,21 +240,9 @@ static int display_probe(void *data) return 0; } -static int input_init_handler(void) -{ - if (!display_conf.input_support) - remove_device_by_devname("input"); - - return 0; -} - static void display_init(void *data) { - int ret, i; - unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); - int timeout = 0; - - _I("Start power manager."); + int ret; /* load configutation */ ret = display_load_config(&display_conf); @@ -297,111 +250,7 @@ static void display_init(void *data) _W("Failed to load '%s', use default value: %d", DISPLAY_CONF_FILE, ret); - register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); - register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); - register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); - - init_save_userlock(); - - for (i = INIT_SETTING; i < INIT_END; i++) { - switch (i) { - case INIT_SETTING: - ret = init_setting(NULL); - break; - case INIT_INTERFACE: - if (display_conf.timeout_enable) - display_initialize_display_state_timeout_from_setting(); - ret = init_sysfs(flags); - break; - case INIT_POLL: - _I("input init"); - ret = input_init_handler(); - - pm_lock_detector_init(); - break; - case INIT_DBUS: - _I("Dbus init."); - ret = init_pm_dbus(); - break; - } - if (ret != 0) { - _E("Failed to init: %s", errMSG[i]); - break; - } - } - - if (i == INIT_END) { - display_ops_init(NULL); -#ifdef ENABLE_PM_LOG - pm_history_init(); -#endif - init_lcd_operation(); - display_misc_set_battery_charging_status_flag(); - display_set_initial_brightness(); - display_set_initial_battery_flag(); - display_set_initial_lockscreen_status(); - - /* In smd test, TSP should be turned off if display panel is not existed. */ - if (display_panel_get_dpms_cached_state() == -ENOENT) { - _I("Display panel is not existed."); - lcd_direct_control(DPMS_OFF, NORMAL_MODE); - exit_lcd_operation(); - } - - /* wm_ready needs to be checked - * since display manager can be launched later than deviced. - * In the case, display cannot be turned on at the first booting */ - // wm_ready = check_wm_ready(); - if (display_panel_init_dpms()) { - if (is_lcdon_blocked() != LCDON_BLOCK_NONE) - display_panel_lcd_off_procedure(LCD_OFF_BY_EVENT); - else - display_panel_lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - } else { - display_add_timer_for_waiting_dpms_init(); - } - - if (display_conf.lcd_always_on) { - _I("LCD always on."); - display_state_transition_set_transition_table_display_state(S_NORMAL, S_NORMAL, EVENT_TIMEOUT); - } - - if (flags & WITHOUT_STARTNOTI) { /* start without noti */ - _I("Start Power managing without noti"); - power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, - HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN, NULL); - /* - * Lock lcd off until booting is done. - * deviced guarantees all booting script is executing. - * Last script of booting unlocks this suspend blocking state. - */ - display_lock_request_lock_with_option(INTERNAL_LOCK_BOOTING, LCD_OFF, - STAY_CUR_STATE, DELAYED_INIT_WATING_TIME); - - /* Initial display state right after the booting done */ - if (is_lcdon_blocked()) - set_pm_cur_state(S_LCDOFF); - else - set_pm_cur_state(S_NORMAL); - ret = vconf_set_int(VCONFKEY_PM_STATE, get_pm_cur_state()); - if (ret < 0) - _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); - - display_set_display_ops_status(DEVICE_OPS_STATUS_START); - if (display_conf.timeout_enable) { - timeout = states[S_NORMAL].timeout; - /* check minimun lcd on time */ - if (timeout < SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT)) - timeout = SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT); - - display_lock_request_lock_with_option(INTERNAL_LOCK_BOOTING, LCD_NORMAL, - STAY_CUR_STATE, timeout); - } - - } - - set_display_init_direction(display_conf.display_init_direction); - } + display_misc_set_battery_charging_status_flag(); } static void display_exit(void *data) @@ -435,7 +284,7 @@ static void display_exit(void *data) } } - exit_lcd_operation(); + display_unregister_dependent_device(); free_lock_info_list(); /* free display service */ diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 7c74c83..60bee65 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -123,14 +123,6 @@ void setup_display_plugin_backlight_ops(struct display_plugin *dp) dp->backlight = &backlight_ops; } -int init_sysfs(unsigned int flags) -{ - register_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); - register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); - - return 0; -} - int exit_sysfs(void) { const struct device_ops *ops = NULL; diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index ba2a191..5a40817 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -77,8 +77,6 @@ * @{ */ -extern void init_save_userlock(void); - static struct display_plugin *disp_plgn; static struct display_backlight_ops *backlight_ops; @@ -94,8 +92,6 @@ static struct state states[S_END] = { { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; -#define DELAYED_INIT_WATING_TIME 60000 /* 1 minute */ - #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ #define LONG_PRESS_INTERVAL 2 /* 2 seconds */ #define SAMPLING_INTERVAL 1 /* 1 sec */ @@ -139,27 +135,7 @@ inline struct state* state_st(enum state_t state) return &states[state]; } -static void init_lcd_operation(void) -{ - const struct device_ops *ops = NULL; - - ops = find_device("display"); - if (!check_default(ops)) - display_register_dependent_device(ops); - - ops = find_device("touchkey"); - if (!check_default(ops)) - display_register_dependent_device(ops); - - ops = find_device("touchscreen"); - if (!check_default(ops)) - display_register_dependent_device(ops); -} -static void exit_lcd_operation(void) -{ - display_unregister_dependent_device(); -} enum { INIT_SETTING = 0, @@ -170,14 +146,6 @@ enum { INIT_END }; -static const char *errMSG[INIT_END] = { - [INIT_SETTING] = "setting init error", - [INIT_INTERFACE] = "lowlevel interface(sysfs or others) init error", - [INIT_POLL] = "input devices poll init error", - [INIT_FIFO] = "FIFO poll init error", - [INIT_DBUS] = "d-bus init error", -}; - static void init_display_states(void *data) { struct display_plugin *dp = (struct display_plugin *) data; @@ -188,7 +156,6 @@ static void init_display_states(void *data) * Power manager Main * */ - static int display_probe(void *data) { int ret; @@ -209,7 +176,6 @@ static int display_probe(void *data) dp->default_saving_mode = NULL; dp->is_lcdon_blocked = is_lcdon_blocked; dp->proc_change_state = NULL; - setup_display_plugin_backlight_ops(dp); /** * load display service @@ -223,132 +189,16 @@ static int display_probe(void *data) return 0; } -static int input_init_handler(void) -{ - if (!display_conf.input_support) - remove_device_by_devname("input"); - - return 0; -} static void display_init(void *data) { - int ret, i; - unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); - int timeout = 0; - - _I("Start power manager."); + int ret; /* load configutation */ ret = display_load_config(&display_conf); if (ret < 0) _W("Failed to load '%s', use default value: %d", DISPLAY_CONF_FILE, ret); - - register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); - register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); - register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); - - init_save_userlock(); - - for (i = INIT_SETTING; i < INIT_END; i++) { - switch (i) { - case INIT_SETTING: - ret = init_setting(NULL); - break; - case INIT_INTERFACE: - if (display_conf.timeout_enable) - display_initialize_display_state_timeout_from_setting(); - ret = init_sysfs(flags); - break; - case INIT_POLL: - _I("input init"); - ret = input_init_handler(); - - pm_lock_detector_init(); - break; - case INIT_DBUS: - _I("Dbus init."); - ret = init_pm_dbus(); - break; - } - if (ret != 0) { - _E("Failed to init: %s", errMSG[i]); - break; - } - } - - if (i == INIT_END) { - display_ops_init(NULL); -#ifdef ENABLE_PM_LOG - pm_history_init(); -#endif - init_lcd_operation(); - display_set_initial_brightness(); - display_set_initial_battery_flag(); - display_set_initial_lockscreen_status(); - - /* In smd test, TSP should be turned off if display panel is not existed. */ - if (display_panel_get_dpms_cached_state() == -ENOENT) { - _I("Display panel is not existed."); - lcd_direct_control(DPMS_OFF, NORMAL_MODE); - exit_lcd_operation(); - } - - /* wm_ready needs to be checked - * since display manager can be launched later than deviced. - * In the case, display cannot be turned on at the first booting */ - // wm_ready = check_wm_ready(); - if (display_panel_init_dpms()) { - if (is_lcdon_blocked() != LCDON_BLOCK_NONE) - display_panel_lcd_off_procedure(LCD_OFF_BY_EVENT); - else - display_panel_lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - } else { - display_add_timer_for_waiting_dpms_init(); - } - - if (display_conf.lcd_always_on) { - _I("LCD always on."); - display_state_transition_set_transition_table_display_state(S_NORMAL, S_NORMAL, EVENT_TIMEOUT); - } - - if (flags & WITHOUT_STARTNOTI) { /* start without noti */ - _I("Start Power managing without noti"); - power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, - HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN, NULL); - /* - * Lock lcd off until booting is done. - * deviced guarantees all booting script is executing. - * Last script of booting unlocks this suspend blocking state. - */ - display_lock_request_lock_with_option(INTERNAL_LOCK_BOOTING, LCD_OFF, - STAY_CUR_STATE, DELAYED_INIT_WATING_TIME); - - /* Initial display state right after the booting done */ - if (is_lcdon_blocked()) - set_pm_cur_state(S_LCDOFF); - else - set_pm_cur_state(S_NORMAL); - ret = vconf_set_int(VCONFKEY_PM_STATE, get_pm_cur_state()); - if (ret < 0) - _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); - - display_set_display_ops_status(DEVICE_OPS_STATUS_START); - if (display_conf.timeout_enable) { - timeout = states[S_NORMAL].timeout; - /* check minimun lcd on time */ - if (timeout < SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT)) - timeout = SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT); - - display_lock_request_lock_with_option(INTERNAL_LOCK_BOOTING, LCD_NORMAL, - STAY_CUR_STATE, timeout); - } - - } - - set_display_init_direction(display_conf.display_init_direction); - } } static void display_exit(void *data) @@ -382,7 +232,7 @@ static void display_exit(void *data) } } - exit_lcd_operation(); + display_unregister_dependent_device(); free_lock_info_list(); /* free display service */ diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 2db6d71..8935e77 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -107,13 +107,6 @@ void setup_display_plugin_backlight_ops(struct display_plugin *dp) dp->backlight = &backlight_ops; } -int init_sysfs(unsigned int flags) -{ - register_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); - - return 0; -} - int exit_sysfs(void) { const struct device_ops *ops = NULL; diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 082e87b..5b514e8 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -87,8 +87,6 @@ #define LATE_LCD_TRANSIT 1 -extern void init_save_userlock(void); - static struct display_plugin *disp_plgn; static struct display_backlight_ops *backlight_ops; @@ -115,8 +113,6 @@ static struct state states[S_END] = { { S_POWEROFF, "S_POWEROFF", NULL, NULL, NULL, NULL }, }; -#define DELAYED_INIT_WATING_TIME 60000 /* 1 minute */ - #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ #define LONG_PRESS_INTERVAL 500 /* 0.5 seconds */ #define SAMPLING_INTERVAL 1 /* 1 sec */ @@ -901,24 +897,11 @@ static void init_lcd_operation(void) { const struct device_ops *ops = NULL; - ops = find_device("display"); - if (!check_default(ops)) - display_register_dependent_device(ops); - - ops = find_device("touchscreen"); - if (!check_default(ops)) - display_register_dependent_device(ops); - ops = find_device("bezel"); if (!check_default(ops)) display_register_dependent_device(ops); } -static void exit_lcd_operation(void) -{ - display_unregister_dependent_device(); -} - enum { INIT_SETTING = 0, INIT_INTERFACE, @@ -928,14 +911,6 @@ enum { INIT_END }; -static const char *errMSG[INIT_END] = { - [INIT_SETTING] = "setting init error", - [INIT_INTERFACE] = "lowlevel interface(sysfs or others) init error", - [INIT_POLL] = "input devices poll init error", - [INIT_FIFO] = "FIFO poll init error", - [INIT_DBUS] = "d-bus init error", -}; - static void init_display_states(void *data) { struct display_plugin *dp = (struct display_plugin *) data; @@ -966,7 +941,6 @@ static int display_probe(void *data) dp->default_saving_mode = default_saving_mode; dp->is_lcdon_blocked = is_lcdon_blocked; dp->proc_change_state = default_proc_change_state; - setup_display_plugin_backlight_ops(dp); /** * load display service @@ -980,14 +954,6 @@ static int display_probe(void *data) return 0; } -static int input_init_handler(void) -{ - if (!display_conf.input_support) - remove_device_by_devname("input"); - - return 0; -} - static void sec_dsim_uevent_changed(struct udev_device *dev) { const char *devpath; @@ -1021,11 +987,8 @@ static const struct uevent_handler sec_dsim_uevent_ops = { static void display_init(void *data) { - int ret, i; + int ret; unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); - int timeout = 0; - - _I("Start power manager."); /* load configutation */ ret = display_load_config(&display_conf); @@ -1035,112 +998,12 @@ static void display_init(void *data) register_kernel_uevent_control(&sec_dsim_uevent_ops); - register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); - register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); - register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); register_notifier(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, display_auto_brightness_sensing); - init_save_userlock(); - - for (i = INIT_SETTING; i < INIT_END; i++) { - switch (i) { - case INIT_SETTING: - ret = init_setting(update_setting); - break; - case INIT_INTERFACE: - if (display_conf.timeout_enable) - display_initialize_display_state_timeout_from_setting(); - ret = init_sysfs(flags); - break; - case INIT_POLL: - _I("input init"); - ret = input_init_handler(); - - pm_lock_detector_init(); - break; - case INIT_DBUS: - _I("Dbus init."); - ret = init_pm_dbus(); - break; - } - if (ret != 0) { - _E("Failed to init: %s", errMSG[i]); - break; - } - } - - if (i == INIT_END) { - display_ops_init(NULL); -#ifdef ENABLE_PM_LOG - pm_history_init(); -#endif - init_lcd_operation(); - display_misc_set_battery_charging_status_flag(); - display_set_initial_brightness(); - display_set_initial_battery_flag(); - display_set_initial_lockscreen_status(); - - /* In smd test, TSP should be turned off if display panel is not existed. */ - if (display_panel_get_dpms_cached_state() == -ENOENT) { - _I("Display panel is not existed."); - lcd_direct_control(DPMS_OFF, NORMAL_MODE); - exit_lcd_operation(); - } - - /* wm_ready needs to be checked - * since display manager can be launched later than deviced. - * In the case, display cannot be turned on at the first booting */ - // wm_ready = check_wm_ready(); - if (display_panel_init_dpms()) { - if (is_lcdon_blocked() != LCDON_BLOCK_NONE) - lcd_off_procedure(LCD_OFF_BY_EVENT); - else - lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); - } else { - display_add_timer_for_waiting_dpms_init(); - } - - if (display_conf.lcd_always_on) { - _I("LCD always on."); - display_state_transition_set_transition_table_display_state(S_NORMAL, S_NORMAL, EVENT_TIMEOUT); - } - - if (flags & WITHOUT_STARTNOTI) { /* start without noti */ - _I("Start Power managing without noti"); - power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, - HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN, NULL); - /* - * Lock lcd off until booting is done. - * deviced guarantees all booting script is executing. - * Last script of booting unlocks this suspend blocking state. - */ - display_lock_request_lock_with_option(INTERNAL_LOCK_BOOTING, LCD_OFF, - STAY_CUR_STATE, DELAYED_INIT_WATING_TIME); - - /* Initial display state right after the booting done */ - if (is_lcdon_blocked()) - set_pm_cur_state(S_LCDOFF); - else - set_pm_cur_state(S_NORMAL); - ret = vconf_set_int(VCONFKEY_PM_STATE, get_pm_cur_state()); - if (ret < 0) - _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); - - display_set_display_ops_status(DEVICE_OPS_STATUS_START); - if (display_conf.timeout_enable) { - timeout = states[S_NORMAL].timeout; - /* check minimun lcd on time */ - if (timeout < SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT)) - timeout = SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT); - - display_lock_request_lock_with_option(INTERNAL_LOCK_BOOTING, LCD_NORMAL, - STAY_CUR_STATE, timeout); - } - - } - - set_display_init_direction(display_conf.display_init_direction); - } + init_setting(update_setting); + init_sysfs(flags); + init_lcd_operation(); + display_misc_set_battery_charging_status_flag(); } static void display_exit(void *data) @@ -1176,7 +1039,7 @@ static void display_exit(void *data) } } - exit_lcd_operation(); + display_unregister_dependent_device(); free_lock_info_list(); /* free display service */ diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 3fa8e72..6db9e32 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -254,10 +254,9 @@ void setup_display_plugin_backlight_ops(struct display_plugin *dp) dp->backlight = &backlight_ops; } +/* FIXME: This batterey plugin handle should be moved while battery backend separation */ int init_sysfs(unsigned int flags) { - register_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); - if (battery_plgn->handle) { fp_get_var_battery_status = dlsym(battery_plgn->handle, "get_var_battery_status"); if (fp_get_var_battery_status) { diff --git a/src/display/display.c b/src/display/display.c index 97e4f27..9c57d95 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -24,16 +24,21 @@ #include "core/udev.h" #include "shared/device-notifier.h" #include "shared/log.h" +#include "power/power.h" +#include "power/power-suspend.h" #include "device-interface.h" #include "display.h" #include "display-lock.h" #include "display-plugin.h" #include "display-config.h" #include "display-misc.h" +#include "display-ops.h" #include "display-signal.h" #include "display-state-transition.h" #include "lock-detector.h" +#define DELAYED_INIT_WATING_TIME 60000 /* 1 minute */ + static const struct device_ops *display_plugin_device_ops; static int pm_cur_state; static int pm_old_state; @@ -43,6 +48,8 @@ static bool g_display_hal_backend_available; static GList *display_dependent_device_ops; static enum device_ops_status display_ops_status = DEVICE_OPS_STATUS_UNINIT; +extern void init_save_userlock(void); + inline int get_pm_cur_state(void) { return pm_cur_state; @@ -437,6 +444,23 @@ static int delayed_init_done(void *data) return done; } +static void init_lcd_operation(void) +{ + const struct device_ops *ops = NULL; + + ops = find_device("display"); + if (!check_default(ops)) + display_register_dependent_device(ops); + + ops = find_device("touchkey"); + if (!check_default(ops)) + display_register_dependent_device(ops); + + ops = find_device("touchscreen"); + if (!check_default(ops)) + display_register_dependent_device(ops); +} + static int display_probe(void *data) { display_plugin_device_ops = find_device("display-plugin"); @@ -446,21 +470,133 @@ static int display_probe(void *data) return display_plugin_device_ops->probe(&g_display_plugin); } +static int input_init_handler(void) +{ + if (!g_display_plugin.config->input_support) + remove_device_by_devname("input"); + + return 0; +} + static void display_init(void *data) { + bool timeout_enable = false; + int lcd_always_on = 0; + int timeout = 0; + int ret = 0; + unsigned int flags = (WITHOUT_STARTNOTI | FLAG_X_DPMS); + if (!display_plugin_device_ops || !display_plugin_device_ops->init) return; g_unix_signal_add(SIGHUP, handle_sighup, (gpointer) SIGHUP); - register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); + /* FIMXE: display config load should be put here*/ display_plugin_device_ops->init(data); register_kernel_uevent_control(&lcd_uevent_ops); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); + register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); + register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); + register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); display_signal_register_display_brightness_notifier(); display_misc_register_battery_health_notifier(); register_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback); register_notifier(DEVICE_NOTIFIER_POWEROFF_TRIGGERED, poweroff_triggered_callback); + + init_save_userlock(); + + ret = init_setting(NULL); + if (ret != 0) + _W("Failed to init: setting init error"); + + display_plugin_config_get_timeout_enable(&timeout_enable); + if (timeout_enable) + display_initialize_display_state_timeout_from_setting(); + + register_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); + + _I("input init"); + ret = input_init_handler(); + pm_lock_detector_init(); + if (ret != 0) + _W("Failed to init: input devices poll init error"); + + _I("Dbus init."); + ret = init_pm_dbus(); + if (ret != 0) + _W("Failed to init: dbus initialization error"); + + display_ops_init(NULL); +#ifdef ENABLE_PM_LOG + pm_history_init(); +#endif + init_lcd_operation(); + display_set_initial_brightness(); + display_set_initial_battery_flag(); + display_set_initial_lockscreen_status(); + + /* In smd test, TSP should be turned off if display panel is not existed. */ + if (display_panel_get_dpms_cached_state() == -ENOENT) { + _I("Display panel is not existed."); + lcd_direct_control(DPMS_OFF, NORMAL_MODE); + display_unregister_dependent_device(); + } + + /* wm_ready needs to be checked + * since display manager can be launched later than deviced. + * In the case, display cannot be turned on at the first booting */ + // wm_ready = check_wm_ready(); + if (display_panel_init_dpms()) { + if (display_plugin_is_lcd_on_blocked() != LCDON_BLOCK_NONE) { + display_panel_lcd_off_procedure(LCD_OFF_BY_EVENT); + } else { + display_panel_lcd_on_procedure(LCD_NORMAL, LCD_ON_BY_EVENT); + } + } else { + display_add_timer_for_waiting_dpms_init(); + } + + display_plugin_config_get_lcd_always_on(&lcd_always_on); + if (lcd_always_on) { + _I("LCD always on."); + display_state_transition_set_transition_table_display_state(S_NORMAL, S_NORMAL, EVENT_TIMEOUT); + } + + if (flags & WITHOUT_STARTNOTI) { /* start without noti */ + _I("Start Power managing without noti"); + power_request_change_state_strict(DEVICED_POWER_STATE_SLEEP, DEVICED_POWER_STATE_NORMAL, + HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN, NULL); + /* + * Lock lcd off until booting is done. + * deviced guarantees all booting script is executing. + * Last script of booting unlocks this suspend blocking state. + */ + display_lock_request_lock_with_option(INTERNAL_LOCK_BOOTING, LCD_OFF, + STAY_CUR_STATE, DELAYED_INIT_WATING_TIME); + + /* Initial display state right after the booting done */ + if (display_plugin_is_lcd_on_blocked()) + set_pm_cur_state(S_LCDOFF); + else + set_pm_cur_state(S_NORMAL); + ret = vconf_set_int(VCONFKEY_PM_STATE, get_pm_cur_state()); + if (ret < 0) + _E("Failed to set vconf value for pm cur state: %d", vconf_get_ext_errno()); + + display_set_display_ops_status(DEVICE_OPS_STATUS_START); + if (timeout_enable) { + display_plugin_state_get_timeout(S_NORMAL, &timeout); + /* check minimun lcd on time */ + if (timeout < SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT)) { + timeout = SEC_TO_MSEC(DEFAULT_NORMAL_TIMEOUT); + } + display_lock_request_lock_with_option(INTERNAL_LOCK_BOOTING, LCD_NORMAL, + STAY_CUR_STATE, timeout); + } + } + + set_display_init_direction(g_display_plugin.config->display_init_direction); } static void display_exit(void *data) -- 2.7.4 From 6195ac94623f2c756fa3a52adc6fd0234d8e97b2 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Fri, 14 Jul 2023 16:25:10 +0900 Subject: [PATCH 10/16] display: Relocate display hal-backend loader/unloader display_service_load/display_service_free() is used as display hal-backend loader/unloader. However, display core should treat hal-backend using during display probe,exit process. Thus, display_service_load/display_service_free() are removed. Also, display_set_hal_backend_available() is removed. Because display core(display.c) only decides whether the display hal-backend using or not. Change-Id: I6533145b0d558c2bae831eee1ea04ab313f286ac Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 13 -------- plugins/iot-headed/display/device-interface.c | 33 ------------------ plugins/mobile/display/core.c | 13 -------- plugins/mobile/display/device-interface.c | 33 ------------------ plugins/tv/display/core.c | 13 -------- plugins/tv/display/device-interface.c | 33 ------------------ plugins/wearable/display/core.c | 13 -------- plugins/wearable/display/device-interface.c | 35 +------------------ plugins/wearable/display/lbm.c | 2 +- src/display/device-interface.h | 3 -- src/display/display.c | 48 ++++++++++++++++++++++----- src/display/display.h | 1 - 12 files changed, 41 insertions(+), 199 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 1a4e4b2..b4d71dd 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -156,7 +156,6 @@ static void init_display_states(void *data) */ static int display_probe(void *data) { - int ret; struct display_plugin *dp = (struct display_plugin *) data; assert(dp); @@ -179,15 +178,6 @@ static int display_probe(void *data) if (!is_feature_display_supported()) return -ENODEV; - /** - * load display service - * if there is no display shared library, - * deviced does not provide any method and function of display. - */ - ret = display_service_load(); - if (ret) - return ret; - return 0; } @@ -236,9 +226,6 @@ static void display_exit(void *data) display_unregister_dependent_device(); free_lock_info_list(); - /* free display service */ - display_service_free(); - _I("Stop power manager."); } diff --git a/plugins/iot-headed/display/device-interface.c b/plugins/iot-headed/display/device-interface.c index e599fc7..36f1854 100644 --- a/plugins/iot-headed/display/device-interface.c +++ b/plugins/iot-headed/display/device-interface.c @@ -46,7 +46,6 @@ #include "display-panel.h" static struct display_backlight_ops backlight_ops; -static bool display_dev_available = false; static const struct display_config *display_conf; inline struct display_backlight_ops *get_var_backlight_ops(void) @@ -54,11 +53,6 @@ inline struct display_backlight_ops *get_var_backlight_ops(void) return &backlight_ops; } -bool display_dev_ready(void) -{ - return display_dev_available; -} - static struct display_backlight_ops backlight_ops = { .get_lcd_power = display_panel_get_dpms_cached_state, .set_brightness = NULL, @@ -67,33 +61,6 @@ static struct display_backlight_ops backlight_ops = { .transit_brt = NULL, }; -int display_service_load(void) -{ - int r; - - if (display_dev_available) - return 0; - - r = hal_device_display_get_backend(); - if (r < 0) { - _E("There is no HAL for display."); - display_dev_available = false; - display_set_hal_backend_available(display_dev_available); - return 0; - } - - display_dev_available = true; - display_set_hal_backend_available(display_dev_available); - _D("Display device structure load success."); - return 0; -} - -int display_service_free(void) -{ - display_dev_available = false; - return hal_device_display_put_backend(); -} - /* Dummy. Do not consider detached display state */ int is_lcdon_blocked(void) { diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 85f378d..bb1fbbc 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -209,7 +209,6 @@ static void init_display_states(void *data) */ static int display_probe(void *data) { - int ret; struct display_plugin *dp = (struct display_plugin *) data; assert(dp); @@ -228,15 +227,6 @@ static int display_probe(void *data) dp->is_lcdon_blocked = is_lcdon_blocked; dp->proc_change_state = default_proc_change_state; - /** - * load display service - * if there is no display shared library, - * deviced does not provide any method and function of display. - */ - ret = display_service_load(); - if (ret) - return ret; - return 0; } @@ -287,9 +277,6 @@ static void display_exit(void *data) display_unregister_dependent_device(); free_lock_info_list(); - /* free display service */ - display_service_free(); - _I("Stop power manager."); } diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index 60bee65..df36e8e 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -47,7 +47,6 @@ #include "power/power-suspend.h" static struct display_backlight_ops backlight_ops; -static bool display_dev_available = false; static const struct display_config *display_conf; inline struct display_backlight_ops *get_var_backlight_ops(void) @@ -55,11 +54,6 @@ inline struct display_backlight_ops *get_var_backlight_ops(void) return &backlight_ops; } -bool display_dev_ready(void) -{ - return display_dev_available; -} - static struct display_backlight_ops backlight_ops = { .get_lcd_power = display_panel_get_dpms_cached_state, .set_brightness = NULL, @@ -68,33 +62,6 @@ static struct display_backlight_ops backlight_ops = { .transit_brt = NULL, }; -int display_service_load(void) -{ - int r; - - if (display_dev_available) - return 0; - - r = hal_device_display_get_backend(); - if (r < 0) { - _E("There is no HAL for display."); - display_dev_available = false; - display_set_hal_backend_available(display_dev_available); - return 0; - } - - display_dev_available = true; - display_set_hal_backend_available(display_dev_available); - _D("Display device structure load success."); - return 0; -} - -int display_service_free(void) -{ - display_dev_available = false; - return hal_device_display_put_backend(); -} - static int delayed_init_done(void *data) { static int done = false; diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 5a40817..341527d 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -158,7 +158,6 @@ static void init_display_states(void *data) */ static int display_probe(void *data) { - int ret; struct display_plugin *dp = (struct display_plugin *) data; assert(dp); @@ -177,15 +176,6 @@ static int display_probe(void *data) dp->is_lcdon_blocked = is_lcdon_blocked; dp->proc_change_state = NULL; - /** - * load display service - * if there is no display shared library, - * deviced does not provide any method and function of display. - */ - ret = display_service_load(); - if (ret) - return ret; - return 0; } @@ -235,9 +225,6 @@ static void display_exit(void *data) display_unregister_dependent_device(); free_lock_info_list(); - /* free display service */ - display_service_free(); - _I("Stop power manager."); } diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 8935e77..9857e12 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -46,7 +46,6 @@ #include "display-lock.h" static struct display_backlight_ops backlight_ops; -static bool display_dev_available = false; static const struct display_config *display_conf; inline struct display_backlight_ops *get_var_backlight_ops(void) @@ -54,11 +53,6 @@ inline struct display_backlight_ops *get_var_backlight_ops(void) return &backlight_ops; } -bool display_dev_ready(void) -{ - return display_dev_available; -} - static struct display_backlight_ops backlight_ops = { .get_lcd_power = display_panel_get_dpms_cached_state, .set_brightness = NULL, @@ -67,33 +61,6 @@ static struct display_backlight_ops backlight_ops = { .transit_brt = NULL, }; -int display_service_load(void) -{ - int r; - - if (display_dev_available) - return 0; - - r = hal_device_display_get_backend(); - if (r < 0) { - _E("There is no HAL for display."); - display_dev_available = false; - display_set_hal_backend_available(display_dev_available); - return 0; - } - - display_dev_available = true; - display_set_hal_backend_available(display_dev_available); - _D("Display device structure load success."); - return 0; -} - -int display_service_free(void) -{ - display_dev_available = false; - return hal_device_display_put_backend(); -} - /* Dummy. Do not consider detached display state */ int is_lcdon_blocked(void) { diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 5b514e8..94f6823 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -923,7 +923,6 @@ static void init_display_states(void *data) */ static int display_probe(void *data) { - int ret; struct display_plugin *dp = (struct display_plugin *) data; assert(dp); @@ -942,15 +941,6 @@ static int display_probe(void *data) dp->is_lcdon_blocked = is_lcdon_blocked; dp->proc_change_state = default_proc_change_state; - /** - * load display service - * if there is no display shared library, - * deviced does not provide any method and function of display. - */ - ret = display_service_load(); - if (ret) - return ret; - return 0; } @@ -1042,9 +1032,6 @@ static void display_exit(void *data) display_unregister_dependent_device(); free_lock_info_list(); - /* free display service */ - display_service_free(); - _I("Stop power manager."); } diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 6db9e32..135740c 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -51,7 +51,6 @@ static struct display_backlight_ops backlight_ops; static struct battery_plugin *battery_plgn; -static bool display_dev_available = false; static int aod_max_level = -1; static int aod_normal_level = -1; static int aod_min_level = -1; @@ -65,11 +64,6 @@ inline struct display_backlight_ops *get_var_backlight_ops(void) return &backlight_ops; } -bool display_dev_ready(void) -{ - return display_dev_available; -} - static int set_brightness(int val) { int max, ret; @@ -78,7 +72,7 @@ static int set_brightness(int val) display_backlight_get_default_brightness(&default_brightness); display_backlight_get_force_brightness(&force_brightness); - if (!display_dev_available) { + if (!display_is_hal_backend_available()) { _E("There is no display device."); return -ENOENT; } @@ -210,33 +204,6 @@ static struct display_backlight_ops backlight_ops = { .transit_brt = NULL, }; -int display_service_load(void) -{ - int r; - - if (display_dev_available) - return 0; - - r = hal_device_display_get_backend(); - if (r < 0) { - _E("There is no HAL for display."); - display_dev_available = false; - display_set_hal_backend_available(display_dev_available); - return 0; - } - - display_dev_available = true; - display_set_hal_backend_available(display_dev_available); - _D("Display device structure load success."); - return 0; -} - -int display_service_free(void) -{ - display_dev_available = false; - return hal_device_display_put_backend(); -} - int is_lcdon_blocked(void) { int state = display_panel_get_dpms_cached_state(); diff --git a/plugins/wearable/display/lbm.c b/plugins/wearable/display/lbm.c index eea8f65..f15adbc 100644 --- a/plugins/wearable/display/lbm.c +++ b/plugins/wearable/display/lbm.c @@ -338,7 +338,7 @@ static void lbm_init(void *data) if (ret < 0) _E("Failed to init dbus method, %d.", ret); - display_dev_available = display_dev_ready(); + display_dev_available = display_is_hal_backend_available(); _I("LBM setting value is %d.", lbm_setting_mode); } diff --git a/src/display/device-interface.h b/src/display/device-interface.h index f286464..c3d87bf 100644 --- a/src/display/device-interface.h +++ b/src/display/device-interface.h @@ -59,12 +59,9 @@ enum { int init_sysfs(unsigned int); int exit_sysfs(void); -int display_service_load(void); -int display_service_free(void); struct display_backlight_ops *get_var_backlight_ops(void); -bool display_dev_ready(void); void dpms_set_running_state(int val); enum lcdon_block_state { diff --git a/src/display/display.c b/src/display/display.c index 9c57d95..c0a42d3 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -44,7 +44,7 @@ static int pm_cur_state; static int pm_old_state; static unsigned int pm_status_flag; static enum display_init_direction_e g_display_init_direction; -static bool g_display_hal_backend_available; +static bool g_display_hal_backend_available = false; static GList *display_dependent_device_ops; static enum device_ops_status display_ops_status = DEVICE_OPS_STATUS_UNINIT; @@ -115,13 +115,6 @@ void lcd_direct_control(enum dpms_state dpms_state, int flags) } } -/* FIXME: This function is for temporary use, should be fixed after plugin refactoring */ -void display_set_hal_backend_available(bool display_hal_backend_available) -{ - g_display_hal_backend_available = display_hal_backend_available; -} - -/* FIXME: This function is for temporary use, should be fixed after plugin refactoring */ bool display_is_hal_backend_available(void) { return g_display_hal_backend_available; @@ -461,13 +454,48 @@ static void init_lcd_operation(void) display_register_dependent_device(ops); } +static void load_display_hal_backend(void) +{ + int ret; + + if (g_display_hal_backend_available) + return; + + ret = hal_device_display_get_backend(); + if (ret < 0) { + _W("There is no HAL for display."); + g_display_hal_backend_available = false; + } + + g_display_hal_backend_available = true; + _W("Display device structure load success."); +} + +static int unload_display_hal_backend(void) +{ + g_display_hal_backend_available = false; + return hal_device_display_put_backend(); +} + static int display_probe(void *data) { + int ret = 0; + display_plugin_device_ops = find_device("display-plugin"); if (!display_plugin_device_ops || !display_plugin_device_ops->probe) return 0; - return display_plugin_device_ops->probe(&g_display_plugin); + ret = display_plugin_device_ops->probe(&g_display_plugin); + if (ret < 0) + return ret; + + /** + * load display hal backend + * if there is no display shared library, + * deviced does not provide any method and function of display. + */ + load_display_hal_backend(); + return 0; } static int input_init_handler(void) @@ -613,6 +641,8 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback); unregister_notifier(DEVICE_NOTIFIER_POWEROFF_TRIGGERED, poweroff_triggered_callback); unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); + + unload_display_hal_backend(); } static int display_start(enum device_flags flags) diff --git a/src/display/display.h b/src/display/display.h index 48c7d35..3a4d451 100644 --- a/src/display/display.h +++ b/src/display/display.h @@ -49,7 +49,6 @@ void set_pm_status_flag(unsigned int status_flag); void clear_pm_status_flag(unsigned int status_flag); enum display_init_direction_e get_display_init_direction(void); void set_display_init_direction(enum display_init_direction_e display_init_direction); -void display_set_hal_backend_available(bool display_hal_backend_available); bool display_is_hal_backend_available(void); void display_start_dependent_device(unsigned long flags); void display_stop_dependent_device(unsigned long flags); -- 2.7.4 From a2f6461f0997920012bf69b5d280c5498425a688 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Fri, 14 Jul 2023 15:47:46 +0900 Subject: [PATCH 11/16] display: Remove duplicated display_exit codes display all plugins follow same display_exit logic. There is no need to keep same logic code except specific profile code logic. Thus display_exit() logic is moved to display.c. Change-Id: I48b00e9289dbac9adc14b7d619f7e5f3ff81b853 Signed-off-by: Yunhee Seo --- plugins/iot-headed/display/core.c | 43 +------------------------ plugins/iot-headed/display/device-interface.c | 21 ------------- plugins/mobile/display/core.c | 43 +------------------------ plugins/mobile/display/device-interface.c | 21 ------------- plugins/tv/display/core.c | 45 +-------------------------- plugins/tv/display/device-interface.c | 21 ------------- plugins/wearable/display/core.c | 44 +------------------------- plugins/wearable/display/device-interface.c | 17 ---------- src/display/device-interface.h | 1 - src/display/display.c | 37 ++++++++++++++++++++-- 10 files changed, 39 insertions(+), 254 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index b4d71dd..d83ee55 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -135,15 +135,6 @@ inline struct state* state_st(enum state_t state) return &states[state]; } -enum { - INIT_SETTING = 0, - INIT_INTERFACE, - INIT_POLL, - INIT_FIFO, - INIT_DBUS, - INIT_END -}; - static void init_display_states(void *data) { struct display_plugin *dp = (struct display_plugin *) data; @@ -194,39 +185,7 @@ static void display_init(void *data) static void display_exit(void *data) { - int i = INIT_END; - - display_set_display_ops_status(DEVICE_OPS_STATUS_STOP); - - /* Set current state to S_NORMAL */ - set_pm_cur_state(S_NORMAL); - set_setting_pmstate(get_pm_cur_state()); - /* timeout is not needed */ - display_state_transition_reset_state_transition_timeout(TIMEOUT_NONE); - - display_ops_exit(NULL); - - for (i = i - 1; i >= INIT_SETTING; i--) { - switch (i) { - case INIT_SETTING: - exit_setting(); - break; - case INIT_INTERFACE: - exit_sysfs(); - break; - case INIT_POLL: - unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); - unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); - unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); - - break; - } - } - - display_unregister_dependent_device(); - free_lock_info_list(); - - _I("Stop power manager."); + return; } static int display_start(enum device_flags flags) diff --git a/plugins/iot-headed/display/device-interface.c b/plugins/iot-headed/display/device-interface.c index 36f1854..2d37e96 100644 --- a/plugins/iot-headed/display/device-interface.c +++ b/plugins/iot-headed/display/device-interface.c @@ -74,27 +74,6 @@ void setup_display_plugin_backlight_ops(struct display_plugin *dp) dp->backlight = &backlight_ops; } -int exit_sysfs(void) -{ - const struct device_ops *ops = NULL; - - display_backlight_update_by_default_brightness(); - - display_panel_exit_dpms(); - - ops = find_device("touchscreen"); - if (!check_default(ops)) - ops->start(NORMAL_MODE); - - ops = find_device("touchkey"); - if (!check_default(ops)) - ops->start(NORMAL_MODE); - - unregister_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); - - return 0; -} - static void __CONSTRUCTOR__ initialize(void) { display_conf = get_var_display_config(); diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index bb1fbbc..6b6c49d 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -188,15 +188,6 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) return 0; } -enum { - INIT_SETTING = 0, - INIT_INTERFACE, - INIT_POLL, - INIT_FIFO, - INIT_DBUS, - INIT_END -}; - static void init_display_states(void *data) { struct display_plugin *dp = (struct display_plugin *) data; @@ -245,39 +236,7 @@ static void display_init(void *data) static void display_exit(void *data) { - int i = INIT_END; - - display_set_display_ops_status(DEVICE_OPS_STATUS_STOP); - - /* Set current state to S_NORMAL */ - set_pm_cur_state(S_NORMAL); - set_setting_pmstate(get_pm_cur_state()); - /* timeout is not needed */ - display_state_transition_reset_state_transition_timeout(TIMEOUT_NONE); - - display_ops_exit(NULL); - - for (i = i - 1; i >= INIT_SETTING; i--) { - switch (i) { - case INIT_SETTING: - exit_setting(); - break; - case INIT_INTERFACE: - exit_sysfs(); - break; - case INIT_POLL: - unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); - unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); - unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); - - break; - } - } - - display_unregister_dependent_device(); - free_lock_info_list(); - - _I("Stop power manager."); + return; } static int display_start(enum device_flags flags) diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index df36e8e..4799a42 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -90,27 +90,6 @@ void setup_display_plugin_backlight_ops(struct display_plugin *dp) dp->backlight = &backlight_ops; } -int exit_sysfs(void) -{ - const struct device_ops *ops = NULL; - - display_backlight_update_by_default_brightness(); - - display_panel_exit_dpms(); - - ops = find_device("touchscreen"); - if (!check_default(ops)) - ops->start(NORMAL_MODE); - - ops = find_device("touchkey"); - if (!check_default(ops)) - ops->start(NORMAL_MODE); - - unregister_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); - - return 0; -} - static void __CONSTRUCTOR__ initialize(void) { display_conf = get_var_display_config(); diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 341527d..68e444b 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -135,17 +135,6 @@ inline struct state* state_st(enum state_t state) return &states[state]; } - - -enum { - INIT_SETTING = 0, - INIT_INTERFACE, - INIT_POLL, - INIT_FIFO, - INIT_DBUS, - INIT_END -}; - static void init_display_states(void *data) { struct display_plugin *dp = (struct display_plugin *) data; @@ -193,39 +182,7 @@ static void display_init(void *data) static void display_exit(void *data) { - int i = INIT_END; - - display_set_display_ops_status(DEVICE_OPS_STATUS_STOP); - - /* Set current state to S_NORMAL */ - set_pm_cur_state(S_NORMAL); - set_setting_pmstate(get_pm_cur_state()); - /* timeout is not needed */ - display_state_transition_reset_state_transition_timeout(TIMEOUT_NONE); - - display_ops_exit(NULL); - - for (i = i - 1; i >= INIT_SETTING; i--) { - switch (i) { - case INIT_SETTING: - exit_setting(); - break; - case INIT_INTERFACE: - exit_sysfs(); - break; - case INIT_POLL: - unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); - unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); - unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); - - break; - } - } - - display_unregister_dependent_device(); - free_lock_info_list(); - - _I("Stop power manager."); + return; } static int display_start(enum device_flags flags) diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index 9857e12..3abf17c 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -74,27 +74,6 @@ void setup_display_plugin_backlight_ops(struct display_plugin *dp) dp->backlight = &backlight_ops; } -int exit_sysfs(void) -{ - const struct device_ops *ops = NULL; - - display_backlight_update_by_default_brightness(); - - display_panel_exit_dpms(); - - ops = find_device("touchscreen"); - if (!check_default(ops)) - ops->start(NORMAL_MODE); - - ops = find_device("touchkey"); - if (!check_default(ops)) - ops->start(NORMAL_MODE); - - unregister_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); - - return 0; -} - static void __CONSTRUCTOR__ initialize(void) { display_conf = get_var_display_config(); diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 94f6823..7f8b507 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -902,15 +902,6 @@ static void init_lcd_operation(void) display_register_dependent_device(ops); } -enum { - INIT_SETTING = 0, - INIT_INTERFACE, - INIT_POLL, - INIT_FIFO, - INIT_DBUS, - INIT_END -}; - static void init_display_states(void *data) { struct display_plugin *dp = (struct display_plugin *) data; @@ -998,41 +989,8 @@ static void display_init(void *data) static void display_exit(void *data) { - int i = INIT_END; - - display_set_display_ops_status(DEVICE_OPS_STATUS_STOP); - - /* Set current state to S_NORMAL */ - set_pm_cur_state(S_NORMAL); - set_setting_pmstate(get_pm_cur_state()); - /* timeout is not needed */ - display_state_transition_reset_state_transition_timeout(TIMEOUT_NONE); - unregister_kernel_uevent_control(&sec_dsim_uevent_ops); - - display_ops_exit(NULL); - - for (i = i - 1; i >= INIT_SETTING; i--) { - switch (i) { - case INIT_SETTING: - exit_setting(); - break; - case INIT_INTERFACE: - exit_sysfs(); - break; - case INIT_POLL: - unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); - unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); - unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); - - break; - } - } - - display_unregister_dependent_device(); - free_lock_info_list(); - - _I("Stop power manager."); + return; } static int display_start(enum device_flags flags) diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 135740c..bb2469c 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -238,23 +238,6 @@ int init_sysfs(unsigned int flags) return 0; } -int exit_sysfs(void) -{ - const struct device_ops *ops = NULL; - - display_backlight_update_by_default_brightness(); - - display_panel_exit_dpms(); - - ops = find_device("touchscreen"); - if (!check_default(ops)) - ops->start(NORMAL_MODE); - - unregister_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); - - return 0; -} - static void __CONSTRUCTOR__ initialize(void) { display_conf = get_var_display_config(); diff --git a/src/display/device-interface.h b/src/display/device-interface.h index c3d87bf..6f0fb1c 100644 --- a/src/display/device-interface.h +++ b/src/display/device-interface.h @@ -58,7 +58,6 @@ enum { }; int init_sysfs(unsigned int); -int exit_sysfs(void); struct display_backlight_ops *get_var_backlight_ops(void); diff --git a/src/display/display.c b/src/display/display.c index c0a42d3..2b346af 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -629,18 +629,51 @@ static void display_init(void *data) static void display_exit(void *data) { + const struct device_ops *ops = NULL; + if (!display_plugin_device_ops || !display_plugin_device_ops->exit) return; display_plugin_device_ops->exit(data); + display_set_display_ops_status(DEVICE_OPS_STATUS_STOP); + + /* Set current state to S_NORMAL */ + set_pm_cur_state(S_NORMAL); + set_setting_pmstate(get_pm_cur_state()); + /* timeout is not needed */ + display_state_transition_reset_state_transition_timeout(TIMEOUT_NONE); + unregister_kernel_uevent_control(&lcd_uevent_ops); - display_signal_unregister_display_brightness_notifier(); + display_ops_exit(NULL); + + exit_setting(); + + display_backlight_update_by_default_brightness(); + + display_panel_exit_dpms(); + + ops = find_device("touchscreen"); + if (!check_default(ops)) + ops->start(NORMAL_MODE); + + ops = find_device("touchkey"); + if (!check_default(ops)) + ops->start(NORMAL_MODE); + + unregister_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); + unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); + unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); + unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); + unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); display_misc_unregister_battery_health_notifier(); + display_signal_unregister_display_brightness_notifier(); unregister_notifier(DEVICE_NOTIFIER_POWER_RESUME_FROM_ECHO_MEM, power_resume_from_echomem_callback); unregister_notifier(DEVICE_NOTIFIER_POWEROFF_TRIGGERED, poweroff_triggered_callback); - unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); + + display_unregister_dependent_device(); + free_lock_info_list(); unload_display_hal_backend(); } -- 2.7.4 From 544b25f77996f8bb4241e7d091cb46910e3eb9f3 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Mon, 17 Jul 2023 16:50:23 +0900 Subject: [PATCH 12/16] display: Add omitted code to display-panel Add lcd_on_timeval initizalization code. Because of this, the reset timeout value calculation was not accurate. Change-Id: I2361ed311da06589911e456481977d87426971fb Signed-off-by: Yunhee Seo --- src/display/display-panel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/display/display-panel.c b/src/display/display-panel.c index aa3df63..85b56a4 100644 --- a/src/display/display-panel.c +++ b/src/display/display-panel.c @@ -507,6 +507,7 @@ int display_panel_calculate_diff_time_between_lcd_on_direct_and_state_action(int if (lcd_on_timeval.tv_sec != 0) { gettimeofday(&now_timeval, NULL); *diff_time = DIFF_TIMEVAL_MS(now_timeval, lcd_on_timeval); + lcd_on_timeval.tv_sec = 0; return 0; } -- 2.7.4 From a78e82dee540ac685502b9f1e250e26d48c1f89a Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 17 Jul 2023 10:19:26 +0900 Subject: [PATCH 13/16] bitmap: Replace bitmap with that of the libsyscommon Change-Id: I701b7102f466f6f16dae6ce499fc04a0218b5c68 Signed-off-by: Youngjae Cho --- src/extcon/hdmi.c | 19 +-- src/power/power-event-lock.c | 15 +-- src/shared/apps.c | 14 +-- src/shared/bitmap.c | 152 ----------------------- src/shared/bitmap.h | 60 --------- tests/deviced-common-private-test/CMakeLists.txt | 1 - tests/deviced-common-private-test/test-bitmap.c | 95 -------------- 7 files changed, 25 insertions(+), 331 deletions(-) delete mode 100644 src/shared/bitmap.c delete mode 100644 src/shared/bitmap.h delete mode 100644 tests/deviced-common-private-test/test-bitmap.c diff --git a/src/extcon/hdmi.c b/src/extcon/hdmi.c index 34b11ef..a082344 100644 --- a/src/extcon/hdmi.c +++ b/src/extcon/hdmi.c @@ -20,8 +20,8 @@ #include #include #include +#include #include "core/log.h" -#include "shared/bitmap.h" #include "shared/device-notifier.h" #include "core.h" #include "display-ops.h" @@ -33,7 +33,7 @@ #define HDMI_NUMBER_MAX (64) // max number of supported hdmi -static struct dd_bitmap *bm_hdmi; +static struct syscommon_bitmap *bm_hdmi; static struct extcon_ops hdmi_extcon_ops; static void hdmi_send_broadcast(int status) @@ -64,7 +64,7 @@ static int get_hdmi_status(void) return HDMI_DISCONNECTED; } - if (count_set_bit(bm_hdmi) > 0) + if (syscommon_bitmap_count_set_bit(bm_hdmi) > 0) return HDMI_CONNECTED; return HDMI_DISCONNECTED; @@ -79,9 +79,9 @@ static void update_hdmi_bitmap(int index, int status) } if (status == HDMI_CONNECTED) - set_bit(bm_hdmi, index); + syscommon_bitmap_set_bit(bm_hdmi, index); else - clear_bit(bm_hdmi, index); + syscommon_bitmap_clear_bit(bm_hdmi, index); } static void update_all_hdmi_bitmap(int status) @@ -92,9 +92,9 @@ static void update_all_hdmi_bitmap(int status) } if (status == HDMI_CONNECTED) - set_all_bits(bm_hdmi); + syscommon_bitmap_set_all_bits(bm_hdmi); else - clear_all_bits(bm_hdmi); + syscommon_bitmap_clear_all_bits(bm_hdmi); } static int hdmi_update(const char *index, int status) @@ -159,12 +159,13 @@ static void hdmi_init(void *data) if (ret < 0) _E("Failed to init dbus method: %d", ret); - bm_hdmi = init_bitmap(HDMI_NUMBER_MAX); + bm_hdmi = syscommon_bitmap_init_bitmap(HDMI_NUMBER_MAX); } static void hdmi_exit(void *data) { - deinit_bitmap(bm_hdmi); + syscommon_bitmap_deinit_bitmap(bm_hdmi); + bm_hdmi = NULL; } static struct extcon_ops hdmi_extcon_ops = { diff --git a/src/power/power-event-lock.c b/src/power/power-event-lock.c index cca7921..15beb06 100644 --- a/src/power/power-event-lock.c +++ b/src/power/power-event-lock.c @@ -20,8 +20,9 @@ #include #include #include +#include +#include -#include "shared/bitmap.h" #include "shared/device-notifier.h" #include "shared/log.h" #include "power-event-lock.h" @@ -35,7 +36,7 @@ * of an event from going to sleep regardless of the power state. */ #define EVENT_LOCK "eventlock" -static struct dd_bitmap *eventlock; +static struct syscommon_bitmap *eventlock; static int notifier_id[EL_MAX][2]; void event_wake_lock(enum eventlock_type type) @@ -45,8 +46,8 @@ void event_wake_lock(enum eventlock_type type) if (type <= EL_MIN || type >= EL_MAX) return; - set_bit(eventlock, type); - setcount = count_set_bit(eventlock); + syscommon_bitmap_set_bit(eventlock, type); + setcount = syscommon_bitmap_count_set_bit(eventlock); _I("Set eventlock of type=%d, current number of eventlock=%d", type, setcount); @@ -63,8 +64,8 @@ void event_wake_unlock(enum eventlock_type type) if (type <= EL_MIN || type >= EL_MAX) return; - clear_bit(eventlock, type); - setcount = count_set_bit(eventlock); + syscommon_bitmap_clear_bit(eventlock, type); + setcount = syscommon_bitmap_count_set_bit(eventlock); _I("Unset eventlock of type=%d, current number of eventlock=%d", type, setcount); @@ -143,7 +144,7 @@ void power_event_lock_init(void) { int charger_wakelock = 0; - eventlock = init_bitmap(EL_MAX); + eventlock = syscommon_bitmap_init_bitmap(EL_MAX); if (!eventlock) { _E("Failed to init event lock bitmap"); return; diff --git a/src/shared/apps.c b/src/shared/apps.c index bb3a9c9..2a97507 100644 --- a/src/shared/apps.c +++ b/src/shared/apps.c @@ -18,18 +18,18 @@ #include #include +#include #include "core/log.h" #include "shared/common.h" #include "apps.h" #include "display-plugin.h" #include "display-state-transition.h" -#include "shared/bitmap.h" #define POPUP_METHOD "PopupLaunch" #define BUFF_MAX 255 -static struct dd_bitmap *bm_background; +static struct syscommon_bitmap *bm_background; static int pid_max; static const struct app_dbus_match { @@ -161,7 +161,7 @@ int remove_notification(char *type, int id) bool is_app_background(pid_t pid) { - return test_bit(bm_background, pid); + return syscommon_bitmap_test_bit(bm_background, pid); } void init_bm_background(void) @@ -173,7 +173,7 @@ void init_bm_background(void) pid_max = 32768; /* need (pid_max + 1) bits to represent pid 0 ~ pid_max */ - bm_background = init_bitmap(pid_max + 1); + bm_background = syscommon_bitmap_init_bitmap(pid_max + 1); if (!bm_background) _E("Failed to allock bm_background."); } @@ -187,9 +187,9 @@ void set_app_state(pid_t pid, enum application_state as) return; if (as == APPLICATION_BACKGROUND) - set_bit(bm_background, pid); + syscommon_bitmap_set_bit(bm_background, pid); else if (as == APPLICATION_FOREGROUND || as == APPLICATION_TERMINATED) - clear_bit(bm_background, pid); + syscommon_bitmap_clear_bit(bm_background, pid); else _E("Invalid as=%d", as); } @@ -201,5 +201,5 @@ static void __CONSTRUCTOR__ initialize(void) static void __DESTRUCTOR__ finalize(void) { - deinit_bitmap(bm_background); + syscommon_bitmap_deinit_bitmap(bm_background); } diff --git a/src/shared/bitmap.c b/src/shared/bitmap.c deleted file mode 100644 index d528188..0000000 --- a/src/shared/bitmap.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2020 - 2021 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 "bitmap.h" -#include "log.h" - -static void bitmap_alloc_size(struct dd_bitmap *bm, unsigned int nbits) -{ - unsigned int bytes = ROUNDUP_BITS_TO_LONGS(nbits) * BYTES_PER_LONG; - - bytes += BITMAP_MARGIN; - - bm->b = (unsigned long *) malloc(bytes); - if (!bm->b) - return; - - bm->size = nbits; -} - -void set_all_bits(struct dd_bitmap *bm) -{ - unsigned long complete_longs = bm->size / BITS_PER_LONG; - unsigned long complete_bytes = complete_longs * BYTES_PER_LONG; - unsigned long residue_bits = bm->size % BITS_PER_LONG; - - /* set all bits of the long element except the last long element */ - memset(bm->b, ~0, complete_bytes); - - /* set residue bits in the last long element */ - if (residue_bits) - bm->b[complete_longs] = (1UL << residue_bits) - 1; -} - -void clear_all_bits(struct dd_bitmap *bm) -{ - unsigned int bytes = ROUNDUP_BITS_TO_LONGS(bm->size) * BYTES_PER_LONG; - memset(bm->b, 0, bytes); -} - -void set_bit(struct dd_bitmap *bm, unsigned long nr) -{ - if (!bm) - return; - - if (nr >= bm->size) { - _E("Requested nr=%lu exceeds max bit=%lu", nr, bm->size - 1); - return; - } - - bm->b[BIT_WORD(nr)] |= BIT_MASK(nr); -} - -void clear_bit(struct dd_bitmap *bm, unsigned long nr) -{ - if (!bm) - return; - - if (nr >= bm->size) { - _E("Requested nr=%lu exceeds max bit=%lu", nr, bm->size - 1); - return; - } - - bm->b[BIT_WORD(nr)] &= ~BIT_MASK(nr); -} - -bool test_bit(struct dd_bitmap *bm, unsigned long nr) -{ - if (!bm) - return false; - - if (nr >= bm->size) { - _E("Requested nr=%lu exceeds max bit=%lu", nr, bm->size - 1); - return false; - } - - return bm->b[BIT_WORD(nr)] & BIT_MASK(nr); -} - -int count_set_bit(struct dd_bitmap *bm) -{ - int i; - int count = 0; - - if (!bm) - return -1; - - for (i = 0; i < ROUNDUP_BITS_TO_LONGS(bm->size); ++i) - count += __builtin_popcountl(bm->b[i]); - - return count; -} - -int count_unset_bit(struct dd_bitmap *bm) -{ - if (!bm) - return -1; - - return bm->size - count_set_bit(bm); -} - -struct dd_bitmap* init_bitmap(unsigned int nbits) -{ - struct dd_bitmap *bm = NULL; - - if (nbits == 0) - return NULL; - - bm = (struct dd_bitmap *) malloc(sizeof(struct dd_bitmap)); - if (!bm) - return NULL; - - bm->b = NULL; - bm->size = 0; - - bitmap_alloc_size(bm, nbits); - if (!bm->b) { - free(bm); - return NULL; - } - - clear_all_bits(bm); - bm->size = nbits; - - return bm; -} - -void deinit_bitmap(struct dd_bitmap *bm) -{ - if (!bm) - return; - - free(bm->b); - free(bm); -} diff --git a/src/shared/bitmap.h b/src/shared/bitmap.h deleted file mode 100644 index 902a44d..0000000 --- a/src/shared/bitmap.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2020 - 2021 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 __DD_BITMAP_H__ -#define __DD_BITMAP_H__ - -#include - -#include "shared/common.h" - -/* Align bits by size of long, and convert it to long, - * for example, if long is 64bit then, - * ROUNDUP_BITS_TO_LONGS(0) -> 0 - * ROUNDUP_BITS_TO_LONGS(1) -> 1 - * ROUNDUP_BITS_TO_LONGS(64) -> 1 - * ROUNDUP_BITS_TO_LONGS(65) -> 2 - * ROUNDUP_BITS_TO_LONGS(128) -> 2 - * ROUNDUP_BITS_TO_LONGS(129) -> 3 - * ... */ -#define ROUNDUP_BITS_TO_LONGS(nbits) (roundup(nbits, BITS_PER_LONG) / BITS_PER_LONG) - -#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) -#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) -#define BITMAP_MARGIN (BYTES_PER_LONG * 2) /* trailing margin for safety, bytes */ - -struct dd_bitmap { - /* bitmap */ - unsigned long *b; - - /* number of bits, not the maximum bit. - * maximum bit is size - 1 */ - unsigned long size; -}; - -void set_bit(struct dd_bitmap *bm, unsigned long nr); -void clear_bit(struct dd_bitmap *bm, unsigned long nr); -bool test_bit(struct dd_bitmap *bm, unsigned long nr); -void set_all_bits(struct dd_bitmap *bm); -void clear_all_bits(struct dd_bitmap *bm); -int count_set_bit(struct dd_bitmap *bm); -int count_unset_bit(struct dd_bitmap *bm); -struct dd_bitmap* init_bitmap(unsigned int nbits); -void deinit_bitmap(struct dd_bitmap *bm); - -#endif diff --git a/tests/deviced-common-private-test/CMakeLists.txt b/tests/deviced-common-private-test/CMakeLists.txt index c4262d7..6e69ca8 100644 --- a/tests/deviced-common-private-test/CMakeLists.txt +++ b/tests/deviced-common-private-test/CMakeLists.txt @@ -23,7 +23,6 @@ TARGET_LINK_LIBRARIES(test-shared ${ORIG_REQUIRED_PKGS_LDFLAGS}) PKG_CHECK_MODULES(TEST_REQUIRED_PKGS REQUIRED cmocka) -LIST(APPEND TEST_DRIVERS test-bitmap.c) LIST(APPEND TEST_DRIVERS test-device-notifier.c) LIST(APPEND TEST_DRIVERS test-plugin.c) diff --git a/tests/deviced-common-private-test/test-bitmap.c b/tests/deviced-common-private-test/test-bitmap.c deleted file mode 100644 index 23e5644..0000000 --- a/tests/deviced-common-private-test/test-bitmap.c +++ /dev/null @@ -1,95 +0,0 @@ -#include - -#include "test-main.h" - -static void test_init_bitmap_p(void **state) -{ - struct dd_bitmap *bm; - - bm = init_bitmap(10); - assert_non_null(bm); - - deinit_bitmap(bm); -} - -static void test_init_bitmap_n(void **state) -{ - struct dd_bitmap *bm = NULL; - - bm = init_bitmap(0); - assert_null(bm); -} - -static void test_test_bit(void **state) -{ - struct dd_bitmap *bm; - const int bmsize = 37; - bool bit; - int i, nbit; - - bm = init_bitmap(bmsize); - assert_non_null(bm); - - for (i = 0; i < bmsize; ++i) { - bit = test_bit(bm, i); - assert_false(bit); - } - - /* count bit by setting one by one */ - for (i = 0; i < bmsize; ++i) { - set_bit(bm, i); - nbit = count_set_bit(bm); - assert_int_equal(nbit, i + 1); - } - - /* test the marginal bit */ - bit = test_bit(bm, 0); - assert_true(bit); - bit = test_bit(bm, bmsize - 1); - assert_true(bit); - bit = test_bit(bm, bmsize); - assert_false(bit); - - - /* count bit by clearing one by one */ - for (i = 0; i < bmsize; ++i) { - clear_bit(bm, i); - nbit = count_set_bit(bm); - assert_int_equal(nbit, bmsize - i - 1); - } - - deinit_bitmap(bm); -} - -static void test_all_bit(void **state) -{ - struct dd_bitmap *bm; - const int bmsize = 37; - int nbit; - - bm = init_bitmap(bmsize); - assert_non_null(bm); - - set_all_bits(bm); - nbit = count_set_bit(bm); - assert_int_equal(nbit, bmsize); - - clear_all_bits(bm); - nbit = count_set_bit(bm); - assert_int_equal(nbit, 0); - - deinit_bitmap(bm); -} - -static int run_bitmap_test(void) -{ - static const struct CMUnitTest testsuite[] = { - cmocka_unit_test(test_init_bitmap_p), - cmocka_unit_test(test_init_bitmap_n), - cmocka_unit_test(test_test_bit), - cmocka_unit_test(test_all_bit), - }; - - return cmocka_run_group_tests(testsuite, NULL, NULL); -} -ADD_TEST_FUNCTION(run_bitmap_test) -- 2.7.4 From 991d161e6ebbcefeb13f0796d0dc82eace52dcf1 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 17 Jul 2023 11:32:19 +0900 Subject: [PATCH 14/16] shared: Move suspend_path()/resume_path() to tzip Those functions are only used by tzip module. Change-Id: I28a861373835a6e26bed39de8280c29b348c7552 Signed-off-by: Youngjae Cho --- src/shared/common.c | 146 ---------------------------------------------------- src/shared/common.h | 2 - src/tzip/tzip.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 148 deletions(-) diff --git a/src/shared/common.c b/src/shared/common.c index f52fa6f..552c3ad 100644 --- a/src/shared/common.c +++ b/src/shared/common.c @@ -261,152 +261,6 @@ void umount_partition_by_kill(const char *path, const int max_retry) return; } -#define CMD_FROZEN "FROZEN" -#define CMD_THAWED "THAWED" -static int freeze_processes_on_path(const char *frz_name, const char *part_path) -{ - char *fuser_cmd = NULL; - FILE *fuser_fp; - char *line = NULL; - size_t len = 0; - int task_fd; - int freezer_fd; - char *freezer_procs; - char *freezer_state; - int ret; - - ret = asprintf(&fuser_cmd, "fuser -m %s | grep -o '[0-9]*'", part_path); - if (ret < 0) - return -1; - - fuser_fp = popen(fuser_cmd, "r"); - free(fuser_cmd); - if (fuser_fp == NULL) - return -1; - - ret = asprintf(&freezer_procs, "/sys/fs/cgroup/freezer/%s/cgroup.procs", frz_name); - if (ret < 0) { - pclose(fuser_fp); - return -1; - } - - task_fd = open(freezer_procs, O_RDWR); - free(freezer_procs); - if (task_fd < 0) { - pclose(fuser_fp); - return -1; - } - - while (getline(&line, &len, fuser_fp) != -1) { - int ret; - int str_len = strlen(line); - if (str_len <= 1) - continue; - - ret = write(task_fd, line, str_len-1); - if (ret < 0) - break; - } - - close(task_fd); - free(line); - pclose(fuser_fp); - - ret = asprintf(&freezer_state, "/sys/fs/cgroup/freezer/%s/freezer.state", frz_name); - if (ret < 0) - return -1; - - freezer_fd = open(freezer_state, O_RDWR); - free(freezer_state); - if (freezer_fd < 0) - return -1; - - ret = write(freezer_fd, CMD_FROZEN, strlen(CMD_FROZEN)); - close(freezer_fd); - if (ret < 0) - return -1; - - return 0; -} - -static bool check_frozen(const char *frz_name) -{ - char *state_path = NULL; - char *line = NULL; - size_t len = 0; - FILE *fd; - int ret; - bool result = false; - - ret = asprintf(&state_path, "/sys/fs/cgroup/freezer/%s/freezer.state", frz_name); - if (ret < 0) - return false; - - fd = fopen(state_path, "r"); - free(state_path); - if (fd == NULL) - return false; - - ret = getline(&line, &len, fd); - if (ret != -1 && line) { - if (!strncmp(line, CMD_FROZEN, strlen(CMD_FROZEN))) - result = true; - else - result = false; - - } - - free(line); - fclose(fd); - - return result; -} - -static int thaw_processes_on_path(const char *frz_name) -{ - int freezer_fd; - int ret; - - char *freezer_state; - ret = asprintf(&freezer_state, "/sys/fs/cgroup/freezer/%s/freezer.state", frz_name); - if (ret < 0) - return -1; - - freezer_fd = open(freezer_state, O_RDWR); - free(freezer_state); - if (freezer_fd < 0) - return -1; - - ret = write(freezer_fd, CMD_THAWED, strlen(CMD_THAWED)); - close(freezer_fd); - if (ret < 0) - return -1; - - return 0; -} - -void suspend_path(const char *frz_name, const char *path, const int max_retry) -{ - bool frozen = false; - int retry = 0; - - freeze_processes_on_path(frz_name, path); - - do { - usleep((useconds_t)MSEC_TO_USEC(500)); - - frozen = check_frozen(frz_name); - - retry++; - - } while (!frozen && retry < max_retry); -} - -void resume_path(const char *frz_name, const char *path) -{ - thaw_processes_on_path(frz_name); -} - int get_privilege(pid_t pid, char *name, size_t len) { char path[PATH_MAX]; diff --git a/src/shared/common.h b/src/shared/common.h index 627700c..1d9f1a0 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -204,8 +204,6 @@ int sys_check_node(char *path); int get_systemd_reboot_param(char *buf, unsigned bufsize); int terminate_process(const char *partition, bool force); int mount_check(const char* path); -void suspend_path(const char *frz_name, const char *path, const int max_retry); -void resume_path(const char *frz_name, const char *path); void umount_partition_by_kill(const char *path, const int max_retry); int get_privilege(pid_t pid, char *name, size_t len); bool is_emulator(void); diff --git a/src/tzip/tzip.c b/src/tzip/tzip.c index d99ed56..72bf41f 100644 --- a/src/tzip/tzip.c +++ b/src/tzip/tzip.c @@ -68,6 +68,152 @@ static int tzip_is_mounted(const char *mount_point); static int tzip_unmount_zipfs(const char *mount_point); static int tzip_mount_zipfs(const char *src_file, const char *mount_point, const char *smack); +#define CMD_FROZEN "FROZEN" +#define CMD_THAWED "THAWED" +static int freeze_processes_on_path(const char *frz_name, const char *part_path) +{ + char *fuser_cmd = NULL; + FILE *fuser_fp; + char *line = NULL; + size_t len = 0; + int task_fd; + int freezer_fd; + char *freezer_procs; + char *freezer_state; + int ret; + + ret = asprintf(&fuser_cmd, "fuser -m %s | grep -o '[0-9]*'", part_path); + if (ret < 0) + return -1; + + fuser_fp = popen(fuser_cmd, "r"); + free(fuser_cmd); + if (fuser_fp == NULL) + return -1; + + ret = asprintf(&freezer_procs, "/sys/fs/cgroup/freezer/%s/cgroup.procs", frz_name); + if (ret < 0) { + pclose(fuser_fp); + return -1; + } + + task_fd = open(freezer_procs, O_RDWR); + free(freezer_procs); + if (task_fd < 0) { + pclose(fuser_fp); + return -1; + } + + while (getline(&line, &len, fuser_fp) != -1) { + int ret; + int str_len = strlen(line); + if (str_len <= 1) + continue; + + ret = write(task_fd, line, str_len-1); + if (ret < 0) + break; + } + + close(task_fd); + free(line); + pclose(fuser_fp); + + ret = asprintf(&freezer_state, "/sys/fs/cgroup/freezer/%s/freezer.state", frz_name); + if (ret < 0) + return -1; + + freezer_fd = open(freezer_state, O_RDWR); + free(freezer_state); + if (freezer_fd < 0) + return -1; + + ret = write(freezer_fd, CMD_FROZEN, strlen(CMD_FROZEN)); + close(freezer_fd); + if (ret < 0) + return -1; + + return 0; +} + +static bool check_frozen(const char *frz_name) +{ + char *state_path = NULL; + char *line = NULL; + size_t len = 0; + FILE *fd; + int ret; + bool result = false; + + ret = asprintf(&state_path, "/sys/fs/cgroup/freezer/%s/freezer.state", frz_name); + if (ret < 0) + return false; + + fd = fopen(state_path, "r"); + free(state_path); + if (fd == NULL) + return false; + + ret = getline(&line, &len, fd); + if (ret != -1 && line) { + if (!strncmp(line, CMD_FROZEN, strlen(CMD_FROZEN))) + result = true; + else + result = false; + + } + + free(line); + fclose(fd); + + return result; +} + +static int thaw_processes_on_path(const char *frz_name) +{ + int freezer_fd; + int ret; + + char *freezer_state; + ret = asprintf(&freezer_state, "/sys/fs/cgroup/freezer/%s/freezer.state", frz_name); + if (ret < 0) + return -1; + + freezer_fd = open(freezer_state, O_RDWR); + free(freezer_state); + if (freezer_fd < 0) + return -1; + + ret = write(freezer_fd, CMD_THAWED, strlen(CMD_THAWED)); + close(freezer_fd); + if (ret < 0) + return -1; + + return 0; +} + +static void suspend_path(const char *frz_name, const char *path, const int max_retry) +{ + bool frozen = false; + int retry = 0; + + freeze_processes_on_path(frz_name, path); + + do { + usleep((useconds_t)MSEC_TO_USEC(500)); + + frozen = check_frozen(frz_name); + + retry++; + + } while (!frozen && retry < max_retry); +} + +static void resume_path(const char *frz_name, const char *path) +{ + thaw_processes_on_path(frz_name); +} + static int check_path_available(char *mountpath) { const char *path; -- 2.7.4 From a0802f81fe5e80fc16086d3eb458690ab2205f1e Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 17 Jul 2023 11:43:43 +0900 Subject: [PATCH 15/16] Remove unused code and file Change-Id: I9c9c6e4652e9b97ad6e06efa8c0baebe0a2b4db4 Signed-off-by: Youngjae Cho --- src/libdeviced/deviced-noti.c | 2 +- src/libdeviced/deviced-util.c | 4 +++- src/shared/common.h | 4 ---- src/shared/deviced-internal.h | 38 -------------------------------------- src/shared/deviced-priv.h | 36 ------------------------------------ src/shared/score-defines.h | 31 ------------------------------- 6 files changed, 4 insertions(+), 111 deletions(-) delete mode 100644 src/shared/deviced-internal.h delete mode 100644 src/shared/deviced-priv.h delete mode 100644 src/shared/score-defines.h diff --git a/src/libdeviced/deviced-noti.c b/src/libdeviced/deviced-noti.c index 401a365..c148eeb 100644 --- a/src/libdeviced/deviced-noti.c +++ b/src/libdeviced/deviced-noti.c @@ -29,8 +29,8 @@ #include #include +#include "common.h" #include "dd-deviced.h" -#include "deviced-priv.h" #include "log.h" #define PREDEF_PWROFF_POPUP "pwroff-popup" diff --git a/src/libdeviced/deviced-util.c b/src/libdeviced/deviced-util.c index 6f73b5f..f38ad0d 100644 --- a/src/libdeviced/deviced-util.c +++ b/src/libdeviced/deviced-util.c @@ -32,7 +32,9 @@ #include "log.h" #include "dd-deviced.h" -#include "deviced-priv.h" +#include "common.h" + +#define BUFF_MAX 255 API int deviced_get_pid(const char *execpath) { diff --git a/src/shared/common.h b/src/shared/common.h index 1d9f1a0..08754f0 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -196,13 +196,10 @@ static inline void __cleanup_fclose_func(FILE **f) { #define _cleanup_fclose_ _cleanup_(__cleanup_fclose_func) #endif -int get_exec_pid(const char *execpath); -int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size); int is_app(pid_t pid); int run_child(int argc, const char *argv[]); int sys_check_node(char *path); int get_systemd_reboot_param(char *buf, unsigned bufsize); -int terminate_process(const char *partition, bool force); int mount_check(const char* path); void umount_partition_by_kill(const char *path, const int max_retry); int get_privilege(pid_t pid, char *name, size_t len); @@ -210,7 +207,6 @@ bool is_emulator(void); int do_mkdir(const char *path, mode_t mode); int do_copy_force(const char *src, const char *dst); void watchdog_notify(void); -int print_open_files(const char *mount_point); int get_command(pid_t pid, char *comm, size_t len); #ifdef __cplusplus diff --git a/src/shared/deviced-internal.h b/src/shared/deviced-internal.h deleted file mode 100644 index b26d67e..0000000 --- a/src/shared/deviced-internal.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef ___DEVICED_INTERNAL___ -#define ___DEVICED_INTERNAL___ -#include -#include "dd-deviced.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* This file will be removed */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif -#endif /* ___DEVICED_INTERNAL___ */ diff --git a/src/shared/deviced-priv.h b/src/shared/deviced-priv.h deleted file mode 100644 index 8cb6cf9..0000000 --- a/src/shared/deviced-priv.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __SYSTEM_PRIVATE__ -#define __SYSTEM_PRIVATE__ - -#include "common.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define BUFF_MAX 255 - - int util_launch_app_cmd(const char *cmdline); - -#ifdef __cplusplus -} -#endif -#endif /* __SYSTEM_PRIVATE__ */ diff --git a/src/shared/score-defines.h b/src/shared/score-defines.h deleted file mode 100644 index 44638e7..0000000 --- a/src/shared/score-defines.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __OOM_H__ -#define __OOM_H__ - -#define OOMADJ_SU (0) -#define OOMADJ_INIT (100) -#define OOMADJ_FOREGRD_LOCKED (150) -#define OOMADJ_FOREGRD_UNLOCKED (200) -#define OOMADJ_BACKGRD_LOCKED (250) -#define OOMADJ_BACKGRD_UNLOCKED (300) -#define OOMADJ_APP_LIMIT OOMADJ_INIT - -#endif /* __OOM_H__ */ -- 2.7.4 From c7b1ab8397aad066775a65575fbf8e15ec16f20d Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 17 Jul 2023 15:20:06 +0900 Subject: [PATCH 16/16] shared: Replace proc operation with that of the libsyscommon Change-Id: I733374a063ab2dee5192cf1c553e1480f9a2343c Signed-off-by: Youngjae Cho --- src/display/display-dbus.c | 3 +- src/display/display-lock.c | 6 ++-- src/power/power-dbus.c | 3 +- src/power/power-off.c | 5 +-- src/power/power.c | 3 +- src/shared/common.c | 88 ---------------------------------------------- src/shared/common.h | 3 -- src/tzip/tzip.c | 5 +-- 8 files changed, 16 insertions(+), 100 deletions(-) diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 05c9a9d..7ebab24 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -1084,7 +1085,7 @@ static GVariant *dbus_locktimeout_expired(GDBusConnection *conn, goto out; } - ret = get_command(pid, comm, sizeof(comm)); + ret = syscommon_proc_get_comm(pid, comm, sizeof(comm)); if (ret < 0) { _E("Failed to get command (%d)", ret); goto out; diff --git a/src/display/display-lock.c b/src/display/display-lock.c index fe24f75..87bfae6 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -21,6 +21,8 @@ * @brief Manage each state's lock. Lock blocks state transition by timeout. * */ +#include + #include "shared/common.h" #include "ambient-mode.h" #include "device-interface.h" @@ -311,7 +313,7 @@ static gboolean lock_watchdog_callback(void *data) return G_SOURCE_REMOVE; } - if (!is_app(dl->pid)) { + if (!syscommon_proc_is_app(dl->pid)) { /* For daemon, no need to ask resourced if it is abnormal lock */ // TODO: is it correct? broadcast_lock_watchdog_expired(dl->pid, dl->state, NULL, dl->time); @@ -785,4 +787,4 @@ int display_lock_request_unlock_with_option(pid_t pid, int s_bits, int flag) display_state_transition_do_state_transition_by_pm_control_event(&recv_data); return 0; -} \ No newline at end of file +} diff --git a/src/power/power-dbus.c b/src/power/power-dbus.c index 7f68edf..d7e9feb 100644 --- a/src/power/power-dbus.c +++ b/src/power/power-dbus.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "shared/devices.h" @@ -443,7 +444,7 @@ static GVariant *dbus_power_change_state(GDBusConnection *conn, if (pid == -1 || kill(pid, 0) == -1) goto out; - get_command(pid, comm, sizeof(comm)); + syscommon_proc_get_comm(pid, comm, sizeof(comm)); if (is_poweroff_state(next)) CRITICAL_LOG("Pid=%d(%s) sent request for PowerChangeState to %s", pid, comm, state_name(next)); diff --git a/src/power/power-off.c b/src/power/power-off.c index 1d4bdec..56369c6 100644 --- a/src/power/power-off.c +++ b/src/power/power-off.c @@ -37,6 +37,7 @@ #include #include #include +#include #include "dd-deviced.h" #include "core/log.h" @@ -357,7 +358,7 @@ static GVariant *dbus_poweroff_handler(GDBusConnection *conn, if (ret < 0) goto out; - get_command(ret, comm, sizeof(comm)); + syscommon_proc_get_comm(ret, comm, sizeof(comm)); if (strncmp(type, "poweroff", sizeof("poweroff")) == 0) next = DEVICED_POWER_STATE_POWEROFF; @@ -393,7 +394,7 @@ static GVariant *dbus_poweroff_option_handler(GDBusConnection *conn, if (ret < 0) goto out; - get_command(ret, comm, sizeof(comm)); + syscommon_proc_get_comm(ret, comm, sizeof(comm)); if (strncmp(type, "poweroff", sizeof("poweroff")) == 0) next = DEVICED_POWER_STATE_POWEROFF; diff --git a/src/power/power.c b/src/power/power.c index 6682617..2b00c67 100644 --- a/src/power/power.c +++ b/src/power/power.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include "shared/devices.h" @@ -190,7 +191,7 @@ int add_change_state_wait(pid_t pid, guint64 state) pi->pid = pid; pi->state_bitmap = state; - get_command(pid, pi->comm, sizeof(pi->comm)); + syscommon_proc_get_comm(pid, pi->comm, sizeof(pi->comm)); proc_list = g_list_append(proc_list, pi); _D("pid=%d(%s) added csw for %#"PRIx64, pid, pi->comm, state); diff --git a/src/shared/common.c b/src/shared/common.c index 552c3ad..d87c54e 100644 --- a/src/shared/common.c +++ b/src/shared/common.c @@ -41,70 +41,6 @@ #define BUFF_MAX 255 -#define APP_ATTR_PATH "/proc/%d/attr/current" - -int get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size) -{ - int fd, ret; - char buf[PATH_MAX + 1]; - char *filename; - - snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); - fd = open(buf, O_RDONLY); - if (fd < 0) { - errno = ESRCH; - return -1; - } - - ret = read(fd, buf, PATH_MAX); - close(fd); - if (ret < 0) - return -1; - - buf[PATH_MAX] = '\0'; - - filename = strrchr(buf, '/'); - if (filename == NULL) - filename = buf; - else - filename = filename + 1; - - if (cmdline_size < strlen(filename) + 1) { - errno = EOVERFLOW; - return -1; - } - - strncpy(cmdline, filename, cmdline_size - 1); - cmdline[cmdline_size - 1] = '\0'; - return 0; -} - -int is_app(pid_t pid) -{ - char attr[64]; - size_t len; - int ret; - - ret = get_privilege(pid, attr, sizeof(attr)); - if (ret < 0) { - _E("Failed to get privilege of PID(%d).", pid); - return -1; - } - - len = strlen(attr) + 1; - - if (!strncmp("System", attr, len)) - return 0; - - if (!strncmp("User", attr, len)) - return 0; - - if (!strncmp("System::Privileged", attr, len)) - return 0; - - return 1; -} - /* * Helper function * - Read from sysfs entry @@ -261,30 +197,6 @@ void umount_partition_by_kill(const char *path, const int max_retry) return; } -int get_privilege(pid_t pid, char *name, size_t len) -{ - char path[PATH_MAX]; - char attr[BUFF_MAX]; - size_t attr_len; - FILE *fp; - - snprintf(path, sizeof(path), APP_ATTR_PATH, pid); - - fp = fopen(path, "r"); - if (!fp) - return -errno; - - attr_len = fread(attr, 1, sizeof(attr) - 1, fp); - fclose(fp); - if (attr_len <= 0) - return -ENOENT; - - attr[attr_len] = '\0'; - - snprintf(name, len, "%s", attr); - return 0; -} - #define MODEL_NAME "http://tizen.org/system/model_name" #define MODEL_EMULATOR "Emulator" diff --git a/src/shared/common.h b/src/shared/common.h index 08754f0..12e2814 100644 --- a/src/shared/common.h +++ b/src/shared/common.h @@ -196,18 +196,15 @@ static inline void __cleanup_fclose_func(FILE **f) { #define _cleanup_fclose_ _cleanup_(__cleanup_fclose_func) #endif -int is_app(pid_t pid); int run_child(int argc, const char *argv[]); int sys_check_node(char *path); int get_systemd_reboot_param(char *buf, unsigned bufsize); int mount_check(const char* path); void umount_partition_by_kill(const char *path, const int max_retry); -int get_privilege(pid_t pid, char *name, size_t len); bool is_emulator(void); int do_mkdir(const char *path, mode_t mode); int do_copy_force(const char *src, const char *dst); void watchdog_notify(void); -int get_command(pid_t pid, char *comm, size_t len); #ifdef __cplusplus } diff --git a/src/tzip/tzip.c b/src/tzip/tzip.c index 72bf41f..4f0602e 100644 --- a/src/tzip/tzip.c +++ b/src/tzip/tzip.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "core/log.h" #include "shared/devices.h" @@ -912,7 +913,7 @@ static GVariant *dbus_request_mount_tzip_internal(GDBusConnection *conn, const g } pid = gdbus_connection_get_sender_pid(conn, sender); - if (is_app(pid) != 0) { + if (syscommon_proc_is_app(pid) != 0) { _E("PID(%d) is not privileged to use tzip.", pid); ret = -EPERM; goto out; @@ -997,7 +998,7 @@ static GVariant *dbus_request_unmount_tzip_internal(GDBusConnection *conn, const } pid = gdbus_connection_get_sender_pid(conn, sender); - if (is_app(pid) != 0) { + if (syscommon_proc_is_app(pid) != 0) { _E("PID(%d) is not privileged to use tzip.", pid); ret = -EPERM; goto out; -- 2.7.4