From: Youngjae Cho Date: Fri, 17 Jun 2022 05:26:50 +0000 (+0900) Subject: apps: move to shared library X-Git-Tag: submit/tizen/20220624.005127~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7556e7bcf29b4b8e108d4dfbb0f415ff941a5760;p=platform%2Fcore%2Fsystem%2Fdeviced.git apps: move to shared library Change-Id: I039bff30ad1b3745abd72ee4637caadd37487319 Signed-off-by: Youngjae Cho --- diff --git a/CMakeLists.txt b/CMakeLists.txt index de829181..ba0c0c86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,7 +64,6 @@ SET(CONFDIR "/etc/${PROJECT_NAME}") SET(VERSION 0.1.0) SET(SRCS - src/apps/apps.c src/control/control.c src/core/delayed-init-notifier.c src/core/devices.c diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index cda404c6..b6edf04e 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -51,7 +51,7 @@ #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" -#include "apps/apps.h" +#include "shared/apps.h" #include "extcon/extcon.h" #include "battery/power-supply.h" #include "power/power-off.h" diff --git a/plugins/iot-headed/display/key-filter.c b/plugins/iot-headed/display/key-filter.c index 5f0d544a..db9a338e 100644 --- a/plugins/iot-headed/display/key-filter.c +++ b/plugins/iot-headed/display/key-filter.c @@ -38,10 +38,10 @@ #include "shared/device-notifier.h" #include "shared/common.h" #include "shared/plugin.h" +#include "shared/apps.h" #include "power/power-off.h" #include "power/power-suspend.h" #include "led/touch-key.h" -#include "apps/apps.h" #include "display/display-lock.h" #ifndef KEY_SCREENLOCK diff --git a/plugins/mobile/battery/battery-notification.c b/plugins/mobile/battery/battery-notification.c index 8b7b1e60..b8a95783 100644 --- a/plugins/mobile/battery/battery-notification.c +++ b/plugins/mobile/battery/battery-notification.c @@ -21,7 +21,6 @@ #include #include -#include "apps/apps.h" #include "core/log.h" #include "battery.h" #include "config.h" @@ -34,6 +33,7 @@ #include "shared/eventsystem.h" #include "shared/plugin.h" #include "shared/device-notifier.h" +#include "shared/apps.h" #define METHOD_LOW_NOTI_ON "BatteryLowNotiOn" diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 8a0a100d..2e2d569e 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -50,7 +50,7 @@ #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" -#include "apps/apps.h" +#include "shared/apps.h" #include "extcon/extcon.h" #include "battery/power-supply.h" #include "power/power-off.h" diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index c596cc18..1e56db1c 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -38,10 +38,10 @@ #include "shared/device-notifier.h" #include "shared/common.h" #include "shared/plugin.h" +#include "shared/apps.h" #include "power/power-off.h" #include "power/power-suspend.h" #include "led/touch-key.h" -#include "apps/apps.h" #include "display/display-lock.h" #ifndef KEY_SCREENLOCK diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index f515e7ad..d8ba6420 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -50,7 +50,7 @@ #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" -#include "apps/apps.h" +#include "shared/apps.h" #include "extcon/extcon.h" #include "battery/power-supply.h" #include "power/power-off.h" diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index dc2c2bd1..42851ce1 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -38,10 +38,10 @@ #include "shared/device-notifier.h" #include "shared/common.h" #include "shared/plugin.h" +#include "shared/apps.h" #include "power/power-off.h" #include "power/power-suspend.h" #include "led/touch-key.h" -#include "apps/apps.h" #include "display/display-lock.h" #ifndef KEY_SCREENLOCK diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index e29e1706..1506958e 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -51,7 +51,7 @@ #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" -#include "apps/apps.h" +#include "shared/apps.h" #include "extcon/extcon.h" #include "battery/power-supply.h" #include "power/power-off.h" diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 68e774f9..ab4b47cd 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -38,10 +38,10 @@ #include "shared/device-notifier.h" #include "shared/common.h" #include "shared/plugin.h" +#include "shared/apps.h" #include "power/power-off.h" #include "power/power-suspend.h" #include "led/touch-key.h" -#include "apps/apps.h" #include "display/display-lock.h" #ifndef KEY_SCREENLOCK diff --git a/src/apps/apps.c b/src/apps/apps.c deleted file mode 100644 index dc20230a..00000000 --- a/src/apps/apps.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2015 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 "core/log.h" -#include "shared/common.h" -#include "apps.h" -#include "shared/plugin.h" -#include "shared/bitmap.h" - -#define POPUP_METHOD "PopupLaunch" -#define BUFF_MAX 255 - -static struct display_plugin *disp_plgn; -static struct dd_bitmap *bm_background; -static int pid_max; - -static const struct app_dbus_match { - const char *type; - const char *bus; - const char *path; - const char *iface; - const char *method; -} app_match[] = { - { APP_DEFAULT , POPUP_BUS_NAME, POPUP_PATH_SYSTEM , POPUP_INTERFACE_SYSTEM , POPUP_METHOD }, - { APP_POWERKEY, POPUP_BUS_NAME, POPUP_PATH_POWERKEY, POPUP_INTERFACE_POWERKEY, POPUP_METHOD }, - { APP_OVERHEAT, POPUP_BUS_NAME, POPUP_PATH_OVERHEAT, POPUP_INTERFACE_OVERHEAT, POPUP_METHOD }, - { APP_ABNORMAL, POPUP_BUS_NAME, POPUP_PATH_SYSTEM , POPUP_INTERFACE_SYSTEM , POPUP_METHOD }, - { APP_REMOVE , POPUP_BUS_NAME, POPUP_PATH_SYSTEM , POPUP_INTERFACE_SYSTEM , POPUP_METHOD }, -}; - -static void __cb(GVariant *var, void *user_data, GError *err) -{ - int ret; - - if (!var) { - _E("No message: %s", err->message); - return; - } - - if (!g_variant_get_safe(var, "(i)", &ret)) { - _E("No message: %s", g_variant_get_type_string(var)); - goto out; - } - - _D("Reply value: %d", ret); - -out: - g_variant_unref(var); -} - - -int launch_system_app(char *type, int num, ...) -{ - char *app_type; - va_list args; - int i, match, ret; - - if (type) - app_type = type; - else - app_type = APP_DEFAULT; - - match = -1; - for (i = 0 ; i < ARRAY_SIZE(app_match) ; i++) { - if (strncmp(app_type, app_match[i].type, strlen(app_type))) - continue; - match = i; - break; - } - if (match < 0) { - _E("Failed to find matched app type(%s).", app_type); - return -EINVAL; - } - - va_start(args, num); - - ret = gdbus_call_pairs_async_with_reply(app_match[match].bus, - app_match[match].path, - app_match[match].iface, - app_match[match].method, - num, - args, - __cb, - -1, - NULL); - - va_end(args); - - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); - - return ret; -} - -int launch_message_post(char *type) -{ - int ret; - - if (!type) - return -EINVAL; - - ret = gdbus_call_async_with_reply(POPUP_BUS_NAME, - POPUP_PATH_NOTI, - POPUP_INTERFACE_NOTI, - "MessagePostOn", - g_variant_new("(s)", type), - __cb, -1, NULL); - - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); - return ret; -} - -int add_async_notification(char *type, dbus_pending_cb func, GVariant *param) -{ - int ret; - - if (!type) - return -EINVAL; - - ret = gdbus_call_async_with_reply(POPUP_BUS_NAME, - POPUP_PATH_NOTI, - POPUP_INTERFACE_NOTI, - type, - param, - func, - -1, - NULL); - - return ret; -} - -int remove_notification(char *type, int id) -{ - if (!type || id < 0) - return -EINVAL; - - return gdbus_call_async_with_reply(POPUP_BUS_NAME, - POPUP_PATH_NOTI, - POPUP_INTERFACE_NOTI, - type, g_variant_new("(i)", id), - __cb, -1, NULL); -} - -bool is_app_background(pid_t pid) -{ - return test_bit(bm_background, pid); -} - -void init_bm_background(void) -{ - int ret; - - ret = sys_get_int("/proc/sys/kernel/pid_max", &pid_max); - if (ret < 0) - pid_max = 32768; - - /* need (pid_max + 1) bits to represent pid 0 ~ pid_max */ - bm_background = init_bitmap(pid_max + 1); - if (!bm_background) - _E("Failed to allock bm_background."); -} - -void set_app_state(pid_t pid, enum application_state as) -{ - if (!bm_background) - return; - - if (pid < 0 || pid > pid_max) - return; - - if (as == APPLICATION_BACKGROUND) - set_bit(bm_background, pid); - else if (as == APPLICATION_FOREGROUND || as == APPLICATION_TERMINATED) - clear_bit(bm_background, pid); - else - _E("Invalid as=%d", as); -} - -static void __CONSTRUCTOR__ initialize(void) -{ - disp_plgn = get_var_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin variable."); - - init_bm_background(); -} - -static void __DESTRUCTOR__ finalize(void) -{ - deinit_bitmap(bm_background); -} diff --git a/src/apps/apps.h b/src/apps/apps.h deleted file mode 100644 index 8e6ac233..00000000 --- a/src/apps/apps.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2015 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 __APPS_H__ -#define __APPS_H__ - -#include -#include -#include "shared/common.h" -#include "display/poll.h" -#include "display/display-ops.h" - -#define APP_POWERKEY "powerkey" -#define APP_OVERHEAT "overheat" -#define APP_DEFAULT "system" -#define APP_ABNORMAL "abnormal" -#define APP_REMOVE "remove" -#define APP_KEY_TYPE "_SYSPOPUP_CONTENT_" - -enum application_state { - APPLICATION_TERMINATED = 0, - APPLICATION_FOREGROUND, - APPLICATION_BACKGROUND, /* deactivate NORMAL, DIM lock */ -}; - -int launch_system_app(char *type, int num, ...); -int launch_message_post(char *type); -int add_async_notification(char *type, dbus_pending_cb func, GVariant *param); -int remove_notification(char *type, int id); -void set_app_state(pid_t pid, enum application_state as); -bool is_app_background (pid_t pid); -#endif /* __APPS_H__ */ - diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 54b85f51..adc3513f 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -36,6 +36,7 @@ #include "shared/devices.h" #include "shared/device-notifier.h" #include "shared/common.h" +#include "shared/apps.h" #include "core/udev.h" #include "shared/eventsystem.h" #include "shared/plugin.h" @@ -44,7 +45,6 @@ #include "display/display-ops.h" #include "power/power.h" #include "power/power-off.h" -#include "apps/apps.h" #include "power-supply.h" #define BATTERY_UNKNOWN -1 diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index f5c57c4f..dea6007e 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -34,9 +34,9 @@ #include "display/setting.h" #include "shared/eventsystem.h" #include "shared/plugin.h" +#include "shared/apps.h" #include "display/core.h" #include "display/display-ops.h" -#include "apps/apps.h" #include "power-supply.h" #include "battery.h" #include "battery-ops.h" diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index a6a59096..9b73ba9b 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -36,7 +36,7 @@ #include "shared/common.h" #include "shared/devices.h" #include "shared/device-notifier.h" -#include "apps/apps.h" +#include "shared/apps.h" #include "dd-display.h" #include "display-actor.h" #include "display-ops.h" diff --git a/src/display/display-lock.c b/src/display/display-lock.c index 9fb232fa..b866a664 100644 --- a/src/display/display-lock.c +++ b/src/display/display-lock.c @@ -29,7 +29,7 @@ #include "lock-detector.h" #include "display-lock.h" #include "shared/log-macro.h" -#include "apps/apps.h" +#include "shared/apps.h" #define METHOD_APP_STATUS "CheckAppStatus" #define PID_MAX 6 diff --git a/src/power/power-off.c b/src/power/power-off.c index b7bb97c2..89f9b190 100644 --- a/src/power/power-off.c +++ b/src/power/power-off.c @@ -49,7 +49,6 @@ #include "display/display-ops.h" #include "power-off.h" #include "power.h" -#include "apps/apps.h" #include "power-boot.h" #include "shared/plugin.h" diff --git a/src/shared/apps.c b/src/shared/apps.c new file mode 100644 index 00000000..10e53a0a --- /dev/null +++ b/src/shared/apps.c @@ -0,0 +1,210 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2015 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 "core/log.h" +#include "shared/common.h" +#include "apps.h" +#include "shared/plugin.h" +#include "shared/bitmap.h" + +#define POPUP_METHOD "PopupLaunch" +#define BUFF_MAX 255 + +static struct display_plugin *disp_plgn; +static struct dd_bitmap *bm_background; +static int pid_max; + +static const struct app_dbus_match { + const char *type; + const char *bus; + const char *path; + const char *iface; + const char *method; +} app_match[] = { + { APP_DEFAULT , POPUP_BUS_NAME, POPUP_PATH_SYSTEM , POPUP_INTERFACE_SYSTEM , POPUP_METHOD }, + { APP_POWERKEY, POPUP_BUS_NAME, POPUP_PATH_POWERKEY, POPUP_INTERFACE_POWERKEY, POPUP_METHOD }, + { APP_OVERHEAT, POPUP_BUS_NAME, POPUP_PATH_OVERHEAT, POPUP_INTERFACE_OVERHEAT, POPUP_METHOD }, + { APP_ABNORMAL, POPUP_BUS_NAME, POPUP_PATH_SYSTEM , POPUP_INTERFACE_SYSTEM , POPUP_METHOD }, + { APP_REMOVE , POPUP_BUS_NAME, POPUP_PATH_SYSTEM , POPUP_INTERFACE_SYSTEM , POPUP_METHOD }, +}; + +static void __cb(GVariant *var, void *user_data, GError *err) +{ + int ret; + + if (!var) { + _E("No message: %s", err->message); + return; + } + + if (!g_variant_get_safe(var, "(i)", &ret)) { + _E("No message: %s", g_variant_get_type_string(var)); + goto out; + } + + _D("Reply value: %d", ret); + +out: + g_variant_unref(var); +} + + +int launch_system_app(char *type, int num, ...) +{ + char *app_type; + va_list args; + int i, match, ret; + + if (type) + app_type = type; + else + app_type = APP_DEFAULT; + + match = -1; + for (i = 0 ; i < ARRAY_SIZE(app_match) ; i++) { + if (strncmp(app_type, app_match[i].type, strlen(app_type))) + continue; + match = i; + break; + } + if (match < 0) { + _E("Failed to find matched app type(%s).", app_type); + return -EINVAL; + } + + va_start(args, num); + + ret = gdbus_call_pairs_async_with_reply(app_match[match].bus, + app_match[match].path, + app_match[match].iface, + app_match[match].method, + num, + args, + __cb, + -1, + NULL); + + va_end(args); + + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); + + return ret; +} + +int launch_message_post(char *type) +{ + int ret; + + if (!type) + return -EINVAL; + + ret = gdbus_call_async_with_reply(POPUP_BUS_NAME, + POPUP_PATH_NOTI, + POPUP_INTERFACE_NOTI, + "MessagePostOn", + g_variant_new("(s)", type), + __cb, -1, NULL); + + if (disp_plgn->pm_change_internal) + disp_plgn->pm_change_internal(INTERNAL_LOCK_POPUP, LCD_NORMAL); + return ret; +} + +int add_async_notification(char *type, dbus_pending_cb func, GVariant *param) +{ + int ret; + + if (!type) + return -EINVAL; + + ret = gdbus_call_async_with_reply(POPUP_BUS_NAME, + POPUP_PATH_NOTI, + POPUP_INTERFACE_NOTI, + type, + param, + func, + -1, + NULL); + + return ret; +} + +int remove_notification(char *type, int id) +{ + if (!type || id < 0) + return -EINVAL; + + return gdbus_call_async_with_reply(POPUP_BUS_NAME, + POPUP_PATH_NOTI, + POPUP_INTERFACE_NOTI, + type, g_variant_new("(i)", id), + __cb, -1, NULL); +} + +bool is_app_background(pid_t pid) +{ + return test_bit(bm_background, pid); +} + +void init_bm_background(void) +{ + int ret; + + ret = sys_get_int("/proc/sys/kernel/pid_max", &pid_max); + if (ret < 0) + pid_max = 32768; + + /* need (pid_max + 1) bits to represent pid 0 ~ pid_max */ + bm_background = init_bitmap(pid_max + 1); + if (!bm_background) + _E("Failed to allock bm_background."); +} + +void set_app_state(pid_t pid, enum application_state as) +{ + if (!bm_background) + return; + + if (pid < 0 || pid > pid_max) + return; + + if (as == APPLICATION_BACKGROUND) + set_bit(bm_background, pid); + else if (as == APPLICATION_FOREGROUND || as == APPLICATION_TERMINATED) + clear_bit(bm_background, pid); + else + _E("Invalid as=%d", as); +} + +static void __CONSTRUCTOR__ initialize(void) +{ + disp_plgn = get_var_display_plugin(); + if (!disp_plgn) + _E("Failed to get display plugin variable."); + + init_bm_background(); +} + +static void __DESTRUCTOR__ finalize(void) +{ + deinit_bitmap(bm_background); +} diff --git a/src/shared/apps.h b/src/shared/apps.h new file mode 100644 index 00000000..8e6ac233 --- /dev/null +++ b/src/shared/apps.h @@ -0,0 +1,48 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2015 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 __APPS_H__ +#define __APPS_H__ + +#include +#include +#include "shared/common.h" +#include "display/poll.h" +#include "display/display-ops.h" + +#define APP_POWERKEY "powerkey" +#define APP_OVERHEAT "overheat" +#define APP_DEFAULT "system" +#define APP_ABNORMAL "abnormal" +#define APP_REMOVE "remove" +#define APP_KEY_TYPE "_SYSPOPUP_CONTENT_" + +enum application_state { + APPLICATION_TERMINATED = 0, + APPLICATION_FOREGROUND, + APPLICATION_BACKGROUND, /* deactivate NORMAL, DIM lock */ +}; + +int launch_system_app(char *type, int num, ...); +int launch_message_post(char *type); +int add_async_notification(char *type, dbus_pending_cb func, GVariant *param); +int remove_notification(char *type, int id); +void set_app_state(pid_t pid, enum application_state as); +bool is_app_background (pid_t pid); +#endif /* __APPS_H__ */ + diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index 6eee2634..386d96b3 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -23,7 +23,7 @@ #include #include -#include "apps/apps.h" +#include "shared/apps.h" #include "shared/devices.h" #include "core/log.h" #include "shared/device-notifier.h" diff --git a/src/usb-gadget/usb-state.c b/src/usb-gadget/usb-state.c index a3e766df..8d7a4cc2 100644 --- a/src/usb-gadget/usb-state.c +++ b/src/usb-gadget/usb-state.c @@ -23,7 +23,7 @@ #include #include "core/log.h" -#include "apps/apps.h" +#include "shared/apps.h" #include "extcon/extcon.h" #include "usb-gadget.h" diff --git a/src/usb-host/usb-host.c b/src/usb-host/usb-host.c index 9155fb5f..3dc6d789 100644 --- a/src/usb-host/usb-host.c +++ b/src/usb-host/usb-host.c @@ -28,8 +28,8 @@ #include "core/log.h" #include "shared/devices.h" #include "shared/device-notifier.h" +#include "shared/apps.h" #include "core/udev.h" -#include "apps/apps.h" #include "extcon/extcon.h" #include "display/display-ops.h" #include "display/core.h"