From 6acfb5be496be47651c378d8dcc3c1eba4810245 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 14 Jun 2022 10:35:50 +0900 Subject: [PATCH 01/16] power: reinforce log at PowerChangeState method Change-Id: I53db2b4855fc8fafb5ab4436d3d95d37e04bbf77 Signed-off-by: Youngjae Cho --- src/power/power-dbus.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/power/power-dbus.c b/src/power/power-dbus.c index 3f82a3a..61c7922 100644 --- a/src/power/power-dbus.c +++ b/src/power/power-dbus.c @@ -294,6 +294,8 @@ static GVariant *dbus_power_change_state(GDBusConnection *conn, int ret = 0; int index; guint64 next; + pid_t pid; + char comm[128] = "Unknown"; g_variant_get(param, "(t)", &next); @@ -307,6 +309,18 @@ static GVariant *dbus_power_change_state(GDBusConnection *conn, goto out; } + pid = gdbus_connection_get_sender_pid(conn, sender); + if (pid == -1 || kill(pid, 0) == -1) + goto out; + + get_command(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)); + else + _I("Pid=%d(%s) sent request for PowerChangeState to %s", pid, comm, state_name(next)); + + power_request_change_state_strict(POWER_STATE_ALL, next, 0, NULL); out: @@ -319,7 +333,7 @@ static const dbus_method_s dbus_methods[] = { { "AddChangeStateWait", "t", "i", dbus_power_add_change_state_wait }, { "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 }, + { "PowerChangeState", "t", "i", dbus_power_change_state }, /* Add methods here */ }; -- 2.7.4 From fa73bf6c049d7808c4eb0209b079acdbb0c86eca Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 13 Jun 2022 14:09:27 +0900 Subject: [PATCH 02/16] Change format of EventAction properties There were two types of Action= property, one is broadcasting and the other is changing state. Separate them to have different property name, Broadcast= and ChangeState=. - Action=broadcast -> ActionBroadcast=yes - Action=curr,next -> ActionChangeState=curr,next In addition to this, changed Duration= to clarify its meaning. - Duration -> DetectionRangeMsec This is intermediate patch. Therefore in this version, the property 'ActionBroadcast=yes' won't work properly. Change-Id: I00440c9bc30557812618b95f1a25663e9466158a Signed-off-by: Youngjae Cho --- conf/battery.conf | 11 +++++---- conf/init.conf | 4 ++-- conf/input-profile-iot-headless.conf | 30 +++++++++++------------ plugins/iot-headless/battery/battery-plugin.c | 7 +++++- plugins/iot-headless/input/input-config.c | 15 ++++++------ plugins/iot-headless/input/input-config.h | 3 +++ plugins/iot-headless/input/input-handler.c | 34 ++++++++------------------- src/power/power-boot.c | 2 +- src/shared/device-notifier.c | 4 ---- src/shared/device-notifier.h | 4 ---- 10 files changed, 50 insertions(+), 64 deletions(-) diff --git a/conf/battery.conf b/conf/battery.conf index 0fcb21c..d3c9c76 100644 --- a/conf/battery.conf +++ b/conf/battery.conf @@ -14,18 +14,19 @@ ChargerWakeLockEnabled=yes # define event-action, iot-headless only # DeviceNotifier= # - define which event(device-notifiy) is filtered -# Action= +# ChangeState= # - define action for the event +# ActionBroadcast=yes +# - broadcast upon occuring the event + [EventAction] Name=CHARGER_CONNECTED Enum=2001 DeviceNotifier=DEVICE_NOTIFIER_BATTERY_CHARGER_CONNECTED -Action=sleep,sleep -Action=normal,normal +ActionBroadcast=yes [EventAction] Name=CHARGER_DISCONNECTED Enum=2002 DeviceNotifier=DEVICE_NOTIFIER_BATTERY_CHARGER_DISCONNECTED -Action=sleep,sleep -Action=normal,normal +ActionBroadcast=yes diff --git a/conf/init.conf b/conf/init.conf index e9df34f..22c910d 100644 --- a/conf/init.conf +++ b/conf/init.conf @@ -2,10 +2,10 @@ #INITIAL_STATE_BY_POWERKEY_BOOTING Enum=3000 BootReason=powerkey -Action=start,normal +ActionChangeState=start,normal [EventAction] #INITIAL_STATE_BY_CHARGER_BOOTING Enum=3001 BootReason=charger -Action=start,sleep +ActionChangeState=start,sleep diff --git a/conf/input-profile-iot-headless.conf b/conf/input-profile-iot-headless.conf index 5640a99..8cf5d8b 100644 --- a/conf/input-profile-iot-headless.conf +++ b/conf/input-profile-iot-headless.conf @@ -6,53 +6,53 @@ # integer in broadcasting dbus signal. # Keycode=integer # - define keycode to filter key event -# Duration=integer,integer +# DetectionRangeMsec=integer,integer # - define time window in milisecond for filtering key event. -1 means no limit. # TriggerType=level/edge # - define event type -# Action=broadcast -# - define broadcast action for the event. -# Action=current,next +# ActionBroadcast=yes +# - Broadcast upon occuring an event, default no. +# ActionChangeState=current,next # - define state transition action for the event. [EventAction] Name=BLINKKEY_EDGE Enum=1000 Keycode=bluetooth -Duration=0,2000 +DetectionRangeMsec=0,2000 TriggerType=edge -Action=sleep,sleep +ActionBroadcast=yes [EventAction] Name=SHORTKEY_LEVEL Enum=1001 Keycode=power -Duration=2000,-1 +DetectionRangeMsec=2000,-1 TriggerType=level -Action=broadcast +ActionBroadcast=yes [EventAction] Name=SHORTKEY_EDGE Enum=1002 Keycode=power -Duration=2000,7000 +DetectionRangeMsec=2000,7000 TriggerType=edge -Action=normal,sleep -Action=sleep,normal +ActionChangeState=normal,sleep +ActionChangeState=sleep,normal [EventAction] Name=LONGKEY_LEVEL Enum=1003 Keycode=power -Duration=7000,-1 +DetectionRangeMsec=7000,-1 TriggerType=level -Action=broadcast +ActionBroadcast=yes [EventAction] Name=LONGKEY_EDGE Enum=1004 Keycode=power -Duration=7000,-1 +DetectionRangeMsec=7000,-1 TriggerType=edge ConditionVconf=memory/sysman/charger_status,int,0 -Action=normal,poweroff +ActionChangeState=normal,poweroff diff --git a/plugins/iot-headless/battery/battery-plugin.c b/plugins/iot-headless/battery/battery-plugin.c index 95a427d..99c9aef 100644 --- a/plugins/iot-headless/battery/battery-plugin.c +++ b/plugins/iot-headless/battery/battery-plugin.c @@ -33,6 +33,9 @@ struct battery_event_handler { char *name; int id; + /* broadcast upon occuring this event */ + int broadcast; + /* which action to do on receiving an event */ enum device_notifier_type action; void *user_data; @@ -99,8 +102,10 @@ static void parse_event_action_property(gpointer data, gpointer user_data) sscanf(prop->value, "%d", &handler->id); } else if (MATCH(prop->key, "DeviceNotifier")) { parse_device_notifier(handler, prop->value); - } else if (MATCH(prop->key, "Action")) { + } else if (MATCH(prop->key, "ActionChangeState")) { parse_action(handler, prop->value); + } else if (MATCH(prop->key, "ActionBroadcast")) { + handler->broadcast = MATCH(prop->value, "yes"); } } diff --git a/plugins/iot-headless/input/input-config.c b/plugins/iot-headless/input/input-config.c index 4635159..a8dd609 100644 --- a/plugins/iot-headless/input/input-config.c +++ b/plugins/iot-headless/input/input-config.c @@ -143,15 +143,12 @@ static void add_action_transition_info(struct input_event_unit *ieu, char *curr, SYS_G_LIST_APPEND(*action_list, ti); } -static void parse_action(struct input_event_unit *ieu, const char *action) +static void parse_change_state(struct input_event_unit *ieu, const char *action) { char curr[16] = { 0, }; char next[16] = { 0, }; - if (MATCH(action, "broadcast")) { - ieu->notifier = DEVICE_NOTIFIER_INPUT_BROADCAST_SIGNAL; - ieu->user_data = (void *) ieu; - } else if (sscanf(action, "%15[^,],%15s", curr, next) == 2) { + if (sscanf(action, "%15[^,],%15s", curr, next) == 2) { ieu->notifier = DEVICE_NOTIFIER_REQUEST_TRANSITION_STATE; /* append transition info to ieu->user_data */ add_action_transition_info(ieu, curr, next); @@ -176,14 +173,16 @@ static void parse_event_action_property(gpointer data, gpointer user_data) sscanf(prop->value, "%d", &ieu->id); } else if (MATCH(prop->key, "Keycode")) { parse_keycode(ieu, prop->value); - } else if (MATCH(prop->key, "Duration")) { + } else if (MATCH(prop->key, "DetectionRangeMsec")) { parse_duration(ieu, prop->value); } else if (MATCH(prop->key, "TriggerType")) { parse_trigger_type(ieu, prop->value); } else if (MATCH(prop->key, "ConditionVconf")) { parse_condition_vconf(ieu, prop->value); - } else if (MATCH(prop->key, "Action")) { - parse_action(ieu, prop->value); + } else if (MATCH(prop->key, "ActionChangeState")) { + parse_change_state(ieu, prop->value); + } else if (MATCH(prop->key, "ActionBroadcast")) { + ieu->broadcast = MATCH(prop->value, "yes"); } } diff --git a/plugins/iot-headless/input/input-config.h b/plugins/iot-headless/input/input-config.h index 8e192a6..9d7d060 100644 --- a/plugins/iot-headless/input/input-config.h +++ b/plugins/iot-headless/input/input-config.h @@ -50,6 +50,9 @@ struct input_event_unit { /* condition for triggering action */ struct condition_vconf cv; + /* broadcast upon occuring this event */ + int broadcast; + /* which action to do on receiving an event */ enum device_notifier_type notifier; void *user_data; diff --git a/plugins/iot-headless/input/input-handler.c b/plugins/iot-headless/input/input-handler.c index cce01be..dd31b2c 100644 --- a/plugins/iot-headless/input/input-handler.c +++ b/plugins/iot-headless/input/input-handler.c @@ -38,24 +38,26 @@ static gboolean level_triggered(gpointer data) ieu->timer = 0; - if (check_input_event_condition(ieu)) { - _D("Trigger(level) event=%s(%d), action=%d", ieu->name, ieu->id, ieu->notifier); - device_notify(ieu->notifier, ieu->user_data); - } else { + if (check_input_event_condition(ieu) == 0) { _D("Skip(level) event=%s(%d), condition=%s isn't meet", ieu->name, ieu->id, ieu->cv.keyname); + return G_SOURCE_REMOVE; } + _D("Trigger(level) event=%s(%d), action=%d", ieu->name, ieu->id, ieu->notifier); + device_notify(ieu->notifier, ieu->user_data); + return G_SOURCE_REMOVE; } static void edge_triggered(struct input_event_unit *ieu) { - if (check_input_event_condition(ieu)) { - _D("Trigger(edge) event=%s(%d), action=%d", ieu->name, ieu->id, ieu->notifier); - device_notify(ieu->notifier, ieu->user_data); - } else { + if (check_input_event_condition(ieu) == 0) { _D("Skip(edge) event=%s(%d), condition=%s isn't meet", ieu->name, ieu->id, ieu->cv.keyname); + return; } + + _D("Trigger(edge) event=%s(%d), action=%d", ieu->name, ieu->id, ieu->notifier); + device_notify(ieu->notifier, ieu->user_data); } static void start_event_timer(struct input_config *ic) @@ -145,24 +147,8 @@ static int input_handler_execute(void *data) return 0; } -static int broadcast_input_signal_cb(void *data) -{ - struct input_event_unit *ieu = (struct input_event_unit *) data; - - if (!ieu) - return 0; - - _D("Broadcast siganl, event=%s(%d)", ieu->name, ieu->id); - gdbus_signal_emit(NULL, DEVICED_PATH_INPUT, DEVICED_INTERFACE_INPUT, - "Key", g_variant_new("(i)", ieu->id)); - - return 0; -} - static void input_handler_init(void *data) { - register_notifier(DEVICE_NOTIFIER_INPUT_BROADCAST_SIGNAL, broadcast_input_signal_cb); - init_input_config(); } diff --git a/src/power/power-boot.c b/src/power/power-boot.c index f33bbd4..9926b68 100644 --- a/src/power/power-boot.c +++ b/src/power/power-boot.c @@ -138,7 +138,7 @@ static void parse_init_ti(const struct parse_result *result) SYS_G_LIST_FOREACH(result->props, elem, prop) { if (MATCH(prop->key, "Enum")) init_ti.reason = atoi(prop->value); - else if (MATCH(prop->key, "Action")) + else if (MATCH(prop->key, "ActionChangeState")) parse_transition_info(prop->value); } } diff --git a/src/shared/device-notifier.c b/src/shared/device-notifier.c index badf4e7..77980fb 100644 --- a/src/shared/device-notifier.c +++ b/src/shared/device-notifier.c @@ -94,10 +94,6 @@ static const char *device_notifier_type_str[DEVICE_NOTIFIER_MAX] = { NOTIFY_STR(DEVICE_NOTIFIER_KEY_PRESS), NOTIFY_STR(DEVICE_NOTIFIER_KEY_RELEASE), - /* action triggered by input event */ - NOTIFY_STR(DEVICE_NOTIFIER_INPUT_TRIGGER_POWEROFF), - NOTIFY_STR(DEVICE_NOTIFIER_INPUT_BROADCAST_SIGNAL), - /* Purpose of calling methods of different modules * Use prefix DEVICE_NOTIFIER_REQUEST */ NOTIFY_STR(DEVICE_NOTIFIER_REQUEST_TRANSITION_STATE), diff --git a/src/shared/device-notifier.h b/src/shared/device-notifier.h index 3acf22e..c81db6a 100644 --- a/src/shared/device-notifier.h +++ b/src/shared/device-notifier.h @@ -67,10 +67,6 @@ enum device_notifier_type { DEVICE_NOTIFIER_KEY_PRESS, DEVICE_NOTIFIER_KEY_RELEASE, - /* action triggered by input event */ - DEVICE_NOTIFIER_INPUT_TRIGGER_POWEROFF, - DEVICE_NOTIFIER_INPUT_BROADCAST_SIGNAL, - /* Purpose of calling methods of different modules * Use prefix DEVICE_NOTIFIER_REQUEST */ DEVICE_NOTIFIER_REQUEST_TRANSITION_STATE, -- 2.7.4 From cd06534f1ae7ff3a12af8e3371134d1c008efd60 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 13 Jun 2022 15:09:12 +0900 Subject: [PATCH 03/16] event: add event functions to shared library It contains functions that handling wakelock of event, and broadcasting signal about an event itself. The properties, WakeLockDurationSec= and ActionBroadcast= of configuration file, utilize those functions. Change-Id: I926f5e9cf19bfe09042797a200569c69e2b25a21 Signed-off-by: Youngjae Cho --- conf/battery.conf | 2 + conf/input-profile-iot-headless.conf | 1 + plugins/iot-headless/battery/battery-plugin.c | 20 +++++++++- plugins/iot-headless/input/input-config.c | 2 + plugins/iot-headless/input/input-config.h | 9 +++-- plugins/iot-headless/input/input-handler.c | 40 ++++++++++++++------ src/power/power-event-lock.c | 16 ++++++-- src/shared/device-notifier.c | 2 + src/shared/device-notifier.h | 2 + src/shared/event.c | 53 +++++++++++++++++++++++++++ src/shared/event.h | 45 +++++++++++++++++++++++ 11 files changed, 172 insertions(+), 20 deletions(-) create mode 100644 src/shared/event.c create mode 100644 src/shared/event.h diff --git a/conf/battery.conf b/conf/battery.conf index d3c9c76..1bd6a2c 100644 --- a/conf/battery.conf +++ b/conf/battery.conf @@ -24,9 +24,11 @@ Name=CHARGER_CONNECTED Enum=2001 DeviceNotifier=DEVICE_NOTIFIER_BATTERY_CHARGER_CONNECTED ActionBroadcast=yes +WakeLockDurationSec=5 [EventAction] Name=CHARGER_DISCONNECTED Enum=2002 DeviceNotifier=DEVICE_NOTIFIER_BATTERY_CHARGER_DISCONNECTED ActionBroadcast=yes +WakeLockDurationSec=5 diff --git a/conf/input-profile-iot-headless.conf b/conf/input-profile-iot-headless.conf index 8cf5d8b..c422d64 100644 --- a/conf/input-profile-iot-headless.conf +++ b/conf/input-profile-iot-headless.conf @@ -22,6 +22,7 @@ Keycode=bluetooth DetectionRangeMsec=0,2000 TriggerType=edge ActionBroadcast=yes +WakeLockDurationSec=5 [EventAction] Name=SHORTKEY_LEVEL diff --git a/plugins/iot-headless/battery/battery-plugin.c b/plugins/iot-headless/battery/battery-plugin.c index 99c9aef..2c03708 100644 --- a/plugins/iot-headless/battery/battery-plugin.c +++ b/plugins/iot-headless/battery/battery-plugin.c @@ -23,6 +23,7 @@ #include "shared/device-notifier.h" #include "shared/log.h" +#include "shared/event.h" #include "battery/battery-ops.h" #include "power/power.h" @@ -39,6 +40,9 @@ struct battery_event_handler { /* which action to do on receiving an event */ enum device_notifier_type action; void *user_data; + + /* hold wakelock for a duration on detecting the event */ + int wakelock_duration; }; static struct battery_event_handler *handler_connected; @@ -106,6 +110,8 @@ static void parse_event_action_property(gpointer data, gpointer user_data) parse_action(handler, prop->value); } else if (MATCH(prop->key, "ActionBroadcast")) { handler->broadcast = MATCH(prop->value, "yes"); + } else if (MATCH(prop->key, "WakeLockDurationSec")) { + sscanf(prop->value, "%d", &handler->wakelock_duration); } } @@ -130,7 +136,12 @@ static int parse_event_action(const struct parse_result *result, void *data) static int charger_connected_callback(void *data) { _D("event=%s(%d), action=%d", handler_connected->name, handler_connected->id, handler_connected->action); - device_notify(handler_connected->action, handler_connected->user_data); + + if (handler_connected->wakelock_duration) + event_acquire_wakelock(handler_connected->id, handler_connected->wakelock_duration); + + if (handler_connected->action) + device_notify(handler_connected->action, handler_connected->user_data); return 0; } @@ -138,7 +149,12 @@ static int charger_connected_callback(void *data) static int charger_disconnected_callback(void *data) { _D("event=%s(%d), action=%d", handler_disconnected->name, handler_disconnected->id, handler_disconnected->action); - device_notify(handler_disconnected->action, handler_disconnected->user_data); + + if (handler_disconnected->wakelock_duration) + event_acquire_wakelock(handler_disconnected->id, handler_disconnected->wakelock_duration); + + if (handler_disconnected->action) + device_notify(handler_disconnected->action, handler_disconnected->user_data); return 0; } diff --git a/plugins/iot-headless/input/input-config.c b/plugins/iot-headless/input/input-config.c index a8dd609..4a8715d 100644 --- a/plugins/iot-headless/input/input-config.c +++ b/plugins/iot-headless/input/input-config.c @@ -183,6 +183,8 @@ static void parse_event_action_property(gpointer data, gpointer user_data) parse_change_state(ieu, prop->value); } else if (MATCH(prop->key, "ActionBroadcast")) { ieu->broadcast = MATCH(prop->value, "yes"); + } else if (MATCH(prop->key, "WakeLockDurationSec")) { + sscanf(prop->value, "%d", &ieu->wakelock_duration); } } diff --git a/plugins/iot-headless/input/input-config.h b/plugins/iot-headless/input/input-config.h index 9d7d060..4f03f30 100644 --- a/plugins/iot-headless/input/input-config.h +++ b/plugins/iot-headless/input/input-config.h @@ -47,18 +47,21 @@ struct input_event_unit { enum trigger_type type; unsigned long interval[2]; + /* level-trigger timer */ + int timer; + /* condition for triggering action */ struct condition_vconf cv; - /* broadcast upon occuring this event */ + /* broadcast upon occuring the event */ int broadcast; /* which action to do on receiving an event */ enum device_notifier_type notifier; void *user_data; - /* level-trigger timer */ - int timer; + /* hold wakelock for a duration on detecting the event */ + int wakelock_duration; }; struct input_config { diff --git a/plugins/iot-headless/input/input-handler.c b/plugins/iot-headless/input/input-handler.c index dd31b2c..1176963 100644 --- a/plugins/iot-headless/input/input-handler.c +++ b/plugins/iot-headless/input/input-handler.c @@ -17,6 +17,7 @@ */ #include +#include #include #include #include @@ -26,38 +27,55 @@ #include "shared/devices.h" #include "shared/device-notifier.h" #include "shared/log.h" +#include "shared/event.h" #include "input-config.h" #define KEYVALUE_PRESS 1 #define KEYVALUE_RELEASE 0 -static gboolean level_triggered(gpointer data) +static gboolean level_event_detected(gpointer data) { struct input_event_unit *ieu = (struct input_event_unit *) data; ieu->timer = 0; + _D("Detected level event=%s(%d), action=%d", ieu->name, ieu->id, ieu->notifier); + if (check_input_event_condition(ieu) == 0) { - _D("Skip(level) event=%s(%d), condition=%s isn't meet", ieu->name, ieu->id, ieu->cv.keyname); + _D("Skip triggering event=%s(%d), condition=%s isn't meet", ieu->name, ieu->id, ieu->cv.keyname); return G_SOURCE_REMOVE; } - _D("Trigger(level) event=%s(%d), action=%d", ieu->name, ieu->id, ieu->notifier); - device_notify(ieu->notifier, ieu->user_data); + if (ieu->broadcast) + event_broadcast_id(ieu->id); + + if (ieu->wakelock_duration > 0) + event_acquire_wakelock(ieu->id, ieu->wakelock_duration); + + if (ieu->notifier) + device_notify(ieu->notifier, ieu->user_data); return G_SOURCE_REMOVE; } -static void edge_triggered(struct input_event_unit *ieu) +static void edge_event_detected(struct input_event_unit *ieu) { + _D("Detected edge event=%s(%d), action=%d", ieu->name, ieu->id, ieu->notifier); + if (check_input_event_condition(ieu) == 0) { - _D("Skip(edge) event=%s(%d), condition=%s isn't meet", ieu->name, ieu->id, ieu->cv.keyname); + _D("Skip triggering event=%s(%d), condition=%s isn't meet", ieu->name, ieu->id, ieu->cv.keyname); return; } - _D("Trigger(edge) event=%s(%d), action=%d", ieu->name, ieu->id, ieu->notifier); - device_notify(ieu->notifier, ieu->user_data); + if (ieu->broadcast) + event_broadcast_id(ieu->id); + + if (ieu->wakelock_duration > 0) + event_acquire_wakelock(ieu->id, ieu->wakelock_duration); + + if (ieu->notifier) + device_notify(ieu->notifier, ieu->user_data); } static void start_event_timer(struct input_config *ic) @@ -74,7 +92,7 @@ static void start_event_timer(struct input_config *ic) if (ieu->type == TRIGGER_TYPE_LEVEL) { if (ieu->timer) g_source_remove(ieu->timer); - ieu->timer = g_timeout_add(ieu->interval[0], level_triggered, (gpointer) ieu); + ieu->timer = g_timeout_add(ieu->interval[0], level_event_detected, (gpointer) ieu); } } } @@ -102,9 +120,9 @@ static void stop_event_timer(struct input_config *ic) ieu->timer = 0; } - /* trigger edge-trigger action */ + /* detected edge-trigger event */ if (lapse >= ieu->interval[0] && lapse < ieu->interval[1] && ieu->type == TRIGGER_TYPE_EDGE) - edge_triggered(ieu); + edge_event_detected(ieu); } } diff --git a/src/power/power-event-lock.c b/src/power/power-event-lock.c index dc8353c..70bb44c 100644 --- a/src/power/power-event-lock.c +++ b/src/power/power-event-lock.c @@ -43,6 +43,7 @@ enum eventlock_type { EL_KEY_BLUETOOTH, EL_CHARGER, + EL_EVENT_ACTION, /* add eventlock type here */ EL_MAX, }; @@ -60,11 +61,11 @@ static void event_wake_lock(enum eventlock_type type) set_bit(eventlock, type); setcount = count_set_bit(eventlock); - _D("Set eventlock of type=%d, current number of eventlock=%d", type, setcount); + _I("Set eventlock of type=%d, current number of eventlock=%d", type, setcount); if (setcount == 1) { sys_set_str("/sys/power/wake_lock", EVENT_LOCK); - _D("Acquired eventlock"); + _I("Acquired eventlock"); } } @@ -78,11 +79,11 @@ static void event_wake_unlock(enum eventlock_type type) clear_bit(eventlock, type); setcount = count_set_bit(eventlock); - _D("Unset eventlock of type=%d, current number of eventlock=%d", type, setcount); + _I("Unset eventlock of type=%d, current number of eventlock=%d", type, setcount); if (setcount == 0) { sys_set_str("/sys/power/wake_unlock", EVENT_LOCK); - _D("Released eventlock"); + _I("Released eventlock"); } } @@ -163,10 +164,17 @@ void power_event_lock_init(void) config_parse(BATTERY_CONF_FILE, check_charger_wakelock, &charger_wakelock); + /* general events, mostly defined by configuration file */ + register_power_event_lock_controller(EL_EVENT_ACTION, + DEVICE_NOTIFIER_EVENT_ACQUIRE_WAKELOCK, + DEVICE_NOTIFIER_EVENT_RELEASE_WAKELOCK); + + /* key input event */ register_power_event_lock_controller(EL_KEY, DEVICE_NOTIFIER_KEY_PRESS, DEVICE_NOTIFIER_KEY_RELEASE); + /* charger event */ if (charger_wakelock) { register_power_event_lock_controller(EL_CHARGER, DEVICE_NOTIFIER_BATTERY_CHARGER_CONNECTED, diff --git a/src/shared/device-notifier.c b/src/shared/device-notifier.c index 77980fb..61cd1c2 100644 --- a/src/shared/device-notifier.c +++ b/src/shared/device-notifier.c @@ -93,6 +93,8 @@ static const char *device_notifier_type_str[DEVICE_NOTIFIER_MAX] = { 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), + NOTIFY_STR(DEVICE_NOTIFIER_EVENT_RELEASE_WAKELOCK), /* Purpose of calling methods of different modules * Use prefix DEVICE_NOTIFIER_REQUEST */ diff --git a/src/shared/device-notifier.h b/src/shared/device-notifier.h index c81db6a..bd1880a 100644 --- a/src/shared/device-notifier.h +++ b/src/shared/device-notifier.h @@ -66,6 +66,8 @@ enum device_notifier_type { DEVICE_NOTIFIER_EXTCON_COUNT, DEVICE_NOTIFIER_KEY_PRESS, DEVICE_NOTIFIER_KEY_RELEASE, + DEVICE_NOTIFIER_EVENT_ACQUIRE_WAKELOCK, + DEVICE_NOTIFIER_EVENT_RELEASE_WAKELOCK, /* Purpose of calling methods of different modules * Use prefix DEVICE_NOTIFIER_REQUEST */ diff --git a/src/shared/event.c b/src/shared/event.c new file mode 100644 index 0000000..4915f76 --- /dev/null +++ b/src/shared/event.c @@ -0,0 +1,53 @@ +/* + * deviced + * + * Copyright (c) 2022 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 "device-notifier.h" +#include "log.h" + +static int wakelock_counter; + +static gboolean event_release_wakelock(gpointer data) +{ + int eventid = (int)(intptr_t) data; + + --wakelock_counter; + + _D("Decreased counter=%d, eventid=%d", wakelock_counter, eventid); + + if (wakelock_counter == 0) + device_notify(DEVICE_NOTIFIER_EVENT_RELEASE_WAKELOCK, NULL); + + return G_SOURCE_REMOVE; +} + +void event_acquire_wakelock(int eventid, int timeout) +{ + if (timeout <= 0) + return; + + ++wakelock_counter; + + _D("Increased counter=%d, eventid=%d, timeout=%d", wakelock_counter, eventid, timeout); + g_timeout_add_seconds(timeout, event_release_wakelock, (gpointer)(intptr_t) eventid); + + if (wakelock_counter == 1) + device_notify(DEVICE_NOTIFIER_EVENT_ACQUIRE_WAKELOCK, NULL); +} diff --git a/src/shared/event.h b/src/shared/event.h new file mode 100644 index 0000000..44821e5 --- /dev/null +++ b/src/shared/event.h @@ -0,0 +1,45 @@ +/* + * deviced + * + * Copyright (c) 2022 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_EVENT_H__ +#define __DD_EVENT_H__ + +#include + +#define DEVICED_PATH_EVENT "/Org/Tizen/System/DeviceD/Event" +#define DEVICED_INTERFACE_EVENT "org.tizen.system.deviced.Event" +#define DEVICED_SIGNAME_ID "Id" + +static inline void event_broadcast_id(int id) +{ + _I("Broadcast eventid=%d", id); + + gdbus_signal_emit(NULL, + DEVICED_PATH_EVENT, + DEVICED_INTERFACE_EVENT, + DEVICED_SIGNAME_ID, + g_variant_new("(i)", id)); +} + +/** + * Hold wakelock for a specified timeout. + * The parameter eventid is only used for logging + */ +void event_acquire_wakelock(int eventid, int timeout); + +#endif //__DD_EVENT_H__ -- 2.7.4 From 750ac44ddbac46babedeadae439ab8de2999e57e Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 15 Jun 2022 14:28:17 +0900 Subject: [PATCH 04/16] Reconfigure input for iot-headless Change-Id: I035784568172ce7d8367f26361460d136b7d9c32 Signed-off-by: Youngjae Cho --- conf/battery.conf | 2 ++ conf/input-profile-iot-headless.conf | 57 +++++++++++++++++++++++++++--------- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/conf/battery.conf b/conf/battery.conf index 1bd6a2c..d854e14 100644 --- a/conf/battery.conf +++ b/conf/battery.conf @@ -18,6 +18,8 @@ ChargerWakeLockEnabled=yes # - define action for the event # ActionBroadcast=yes # - broadcast upon occuring the event +# WakeLockDurationSec= +# - acquire wakelock for a specfied timeout [EventAction] Name=CHARGER_CONNECTED diff --git a/conf/input-profile-iot-headless.conf b/conf/input-profile-iot-headless.conf index c422d64..a2c0284 100644 --- a/conf/input-profile-iot-headless.conf +++ b/conf/input-profile-iot-headless.conf @@ -14,9 +14,11 @@ # - Broadcast upon occuring an event, default no. # ActionChangeState=current,next # - define state transition action for the event. +# WakeLockDurationSec= +# - acquire wakelock for a specfied timeout [EventAction] -Name=BLINKKEY_EDGE +Name=BTKEY_SHORT Enum=1000 Keycode=bluetooth DetectionRangeMsec=0,2000 @@ -25,35 +27,62 @@ ActionBroadcast=yes WakeLockDurationSec=5 [EventAction] -Name=SHORTKEY_LEVEL +Name=BTKEY_LONG Enum=1001 -Keycode=power -DetectionRangeMsec=2000,-1 -TriggerType=level +Keycode=bluetooth +DetectionRangeMsec=2000,7000 +TriggerType=edge ActionBroadcast=yes [EventAction] -Name=SHORTKEY_EDGE +Name=PWKEY_SHORT Enum=1002 Keycode=power -DetectionRangeMsec=2000,7000 +DetectionRangeMsec=0,2000 TriggerType=edge -ActionChangeState=normal,sleep -ActionChangeState=sleep,normal +ActionBroadcast=yes [EventAction] -Name=LONGKEY_LEVEL +Name=PWKEY_LONG Enum=1003 Keycode=power -DetectionRangeMsec=7000,-1 -TriggerType=level -ActionBroadcast=yes +DetectionRangeMsec=2000,7000 +TriggerType=edge +ActionChangeState=normal,sleep +ActionChangeState=sleep,normal [EventAction] -Name=LONGKEY_EDGE +Name=PWKEY_LONGEST Enum=1004 Keycode=power DetectionRangeMsec=7000,-1 TriggerType=edge ConditionVconf=memory/sysman/charger_status,int,0 ActionChangeState=normal,poweroff + +# This doesn't trigger any action. +# It is just for logging that bluetooth key has been pressed for 2000ms +[EventAction] +Name=BTKEY_CHECKPOINT_LONG +Enum=1005 +Keycode=bluetooth +DetectionRangeMsec=2000,-1 +TriggerType=level + +# This doesn't trigger any action. +# It is just for logging that powerkey has been pressed for 2000ms +[EventAction] +Name=PWKEY_CHECKPOINT_LONG +Enum=1006 +Keycode=power +DetectionRangeMsec=2000,-1 +TriggerType=level + +# Powerkey has been pressed for 7000ms +# It is just for logging that powerkey has been pressed for 7000ms +[EventAction] +Name=PWKEY_CHECKPOINT_LONGEST +Enum=1007 +Keycode=power +DetectionRangeMsec=7000,-1 +TriggerType=level -- 2.7.4 From d932a1f0057f9892d2ad11b042eeed3aebf04c9d Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 16 Jun 2022 14:22:07 +0900 Subject: [PATCH 05/16] input: add broadcasting action for level event Change-Id: I57090ba79f082d9c8c2a3c657e586ccc7f12a97f Signed-off-by: Youngjae Cho --- conf/input-profile-iot-headless.conf | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/conf/input-profile-iot-headless.conf b/conf/input-profile-iot-headless.conf index a2c0284..0545f06 100644 --- a/conf/input-profile-iot-headless.conf +++ b/conf/input-profile-iot-headless.conf @@ -60,29 +60,26 @@ TriggerType=edge ConditionVconf=memory/sysman/charger_status,int,0 ActionChangeState=normal,poweroff -# This doesn't trigger any action. -# It is just for logging that bluetooth key has been pressed for 2000ms [EventAction] Name=BTKEY_CHECKPOINT_LONG Enum=1005 Keycode=bluetooth DetectionRangeMsec=2000,-1 TriggerType=level +ActionBroadcast=yes -# This doesn't trigger any action. -# It is just for logging that powerkey has been pressed for 2000ms [EventAction] Name=PWKEY_CHECKPOINT_LONG Enum=1006 Keycode=power DetectionRangeMsec=2000,-1 TriggerType=level +ActionBroadcast=yes -# Powerkey has been pressed for 7000ms -# It is just for logging that powerkey has been pressed for 7000ms [EventAction] Name=PWKEY_CHECKPOINT_LONGEST Enum=1007 Keycode=power DetectionRangeMsec=7000,-1 TriggerType=level +ActionBroadcast=yes -- 2.7.4 From 357be092c844952322166dbceb083dbcbe46166f Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 16 Jun 2022 14:23:50 +0900 Subject: [PATCH 06/16] input: rearrange EventAction in chronological order Change-Id: Idd1363d61ca4c303936fcd027b812eb57c6efb5c Signed-off-by: Youngjae Cho --- conf/input-profile-iot-headless.conf | 48 ++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/conf/input-profile-iot-headless.conf b/conf/input-profile-iot-headless.conf index 0545f06..3acdc6a 100644 --- a/conf/input-profile-iot-headless.conf +++ b/conf/input-profile-iot-headless.conf @@ -18,33 +18,24 @@ # - acquire wakelock for a specfied timeout [EventAction] -Name=BTKEY_SHORT +Name=PWKEY_SHORT Enum=1000 -Keycode=bluetooth +Keycode=power DetectionRangeMsec=0,2000 TriggerType=edge ActionBroadcast=yes -WakeLockDurationSec=5 [EventAction] -Name=BTKEY_LONG +Name=PWKEY_CHECKPOINT_LONG Enum=1001 -Keycode=bluetooth -DetectionRangeMsec=2000,7000 -TriggerType=edge -ActionBroadcast=yes - -[EventAction] -Name=PWKEY_SHORT -Enum=1002 Keycode=power -DetectionRangeMsec=0,2000 -TriggerType=edge +DetectionRangeMsec=2000,-1 +TriggerType=level ActionBroadcast=yes [EventAction] Name=PWKEY_LONG -Enum=1003 +Enum=1002 Keycode=power DetectionRangeMsec=2000,7000 TriggerType=edge @@ -52,6 +43,14 @@ ActionChangeState=normal,sleep ActionChangeState=sleep,normal [EventAction] +Name=PWKEY_CHECKPOINT_LONGEST +Enum=1003 +Keycode=power +DetectionRangeMsec=7000,-1 +TriggerType=level +ActionBroadcast=yes + +[EventAction] Name=PWKEY_LONGEST Enum=1004 Keycode=power @@ -61,25 +60,26 @@ ConditionVconf=memory/sysman/charger_status,int,0 ActionChangeState=normal,poweroff [EventAction] -Name=BTKEY_CHECKPOINT_LONG +Name=BTKEY_SHORT Enum=1005 Keycode=bluetooth -DetectionRangeMsec=2000,-1 -TriggerType=level +DetectionRangeMsec=0,2000 +TriggerType=edge ActionBroadcast=yes +WakeLockDurationSec=5 [EventAction] -Name=PWKEY_CHECKPOINT_LONG +Name=BTKEY_CHECKPOINT_LONG Enum=1006 -Keycode=power +Keycode=bluetooth DetectionRangeMsec=2000,-1 TriggerType=level ActionBroadcast=yes [EventAction] -Name=PWKEY_CHECKPOINT_LONGEST +Name=BTKEY_LONG Enum=1007 -Keycode=power -DetectionRangeMsec=7000,-1 -TriggerType=level +Keycode=bluetooth +DetectionRangeMsec=2000,7000 +TriggerType=edge ActionBroadcast=yes -- 2.7.4 From 552c2c2e35dc84558cb12b514d3872ff4a8e69da Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 16 Jun 2022 14:42:25 +0900 Subject: [PATCH 07/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 08/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 09/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 10/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 11/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 12/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 13/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 14/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 15/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 16/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