From 8c6290d2a97e766e91c2382d2902636977ca0ad6 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 15 May 2020 17:16:40 +0900 Subject: [PATCH 01/16] Remove declared but not implemented functions - deviced_mmc_control - deviced_usb_control - deviced_get_usb_control Change-Id: If237e8bfa9c54265f785a3bb89820511f7928f7a Signed-off-by: lokilee73 Signed-off-by: Youngjae Cho --- src/deviced/dd-control.h | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/src/deviced/dd-control.h b/src/deviced/dd-control.h index 120ed6c..87a3944 100644 --- a/src/deviced/dd-control.h +++ b/src/deviced/dd-control.h @@ -53,47 +53,6 @@ enum control_device_type { }; /** - * @par Description: - * This API is used to enable/disable mmc device.\n - * @param[in] enable enable/disable mmc device - * @return 0 on success, -1 if failed - * @par Example - * @code - * ... - * if( deviced_mmc_control(1) < 0 ) - * printf("Enable mmc device failed\n"); - * ... - * @endcode - */ -int deviced_mmc_control(bool enable); - -/** - * @par Description: - * This API is used to enable/disable usb device.\n - * @param[in] enable enable/disable usb device - * @return 0 on success, -1 if failed - * @par Example - * @code - * ... - * if( deviced_usb_control(1) < 0 ) - * printf("Enable usb device failed\n"); - * ... - * @endcode - */ -int deviced_usb_control(bool enable); - -/* Only USB-manager will use the api */ -/** - * @par Description: - * @return - * @par Example - * @code - * @endcode - * @todo describe function - */ -int deviced_get_usb_control(void); - -/** * @} // end of CAPI_SYSTEM_DEVICED_CONTROL_MODULE */ -- 2.7.4 From faea9817e27e32f90e74ed2a5f82f1fc26ef2168 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 15 May 2020 16:46:36 +0900 Subject: [PATCH 02/16] Fix battery noti depending on profiles Only mobile profile sends noti - remove_health_popup() - changed_battery_cf() Change-Id: Ib1e2a5b1979acf477a8b7f533d4ab7f98d9d6ddd Signed-off-by: Youngjae Cho Signed-off-by: lokilee73 Signed-off-by: Youngjae Cho --- ...owbat-notification.c => battery-notification.c} | 35 ++++++++++++++++++---- src/battery/battery-ops.h | 3 ++ src/battery/power-supply.c | 25 +++------------- 3 files changed, 36 insertions(+), 27 deletions(-) rename plugins/mobile/battery/{lowbat-notification.c => battery-notification.c} (88%) diff --git a/plugins/mobile/battery/lowbat-notification.c b/plugins/mobile/battery/battery-notification.c similarity index 88% rename from plugins/mobile/battery/lowbat-notification.c rename to plugins/mobile/battery/battery-notification.c index f1a7013..15df6b7 100644 --- a/plugins/mobile/battery/lowbat-notification.c +++ b/plugins/mobile/battery/battery-notification.c @@ -21,6 +21,7 @@ #include #include +#include "apps/apps.h" #include "core/log.h" #include "battery.h" #include "config.h" @@ -38,6 +39,9 @@ #define METHOD_CRITICAL_NOTI_UPDATE "BatteryCriticalNotiUpdate" #define METHOD_CRITICAL_NOTI_OFF "BatteryCriticalNotiOff" +#define REMOVE_POPUP "remove_battery_popups" +#define DISCONNECT_POPUP "battdisconnect" + enum event_noti_type { NOTI_NONE = -1, NOTI_UPDATE = 0, @@ -272,21 +276,40 @@ static void clean_lowbat_noti(const char *prev, const char *str) _D("Noti_crit(%d) noti_low(%d).", noti_crit, noti_low); } -static void lowbat_notification_init(void *data) +static int changed_battery_cf(int status) +{ + if (status == PRESENT_ABNORMAL) + return launch_system_app(APP_ABNORMAL, 2, APP_KEY_TYPE, DISCONNECT_POPUP); + return launch_system_app(APP_REMOVE, 2, APP_KEY_TYPE, REMOVE_POPUP); +} + +static void remove_health_popup(void) +{ + int ret; + + ret = launch_system_app(APP_REMOVE, 2, APP_KEY_TYPE, REMOVE_POPUP); + if (ret < 0) + _E("Failed to launch remove battery popup(%d)", ret); +} + +static void battery_notification_init(void *data) { struct battery_plugin *plugin = (struct battery_plugin *)data; if (!plugin) return; - _D("Add plugins for low battery notify."); + _D("Add plugins for battery notification."); plugin->lowbat_noti_launch = launch_lowbat_noti; plugin->lowbat_noti_clean = clean_lowbat_noti; + + plugin->changed_battery_cf = changed_battery_cf; + plugin->remove_health_popup = remove_health_popup; } -static const struct battery_ops lowbat_notification_ops = { - .name = "lowbat_notification", - .init = lowbat_notification_init, +static const struct battery_ops battery_notification_ops = { + .name = "battery_notification", + .init = battery_notification_init, }; -BATTERY_OPS_REGISTER(&lowbat_notification_ops) +BATTERY_OPS_REGISTER(&battery_notification_ops) diff --git a/src/battery/battery-ops.h b/src/battery/battery-ops.h index 4d80cf0..67376ef 100644 --- a/src/battery/battery-ops.h +++ b/src/battery/battery-ops.h @@ -35,6 +35,9 @@ struct battery_plugin { /* low battery notification */ int (*lowbat_noti_launch) (int capacity, int option); void (*lowbat_noti_clean) (const char *prev, const char *str); + + int (*changed_battery_cf) (int status); + void (*remove_health_popup) (void); /* Add plugins here */ }; extern struct battery_plugin battery_plgn; diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 68ed4a1..8da3b98 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -64,9 +64,6 @@ #define OVERVOLT_NAME "Over voltage" #define GOOD_NAME "Good" -#define REMOVE_POPUP "remove_battery_popups" -#define DISCONNECT_POPUP "battdisconnect" - #define CHARGER_WIRELESS_TYPE_BT 10 #define CHARGER_WIRELESS_TYPE_3G 22 #define CHARGER_INCOMPATIBLE_TYPE 11 @@ -438,13 +435,6 @@ static void charger_state_send_system_event(int state) event_system_send(SYS_EVENT_BATTERY_CHARGER_STATUS, EVT_KEY_BATTERY_CHARGER_STATUS, str); } -int changed_battery_cf(int status) -{ - if (status == PRESENT_ABNORMAL) - return launch_system_app(APP_ABNORMAL, 2, APP_KEY_TYPE, DISCONNECT_POPUP); - return launch_system_app(APP_REMOVE, 2, APP_KEY_TYPE, REMOVE_POPUP); -} - static void update_present(enum battery_noti_status status) { @@ -462,16 +452,8 @@ static void update_present(enum battery_noti_status status) if (disp_plgn.pm_unlock_internal) disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, PM_SLEEP_MARGIN); } - changed_battery_cf(battery.present); -} - -void remove_health_popup(void) -{ - int ret; - - ret = launch_system_app(APP_REMOVE, 2, APP_KEY_TYPE, REMOVE_POPUP); - if (ret < 0) - _E("Failed to launch remove battery popup(%d)", ret); + if (battery_plgn.changed_battery_cf) + battery_plgn.changed_battery_cf(battery.present); } static void launch_health_popup(void) @@ -521,7 +503,8 @@ static void update_health(enum battery_noti_status status) g_source_remove(abnormal_health_popup_timer); abnormal_health_popup_timer = 0; } - remove_health_popup(); + if (battery_plgn.remove_health_popup) + battery_plgn.remove_health_popup(); } } -- 2.7.4 From 68b2c5c7e5ad00797caecc45bb1e320ec4490fe8 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 15 May 2020 16:57:08 +0900 Subject: [PATCH 03/16] Add PACKAGE_UNPACK_PATH Change-Id: I479937e2e8af68af53c0e158883601e6b79f8c47 Signed-off-by: lokilee73 Signed-off-by: Youngjae Cho --- src/tzip/tzip.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tzip/tzip.c b/src/tzip/tzip.c index 030f196..0eedc26 100644 --- a/src/tzip/tzip.c +++ b/src/tzip/tzip.c @@ -44,6 +44,8 @@ #include "core/common.h" #include "tzip-utility.h" +#define PACKAGE_UNPACK_PATH "/opt/usr/share/package-unpacked" + enum tzip_state_t { TZIP_RUNNING_STATE = 0, TZIP_STOP_STATE, @@ -82,6 +84,9 @@ static int check_path_available(char *mountpath) if (path && !strncmp(mountpath, path, strlen(path))) return 1; + if (!strncmp(mountpath, PACKAGE_UNPACK_PATH, strlen(PACKAGE_UNPACK_PATH))) + return 1; + return 0; } -- 2.7.4 From 9e9c928d5d916af1efb5831bbc758a0447127d55 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 18 May 2020 17:08:59 +0900 Subject: [PATCH 04/16] Deduplicate display plugin source code: Display Lock Change-Id: Ia0e44856f304f345543e50744dd8a459006fcd2d Signed-off-by: Youngjae Cho --- plugins/iot/display/core.c | 428 +--------------------------------- plugins/iot/display/key-filter.c | 1 + plugins/mobile/display/core.c | 425 +-------------------------------- plugins/mobile/display/key-filter.c | 1 + plugins/tv/display/core.c | 425 +-------------------------------- plugins/tv/display/key-filter.c | 1 + plugins/tv/display/state-tv.c | 1 + plugins/wearable/display/core.c | 421 +-------------------------------- plugins/wearable/display/key-filter.c | 1 + src/display/core.h | 4 - src/display/display-lock.c | 393 +++++++++++++++++++++++++++++++ src/display/display-lock.h | 55 +++++ src/display/display-ops.h | 1 - src/display/display-signal.c | 21 ++ src/display/display-signal.h | 1 + src/time/time-handler.c | 12 +- 16 files changed, 519 insertions(+), 1672 deletions(-) create mode 100644 src/display/display-lock.c create mode 100644 src/display/display-lock.h diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 71501aa..2b2255e 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -58,8 +58,9 @@ #include "power/power-handler.h" #include "power/boot.h" #include "dd-display.h" -#include "display/display-dpms.h" -#include "display/display-signal.h" +#include "display-dpms.h" +#include "display-signal.h" +#include "display-lock.h" #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -73,8 +74,6 @@ #define ALWAYS_ON_TIMEOUT 360000000 #define LATE_LCD_TRANSIT 1 -#define PID_MAX 6 - #define GESTURE_STR "gesture" #define POWER_KEY_STR "powerkey" #define TOUCH_STR "touch" @@ -84,8 +83,6 @@ #define PALM_STR "palm" #define UNKNOWN_STR "unknown" -#define METHOD_APP_STATUS "CheckAppStatus" - #define PM_WAKEUP 0 #define PM_SUSPEND 1 @@ -94,7 +91,6 @@ extern int get_charging_status(int *val); extern void init_save_userlock(void); unsigned int pm_status_flag; -static int trans_condition; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -105,8 +101,7 @@ guint timeout_src_id; int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; -static int custom_holdkey_block = false; -static int custom_change_pid = -1; +int custom_holdkey_block = false; static char *custom_change_name; static bool hallic_open = true; static guint lock_timeout_id; @@ -133,8 +128,6 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); -static gboolean pmlock_check(void *data); - static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; @@ -172,10 +165,6 @@ static int trans_table[S_END][EVENT_END] = { #define S_COVER_TIMEOUT 8000 #define GET_HOLDKEY_BLOCK_STATE(x) ((x >> SHIFT_LOCK_FLAG) & HOLD_KEY_BLOCK_BIT) #define BOOTING_DONE_WATING_TIME 60000 /* 1 minute */ -#define LOCK_TIME_WARNING 60 /* 60 seconds */ - -#define ACTIVE_ACT "active" -#define INACTIVE_ACT "inactive" #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ #define LONG_PRESS_INTERVAL 2 /* 2 seconds */ @@ -221,49 +210,6 @@ struct display_function_info display_info = { .face_detection = NULL, }; -typedef struct _pm_lock_node { - pid_t pid; - guint timeout_id; - guint warning_id; - GVariant *warning_param; - time_t time; - bool holdkey_block; - bool background; - bool broadcast_warning; -} PmLockNode; - -static dd_list *cond_head[S_END]; - -static void set_process_active(bool flag, pid_t pid) -{ - int ret; - - if (pid >= INTERNAL_LOCK_BASE) - return; - - /* Send dbug to resourced */ - ret = dbus_handle_emit_dbus_signal(NULL, - RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - RESOURCED_METHOD_ACTIVE, - g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); - if (ret < 0) - _E("Failed to send dbus signal to resourced."); -} - -bool check_lock_state(int state) -{ - dd_list *elem; - PmLockNode *t; - - DD_LIST_FOREACH(cond_head[state], elem, t) { - if (t->background == false) - return true; - } - - return false; -} - void change_state_action(enum state_t state, int (*func)(int timeout)) { _I("[%s] 'action' is changed.", states[state].name); @@ -542,141 +488,6 @@ int get_hallic_open(void) return hallic_open; } -static int refresh_app_cond() -{ - trans_condition = 0; - - if (check_lock_state(S_NORMAL)) - trans_condition = trans_condition | MASK_NORMAL; - if (check_lock_state(S_LCDDIM)) - trans_condition = trans_condition | MASK_DIM; - if (check_lock_state(S_LCDOFF)) - trans_condition = trans_condition | MASK_OFF; - - return 0; -} - -static void makeup_trans_condition(void) -{ - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - check_processes(S_LCDOFF); - refresh_app_cond(); -} - -static PmLockNode *find_node(enum state_t s_index, pid_t pid) -{ - dd_list *elem; - PmLockNode *t = NULL; - - DD_LIST_FOREACH(cond_head[s_index], elem, t) { - if (t->pid == pid) - return t; - } - - return NULL; -} - -static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, - bool holdkey_block) -{ - guint warning_id = 0; - PmLockNode *n; - GVariant *v = NULL; - time_t now; - - n = (PmLockNode *) malloc(sizeof(PmLockNode)); - if (n == NULL) { - _E("Not enough memory, add cond. fail"); - return NULL; - } - - if (pid < INTERNAL_LOCK_BASE) { - v = g_variant_new("(ii)", s_index, pid); - if (v) { - warning_id = g_timeout_add_seconds(display_conf.lockcheck_timeout, - pmlock_check, (void *)v); - } else { - _E("Failed to make GVariant."); - } - } - - time(&now); - n->pid = pid; - n->timeout_id = timeout_id; - n->warning_id = warning_id; - n->warning_param = v; - n->time = now; - n->holdkey_block = holdkey_block; - n->background = false; - n->broadcast_warning = true; - DD_LIST_APPEND(cond_head[s_index], n); - - refresh_app_cond(); - return n; -} - -static int del_node(enum state_t s_index, PmLockNode *n) -{ - if (n == NULL) - return 0; - - DD_LIST_REMOVE(cond_head[s_index], n); - - /* delete timer */ - if (n->timeout_id) { - g_source_remove(n->timeout_id); - n->timeout_id = 0; - } - if (n->warning_id) { - g_source_remove(n->warning_id); - n->warning_id = 0; - } - if (n->warning_param) { - g_variant_unref(n->warning_param); - n->warning_param = NULL; - } - - free(n); - refresh_app_cond(); - return 0; -} - -static void print_node(int next) -{ - int ret; - dd_list *elem; - PmLockNode *n; - char buf[30]; - time_t now; - double diff; - - if (next <= S_START || next >= S_END) - return; - - time(&now); - DD_LIST_FOREACH(cond_head[next], elem, n) { - diff = difftime(now, n->time); - ctime_r(&n->time, buf); - buf[strlen(buf) - 1] = 0; - - if (diff > LOCK_TIME_WARNING) { - if (diff > LOCK_TIME_WARNING * 60 && n->pid < INTERNAL_LOCK_BASE && n->broadcast_warning) { - ret = dbus_handle_emit_dbus_signal(NULL, - DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - "pmlock_over", - g_variant_new("(i)", n->pid)); - if (ret < 0) - _E("Failed to send dbus signal pmlock_over."); - n->broadcast_warning = false; - } - _W("Over(%.0f s) pid( %5d) lock time(%s)", diff, n->pid, buf); - } else - _I("Pid(%5d) lock time(%s)", n->pid, buf); - } -} - void get_pname(pid_t pid, char *pname) { char buf[PATH_MAX]; @@ -747,119 +558,6 @@ static gboolean del_off_cond(void *data) return G_SOURCE_REMOVE; } -static void pmlock_check_cb(GVariant *var, void *user_data, GError *err) -{ - pid_t pid = 0; - int ret, detected = 0; - char *app_id = NULL; - enum state_t state = (enum state_t) user_data; - PmLockNode *node; - time_t now; - double diff; - - if (!var) - return; - - if (!dh_get_param_from_var(var, "(iis)", &pid, &detected, &app_id)) { - _E("Failed to get params from gvariant. expected:%s, type:%s", "(iis)", g_variant_get_type_string(var)); - goto out; - } - - if (is_app(pid) == 1 && !detected) - goto out; - - node = find_node(state, pid); - if (!node) - goto out; - - time(&now); - diff = difftime(now, node->time); - - CRITICAL_LOG("%s(%d) has held %s lock for a long time(%.0f s).", - app_id, pid, states[state].name + 2, diff); - - ret = dbus_handle_emit_dbus_signal(NULL, - DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - "pmlock_expired", - g_variant_new("(i)", pid)); - if (ret < 0) - _E("Failed to send dbus pmlock_expired"); - -out: - if (app_id) - g_free(app_id); - g_variant_unref(var); -} - -/* - * Any process is possible many time lock, deviced can not know malicious - * or good process. so infinity or more then 10 min lock process, deviced - * will check it through resoured. And then, it will ask the user whether to quit or not. - */ -static gboolean pmlock_check(void *data) -{ - const char *arr[2]; - char chr_pid[PID_MAX]; - PmLockNode *node; - GVariant *v; - enum state_t state; - pid_t pid; - int ret; - - if (!data) { - _E("Invalid parameter."); - return G_SOURCE_REMOVE; - } - - v = (GVariant*)data; - g_variant_get(v, "(ii)", &state, &pid); - - _D("Process %d requested state %d lock.", pid, state); - - if (state == S_LCDOFF && backlight_ops.get_lcd_power() == DPMS_ON) { - _D("Lcd state is PM_LCD_POWER_ON"); - return G_SOURCE_CONTINUE; - } - - /* Stop checking lock if process had been terminated */ - if (kill(pid, 0) == -1) { - node = find_node(state, pid); - del_node(state, node); - _I("Process %d not found. Stop checking lock.", pid); - return G_SOURCE_REMOVE; - } - - snprintf(chr_pid, sizeof(chr_pid), "%d", pid); - - arr[0] = chr_pid; - switch (state) { - case S_NORMAL: - arr[1] = "normal"; - break; - case S_LCDDIM: - arr[1] = "lcddim"; - break; - case S_LCDOFF: - arr[1] = "lcdoff"; - break; - default: - _E("Invalid state."); - g_variant_unref(v); - return G_SOURCE_REMOVE; - } - - ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, - RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - METHOD_APP_STATUS, - "is", arr, pmlock_check_cb, -1, (void *)(intptr_t)state); - if (ret < 0) - _E("Failed to call dbus method"); - - return G_SOURCE_CONTINUE; -} - /* timeout handler */ gboolean timeout_handler(void *data) { @@ -1020,26 +718,6 @@ static inline bool check_lcd_is_on(void) return true; } -static int check_lock_condition(enum state_t state) -{ - dd_list *elem; - PmLockNode *t = NULL; - int ret = false; - pid_t owner = getpid(); - - _D("check holdkey block : state of %s", states[state].name); - - DD_LIST_FOREACH(cond_head[state], elem, t) { - if (t->pid != owner && t->background == false) { - ret = true; - _I("state change was blocked by pid(%d)!", t->pid); - break; - } - } - - return ret; -} - static gboolean timer_refresh_cb(gpointer data) { struct state *st; @@ -1446,85 +1124,6 @@ static int proc_condition(PMMsg *data) return 0; } -/* If some changed, return 1 */ -int check_processes(enum state_t prohibit_state) -{ - dd_list *elem, *next; - PmLockNode *t = NULL; - int ret = 0; - - DD_LIST_FOREACH_SAFE(cond_head[prohibit_state], elem, next, t) { - if (t->pid < INTERNAL_LOCK_BASE && kill(t->pid, 0) == -1) { - _E("%d process does not exist, delete the REQ" - " - prohibit state %d ", - t->pid, prohibit_state); - if (t->pid == custom_change_pid) { - get_lcd_timeout_from_settings(); - custom_normal_timeout = custom_dim_timeout = 0; - custom_change_pid = -1; - } - ret = 1; - set_unlock_time(t->pid, prohibit_state); - del_node(prohibit_state, t); - } - } - - return ret; -} - -int check_holdkey_block(enum state_t state) -{ - dd_list *elem; - PmLockNode *t = NULL; - int ret = 0; - - _I("Check holdkey block: state of %s", states[state].name); - - if (custom_holdkey_block == true) { - _I("Custom hold key blocked by pid(%d).", - custom_change_pid); - return 1; - } - - DD_LIST_FOREACH(cond_head[state], elem, t) { - if (t->holdkey_block == true) { - ret = 1; - _I("Hold key blocked by pid(%d).", t->pid); - break; - } - } - - return ret; -} - -int delete_condition(enum state_t state) -{ - dd_list *elem, *next; - PmLockNode *t = NULL; - - _I("delete condition : state of %s", states[state].name); - - if (!cond_head[state]) - return 0; - - DD_LIST_FOREACH_SAFE(cond_head[state], elem, next, t) { - if (t->timeout_id > 0) { - g_source_remove(t->timeout_id); - t->timeout_id = 0; - } - if (state == S_LCDOFF) - set_process_active(false, t->pid); - _I("delete node of pid(%d)", t->pid); - set_unlock_time(t->pid, state); - del_node(state, t); - } - - DD_LIST_FREE_LIST(cond_head[state]); - cond_head[state] = NULL; - - return 0; -} - void update_lcdoff_source(int source) { int ret; @@ -1647,9 +1246,9 @@ void print_info(int fd) _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Tran. Locked : %s %s %s\n", - (trans_condition & MASK_NORMAL) ? states[S_NORMAL].name : "-", - (trans_condition & MASK_DIM) ? states[S_LCDDIM].name : "-", - (trans_condition & MASK_OFF) ? states[S_LCDOFF].name : "-"); + (get_trans_condition() & MASK_NORMAL) ? states[S_NORMAL].name : "-", + (get_trans_condition() & MASK_DIM) ? states[S_LCDDIM].name : "-", + (get_trans_condition() & MASK_OFF) ? states[S_LCDOFF].name : "-"); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("Write() failed: %d", errno); @@ -1666,7 +1265,7 @@ void print_info(int fd) _E("Write() failed: %d", errno); for (s_index = S_NORMAL; s_index < S_END; s_index++) { - DD_LIST_FOREACH(cond_head[s_index], elem, t) { + DD_LIST_FOREACH(get_cond_head(s_index), elem, t) { get_pname((pid_t)t->pid, pname); ctime_r(&t->time, time_buf); time_buf[strlen(time_buf) - 1] = 0; @@ -1774,14 +1373,6 @@ int check_lcdoff_direct(void) return true; } -static int __check_lcdoff_lock_state(void) -{ - if (cond_head[S_LCDOFF] != NULL) - return true; - - return false; -} - /* * default transition function * 1. call check @@ -2041,7 +1632,7 @@ static int default_check(int curr, int next) makeup_trans_condition(); - trans_cond = trans_condition & MASK_BIT; + trans_cond = get_trans_condition() & MASK_BIT; if (next == S_NORMAL) /* S_NORMAL is exceptional */ return 1; @@ -2600,7 +2191,6 @@ static int display_probe(void *data) /* display_plugin instance initialization */ init_pm_internal(); - disp_plgn.check_lcdoff_lock_state = __check_lcdoff_lock_state; disp_plgn.device_flags_to_string = __device_flags_to_string; return 0; diff --git a/plugins/iot/display/key-filter.c b/plugins/iot/display/key-filter.c index 5e77658..9388a18 100644 --- a/plugins/iot/display/key-filter.c +++ b/plugins/iot/display/key-filter.c @@ -41,6 +41,7 @@ #include "power/power-handler.h" #include "led/touch-key.h" #include "apps/apps.h" +#include "display/display-lock.h" #ifndef KEY_SCREENLOCK #define KEY_SCREENLOCK 0x98 diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 4362f5e..67c2efe 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -61,7 +61,9 @@ #include "display/display-dpms.h" #include "proximity.h" #include "display-info.h" -#include "display/display-signal.h" +#include "display-signal.h" +#include "display-lock.h" + #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" /** @@ -74,8 +76,6 @@ #define ALWAYS_ON_TIMEOUT 360000000 #define LATE_LCD_TRANSIT 1 -#define PID_MAX 6 - #define GESTURE_STR "gesture" #define POWER_KEY_STR "powerkey" #define TOUCH_STR "touch" @@ -85,8 +85,6 @@ #define PALM_STR "palm" #define UNKNOWN_STR "unknown" -#define METHOD_APP_STATUS "CheckAppStatus" - #define PM_WAKEUP 0 #define PM_SUSPEND 1 @@ -95,7 +93,6 @@ extern int get_charging_status(int *val); extern void init_save_userlock(void); unsigned int pm_status_flag; -static int trans_condition; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -106,8 +103,7 @@ guint timeout_src_id; int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; -static int custom_holdkey_block = false; -static int custom_change_pid = -1; +int custom_holdkey_block = false; static char *custom_change_name; static bool hallic_open = true; static guint lock_timeout_id; @@ -134,8 +130,6 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); -static gboolean pmlock_check(void *data); - static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; @@ -173,10 +167,6 @@ static int trans_table[S_END][EVENT_END] = { #define S_COVER_TIMEOUT 8000 #define GET_HOLDKEY_BLOCK_STATE(x) ((x >> SHIFT_LOCK_FLAG) & HOLD_KEY_BLOCK_BIT) #define BOOTING_DONE_WATING_TIME 60000 /* 1 minute */ -#define LOCK_TIME_WARNING 60 /* 60 seconds */ - -#define ACTIVE_ACT "active" -#define INACTIVE_ACT "inactive" #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ #define LONG_PRESS_INTERVAL 400 /* 0.4 seconds */ @@ -222,49 +212,6 @@ struct display_function_info display_info = { .face_detection = NULL, }; -typedef struct _pm_lock_node { - pid_t pid; - guint timeout_id; - guint warning_id; - GVariant *warning_param; - time_t time; - bool holdkey_block; - bool background; - bool broadcast_warning; -} PmLockNode; - -static dd_list *cond_head[S_END]; - -static void set_process_active(bool flag, pid_t pid) -{ - int ret; - - if (pid >= INTERNAL_LOCK_BASE) - return; - - /* Send dbug to resourced */ - ret = dbus_handle_emit_dbus_signal(NULL, - RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - RESOURCED_METHOD_ACTIVE, - g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); - if (ret < 0) - _E("Failed to send dbus signal to resourced."); -} - -bool check_lock_state(int state) -{ - dd_list *elem; - PmLockNode *t; - - DD_LIST_FOREACH(cond_head[state], elem, t) { - if (t->background == false) - return true; - } - - return false; -} - void change_state_action(enum state_t state, int (*func)(int timeout)) { _I("[%s] 'action' is changed.", states[state].name); @@ -548,142 +495,6 @@ int get_hallic_open(void) return hallic_open; } -static int refresh_app_cond() -{ - trans_condition = 0; - - if (check_lock_state(S_NORMAL)) - trans_condition = trans_condition | MASK_NORMAL; - if (check_lock_state(S_LCDDIM)) - trans_condition = trans_condition | MASK_DIM; - if (check_lock_state(S_LCDOFF)) - trans_condition = trans_condition | MASK_OFF; - - return 0; -} - -static void makeup_trans_condition(void) -{ - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - check_processes(S_LCDOFF); - refresh_app_cond(); -} - -static PmLockNode *find_node(enum state_t s_index, pid_t pid) -{ - dd_list *elem; - PmLockNode *t = NULL; - - DD_LIST_FOREACH(cond_head[s_index], elem, t) { - if (t->pid == pid) - return t; - } - - return NULL; -} - -static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, - bool holdkey_block) -{ - guint warning_id = 0; - PmLockNode *n; - GVariant *v = NULL; - time_t now; - - n = (PmLockNode *) malloc(sizeof(PmLockNode)); - if (n == NULL) { - _E("Not enough memory, add cond. fail"); - return NULL; - } - - if (pid < INTERNAL_LOCK_BASE) { - v = g_variant_new("(ii)", s_index, pid); - if (v) { - warning_id = g_timeout_add_seconds(display_conf.lockcheck_timeout, - pmlock_check, (void *)v); - } else { - _E("Failed to make GVariant."); - } - - } - - time(&now); - n->pid = pid; - n->timeout_id = timeout_id; - n->warning_id = warning_id; - n->warning_param = v; - n->time = now; - n->holdkey_block = holdkey_block; - n->background = false; - n->broadcast_warning = true; - DD_LIST_APPEND(cond_head[s_index], n); - - refresh_app_cond(); - return n; -} - -static int del_node(enum state_t s_index, PmLockNode *n) -{ - if (n == NULL) - return 0; - - DD_LIST_REMOVE(cond_head[s_index], n); - - /* delete timer */ - if (n->timeout_id) { - g_source_remove(n->timeout_id); - n->timeout_id = 0; - } - if (n->warning_id) { - g_source_remove(n->warning_id); - n->warning_id = 0; - } - if (n->warning_param) { - g_variant_unref(n->warning_param); - n->warning_param = NULL; - } - - free(n); - refresh_app_cond(); - return 0; -} - -static void print_node(int next) -{ - int ret; - dd_list *elem; - PmLockNode *n; - char buf[30]; - time_t now; - double diff; - - if (next <= S_START || next >= S_END) - return; - - time(&now); - DD_LIST_FOREACH(cond_head[next], elem, n) { - diff = difftime(now, n->time); - ctime_r(&n->time, buf); - buf[strlen(buf) - 1] = 0; - - if (diff > LOCK_TIME_WARNING) { - if (diff > LOCK_TIME_WARNING * 60 && n->pid < INTERNAL_LOCK_BASE && n->broadcast_warning) { - ret = dbus_handle_emit_dbus_signal(NULL, - DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - "pmlock_over", - g_variant_new("(i)", n->pid)); - if (ret < 0) - _E("Failed to send dbus signal pmlock_over."); - n->broadcast_warning = false; - } - _W("Over(%.0f s) pid( %5d) lock time(%s)", diff, n->pid, buf); - } else - _I("Pid(%5d) lock time(%s)", n->pid, buf); - } -} - void get_pname(pid_t pid, char *pname) { char buf[PATH_MAX]; @@ -754,116 +565,6 @@ static gboolean del_off_cond(void *data) return G_SOURCE_REMOVE; } -static void pmlock_check_cb(GVariant *var, void *user_data, GError *err) -{ - pid_t pid = 0; - int ret, detected = 0; - char *app_id = NULL; - enum state_t state = (enum state_t) user_data; - PmLockNode *node; - time_t now; - double diff; - - if (!var) - return; - - if (!dh_get_param_from_var(var, "(iis)", &pid, &detected, &app_id)) { - _E("Failed to get params from gvariant. expected:%s, type:%s", "(iis)", g_variant_get_type_string(var)); - goto out; - } - - if (is_app(pid) == 1 && !detected) - goto out; - - node = find_node(state, pid); - if (!node) - goto out; - - time(&now); - diff = difftime(now, node->time); - - CRITICAL_LOG("%s(%d) has held %s lock for a long time(%.0f s).", - app_id, pid, states[state].name + 2, diff); - - ret = dbus_handle_emit_dbus_signal(NULL, - DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - "pmlock_expired", - g_variant_new("(i)", pid)); - if (ret < 0) - _E("Failed to send dbus pmlock_expired"); - -out: - if (app_id) - g_free(app_id); - g_variant_unref(var); -} - -/* - * Any process is possible many time lock, deviced can not know malicious - * or good process. so infinity or more then 10 min lock process, deviced - * will check it through resoured. And then, it will ask the user whether to quit or not. - */ -static gboolean pmlock_check(void *data) -{ - const char *arr[2]; - char chr_pid[PID_MAX]; - PmLockNode *node; - GVariant *v; - enum state_t state; - pid_t pid; - int ret; - - if (!data) { - _E("Invalid parameter."); - return G_SOURCE_REMOVE; - } - - v = (GVariant*)data; - g_variant_get(v, "(ii)", &state, &pid); - - if (state == S_LCDOFF && backlight_ops.get_lcd_power() == DPMS_ON) { - _D("Lcd state is PM_LCD_POWER_ON"); - return G_SOURCE_CONTINUE; - } - - /* Stop checking lock if process had been terminated */ - if (kill(pid, 0) == -1) { - node = find_node(state, pid); - del_node(state, node); - _I("Process %d not found. Stop checking lock.", pid); - return G_SOURCE_REMOVE; - } - - snprintf(chr_pid, sizeof(chr_pid), "%d", pid); - arr[0] = chr_pid; - switch (state) { - case S_NORMAL: - arr[1] = "normal"; - break; - case S_LCDDIM: - arr[1] = "lcddim"; - break; - case S_LCDOFF: - arr[1] = "lcdoff"; - break; - default: - _E("Invalid state."); - g_variant_unref(v); - return G_SOURCE_REMOVE; - } - - ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, - RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - METHOD_APP_STATUS, - "is", arr, pmlock_check_cb, -1, (void *)(intptr_t)state); - if (ret < 0) - _E("Failed to call dbus method"); - - return G_SOURCE_CONTINUE; -} - /* timeout handler */ gboolean timeout_handler(void *data) { @@ -1024,26 +725,6 @@ static inline bool check_lcd_is_on(void) return true; } -static int check_lock_condition(enum state_t state) -{ - dd_list *elem; - PmLockNode *t = NULL; - int ret = false; - pid_t owner = getpid(); - - _D("check holdkey block : state of %s", states[state].name); - - DD_LIST_FOREACH(cond_head[state], elem, t) { - if (t->pid != owner && t->background == false) { - ret = true; - _I("state change was blocked by pid(%d)!", t->pid); - break; - } - } - - return ret; -} - static gboolean timer_refresh_cb(gpointer data) { struct state *st; @@ -1454,85 +1135,6 @@ static int proc_condition(PMMsg *data) return 0; } -/* If some changed, return 1 */ -int check_processes(enum state_t prohibit_state) -{ - dd_list *elem, *next; - PmLockNode *t = NULL; - int ret = 0; - - DD_LIST_FOREACH_SAFE(cond_head[prohibit_state], elem, next, t) { - if (t->pid < INTERNAL_LOCK_BASE && kill(t->pid, 0) == -1) { - _E("%d process does not exist, delete the REQ" - " - prohibit state %d ", - t->pid, prohibit_state); - if (t->pid == custom_change_pid) { - get_lcd_timeout_from_settings(); - custom_normal_timeout = custom_dim_timeout = 0; - custom_change_pid = -1; - } - ret = 1; - set_unlock_time(t->pid, prohibit_state); - del_node(prohibit_state, t); - } - } - - return ret; -} - -int check_holdkey_block(enum state_t state) -{ - dd_list *elem; - PmLockNode *t = NULL; - int ret = 0; - - _I("Check holdkey block: state of %s", states[state].name); - - if (custom_holdkey_block == true) { - _I("Custom hold key blocked by pid(%d).", - custom_change_pid); - return 1; - } - - DD_LIST_FOREACH(cond_head[state], elem, t) { - if (t->holdkey_block == true) { - ret = 1; - _I("Hold key blocked by pid(%d).", t->pid); - break; - } - } - - return ret; -} - -int delete_condition(enum state_t state) -{ - dd_list *elem, *next; - PmLockNode *t = NULL; - - _I("delete condition : state of %s", states[state].name); - - if (!cond_head[state]) - return 0; - - DD_LIST_FOREACH_SAFE(cond_head[state], elem, next, t) { - if (t->timeout_id > 0) { - g_source_remove(t->timeout_id); - t->timeout_id = 0; - } - if (state == S_LCDOFF) - set_process_active(false, t->pid); - _I("delete node of pid(%d)", t->pid); - set_unlock_time(t->pid, state); - del_node(state, t); - } - - DD_LIST_FREE_LIST(cond_head[state]); - cond_head[state] = NULL; - - return 0; -} - void update_lcdoff_source(int source) { int ret; @@ -1655,9 +1257,9 @@ void print_info(int fd) _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Tran. Locked : %s %s %s\n", - (trans_condition & MASK_NORMAL) ? states[S_NORMAL].name : "-", - (trans_condition & MASK_DIM) ? states[S_LCDDIM].name : "-", - (trans_condition & MASK_OFF) ? states[S_LCDOFF].name : "-"); + (get_trans_condition() & MASK_NORMAL) ? states[S_NORMAL].name : "-", + (get_trans_condition() & MASK_DIM) ? states[S_LCDDIM].name : "-", + (get_trans_condition() & MASK_OFF) ? states[S_LCDOFF].name : "-"); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("Write() failed: %d", errno); @@ -1674,7 +1276,7 @@ void print_info(int fd) _E("Write() failed: %d", errno); for (s_index = S_NORMAL; s_index < S_END; s_index++) { - DD_LIST_FOREACH(cond_head[s_index], elem, t) { + DD_LIST_FOREACH(get_cond_head(s_index), elem, t) { get_pname((pid_t)t->pid, pname); ctime_r(&t->time, time_buf); time_buf[strlen(time_buf) - 1] = 0; @@ -1782,14 +1384,6 @@ int check_lcdoff_direct(void) return true; } -static int __check_lcdoff_lock_state(void) -{ - if (cond_head[S_LCDOFF] != NULL) - return true; - - return false; -} - /* * default transition function * 1. call check @@ -2049,7 +1643,7 @@ static int default_check(int curr, int next) makeup_trans_condition(); - trans_cond = trans_condition & MASK_BIT; + trans_cond = get_trans_condition() & MASK_BIT; if (next == S_NORMAL) /* S_NORMAL is exceptional */ return 1; @@ -2608,7 +2202,6 @@ static int display_probe(void *data) /* display_plugin instance initialization */ init_pm_internal(); - disp_plgn.check_lcdoff_lock_state = __check_lcdoff_lock_state; disp_plgn.device_flags_to_string = __device_flags_to_string; return 0; diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index c948043..d1ea239 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -41,6 +41,7 @@ #include "power/power-handler.h" #include "led/touch-key.h" #include "apps/apps.h" +#include "display/display-lock.h" #ifndef KEY_SCREENLOCK #define KEY_SCREENLOCK 0x98 diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 0847bb5..8402a6c 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -58,8 +58,9 @@ #include "power/power-handler.h" #include "power/boot.h" #include "dd-display.h" -#include "display/display-dpms.h" -#include "display/display-signal.h" +#include "display-dpms.h" +#include "display-signal.h" +#include "display-lock.h" #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -73,8 +74,6 @@ #define ALWAYS_ON_TIMEOUT 360000000 #define LATE_LCD_TRANSIT 1 -#define PID_MAX 6 - #define GESTURE_STR "gesture" #define POWER_KEY_STR "powerkey" #define TOUCH_STR "touch" @@ -84,8 +83,6 @@ #define PALM_STR "palm" #define UNKNOWN_STR "unknown" -#define METHOD_APP_STATUS "CheckAppStatus" - #define PM_WAKEUP 0 #define PM_SUSPEND 1 @@ -94,7 +91,6 @@ extern int get_charging_status(int *val); extern void init_save_userlock(void); unsigned int pm_status_flag; -static int trans_condition; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -105,8 +101,7 @@ guint timeout_src_id; int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; -static int custom_holdkey_block = false; -static int custom_change_pid = -1; +int custom_holdkey_block = false; static char *custom_change_name; static bool hallic_open = true; static guint lock_timeout_id; @@ -133,8 +128,6 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); -static gboolean pmlock_check(void *data); - static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; @@ -172,10 +165,6 @@ static int trans_table[S_END][EVENT_END] = { #define S_COVER_TIMEOUT 8000 #define GET_HOLDKEY_BLOCK_STATE(x) ((x >> SHIFT_LOCK_FLAG) & HOLD_KEY_BLOCK_BIT) #define BOOTING_DONE_WATING_TIME 60000 /* 1 minute */ -#define LOCK_TIME_WARNING 60 /* 60 seconds */ - -#define ACTIVE_ACT "active" -#define INACTIVE_ACT "inactive" #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ #define LONG_PRESS_INTERVAL 2 /* 2 seconds */ @@ -221,49 +210,6 @@ struct display_function_info display_info = { .face_detection = NULL, }; -typedef struct _pm_lock_node { - pid_t pid; - guint timeout_id; - guint warning_id; - GVariant *warning_param; - time_t time; - bool holdkey_block; - bool background; - bool broadcast_warning; -} PmLockNode; - -static dd_list *cond_head[S_END]; - -static void set_process_active(bool flag, pid_t pid) -{ - int ret; - - if (pid >= INTERNAL_LOCK_BASE) - return; - - /* Send dbug to resourced */ - ret = dbus_handle_emit_dbus_signal(NULL, - RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - RESOURCED_METHOD_ACTIVE, - g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); - if (ret < 0) - _E("Failed to send dbus signal to resourced."); -} - -bool check_lock_state(int state) -{ - dd_list *elem; - PmLockNode *t; - - DD_LIST_FOREACH(cond_head[state], elem, t) { - if (t->background == false) - return true; - } - - return false; -} - void change_state_action(enum state_t state, int (*func)(int timeout)) { _I("[%s] 'action' is changed.", states[state].name); @@ -542,141 +488,6 @@ int get_hallic_open(void) return hallic_open; } -static int refresh_app_cond() -{ - trans_condition = 0; - - if (check_lock_state(S_NORMAL)) - trans_condition = trans_condition | MASK_NORMAL; - if (check_lock_state(S_LCDDIM)) - trans_condition = trans_condition | MASK_DIM; - if (check_lock_state(S_LCDOFF)) - trans_condition = trans_condition | MASK_OFF; - - return 0; -} - -static void makeup_trans_condition(void) -{ - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - check_processes(S_LCDOFF); - refresh_app_cond(); -} - -static PmLockNode *find_node(enum state_t s_index, pid_t pid) -{ - dd_list *elem; - PmLockNode *t = NULL; - - DD_LIST_FOREACH(cond_head[s_index], elem, t) { - if (t->pid == pid) - return t; - } - - return NULL; -} - -static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, - bool holdkey_block) -{ - guint warning_id = 0; - PmLockNode *n; - GVariant *v = NULL; - time_t now; - - n = (PmLockNode *) malloc(sizeof(PmLockNode)); - if (n == NULL) { - _E("Not enough memory, add cond. fail"); - return NULL; - } - - if (pid < INTERNAL_LOCK_BASE) { - v = g_variant_new("(ii)", s_index, pid); - if (v) { - warning_id = g_timeout_add_seconds(display_conf.lockcheck_timeout, - pmlock_check, (void *)v); - } else { - _E("Failed to make GVariant."); - } - } - - time(&now); - n->pid = pid; - n->timeout_id = timeout_id; - n->warning_id = warning_id; - n->warning_param = v; - n->time = now; - n->holdkey_block = holdkey_block; - n->background = false; - n->broadcast_warning = true; - DD_LIST_APPEND(cond_head[s_index], n); - - refresh_app_cond(); - return n; -} - -static int del_node(enum state_t s_index, PmLockNode *n) -{ - if (n == NULL) - return 0; - - DD_LIST_REMOVE(cond_head[s_index], n); - - /* delete timer */ - if (n->timeout_id) { - g_source_remove(n->timeout_id); - n->timeout_id = 0; - } - if (n->warning_id) { - g_source_remove(n->warning_id); - n->warning_id = 0; - } - if (n->warning_param) { - g_variant_unref(n->warning_param); - n->warning_param = NULL; - } - - free(n); - refresh_app_cond(); - return 0; -} - -static void print_node(int next) -{ - int ret; - dd_list *elem; - PmLockNode *n; - char buf[30]; - time_t now; - double diff; - - if (next <= S_START || next >= S_END) - return; - - time(&now); - DD_LIST_FOREACH(cond_head[next], elem, n) { - diff = difftime(now, n->time); - ctime_r(&n->time, buf); - buf[strlen(buf) - 1] = 0; - - if (diff > LOCK_TIME_WARNING) { - if (diff > LOCK_TIME_WARNING * 60 && n->pid < INTERNAL_LOCK_BASE && n->broadcast_warning) { - ret = dbus_handle_emit_dbus_signal(NULL, - DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - "pmlock_over", - g_variant_new("(i)", n->pid)); - if (ret < 0) - _E("Failed to send dbus signal pmlock_over."); - n->broadcast_warning = false; - } - _W("Over(%.0f s) pid( %5d) lock time(%s)", diff, n->pid, buf); - } else - _I("Pid(%5d) lock time(%s)", n->pid, buf); - } -} - void get_pname(pid_t pid, char *pname) { char buf[PATH_MAX]; @@ -747,116 +558,6 @@ static gboolean del_off_cond(void *data) return G_SOURCE_REMOVE; } -static void pmlock_check_cb(GVariant *var, void *user_data, GError *err) -{ - pid_t pid = 0; - int ret, detected = 0; - char *app_id = NULL; - enum state_t state = (enum state_t) user_data; - PmLockNode *node; - time_t now; - double diff; - - if (!var) - return; - - if (!dh_get_param_from_var(var, "(iis)", &pid, &detected, &app_id)) { - _E("Failed to get params from gvariant. expected:%s, type:%s", "(iis)", g_variant_get_type_string(var)); - goto out; - } - - if (is_app(pid) == 1 && !detected) - goto out; - - node = find_node(state, pid); - if (!node) - goto out; - - time(&now); - diff = difftime(now, node->time); - - CRITICAL_LOG("%s(%d) has held %s lock for a long time(%.0f s).", - app_id, pid, states[state].name + 2, diff); - - ret = dbus_handle_emit_dbus_signal(NULL, - DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - "pmlock_expired", - g_variant_new("(i)", pid)); - if (ret < 0) - _E("Failed to send dbus pmlock_expired"); - -out: - if (app_id) - g_free(app_id); - g_variant_unref(var); -} - -/* - * Any process is possible many time lock, deviced can not know malicious - * or good process. so infinity or more then 10 min lock process, deviced - * will check it through resoured. And then, it will ask the user whether to quit or not. - */ -static gboolean pmlock_check(void *data) -{ - const char *arr[2]; - char chr_pid[PID_MAX]; - PmLockNode *node; - GVariant *v; - enum state_t state; - pid_t pid; - int ret; - - if (!data) { - _E("Invalid parameter."); - return G_SOURCE_REMOVE; - } - - v = (GVariant*)data; - g_variant_get(v, "(ii)", &state, &pid); - - if (state == S_LCDOFF && backlight_ops.get_lcd_power() == DPMS_ON) { - _D("Lcd state is PM_LCD_POWER_ON"); - return G_SOURCE_CONTINUE; - } - - /* Stop checking lock if process had been terminated */ - if (kill(pid, 0) == -1) { - node = find_node(state, pid); - del_node(state, node); - _I("Process %d not found. Stop checking lock.", pid); - return G_SOURCE_REMOVE; - } - - snprintf(chr_pid, sizeof(chr_pid), "%d", pid); - arr[0] = chr_pid; - switch (state) { - case S_NORMAL: - arr[1] = "normal"; - break; - case S_LCDDIM: - arr[1] = "lcddim"; - break; - case S_LCDOFF: - arr[1] = "lcdoff"; - break; - default: - _E("Invalid state."); - g_variant_unref(v); - return G_SOURCE_REMOVE; - } - - ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, - RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - METHOD_APP_STATUS, - "is", arr, pmlock_check_cb, -1, (void *)(intptr_t)state); - if (ret < 0) - _E("Failed to call dbus method"); - - return G_SOURCE_CONTINUE; -} - /* timeout handler */ gboolean timeout_handler(void *data) { @@ -1017,26 +718,6 @@ static inline bool check_lcd_is_on(void) return true; } -static int check_lock_condition(enum state_t state) -{ - dd_list *elem; - PmLockNode *t = NULL; - int ret = false; - pid_t owner = getpid(); - - _D("check holdkey block : state of %s", states[state].name); - - DD_LIST_FOREACH(cond_head[state], elem, t) { - if (t->pid != owner && t->background == false) { - ret = true; - _I("state change was blocked by pid(%d)!", t->pid); - break; - } - } - - return ret; -} - static gboolean timer_refresh_cb(gpointer data) { struct state *st; @@ -1443,85 +1124,6 @@ static int proc_condition(PMMsg *data) return 0; } -/* If some changed, return 1 */ -int check_processes(enum state_t prohibit_state) -{ - dd_list *elem, *next; - PmLockNode *t = NULL; - int ret = 0; - - DD_LIST_FOREACH_SAFE(cond_head[prohibit_state], elem, next, t) { - if (t->pid < INTERNAL_LOCK_BASE && kill(t->pid, 0) == -1) { - _E("%d process does not exist, delete the REQ" - " - prohibit state %d ", - t->pid, prohibit_state); - if (t->pid == custom_change_pid) { - get_lcd_timeout_from_settings(); - custom_normal_timeout = custom_dim_timeout = 0; - custom_change_pid = -1; - } - ret = 1; - set_unlock_time(t->pid, prohibit_state); - del_node(prohibit_state, t); - } - } - - return ret; -} - -int check_holdkey_block(enum state_t state) -{ - dd_list *elem; - PmLockNode *t = NULL; - int ret = 0; - - _I("Check holdkey block: state of %s", states[state].name); - - if (custom_holdkey_block == true) { - _I("Custom hold key blocked by pid(%d).", - custom_change_pid); - return 1; - } - - DD_LIST_FOREACH(cond_head[state], elem, t) { - if (t->holdkey_block == true) { - ret = 1; - _I("Hold key blocked by pid(%d).", t->pid); - break; - } - } - - return ret; -} - -int delete_condition(enum state_t state) -{ - dd_list *elem, *next; - PmLockNode *t = NULL; - - _I("delete condition : state of %s", states[state].name); - - if (!cond_head[state]) - return 0; - - DD_LIST_FOREACH_SAFE(cond_head[state], elem, next, t) { - if (t->timeout_id > 0) { - g_source_remove(t->timeout_id); - t->timeout_id = 0; - } - if (state == S_LCDOFF) - set_process_active(false, t->pid); - _I("delete node of pid(%d)", t->pid); - set_unlock_time(t->pid, state); - del_node(state, t); - } - - DD_LIST_FREE_LIST(cond_head[state]); - cond_head[state] = NULL; - - return 0; -} - void update_lcdoff_source(int source) { int ret; @@ -1644,9 +1246,9 @@ void print_info(int fd) _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Tran. Locked : %s %s %s\n", - (trans_condition & MASK_NORMAL) ? states[S_NORMAL].name : "-", - (trans_condition & MASK_DIM) ? states[S_LCDDIM].name : "-", - (trans_condition & MASK_OFF) ? states[S_LCDOFF].name : "-"); + (get_trans_condition() & MASK_NORMAL) ? states[S_NORMAL].name : "-", + (get_trans_condition() & MASK_DIM) ? states[S_LCDDIM].name : "-", + (get_trans_condition() & MASK_OFF) ? states[S_LCDOFF].name : "-"); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("Write() failed: %d", errno); @@ -1663,7 +1265,7 @@ void print_info(int fd) _E("Write() failed: %d", errno); for (s_index = S_NORMAL; s_index < S_END; s_index++) { - DD_LIST_FOREACH(cond_head[s_index], elem, t) { + DD_LIST_FOREACH(get_cond_head(s_index), elem, t) { get_pname((pid_t)t->pid, pname); ctime_r(&t->time, time_buf); time_buf[strlen(time_buf) - 1] = 0; @@ -1771,14 +1373,6 @@ int check_lcdoff_direct(void) return true; } -static int __check_lcdoff_lock_state(void) -{ - if (cond_head[S_LCDOFF] != NULL) - return true; - - return false; -} - /* * default transition function * 1. call check @@ -2038,7 +1632,7 @@ static int default_check(int curr, int next) makeup_trans_condition(); - trans_cond = trans_condition & MASK_BIT; + trans_cond = get_trans_condition() & MASK_BIT; if (next == S_NORMAL) /* S_NORMAL is exceptional */ return 1; @@ -2597,7 +2191,6 @@ static int display_probe(void *data) /* display_plugin instance initialization */ init_pm_internal(); - disp_plgn.check_lcdoff_lock_state = __check_lcdoff_lock_state; disp_plgn.device_flags_to_string = __device_flags_to_string; return 0; diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 90c0f05..88324d7 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -41,6 +41,7 @@ #include "power/power-handler.h" #include "led/touch-key.h" #include "apps/apps.h" +#include "display/display-lock.h" #ifndef KEY_SCREENLOCK #define KEY_SCREENLOCK 0x98 diff --git a/plugins/tv/display/state-tv.c b/plugins/tv/display/state-tv.c index b99ea0f..435ae19 100644 --- a/plugins/tv/display/state-tv.c +++ b/plugins/tv/display/state-tv.c @@ -25,6 +25,7 @@ #include "core/device-notifier.h" #include "core/devices.h" #include "display/display-ops.h" +#include "display/display-lock.h" #include "power/power-handler.h" #include "core.h" #include "poll.h" diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 1837df7..0c52ac4 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -62,6 +62,7 @@ #include "display-info.h" #include "battery-monitor.h" #include "display/display-signal.h" +#include "display-lock.h" #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" @@ -75,8 +76,6 @@ #define ALWAYS_ON_TIMEOUT 360000000 #define LATE_LCD_TRANSIT 1 -#define PID_MAX 6 - #define GESTURE_STR "gesture" #define POWER_KEY_STR "powerkey" #define BACK_KEY_STR "backkey" @@ -89,14 +88,11 @@ #define DISPLAY_DETACH_STR "display_detach" #define UNKNOWN_STR "unknown" -#define METHOD_APP_STATUS "CheckAppStatus" - extern void init_pm_internal(); extern int get_charging_status(int *val); extern void init_save_userlock(void); unsigned int pm_status_flag; -static int trans_condition; static void (*power_saving_func) (int onoff); static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT; @@ -107,8 +103,7 @@ guint timeout_src_id; int system_wakeup_flag = false; static unsigned int custom_normal_timeout = 0; static unsigned int custom_dim_timeout = 0; -static int custom_holdkey_block = false; -static int custom_change_pid = -1; +int custom_holdkey_block = false; static char *custom_change_name; static bool hallic_open = true; static guint lock_timeout_id; @@ -135,8 +130,6 @@ static gboolean del_normal_cond(void *data); static gboolean del_dim_cond(void *data); static gboolean del_off_cond(void *data); -static gboolean pmlock_check(void *data); - static int default_proc_change_state(unsigned int cond, pid_t pid); static int (*proc_change_state)(unsigned int cond, pid_t pid) = default_proc_change_state; @@ -174,10 +167,6 @@ static int trans_table[S_END][EVENT_END] = { #define S_COVER_TIMEOUT 8000 #define GET_HOLDKEY_BLOCK_STATE(x) ((x >> SHIFT_LOCK_FLAG) & HOLD_KEY_BLOCK_BIT) #define BOOTING_DONE_WATING_TIME 60000 /* 1 minute */ -#define LOCK_TIME_WARNING 60 /* 60 seconds */ - -#define ACTIVE_ACT "active" -#define INACTIVE_ACT "inactive" #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ #define LONG_PRESS_INTERVAL 500 /* 0.5 seconds */ @@ -223,49 +212,6 @@ struct display_function_info display_info = { .face_detection = NULL, }; -typedef struct _pm_lock_node { - pid_t pid; - guint timeout_id; - guint warning_id; - GVariant *warning_param; - time_t time; - bool holdkey_block; - bool background; - bool broadcast_warning; -} PmLockNode; - -static dd_list *cond_head[S_END]; - -static void set_process_active(bool flag, pid_t pid) -{ - int ret; - - if (pid >= INTERNAL_LOCK_BASE) - return; - - /* Send dbug to resourced */ - ret = dbus_handle_emit_dbus_signal(NULL, - RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - RESOURCED_METHOD_ACTIVE, - g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); - if (ret < 0) - _E("Failed to send dbus signal to resourced."); -} - -bool check_lock_state(int state) -{ - dd_list *elem; - PmLockNode *t; - - DD_LIST_FOREACH(cond_head[state], elem, t) { - if (t->background == false) - return true; - } - - return false; -} - void change_state_action(enum state_t state, int (*func)(int timeout)) { _I("[%s] 'action' is changed.", states[state].name); @@ -563,141 +509,6 @@ int get_hallic_open(void) return hallic_open; } -static int refresh_app_cond() -{ - trans_condition = 0; - - if (check_lock_state(S_NORMAL)) - trans_condition = trans_condition | MASK_NORMAL; - if (check_lock_state(S_LCDDIM)) - trans_condition = trans_condition | MASK_DIM; - if (check_lock_state(S_LCDOFF)) - trans_condition = trans_condition | MASK_OFF; - - return 0; -} - -static void makeup_trans_condition(void) -{ - check_processes(S_NORMAL); - check_processes(S_LCDDIM); - check_processes(S_LCDOFF); - refresh_app_cond(); -} - -static PmLockNode *find_node(enum state_t s_index, pid_t pid) -{ - dd_list *elem; - PmLockNode *t = NULL; - - DD_LIST_FOREACH(cond_head[s_index], elem, t) { - if (t->pid == pid) - return t; - } - - return NULL; -} - -static PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, - bool holdkey_block) -{ - guint warning_id = 0; - PmLockNode *n; - GVariant *v = NULL; - time_t now; - - n = (PmLockNode *) malloc(sizeof(PmLockNode)); - if (n == NULL) { - _E("Not enough memory, add cond. fail"); - return NULL; - } - - if (pid < INTERNAL_LOCK_BASE) { - v = g_variant_new("(ii)", s_index, pid); - if (v) { - warning_id = g_timeout_add_seconds(display_conf.lockcheck_timeout, - pmlock_check, (void *)v); - } else { - _E("Failed to make GVariant."); - } - } - - time(&now); - n->pid = pid; - n->timeout_id = timeout_id; - n->warning_id = warning_id; - n->warning_param = v; - n->time = now; - n->holdkey_block = holdkey_block; - n->background = false; - n->broadcast_warning = true; - DD_LIST_APPEND(cond_head[s_index], n); - - refresh_app_cond(); - return n; -} - -static int del_node(enum state_t s_index, PmLockNode *n) -{ - if (n == NULL) - return 0; - - DD_LIST_REMOVE(cond_head[s_index], n); - - /* delete timer */ - if (n->timeout_id) { - g_source_remove(n->timeout_id); - n->timeout_id = 0; - } - if (n->warning_id) { - g_source_remove(n->warning_id); - n->warning_id = 0; - } - if (n->warning_param) { - g_variant_unref(n->warning_param); - n->warning_param = NULL; - } - - free(n); - refresh_app_cond(); - return 0; -} - -static void print_node(int next) -{ - int ret; - dd_list *elem; - PmLockNode *n; - char buf[30]; - time_t now; - double diff; - - if (next <= S_START || next >= S_END) - return; - - time(&now); - DD_LIST_FOREACH(cond_head[next], elem, n) { - diff = difftime(now, n->time); - ctime_r(&n->time, buf); - buf[strlen(buf) - 1] = 0; - - if (diff > LOCK_TIME_WARNING) { - if (diff > LOCK_TIME_WARNING * 60 && n->pid < INTERNAL_LOCK_BASE && n->broadcast_warning) { - ret = dbus_handle_emit_dbus_signal(NULL, - DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - "pmlock_over", - g_variant_new("(i)", n->pid)); - if (ret < 0) - _E("Failed to send dbus signal pmlock_over."); - n->broadcast_warning = false; - } - _W("Over(%.0f s) pid( %5d) lock time(%s)", diff, n->pid, buf); - } else - _I("Pid(%5d) lock time(%s)", n->pid, buf); - } -} - void get_pname(pid_t pid, char *pname) { char buf[PATH_MAX]; @@ -768,116 +579,6 @@ static gboolean del_off_cond(void *data) return G_SOURCE_REMOVE; } -static void pmlock_check_cb(GVariant *var, void *user_data, GError *err) -{ - pid_t pid = 0; - int ret, detected = 0; - char *app_id = NULL; - enum state_t state = (enum state_t) user_data; - PmLockNode *node; - time_t now; - double diff; - - if (!var) - return; - - if (!dh_get_param_from_var(var, "(iis)", &pid, &detected, &app_id)) { - _E("Failed to get params from gvariant. expected:%s, type:%s", "(iis)", g_variant_get_type_string(var)); - goto out; - } - - if (is_app(pid) == 1 && !detected) - goto out; - - node = find_node(state, pid); - if (!node) - goto out; - - time(&now); - diff = difftime(now, node->time); - - CRITICAL_LOG("%s(%d) has held %s lock for a long time(%.0f s).", - app_id, pid, states[state].name + 2, diff); - - ret = dbus_handle_emit_dbus_signal(NULL, - DEVICED_PATH_DISPLAY, - DEVICED_INTERFACE_DISPLAY, - "pmlock_expired", - g_variant_new("(i)", pid)); - if (ret < 0) - _E("Failed to send dbus pmlock_expired"); - -out: - if (app_id) - g_free(app_id); - g_variant_unref(var); -} - -/* - * Any process is possible many time lock, deviced can not know malicious - * or good process. so infinity or more then 10 min lock process, deviced - * will check it through resoured. And then, it will ask the user whether to quit or not. - */ -static gboolean pmlock_check(void *data) -{ - const char *arr[2]; - char chr_pid[PID_MAX]; - PmLockNode *node; - GVariant *v; - enum state_t state; - pid_t pid; - int ret; - - if (!data) { - _E("Invalid parameter."); - return G_SOURCE_REMOVE; - } - - v = (GVariant*)data; - g_variant_get(v, "(ii)", &state, &pid); - - if (state == S_LCDOFF && backlight_ops.get_lcd_power() == DPMS_ON) { - _D("Lcd state is PM_LCD_POWER_ON"); - return G_SOURCE_CONTINUE; - } - - /* Stop checking lock if process had been terminated */ - if (kill(pid, 0) == -1) { - node = find_node(state, pid); - del_node(state, node); - _I("Process %d not found. Stop checking lock.", pid); - return G_SOURCE_REMOVE; - } - - snprintf(chr_pid, sizeof(chr_pid), "%d", pid); - arr[0] = chr_pid; - switch (state) { - case S_NORMAL: - arr[1] = "normal"; - break; - case S_LCDDIM: - arr[1] = "lcddim"; - break; - case S_LCDOFF: - arr[1] = "lcdoff"; - break; - default: - _E("Invalid state."); - g_variant_unref(v); - return G_SOURCE_REMOVE; - } - - ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, - RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - METHOD_APP_STATUS, - "is", arr, pmlock_check_cb, -1, (void *)(intptr_t)state); - if (ret < 0) - _E("Failed to call dbus method"); - - return G_SOURCE_CONTINUE; -} - /* timeout handler */ gboolean timeout_handler(void *data) { @@ -1047,26 +748,6 @@ static inline bool check_lcd_is_on(void) return true; } -static int check_lock_condition(enum state_t state) -{ - dd_list *elem; - PmLockNode *t = NULL; - int ret = false; - pid_t owner = getpid(); - - _D("check holdkey block : state of %s", states[state].name); - - DD_LIST_FOREACH(cond_head[state], elem, t) { - if (t->pid != owner && t->background == false) { - ret = true; - _I("state change was blocked by pid(%d)!", t->pid); - break; - } - } - - return ret; -} - static gboolean timer_refresh_cb(gpointer data) { struct state *st; @@ -1493,85 +1174,6 @@ static int proc_condition(PMMsg *data) return 0; } -/* If some changed, return 1 */ -int check_processes(enum state_t prohibit_state) -{ - dd_list *elem, *next; - PmLockNode *t = NULL; - int ret = 0; - - DD_LIST_FOREACH_SAFE(cond_head[prohibit_state], elem, next, t) { - if (t->pid < INTERNAL_LOCK_BASE && kill(t->pid, 0) == -1) { - _E("%d process does not exist, delete the REQ" - " - prohibit state %d ", - t->pid, prohibit_state); - if (t->pid == custom_change_pid) { - get_lcd_timeout_from_settings(); - custom_normal_timeout = custom_dim_timeout = 0; - custom_change_pid = -1; - } - ret = 1; - set_unlock_time(t->pid, prohibit_state); - del_node(prohibit_state, t); - } - } - - return ret; -} - -int check_holdkey_block(enum state_t state) -{ - dd_list *elem; - PmLockNode *t = NULL; - int ret = 0; - - _I("Check holdkey block: state of %s", states[state].name); - - if (custom_holdkey_block == true) { - _I("Custom hold key blocked by pid(%d).", - custom_change_pid); - return 1; - } - - DD_LIST_FOREACH(cond_head[state], elem, t) { - if (t->holdkey_block == true) { - ret = 1; - _I("Hold key blocked by pid(%d).", t->pid); - break; - } - } - - return ret; -} - -int delete_condition(enum state_t state) -{ - dd_list *elem, *next; - PmLockNode *t = NULL; - - _I("delete condition : state of %s", states[state].name); - - if (!cond_head[state]) - return 0; - - DD_LIST_FOREACH_SAFE(cond_head[state], elem, next, t) { - if (t->timeout_id > 0) { - g_source_remove(t->timeout_id); - t->timeout_id = 0; - } - if (state == S_LCDOFF) - set_process_active(false, t->pid); - _I("delete node of pid(%d)", t->pid); - set_unlock_time(t->pid, state); - del_node(state, t); - } - - DD_LIST_FREE_LIST(cond_head[state]); - cond_head[state] = NULL; - - return 0; -} - void update_lcdoff_source(int source) { int ret; @@ -1694,9 +1296,9 @@ void print_info(int fd) _E("Write() failed: %d", errno); snprintf(buf, sizeof(buf), "Tran. Locked : %s %s %s\n", - (trans_condition & MASK_NORMAL) ? states[S_NORMAL].name : "-", - (trans_condition & MASK_DIM) ? states[S_LCDDIM].name : "-", - (trans_condition & MASK_OFF) ? states[S_LCDOFF].name : "-"); + (get_trans_condition() & MASK_NORMAL) ? states[S_NORMAL].name : "-", + (get_trans_condition() & MASK_DIM) ? states[S_LCDDIM].name : "-", + (get_trans_condition() & MASK_OFF) ? states[S_LCDOFF].name : "-"); ret = write(fd, buf, strlen(buf)); if (ret < 0) _E("Write() failed: %d", errno); @@ -1713,7 +1315,7 @@ void print_info(int fd) _E("Write() failed: %d", errno); for (s_index = S_NORMAL; s_index < S_END; s_index++) { - DD_LIST_FOREACH(cond_head[s_index], elem, t) { + DD_LIST_FOREACH(get_cond_head(s_index), elem, t) { get_pname((pid_t)t->pid, pname); ctime_r(&t->time, time_buf); time_buf[strlen(time_buf) - 1] = 0; @@ -1821,14 +1423,6 @@ int check_lcdoff_direct(void) return true; } -static int __check_lcdoff_lock_state(void) -{ - if (cond_head[S_LCDOFF] != NULL) - return true; - - return false; -} - /* * default transition function * 1. call check @@ -2108,7 +1702,7 @@ static int default_check(int curr, int next) makeup_trans_condition(); - trans_cond = trans_condition & MASK_BIT; + trans_cond = get_trans_condition() & MASK_BIT; if (next == S_NORMAL) /* S_NORMAL is exceptional */ return 1; @@ -2671,7 +2265,6 @@ static int display_probe(void *data) /* display_plugin instance initialization */ init_pm_internal(); - disp_plgn.check_lcdoff_lock_state = __check_lcdoff_lock_state; disp_plgn.device_flags_to_string = __device_flags_to_string; return 0; diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 97aab1c..e84836a 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -41,6 +41,7 @@ #include "power/power-handler.h" #include "led/touch-key.h" #include "apps/apps.h" +#include "display/display-lock.h" #ifndef KEY_SCREENLOCK #define KEY_SCREENLOCK 0x98 diff --git a/src/display/core.h b/src/display/core.h index 3f175f8..eb9ddb5 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -183,7 +183,6 @@ void reset_lcd_timeout(GDBusConnection *conn, const gchar *sender, const gchar *unique_name, gpointer data); -int check_lcdoff_lock_state(void); /* setting.c */ int get_lock_screen_bg_state(void); @@ -199,8 +198,6 @@ void change_state_name(enum state_t state, const char *name); void change_trans_table(enum state_t state, enum state_t next); void change_proc_change_state(int (*func)(unsigned int cond, pid_t pid)); -bool check_lock_state(int state); - int delete_condition(enum state_t state); int custom_lcdoff(enum device_flags flag); int display_on_by_reason(const char *reason, int timeout); @@ -216,7 +213,6 @@ void lcd_on_direct(enum device_flags flags); void lcd_on_procedure(int state, enum device_flags flag); void lcd_off_procedure(enum device_flags flag); void lcd_direct_control(enum dpms_state state, int flags); -int check_holdkey_block(enum state_t state); bool touch_event_blocked(void); void broadcast_lcd_off_late(enum device_flags flags); void set_dim_state(bool on); diff --git a/src/display/display-lock.c b/src/display/display-lock.c new file mode 100644 index 0000000..a7e6ae9 --- /dev/null +++ b/src/display/display-lock.c @@ -0,0 +1,393 @@ +/* + * deviced + * + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file display-lock.c + * @brief Manage each state's lock. Lock blocks state transition by timeout. + * + */ +#include "core/common.h" +#include "device-interface.h" +#include "poll.h" +#include "display-signal.h" +#include "lock-detector.h" +#include "display-lock.h" +#include "shared/log-macro.h" + +#define METHOD_APP_STATUS "CheckAppStatus" +#define PID_MAX 6 +#define LOCK_TIME_WARNING 60 /* 60 seconds */ + +static dd_list *cond_head[S_END]; +static int trans_condition; + +bool check_lock_state(int state) +{ + dd_list *elem; + PmLockNode *t; + + DD_LIST_FOREACH(cond_head[state], elem, t) { + if (t->background == false) + return true; + } + + return false; +} + +static void refresh_app_cond() +{ + trans_condition = 0; + + if (check_lock_state(S_NORMAL)) + trans_condition |= MASK_NORMAL; + if (check_lock_state(S_LCDDIM)) + trans_condition |= MASK_DIM; + if (check_lock_state(S_LCDOFF)) + trans_condition |= MASK_OFF; +} + +static void pmlock_check_cb(GVariant *var, void *user_data, GError *err) +{ + pid_t pid = 0; + int ret, detected = 0; + char *app_id = NULL; + enum state_t state = (enum state_t) user_data; + PmLockNode *node; + time_t now; + double diff; + + if (!var) + return; + + if (!dh_get_param_from_var(var, "(iis)", &pid, &detected, &app_id)) { + _E("Failed to get params from gvariant. expected:%s, type:%s", "(iis)", g_variant_get_type_string(var)); + goto out; + } + + if (is_app(pid) == 1 && !detected) + goto out; + + node = find_node(state, pid); + if (!node) + goto out; + + time(&now); + diff = difftime(now, node->time); + + CRITICAL_LOG("%s(%d) has held %s lock for a long time(%.0f s).", + app_id, pid, states[state].name + 2, diff); + + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "pmlock_expired", + g_variant_new("(i)", pid)); + if (ret < 0) + _E("Failed to send dbus pmlock_expired"); + +out: + if (app_id) + g_free(app_id); + g_variant_unref(var); +} + +static gboolean pmlock_check(void *data) +{ + const char *arr[2]; + char chr_pid[PID_MAX]; + PmLockNode *node; + GVariant *v; + enum state_t state; + pid_t pid; + int ret; + + if (!data) { + _E("Invalid parameter."); + return G_SOURCE_REMOVE; + } + + v = (GVariant*)data; + g_variant_get(v, "(ii)", &state, &pid); + + if (state == S_LCDOFF && backlight_ops.get_lcd_power() == DPMS_ON) { + _D("Lcd state is PM_LCD_POWER_ON"); + return G_SOURCE_CONTINUE; + } + + /* Stop checking lock if process had been terminated */ + if (kill(pid, 0) == -1) { + node = find_node(state, pid); + del_node(state, node); + _I("Process %d not found. Stop checking lock.", pid); + return G_SOURCE_REMOVE; + } + + snprintf(chr_pid, sizeof(chr_pid), "%d", pid); + arr[0] = chr_pid; + switch (state) { + case S_NORMAL: + arr[1] = "normal"; + break; + case S_LCDDIM: + arr[1] = "lcddim"; + break; + case S_LCDOFF: + arr[1] = "lcdoff"; + break; + default: + _E("Invalid state."); + g_variant_unref(v); + return G_SOURCE_REMOVE; + } + + ret = dbus_handle_method_async_with_reply(RESOURCED_BUS_NAME, + RESOURCED_PATH_PROCESS, + RESOURCED_INTERFACE_PROCESS, + METHOD_APP_STATUS, + "is", arr, pmlock_check_cb, -1, (void *)(intptr_t)state); + if (ret < 0) + _E("Failed to call dbus method"); + + return G_SOURCE_CONTINUE; +} + + +PmLockNode *find_node(enum state_t s_index, pid_t pid) +{ + dd_list *elem; + PmLockNode *t = NULL; + + DD_LIST_FOREACH(cond_head[s_index], elem, t) { + if (t->pid == pid) + return t; + } + + return NULL; +} + +PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, + bool holdkey_block) +{ + guint warning_id = 0; + PmLockNode *n; + GVariant *v = NULL; + time_t now; + + n = (PmLockNode *) malloc(sizeof(PmLockNode)); + if (n == NULL) { + _E("Not enough memory, add cond. fail"); + return NULL; + } + + if (pid < INTERNAL_LOCK_BASE) { + v = g_variant_new("(ii)", s_index, pid); + if (v) { + warning_id = g_timeout_add_seconds(display_conf.lockcheck_timeout, + pmlock_check, (void *)v); + } else { + _E("Failed to make GVariant."); + } + } + + time(&now); + n->pid = pid; + n->timeout_id = timeout_id; + n->warning_id = warning_id; + n->warning_param = v; + n->time = now; + n->holdkey_block = holdkey_block; + n->background = false; + n->broadcast_warning = true; + DD_LIST_APPEND(cond_head[s_index], n); + + refresh_app_cond(); + return n; +} + +int del_node(enum state_t s_index, PmLockNode *n) +{ + if (n == NULL) + return 0; + + DD_LIST_REMOVE(cond_head[s_index], n); + + /* delete timer */ + if (n->timeout_id) { + g_source_remove(n->timeout_id); + n->timeout_id = 0; + } + if (n->warning_id) { + g_source_remove(n->warning_id); + n->warning_id = 0; + } + if (n->warning_param) { + g_variant_unref(n->warning_param); + n->warning_param = NULL; + } + + free(n); + refresh_app_cond(); + return 0; +} + +int check_lock_condition(enum state_t state) +{ + dd_list *elem; + PmLockNode *t = NULL; + int ret = false; + pid_t owner = getpid(); + + _D("check holdkey block : state of %s", states[state].name); + + DD_LIST_FOREACH(cond_head[state], elem, t) { + if (t->pid != owner && t->background == false) { + ret = true; + _I("state change was blocked by pid(%d)!", t->pid); + break; + } + } + + return ret; +} + +int check_holdkey_block(enum state_t state) +{ + dd_list *elem; + PmLockNode *t = NULL; + int ret = 0; + + _I("Check holdkey block: state of %s", states[state].name); + + if (custom_holdkey_block == true) { + _I("Custom hold key blocked"); + return 1; + } + + DD_LIST_FOREACH(cond_head[state], elem, t) { + if (t->holdkey_block == true) { + ret = 1; + _I("Hold key blocked by pid(%d).", t->pid); + break; + } + } + + return ret; +} + +int delete_condition(enum state_t state) +{ + dd_list *elem, *next; + PmLockNode *t = NULL; + + _I("delete condition : state of %s", states[state].name); + + if (!cond_head[state]) + return 0; + + DD_LIST_FOREACH_SAFE(cond_head[state], elem, next, t) { + if (t->timeout_id > 0) { + g_source_remove(t->timeout_id); + t->timeout_id = 0; + } + if (state == S_LCDOFF) + set_process_active(false, t->pid); + _I("delete node of pid(%d)", t->pid); + set_unlock_time(t->pid, state); + del_node(state, t); + } + + DD_LIST_FREE_LIST(cond_head[state]); + cond_head[state] = NULL; + + return 0; +} + +void print_node(int next) +{ + int ret; + dd_list *elem; + PmLockNode *n; + char buf[30]; + time_t now; + double diff; + + if (next <= S_START || next >= S_END) + return; + + time(&now); + DD_LIST_FOREACH(cond_head[next], elem, n) { + diff = difftime(now, n->time); + ctime_r(&n->time, buf); + buf[strlen(buf) - 1] = 0; + + if (diff > LOCK_TIME_WARNING) { + if (diff > LOCK_TIME_WARNING * 60 && n->pid < INTERNAL_LOCK_BASE && n->broadcast_warning) { + ret = dbus_handle_emit_dbus_signal(NULL, + DEVICED_PATH_DISPLAY, + DEVICED_INTERFACE_DISPLAY, + "pmlock_over", + g_variant_new("(i)", n->pid)); + if (ret < 0) + _E("Failed to send dbus signal pmlock_over."); + n->broadcast_warning = false; + } + _W("Over(%.0f s) pid( %5d) lock time(%s)", diff, n->pid, buf); + } else + _I("Pid(%5d) lock time(%s)", n->pid, buf); + } +} + +void makeup_trans_condition(void) +{ + check_processes(S_NORMAL); + check_processes(S_LCDDIM); + check_processes(S_LCDOFF); + refresh_app_cond(); +} + +/* If a lock node in the given state had been dead, delete it form lock list, + * and returns 1, else returns 0 */ +int check_processes(enum state_t prohibit_state) +{ + dd_list *elem, *next; + PmLockNode *t = NULL; + int ret = 0; + + DD_LIST_FOREACH_SAFE(cond_head[prohibit_state], elem, next, t) { + if (t->pid < INTERNAL_LOCK_BASE && kill(t->pid, 0) == -1) { + _E("%d process does not exist, delete the REQ" + " - prohibit state %d ", + t->pid, prohibit_state); + ret = 1; + set_unlock_time(t->pid, prohibit_state); + del_node(prohibit_state, t); + } + } + + return ret; +} + +int get_trans_condition(void) +{ + return trans_condition; +} + +dd_list *get_cond_head(enum state_t s_index) +{ + return cond_head[s_index]; +} diff --git a/src/display/display-lock.h b/src/display/display-lock.h new file mode 100644 index 0000000..bde19db --- /dev/null +++ b/src/display/display-lock.h @@ -0,0 +1,55 @@ +/* + * deviced + * + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file display-lock.h + * @brief Manage each state's lock. Lock blocks state transition by timeout. + * + */ +#ifndef __DISPLAY_LOCK_H__ +#define __DISPLAY_LOCK_H__ + +#include "core.h" + +typedef struct _pm_lock_node { + pid_t pid; + guint timeout_id; + guint warning_id; + GVariant *warning_param; + time_t time; + bool holdkey_block; + bool background; + bool broadcast_warning; +} PmLockNode; + +bool check_lock_state(int state); +PmLockNode *find_node(enum state_t s_index, pid_t pid); +PmLockNode *add_node(enum state_t s_index, pid_t pid, guint timeout_id, bool holdkey_block); +int del_node(enum state_t s_index, PmLockNode *n); +int check_lock_condition(enum state_t state); +int check_holdkey_block(enum state_t state); +int delete_condition(enum state_t state); +void print_node(int next); +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); + +extern int custom_holdkey_block; + +#endif /* __DISPLAY_LOCK_H__ */ diff --git a/src/display/display-ops.h b/src/display/display-ops.h index d46ba02..49a36ea 100644 --- a/src/display/display-ops.h +++ b/src/display/display-ops.h @@ -63,7 +63,6 @@ struct display_plugin { int (*pm_lock_internal) (pid_t pid, int s_bits, int flag, int timeout); int (*pm_unlock_internal) (pid_t pid, int s_bits, int flag); int (*pm_change_internal) (pid_t pid, int s_bits); - int (*check_lcdoff_lock_state) (); int (*update_pm_setting) (int key_idx, int val); int (*get_lock_screen_state) (); bool system_wakeup_flag; diff --git a/src/display/display-signal.c b/src/display/display-signal.c index 1ec541d..e6f57e9 100644 --- a/src/display/display-signal.c +++ b/src/display/display-signal.c @@ -18,6 +18,10 @@ #include "display-signal.h" #include "display-ops.h" +#include "poll.h" + +#define ACTIVE_ACT "active" +#define INACTIVE_ACT "inactive" static const char *lcdon_sig_lookup[SIGNAL_MAX] = { [SIGNAL_PRE] = "LCDOn", @@ -151,3 +155,20 @@ void broadcast_lcd_off_late(enum device_flags flags) late_flags = flags; } } + +void set_process_active(bool flag, pid_t pid) +{ + int ret; + + if (pid >= INTERNAL_LOCK_BASE) + return; + + /* Send dbus signal to resourced */ + ret = dbus_handle_emit_dbus_signal(NULL, + RESOURCED_PATH_PROCESS, + RESOURCED_INTERFACE_PROCESS, + RESOURCED_METHOD_ACTIVE, + g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid)); + if (ret < 0) + _E("Failed to send dbus signal to resourced."); +} diff --git a/src/display/display-signal.h b/src/display/display-signal.h index ffb9a83..9001c11 100644 --- a/src/display/display-signal.h +++ b/src/display/display-signal.h @@ -53,3 +53,4 @@ void broadcast_pm_wakeup(void); void broadcast_lcd_on(enum signal_type type, enum device_flags flags); void broadcast_lcd_off(enum signal_type type, enum device_flags flags); void broadcast_lcd_off_late(enum device_flags flags); +void set_process_active(bool flag, pid_t pid); diff --git a/src/time/time-handler.c b/src/time/time-handler.c index 964783b..f019b35 100644 --- a/src/time/time-handler.c +++ b/src/time/time-handler.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "core/log.h" #include "core/devices.h" @@ -71,6 +72,7 @@ int tfd = -1; static gboolean tfd_cb(gint fd, GIOCondition condition, gpointer user_data); static int timerfd_check_stop(int fd); static int timerfd_check_start(void); +static dd_list* (*get_cond_head) (enum state_t state); char *substring(const char *str, size_t begin, size_t len) { @@ -363,8 +365,10 @@ static int time_lcd_changed_cb(void *data) if (lcd_state < S_LCDOFF) goto restart; - if (disp_plgn.check_lcdoff_lock_state) - lcd_state = disp_plgn.check_lcdoff_lock_state(); + if (get_cond_head) + lcd_state = get_cond_head(S_LCDOFF) != NULL; + else + lcd_state = 0; if (lcd_state || !tfdh || tfd == -1) goto out; @@ -392,6 +396,10 @@ static void time_init(void *data) if (timerfd_check_start() == -1) _E("Failed system time change detector init."); register_notifier(DEVICE_NOTIFIER_LCD, time_lcd_changed_cb); + + get_cond_head = dlsym(disp_plgn.handle, "get_cond_head"); + if (!get_cond_head) + _E("Failed to load symbol get_cond_head(), %s.", dlerror()); } static const struct device_ops time_device_ops = { -- 2.7.4 From 9a7b536bc3f88971c05880fdbd869e8216714bed Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 26 May 2020 20:18:06 +0900 Subject: [PATCH 05/16] Fix pmqos Now for each pmqos_cpu manages timer itself by name. So it is possible that multiple timer exist and run at the same time. On receiving new pmqos request for starting boost, 1. If there is no timer managed by that pmqos name, starts boost and create a timer. 2. If there is a running timer and the new timeout is later than the previous timeout, delete the existing timer and create a new one. At this time, the important thing is that the cpu boost is already started, so the cpu boost is not performed. 3. If there is a running timer and the new timeout is earlier than the previous timeout, do nothing because the previous timer includes current request. Change-Id: Id3956a949aee85070896ff5cb64d93484f5e3427 Signed-off-by: Youngjae Cho Signed-off-by: lokilee73 Signed-off-by: Youngjae Cho (cherry picked from commit 5bec2b03d472c9e3737714e948029a0ef5a19bde) Signed-off-by: Youngjae Cho --- src/cpu/pmqos.c | 168 ++++++++++++++++---------------------------------------- 1 file changed, 47 insertions(+), 121 deletions(-) diff --git a/src/cpu/pmqos.c b/src/cpu/pmqos.c index 4a0474f..16d2364 100644 --- a/src/cpu/pmqos.c +++ b/src/cpu/pmqos.c @@ -37,23 +37,24 @@ #define PMQOS_CONF_PATH "/etc/deviced/cpu.conf" #define MILLISECONDS(tv) ((tv.tv_sec)*1000 + (tv.tv_nsec)/1000000) -#define DELTA(a, b) (MILLISECONDS(a) - MILLISECONDS(b)) - -static gboolean pmqos_cpu_timer(gpointer data); struct pmqos_cpu { - char name[NAME_MAX]; - int timeout; + char* name; + long timeout; + guint timeout_id; }; static dd_list *pmqos_head; -static guint unlock_timer; -static struct timespec unlock_timer_start_st; -static struct timespec unlock_timer_end_st; -static struct pmqos_cpu unlock_timer_owner = {"NULL", 0}; - static struct cpu_device *cpu_dev; +static long get_current_monotonic_ms(void) +{ + struct timespec current; + clock_gettime(CLOCK_MONOTONIC, ¤t); + + return MILLISECONDS(current); +} + int set_cpu_pmqos(const char *name, int val) { if (!cpu_dev || @@ -75,68 +76,6 @@ int set_cpu_pmqos(const char *name, int val) return cpu_dev->stop_boost((void *)name); } -static void pmqos_unlock_timeout_update(void) -{ - dd_list *elem, *elem_next; - struct pmqos_cpu *cpu; - int delta = 0; - - clock_gettime(CLOCK_REALTIME, &unlock_timer_end_st); - delta = DELTA(unlock_timer_end_st, unlock_timer_start_st); - - if (delta <= 0) - return; - - DD_LIST_FOREACH(pmqos_head, elem, cpu) { - cpu->timeout -= delta; - if (cpu->timeout < 0) - cpu->timeout = 0; - if (cpu->timeout > 0) - continue; - /* Set cpu unlock */ - set_cpu_pmqos(cpu->name, false); - /* Delete previous request */ - } - - DD_LIST_FOREACH_SAFE(pmqos_head, elem, elem_next, cpu) { - if (cpu->timeout > 0) - continue; - DD_LIST_REMOVE(pmqos_head, cpu); - free(cpu); - } -} - -static int pmqos_unlock_timer_start(void) -{ - int ret; - dd_list *elem; - struct pmqos_cpu *cpu; - - if (unlock_timer) { - g_source_remove(unlock_timer); - unlock_timer = 0; - } - - ret = DD_LIST_LENGTH(pmqos_head); - if (ret == 0) - return 0; - - DD_LIST_FOREACH(pmqos_head, elem, cpu) { - if (cpu->timeout <= 0) - continue; - snprintf(unlock_timer_owner.name, sizeof(unlock_timer_owner.name), "%s", cpu->name); - unlock_timer_owner.timeout = cpu->timeout; - clock_gettime(CLOCK_REALTIME, &unlock_timer_start_st); - unlock_timer = g_timeout_add(unlock_timer_owner.timeout, pmqos_cpu_timer, NULL); - if (unlock_timer == 0) { - _E("Failed to init pmqos unlock. name=%s timeout=%d", cpu->name, cpu->timeout); - return -EPERM; - } - break; - } - return 0; -} - static int pmqos_cpu_cancel(const char *name) { dd_list *elem; @@ -156,57 +95,33 @@ static int pmqos_cpu_cancel(const char *name) if (!cpu) return 0; + if (cpu->timeout_id) { + g_source_remove(cpu->timeout_id); + cpu->timeout_id = 0; + } + /* unlock cpu */ set_cpu_pmqos(cpu->name, false); - /* delete cpu */ - DD_LIST_REMOVE(pmqos_head, cpu); - free(cpu); - - if (!strncmp(unlock_timer_owner.name, name, len)) { - /* undata cpu */ - pmqos_unlock_timeout_update(); - pmqos_unlock_timer_start(); - } - return 0; } -static gboolean pmqos_cpu_timer(gpointer data) +static gboolean pmqos_cpu_timeout(void *data) { - int ret; + struct pmqos_cpu *cpu = (struct pmqos_cpu *)data; - ret = pmqos_cpu_cancel(unlock_timer_owner.name); - if (ret < 0) - _E("Can not find %s request.", unlock_timer_owner.name); + cpu->timeout_id = 0; + set_cpu_pmqos(cpu->name, false); - unlock_timer = 0; return G_SOURCE_REMOVE; } -static int compare_timeout(const void *a, const void *b) -{ - const struct pmqos_cpu *pmqos_a = (const struct pmqos_cpu *)a; - const struct pmqos_cpu *pmqos_b = (const struct pmqos_cpu *)b; - - if (!pmqos_a) - return 1; - if (!pmqos_b) - return -1; - - if (pmqos_a->timeout < pmqos_b->timeout) - return -1; - else if (pmqos_a->timeout > pmqos_b->timeout) - return 1; - return 0; -} - static int pmqos_cpu_request(const char *name, int val) { dd_list *elem; - struct pmqos_cpu *cpu = NULL; - int ret; + struct pmqos_cpu *cpu; size_t len; + long next_timeout; /* Check valid parameter */ if (val > DEFAULT_PMQOS_TIMER) { @@ -217,10 +132,8 @@ static int pmqos_cpu_request(const char *name, int val) /* find cpu */ len = strlen(name) + 1; DD_LIST_FOREACH(pmqos_head, elem, cpu) { - if (!strncmp(cpu->name, name, len)) { - cpu->timeout = val; + if (!strncmp(cpu->name, name, len)) break; - } } /* add cpu */ @@ -229,20 +142,22 @@ static int pmqos_cpu_request(const char *name, int val) if (!cpu) return -ENOMEM; - snprintf(cpu->name, sizeof(cpu->name), "%s", name); - cpu->timeout = val; + cpu->name = strndup(name, NAME_MAX); + cpu->timeout_id = 0; + cpu->timeout = 0; DD_LIST_APPEND(pmqos_head, cpu); } - /* sort cpu */ - DD_LIST_SORT(pmqos_head, compare_timeout); - - ret = pmqos_unlock_timer_start(); - if (ret < 0) - return ret; - - /* Set cpu lock */ - set_cpu_pmqos(cpu->name, true); + next_timeout = get_current_monotonic_ms() + val; + if (!cpu->timeout_id) { // start new one + cpu->timeout = next_timeout; + cpu->timeout_id = g_timeout_add(val, pmqos_cpu_timeout, cpu); + set_cpu_pmqos(cpu->name, true); + } else if (next_timeout > cpu->timeout) { // just extend timeout + g_source_remove(cpu->timeout_id); + cpu->timeout = next_timeout; + cpu->timeout_id = g_timeout_add(val, pmqos_cpu_timeout, cpu); + } return 0; } @@ -270,6 +185,8 @@ static GVariant * dbus_pmqos_handler(GDBusConnection *conn, goto error; } + _I("Request pmqos name: %s, val %d", name, val); + if (val) ret = pmqos_cpu_request(name, val); else @@ -538,6 +455,15 @@ static void pmqos_init(void *data) static void pmqos_exit(void *data) { + dd_list *elem, *elem_next; + struct pmqos_cpu *cpu; + + DD_LIST_FOREACH_SAFE(pmqos_head, elem, elem_next, cpu) { + DD_LIST_REMOVE(pmqos_head, cpu); + free(cpu->name); + free(cpu); + } + /* unregister notifier for each event */ unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); unregister_notifier(DEVICE_NOTIFIER_CPU_BOOST_LOWBAT, pmqos_lowbat); -- 2.7.4 From 3d1c90458f9a08db628d66843a85bdab41daa8f4 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 27 May 2020 13:51:48 +0900 Subject: [PATCH 06/16] Remove unused cpu conf related code Change-Id: I2697f58ef58e91048281c14c7d848b6cfe1e2e20 Signed-off-by: lokilee73 (cherry picked from commit 30324e833214e2beb02b28f73c6669a77ad457c9) --- CMakeLists.txt | 4 -- conf/cpu.conf | 15 ----- packaging/deviced.spec | 1 - src/cpu/pmqos-plugin.c | 162 ------------------------------------------------- src/cpu/pmqos.c | 80 +----------------------- src/cpu/pmqos.h | 38 ------------ 6 files changed, 1 insertion(+), 299 deletions(-) delete mode 100644 conf/cpu.conf delete mode 100644 src/cpu/pmqos-plugin.c delete mode 100644 src/cpu/pmqos.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d943f07..bcc2520 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -275,10 +275,6 @@ IF(USB_MODULE STREQUAL on) ENDIF(${SDB_PRESTART} STREQUAL on) ENDIF() -IF(TIZEN_FEATURE_CPU_MODULE STREQUAL on) - INSTALL_CONF(conf cpu) -ENDIF() - IF(CRITICAL_LOG_MODULE STREQUAL on) INSTALL_CONF(conf critical-log) ENDIF() diff --git a/conf/cpu.conf b/conf/cpu.conf deleted file mode 100644 index ca7fb39..0000000 --- a/conf/cpu.conf +++ /dev/null @@ -1,15 +0,0 @@ -[PMQOS] - -############################ -### Add list of scenario ### -############################ -[PmqosScenario] -# set to "yes" scenario_support (Default value is no) -# set scenario_num to be tested -scenario_support=no -scenario_num=0 # Maximum number of the scenarios is 500 - -# describe the scenario section as follows -#[Scenario0] -#name=AppLaunch # (dbus method name) -#support=yes diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 5fcb8eb..86c11b8 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -246,7 +246,6 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %{_unitdir}/basic.target.wants/sdb-prestart.service %endif %config %{_sysconfdir}/dbus-1/system.d/org.tizen.system.deviced.conf -%config %{_sysconfdir}/deviced/cpu.conf %config %{_sysconfdir}/deviced/power.conf %if %{?battery_module} == on %config %{_sysconfdir}/deviced/battery.conf diff --git a/src/cpu/pmqos-plugin.c b/src/cpu/pmqos-plugin.c deleted file mode 100644 index 3113da5..0000000 --- a/src/cpu/pmqos-plugin.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include -#include -#include -#include -#include -#include - -#include "core/log.h" -#include "core/config-parser.h" -#include "pmqos.h" - -#define SCENARIO_MAX 500 - -static bool is_supported(const char *value) -{ - assert(value); - - if (MATCH(value, "yes")) - return true; - return false; -} - -static int pmqos_parse_scenario(struct parse_result *result, void *data) -{ - struct pmqos_scenario *scenarios = (struct pmqos_scenario *)data; - - assert(result); - assert(result->section && result->name && result->value); - - if (MATCH(result->name, "scenario_support")) { - scenarios->support = is_supported(result->value); - return 0; - } - - if (MATCH(result->name, "scenario_num")) { - scenarios->num = atoi(result->value); - if (scenarios->num <= 0) - return 0; - if (scenarios->num > SCENARIO_MAX) - scenarios->num = SCENARIO_MAX; - scenarios->list = malloc(sizeof(struct scenario)*scenarios->num); - if (!scenarios->list) { - _E("Failed to allocat memory for scenario."); - return -errno; - } - } - return 0; -} - -static int pmqos_parse_each_scenario(struct parse_result *result, void *user_data, unsigned int index) -{ - struct pmqos_scenario *scenarios = (struct pmqos_scenario *)user_data; - - assert(result); - assert(result->section && result->name && result->value); - - /* Do not support pmqos scenario */ - if (!scenarios->support) - return 0; - - /* Do not have pmqos scenario */ - if (!scenarios->num) - return 0; - - /* No item to parse */ - if (index >= scenarios->num) - return 0; - - /* Parse 'Scenario' section */ - if (MATCH(result->name, "name")) - snprintf(scenarios->list[index].name, - sizeof(scenarios->list[index].name), "%s", result->value); - else if (MATCH(result->name, "support")) - scenarios->list[index].support = is_supported(result->value); - - return 0; -} - -static int pmqos_load_config(struct parse_result *result, void *user_data) -{ - struct pmqos_scenario *scenarios = (struct pmqos_scenario *)user_data; - char name[NAME_MAX]; - int ret; - static int index; - - if (!result) - return 0; - - if (!result->section || !result->name || !result->value) - return 0; - - /* Parsing 'PMQOS' section */ - if (MATCH(result->section, "PMQOS")) - return 0; - - /* Parsing 'Pmqos Scenario' section */ - if (MATCH(result->section, "PmqosScenario")) { - ret = pmqos_parse_scenario(result, user_data); - if (ret < 0) - _E("Failed to parse 'PmqosScenario' section: %d", ret); - return ret; - } - - /* Parsing 'Scenario' section */ - for (index = 0; index < scenarios->num; ++index) { - snprintf(name, sizeof(name), "Scenario%d", index); - - if (MATCH(result->section, name)) { - ret = pmqos_parse_each_scenario(result, user_data, index); - if (ret < 0) - _E("Failed to parse 'Scenario%d' section: %d", index, ret); - return ret; - } - } - - return 0; -} - -int release_pmqos_table(struct pmqos_scenario *scenarios) -{ - if (!scenarios) - return -EINVAL; - - if (scenarios->num > 0 && !scenarios->list) - free(scenarios->list); - - return 0; -} - -int get_pmqos_table(const char *path, struct pmqos_scenario *scenarios) -{ - int ret; - - /* get configuration file */ - ret = config_parse(path, pmqos_load_config, scenarios); - if (ret < 0) { - _E("Failed to load conficuration file(%s): %d", path, ret); - release_pmqos_table(scenarios); - return ret; - } - - return 0; -} diff --git a/src/cpu/pmqos.c b/src/cpu/pmqos.c index 16d2364..5331661 100644 --- a/src/cpu/pmqos.c +++ b/src/cpu/pmqos.c @@ -31,11 +31,9 @@ #include "core/common.h" #include "core/list.h" #include "core/device-notifier.h" -#include "pmqos.h" #define DEFAULT_PMQOS_TIMER 3000 -#define PMQOS_CONF_PATH "/etc/deviced/cpu.conf" #define MILLISECONDS(tv) ((tv.tv_sec)*1000 + (tv.tv_nsec)/1000000) struct pmqos_cpu { @@ -246,58 +244,6 @@ static GVariant * dbus_psmode_pmqos_handler(GDBusConnection *conn, return g_variant_new("(i)", ret); } -static int get_methods_from_conf(const char *path, dbus_method_s **dbus_methods) -{ - dbus_method_s *methods; - struct pmqos_scenario scenarios = { 0, }; - int i, ret = 0; - - /* get pmqos table from conf */ - ret = get_pmqos_table(path, &scenarios); - if (ret < 0) { - /* release scenarios memory */ - release_pmqos_table(&scenarios); - return ret; - } - - /* if do not support scenario */ - if (!scenarios.support) - return 0; - - /* if do not have scenarios */ - if (scenarios.num <= 0) - return 0; - - /* allocate dbus methods structure */ - methods = malloc(sizeof(dbus_method_s) * scenarios.num); - if (!methods) { - _E("Failed to allocate methods memory: %d", errno); - /* release scenarios memory */ - release_pmqos_table(&scenarios); - return -errno; - } - - /* set dbus_methods structure */ - for (i = 0; i < scenarios.num; ++i) { - - /* if this scenario does not support */ - if (!scenarios.list[i].support) { - _I("Do not support '%s' scenario.", scenarios.list[i].name); - continue; - } - - methods[i].member = scenarios.list[i].name; - methods[i].signature_in = "i"; - methods[i].signature_out = "i"; - methods[i].func = dbus_pmqos_handler; - _D("Support '%s' scenario.", scenarios.list[i].name); - } - - *dbus_methods = methods; - return scenarios.num; -} - - /* Add pmqos name as alphabetically */ static const dbus_method_s dbus_methods[] = { { "AppLaunch", "i", "i", dbus_pmqos_handler }, @@ -362,18 +308,10 @@ static const dbus_interface_u dbus_interface = { .nr_methods = ARRAY_SIZE(dbus_methods), }; -static dbus_interface_u dbus_interface_conf = { - .oh = NULL, - .name = DEVICED_INTERFACE_PMQOS, - .methods = NULL, - .nr_methods = 0, -}; - static int booting_done(void *data) { static int done; - dbus_method_s *methods = NULL; - int ret = 0, size; + int ret = 0; if (data == NULL) goto out; @@ -383,22 +321,6 @@ static int booting_done(void *data) goto out; _I("Booting done."); - - /* get methods from config file */ - size = get_methods_from_conf(PMQOS_CONF_PATH, &methods); - if (size < 0) - _E("Failed to load configuration file(%s).", PMQOS_CONF_PATH); - - /* register dbus methods for pmqos */ - if (methods) { - dbus_interface_conf.methods = methods; - dbus_interface_conf.nr_methods = size; - ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_PMQOS, &dbus_interface_conf); - if (ret < 0) - _E("Failed to init dbus method from conf: %d", ret); - free(methods); - } - ret = dbus_handle_register_dbus_object_all(NULL); if (ret < 0) _E("Failed to register dbus method: %d", ret); diff --git a/src/cpu/pmqos.h b/src/cpu/pmqos.h deleted file mode 100644 index 531847c..0000000 --- a/src/cpu/pmqos.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#ifndef __PMQOS_H__ -#define __PMQOS_H__ - -#include -#include - -struct pmqos_scenario { - struct scenario { - char name[NAME_MAX]; - bool support; - } *list; - int num; - bool support; -}; - -int get_pmqos_table(const char *path, struct pmqos_scenario *scenarios); -int release_pmqos_table(struct pmqos_scenario *scenarios); - -#endif /* __PMQOS_H__ */ -- 2.7.4 From 72160421e4397e8056f2d18e510f69dd17a30732 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 27 May 2020 19:42:31 +0900 Subject: [PATCH 07/16] Reset timer on switch_lcd_on switch_lcd_on turns on lcd and change internal state to LCD_NORMAL. But it doesn't reset timer. It will be done in subroutine, default_action(). But some cases, default_action() cannot be reached. For that case, switch_lcd_on() has to reset timer once more. Change-Id: I3709195337de05509d7b32af60f698d27022d938 Signed-off-by: lokilee73 --- plugins/wearable/display/key-filter.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index e84836a..f058c9e 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -214,6 +214,9 @@ static inline bool switch_on_lcd(enum device_flags flags) lcd_on_direct(flags); + if (pm_cur_state == S_NORMAL) + reset_timeout(states[S_NORMAL].timeout); + return true; } -- 2.7.4 From 0051c61bcbddaa15e27dd209687386ec8431cdaa Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 27 May 2020 19:46:25 +0900 Subject: [PATCH 08/16] Fix not to reset timer by 7 seconds by custom_lcdon() during tutorial custom_lcdon() resets normal timeout by 7 seconds. This method is called when, for example, wrist-up or notification occurs. But during tutorial, fixed it not to reset timeout timer by fixed 7 seconds, but to reset the value of setting timeout. Change-Id: I9b3dda9c057ca8e7f0d895455573db47ebed39da Signed-off-by: lokilee73 --- plugins/wearable/display/core.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 0c52ac4..38949a5 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -66,6 +66,10 @@ #define DISPLAY_CONF_FILE "/etc/deviced/display.conf" +#ifndef VCONFKEY_HOMESCREEN_TUTORIAL_OOBE_ENABLED +#define VCONFKEY_HOMESCREEN_TUTORIAL_OOBE_ENABLED "db/private/com.samsung.w-home/tutorial_oobe_enabled" +#endif + /** * @addtogroup POWER_MANAGER * @{ @@ -781,6 +785,8 @@ static gboolean timer_refresh_cb(gpointer data) int custom_lcdon(int timeout) { struct state *st; + int ret, update; + int tutorial = 0; if (timeout <= 0) return -EINVAL; @@ -788,8 +794,18 @@ int custom_lcdon(int timeout) if (check_lcd_is_on() == false) lcd_on_direct(LCD_ON_BY_GESTURE); - _I("Custom lcd on timeout(%d ms).", timeout); - if (set_custom_lcdon_timeout(timeout) == true) + /* Exceptional case: + * During tutorial, reset timeout by default timeout, not the given timeout */ + ret = vconf_get_int(VCONFKEY_HOMESCREEN_TUTORIAL_OOBE_ENABLED, &tutorial); + if (ret == 0 && tutorial) { + _D("During tutorial, reset timeout to default timeout."); + update = set_custom_lcdon_timeout(0); + } else { + _D("Custom lcd on timeout %dms.", timeout); + update = set_custom_lcdon_timeout(timeout); + } + + if (update) update_display_time(); /* state transition */ @@ -801,7 +817,8 @@ int custom_lcdon(int timeout) if (st->action) st->action(st->timeout); - g_idle_add(timer_refresh_cb, NULL); + if (!tutorial) + g_idle_add(timer_refresh_cb, NULL); return 0; } -- 2.7.4 From e7e17d0caa68880c295efaba3b08902277f9e27d Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 20 May 2020 18:36:49 +0900 Subject: [PATCH 09/16] Fix linking error detected by ASAN global variable battery_plgn is multiply defined in plugin.c and power-supply.c error log: [ 283s] /usr/lib/gcc/armv7l-tizen-linux-gnueabi/9.2.0/../../../../armv7l-tizen-linux-gnueabi/bin/ld: ../../../src/shared/libshared.a(plugin.c.o):(.bss+0x40): multiple definition of `battery_plgn'; CMakeFiles/mobile-battery.dir/__/__/__/src/battery/power-supply.c.o:(.bss+0x5a0): first defined here [ 283s] /usr/lib/gcc/armv7l-tizen-linux-gnueabi/9.2.0/../../../../armv7l-tizen-linux-gnueabi/bin/ld: ../../../src/shared/libshared.a(plugin.c.o):(.bss+0xc1): multiple definition of `__odr_asan.battery_plgn'; CMakeFiles/mobile-battery.dir/__/__/__/src/battery/power-supply.c.o:(.bss+0x7a0): first defined here Change-Id: I76d354f7a7d3532c8c5a933090fcc88a57c2e76e Signed-off-by: lokilee73 --- src/battery/power-supply.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 8da3b98..5fb0224 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -98,7 +98,6 @@ static int online_status; static int abnormal_health_popup_timer; static guint power_timer; -struct battery_plugin battery_plgn; bool battery_do_not_disturb(void); static int battery_pm_change_internal(int pid, int s_bits); -- 2.7.4 From 10e5620ea9ffc2643dbc7dbe301653b58fc0c767 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 3 Jun 2020 13:50:45 +0900 Subject: [PATCH 10/16] Add udev related code in auto test for battery tests udev events should not be delivered for battery tests. So, add udev related code to start and stop it. In addition, add battery full and temperature test functions. Change-Id: I3624b2c8238b08b36a89eacc9c6674458ffab452 Signed-off-by: lokilee73 (cherry picked from commit fa309a75edd44811da1bc1cbc9ec4f2a6daa1680) --- conf/org.tizen.system.deviced.conf | 3 +- src/auto-test/CMakeLists.txt | 1 + src/auto-test/auto-test.conf | 4 ++ src/auto-test/battery.c | 75 +++++++++++++++++++++- src/auto-test/udev.c | 126 +++++++++++++++++++++++++++++++++++++ src/battery/power-supply.c | 12 ++-- 6 files changed, 215 insertions(+), 6 deletions(-) create mode 100644 src/auto-test/udev.c diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index 4f26e05..6ade2fa 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -17,6 +17,7 @@ + @@ -56,7 +57,6 @@ - @@ -65,6 +65,7 @@ + diff --git a/src/auto-test/CMakeLists.txt b/src/auto-test/CMakeLists.txt index de6e43e..e840808 100644 --- a/src/auto-test/CMakeLists.txt +++ b/src/auto-test/CMakeLists.txt @@ -23,6 +23,7 @@ SET(SRCS time.c test_dbus_interface.c battery-monitor-test.c + udev.c ) FOREACH(flag ${pkgs_CFLAGS}) diff --git a/src/auto-test/auto-test.conf b/src/auto-test/auto-test.conf index 445175b..1b4f78e 100644 --- a/src/auto-test/auto-test.conf +++ b/src/auto-test/auto-test.conf @@ -8,6 +8,7 @@ proc=1 extcon=1 ir=1 time=1 +udev=1 [wearable] battery-monitor=1 @@ -19,6 +20,7 @@ proc=1 extcon=1 ir=0 time=1 +udev=1 [tv] battery-monitor=0 @@ -30,6 +32,7 @@ proc=1 extcon=1 ir=0 time=1 +udev=1 [common] battery-monitor=0 @@ -41,3 +44,4 @@ proc=1 extcon=1 ir=0 time=1 +udev=1 diff --git a/src/auto-test/battery.c b/src/auto-test/battery.c index a399755..c688d4d 100644 --- a/src/auto-test/battery.c +++ b/src/auto-test/battery.c @@ -133,7 +133,6 @@ static struct power_supply_type { {"freq", S_LEAVE, "100", DISCHARGE_NAME, GOOD_NAME, POWER_SUPPLY_TYPE_BATTERY, PRESENT_NORMAL, MISC_NORMAL, FREQ_STRENGTH_LEVEL_0, "DISCHARGE"}, /* init */ }; - static bool get_battery_method(const char *method, int *value) { GVariant *msg = NULL; @@ -430,6 +429,72 @@ static bool set_battery_power_supply(int index) return ret; } +static void full_scenario(char *unit, char *capacity, int status) +{ + int index; + int len; + + if (!unit || !capacity) + return; + + len = strlen(unit); + + for (index = 0; index < ARRAY_SIZE(power_supply_types); index++) { + if (len != strlen(power_supply_types[index].scenario)) + continue; + if (strncmp(unit, power_supply_types[index].scenario, len) != 0 || + power_supply_types[index].status != status) + continue; + power_supply_types[index].capacity = capacity; + _D("%s", power_supply_types[index].capacity); + set_battery_power_supply(index); + } +} + +static void battery_scenario(char *unit, int status) +{ + int index; + int found = 0; + int unit_len; + char *scenario = NULL; + + if (!unit) + return; + + unit_len = strlen(unit); + + for (index = 0; index < ARRAY_SIZE(power_supply_types); index++) { + if (unit_len != strlen(power_supply_types[index].scenario)) + continue; + scenario = power_supply_types[index].scenario; + if (strncmp(unit, scenario, unit_len) != 0 || + power_supply_types[index].status != status) + continue; + found = 1; + set_battery_power_supply(index); + } + + if (found) + return; + + index = strlen(unit); + if (index < 0 || index > 3) + return; + + index = strtol(unit, NULL, 10); + if (index < 0 || index > 100) + return; + + for (index = 0; index < ARRAY_SIZE(power_supply_types); index++){ + if (strncmp("capa", power_supply_types[index].scenario, 4) != 0 || + power_supply_types[index].status != status) + continue; + power_supply_types[index].capacity = unit; + _D("%s", power_supply_types[index].capacity); + set_battery_power_supply(index); + } +} + void battery_test_all(int *success, int *fail) { int s = 0; @@ -509,6 +574,14 @@ static int battery_unit(int argc, char **argv) } else if (0 == strcasecmp(argv[3], METHOD_BATTERY_POWERSUPPLY)) { for (int index = 0; index < ARRAY_SIZE(power_supply_types); index++) set_battery_power_supply(index); + } else if (argc > 4 && argv[4] && !strncmp("enter", argv[4], 5)) { + battery_scenario(argv[3], S_ENTER); + } else if (argc > 4 && argv[4] && !strncmp("leave", argv[4], 5)) { + battery_scenario(argv[3], S_LEAVE); + } else if (argc >5 && argv[5] && !strncmp("enter", argv[5], 5)) { + full_scenario(argv[3], argv[4], S_ENTER); + } else if (argc >5 && argv[5] && !strncmp("leave", argv[5], 5)) { + full_scenario(argv[3], argv[5], S_LEAVE); } else { _E("Unknown test case."); } diff --git a/src/auto-test/udev.c b/src/auto-test/udev.c new file mode 100644 index 0000000..86076b0 --- /dev/null +++ b/src/auto-test/udev.c @@ -0,0 +1,126 @@ +/* + * test + * + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "test.h" + +static const struct device_change_type { + char *name; + char *status; +} device_change_types[] = { + {"udev", "start"}, + {"udev", "stop"}, +}; + +static int udev(int index) +{ + GVariant *msg; + int ret, val; + + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, + DEVICED_PATH_SYSNOTI, + DEVICED_INTERFACE_SYSNOTI, + "udev", + g_variant_new("(sis)", "udev", 1, device_change_types[index].status)); + if (!msg) { + _E("fail : %s %s %s %s", + DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, + "udev"); + return -EBADMSG; + } + + if (!dh_get_param_from_var(msg, "(i)", &val)) + _E("fail : no message"); + else { + if ((val == -ENOTSUP) || (val == -ENOSYS)) { + _I("Not supported feature! : %d", val); + ret = TRUE; + } else if (val < 0) { + _E("fail : returned fail (%d)", val); + } else { + _I("success : %d", val); + ret = TRUE; + } + } + + _I("%s", device_change_types[index].status); + if (val < 0) + _R("[NG] ---- %s : %s", + __func__, device_change_types[index].status); + else + _R("[OK] ---- %s : %s", + __func__, device_change_types[index].status); + + g_variant_unref(msg); + sleep(TEST_WAIT_TIME_INTERVAL); + return ret; +} + +static void unit(char *unit, char *status) +{ + int index; + int unit_len; + int status_len; + + if (!unit || !status) + return; + + unit_len = strlen(unit); + status_len = strlen(status); + + for (index = 0; index < ARRAY_SIZE(device_change_types); index++) { + if (unit_len != strlen(device_change_types[index].name) || + status_len != strlen(device_change_types[index].status)) + continue; + if (strncmp(unit, device_change_types[index].name, unit_len) != 0 || + strncmp(status, device_change_types[index].status, status_len) != 0) + continue; + udev(index); + } +} + +static void udev_init(void *data) +{ + int index; + + _I("start test"); + for (index = 0; index < ARRAY_SIZE(device_change_types); index++) + udev(index); +} + +static void udev_exit(void *data) +{ + _I("end test"); +} + +static int udev_unit(int argc, char **argv) +{ + if (argc != 4) + return -EINVAL; + + unit(argv[2], argv[3]); + return 0; +} + +static const struct test_ops udev_test_ops = { + .priority = TEST_PRIORITY_HIGH, + .name = "udev", + .init = udev_init, + .exit = udev_exit, + .unit = udev_unit, +}; + +TEST_OPS_REGISTER(&udev_test_ops) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 5fb0224..ffc6d6a 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -98,6 +98,7 @@ static int online_status; static int abnormal_health_popup_timer; static guint power_timer; +static device_notifier_state_e old_state = -1; bool battery_do_not_disturb(void); static int battery_pm_change_internal(int pid, int s_bits); @@ -1314,10 +1315,13 @@ static GVariant *dbus_get_battery_info(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) { - int ret, val; + int ret = 0, val; const char *str; struct battery_info info = {0, }; + if (old_state == DEVICE_NOTIFIER_STATE_STOP) + goto out; + if (battery_dev && battery_dev->get_current_state) { ret = battery_dev->get_current_state(battery_get_info, &info); if (ret < 0) @@ -1343,6 +1347,7 @@ static GVariant *dbus_get_battery_info(GDBusConnection *conn, ret = 0; } +out: return g_variant_new("(isssiiiiiiii)", ret, battery.status_s, battery.health_s, @@ -1601,13 +1606,12 @@ static void remove_power_supply_handler(void) static int event_handler_state_changed(void *data) { - static device_notifier_state_e old = DEVICE_NOTIFIER_STATE_STOP; device_notifier_state_e state = *(device_notifier_state_e *)data; - if (old == state) + if (old_state == state) return 0; - old = state; + old_state = state; if (state == DEVICE_NOTIFIER_STATE_START) add_power_supply_handler(); -- 2.7.4 From e0a73baccd9b9f5503018d99f65d2a4bada43a87 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 3 Jun 2020 13:59:58 +0900 Subject: [PATCH 11/16] Fix lcd_on_direct() not to update old state As updating old state within lcd_on_direct() causes several problems, this patch reverts the parts related to state update of lcd_on_direct() from the following patches. - 613ecd25da136c6cf210e00a15a21783f7ecdf5b - 32a6e47d137a00c2a8b037b23ef4387f2ebecb23 - 6e04a05360c0a77a1e4d0275d967acb89719d3e1 In general, lcd_on_direct() is followed by default_proc_change_state_action(), and the subroutine is like below. - lcd_on_direct() : update old state -> ... (do something) -> default_proc_change_state_action() : update old state once more -> default_action() So for the default_action(), if it is called through lcd_on_direct(), pm_old_state and pm_cur_state is always same because old state is updated twice. This makes below code in default_action() unreachable. device_notify(DEVICE_NOTIFIER_LCD, (void *)&pm_cur_state); As a result, lcd_on_direct() should not update the pm_old_state. Change-Id: Iefe46720100c9adc858f86ba54b06361946e3b88 Signed-off-by: Youngjae Cho --- plugins/iot/display/core.c | 3 +-- plugins/mobile/display/core.c | 3 +-- plugins/tv/display/core.c | 3 +-- plugins/wearable/display/core.c | 4 +--- plugins/wearable/display/key-filter.c | 3 --- 5 files changed, 4 insertions(+), 12 deletions(-) diff --git a/plugins/iot/display/core.c b/plugins/iot/display/core.c index 2b2255e..9f2110c 100644 --- a/plugins/iot/display/core.c +++ b/plugins/iot/display/core.c @@ -699,10 +699,9 @@ void lcd_on_direct(enum device_flags flags) && pm_cur_state == S_SLEEP) { broadcast_pm_wakeup(); power_ops.power_lock(); + pm_cur_state = S_NORMAL; } - pm_cur_state = S_NORMAL; - _D("lcd is on directly"); gettimeofday(&lcdon_tv, NULL); lcd_on_procedure(LCD_NORMAL, flags); diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 67c2efe..74899e2 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -706,10 +706,9 @@ void lcd_on_direct(enum device_flags flags) && pm_cur_state == S_SLEEP) { broadcast_pm_wakeup(); power_ops.power_lock(); + pm_cur_state = S_NORMAL; } - pm_cur_state = S_NORMAL; - _D("lcd is on directly"); gettimeofday(&lcdon_tv, NULL); lcd_on_procedure(LCD_NORMAL, flags); diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 8402a6c..d609bdb 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -699,10 +699,9 @@ void lcd_on_direct(enum device_flags flags) && pm_cur_state == S_SLEEP) { broadcast_pm_wakeup(); power_ops.power_lock(); + pm_cur_state = S_NORMAL; } - pm_cur_state = S_NORMAL; - _D("lcd is on directly"); gettimeofday(&lcdon_tv, NULL); lcd_on_procedure(LCD_NORMAL, flags); diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 38949a5..0fc669c 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -726,6 +726,7 @@ void lcd_on_direct(enum device_flags flags) && pm_cur_state == S_SLEEP) { broadcast_pm_wakeup(); power_ops.power_lock(); + pm_cur_state = S_NORMAL; } ret = is_lcdon_blocked(); @@ -734,9 +735,6 @@ void lcd_on_direct(enum device_flags flags) return; } - pm_old_state = pm_cur_state; - pm_cur_state = S_NORMAL; - _D("lcd is on directly"); gettimeofday(&lcdon_tv, NULL); lcd_on_procedure(LCD_NORMAL, flags); diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index f058c9e..e84836a 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -214,9 +214,6 @@ static inline bool switch_on_lcd(enum device_flags flags) lcd_on_direct(flags); - if (pm_cur_state == S_NORMAL) - reset_timeout(states[S_NORMAL].timeout); - return true; } -- 2.7.4 From 4fc4b9fa04d8b5097f41a6d30b7c597197664560 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 4 Jun 2020 16:29:34 +0900 Subject: [PATCH 12/16] Fix svace warning Change-Id: I8b55e5fe02d4f03c9df0f81f87dc3ca4a0d20e7c Signed-off-by: lokilee73 (cherry picked from commit 87865b414580b2b274e05e32f37c5bedd5b0d17e) --- src/auto-test/udev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auto-test/udev.c b/src/auto-test/udev.c index 86076b0..25e3c8e 100644 --- a/src/auto-test/udev.c +++ b/src/auto-test/udev.c @@ -28,7 +28,7 @@ static const struct device_change_type { static int udev(int index) { GVariant *msg; - int ret, val; + int ret = 0, val = 0; msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, -- 2.7.4 From 61c03ed27c34ef030a205c466c11f539413baf33 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Tue, 2 Jun 2020 14:35:10 +0900 Subject: [PATCH 13/16] Add battery plugin for wearable and mobile Wearable plugin - check_power_supply_noti - update_ovp - display_changed: relaunch health popup on LCDON Mobile plugin - check_power_supply_noti - update_ovp - display_changed - added dbus signal handler: abnormal_popup_dbus_signal_handler Change-Id: I86a08e0f8d61e997fa0fc424e32d6d8c1de5cf96 Signed-off-by: lokilee73 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 1 + packaging/deviced.spec | 2 + plugins/mobile/battery/battery-notification.c | 91 +++++++++++++++++ plugins/wearable/battery/CMakeLists.txt | 28 ++++++ plugins/wearable/battery/battery-notification.c | 100 +++++++++++++++++++ src/battery/battery-ops.h | 6 ++ src/battery/power-supply.c | 127 +++++++++++------------- src/battery/power-supply.h | 5 + 8 files changed, 291 insertions(+), 69 deletions(-) create mode 100644 plugins/wearable/battery/CMakeLists.txt create mode 100644 plugins/wearable/battery/battery-notification.c diff --git a/CMakeLists.txt b/CMakeLists.txt index bcc2520..c2cda03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -315,6 +315,7 @@ ADD_SUBDIRECTORY(plugins/wearable/display) ADD_SUBDIRECTORY(plugins/tv/display) ADD_SUBDIRECTORY(plugins/iot/display) ADD_SUBDIRECTORY(plugins/mobile/battery) +ADD_SUBDIRECTORY(plugins/wearable/battery) INSTALL_CONF(conf mobile-display) INSTALL_CONF(conf wearable-display) INSTALL_CONF(conf tv-display) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 86c11b8..d119d2a 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -223,6 +223,7 @@ mv %{_libdir}/mobile-battery.so %{_libdir}/deviced/battery.so mv %{_sysconfdir}/deviced/wearable-display.conf %{_sysconfdir}/deviced/display.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/wearable-display.so %{_libdir}/deviced/display.so +mv %{_libdir}/wearable-battery.so %{_libdir}/deviced/battery.so %post plugin-profile-tv mv %{_sysconfdir}/deviced/tv-display.conf %{_sysconfdir}/deviced/display.conf @@ -307,6 +308,7 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/wearable-display.conf %{_libdir}/wearable-display.so +%{_libdir}/wearable-battery.so %{_unitdir}/rndis.service %{_bindir}/rndis.sh diff --git a/plugins/mobile/battery/battery-notification.c b/plugins/mobile/battery/battery-notification.c index 15df6b7..5ba04e0 100644 --- a/plugins/mobile/battery/battery-notification.c +++ b/plugins/mobile/battery/battery-notification.c @@ -28,9 +28,12 @@ #include "power-supply.h" #include "lowbat-handler.h" #include "battery-ops.h" +#include "display/core.h" #include "display/display-ops.h" #include "display/poll.h" #include "shared/eventsystem.h" +#include "core/device-notifier.h" + #define METHOD_LOW_NOTI_ON "BatteryLowNotiOn" #define METHOD_LOW_NOTI_UPDATE "BatteryLowNotiUpdate" @@ -47,6 +50,8 @@ enum event_noti_type { NOTI_UPDATE = 0, }; +static guint abnormal_timer; + static int noti_low = NOTI_NONE; static int noti_crit = NOTI_NONE; @@ -292,9 +297,84 @@ static void remove_health_popup(void) _E("Failed to launch remove battery popup(%d)", ret); } +static int check_power_supply_noti(void) +{ + return 1; +} + +static void update_ovp(enum battery_noti_status status) +{ + _I("charge %d ovp %d(old %d)", battery.charge_now, battery.health, old_battery.health); + + old_battery.health = battery.health; + if (status == DEVICE_NOTI_ON) + battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_DIM); + else + battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); + device_notify(DEVICE_NOTIFIER_BATTERY_OVP, (void *)&battery.health); +} + +static void health_timer_reset(void) +{ + abnormal_timer = 0; +} + +static gboolean health_timer_cb(void *data) +{ + health_timer_reset(); + + if (battery.health != HEALTH_LOW && battery.health != HEALTH_HIGH) + return G_SOURCE_REMOVE; + + CRITICAL_LOG("Popup: Battery health status is not good, %s.", battery.health_s); + device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)&battery.health); + battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_DIM); + if (disp_plgn.pm_unlock_internal) + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, 0); + if (battery.health == HEALTH_LOW) + battery_charge_err_low_act(NULL); + else if (battery.health == HEALTH_HIGH) + battery_charge_err_high_act(NULL); + return G_SOURCE_REMOVE; +} + +static void abnormal_popup_dbus_signal_handler(GDBusConnection *conn, + const gchar *sender, + const gchar *path, + const gchar *iface, + const gchar *name, + GVariant *param, + gpointer user_data) + +{ + if (battery.health == HEALTH_GOOD) + return; + + _I("Restart health timer."); + abnormal_timer = g_timeout_add_seconds(ABNORMAL_CHECK_TIMER_INTERVAL, + health_timer_cb, NULL); + if (abnormal_timer == 0) + _E("Failed to add abnormal check timer."); +} + +static int display_changed(void *data) +{ + static enum state_t state; + + if (!data) + return state; + + state = *(int *)data; + + return state; +} + static void battery_notification_init(void *data) { struct battery_plugin *plugin = (struct battery_plugin *)data; + int ret; if (!plugin) return; @@ -305,6 +385,17 @@ static void battery_notification_init(void *data) plugin->changed_battery_cf = changed_battery_cf; plugin->remove_health_popup = remove_health_popup; + plugin->check_power_supply_noti = check_power_supply_noti; + plugin->update_ovp = update_ovp; + + plugin->display_changed = display_changed; + + ret = subscribe_dbus_signal(NULL, DEVICED_PATH_SYSNOTI, + DEVICED_INTERFACE_SYSNOTI, SIGNAL_CHARGEERR_RESPONSE, abnormal_popup_dbus_signal_handler, NULL, NULL); + if (ret <= 0) + _E("Failed to init dbus signal: %d", ret); + + register_notifier(DEVICE_NOTIFIER_LCD, display_changed); } static const struct battery_ops battery_notification_ops = { diff --git a/plugins/wearable/battery/CMakeLists.txt b/plugins/wearable/battery/CMakeLists.txt new file mode 100644 index 0000000..1932820 --- /dev/null +++ b/plugins/wearable/battery/CMakeLists.txt @@ -0,0 +1,28 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(wearable-battery C) + +FILE(GLOB ALL_SRCS "*.c") +SET(SRCS ${ALL_SRCS}) +ADD_SOURCE(${CMAKE_SOURCE_DIR}/src/battery COMMON_SRCS) +SET(SRCS ${SRCS} ${COMMON_SRCS}) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/battery) + +INCLUDE(FindPkgConfig) +pkg_check_modules(libpkgs REQUIRED + dlog + glib-2.0 + gio-2.0 + gio-unix-2.0 + libinput) + +FOREACH(flag ${libpkgs_CFLAGS}) + SET(EXTRA_LIB_CFLAGS "${EXTRA_LIB_CFLAGS} ${flag}") +ENDFOREACH(flag) +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_LIB_CFLAGS}") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libpkgs_LDFLAGS} shared) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME wearable-battery) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) diff --git a/plugins/wearable/battery/battery-notification.c b/plugins/wearable/battery/battery-notification.c new file mode 100644 index 0000000..8ab24f4 --- /dev/null +++ b/plugins/wearable/battery/battery-notification.c @@ -0,0 +1,100 @@ +/* + * 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 "display/core.h" +#include "core/log.h" +#include "core/device-notifier.h" +#include "power-supply.h" +#include "battery-ops.h" +#include "battery.h" +#include "dd-display.h" + +static int display_changed(void *data) +{ + static enum state_t old; + static enum state_t state; + + if (!data) + return state; + + old = state; + state = *(int *)data; + + if (battery.health != HEALTH_LOW && battery.health != HEALTH_HIGH) + return state; + + /* relaunch health popup on LCDON */ + if ((old == S_SLEEP || old == S_LCDOFF) + && (state == S_LCDDIM || state == S_NORMAL)) + relaunch_health_popup(); + + return state; +} + +static int check_power_supply_noti(void) +{ + int block; + + if (vconf_get_bool("db/setting/blockmode_wearable", &block) != 0) + return 1; + if (block == 0) + return 1; + return 0; +} + +static void update_ovp(enum battery_noti_status status) +{ + static int old = DEVICE_NOTI_OFF; + + if (old == status) + return; + + old = status; + _I("Charge(%d) ovp(%d, old: %d) with lcd(%s)", battery.charge_now, battery.health, + old_battery.health, (status == DEVICE_NOTI_ON) ? "dim" : "normal"); + + old_battery.health = battery.health; + device_notify(DEVICE_NOTIFIER_BATTERY_OVP, (void *)&battery.health); + battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); +} + +static void battery_notification_init(void *data) +{ + struct battery_plugin *plugin = (struct battery_plugin *)data; + + if (!plugin) + return; + + _D("Add plugins for battery notification."); + plugin->check_power_supply_noti = check_power_supply_noti; + plugin->update_ovp = update_ovp; + + plugin->display_changed = display_changed; + + register_notifier(DEVICE_NOTIFIER_LCD, display_changed); +} + +static const struct battery_ops battery_notification_ops = { + .name = "battery_notification", + .init = battery_notification_init, +}; + +BATTERY_OPS_REGISTER(&battery_notification_ops) diff --git a/src/battery/battery-ops.h b/src/battery/battery-ops.h index 67376ef..a8397f0 100644 --- a/src/battery/battery-ops.h +++ b/src/battery/battery-ops.h @@ -22,6 +22,8 @@ #include #include "core/common.h" +#include "power-supply.h" +#include struct battery_ops { char *name; @@ -38,6 +40,10 @@ struct battery_plugin { int (*changed_battery_cf) (int status); void (*remove_health_popup) (void); + + int (*display_changed) (void *); + int (*check_power_supply_noti) (void); + void (*update_ovp) (enum battery_noti_status status); /* Add plugins here */ }; extern struct battery_plugin battery_plgn; diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index ffc6d6a..09f16bc 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -70,11 +70,8 @@ #define CHARGER_D2D_TYPE 110 #define WIRELESS_CHARGER_CONNECTED 2 -#define SIGNAL_CHARGEERR_RESPONSE "ChargeErrResponse" #define SIGNAL_TEMP_GOOD "TempGood" -#define ABNORMAL_CHECK_TIMER_INTERVAL 60 - #define METHOD_FULL_NOTI_ON "BatteryFullNotiOn" #define METHOD_FULL_NOTI_OFF "BatteryFullNotiOff" #define METHOD_CHARGE_NOTI_ON "BatteryChargeNotiOn" @@ -96,13 +93,13 @@ struct battery_status old_battery; static int noti_id; static int online_status; static int abnormal_health_popup_timer; +static bool launching_health_popup; static guint power_timer; static device_notifier_state_e old_state = -1; bool battery_do_not_disturb(void); -static int battery_pm_change_internal(int pid, int s_bits); -static int display_changed(void *data); +int battery_pm_change_internal(int pid, int s_bits); static int booting_done(void *data); static void update_health(enum battery_noti_status status); @@ -204,27 +201,17 @@ out: g_variant_unref(var); } -int check_power_supply_noti(void) -{ - int block; - - if (vconf_get_bool("db/setting/blockmode_wearable", &block) != 0) - return 1; - if (block == 0) - return 1; - return 0; -} - static int send_full_noti(enum charge_full_type state) { int ret = 0; - int noti; + int noti = 0; int retry; - noti = check_power_supply_noti(); + if (battery_plgn.check_power_supply_noti) + noti = battery_plgn.check_power_supply_noti(); if (!noti) - return noti; + return ret; switch (state) { case CHARGING_FULL: @@ -240,7 +227,7 @@ static int send_full_noti(enum charge_full_type state) } } _E("Failed to call dbus method: %d", ret); - break; + break; case CHARGING_NOT_FULL: if (noti_id <= 0) return -EPERM; @@ -258,7 +245,7 @@ static int send_full_noti(enum charge_full_type state) } } _E("Failed to call dbus method: %d", ret); - break; + break; } return ret; } @@ -372,7 +359,6 @@ int power_supply_broadcast(char *sig, int status) static void noti_batt_full(void) { static int bat_full_noti; - int noti; if (!battery.charge_full && bat_full_noti == 1) { power_supply_noti(DEVICE_NOTI_BATT_FULL, DEVICE_NOTI_OFF); @@ -383,9 +369,8 @@ static void noti_batt_full(void) if (battery.charge_full && bat_full_noti == 0) { power_supply_noti(DEVICE_NOTI_BATT_FULL, DEVICE_NOTI_ON); bat_full_noti = 1; - /* turn on LCD, if battery is full charged */ - noti = check_power_supply_noti(); - if (noti) { + /* turn on LCD, if battery is fully charged */ + if (battery_plgn.check_power_supply_noti && battery_plgn.check_power_supply_noti()) { battery_pm_change_internal(INTERNAL_LOCK_BATTERY_FULL, LCD_NORMAL); } else _I("Block LCD."); @@ -458,6 +443,11 @@ static void update_present(enum battery_noti_status status) static void launch_health_popup(void) { + if (launching_health_popup) + return; + + launching_health_popup = true; + device_notify(DEVICE_NOTIFIER_BATTERY_HEALTH, (void *)&battery.health); battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_DIM); @@ -469,6 +459,8 @@ static void launch_health_popup(void) battery_charge_err_low_act(NULL); else if (battery.health == HEALTH_HIGH) battery_charge_err_high_act(NULL); + + launching_health_popup = false; } /* Warning popup for every 1 minutes until @@ -508,20 +500,28 @@ static void update_health(enum battery_noti_status status) } } -static void update_ovp(enum battery_noti_status status) +void relaunch_health_popup(void) { - static int old = DEVICE_NOTI_OFF; - - if (old == status) + if (launching_health_popup) return; - old = status; - _I("Charge(%d) ovp(%d, old: %d) with lcd(%s)", battery.charge_now, battery.health, - old_battery.health, (status == DEVICE_NOTI_ON) ? "dim" : "normal"); + launching_health_popup = true; - old_battery.health = battery.health; - device_notify(DEVICE_NOTIFIER_BATTERY_OVP, (void *)&battery.health); - battery_pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); + if (abnormal_health_popup_timer) + g_source_remove(abnormal_health_popup_timer); + + if (disp_plgn.pm_unlock_internal) + disp_plgn.pm_unlock_internal(INTERNAL_LOCK_POPUP, LCD_OFF, PM_SLEEP_MARGIN); + if (disp_plgn.pm_lock_internal) + disp_plgn.pm_lock_internal(INTERNAL_LOCK_POPUP, LCD_DIM, STAY_CUR_STATE, LCD_DIM_TIME_IN_BATTERY_HEALTH); + if (battery.health == HEALTH_LOW) + battery_charge_err_low_act(NULL); + else if (battery.health == HEALTH_HIGH) + battery_charge_err_high_act(NULL); + + abnormal_health_popup_timer = g_timeout_add_seconds(ABNORMAL_CHECK_TIMER_INTERVAL, health_popup_cb, NULL); + + launching_health_popup = false; } static void check_abnormal_status(void) @@ -538,10 +538,13 @@ static void check_abnormal_status(void) else if (battery.present != PRESENT_ABNORMAL && old_battery.present == PRESENT_ABNORMAL) update_present(DEVICE_NOTI_OFF); - if (old_battery.health != HEALTH_OVP && battery.health == HEALTH_OVP) - update_ovp(DEVICE_NOTI_ON); - else if (battery.health != HEALTH_OVP && old_battery.health == HEALTH_OVP) - update_ovp(DEVICE_NOTI_OFF); + if (old_battery.health != HEALTH_OVP && battery.health == HEALTH_OVP) { + if (battery_plgn.update_ovp) + battery_plgn.update_ovp(DEVICE_NOTI_ON); + } else if (battery.health != HEALTH_OVP && old_battery.health == HEALTH_OVP) { + if (battery_plgn.update_ovp) + battery_plgn.update_ovp(DEVICE_NOTI_OFF); + } } static bool update_online(void) @@ -1437,30 +1440,32 @@ static int booting_done(void *data) bool battery_do_not_disturb(void) { - int block = 0; + int block = 0, theater = 0, night = 0; int r; - if (display_changed(NULL) == S_LCDOFF) { - r = vconf_get_bool(VCONFKEY_SETAPPL_BLOCKMODE_WEARABLE_BOOL, &block); - if (r < 0) - _E("Failed to set vconf value for blockmode wearable: %d", vconf_get_ext_errno()); - r = vconf_get_bool(VCONFKEY_SETAPPL_THEATER_MODE_ENABLE, &block); - if (r < 0) - _E("Failed to set vconf value for theator mode enable: %d", vconf_get_ext_errno()); - r = vconf_get_bool(VCONFKEY_SETAPPL_GOODNIGHT_MODE_ENABLE, &block); - if (r < 0) - _E("Failed to set vconf value for goodnight mode enable: %d", vconf_get_ext_errno()); + if (battery_plgn.display_changed) { + if (battery_plgn.display_changed(NULL) == S_LCDOFF) { + r = vconf_get_bool(VCONFKEY_SETAPPL_BLOCKMODE_WEARABLE_BOOL, &block); + if (r < 0) + _E("Failed to set vconf value for blockmode wearable: %d", vconf_get_ext_errno()); + r = vconf_get_bool(VCONFKEY_SETAPPL_THEATER_MODE_ENABLE, &theater); + if (r < 0) + _E("Failed to set vconf value for theator mode enable: %d", vconf_get_ext_errno()); + r = vconf_get_bool(VCONFKEY_SETAPPL_GOODNIGHT_MODE_ENABLE, &night); + if (r < 0) + _E("Failed to set vconf value for goodnight mode enable: %d", vconf_get_ext_errno()); + } } - if (block != 0) { - _I("Skip lcd and popup(block %d).", block); + if (block != 0 || theater != 0 || night != 0) { + _I("Skip lcd and popup(block %d theater %d night %d).", block, theater, night); return true; } return false; } -static int battery_pm_change_internal(int pid, int s_bits) +int battery_pm_change_internal(int pid, int s_bits) { if (battery_do_not_disturb()) return 0; @@ -1471,18 +1476,6 @@ static int battery_pm_change_internal(int pid, int s_bits) return 0; } -static int display_changed(void *data) -{ - static enum state_t state; - - if (!data) - return state; - - state = *(int *)data; - - return state; -} - static int load_uevent(struct parse_result *result, void *user_data) { struct battery_status *info = user_data; @@ -1635,16 +1628,12 @@ static void power_supply_init(void *data) power_supply_timer_start(); register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - register_notifier(DEVICE_NOTIFIER_LCD, display_changed); register_notifier(DEVICE_NOTIFIER_EVENT_HANDLER, event_handler_state_changed); ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_BATTERY, &dbus_interface); if (ret < 0) _E("Failed to init dbus method: %d", ret); - if (ret <= 0) - _E("Failed to init dbus signal: %d", ret); - battery_ops_init((void *)&battery_plgn); } diff --git a/src/battery/power-supply.h b/src/battery/power-supply.h index 34bb993..af4fb0c 100644 --- a/src/battery/power-supply.h +++ b/src/battery/power-supply.h @@ -21,6 +21,9 @@ #define __POWER_SUPPLY_H__ #define CHARGER_TYPE_SIGNAL "ChargerType" +#define SIGNAL_CHARGEERR_RESPONSE "ChargeErrResponse" + +#define ABNORMAL_CHECK_TIMER_INTERVAL 60 enum device_change_type { DEVICE_CHANGE_ABNORMAL, @@ -119,6 +122,8 @@ extern struct battery_status battery; extern struct battery_status old_battery; int power_supply_broadcast(char *sig, int status); +int battery_pm_change_internal(int pid, int s_bits); +void relaunch_health_popup(void); #define CHARGER_STATUS_SIGNAL "ChargerStatus" #define CHARGE_NOW_SIGNAL "ChargeNow" -- 2.7.4 From 8ddd16fdf892cf9349df32d87b07248a4a81edfd Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 2 Jun 2020 11:01:07 +0900 Subject: [PATCH 14/16] Filter pid -1 by dbus_connection_get_sender_pid() When dbus_connection_get_sender_pid() returns -1 as pid, regards it as the sender has been dead. Change-Id: Iecaa3f946b9da6533583fe2f4bfc4f2af4842931 Signed-off-by: Youngjae Cho --- plugins/wearable/display/swim.c | 5 +++++ src/battery/power-supply.c | 2 +- src/control/control.c | 4 ++-- src/display/display-dbus.c | 20 ++++++++++++++++---- src/display/display-lock.c | 2 +- src/led/rgb.c | 15 +++++++++++++++ src/power/low-power.c | 11 +++++++++++ src/power/power-handler.c | 2 +- src/time/time-handler.c | 2 +- 9 files changed, 53 insertions(+), 10 deletions(-) diff --git a/plugins/wearable/display/swim.c b/plugins/wearable/display/swim.c index 17cf08f..3ebca55 100644 --- a/plugins/wearable/display/swim.c +++ b/plugins/wearable/display/swim.c @@ -80,6 +80,11 @@ static void swimmode_signal_handler(GDBusConnection *conn, } pid = dbus_connection_get_sender_pid(conn, sender); + if (pid == -1 || kill(pid, 0) == -1) { + _E("Sender(%d) does not exist.", pid); + return; + } + _I("Request swim mode state %d by %d", val, pid); if (backlight_ops.get_lcd_power != DPMS_ON) { diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 09f16bc..96a0ada 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -1238,7 +1238,7 @@ static GVariant *dbus_power_supply_handler(GDBusConnection *conn, } pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { + if (pid == -1 || kill(pid, 0) == -1) { _E("Process(%d) does not exist, dbus ignored.", pid); ret = -ESRCH; goto out; diff --git a/src/control/control.c b/src/control/control.c index 7a1bd3e..87f5801 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -131,7 +131,7 @@ static GVariant *dbus_control_handler(GDBusConnection *conn, } pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { + if (pid == -1 || kill(pid, 0) == -1) { _E("Process(%d) does not exist. Dbus ignored.", pid); ret = -ESRCH; goto out; @@ -162,7 +162,7 @@ static GVariant *dbus_get_control_handler(GDBusConnection *conn, } pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { + if (pid == -1 || kill(pid, 0) == -1) { _E("Process(%d) does not exist. Dbus ignored.", pid); ret = -ESRCH; goto out; diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 015e86c..1cadc8b 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -125,7 +125,7 @@ static GVariant *dbus_lockstate(GDBusConnection *conn, goto out; pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { + if (pid == -1 || kill(pid, 0) == -1) { _E("%d process does not exist, dbus ignored!", pid); ret = -ESRCH; goto out; @@ -210,7 +210,7 @@ static GVariant *dbus_unlockstate(GDBusConnection *conn, goto out; pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { + if (pid == -1 || kill(pid, 0) == -1) { _E("%d process does not exist, dbus ignored!", pid); ret = -ESRCH; goto out; @@ -269,7 +269,7 @@ static GVariant *dbus_changestate(GDBusConnection *conn, goto out; pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { + if (pid == -1 || kill(pid, 0) == -1) { _E("%d process does not exist, dbus ignored!", pid); ret = -ESRCH; goto out; @@ -643,6 +643,11 @@ static GVariant *dbus_setautobrightnessmin(GDBusConnection *conn, g_variant_get(param, "(i)", &val); pid = dbus_connection_get_sender_pid(conn, sender); + if (pid == -1 || kill(pid, 0) == -1) { + _E("%d process does not exist, dbus ignored!", pid); + ret = -ESRCH; + goto error; + } ret = display_info.set_autobrightness_min(val, (char *)sender); if (ret) { _W("fail to set autobrightness min %d, %d by %d", val, ret, pid); @@ -671,6 +676,12 @@ static GVariant *dbus_setlcdtimeout(GDBusConnection *conn, g_variant_get(param, "(iii)", &on, &dim, &holdkey_block); pid = dbus_connection_get_sender_pid(conn, sender); + if (pid == -1 || kill(pid, 0) == -1) { + _E("%d process does not exist, dbus ignored!", pid); + ret = -ESRCH; + goto error; + } + ret = set_lcd_timeout(on, dim, holdkey_block, sender); if (ret) { _W("fail to set lcd timeout %d by %d", ret, pid); @@ -684,6 +695,7 @@ static GVariant *dbus_setlcdtimeout(GDBusConnection *conn, on, dim, holdkey_block, pid); } +error: return g_variant_new("(i)", ret); } @@ -962,7 +974,7 @@ static GVariant *dbus_locktimeout_expired(GDBusConnection *conn, g_variant_get(param, "(s)", &req_id); pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { + if (pid == -1 || kill(pid, 0) == -1) { _E("%d process does not exist, dbus ignored!", pid); ret = -ESRCH; goto out; diff --git a/src/display/display-lock.c b/src/display/display-lock.c index a7e6ae9..b34ab61 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -369,7 +369,7 @@ int check_processes(enum state_t prohibit_state) int ret = 0; DD_LIST_FOREACH_SAFE(cond_head[prohibit_state], elem, next, t) { - if (t->pid < INTERNAL_LOCK_BASE && kill(t->pid, 0) == -1) { + if (t->pid == -1 || (t->pid < INTERNAL_LOCK_BASE && kill(t->pid, 0) == -1)) { _E("%d process does not exist, delete the REQ" " - prohibit state %d ", t->pid, prohibit_state); diff --git a/src/led/rgb.c b/src/led/rgb.c index 3a9d4e2..f6a360e 100644 --- a/src/led/rgb.c +++ b/src/led/rgb.c @@ -216,6 +216,11 @@ static GVariant *dbus_playcustom(GDBusConnection *conn, g_variant_get(param, "(iiuu)", &on, &off, &color, &flags); 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("Pid(%d) led play custom on=%d off=%d color=%#x.", pid, on, off, color); @@ -248,6 +253,11 @@ static GVariant *dbus_stopcustom(GDBusConnection *conn, pid_t pid; 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("Pid(%d) led stop custom.", pid); @@ -292,6 +302,11 @@ static GVariant *dbus_multi_led_control(GDBusConnection *conn, struct led_state state; 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("Pid(%d) multi led play control.", pid); diff --git a/src/power/low-power.c b/src/power/low-power.c index 0061bec..9e77a79 100644 --- a/src/power/low-power.c +++ b/src/power/low-power.c @@ -115,6 +115,11 @@ static GVariant *dbus_low_power_start(GDBusConnection *conn, } 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); @@ -124,6 +129,7 @@ static GVariant *dbus_low_power_start(GDBusConnection *conn, 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) @@ -138,6 +144,11 @@ static GVariant *dbus_low_power_stop(GDBusConnection *conn, } 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); diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 9f05cb5..336cf63 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -534,7 +534,7 @@ static int check_sender_process(GDBusConnection *conn, const char *sender) } pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { + if (pid == -1 || kill(pid, 0) == -1) { _E("Process(%d) does not exist, dbus ignored.", pid); return -ESRCH; } diff --git a/src/time/time-handler.c b/src/time/time-handler.c index f019b35..ad99aa4 100644 --- a/src/time/time-handler.c +++ b/src/time/time-handler.c @@ -322,7 +322,7 @@ static GVariant *dbus_time_handler(GDBusConnection *conn, } pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { + if (pid == -1 || kill(pid, 0) == -1) { _E("Process(%d) does not exist, dbus ignored.", pid); ret = -ESRCH; goto out; -- 2.7.4 From 52d298787f08680075e0e80f16e5585feb5ddced Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Thu, 4 Jun 2020 13:18:41 +0900 Subject: [PATCH 15/16] Revert "tzip: enable kernel cache" This reverts commit 943f83448abdbd96607ffce72587663ca75bebfb. These cache option cause a problem in some cases such as mount install. The older version of zip file is mounted even if the newer version is installed. Change-Id: Ia5f6e1fb94d738400b3d28662db25ea84cd3d596 --- src/tzip/tzip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tzip/tzip.c b/src/tzip/tzip.c index 0eedc26..7f91bb0 100644 --- a/src/tzip/tzip.c +++ b/src/tzip/tzip.c @@ -342,7 +342,7 @@ static void *tzip_thread(void *arg) size_t len; ssize_t read; char *saveptr = NULL; - char *argv[4] = {"deviced", "-o", "allow_other,kernel_cache,auto_cache", NULL}; + char *argv[4] = {"deviced", "-o", "allow_other", NULL}; struct fuse_args args = FUSE_ARGS_INIT(3, argv); ret = mkdir(TZIP_ROOT_PATH, 0755); @@ -364,7 +364,7 @@ static void *tzip_thread(void *arg) } } - fuse_handle = fuse_new(channel, &args, &tzip_oper, sizeof(tzip_oper), NULL); + fuse_handle = fuse_new(channel, NULL, &tzip_oper, sizeof(tzip_oper), NULL); if (!fuse_handle) { _E("Failed to fuse_new."); goto out_unlock; -- 2.7.4 From f015f4a4369291767312157f1d89993945aef1d5 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Tue, 9 Jun 2020 13:23:55 +0900 Subject: [PATCH 16/16] Add PATH=/bin:/usr/bin:/sbin:/usr/sbin to rndis.sh Change-Id: I50c9078262d1caf30d8ceef16b03da9990e98719 Signed-off-by: Hyotaek Shim --- scripts/rndis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/rndis.sh b/scripts/rndis.sh index f5e389b..6a390e6 100755 --- a/scripts/rndis.sh +++ b/scripts/rndis.sh @@ -1,5 +1,5 @@ #!/bin/sh - +PATH=/bin:/usr/bin:/sbin:/usr/sbin DEFAULT_IP_ADDR="192.168.129.3" ######################################################################################### -- 2.7.4