From 552c2c2e35dc84558cb12b514d3872ff4a8e69da Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 16 Jun 2022 14:42:25 +0900 Subject: [PATCH 01/16] input: rename Name= of EventAction Change-Id: Iabdf19bd8c90937f0052e598b608f68efc0a6be7 Signed-off-by: Youngjae Cho --- conf/input-profile-iot-headless.conf | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/conf/input-profile-iot-headless.conf b/conf/input-profile-iot-headless.conf index 3acdc6a..69af5ad 100644 --- a/conf/input-profile-iot-headless.conf +++ b/conf/input-profile-iot-headless.conf @@ -18,7 +18,7 @@ # - acquire wakelock for a specfied timeout [EventAction] -Name=PWKEY_SHORT +Name=PWKEY_SHORT_EDGE Enum=1000 Keycode=power DetectionRangeMsec=0,2000 @@ -26,7 +26,7 @@ TriggerType=edge ActionBroadcast=yes [EventAction] -Name=PWKEY_CHECKPOINT_LONG +Name=PWKEY_LONG_LEVEL Enum=1001 Keycode=power DetectionRangeMsec=2000,-1 @@ -34,7 +34,7 @@ TriggerType=level ActionBroadcast=yes [EventAction] -Name=PWKEY_LONG +Name=PWKEY_LONG_EDGE Enum=1002 Keycode=power DetectionRangeMsec=2000,7000 @@ -43,7 +43,7 @@ ActionChangeState=normal,sleep ActionChangeState=sleep,normal [EventAction] -Name=PWKEY_CHECKPOINT_LONGEST +Name=PWKEY_LONGEST_LEVEL Enum=1003 Keycode=power DetectionRangeMsec=7000,-1 @@ -51,7 +51,7 @@ TriggerType=level ActionBroadcast=yes [EventAction] -Name=PWKEY_LONGEST +Name=PWKEY_LONGEST_EDGE Enum=1004 Keycode=power DetectionRangeMsec=7000,-1 @@ -60,7 +60,7 @@ ConditionVconf=memory/sysman/charger_status,int,0 ActionChangeState=normal,poweroff [EventAction] -Name=BTKEY_SHORT +Name=BTKEY_SHORT_EDGE Enum=1005 Keycode=bluetooth DetectionRangeMsec=0,2000 @@ -69,7 +69,7 @@ ActionBroadcast=yes WakeLockDurationSec=5 [EventAction] -Name=BTKEY_CHECKPOINT_LONG +Name=BTKEY_LONG_LEVEL Enum=1006 Keycode=bluetooth DetectionRangeMsec=2000,-1 @@ -77,7 +77,7 @@ TriggerType=level ActionBroadcast=yes [EventAction] -Name=BTKEY_LONG +Name=BTKEY_LONG_EDGE Enum=1007 Keycode=bluetooth DetectionRangeMsec=2000,7000 -- 2.7.4 From 28fa8fb282e92660f5f6417775450a3d2e94bd88 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 16 Jun 2022 14:59:57 +0900 Subject: [PATCH 02/16] input: add wakelock action for level event Change-Id: Ie7fa5cb2d4c8101c9d56bc52130ed29caac2ccf4 Signed-off-by: Youngjae Cho --- conf/input-profile-iot-headless.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/conf/input-profile-iot-headless.conf b/conf/input-profile-iot-headless.conf index 69af5ad..7c2d01b 100644 --- a/conf/input-profile-iot-headless.conf +++ b/conf/input-profile-iot-headless.conf @@ -32,6 +32,7 @@ Keycode=power DetectionRangeMsec=2000,-1 TriggerType=level ActionBroadcast=yes +WakeLockDurationSec=5 [EventAction] Name=PWKEY_LONG_EDGE @@ -49,6 +50,7 @@ Keycode=power DetectionRangeMsec=7000,-1 TriggerType=level ActionBroadcast=yes +WakeLockDurationSec=5 [EventAction] Name=PWKEY_LONGEST_EDGE @@ -75,6 +77,7 @@ Keycode=bluetooth DetectionRangeMsec=2000,-1 TriggerType=level ActionBroadcast=yes +WakeLockDurationSec=5 [EventAction] Name=BTKEY_LONG_EDGE -- 2.7.4 From ddf0575b32d7bdcf763d8ec7f551137a74eb4350 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 16 Jun 2022 17:24:17 +0900 Subject: [PATCH 03/16] input: add WakeLockDurationSec to PWKEY_SHORT_EDGE Change-Id: Ia9e6ab7cec68ef7fe5e3cbe8926f3838fd583da6 Signed-off-by: Youngjae Cho --- conf/input-profile-iot-headless.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/input-profile-iot-headless.conf b/conf/input-profile-iot-headless.conf index 7c2d01b..1e20825 100644 --- a/conf/input-profile-iot-headless.conf +++ b/conf/input-profile-iot-headless.conf @@ -24,6 +24,7 @@ Keycode=power DetectionRangeMsec=0,2000 TriggerType=edge ActionBroadcast=yes +WakeLockDurationSec=5 [EventAction] Name=PWKEY_LONG_LEVEL -- 2.7.4 From 7556e7bcf29b4b8e108d4dfbb0f415ff941a5760 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 17 Jun 2022 14:26:50 +0900 Subject: [PATCH 04/16] apps: move to shared library Change-Id: I039bff30ad1b3745abd72ee4637caadd37487319 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 1 - plugins/iot-headed/display/core.c | 2 +- plugins/iot-headed/display/key-filter.c | 2 +- plugins/mobile/battery/battery-notification.c | 2 +- plugins/mobile/display/core.c | 2 +- plugins/mobile/display/key-filter.c | 2 +- plugins/tv/display/core.c | 2 +- plugins/tv/display/key-filter.c | 2 +- plugins/wearable/display/core.c | 2 +- plugins/wearable/display/key-filter.c | 2 +- src/battery/lowbat-handler.c | 2 +- src/battery/power-supply.c | 2 +- src/display/display-dbus.c | 2 +- src/display/display-lock.c | 2 +- src/power/power-off.c | 1 - src/{apps => shared}/apps.c | 2 ++ src/{apps => shared}/apps.h | 0 src/thermal/thermal.c | 2 +- src/usb-gadget/usb-state.c | 2 +- src/usb-host/usb-host.c | 2 +- 20 files changed, 18 insertions(+), 18 deletions(-) rename src/{apps => shared}/apps.c (99%) rename src/{apps => shared}/apps.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index de82918..ba0c0c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,7 +64,6 @@ SET(CONFDIR "/etc/${PROJECT_NAME}") SET(VERSION 0.1.0) SET(SRCS - src/apps/apps.c src/control/control.c src/core/delayed-init-notifier.c src/core/devices.c diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index cda404c..b6edf04 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -51,7 +51,7 @@ #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" -#include "apps/apps.h" +#include "shared/apps.h" #include "extcon/extcon.h" #include "battery/power-supply.h" #include "power/power-off.h" diff --git a/plugins/iot-headed/display/key-filter.c b/plugins/iot-headed/display/key-filter.c index 5f0d544..db9a338 100644 --- a/plugins/iot-headed/display/key-filter.c +++ b/plugins/iot-headed/display/key-filter.c @@ -38,10 +38,10 @@ #include "shared/device-notifier.h" #include "shared/common.h" #include "shared/plugin.h" +#include "shared/apps.h" #include "power/power-off.h" #include "power/power-suspend.h" #include "led/touch-key.h" -#include "apps/apps.h" #include "display/display-lock.h" #ifndef KEY_SCREENLOCK diff --git a/plugins/mobile/battery/battery-notification.c b/plugins/mobile/battery/battery-notification.c index 8b7b1e6..b8a9578 100644 --- a/plugins/mobile/battery/battery-notification.c +++ b/plugins/mobile/battery/battery-notification.c @@ -21,7 +21,6 @@ #include #include -#include "apps/apps.h" #include "core/log.h" #include "battery.h" #include "config.h" @@ -34,6 +33,7 @@ #include "shared/eventsystem.h" #include "shared/plugin.h" #include "shared/device-notifier.h" +#include "shared/apps.h" #define METHOD_LOW_NOTI_ON "BatteryLowNotiOn" diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 8a0a100..2e2d569 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -50,7 +50,7 @@ #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" -#include "apps/apps.h" +#include "shared/apps.h" #include "extcon/extcon.h" #include "battery/power-supply.h" #include "power/power-off.h" diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index c596cc1..1e56db1 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -38,10 +38,10 @@ #include "shared/device-notifier.h" #include "shared/common.h" #include "shared/plugin.h" +#include "shared/apps.h" #include "power/power-off.h" #include "power/power-suspend.h" #include "led/touch-key.h" -#include "apps/apps.h" #include "display/display-lock.h" #ifndef KEY_SCREENLOCK diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index f515e7a..d8ba642 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -50,7 +50,7 @@ #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" -#include "apps/apps.h" +#include "shared/apps.h" #include "extcon/extcon.h" #include "battery/power-supply.h" #include "power/power-off.h" diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index dc2c2bd..42851ce 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -38,10 +38,10 @@ #include "shared/device-notifier.h" #include "shared/common.h" #include "shared/plugin.h" +#include "shared/apps.h" #include "power/power-off.h" #include "power/power-suspend.h" #include "led/touch-key.h" -#include "apps/apps.h" #include "display/display-lock.h" #ifndef KEY_SCREENLOCK diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index e29e170..1506958 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -51,7 +51,7 @@ #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" -#include "apps/apps.h" +#include "shared/apps.h" #include "extcon/extcon.h" #include "battery/power-supply.h" #include "power/power-off.h" diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 68e774f..ab4b47c 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -38,10 +38,10 @@ #include "shared/device-notifier.h" #include "shared/common.h" #include "shared/plugin.h" +#include "shared/apps.h" #include "power/power-off.h" #include "power/power-suspend.h" #include "led/touch-key.h" -#include "apps/apps.h" #include "display/display-lock.h" #ifndef KEY_SCREENLOCK diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 54b85f5..adc3513 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -36,6 +36,7 @@ #include "shared/devices.h" #include "shared/device-notifier.h" #include "shared/common.h" +#include "shared/apps.h" #include "core/udev.h" #include "shared/eventsystem.h" #include "shared/plugin.h" @@ -44,7 +45,6 @@ #include "display/display-ops.h" #include "power/power.h" #include "power/power-off.h" -#include "apps/apps.h" #include "power-supply.h" #define BATTERY_UNKNOWN -1 diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index f5c57c4..dea6007 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -34,9 +34,9 @@ #include "display/setting.h" #include "shared/eventsystem.h" #include "shared/plugin.h" +#include "shared/apps.h" #include "display/core.h" #include "display/display-ops.h" -#include "apps/apps.h" #include "power-supply.h" #include "battery.h" #include "battery-ops.h" diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index a6a5909..9b73ba9 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -36,7 +36,7 @@ #include "shared/common.h" #include "shared/devices.h" #include "shared/device-notifier.h" -#include "apps/apps.h" +#include "shared/apps.h" #include "dd-display.h" #include "display-actor.h" #include "display-ops.h" diff --git a/src/display/display-lock.c b/src/display/display-lock.c index 9fb232f..b866a66 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -29,7 +29,7 @@ #include "lock-detector.h" #include "display-lock.h" #include "shared/log-macro.h" -#include "apps/apps.h" +#include "shared/apps.h" #define METHOD_APP_STATUS "CheckAppStatus" #define PID_MAX 6 diff --git a/src/power/power-off.c b/src/power/power-off.c index b7bb97c..89f9b19 100644 --- a/src/power/power-off.c +++ b/src/power/power-off.c @@ -49,7 +49,6 @@ #include "display/display-ops.h" #include "power-off.h" #include "power.h" -#include "apps/apps.h" #include "power-boot.h" #include "shared/plugin.h" diff --git a/src/apps/apps.c b/src/shared/apps.c similarity index 99% rename from src/apps/apps.c rename to src/shared/apps.c index dc20230..10e53a0 100644 --- a/src/apps/apps.c +++ b/src/shared/apps.c @@ -17,6 +17,8 @@ */ #include +#include + #include "core/log.h" #include "shared/common.h" #include "apps.h" diff --git a/src/apps/apps.h b/src/shared/apps.h similarity index 100% rename from src/apps/apps.h rename to src/shared/apps.h diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index 6eee263..386d96b 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -23,7 +23,7 @@ #include #include -#include "apps/apps.h" +#include "shared/apps.h" #include "shared/devices.h" #include "core/log.h" #include "shared/device-notifier.h" diff --git a/src/usb-gadget/usb-state.c b/src/usb-gadget/usb-state.c index a3e766d..8d7a4cc 100644 --- a/src/usb-gadget/usb-state.c +++ b/src/usb-gadget/usb-state.c @@ -23,7 +23,7 @@ #include #include "core/log.h" -#include "apps/apps.h" +#include "shared/apps.h" #include "extcon/extcon.h" #include "usb-gadget.h" diff --git a/src/usb-host/usb-host.c b/src/usb-host/usb-host.c index 9155fb5..3dc6d78 100644 --- a/src/usb-host/usb-host.c +++ b/src/usb-host/usb-host.c @@ -28,8 +28,8 @@ #include "core/log.h" #include "shared/devices.h" #include "shared/device-notifier.h" +#include "shared/apps.h" #include "core/udev.h" -#include "apps/apps.h" #include "extcon/extcon.h" #include "display/display-ops.h" #include "display/core.h" -- 2.7.4 From f00cae981ffcd8628652241973c6bf9775306607 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 20 Jun 2022 16:57:46 +0900 Subject: [PATCH 05/16] power: change state only when it is explicitly specified It might not to change state if there is no defined ActionChangeState. Change-Id: I16f6bd7992722787d2a95cc38c6764db81b67238 Signed-off-by: Youngjae Cho --- conf/init.conf | 6 ++++++ src/power/power-boot.c | 15 ++++++++++----- src/power/power-boot.h | 2 +- src/power/power.c | 13 ++++++++++--- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/conf/init.conf b/conf/init.conf index 22c910d..3b19f18 100644 --- a/conf/init.conf +++ b/conf/init.conf @@ -9,3 +9,9 @@ ActionChangeState=start,normal Enum=3001 BootReason=charger ActionChangeState=start,sleep + +[EventAction] +#INITIAL_STATE_BY_SILENT_REBOOT +#Do no action. Stay in POWER_STATE_START on booting. +Enum=3002 +BootReason=reboot diff --git a/src/power/power-boot.c b/src/power/power-boot.c index 9926b68..ff6ba8a 100644 --- a/src/power/power-boot.c +++ b/src/power/power-boot.c @@ -43,8 +43,8 @@ static struct trans_info init_ti = { .reason = -1, - .curr = POWER_STATE_START, - .next = POWER_STATE_NORMAL, + .curr = 0, + .next = 0, }; static guint sig_id[2] = {0, 0}; @@ -160,15 +160,20 @@ static int parse_matching_bootreason(const struct parse_result *result, void *da return 0; } -void do_initial_transition_by_bootreason(void) +void initial_transition_by_bootreason(void) { int retval; char bootreason[64] = "Unknown"; retval = hal_device_board_get_boot_reason(bootreason, sizeof(bootreason)); - if (retval == 0) - libsys_config_parse_by_section(INIT_CONF_PATH, parse_matching_bootreason, bootreason); + if (retval != 0) { + _I("Failed to get BootReason, %d. Default change state to normal.", retval); + power_request_change_state_strict(POWER_STATE_START, POWER_STATE_NORMAL, 1, NULL); + return; + } CRITICAL_LOG("BootReason=%s", bootreason); + libsys_config_parse_by_section(INIT_CONF_PATH, parse_matching_bootreason, bootreason); + power_request_change_state_strict(init_ti.curr, init_ti.next, init_ti.reason, NULL); } diff --git a/src/power/power-boot.h b/src/power/power-boot.h index c0fcda6..cdabd28 100644 --- a/src/power/power-boot.h +++ b/src/power/power-boot.h @@ -21,7 +21,7 @@ void add_delayed_init_done_handler(void *data); void remove_delayed_init_done_handler(void *data); -void do_initial_transition_by_bootreason(void); +void initial_transition_by_bootreason(void); extern int silent_boot; diff --git a/src/power/power.c b/src/power/power.c index 793a4a0..43cd084 100644 --- a/src/power/power.c +++ b/src/power/power.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -245,6 +246,12 @@ static int power_transition_state(void *data) if (!ti) return 0; + // check invalid next state + if (__builtin_popcountll(ti->next & POWER_STATE_ALL) != 1) { + _E("Invalid next state, curr=%"PRIx64", next=%"PRIx64", reason=%d", ti->curr, ti->next, ti->reason); + return 0; + } + // defer state transition until delayed_init_done unless it is transition to poweroff. // poweroff shall be handled immediately regardless of the delayed_init_done. if (!delayed_init_done && !is_poweroff_state(ti->next)) { @@ -303,9 +310,9 @@ void power_state_init(void *data) /* Take the first transition. * * It is determined by bootreason to which state to transition, POWER_STATE_NORMAL or POWER_STATE_SLEEP. - * Normally, it will be transitioned to the POWER_STATE_NORMAL unless there is configuration for - * the initial state in init.conf. */ - do_initial_transition_by_bootreason(); + * Or it may stay in POWER_STATE_START if there is no defined action for the matching bootreason. + */ + initial_transition_by_bootreason(); } static const struct device_ops power_state_device_ops = { -- 2.7.4 From 1d948c306f45c6a37490574418fdfa0c5c7fcd4e Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 24 Jun 2022 10:05:40 +0900 Subject: [PATCH 06/16] extcon: remove unused extcon count Change-Id: I8d666e031338dd05db478b033ecf757a23971785 Signed-off-by: Youngjae Cho --- src/battery/power-supply.c | 41 ----------------------------------------- src/extcon/earjack.c | 2 -- src/extcon/extcon-count.h | 36 ------------------------------------ src/extcon/extcon.c | 9 --------- src/extcon/extcon.h | 2 -- src/shared/device-notifier.c | 1 - src/shared/device-notifier.h | 1 - 7 files changed, 92 deletions(-) delete mode 100644 src/extcon/extcon-count.h diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index dea6007..672410e 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -655,45 +655,6 @@ static void check_temperature_status(const char *env_value) battery.temperature = atoi(env_value) / 10; } -static void update_capacity_full(void) -{ - static int old; - int delta; - - if (battery.charger_connected == 0 || - old == 0 || - old >= battery.capacity) { - old = battery.capacity; - return; - } - delta = battery.capacity - old; - old = battery.capacity; - extcon_update_count(EXTCON_BATTERY_FULL, delta); -} - -static void update_battery_cycle(void) -{ - static int first = 1; - static int old; - int delta; - - if (first) { - first = 0; - extcon_update_count(EXTCON_BATTERY_CYCLE, 0); - return; - } - - if (battery.charger_connected == 1 || - old == 0 || - old <= battery.capacity) { - old = battery.capacity; - return; - } - delta = old - battery.capacity; - old = battery.capacity; - extcon_update_count(EXTCON_BATTERY_CYCLE, delta); -} - static void process_power_supply(void *data) { bool broadcasted = true; @@ -809,8 +770,6 @@ static void process_power_supply(void *data) device_notify(DEVICE_NOTIFIER_BATTERY_CHARGING, &battery.charge_now); old_battery.charge_now = battery.charge_now; } - update_capacity_full(); - update_battery_cycle(); if (disp_plgn->pm_unlock_internal) { if (ret_lock == 0) { diff --git a/src/extcon/earjack.c b/src/extcon/earjack.c index adce493..bc154cb 100644 --- a/src/extcon/earjack.c +++ b/src/extcon/earjack.c @@ -81,8 +81,6 @@ static int earjack_update(const char *index, int status) if (status != EARJACK_DICONNECTED) { if (disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_EARJACK, LCD_NORMAL); - - extcon_update_count(EXTCON_EARJACK, 1); } return 0; diff --git a/src/extcon/extcon-count.h b/src/extcon/extcon-count.h deleted file mode 100644 index 74d28d1..0000000 --- a/src/extcon/extcon-count.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2019 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __EXTCON_COUNT_H__ -#define __EXTCON_COUNT_H__ - -#include "shared/common.h" - -typedef enum { - EXTCON_TA = 0, - EXTCON_EARJACK, - EXTCON_BATTERY_FULL, - EXTCON_BATTERY_CYCLE, -} extcon_index_type_e; - -struct extcon_notifier { - extcon_index_type_e index; - unsigned long count; -}; - -#endif /* __EXTCON_COUNT_H__ */ diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index 5e163de..2da37b4 100644 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -86,15 +86,6 @@ int extcon_get_status(const char *name) return dev->status; } -void extcon_update_count(extcon_index_type_e index, unsigned long count) -{ - struct extcon_notifier extcon; - extcon.index = index; - extcon.count = count; - - device_notify(DEVICE_NOTIFIER_EXTCON_COUNT, (void *)&extcon); -} - static int extcon_update(const char *name, const char *index, const char *value) { struct extcon_ops *dev; diff --git a/src/extcon/extcon.h b/src/extcon/extcon.h index 4747d0c..77247b0 100644 --- a/src/extcon/extcon.h +++ b/src/extcon/extcon.h @@ -23,7 +23,6 @@ #include "shared/common.h" #include #include -#include "extcon-count.h" /** * Extcon cable name is shared with kernel extcon class. @@ -94,5 +93,4 @@ void remove_extcon(struct extcon_ops *dev); int extcon_get_status(const char *name); int extcon_enable_device(const char *name); int extcon_disable_device(const char *name); -void extcon_update_count(extcon_index_type_e index, unsigned long count); #endif /* __EXTCON_H__ */ diff --git a/src/shared/device-notifier.c b/src/shared/device-notifier.c index 61cd1c2..e2ea3c1 100644 --- a/src/shared/device-notifier.c +++ b/src/shared/device-notifier.c @@ -90,7 +90,6 @@ static const char *device_notifier_type_str[DEVICE_NOTIFIER_MAX] = { NOTIFY_STR(DEVICE_NOTIFIER_BEZEL_WAKEUP), NOTIFY_STR(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS), NOTIFY_STR(DEVICE_NOTIFIER_ULTRAPOWERSAVING), - NOTIFY_STR(DEVICE_NOTIFIER_EXTCON_COUNT), NOTIFY_STR(DEVICE_NOTIFIER_KEY_PRESS), NOTIFY_STR(DEVICE_NOTIFIER_KEY_RELEASE), NOTIFY_STR(DEVICE_NOTIFIER_EVENT_ACQUIRE_WAKELOCK), diff --git a/src/shared/device-notifier.h b/src/shared/device-notifier.h index bd1880a..2dabc45 100644 --- a/src/shared/device-notifier.h +++ b/src/shared/device-notifier.h @@ -63,7 +63,6 @@ enum device_notifier_type { DEVICE_NOTIFIER_BEZEL_WAKEUP, DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, DEVICE_NOTIFIER_ULTRAPOWERSAVING, - DEVICE_NOTIFIER_EXTCON_COUNT, DEVICE_NOTIFIER_KEY_PRESS, DEVICE_NOTIFIER_KEY_RELEASE, DEVICE_NOTIFIER_EVENT_ACQUIRE_WAKELOCK, -- 2.7.4 From 9e0a1836a61abc424aa6b4f62889e7e97b070478 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 24 Jun 2022 16:54:05 +0900 Subject: [PATCH 07/16] battery: remove unnecessary probe for power-supply It is naturally done by the power-supply module itself. Therefore it is unnecessary for lowbat module to probe power-supply. Change-Id: Id18bcea6a1bd9a0aae87c5f6a54815dc74b814b6 Signed-off-by: Youngjae Cho --- src/battery/lowbat-handler.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index adc3513..050defe 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -698,19 +698,6 @@ static const dbus_interface_u dbus_interface = { .nr_methods = ARRAY_SIZE(dbus_methods), }; -static int lowbat_probe(void *data) -{ - static const struct device_ops *ops; - int ret = -EINVAL; - - FIND_DEVICE_INT(ops, "power_supply"); - ret = ops->probe(data); - if (ret == 0) - _I("Support lowbat handler."); - - return ret; -} - static void lowbat_init(void *data) { int ret; @@ -784,7 +771,6 @@ void lowbat_disable_uevent_buffering(void) static const struct device_ops lowbat_device_ops = { DECLARE_NAME_LEN("lowbat"), - .probe = lowbat_probe, .init = lowbat_init, .execute = lowbat_execute, .exit = lowbat_exit, -- 2.7.4 From 4409ab4c7e4eff479e69791b7fdfc2962825ef13 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 30 Jun 2022 10:29:45 +0900 Subject: [PATCH 08/16] battery: broadcast signal on charger connected/disconnected Change-Id: Iaef820f91138eddead997f1a3c250d745d8ceb28 Signed-off-by: Youngjae Cho --- plugins/iot-headless/battery/battery-plugin.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/iot-headless/battery/battery-plugin.c b/plugins/iot-headless/battery/battery-plugin.c index 2c03708..1c1d2d2 100644 --- a/plugins/iot-headless/battery/battery-plugin.c +++ b/plugins/iot-headless/battery/battery-plugin.c @@ -140,6 +140,9 @@ static int charger_connected_callback(void *data) if (handler_connected->wakelock_duration) event_acquire_wakelock(handler_connected->id, handler_connected->wakelock_duration); + if (handler_connected->broadcast) + event_broadcast_id(handler_connected->id); + if (handler_connected->action) device_notify(handler_connected->action, handler_connected->user_data); @@ -153,6 +156,9 @@ static int charger_disconnected_callback(void *data) if (handler_disconnected->wakelock_duration) event_acquire_wakelock(handler_disconnected->id, handler_disconnected->wakelock_duration); + if (handler_disconnected->broadcast) + event_broadcast_id(handler_disconnected->id); + if (handler_disconnected->action) device_notify(handler_disconnected->action, handler_disconnected->user_data); -- 2.7.4 From d2837e1a685882c5b993946c43caa6d4d80d7859 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 30 Jun 2022 10:46:34 +0900 Subject: [PATCH 09/16] Remove installation of not existing file The iot-headless-power.so had been removed. Change-Id: I4d45191e70e354934b5991a7f601afdd79e5ae17 Signed-off-by: Youngjae Cho --- packaging/deviced.spec | 1 - 1 file changed, 1 deletion(-) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 326d3fd..caa06af 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -257,7 +257,6 @@ mv %{_sysconfdir}/deviced/input-profile-iot-headless.conf %{_sysconfdir}/deviced mv %{_sysconfdir}/deviced/power-profile-iot-headless.conf %{_sysconfdir}/deviced/power.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/iot-headless-input-handler.so %{_libdir}/deviced/input-handler.so -mv %{_libdir}/iot-headless-power.so %{_libdir}/deviced/power.so mv %{_libdir}/iot-headless-battery.so %{_libdir}/deviced/battery.so %files -- 2.7.4 From c7edc7c1ba83a25a5f019c8768a80116c04bdb24 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 7 Jul 2022 18:18:59 +0900 Subject: [PATCH 10/16] init: define state transition for bootreason=reboot Change-Id: I5cf8b2a27688a3fd0c0c550555673e99abcd4495 Signed-off-by: Youngjae Cho --- conf/init.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/init.conf b/conf/init.conf index 3b19f18..ee77c26 100644 --- a/conf/init.conf +++ b/conf/init.conf @@ -11,7 +11,7 @@ BootReason=charger ActionChangeState=start,sleep [EventAction] -#INITIAL_STATE_BY_SILENT_REBOOT -#Do no action. Stay in POWER_STATE_START on booting. +#INITIAL_STATE_BY_REBOOT Enum=3002 BootReason=reboot +ActionChangeState=start,normal -- 2.7.4 From edbec70fd91d06c4f506d6bb83bd48361212d0ea Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 17 Jun 2022 09:12:24 +0900 Subject: [PATCH 11/16] battery: remove unreachable code The fallback for not existing battery hal is technically useless. It is because if there is no battery backend, the battery module itself won't be work properly as it cannot know about target dependent properties. Change-Id: Iaea07a1ecd47fdf14b13ca9e07d42a28c07357a0 Signed-off-by: Youngjae Cho --- src/battery/battery-time.c | 1 - src/battery/lowbat-handler.c | 1 - src/battery/power-supply.c | 135 ++----------------------------------------- 3 files changed, 5 insertions(+), 132 deletions(-) diff --git a/src/battery/battery-time.c b/src/battery/battery-time.c index 146a503..39259a4 100644 --- a/src/battery/battery-time.c +++ b/src/battery/battery-time.c @@ -27,7 +27,6 @@ #include "shared/common.h" #include "shared/devices.h" #include "core/log.h" -#include "core/udev.h" #include "display/display-ops.h" #include "power-supply.h" #include "shared/plugin.h" diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 050defe..ecf3430 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -37,7 +37,6 @@ #include "shared/device-notifier.h" #include "shared/common.h" #include "shared/apps.h" -#include "core/udev.h" #include "shared/eventsystem.h" #include "shared/plugin.h" #include "display/setting.h" diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 672410e..ce4e7fc 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -86,12 +86,6 @@ static struct display_plugin *disp_plgn; static struct battery_plugin *battery_plgn; -static void uevent_power_handler(struct udev_device *dev); -static const struct uevent_handler uh = { - .subsystem = POWER_SUBSYSTEM, - .uevent_func = uevent_power_handler, -}; - static struct battery_status battery; struct battery_status old_battery; static int noti_id; @@ -107,7 +101,6 @@ bool battery_do_not_disturb(void); int battery_pm_change_internal(int pid, int s_bits); static int delayed_init_done(void *data); static void update_health(enum battery_noti_status status); -static bool battery_dev_available = false; static int load_uevent(struct parse_result *result, void *user_data); static int event_handler_state_changed(void *data); static void power_supply_exit(void *data); @@ -625,36 +618,6 @@ static void check_misc_status(const char *env_value) battery.misc = atoi(env_value); } -static void check_online_type(const char *env_value) -{ - if (env_value == NULL) - return; - battery.charger_connected = atoi(env_value); -} - -static void check_present_status(const char *env_value) -{ - if (env_value == NULL) { - battery.present = PRESENT_NORMAL; - return; - } - battery.present = atoi(env_value); -} - -static void check_capacity_status(const char *env_value) -{ - if (env_value == NULL) - return; - battery.capacity = atoi(env_value); -} - -static void check_temperature_status(const char *env_value) -{ - if (env_value == NULL) - return; - battery.temperature = atoi(env_value) / 10; -} - static void process_power_supply(void *data) { bool broadcasted = true; @@ -778,70 +741,6 @@ static void process_power_supply(void *data) } } -static void uevent_power_handler(struct udev_device *dev) -{ - struct udev_list_entry *list_entry; - const char *env_name; - const char *env_value; - bool matched = false; - int ret_val; - - udev_list_entry_foreach(list_entry, - udev_device_get_properties_list_entry(dev)) { - env_name = udev_list_entry_get_name(list_entry); - if (!env_name) - continue; - - if (!strncmp(env_name, CHARGE_NAME, sizeof(CHARGE_NAME))) { - env_value = udev_list_entry_get_value(list_entry); - if (!env_value) - continue; - if (!strncmp(env_value, BATTERY_NAME, - sizeof(BATTERY_NAME))) { - matched = true; - break; - } - } - } - - if (!matched) - return; - - env_value = udev_device_get_property_value(dev, CHARGE_STATUS); - check_charging_status(env_value); - env_value = udev_device_get_property_value(dev, CHARGE_ONLINE); - check_online_type(env_value); - env_value = udev_device_get_property_value(dev, CHARGE_HEALTH); - check_health_status(env_value); - env_value = udev_device_get_property_value(dev, CHARGE_MISC_EVENT); - check_misc_status(env_value); - env_value = udev_device_get_property_value(dev, CHARGE_PRESENT); - check_present_status(env_value); - env_value = udev_device_get_property_value(dev, CAPACITY); - check_capacity_status(env_value); - env_value = udev_device_get_property_value(dev, TEMPERATURE); - check_temperature_status(env_value); - - /* The uevent property or HAL API for charger_type is not supported. Therefore, - * use pseudo value for the online_type according to charger connectivity. */ - if (battery.charger_connected == 0) - battery.online_type = CHARGER_TYPE_NONE; - else if (battery.charger_connected == 1) - battery.online_type = CHARGER_TYPE_USB; - - battery_initialized = true; - - ret_val = delayed_init_done(NULL); - if (ret_val) { - if (battery.charger_connected == 1) - power_supply_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_ON); - else - power_supply_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_OFF); - } - - process_power_supply(&battery.capacity); -} - static int battery_state(struct battery_info *info) { static struct battery_status prev_status; @@ -985,9 +884,6 @@ static gboolean power_supply_update_during_booting(void *data) { int retval; - if (!battery_dev_available) - return G_SOURCE_REMOVE; - retval = hal_device_battery_get_current_state(battery_changed, NULL); if (retval == -ENODEV) { CRITICAL_LOG_E("There is no battery detected. Disable the battery module."); @@ -1199,8 +1095,7 @@ static GVariant *dbus_power_supply_handler(GDBusConnection *conn, _D("C(%d) S(%s) H(%s) O(%d) P(%d) SRC(%s) Vol(%d %d) Cur(%d %d) T(%d)", info.capacity, info.status, info.health, info.online, info.present, info.power_source, info.voltage_now, info.voltage_average, info.current_now, info.current_average, info.temperature); - if (battery_dev_available) - battery_changed(&info, NULL); + battery_changed(&info, NULL); out: g_free(type_str); @@ -1259,7 +1154,7 @@ static GVariant *dbus_get_battery_info(GDBusConnection *conn, goto out; ret = hal_device_battery_get_current_state(battery_get_info, &info); - if (battery_dev_available && (ret != -ENODEV)) { + if (ret != -ENODEV) { if (ret < 0) _E("Failed to get battery info: %d", ret); @@ -1467,13 +1362,9 @@ static int power_supply_probe(void *data) int ret_val, r; - if (battery_dev_available) - return 0; - ret_val = hal_device_battery_get_backend(); if (ret_val < 0) { _E("There is no HAL for battery."); - battery_dev_available = false; if (access(POWER_PATH, R_OK) == 0) return 0; /* Just power_supply uevent is used */ @@ -1481,7 +1372,6 @@ static int power_supply_probe(void *data) } _I("Battery device structure load success."); - battery_dev_available = true; return 0; out: @@ -1504,27 +1394,13 @@ out: static void add_power_supply_handler(void) { - int ret_val; - - if (battery_dev_available) { - hal_device_battery_register_changed_event(battery_changed, NULL); - hal_device_battery_get_current_state(battery_changed, NULL); - } else { - ret_val = config_parse(POWER_SUPPLY_UEVENT, load_uevent, &battery); - if (ret_val < 0) - _E("Failed to load %s, %d Use default value!", POWER_SUPPLY_UEVENT, ret_val); - - /* register power subsystem */ - register_kernel_uevent_control(&uh); - } + hal_device_battery_register_changed_event(battery_changed, NULL); + hal_device_battery_get_current_state(battery_changed, NULL); } static void remove_power_supply_handler(void) { - if (battery_dev_available) - hal_device_battery_unregister_changed_event(battery_changed); - else - unregister_kernel_uevent_control(&uh); + hal_device_battery_unregister_changed_event(battery_changed); } static int event_handler_state_changed(void *data) @@ -1579,7 +1455,6 @@ static void power_supply_exit(void *data) event_handler_state_changed((void *)&state); battery_ops_exit(NULL); - battery_dev_available = false; } static const struct device_ops power_supply_ops = { -- 2.7.4 From c55dd602a7f055333c4d42ab5c0af7ad53524cbf Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 12 Jul 2022 15:16:53 +0900 Subject: [PATCH 12/16] device-notifier: find existing notifier only It only finds a notifier that has not been deleted. Change-Id: Ica945fb57cfe09cf4c82c94e07558abe23704b32 Signed-off-by: Youngjae Cho --- src/shared/device-notifier.c | 2 +- .../test-device-notifier.c | 23 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/shared/device-notifier.c b/src/shared/device-notifier.c index e2ea3c1..e9190d6 100644 --- a/src/shared/device-notifier.c +++ b/src/shared/device-notifier.c @@ -45,7 +45,7 @@ static guint idl; #define FIND_NOTIFIER(a, b, d, e, f) \ SYS_G_LIST_FOREACH(a, b, d) \ - if (e == d->e && f == (d->f)) + if (e == d->e && f == (d->f) && !d->deleted) #define NOTIFY_STR(x) [(x)] = __stringify((x)) diff --git a/tests/deviced-common-private-test/test-device-notifier.c b/tests/deviced-common-private-test/test-device-notifier.c index d049317..050e814 100644 --- a/tests/deviced-common-private-test/test-device-notifier.c +++ b/tests/deviced-common-private-test/test-device-notifier.c @@ -184,6 +184,28 @@ static void test_destroy_callback_p2(void **state) device_notify_once(DEVICE_NOTIFIER_LOWBAT, (void *)(intptr_t) 0x9a9a9a9a); } +static void test_destroy_callback_p3(void **state) +{ + int retval; + + retval = register_notifier(DEVICE_NOTIFIER_UPSM, notify_callback); + assert_int_equal(retval, 0); + expect_value(notify_callback, data, (void *)(intptr_t) 0x3f3f3f3f); + device_notify(DEVICE_NOTIFIER_UPSM, (void *)(intptr_t) 0x3f3f3f3f); + + /* notify_callback() should not be invoked */ + unregister_notifier(DEVICE_NOTIFIER_UPSM, notify_callback); + device_notify(DEVICE_NOTIFIER_UPSM, (void *)(intptr_t) 0x34ab34ab); + + /* if a notifier have successfully been deleted, + * re-registering the notifier must be successful */ + retval = register_notifier(DEVICE_NOTIFIER_UPSM, notify_callback); + assert_int_equal(retval, 0); + + expect_value(notify_callback, data, (void *)(intptr_t) 0x7878444); + device_notify(DEVICE_NOTIFIER_UPSM, (void *)(intptr_t) 0x7878444); +} + static void test_device_notify_priority_p1(void **state) { int id1, id2, id3; @@ -223,6 +245,7 @@ static int run_device_notifier_test(void) cmocka_unit_test(test_device_notify_once_p), cmocka_unit_test(test_destroy_callback_p1), cmocka_unit_test(test_destroy_callback_p2), + cmocka_unit_test(test_destroy_callback_p3), cmocka_unit_test(test_device_notify_priority_p1), }; -- 2.7.4 From b2544937b9f2faaa792412e3cac621e24d45e311 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 12 Jul 2022 10:10:23 +0900 Subject: [PATCH 13/16] power: add getter for power state Change-Id: I792f01d67adeba213f84003fea4fc506f4f04ad9 Signed-off-by: Youngjae Cho --- src/power/power-dbus.c | 8 ++++++++ src/power/power.c | 5 +++++ src/power/power.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/src/power/power-dbus.c b/src/power/power-dbus.c index 61c7922..a0c6cfa 100644 --- a/src/power/power-dbus.c +++ b/src/power/power-dbus.c @@ -327,6 +327,13 @@ out: return g_variant_new("(i)", ret); } +static GVariant *dbus_power_get_state(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + return g_variant_new("(t)", power_get_state()); +} + static const dbus_method_s dbus_methods[] = { { "LockCpu", "i", "i", dbus_power_lock_cpu }, { "UnlockCpu", NULL, "i", dbus_power_unlock_cpu }, @@ -334,6 +341,7 @@ static const dbus_method_s dbus_methods[] = { { "RemoveChangeStateWait", "t", NULL, dbus_power_remove_change_state_wait }, { "ConfirmChangeStateWait", "t", "i", dbus_power_confirm_change_state_wait }, { "PowerChangeState", "t", "i", dbus_power_change_state }, + { "PowerGetState", NULL, "t", dbus_power_get_state }, /* Add methods here */ }; diff --git a/src/power/power.c b/src/power/power.c index 43cd084..01ee2df 100644 --- a/src/power/power.c +++ b/src/power/power.c @@ -47,6 +47,11 @@ static GList *deferred_transition_list; static int power_transition_state(void *data); +uint64_t power_get_state(void) +{ + return current; +} + static void power_wake_unlock(void *udata) { /* for POWER_STATE_NORMAL, POWER_STATE_POWEROFF, do not wake unlock */ diff --git a/src/power/power.h b/src/power/power.h index 366b8a4..7ce29b2 100644 --- a/src/power/power.h +++ b/src/power/power.h @@ -98,4 +98,6 @@ static inline void power_request_change_state(uint64_t next, int reason) power_request_change_state_strict(POWER_STATE_ALL, next, reason, NULL); } +uint64_t power_get_state(void); + #endif //__POWER_STATE_MANAGER_H__ -- 2.7.4 From 5c60c91dbb653781ba533338b89c83976c024d3f Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 25 Jul 2022 13:50:00 +0900 Subject: [PATCH 14/16] battery: redefine battery level threshold The realoff threshold has been removed and the poweroff level takes over the role of realoff level. Change-Id: I887c3a49cd6d251e3c2837b6a123a6d0b190c708 Signed-off-by: Youngjae Cho --- conf/battery.conf | 3 --- src/battery/battery.h | 1 - src/battery/config.c | 3 --- src/battery/config.h | 1 - src/battery/lowbat-handler.c | 46 +++++++++++++++----------------------------- src/battery/power-supply.c | 14 ++++++++------ tests/auto-test/battery.c | 6 ------ 7 files changed, 23 insertions(+), 51 deletions(-) diff --git a/conf/battery.conf b/conf/battery.conf index d854e14..8b65792 100644 --- a/conf/battery.conf +++ b/conf/battery.conf @@ -3,9 +3,6 @@ Normal=100 Warning=15 Critical=5 PowerOff=1 -RealOff=0 -WarningMethod=warning -CriticalMethod=critical # hold wakelock if a charger has been connected, iot-headless only [ChargerWakelock] diff --git a/src/battery/battery.h b/src/battery/battery.h index 51c73a3..0aa7b8d 100644 --- a/src/battery/battery.h +++ b/src/battery/battery.h @@ -41,7 +41,6 @@ struct battery_config_info { int warning; int critical; int poweroff; - int realoff; }; int battery_charge_err_low_act(void *data); diff --git a/src/battery/config.c b/src/battery/config.c index 1595040..54e3da5 100644 --- a/src/battery/config.c +++ b/src/battery/config.c @@ -58,8 +58,6 @@ static int load_config(struct parse_result *result, void *user_data) info->critical = atoi(value); else if (MATCH(name, "PowerOff")) info->poweroff = atoi(value); - else if (MATCH(name, "RealOff")) - info->realoff = atoi(value); return 0; } @@ -78,6 +76,5 @@ void battery_config_load(struct battery_config_info *info) info->warning = -1; info->critical = -2; info->poweroff = -3; - info->realoff = -4; } } diff --git a/src/battery/config.h b/src/battery/config.h index 77ca856..0e0fa52 100644 --- a/src/battery/config.h +++ b/src/battery/config.h @@ -25,7 +25,6 @@ #define BATTERY_WARNING 15 #define BATTERY_CRITICAL 5 #define BATTERY_POWEROFF 1 -#define BATTERY_REALOFF 0 void battery_config_load(struct battery_config_info *info); #endif /* __BATTERY_CONFIG_H__ */ diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index ecf3430..e3844b4 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -81,7 +81,6 @@ struct battery_config_info battery_info = { .warning = BATTERY_WARNING, .critical = BATTERY_CRITICAL, .poweroff = BATTERY_POWEROFF, - .realoff = BATTERY_REALOFF, }; static GList *lpe; @@ -291,7 +290,7 @@ static int battery_critical_low_act(void *data) return 0; } -int battery_power_off_act(void *data) +static int battery_power_off_act(void *data) { CRITICAL_LOG("Low battery power off."); return power_execute(POWER_STATE_POWEROFF); @@ -329,17 +328,12 @@ static void lowbat_scenario_init(void) lowbat_add_scenario(battery_info.normal, battery_info.warning, battery_warning_low_act); lowbat_add_scenario(battery_info.normal, battery_info.critical, battery_critical_low_act); - lowbat_add_scenario(battery_info.normal, battery_info.poweroff, battery_critical_low_act); - lowbat_add_scenario(battery_info.normal, battery_info.realoff, battery_power_off_act); + lowbat_add_scenario(battery_info.normal, battery_info.poweroff, battery_power_off_act); lowbat_add_scenario(battery_info.warning, battery_info.warning, battery_warning_low_act); lowbat_add_scenario(battery_info.warning, battery_info.critical, battery_critical_low_act); - lowbat_add_scenario(battery_info.warning, battery_info.poweroff, battery_critical_low_act); - lowbat_add_scenario(battery_info.warning, battery_info.realoff, battery_power_off_act); + lowbat_add_scenario(battery_info.warning, battery_info.poweroff, battery_power_off_act); lowbat_add_scenario(battery_info.critical, battery_info.critical, battery_critical_low_act); - lowbat_add_scenario(battery_info.critical, battery_info.realoff, battery_power_off_act); - lowbat_add_scenario(battery_info.poweroff, battery_info.poweroff, battery_critical_low_act); - lowbat_add_scenario(battery_info.poweroff, battery_info.realoff, battery_power_off_act); - lowbat_add_scenario(battery_info.realoff, battery_info.realoff, battery_power_off_act); + lowbat_add_scenario(battery_info.poweroff, battery_info.poweroff, battery_power_off_act); } static void battery_level_send_system_event(int bat_percent) @@ -495,17 +489,7 @@ static int lowbat_process(int bat_percent, void *ad) return -EIO; } - if (new_bat_capacity <= battery_info.realoff) { - if (battery->charge_now == CHARGER_CHARGING) { - new_bat_state = battery_info.poweroff; - if (vconf_state != VCONFKEY_SYSMAN_BAT_POWER_OFF) - status = VCONFKEY_SYSMAN_BAT_POWER_OFF; - } else { - new_bat_state = battery_info.realoff; - if (vconf_state != VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF) - status = VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF; - } - } else if (new_bat_capacity <= battery_info.poweroff) { + if (new_bat_capacity <= battery_info.poweroff) { new_bat_state = battery_info.poweroff; if (vconf_state != VCONFKEY_SYSMAN_BAT_POWER_OFF) status = VCONFKEY_SYSMAN_BAT_POWER_OFF; @@ -535,13 +519,10 @@ static int lowbat_process(int bat_percent, void *ad) /* If the battery continues to run out even though it is being charged * for a certain period of time, turn off the device. */ - if (new_bat_capacity <= battery_info.realoff && battery->charge_now == CHARGER_CHARGING) { + if (new_bat_capacity <= battery_info.poweroff && battery->charge_now == CHARGER_CHARGING) { if (low_bat_skip_cnt >= RETRY_MAX) { - new_bat_state = battery_info.realoff; - status = VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF; _I("Go to real poweroff inspite of charging (c:%d charge:%d online:%d current_now:%d)", battery->capacity, battery->charge_now, battery->charger_connected, battery->current_now); - low_bat_skip_cnt = 0; } else if (battery->current_now <= MIN_INOW_VALUE) { low_bat_skip_cnt++; } else { @@ -572,13 +553,16 @@ static int lowbat_process(int bat_percent, void *ad) return result; if (cur_bat_state == new_bat_state && online == battery->charger_connected) return result; + if (new_bat_state <= battery_info.poweroff && battery->charger_connected && low_bat_skip_cnt < RETRY_MAX) + return result; - online = battery->charger_connected; if (cur_bat_state == BATTERY_UNKNOWN) cur_bat_state = battery_info.normal; if (lowbat_scenario(cur_bat_state, new_bat_state, NULL)) _I("Cur(%d) new(%d) capacity(%d).", cur_bat_state, new_bat_state, bat_percent); - cur_bat_state = new_bat_state; + + online = battery->charger_connected; + cur_bat_state = new_bat_state; return result; } @@ -631,8 +615,8 @@ static int lowbat_monitor_init(void *data) /* load battery configuration file */ battery_config_load(&battery_info); - _I("Battery conf: %d %d %d %d %d", battery_info.normal, battery_info.warning, - battery_info.critical, battery_info.poweroff, battery_info.realoff); + _I("Battery conf: %d %d %d %d", battery_info.normal, battery_info.warning, + battery_info.critical, battery_info.poweroff); lowbat_scenario_init(); check_lowbat_percent(&battery->capacity); @@ -749,8 +733,8 @@ static int lowbat_execute(void *data) /* Do lowbat_process immediately rather deferring it when poweroff is needed. * This prevents poweroff from being delayed infinitely when the uevent continues - * to occur shorter than 1.5 seconds on realoff capacity */ - if (capacity <= battery_info.realoff || !uevent_buffering) + * to occur shorter than 1.5 seconds on poweroff capacity */ + if (capacity <= battery_info.poweroff || !uevent_buffering) low_battery_charging_status(data); else low_batt_sig_timer = g_timeout_add(1500, low_battery_charging_status, data); diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index ce4e7fc..197fabe 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -751,13 +751,15 @@ static int battery_state(struct battery_info *info) } if (battery.capacity != 0 && prev_status.capacity == battery.capacity && - prev_status.charging_status == battery.charging_status && + prev_status.charging_status == battery.charging_status && prev_status.online_type == battery.online_type && - prev_status.charge_full == battery.charge_full && - prev_status.charge_now == battery.charge_now && - prev_status.health == battery.health && - prev_status.present == battery.present && - prev_status.charger_connected == battery.charger_connected) + prev_status.charge_full == battery.charge_full && + prev_status.charge_now == battery.charge_now && + prev_status.health == battery.health && + prev_status.present == battery.present && + prev_status.current_now == battery.current_now && + prev_status.current_average == battery.current_average && + prev_status.charger_connected == battery.charger_connected) return 0; prev_status.capacity = battery.capacity; diff --git a/tests/auto-test/battery.c b/tests/auto-test/battery.c index b21e87d..6e98d98 100644 --- a/tests/auto-test/battery.c +++ b/tests/auto-test/battery.c @@ -89,7 +89,6 @@ #define DEFAULT_WARNING 15 #define DEFAULT_CRITICAL 5 #define DEFAULT_POWEROFF 1 -#define DEFAULT_REALOFF 0 //Charger Type #define CHARGER_WIRELESS_TYPE_BT 10 @@ -532,11 +531,6 @@ static bool compare_vconf(struct power_supply_type list) if (invalid) { temp = -ENODEV; - } else if (capacity <= DEFAULT_REALOFF) { - if (charging_status == CHARGING_STATUS_CHARGING) - temp = VCONFKEY_SYSMAN_BAT_POWER_OFF; - else - temp = VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF; } else if (capacity <= DEFAULT_POWEROFF) { temp = VCONFKEY_SYSMAN_BAT_POWER_OFF; } else if (capacity <= DEFAULT_CRITICAL) { -- 2.7.4 From 725423772178bdf93023807ec86a5d582364c499 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 1 Aug 2022 17:49:44 +0900 Subject: [PATCH 15/16] input: define all possible cases of longest powerkey Change-Id: I98f558f8878bcaa59b4d3d898bfd260143b2a56d Signed-off-by: Youngjae Cho --- conf/input-profile-iot-headless.conf | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/conf/input-profile-iot-headless.conf b/conf/input-profile-iot-headless.conf index 1e20825..5c71600 100644 --- a/conf/input-profile-iot-headless.conf +++ b/conf/input-profile-iot-headless.conf @@ -54,13 +54,24 @@ ActionBroadcast=yes WakeLockDurationSec=5 [EventAction] -Name=PWKEY_LONGEST_EDGE +Name=PWKEY_LONGEST_EDGE_WO_CHARGER Enum=1004 Keycode=power DetectionRangeMsec=7000,-1 TriggerType=edge ConditionVconf=memory/sysman/charger_status,int,0 ActionChangeState=normal,poweroff +ActionChangeState=sleep,normal + +[EventAction] +Name=PWKEY_LONGEST_EDGE_W_CHARGER +Enum=1004 +Keycode=power +DetectionRangeMsec=7000,-1 +TriggerType=edge +ConditionVconf=memory/sysman/charger_status,int,1 +ActionChangeState=normal,sleep +ActionChangeState=sleep,normal [EventAction] Name=BTKEY_SHORT_EDGE -- 2.7.4 From 06c5a75fd7728d32ccd884a6590cdb3195020fc4 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 3 Aug 2022 11:33:50 +0900 Subject: [PATCH 16/16] power: consider bootmode as well as bootreason Take consideration of bootmode as well as bootreason for the initial state transition. Change-Id: I2ba378cbf146215f315b4d413ec4fd4e470cafe1 Signed-off-by: Youngjae Cho --- conf/init.conf | 12 +++++++++++- src/power/power-boot.c | 31 ++++++++++++++++++++++--------- src/power/power-boot.h | 2 +- src/power/power.c | 7 ++++--- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/conf/init.conf b/conf/init.conf index ee77c26..504fec7 100644 --- a/conf/init.conf +++ b/conf/init.conf @@ -1,3 +1,6 @@ +# BootMode= is optional. If it isn't specified then +# it is regarded as BootMode=normal + [EventAction] #INITIAL_STATE_BY_POWERKEY_BOOTING Enum=3000 @@ -11,7 +14,14 @@ BootReason=charger ActionChangeState=start,sleep [EventAction] -#INITIAL_STATE_BY_REBOOT +#INITIAL_STATE_BY_REBOOT_NORMAL Enum=3002 BootReason=reboot ActionChangeState=start,normal + +[EventAction] +#INITIAL_STATE_BY_REBOOT_SILENT +Enum=3003 +BootReason=reboot +BootMode=silent +ActionChangeState=start,sleep diff --git a/src/power/power-boot.c b/src/power/power-boot.c index ff6ba8a..75ed8db 100644 --- a/src/power/power-boot.c +++ b/src/power/power-boot.c @@ -47,6 +47,11 @@ static struct trans_info init_ti = { .next = 0, }; +static struct boot_condition { + char reason[64]; + char mode[64]; +} bc = { "unknown", "normal" }; + static guint sig_id[2] = {0, 0}; void remove_delayed_init_done_handler(void *data) @@ -143,37 +148,45 @@ static void parse_init_ti(const struct parse_result *result) } } -static int parse_matching_bootreason(const struct parse_result *result, void *data) +static int parse_matching_boot_condition(const struct parse_result *result, void *data) { GList *elem; struct section_property *prop; - char *bootreason = (char *) data; + struct boot_condition config_bc = { "", "normal" }; if (!MATCH(result->section, "EventAction")) return 0; SYS_G_LIST_FOREACH(result->props, elem, prop) { - if (MATCH(prop->key, "BootReason") && MATCH(prop->value, bootreason)) - parse_init_ti(result); + if (MATCH(prop->key, "BootReason")) + sscanf(prop->value, "%s", config_bc.reason); + else if (MATCH(prop->key, "BootMode")) + sscanf(prop->value, "%s", config_bc.mode); } + if (MATCH(bc.reason, config_bc.reason) && MATCH(bc.mode, config_bc.mode)) + parse_init_ti(result); + return 0; } -void initial_transition_by_bootreason(void) +void initial_transition_by_boot_condition(void) { int retval; - char bootreason[64] = "Unknown"; - retval = hal_device_board_get_boot_reason(bootreason, sizeof(bootreason)); + retval = hal_device_board_get_boot_reason(bc.reason, sizeof(bc.reason)); if (retval != 0) { _I("Failed to get BootReason, %d. Default change state to normal.", retval); power_request_change_state_strict(POWER_STATE_START, POWER_STATE_NORMAL, 1, NULL); return; } - CRITICAL_LOG("BootReason=%s", bootreason); - libsys_config_parse_by_section(INIT_CONF_PATH, parse_matching_bootreason, bootreason); + retval = hal_device_board_get_boot_mode(bc.mode, sizeof(bc.mode)); + if (retval != 0) + _I("Failed to get BootMode, %d", retval); + + CRITICAL_LOG("BootReason=%s, BootMode=%s", bc.reason, bc.mode); + libsys_config_parse_by_section(INIT_CONF_PATH, parse_matching_boot_condition, NULL); power_request_change_state_strict(init_ti.curr, init_ti.next, init_ti.reason, NULL); } diff --git a/src/power/power-boot.h b/src/power/power-boot.h index cdabd28..d3057ef 100644 --- a/src/power/power-boot.h +++ b/src/power/power-boot.h @@ -21,7 +21,7 @@ void add_delayed_init_done_handler(void *data); void remove_delayed_init_done_handler(void *data); -void initial_transition_by_bootreason(void); +void initial_transition_by_boot_condition(void); extern int silent_boot; diff --git a/src/power/power.c b/src/power/power.c index 01ee2df..519a126 100644 --- a/src/power/power.c +++ b/src/power/power.c @@ -314,10 +314,11 @@ void power_state_init(void *data) /* Take the first transition. * - * It is determined by bootreason to which state to transition, POWER_STATE_NORMAL or POWER_STATE_SLEEP. - * Or it may stay in POWER_STATE_START if there is no defined action for the matching bootreason. + * It is determined by bootreason and bootmode to which state to transition, POWER_STATE_NORMAL + * or POWER_STATE_SLEEP. it may stay in POWER_STATE_START if there is no defined action for the + * matching bootreason and bootmode. */ - initial_transition_by_bootreason(); + initial_transition_by_boot_condition(); } static const struct device_ops power_state_device_ops = { -- 2.7.4