From 7952f9f960397d8d0f8965a0cb517505b7f6e2c3 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 9 Nov 2020 15:48:21 +0900 Subject: [PATCH 01/16] Add bitmap functions Change-Id: I8c39533fa77e6830881062b525b72eec3386342e Signed-off-by: Youngjae Cho --- CMakeLists.txt | 1 + src/core/bitmap.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/bitmap.h | 60 +++++++++++++++++++++ src/core/common.h | 24 ++++++--- src/extcon/hdmi.c | 44 +++++++++++----- 5 files changed, 261 insertions(+), 20 deletions(-) create mode 100644 src/core/bitmap.c create mode 100644 src/core/bitmap.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d00ac6..6bfcc69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,7 @@ SET(SRCS src/core/main.c src/core/sig-handler.c src/core/udev.c + src/core/bitmap.c src/proc/cpu-info.c src/time/time-handler.c ) diff --git a/src/core/bitmap.c b/src/core/bitmap.c new file mode 100644 index 0000000..d528188 --- /dev/null +++ b/src/core/bitmap.c @@ -0,0 +1,152 @@ +/* + * deviced + * + * Copyright (c) 2020 - 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include "bitmap.h" +#include "log.h" + +static void bitmap_alloc_size(struct dd_bitmap *bm, unsigned int nbits) +{ + unsigned int bytes = ROUNDUP_BITS_TO_LONGS(nbits) * BYTES_PER_LONG; + + bytes += BITMAP_MARGIN; + + bm->b = (unsigned long *) malloc(bytes); + if (!bm->b) + return; + + bm->size = nbits; +} + +void set_all_bits(struct dd_bitmap *bm) +{ + unsigned long complete_longs = bm->size / BITS_PER_LONG; + unsigned long complete_bytes = complete_longs * BYTES_PER_LONG; + unsigned long residue_bits = bm->size % BITS_PER_LONG; + + /* set all bits of the long element except the last long element */ + memset(bm->b, ~0, complete_bytes); + + /* set residue bits in the last long element */ + if (residue_bits) + bm->b[complete_longs] = (1UL << residue_bits) - 1; +} + +void clear_all_bits(struct dd_bitmap *bm) +{ + unsigned int bytes = ROUNDUP_BITS_TO_LONGS(bm->size) * BYTES_PER_LONG; + memset(bm->b, 0, bytes); +} + +void set_bit(struct dd_bitmap *bm, unsigned long nr) +{ + if (!bm) + return; + + if (nr >= bm->size) { + _E("Requested nr=%lu exceeds max bit=%lu", nr, bm->size - 1); + return; + } + + bm->b[BIT_WORD(nr)] |= BIT_MASK(nr); +} + +void clear_bit(struct dd_bitmap *bm, unsigned long nr) +{ + if (!bm) + return; + + if (nr >= bm->size) { + _E("Requested nr=%lu exceeds max bit=%lu", nr, bm->size - 1); + return; + } + + bm->b[BIT_WORD(nr)] &= ~BIT_MASK(nr); +} + +bool test_bit(struct dd_bitmap *bm, unsigned long nr) +{ + if (!bm) + return false; + + if (nr >= bm->size) { + _E("Requested nr=%lu exceeds max bit=%lu", nr, bm->size - 1); + return false; + } + + return bm->b[BIT_WORD(nr)] & BIT_MASK(nr); +} + +int count_set_bit(struct dd_bitmap *bm) +{ + int i; + int count = 0; + + if (!bm) + return -1; + + for (i = 0; i < ROUNDUP_BITS_TO_LONGS(bm->size); ++i) + count += __builtin_popcountl(bm->b[i]); + + return count; +} + +int count_unset_bit(struct dd_bitmap *bm) +{ + if (!bm) + return -1; + + return bm->size - count_set_bit(bm); +} + +struct dd_bitmap* init_bitmap(unsigned int nbits) +{ + struct dd_bitmap *bm = NULL; + + if (nbits == 0) + return NULL; + + bm = (struct dd_bitmap *) malloc(sizeof(struct dd_bitmap)); + if (!bm) + return NULL; + + bm->b = NULL; + bm->size = 0; + + bitmap_alloc_size(bm, nbits); + if (!bm->b) { + free(bm); + return NULL; + } + + clear_all_bits(bm); + bm->size = nbits; + + return bm; +} + +void deinit_bitmap(struct dd_bitmap *bm) +{ + if (!bm) + return; + + free(bm->b); + free(bm); +} diff --git a/src/core/bitmap.h b/src/core/bitmap.h new file mode 100644 index 0000000..6135b7c --- /dev/null +++ b/src/core/bitmap.h @@ -0,0 +1,60 @@ +/* + * deviced + * + * Copyright (c) 2020 - 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __DD_BITMAP_H__ +#define __DD_BITMAP_H__ + +#include + +#include "common.h" + +/* Align bits by size of long, and convert it to long, + * for example, if long is 64bit then, + * ROUNDUP_BITS_TO_LONGS(0) -> 0 + * ROUNDUP_BITS_TO_LONGS(1) -> 1 + * ROUNDUP_BITS_TO_LONGS(64) -> 1 + * ROUNDUP_BITS_TO_LONGS(65) -> 2 + * ROUNDUP_BITS_TO_LONGS(128) -> 2 + * ROUNDUP_BITS_TO_LONGS(129) -> 3 + * ... */ +#define ROUNDUP_BITS_TO_LONGS(nbits) (roundup(nbits, BITS_PER_LONG) / BITS_PER_LONG) + +#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) +#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BITMAP_MARGIN (BYTES_PER_LONG * 2) /* trailing margin for safety, bytes */ + +struct dd_bitmap { + /* bitmap */ + unsigned long *b; + + /* number of bits, not the maximum bit. + * maximum bit is size - 1 */ + unsigned long size; +}; + +void set_bit(struct dd_bitmap *bm, unsigned long nr); +void clear_bit(struct dd_bitmap *bm, unsigned long nr); +bool test_bit(struct dd_bitmap *bm, unsigned long nr); +void set_all_bits(struct dd_bitmap *bm); +void clear_all_bits(struct dd_bitmap *bm); +int count_set_bit(struct dd_bitmap *bm); +int count_unset_bit(struct dd_bitmap *bm); +struct dd_bitmap* init_bitmap(unsigned int nbits); +void deinit_bitmap(struct dd_bitmap *bm); + +#endif diff --git a/src/core/common.h b/src/core/common.h index b49e52b..04597ff 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -27,13 +27,12 @@ #include #include -#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) -#define BITS_PER_LONG (sizeof(long) * 8) -#define BITS_PER_CHAR (sizeof(char) * 8) -#define OFFSET(x) ((x) & (BITS_PER_LONG - 1)) -#define BIT(x) (1UL << OFFSET(x)) -#define LONG(x) ((x) / BITS_PER_LONG) -#define test_bit(bit, array) ((array[LONG(bit)] >> OFFSET(bit)) & 1) +#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) +#define BYTES_PER_LONG (sizeof(unsigned long)) +#define BITS_PER_LONG (BYTES_PER_LONG * 8) +#define OFFSET(x) ((x) & (BITS_PER_LONG - 1)) +#define BIT(x) (1UL << OFFSET(x)) +#define LONG(x) ((x) / BITS_PER_LONG) /* * One byte digit has 3 position in decimal representation @@ -91,6 +90,17 @@ }) #endif +/* Round up x to a multiple of y. + * y must be a power of 2, if not, use roundup() */ +#ifndef round_up +#define round_up(x, y) ((((x) - 1 ) | (typeof(x))((y) - 1)) + 1) +#endif + +/* Round up n to a multiple of d. */ +#ifndef roundup +#define roundup(n, d) ((((n) + (d) - 1) / (d)) * (d)) +#endif + #ifndef SEC_TO_MSEC #define SEC_TO_MSEC(x) ((x)*1000) #endif diff --git a/src/extcon/hdmi.c b/src/extcon/hdmi.c index c2cc3af..15a3cf9 100644 --- a/src/extcon/hdmi.c +++ b/src/extcon/hdmi.c @@ -21,6 +21,7 @@ #include #include "core/log.h" #include "core/list.h" +#include "core/bitmap.h" #include "core/device-notifier.h" #include "display/core.h" #include "display/display-ops.h" @@ -31,15 +32,8 @@ #define SIGNAL_HDMI_STATE "ChangedHDMI" #define HDMI_NUMBER_MAX (64) // max number of supported hdmi -#define HDMI_BITMAP_T (sizeof(hdmi_bitmap_t) * BITS_PER_CHAR) // size of hdmi_bitmap_t -/* macro to set/unset bit */ -#define HDMI_SET_BIT(num) (hdmi_bitmap |= (1ULL << ((num) % HDMI_BITMAP_T))) -#define HDMI_UNSET_BIT(num) (hdmi_bitmap &= ~(1ULL << ((num) % HDMI_BITMAP_T))) - -typedef unsigned long long hdmi_bitmap_t; - -static hdmi_bitmap_t hdmi_bitmap; +static struct dd_bitmap *bm_hdmi; static struct display_plugin *disp_plgn; static struct extcon_ops hdmi_extcon_ops; @@ -66,7 +60,12 @@ static void hdmi_send_broadcast(int status) /* if hdmi_bitmap is bigger than 0, we assume hdmi is connected */ static int get_hdmi_status(void) { - if (hdmi_bitmap > 0) + if (!bm_hdmi) { + _E("bm_hdmi is not initialized."); + return HDMI_DISCONNECTED; + } + + if (count_set_bit(bm_hdmi) > 0) return HDMI_CONNECTED; return HDMI_DISCONNECTED; @@ -75,18 +74,28 @@ static int get_hdmi_status(void) static void update_hdmi_bitmap(int index, int status) { + if (!bm_hdmi) { + _E("bm_hdmi is not initialized."); + return; + } + if (status == HDMI_CONNECTED) - HDMI_SET_BIT(index); + set_bit(bm_hdmi, index); else - HDMI_UNSET_BIT(index); + clear_bit(bm_hdmi, index); } static void update_all_hdmi_bitmap(int status) { + if (!bm_hdmi) { + _E("bm_hdmi is not initialized."); + return; + } + if (status == HDMI_CONNECTED) - hdmi_bitmap = ULLONG_MAX; + set_all_bits(bm_hdmi); else - hdmi_bitmap = 0; + clear_all_bits(bm_hdmi); } static int hdmi_update(const char *index, int status) @@ -95,6 +104,11 @@ static int hdmi_update(const char *index, int status) int num = -1; int hdmi_status; + if (!bm_hdmi) { + _E("bm_hdmi is not initialized."); + return -ENODEV; + } + _I("Hdmi changed"); if (disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_HDMI, LCD_NORMAL); @@ -178,11 +192,15 @@ static void hdmi_init(void *data) ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_SYSNOTI, &dbus_interface); if (ret < 0) _E("Failed to init dbus method: %d", ret); + + bm_hdmi = init_bitmap(HDMI_NUMBER_MAX); } static void hdmi_exit(void *data) { unregister_notifier(DEVICE_NOTIFIER_LCD, display_changed); + + deinit_bitmap(bm_hdmi); } static struct extcon_ops hdmi_extcon_ops = { -- 2.7.4 From 1e6745de813f943b1a2aa5e881490bb68de5a4d0 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 10 Nov 2020 18:22:45 +0900 Subject: [PATCH 02/16] Manage application state: foreground, background, terminated Foreground / Background An application's lock is managed more strictly from the point when the application requires it. Now determine the memeber variable 'background' of PmLockNode based on the application's fg/bg state when adding lock as a new PmLockNode. Terminated When an application is terminated without releasing lock, deviced unlocks it right away. At the same time, deviced decides whether to change state or not. At before, for this situation, it was responsible for pmlock_check() to release lingering lock of terminated application. Change-Id: I70e66b69a5f3cdbfa54a2deb2e53ddf15d5456e1 Signed-off-by: Youngjae Cho Signed-off-by: lokilee73 --- plugins/iot/display/core.c | 15 ++++++--- plugins/mobile/display/core.c | 15 ++++++--- plugins/tv/display/core.c | 15 ++++++--- plugins/wearable/display/core.c | 15 ++++++--- src/apps/apps.c | 45 +++++++++++++++++++++++++ src/apps/apps.h | 9 ++++- src/core/device-notifier.c | 5 +-- src/core/device-notifier.h | 5 +-- src/display/core.h | 1 + src/display/display-dbus.c | 36 ++++++++++++++++++-- src/display/display-lock.c | 74 +++++++++++++++++++++++++++++++++-------- src/display/display-lock.h | 8 ++--- 12 files changed, 202 insertions(+), 41 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 228ac67..13f389e 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -221,6 +221,11 @@ inline struct state* state_st(enum state_t state) return &states[state]; } +guint get_transition_timer(void) +{ + return timeout_src_id; +} + void change_state_action(enum state_t state, int (*func)(int timeout)) { _I("[%s] 'action' is changed.", states[state].name); @@ -2095,8 +2100,9 @@ static void display_init(void *data) register_kernel_uevent_control(&lcd_uevent_ops); register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - register_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); - register_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); + register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); + register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); + register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); register_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); register_notifier(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, display_auto_brightness_sensing); @@ -2237,8 +2243,9 @@ static void display_exit(void *data) break; case INIT_POLL: unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - unregister_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); - unregister_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); + unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); + unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); + unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 3a3b7ce..29050cb 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -224,6 +224,11 @@ inline struct state* state_st(enum state_t state) return &states[state]; } +guint get_transition_timer(void) +{ + return timeout_src_id; +} + void change_state_action(enum state_t state, int (*func)(int timeout)) { _I("[%s] 'action' is changed.", states[state].name); @@ -2106,8 +2111,9 @@ static void display_init(void *data) register_kernel_uevent_control(&lcd_uevent_ops); register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - register_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); - register_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); + register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); + register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); + register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); register_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); register_notifier(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, display_auto_brightness_sensing); @@ -2248,8 +2254,9 @@ static void display_exit(void *data) break; case INIT_POLL: unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - unregister_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); - unregister_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); + unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); + unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); + unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 94a6503..41cecfd 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -222,6 +222,11 @@ inline struct state* state_st(enum state_t state) return &states[state]; } +guint get_transition_timer(void) +{ + return timeout_src_id; +} + void change_state_action(enum state_t state, int (*func)(int timeout)) { _I("[%s] 'action' is changed.", states[state].name); @@ -2097,8 +2102,9 @@ static void display_init(void *data) register_kernel_uevent_control(&lcd_uevent_ops); register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - register_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); - register_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); + register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); + register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); + register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); register_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); register_notifier(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, display_auto_brightness_sensing); @@ -2239,8 +2245,9 @@ static void display_exit(void *data) break; case INIT_POLL: unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - unregister_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); - unregister_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); + unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); + unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); + unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 3d13b4c..6596a70 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -244,6 +244,11 @@ inline struct state *state_st(enum state_t state) return &states[state]; } +guint get_transition_timer(void) +{ + return timeout_src_id; +} + void change_state_action(enum state_t state, int (*func)(int timeout)) { _I("[%s] 'action' is changed.", states[state].name); @@ -2440,8 +2445,9 @@ static void display_init(void *data) register_kernel_uevent_control(&sec_dsim_uevent_ops); register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - register_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); - register_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); + register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); + register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); + register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); register_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); register_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); register_notifier(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING, display_auto_brightness_sensing); @@ -2583,8 +2589,9 @@ static void display_exit(void *data) break; case INIT_POLL: unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - unregister_notifier(DEVICE_NOTIFIER_PROCESS_BACKGROUND, process_background); - unregister_notifier(DEVICE_NOTIFIER_PROCESS_FOREGROUND, process_foreground); + unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); + unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); + unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); diff --git a/src/apps/apps.c b/src/apps/apps.c index 1debfa6..8e1923b 100644 --- a/src/apps/apps.c +++ b/src/apps/apps.c @@ -21,11 +21,14 @@ #include "core/common.h" #include "apps.h" #include "shared/plugin.h" +#include "core/bitmap.h" #define POPUP_METHOD "PopupLaunch" #define BUFF_MAX 255 static struct display_plugin *disp_plgn; +static struct dd_bitmap *bm_background; +static int pid_max; static const struct app_dbus_match { const char *type; @@ -173,9 +176,51 @@ int remove_notification(char *type, int id) __cb, -1, NULL); } +bool is_app_background(pid_t pid) +{ + return test_bit(bm_background, pid); +} + +void init_bm_background(void) +{ + int ret; + + ret = sys_get_int("/proc/sys/kernel/pid_max", &pid_max); + if (ret < 0) + pid_max = 32768; + + /* need (pid_max + 1) bits to represent pid 0 ~ pid_max */ + bm_background = init_bitmap(pid_max + 1); + if (!bm_background) + _E("Failed to allock bm_background."); +} + +void set_app_state(pid_t pid, enum application_state as) +{ + if (!bm_background) + return; + + if (pid < 0 || pid > pid_max) + return; + + if (as == APPLICATION_BACKGROUND) + set_bit(bm_background, pid); + else if (as == APPLICATION_FOREGROUND || as == APPLICATION_TERMINATED) + clear_bit(bm_background, pid); + else + _E("Invalid as=%d", as); +} + static void __CONSTRUCTOR__ initialize(void) { disp_plgn = get_var_display_plugin(); if (!disp_plgn) _E("Failed to get display plugin variable."); + + init_bm_background(); +} + +static void __DESTRUCTOR__ finalize(void) +{ + deinit_bitmap(bm_background); } diff --git a/src/apps/apps.h b/src/apps/apps.h index 5e1b393..80daf7d 100644 --- a/src/apps/apps.h +++ b/src/apps/apps.h @@ -32,10 +32,17 @@ #define APP_REMOVE "remove" #define APP_KEY_TYPE "_SYSPOPUP_CONTENT_" +enum application_state { + APPLICATION_TERMINATED = 0, + APPLICATION_FOREGROUND, + APPLICATION_BACKGROUND, /* deactivate NORMAL, DIM lock */ +}; + int launch_system_app(char *type, int num, ...); int launch_message_post(char *type); int add_async_notification(char *type, dbus_pending_cb func, char *sig, ...); int remove_notification(char *type, int id); - +void set_app_state(pid_t pid, enum application_state as); +bool is_app_background (pid_t pid); #endif /* __APPS_H__ */ diff --git a/src/core/device-notifier.c b/src/core/device-notifier.c index 3f8d1b6..78dc63a 100644 --- a/src/core/device-notifier.c +++ b/src/core/device-notifier.c @@ -60,8 +60,9 @@ static const char *device_notifier_type_str[DEVICE_NOTIFIER_MAX] = { NOTIFY_STR(DEVICE_NOTIFIER_DISPLAY_LOCK), NOTIFY_STR(DEVICE_NOTIFIER_POWER_RESUME), NOTIFY_STR(DEVICE_NOTIFIER_POWEROFF), - NOTIFY_STR(DEVICE_NOTIFIER_PROCESS_BACKGROUND), - NOTIFY_STR(DEVICE_NOTIFIER_PROCESS_FOREGROUND), + NOTIFY_STR(DEVICE_NOTIFIER_APPLICATION_BACKGROUND), + NOTIFY_STR(DEVICE_NOTIFIER_APPLICATION_FOREGROUND), + NOTIFY_STR(DEVICE_NOTIFIER_APPLICATION_TERMINATED), NOTIFY_STR(DEVICE_NOTIFIER_USB_DEBUG_MODE), NOTIFY_STR(DEVICE_NOTIFIER_USB_TETHERING_MODE), NOTIFY_STR(DEVICE_NOTIFIER_EVENT_HANDLER), diff --git a/src/core/device-notifier.h b/src/core/device-notifier.h index 6362a82..f8f190d 100644 --- a/src/core/device-notifier.h +++ b/src/core/device-notifier.h @@ -39,8 +39,9 @@ enum device_notifier_type { DEVICE_NOTIFIER_DISPLAY_LOCK, DEVICE_NOTIFIER_POWER_RESUME, DEVICE_NOTIFIER_POWEROFF, - DEVICE_NOTIFIER_PROCESS_BACKGROUND, - DEVICE_NOTIFIER_PROCESS_FOREGROUND, + DEVICE_NOTIFIER_APPLICATION_BACKGROUND, + DEVICE_NOTIFIER_APPLICATION_FOREGROUND, + DEVICE_NOTIFIER_APPLICATION_TERMINATED, DEVICE_NOTIFIER_USB_DEBUG_MODE, DEVICE_NOTIFIER_USB_TETHERING_MODE, DEVICE_NOTIFIER_EVENT_HANDLER, diff --git a/src/display/core.h b/src/display/core.h index 00c3e27..a819135 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -214,6 +214,7 @@ bool touch_event_blocked(void); void broadcast_lcd_off_late(enum device_flags flags); void set_dim_state(bool on); void reset_timeout(int timeout); +guint get_transition_timer(void); /* auto-brightness.c */ void set_brightness_changed_state(void); diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 846c67e..5fa2168 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -43,10 +43,12 @@ #include "display-ops.h" #include "display.h" #include "shared/plugin.h" +#include "display-lock.h" #define AUL_APPSTATUS_PATH "/Org/Tizen/Aul/AppStatus" #define AUL_APPSTATUS_INTERFACE "org.tizen.aul.AppStatus" #define APP_CHANGE_STATE "AppStatusChange" +#define APP_TERMINATED "AppTerminated" #define TELEPHONY_PATH "/org/tizen/telephony" #define TELEPHONY_INTERFACE_SIM "org.tizen.telephony.Manager" @@ -1302,10 +1304,12 @@ static void changestate_signal_handler(GDBusConnection *conn, if (!strcmp(state, "bg")) { _D("process(%d) was going background.", pid); - device_notify(DEVICE_NOTIFIER_PROCESS_BACKGROUND, &pid); + set_app_state(pid, APPLICATION_BACKGROUND); + device_notify(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, &pid); } else if (!strcmp(state, "fg")) { _D("process(%d) was going foreground.", pid); - device_notify(DEVICE_NOTIFIER_PROCESS_FOREGROUND, &pid); + set_app_state(pid, APPLICATION_FOREGROUND); + device_notify(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, &pid); } out: @@ -1313,6 +1317,25 @@ out: g_free(state); } +static void app_terminate_signal_handler(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *name, + GVariant *param, + gpointer data) +{ + pid_t pid; + + if (!g_variant_get_safe(param, "(i)", &pid)) { + _E("failed to get params from gvariant. expected:%s, type:%s", "(i)", g_variant_get_type_string(param)); + return; + } + + set_app_state(pid, APPLICATION_TERMINATED); + device_notify(DEVICE_NOTIFIER_APPLICATION_TERMINATED, &pid); +} + /* * Default capability * api := LCDON | LCDOFF | BRIGHTNESS @@ -1351,6 +1374,15 @@ int init_pm_dbus(void) if (ret <= 0) _E("Failed to register signal handler: %d", ret); + ret = subscribe_dbus_signal(NULL, + AUL_APPSTATUS_PATH, + AUL_APPSTATUS_INTERFACE, + APP_TERMINATED, + app_terminate_signal_handler, + NULL, NULL); + if (ret <= 0) + _E("Failed to register signal handler: %d", ret); + return 0; } diff --git a/src/display/display-lock.c b/src/display/display-lock.c index 2df1497..ade3cd1 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -24,15 +24,20 @@ #include "core/common.h" #include "device-interface.h" #include "poll.h" +#include "display.h" #include "display-signal.h" #include "lock-detector.h" #include "display-lock.h" #include "shared/log-macro.h" +#include "apps/apps.h" #define METHOD_APP_STATUS "CheckAppStatus" #define PID_MAX 6 #define LOCK_TIME_WARNING 60 /* 60 seconds */ +#define no_transition_timer() (get_transition_timer() == 0) +#define no_foreground_lock(st) (check_lock_state(st) == false) + static struct _backlight_ops *backlight_ops; static dd_list *cond_head[S_END]; static int trans_condition; @@ -45,14 +50,14 @@ bool check_lock_state(int state) PmLockNode *t; DD_LIST_FOREACH(cond_head[state], elem, t) { - if (t->background == false) + if (t->app_background == false) return true; } return false; } -static void refresh_app_cond() +static void refresh_app_cond(void) { trans_condition = 0; @@ -216,7 +221,12 @@ PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, n->timeout_id = timeout_id; n->time = now; n->holdkey_block = holdkey_block; - n->background = false; + /* LCDOFF lock should be maintained regardless of fg/bg state */ + if (n->state == S_NORMAL || n->state == S_LCDDIM) { + n->app_background = is_app_background(n->pid); + if (n->app_background) + _W("App(%d) requested %d lock in background.", n->pid, n->state); + } n->broadcast_warning = true; if (pid < INTERNAL_LOCK_BASE) { @@ -274,7 +284,7 @@ int check_lock_condition(enum state_t state) _D("check holdkey block : state of %s", state_st(state)->name); DD_LIST_FOREACH(cond_head[state], elem, t) { - if (t->pid != owner && t->background == false) { + if (t->pid != owner && t->app_background == false) { ret = true; _I("state change was blocked by pid(%d)!", t->pid); break; @@ -411,7 +421,7 @@ dd_list *get_cond_head(enum state_t s_index) return cond_head[s_index]; } -int process_background(void *data) +int display_app_background(void *data) { pid_t pid; PmLockNode *node; @@ -420,20 +430,20 @@ int process_background(void *data) node = find_node(S_NORMAL, pid); if (node) { - node->background = true; - _I("Process(%d) goes background. LCD_NORMAL will be unlocked.", pid); + node->app_background = true; + _I("App(%d) goes background. LCD_NORMAL will be unlocked.", pid); } node = find_node(S_LCDDIM, pid); if (node) { - node->background = true; - _I("Process(%d) goes background. LCD_DIM will be unlocked.", pid); + node->app_background = true; + _I("App(%d) goes background. LCD_DIM will be unlocked.", pid); } return 0; } -int process_foreground(void *data) +int display_app_foreground(void *data) { pid_t pid; PmLockNode *node; @@ -442,19 +452,55 @@ int process_foreground(void *data) node = find_node(S_NORMAL, pid); if (node) { - node->background = false; - _I("Process(%d) goes foreground. LCD_NORMAL will be locked.", pid); + node->app_background = false; + _I("App(%d) goes foreground. LCD_NORMAL will be locked.", pid); } node = find_node(S_LCDDIM, pid); if (node) { - node->background = false; - _I("Process(%d) goes foreground. LCD_DIM will be locked.", pid); + node->app_background = false; + _I("App(%d) goes foreground. LCD_DIM will be locked.", pid); } return 0; } +int display_app_terminated(void *data) +{ + pid_t pid; + PmLockNode *node; + enum state_t state; + enum state_t cur = get_pm_cur_state(); + bool current_unlocked = false; + + pid = *(pid_t *)data; + + /* release lock if it is holding locks */ + for (state = S_START; state < S_END; ++state) { + node = find_node(state, pid); + if (node) { + _W("App=%d is terminated without releasing lockstate=%d. deviced unlocks it.", pid, state); + del_node(state, node); + set_unlock_time(pid, state); + if (state == cur) + current_unlocked = true; + } + } + + /* Change state only when all three conditions below are satisfied. + * 1. the lock released due to the termination of the application + * must be a lock for the current state + * 2. after releasing the lock, there is no foreground lock + * for the current state + * 3. there should be no running state-transition timer + * + * This emulates already expired transition timer */ + if (current_unlocked && no_foreground_lock(cur) && no_transition_timer()) + reset_timeout(0); + + return 0; +} + /* update transition condition for application requrements */ void update_lock_timer(PMMsg *data, PmLockNode *node, guint timeout_id) diff --git a/src/display/display-lock.h b/src/display/display-lock.h index 42c1853..3e83771 100644 --- a/src/display/display-lock.h +++ b/src/display/display-lock.h @@ -34,7 +34,7 @@ typedef struct _pm_lock_node { GVariant *warning_param; time_t time; bool holdkey_block; - bool background; + bool app_background; bool broadcast_warning; /* Set true when the lock holder is an entry of @@ -62,10 +62,10 @@ void makeup_trans_condition(void); int check_processes(enum state_t prohibit_state); int get_trans_condition(void); dd_list *get_cond_head(enum state_t s_index); -int process_background(void *data); -int process_foreground(void *data); +int display_app_background(void *data); +int display_app_foreground(void *data); +int display_app_terminated(void *data); void update_lock_timer(PMMsg *data, PmLockNode *node, guint timeout_id); - extern int custom_holdkey_block; #endif /* __DISPLAY_LOCK_H__ */ -- 2.7.4 From 86777773919c53dfd5d2b8abe406f4e64c5998fb Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 24 Nov 2020 13:59:59 +0900 Subject: [PATCH 03/16] Make critical-log configurable Change-Id: I67eb3788a78f5ce02dacb85f8c3398d5f54fd947 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 2 +- conf/critical-log.conf | 13 ------------- packaging/deviced.spec | 1 + src/shared/log-macro.h | 6 ++++++ 4 files changed, 8 insertions(+), 14 deletions(-) delete mode 100644 conf/critical-log.conf diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bfcc69..b104d6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -282,7 +282,7 @@ IF(USB_MODULE STREQUAL on) ENDIF() IF(CRITICAL_LOG_MODULE STREQUAL on) - INSTALL_CONF(conf critical-log) + ADD_DEFINITIONS("-DCRITICAL_LOG_ON") ENDIF() CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) diff --git a/conf/critical-log.conf b/conf/critical-log.conf deleted file mode 100644 index 0f76445..0000000 --- a/conf/critical-log.conf +++ /dev/null @@ -1,13 +0,0 @@ -#Critical Log will be saved under the /var/log/ghost/boot/#booting_count -#Critical Log Format is "Section|String Value" -#Limit means Last Critical Log Logging Count -[Common] -Limit=100 -[Battery] -Limit=20 -[BatteryHealth] -Limit=10 -[PowerHandle] -Limit=10 -[CoolDown] -Limit=10 diff --git a/packaging/deviced.spec b/packaging/deviced.spec index db438a9..bd7d771 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -165,6 +165,7 @@ Plugin libraries for IoT devices -DTOUCH_SENSITIVITY_MODULE=on \ -DDUMP_MODULE=on \ -DDEVICE_BOARD_MODULE=on \ + -DCRITICAL_LOG_MODULE=on \ #eol %build diff --git a/src/shared/log-macro.h b/src/shared/log-macro.h index 773ea44..440300f 100644 --- a/src/shared/log-macro.h +++ b/src/shared/log-macro.h @@ -22,9 +22,14 @@ #ifdef ENABLE_DLOG #include + /* critical log */ +#ifdef CRITICAL_LOG_ON #define CRITICAL_LOG(fmt, arg...) \ do { CRITICAL_LOG_(LOG_ID_SYSTEM, DLOG_INFO, LOG_TAG, fmt, ##arg); } while (0) +#else +#define CRITICAL_LOG(fmt, arg...) _I(fmt, ##arg) +#endif #define _D(fmt, arg...) \ do { SLOGD(fmt, ##arg); } while (0) @@ -43,6 +48,7 @@ #define _SE(fmt, arg...) \ do { SECURE_SLOGE(fmt, ##arg); } while (0) #else +#define CRITICAL_LOG(...) do { } while (0) #define _D(...) do { } while (0) #define _I(...) do { } while (0) #define _W(...) do { } while (0) -- 2.7.4 From 61ee007663fa4a0dccfde0a4de0ae6163d335bed Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Fri, 27 Nov 2020 19:06:00 +0900 Subject: [PATCH 04/16] usb: change usb initialization - skip usb hal operation when usb is disconnected. If USB is initialized without a USB connection, only initialize the internal usb state and skip usb hal operation. To support sdb over BT, sdbd.service should start automatically at boot time. If usb cable is not connected, usb hal stops sdbd.service when initializing usb. Change-Id: I936d0a62b5d3a0e8229ff02760e1a6d23081a003 --- src/usb/usb.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/usb/usb.c b/src/usb/usb.c index 407edde..f85bba3 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -386,7 +386,7 @@ int usb_change_mode(unsigned int new_mode, bool change_debug_mode) static int usb_state_changed(const char *index, int new_status) { int ret = -1; - static int old_status = -1; + static int old_status = -1; /* -1: Uninitialized, 0: disconnected, 1: connected */ /* For debugging. Do not move the location. */ _I("USB state is changed by extcon from (%d) to (%d).", old_status, new_status); @@ -400,7 +400,21 @@ static int usb_state_changed(const char *index, int new_status) break; case USB_DISCONNECTED: - ret = usb_disconnected(); + if (old_status == -1) { + /* only initialize the internal data state and skip usb hal operation. */ + _I("USB is initialized without USB connection"); + + /* From usb_disconnected() */ + usb_state_set_connection(USB_DISCONNECTED); + send_usb_state_changed_event(VCONFKEY_SYSMAN_USB_DISCONNECTED); + + /* From usb_disable() */ + (void)usb_state_set_current_mode(USB_FUNCTION_NONE); + change_usb_state_notification_handler(USB_FUNCTION_NONE); + + ret = 0; + } else + ret = usb_disconnected(); break; default: -- 2.7.4 From 0358d4d97b46271901ba866260504f81a8b0b32e Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 3 Dec 2020 17:00:46 +0900 Subject: [PATCH 05/16] Remove unused function low-power low-power.c is not used and duplicated with powersaver.c Change-Id: I8e93891c41d83710d26e6d4ecbc2c9a5a77bc7bd Signed-off-by: lokilee73 --- conf/org.tizen.system.deviced.conf | 2 - src/auto-test/power.c | 90 +--------------- src/power/low-power.c | 212 ------------------------------------- 3 files changed, 2 insertions(+), 302 deletions(-) delete mode 100644 src/power/low-power.c diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index 4d99362..bafc8fa 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -60,8 +60,6 @@ - - diff --git a/src/auto-test/power.c b/src/auto-test/power.c index 2a88a98..29b6a3c 100644 --- a/src/auto-test/power.c +++ b/src/auto-test/power.c @@ -20,10 +20,6 @@ #define METHOD_POWEROFF "PowerOff" #define METHOD_POWEROFF_WITH_OPTION "PowerOffWithOption" -#define METHOD_LOWPOWER_START "Start" -#define METHOD_LOWPOWER_STOP "Stop" -#define METHOD_LOWPOWER_GETSTATE "GetState" - static bool set_reboot_method(const char *method, GVariant *param) { GVariant *msg; @@ -68,77 +64,6 @@ static bool set_reboot_with_option(char *type, char *option) return set_reboot_method(METHOD_POWEROFF_WITH_OPTION, g_variant_new("(ss)", type, option)); } -static bool request_lowpower_method(const char *method, GVariant *param) -{ - GVariant *msg; - int val; - bool ret = FALSE; - int retry = 0; - - while (retry++ < 3) { - msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, - DEVICED_PATH_LOWPOWER, - DEVICED_INTERFACE_LOWPOWER, - method, - param); - if (!msg) { - _E("fail (%s): no reply", method); - return ret; - } - - if (!g_variant_get_safe(msg, "(i)", &val)) - _E("fail (%s): no message", method); - else { - if (val == -EAGAIN) { - g_variant_unref(msg); - _I("wait! will try again! (%s): %d", method, val); - sleep(3); - continue; - } else if ((val == -ENOTSUP) || (val == -ENOSYS)) { - _I("Not supported feature! (%s): %d", method, val); - ret = TRUE; - } else if (val < 0) { - _E("fail (%s): returned fail (%d)", method, val); - } else { - _I("success (%s): %d", method, val); - ret = TRUE; - } - } - g_variant_unref(msg); - break; - } - - return ret; -} - -static bool set_lowpower_start() -{ - return request_lowpower_method(METHOD_LOWPOWER_START, NULL); -} - -static bool set_lowpower_stop() -{ - return request_lowpower_method(METHOD_LOWPOWER_STOP, NULL); -} - -static bool set_lowpower_getstate() -{ - return request_lowpower_method(METHOD_LOWPOWER_GETSTATE, NULL); -} - -void lowpower_test_all(int *success, int *fail) -{ - int s = 0; - int f = 0; - - (set_lowpower_start()) ? s++ : f++; - (set_lowpower_stop()) ? s++ : f++; - (set_lowpower_getstate()) ? s++ : f++; - - if (NULL != success) *success = s; - if (NULL != fail) *fail = f; -} - static void power_init(void *data) { int success = 0; @@ -146,8 +71,6 @@ static void power_init(void *data) _I("start test"); - lowpower_test_all(&success, &fail); - _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail); } @@ -163,22 +86,13 @@ static int power_unit(int argc, char **argv) int fail = 0; _I("start test"); - lowpower_test_all(&success, &fail); + _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail); } else if (0 == strcmp(argv[3], METHOD_POWEROFF)) set_reboot(argv[4]); else if (0 == strcasecmp(argv[3], METHOD_POWEROFF_WITH_OPTION)) set_reboot_with_option(argv[4], argv[5]); - else if (0 == strcasecmp(argv[3], "lowpower")) { - if (0 == strcasecmp(argv[4], METHOD_LOWPOWER_START)) - set_lowpower_start(); - else if (0 == strcasecmp(argv[4], METHOD_LOWPOWER_STOP)) - set_lowpower_stop(); - else if (0 == strcasecmp(argv[4], METHOD_LOWPOWER_GETSTATE)) - set_lowpower_getstate(); - else - _E("Unknown test case!!!"); - } else + else _E("Unknown test case!!!"); return 0; diff --git a/src/power/low-power.c b/src/power/low-power.c deleted file mode 100644 index 9e77a79..0000000 --- a/src/power/low-power.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2016 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include - -#include "core/log.h" -#include "core/device-notifier.h" -#include "core/device-idler.h" -#include "core/common.h" -#include "core/devices.h" - -#ifndef VCONFKEY_SYSMAN_LOW_POWER_MODE -#define VCONFKEY_SYSMAN_LOW_POWER_MODE "db/sysman/low_power_mode" -#define VCONFKEY_SYSMAN_LOW_POWER_MODE_OFF 0 -#define VCONFKEY_SYSMAN_LOW_POWER_MODE_ON 1 -#endif - -static bool low_power_enabled; - -static int low_power_start(void *data) -{ - int ret; - - if (low_power_enabled) - return 0; - - ret = vconf_set_int(VCONFKEY_SYSMAN_LOW_POWER_MODE, - VCONFKEY_SYSMAN_LOW_POWER_MODE_ON); - if (ret < 0) { - _E("Failed to set vconf value for low power mode: %d", vconf_get_ext_errno()); - return -ENOMEM; - } - - low_power_enabled = true; - _I("Low Power Mode Start."); - - return 0; -} - -static int low_power_stop(void *data) -{ - int ret; - - if (!low_power_enabled) - return 0; - - ret = vconf_set_int(VCONFKEY_SYSMAN_LOW_POWER_MODE, - VCONFKEY_SYSMAN_LOW_POWER_MODE_OFF); - if (ret < 0) { - _E("Failed to set vconf value for low power mode: %d", vconf_get_ext_errno()); - return -ENOMEM; - } - - low_power_enabled = false; - _I("Low Power Mode Stop."); - - return 0; -} - -static int booting_done(void *data) -{ - static int done = 0; - int mode, ret; - - if (data == NULL) - goto out; - if (done) - goto out; - - done = *(int*)data; - - ret = vconf_get_int(VCONFKEY_SYSMAN_LOW_POWER_MODE, &mode); - if (ret == 0 && mode == VCONFKEY_SYSMAN_LOW_POWER_MODE_ON) { - _I("Low Power Mode Start."); - low_power_enabled = true; - } else if (ret < 0) - _E("Failed to get vconf value for low power mode: %d", vconf_get_ext_errno()); - -out: - return done; -} - -static GVariant *dbus_low_power_start(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - pid_t pid; - - if (!booting_done(NULL)) { - _I("Booting is not done yet."); - ret = -EAGAIN; - goto out; - } - - pid = dbus_connection_get_sender_pid(conn, sender); - if (pid == -1 || kill(pid, 0) == -1) { - _E("Sender(%d) does not exist.", pid); - ret = -EINVAL; - goto out; - } - - _I("Low Power Mode started by PID(%d).", pid); - ret = low_power_start(NULL); - if (ret < 0) - _E("Failed to start Low Power Mode(%d).", ret); - -out: - return g_variant_new("(i)", ret); -} - -static GVariant *dbus_low_power_stop(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - int ret; - pid_t pid; - - if (!booting_done(NULL)) { - _I("Booting is not done yet."); - ret = -EAGAIN; - goto out; - } - - pid = dbus_connection_get_sender_pid(conn, sender); - if (pid == -1 || kill(pid, 0) == -1) { - _E("Sender(%d) does not exist.", pid); - ret = -EINVAL; - goto out; - } - - _I("Low Power Mode stopped by PID(%d).", pid); - ret = low_power_stop(NULL); - if (ret < 0) - _E("Failed to stop Low Power Mode(%d).", ret); - -out: - return g_variant_new("(i)", ret); -} - -static GVariant *dbus_low_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("(i)", (low_power_enabled ? 1 : 0)); -} - -static const dbus_method_s dbus_methods[] = { - { "Start", NULL, "i", dbus_low_power_start }, - { "Stop", NULL, "i", dbus_low_power_stop }, - { "GetState", NULL, "i", dbus_low_power_get_state }, - /* Add methods here */ -}; - -static const dbus_interface_u dbus_interface = { - .oh = NULL, - .name = DEVICED_INTERFACE_LOWPOWER, - .methods = dbus_methods, - .nr_methods = ARRAY_SIZE(dbus_methods), -}; - -static void low_power_init(void *data) -{ - int ret; - - /* init dbus interface */ - ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_LOWPOWER, &dbus_interface); - if (ret < 0) - _E("Failed to init dbus method(%d).", ret); - - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); -} - -static void low_power_exit(void *data) -{ - int ret; - - ret = low_power_stop(NULL); - if (ret < 0) - _E("Failed to stop Low Power Mode(%d).", ret); - - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); -} - -static const struct device_ops low_power_device_ops = { - .name = "low-power", - .init = low_power_init, - .exit = low_power_exit, -}; - -DEVICE_OPS_REGISTER(&low_power_device_ops) -- 2.7.4 From 464cfb4ca23a21f652412cc479805f6f2e405bb9 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 4 Dec 2020 14:53:46 +0900 Subject: [PATCH 06/16] Fix typo Change-Id: I16ff0cf0d03650cdfc909906c9b3e7f959dd6f03 Signed-off-by: lokilee73 --- plugins/iot/display/core.c | 21 +++++++++++---------- plugins/mobile/display/core.c | 21 +++++++++++---------- plugins/tv/display/core.c | 21 +++++++++++---------- plugins/wearable/display/core.c | 22 +++++++++++----------- src/display/display-lock.c | 2 +- src/usbhost/usb-host.c | 10 +++++----- 6 files changed, 50 insertions(+), 47 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 13f389e..acb6790 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -345,19 +345,20 @@ void lcd_on_procedure(int state, enum device_flags flag) unsigned long flags = get_lcd_on_flags(); flags |= flag; - leave_doze(); - /* * Display on procedure - * step 1. broadcast lcd on signal with cause - * step 2. set brightness - * step 3. set pmstate of vconf - * step 4. display on operate + * step 1. leave doze + * step 2. broadcast lcd on signal with cause + * step 3. set brightness + * step 4. set pmstate of vconf + * step 5. display on operate * - a. display on * - b. TSP(touch screen) and touchkey enable - * step 5. broadcast lcd on complete siganl - * step 6. key backlight enable + * step 6. broadcast lcd on complete signal + * step 7. key backlight enable */ + leave_doze(); + _I("[lcdstep] 0x%lx", flags); if (flags & AMBIENT_MODE) { @@ -836,7 +837,7 @@ int display_on_by_reason(const char *reason, int timeout) else if (!strncmp(reason, EVENT_STR, str_len)) flag = LCD_ON_BY_EVENT; else { - _E("Reason is unkown(%s)", reason); + _E("Reason is unknown(%s)", reason); return -EINVAL; } @@ -888,7 +889,7 @@ int display_off_by_reason(const char *reason) flag = LCD_OFF_BY_PALM; } else { - _E("Reason is unkown(%s)", reason); + _E("Reason is unknown(%s)", reason); return -EINVAL; } diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 29050cb..693f4a4 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -353,19 +353,20 @@ void lcd_on_procedure(int state, enum device_flags flag) unsigned long flags = get_lcd_on_flags(); flags |= flag; - leave_doze(); - /* * Display on procedure - * step 1. broadcast lcd on signal with cause - * step 2. set brightness - * step 3. set pmstate of vconf - * step 4. display on operate + * step 1. leave doze + * step 2. broadcast lcd on signal with cause + * step 3. set brightness + * step 4. set pmstate of vconf + * step 5. display on operate * - a. display on * - b. TSP(touch screen) and touchkey enable - * step 5. broadcast lcd on complete siganl - * step 6. key backlight enable + * step 6. broadcast lcd on complete signal + * step 7. key backlight enable */ + leave_doze(); + _I("[lcdstep] 0x%lx", flags); if (flags & AMBIENT_MODE) { @@ -844,7 +845,7 @@ int display_on_by_reason(const char *reason, int timeout) else if (!strncmp(reason, EVENT_STR, str_len)) flag = LCD_ON_BY_EVENT; else { - _E("Reason is unkown(%s)", reason); + _E("Reason is unknown(%s)", reason); return -EINVAL; } @@ -896,7 +897,7 @@ int display_off_by_reason(const char *reason) flag = LCD_OFF_BY_PALM; } else { - _E("Reason is unkown(%s)", reason); + _E("Reason is unknown(%s)", reason); return -EINVAL; } diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 41cecfd..1a8af7f 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -346,19 +346,20 @@ void lcd_on_procedure(int state, enum device_flags flag) unsigned long flags = get_lcd_on_flags(); flags |= flag; - leave_doze(); - /* * Display on procedure - * step 1. broadcast lcd on signal with cause - * step 2. set brightness - * step 3. set pmstate of vconf - * step 4. display on operate + * step 1. leave doze + * step 2. broadcast lcd on signal with cause + * step 3. set brightness + * step 4. set pmstate of vconf + * step 5. display on operate * - a. display on * - b. TSP(touch screen) and touchkey enable - * step 5. broadcast lcd on complete siganl - * step 6. key backlight enable + * step 6. broadcast lcd on complete signal + * step 7. key backlight enable */ + leave_doze(); + _I("[lcdstep] 0x%lx", flags); if (flags & AMBIENT_MODE) { @@ -837,7 +838,7 @@ int display_on_by_reason(const char *reason, int timeout) else if (!strncmp(reason, EVENT_STR, str_len)) flag = LCD_ON_BY_EVENT; else { - _E("Reason is unkown(%s)", reason); + _E("Reason is unknown(%s)", reason); return -EINVAL; } @@ -889,7 +890,7 @@ int display_off_by_reason(const char *reason) flag = LCD_OFF_BY_PALM; } else { - _E("Reason is unkown(%s)", reason); + _E("Reason is unknown(%s)", reason); return -EINVAL; } diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 6596a70..1f1bf44 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -554,20 +554,20 @@ void lcd_on_procedure(int state, enum device_flags flag) flags |= flag; int ret; - leave_doze(); - /* * Display on procedure - * step 0. check if display is detached (only for factory mode) - * step 1. broadcast lcd on signal with cause - * step 2. set brightness - * step 3. set pmstate of vconf - * step 4. display on operate + * step 1. leave doze + * step 2. check if display is detached (only for factory mode) + * step 3. broadcast lcd on signal with cause + * step 4. set brightness + * step 5. set pmstate of vconf + * step 6. display on operate * - a. display on * - b. TSP(touch screen) and touchkey enable - * step 5. broadcast lcd on complete signal - * step 6. key backlight enable + * step 7. broadcast lcd on complete signal + * step 8. key backlight enable */ + leave_doze(); ret = is_lcdon_blocked(); if (ret != LCDON_BLOCK_NONE) { @@ -1089,7 +1089,7 @@ int display_on_by_reason(const char *reason, int timeout) else if (!strncmp(reason, EVENT_STR, str_len)) flag = LCD_ON_BY_EVENT; else { - _E("Reason is unkown(%s)", reason); + _E("Reason is unknown(%s)", reason); return -EINVAL; } @@ -1736,7 +1736,7 @@ static int default_action(int timeout) states[get_pm_cur_state()].name, last_timeout, diff); } - /* update status for batter monitor */ + /* update status for battery monitor */ update_bds_record(get_pm_cur_state()); switch (get_pm_cur_state()) { diff --git a/src/display/display-lock.c b/src/display/display-lock.c index ade3cd1..ad1b27b 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -373,7 +373,7 @@ void print_node(int next) g_variant_new("(i)", n->pid)); if (ret < 0) _E("Failed to send dbus signal pmlock_over."); - n->broadcast_warning = false; + n->broadcast_warning = false; } _W("Over(%.0f s) pid( %5d) lock time(%s)", diff, n->pid, buf); } else diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 83dacf3..e99777a 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -833,9 +833,9 @@ static void finish_opening(struct usbhost_open_request *req, int policy) goto out; } - /* send along the stdin in case - * g_application_command_line_get_stdin_data() is called - */ + /** send along the stdin in case + * g_application_command_line_get_stdin_data() is called + */ fd_list = g_unix_fd_list_new(); if (g_unix_fd_list_append(fd_list, fd, &error) < 0) { _E("Failed to append fd in unix fd list: %s\n", error->message); @@ -1116,7 +1116,7 @@ static const dbus_interface_u dbus_interface = { static int booting_done(void *data) { /** - * To search the attched usb host device is not an argent task. + * To search the attched usb host device is not an urgent task. * So deviced does not load while booting time. * After booting task is done, it tries to find the attached devices. */ @@ -1166,7 +1166,7 @@ static void usbhost_exit(void *data) { int ret; - /* unreigset usbhost uevent */ + /* unregister usbhost uevent */ ret = unregister_kernel_uevent_control(&uh); if (ret < 0) _E("Failed to unregister usb uevent: %d", ret); -- 2.7.4 From a3b95ed49c5f278817416ac45fa96753d36e9c18 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 14 Dec 2020 15:31:59 +0900 Subject: [PATCH 07/16] Fix infinite recursive call for AOD corner case The subroutine triggered by lcd_off_procedure() could lead infinite recursive call. This can happen when the lcd_off_procedure() do not serve actual DPMS_OFF, remaining display state as DPMS_ON even after the call. One of the case is when the clockend signal arrives late. In this situation, deviced forces to set ambient_state as false, but actual node of lcd power remains ON. This combination of two state* makes deviced perceive dpms state as DPMS_ON. As a result, lcd_off_procedure() has been processed, but deviced still recognize dpms state as DPMS_ON, triggering recursive call for lcd_off_procedure() to turning off display. [*] ambient_state=>false && lcd node=>ON Possible callstack of recursive call del_state_cond -> default_trans -> default_action -> lcd_off_procedure** -> ambient_set_state(true) -> pm_lock_internal -> proc_condition -> proc_condition_lock -> proc_change_state -> lcd_off_procedure [repeat **] To fix this, leave ambient_state as it is when clockend arrival is delayed. This makes deviced perceive DPMS state as DPMS_OFF, and it won't trigger lcd_off_procedure(). Change-Id: I14ccca1ba7718975752389cd409a775fbfe80ada Signed-off-by: Youngjae Cho --- src/display/ambient-mode.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index fdf58e4..5fecba8 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -155,7 +155,6 @@ void ambient_check_invalid_state(pid_t pid) */ reset_timeout(TIMEOUT_NONE); - ambient_set_state(false); lcd_direct_control(DPMS_OFF, NORMAL_MODE); broadcast_lcd_off_late(LCD_OFF_LATE_MODE); -- 2.7.4 From ecbfcb943a2302c580d850a9ebac4a5e3ed09fd7 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 15 Dec 2020 14:52:48 +0900 Subject: [PATCH 08/16] Check state trans condition strictly when lock expired Change-Id: I9090937aeaa31817228127d199b710871c166585 Signed-off-by: Youngjae Cho --- plugins/iot/display/core.c | 6 +++++- plugins/mobile/display/core.c | 6 +++++- plugins/tv/display/core.c | 6 +++++- plugins/wearable/display/core.c | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index acb6790..8c5803e 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -555,7 +555,11 @@ static void del_state_cond(void *data, enum state_t state) del_node(state, tmp); set_unlock_time(pid, state); - if (!timeout_src_id) + /* Change state only when the two conditions below are satisfied. + * 1. There should be no running state-transition timer + * 2. Released lock is one of the pm_cur_state's lock + * This emulates already expired transition timer */ + if (!timeout_src_id && get_pm_cur_state() == state) states[get_pm_cur_state()].trans(EVENT_TIMEOUT); if (state == S_LCDOFF) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 693f4a4..0a615c8 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -563,7 +563,11 @@ static void del_state_cond(void *data, enum state_t state) del_node(state, tmp); set_unlock_time(pid, state); - if (!timeout_src_id) + /* Change state only when the two conditions below are satisfied. + * 1. There should be no running state-transition timer + * 2. Released lock is one of the pm_cur_state's lock + * This emulates already expired transition timer */ + if (!timeout_src_id && get_pm_cur_state() == state) states[get_pm_cur_state()].trans(EVENT_TIMEOUT); if (state == S_LCDOFF) diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 1a8af7f..923e95a 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -556,7 +556,11 @@ static void del_state_cond(void *data, enum state_t state) del_node(state, tmp); set_unlock_time(pid, state); - if (!timeout_src_id) + /* Change state only when the two conditions below are satisfied. + * 1. There should be no running state-transition timer + * 2. Released lock is one of the pm_cur_state's lock + * This emulates already expired transition timer */ + if (!timeout_src_id && get_pm_cur_state() == state) states[get_pm_cur_state()].trans(EVENT_TIMEOUT); if (state == S_LCDOFF) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 1f1bf44..6a8e27f 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -771,7 +771,11 @@ static void del_state_cond(void *data, enum state_t state) del_node(state, tmp); set_unlock_time(pid, state); - if (!timeout_src_id) + /* Change state only when the two conditions below are satisfied. + * 1. There should be no running state-transition timer + * 2. Released lock is one of the pm_cur_state's lock + * This emulates already expired transition timer */ + if (!timeout_src_id && get_pm_cur_state() == state) states[get_pm_cur_state()].trans(EVENT_TIMEOUT); if (state == S_LCDOFF) -- 2.7.4 From 0aa8728d034f7056fc250d79a1899ef44dc30b51 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Fri, 11 Dec 2020 10:06:33 +0900 Subject: [PATCH 09/16] Rearrange device_notify(DEVICE_NOTIFIER_LCD_OFF, ..) And remove ambient_set_state() for other profiles except wearable device_notify(LCD_OFF) is triggered after ambient_set and LCD_OFF_PRE. Change-Id: I04c4608334a9627b0804f796056aa84dba5b567e Signed-off-by: Hyotaek Shim --- plugins/iot/display/core.c | 15 +++++++-------- plugins/mobile/display/core.c | 15 +++++++-------- plugins/tv/display/core.c | 15 +++++++-------- plugins/wearable/display/core.c | 13 +++++++++---- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 8c5803e..cfdbb67 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -436,20 +436,19 @@ inline void lcd_off_procedure(enum device_flags flag) */ _I("[lcdstep] 0x%lx", flags); - device_notify(DEVICE_NOTIFIER_LCD_OFF, NULL); - - touch_blocked = true; + /* notification */ - if (flags & AMBIENT_MODE) { - if (ambient_get_state() == true) - return; - ambient_set_state(true); - } + device_notify(DEVICE_NOTIFIER_LCD_OFF, NULL); if (lcdon_broadcast) { broadcast_lcd_off(SIGNAL_PRE, flags); lcdon_broadcast = false; } + + /* operation */ + + touch_blocked = true; + set_setting_pmstate(S_LCDOFF); if (CHECK_OPS(keyfilter_ops, backlight_enable)) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 0a615c8..cf8ab3d 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -444,20 +444,19 @@ inline void lcd_off_procedure(enum device_flags flag) */ _I("[lcdstep] 0x%lx", flags); - device_notify(DEVICE_NOTIFIER_LCD_OFF, NULL); - - touch_blocked = true; + /* notification */ - if (flags & AMBIENT_MODE) { - if (ambient_get_state() == true) - return; - ambient_set_state(true); - } + device_notify(DEVICE_NOTIFIER_LCD_OFF, NULL); if (lcdon_broadcast) { broadcast_lcd_off(SIGNAL_PRE, flags); lcdon_broadcast = false; } + + /* operation */ + + touch_blocked = true; + set_setting_pmstate(S_LCDOFF); if (CHECK_OPS(keyfilter_ops, backlight_enable)) diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 923e95a..35265fd 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -437,20 +437,19 @@ inline void lcd_off_procedure(enum device_flags flag) */ _I("[lcdstep] 0x%lx", flags); - device_notify(DEVICE_NOTIFIER_LCD_OFF, NULL); - - touch_blocked = true; + /* notification */ - if (flags & AMBIENT_MODE) { - if (ambient_get_state() == true) - return; - ambient_set_state(true); - } + device_notify(DEVICE_NOTIFIER_LCD_OFF, NULL); if (lcdon_broadcast) { broadcast_lcd_off(SIGNAL_PRE, flags); lcdon_broadcast = false; } + + /* operation */ + + touch_blocked = true; + set_setting_pmstate(S_LCDOFF); if (CHECK_OPS(keyfilter_ops, backlight_enable)) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 6a8e27f..f5e1b69 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -652,8 +652,17 @@ inline void lcd_off_procedure(enum device_flags flag) */ _I("[lcdstep] 0x%lx", flags); + /* notification */ + device_notify(DEVICE_NOTIFIER_LCD_OFF, NULL); + if (lcdon_broadcast) { + broadcast_lcd_off(SIGNAL_PRE, flags); + lcdon_broadcast = false; + } + + /* operation */ + touch_blocked = true; if (flags & AMBIENT_MODE) { @@ -662,10 +671,6 @@ inline void lcd_off_procedure(enum device_flags flag) ambient_set_state(true); } - if (lcdon_broadcast) { - broadcast_lcd_off(SIGNAL_PRE, flags); - lcdon_broadcast = false; - } set_setting_pmstate(S_LCDOFF); if (CHECK_OPS(keyfilter_ops, backlight_enable)) -- 2.7.4 From 6c4f3e93689a11fe7ec0a6d006d2a4b316b52dcc Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 15 Dec 2020 15:34:39 +0900 Subject: [PATCH 10/16] Fix typo Change-Id: I989aa70be85a684d789b042817871b786712d83e Signed-off-by: lokilee73 --- plugins/iot/display/core.c | 2 +- plugins/mobile/display/core.c | 2 +- plugins/tv/display/core.c | 2 +- plugins/wearable/display/core.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index cfdbb67..2c36504 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -545,7 +545,7 @@ static void del_state_cond(void *data, enum state_t state) /* A passed data is a pid_t type data, not a 64bit data. */ pid = (pid_t)((intptr_t)data); - _I("delete prohibit dim condition by timeout (%d)", pid); + _I("delete prohibit %s condition by timeout (%d)", states[state].name, pid); if (pid == INTERNAL_LOCK_AMBIENT) ambient_check_invalid_state(pid); diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index cf8ab3d..037e1e0 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -553,7 +553,7 @@ static void del_state_cond(void *data, enum state_t state) /* A passed data is a pid_t type data, not a 64bit data. */ pid = (pid_t)((intptr_t)data); - _I("delete prohibit dim condition by timeout (%d)", pid); + _I("delete prohibit %s condition by timeout (%d)", states[state].name, pid); if (pid == INTERNAL_LOCK_AMBIENT) ambient_check_invalid_state(pid); diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 35265fd..292ee87 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -546,7 +546,7 @@ static void del_state_cond(void *data, enum state_t state) /* A passed data is a pid_t type data, not a 64bit data. */ pid = (pid_t)((intptr_t)data); - _I("delete prohibit dim condition by timeout (%d)", pid); + _I("delete prohibit %s condition by timeout (%d)", states[state].name, pid); if (pid == INTERNAL_LOCK_AMBIENT) ambient_check_invalid_state(pid); diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index f5e1b69..fa74617 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -767,7 +767,7 @@ static void del_state_cond(void *data, enum state_t state) /* A passed data is a pid_t type data, not a 64bit data. */ pid = (pid_t)((intptr_t)data); - _I("delete prohibit dim condition by timeout (%d)", pid); + _I("delete prohibit %s condition by timeout (%d)", states[state].name, pid); if (pid == INTERNAL_LOCK_AMBIENT) ambient_check_invalid_state(pid); -- 2.7.4 From 61a32235530e49d1b2d6006432bda2226f9a7d2a Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 15 Dec 2020 20:16:43 +0900 Subject: [PATCH 11/16] Remove duplicated function call in default_trans check_processes is already called via default_check. ex) default_check -> makeup_trans_condition -> check_processes Change-Id: Ie867584ce8c3571fbd2c424ea1a715201864d8ad Signed-off-by: lokilee73 --- plugins/iot/display/core.c | 6 +----- plugins/mobile/display/core.c | 6 +----- plugins/tv/display/core.c | 6 +----- plugins/wearable/display/core.c | 6 +----- 4 files changed, 4 insertions(+), 20 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 2c36504..b748d4a 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -1329,11 +1329,7 @@ static int default_trans(int evt) /* There is a condition. */ _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name, states[next_state].name); - if (!check_processes(get_pm_cur_state())) { - /* This is valid condition - * The application that sent the condition is running now. */ - return -1; - } + return -1; } /* state transition */ diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 037e1e0..98caba4 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -1340,11 +1340,7 @@ static int default_trans(int evt) /* There is a condition. */ _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name, states[next_state].name); - if (!check_processes(get_pm_cur_state())) { - /* This is valid condition - * The application that sent the condition is running now. */ - return -1; - } + return -1; } /* state transition */ diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 292ee87..9a3b157 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -1330,11 +1330,7 @@ static int default_trans(int evt) /* There is a condition. */ _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name, states[next_state].name); - if (!check_processes(get_pm_cur_state())) { - /* This is valid condition - * The application that sent the condition is running now. */ - return -1; - } + return -1; } /* state transition */ diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index fa74617..c7c924a 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -1596,11 +1596,7 @@ static int default_trans(int evt) /* There is a condition. */ _I("%s locked. Trans to %s failed.", states[get_pm_cur_state()].name, states[next_state].name); - if (!check_processes(get_pm_cur_state())) { - /* This is valid condition - * The application that sent the condition is running now. */ - return -1; - } + return -1; } ret = is_lcdon_blocked(); -- 2.7.4 From 5a84d7e19abf1e5880e859005c3081a2352b746c Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 16 Dec 2020 15:39:24 +0900 Subject: [PATCH 12/16] Add null checking code after add_node Change-Id: Ia8a18630551d988e01a90e3158ba4d42b183b4f9 Signed-off-by: lokilee73 --- plugins/iot/display/core.c | 10 +++++++--- plugins/mobile/display/core.c | 10 +++++++--- plugins/tv/display/core.c | 10 +++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index b748d4a..e01f281 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -1014,9 +1014,13 @@ static void proc_condition_lock(PMMsg *data) holdkey_block = GET_COND_FLAG(data->cond) & PM_FLAG_BLOCK_HOLDKEY; tmp = find_node(state, pid); - if (!tmp) - add_node(state, pid, cond_timeout_id, holdkey_block); - else { + if (!tmp) { + tmp = add_node(state, pid, cond_timeout_id, holdkey_block); + if (!tmp) { + _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); + return; + } + } else { update_lock_timer(data, tmp, cond_timeout_id); tmp->holdkey_block = holdkey_block; } diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 98caba4..1c708b0 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -1026,9 +1026,13 @@ static void proc_condition_lock(PMMsg *data) holdkey_block = GET_COND_FLAG(data->cond) & PM_FLAG_BLOCK_HOLDKEY; tmp = find_node(state, pid); - if (!tmp) - add_node(state, pid, cond_timeout_id, holdkey_block); - else { + if (!tmp) { + tmp = add_node(state, pid, cond_timeout_id, holdkey_block); + if (!tmp) { + _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); + return; + } + } else { update_lock_timer(data, tmp, cond_timeout_id); tmp->holdkey_block = holdkey_block; } diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 9a3b157..aaa62db 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -1015,9 +1015,13 @@ static void proc_condition_lock(PMMsg *data) holdkey_block = GET_COND_FLAG(data->cond) & PM_FLAG_BLOCK_HOLDKEY; tmp = find_node(state, pid); - if (!tmp) - add_node(state, pid, cond_timeout_id, holdkey_block); - else { + if (!tmp) { + tmp = add_node(state, pid, cond_timeout_id, holdkey_block); + if (!tmp) { + _E("Failed to acquire lock, state: %d, pid: %d.", state, pid); + return; + } + } else { update_lock_timer(data, tmp, cond_timeout_id); tmp->holdkey_block = holdkey_block; } -- 2.7.4 From 9efbdb46b7170b968deee3eb21d14f7bcaa19db0 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Mon, 21 Dec 2020 10:33:14 +0900 Subject: [PATCH 13/16] Fix build error [ 220s] /home/abuild/rpmbuild/BUILD/deviced-10.0.0/src/tzip/tzip.c:35:10: fatal error: attr/xattr.h: No such file or directory [ 220s] 35 | #include Change-Id: I2d753bcedb29f252e8789de0a8203bbdd72592fd Signed-off-by: lokilee73 --- src/tzip/tzip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tzip/tzip.c b/src/tzip/tzip.c index 7f91bb0..1ba50b4 100644 --- a/src/tzip/tzip.c +++ b/src/tzip/tzip.c @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include #include -- 2.7.4 From a2a35f59370fcae15647e99f8502749d7e1fc7f3 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Mon, 21 Dec 2020 13:07:04 +0900 Subject: [PATCH 14/16] Remove unnecessary dependency The xattr syscalls are provided by glibc since ages. So, there is no need to have dependency with libattr-devel Change-Id: Id2eaf0db2859b48c09e81f87427622f472cc02ad Signed-off-by: lokilee73 --- packaging/deviced.spec | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index bd7d771..ee2b337 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -14,7 +14,6 @@ Source1: deviced.manifest Source2: libdeviced.manifest BuildRequires: cmake -BuildRequires: libattr-devel BuildRequires: gettext-devel BuildRequires: pkgconfig(mount) BuildRequires: pkgconfig(vconf) @@ -23,24 +22,24 @@ BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(libudev) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(eventsystem) +BuildRequires: pkgconfig(eventsystem) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(hwcommon) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(libsystemd) BuildRequires: pkgconfig(libinput) -BuildRequires: pkgconfig(capi-system-sensor) -BuildRequires: pkgconfig(fuse) -BuildRequires: pkgconfig(minizip) -BuildRequires: pkgconfig(libkmod) -BuildRequires: pkgconfig(libusbgx) -BuildRequires: pkgconfig(libsyscommon) -BuildRequires: pkgconfig(capi-system-device) -BuildRequires: pkgconfig(wayland-client) -BuildRequires: pkgconfig(tizen-extension-client) -BuildRequires: pkgconfig(tizen-dpms-client) -BuildRequires: pkgconfig(zlib) -BuildRequires: pkgconfig(argos_watchdog) +BuildRequires: pkgconfig(capi-system-sensor) +BuildRequires: pkgconfig(fuse) +BuildRequires: pkgconfig(minizip) +BuildRequires: pkgconfig(libkmod) +BuildRequires: pkgconfig(libusbgx) +BuildRequires: pkgconfig(libsyscommon) +BuildRequires: pkgconfig(capi-system-device) +BuildRequires: pkgconfig(wayland-client) +BuildRequires: pkgconfig(tizen-extension-client) +BuildRequires: pkgconfig(tizen-dpms-client) +BuildRequires: pkgconfig(zlib) +BuildRequires: pkgconfig(argos_watchdog) Requires: %{name}-tools = %{version}-%{release} %{?systemd_requires} -- 2.7.4 From aca70aaac7a6cc430872609e91bae79fd983f208 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Mon, 21 Dec 2020 14:38:17 +0900 Subject: [PATCH 15/16] Remove touch key/led Touch key/led is not supported on wearable target. Change-Id: I521c0e5cdc77a1c29d95dbd1bd339b7a8a17ca96 Signed-off-by: lokilee73 --- plugins/wearable/display/core.c | 18 ++-------- plugins/wearable/display/device-interface.c | 4 --- plugins/wearable/display/key-filter.c | 52 ++--------------------------- 3 files changed, 5 insertions(+), 69 deletions(-) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index c7c924a..72902ce 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -563,7 +563,7 @@ void lcd_on_procedure(int state, enum device_flags flag) * step 5. set pmstate of vconf * step 6. display on operate * - a. display on - * - b. TSP(touch screen) and touchkey enable + * - b. TSP(touch screen) enable * step 7. broadcast lcd on complete signal * step 8. key backlight enable */ @@ -611,9 +611,6 @@ void lcd_on_procedure(int state, enum device_flags flag) lcdon_broadcast = true; } - if (CHECK_OPS(keyfilter_ops, backlight_enable)) - keyfilter_ops->backlight_enable(true); - touch_blocked = false; } @@ -646,7 +643,7 @@ inline void lcd_off_procedure(enum device_flags flag) * step 2. set pmstate of vconf * step 3. display off operate * - a. display off - * - b. TSP(touch screen) and touchkey disable + * - b. TSP(touch screen) disable * step 4. broadcast lcd off complete siganl * step 5. enter doze mode if it is enabled */ @@ -673,9 +670,6 @@ inline void lcd_off_procedure(enum device_flags flag) set_setting_pmstate(S_LCDOFF); - if (CHECK_OPS(keyfilter_ops, backlight_enable)) - keyfilter_ops->backlight_enable(false); - if (transit_timer) { g_source_remove(transit_timer); transit_timer = 0; @@ -1991,10 +1985,6 @@ static int update_setting(int key_idx, int val) break; case SETTING_LOCK_SCREEN: set_lock_screen_state(val); - if (val == VCONFKEY_IDLE_UNLOCK) { - if (CHECK_OPS(keyfilter_ops, backlight_enable)) - keyfilter_ops->backlight_enable(false); - } /* LCD on if lock screen show before waiting time */ if ((get_pm_cur_state() == S_NORMAL) && @@ -2100,10 +2090,6 @@ static void init_lcd_operation(void) if (!check_default(ops)) DD_LIST_APPEND(lcdon_ops, ops); - ops = find_device("touchkey"); - if (!check_default(ops)) - DD_LIST_APPEND(lcdon_ops, ops); - ops = find_device("touchscreen"); if (!check_default(ops)) DD_LIST_APPEND(lcdon_ops, ops); diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index 655a102..b368fba 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -916,10 +916,6 @@ int exit_sysfs(void) if (!check_default(ops)) ops->start(NORMAL_MODE); - ops = find_device("touchkey"); - if (!check_default(ops)) - ops->start(NORMAL_MODE); - unregister_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); return 0; diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index cdea506..5f8989b 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -103,7 +103,6 @@ static bool touch_pressed = false; static int skip_lcd_off = false; static int skip_combination = false; static int bezel_wakeup = true; -static const struct device_ops *touchled; static int booting_check = true; static inline int current_state_in_on(void) @@ -521,30 +520,6 @@ static int process_screenlock_key(struct input_event *pinput) return true; } -static void process_hardkey_backlight(struct input_event *pinput) -{ - int opt; - - _E("pinput->value : %d", pinput->value); - if (pinput->value == KEY_PRESSED) { - if (touchled && touchled->execute) { - opt = TOUCHLED_PRESS; - touchled->execute(&opt); - } - } else if (pinput->value == KEY_RELEASED) { - /* if lockscreen is idle lock */ - if (__get_lock_screen_state() == VCONFKEY_IDLE_LOCK) { - _D("Lock state, key backlight is off when phone is unlocked!"); - return; - } - - if (touchled && touchled->execute) { - opt = TOUCHLED_RELEASE; - touchled->execute(&opt); - } - } -} - static void update_vital_state(struct input_event *pinput) { int type; @@ -582,17 +557,13 @@ static int check_key(struct input_event *pinput, int fd) case KEY_BACK: ignore = process_back_key(pinput); stop_key_combination(NULL); - if (current_state_in_on()) { - process_hardkey_backlight(pinput); + if (current_state_in_on()) ignore = false; - } break; case KEY_PHONE: stop_key_combination(NULL); - if (current_state_in_on()) { - process_hardkey_backlight(pinput); + if (current_state_in_on()) ignore = false; - } break; case KEY_VOLUMEUP: case KEY_VOLUMEDOWN: @@ -739,33 +710,16 @@ static void keyfilter_init(void) display_add_actor(&display_powerkey_actor); display_add_actor(&display_menukey_actor); - touchled = find_device(TOUCHLED_NAME); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb); } -static void key_backlight_enable(bool enable) -{ - int opt; - - if (!touchled || !touchled->execute) - return; - - if (enable) - opt = TOUCHLED_DIRECT_ON; - else - opt = TOUCHLED_DIRECT_OFF; - - touchled->execute(&opt); -} - static const struct display_keyfilter_ops normal_keyfilter_ops = { .init = keyfilter_init, .check = check_key_filter, .set_powerkey_ignore = NULL, .powerkey_lcdoff = NULL, - .backlight_enable = key_backlight_enable, + .backlight_enable = NULL, }; const struct display_keyfilter_ops *keyfilter_ops = &normal_keyfilter_ops; -- 2.7.4 From 682fd24e22d596677d97e59d4187d582e9c8d62d Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 7 Jan 2021 14:37:39 +0900 Subject: [PATCH 16/16] Apply screen timeout for iot Change-Id: I6e3597d513616d3d269f6c1a96fe18571fb7e201 Signed-off-by: Youngjae Cho --- conf/iot-display.conf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conf/iot-display.conf b/conf/iot-display.conf index 4e14b86..10769a8 100644 --- a/conf/iot-display.conf +++ b/conf/iot-display.conf @@ -34,6 +34,6 @@ # If this value is no, LCD is turned off just by external requests. # TimeoutEnable=(yes or no) -LCDAlwaysOn=yes -TimeoutEnable=no +LCDAlwaysOn=no +TimeoutEnable=yes SleepSupport=no -- 2.7.4