Add unified-system-service-deviced plugin for unified system service support 28/324128/3
authorYunhee Seo <yuni.seo@samsung.com>
Tue, 13 May 2025 08:03:35 +0000 (17:03 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Tue, 13 May 2025 10:17:52 +0000 (10:17 +0000)
To support unified system service, here is the changes.

deviced-unified-system-plugin rpm is newly added to install
libunified-system-service-deviced.so.
Service execution will be replaced as a library init/exit() way.
With this, unified-system-service can run system services as a thread simultaneously.

To avoid dbus rule conflict, a part of dbus conf rule is removed as
different config file 'org.tizen.system.deviced-unified-system-service.conf'.
This file will replace org.tizen.system.deviced.conf by the postscript
of plugin rpm when it is installed.

Change-Id: Ifda03117729dedaf818a0710b21460ca572e8bb9
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
CMakeLists.txt
conf/org.tizen.system.deviced-unified-system-service.conf [new file with mode: 0644]
packaging/deviced.spec
src/core/main.c

index f36ea414550a80d6daba55eedd07eb14c815decf..d56955afac8211bdba9724d7764ba05a08f053b4 100644 (file)
@@ -6,6 +6,7 @@ PROJECT(deviced C)
 ########################################################
 
 SET(CMAKE_VERBOSE_MAKEFILE OFF)
+SET(LIBRARY_NAME "unified-system-service-deviced")
 
 IF("${ARCH}" STREQUAL "arm")
        OPTION(USE_ARM "Use Arm" ON)
@@ -254,6 +255,10 @@ INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
 
 INSTALL(DIRECTORY DESTINATION ${MAKE_INSTALL_PREFIX}${DD_PLUGIN_PATH})
 
+ADD_LIBRARY(${LIBRARY_NAME} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${REQUIRED_PKGS_LDFLAGS} "-lrt -ldl -lm" deviced-common-private)
+INSTALL(TARGETS ${LIBRARY_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
+
 IF(POWER_MODULE STREQUAL on)
        ADD_EXECUTABLE(deviced-shutdown src/power-shutdown/shutdown.c src/shared/common.c)
        SET(deviced-shutdown_LDFLAGS ${REQUIRED_PKGS_LDFLAGS})
@@ -317,6 +322,7 @@ CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/org.tizen.system.deviced.conf       DESTINATION /etc/dbus-1/system.d)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/org.tizen.system.deviced-unified-system-service.conf       DESTINATION /etc/dbus-1/system.d)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/org.tizen.system.deviced.service DESTINATION /usr/share/dbus-1/system-services)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/deviced.service                  DESTINATION /usr/lib/systemd/system)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/usb-host-ffs-test-daemon.service DESTINATION /usr/lib/systemd/system)
diff --git a/conf/org.tizen.system.deviced-unified-system-service.conf b/conf/org.tizen.system.deviced-unified-system-service.conf
new file mode 100644 (file)
index 0000000..9ceb478
--- /dev/null
@@ -0,0 +1,88 @@
+<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
+<busconfig>
+    <policy user="root">
+        <allow own="org.tizen.system.deviced"/>
+        <allow send_destination="org.tizen.system.deviced"/>
+        <allow send_type="signal" send_path="/Org/Tizen/System/DeviceD/Display" send_interface="org.tizen.system.deviced.display"/>
+        <allow send_type="signal" send_path="/Org/Tizen/System/DeviceD/Time" send_interface="org.tizen.system.deviced.Time"/>
+        <allow send_type="signal" send_path="/Org/Tizen/System/DeviceD/Battery" send_interface="org.tizen.system.deviced.Battery"/>
+    </policy>
+
+    <policy user="service_fw">
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.BatteryMonitor" send_member="GetBMData"/>
+    </policy>
+
+    <policy user="system_fw">
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.Battery" send_member="power_supply"/>
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.ExtCon"/>
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.display" send_member="AutoBrightnessChanged"/>
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.SysNoti" send_member="udev"/>
+    </policy>
+
+    <policy user="security_fw">
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.SysNoti" send_member="getcontrol"/>
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.SysNoti" send_member="control"/>
+    </policy>
+
+    <policy user="app_fw">
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.Tzip"/>
+    </policy>
+
+    <policy group="users">
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.Tzip"/>
+    </policy>
+
+    <policy context="default">
+        <deny own="org.tizen.system.deviced"/>
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.freedesktop.DBus.Properties" send_member="GetAll"/>
+
+        <check send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.display"
+            privilege="http://tizen.org/privilege/display"/>
+        <check send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.Power"
+            privilege="http://tizen.org/privilege/power"/>
+        <check send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.PowerOff"
+            privilege="http://tizen.org/privilege/reboot"/>
+        <check send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.Led"
+            privilege="http://tizen.org/privilege/led"/>
+        <check send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.ir"
+            privilege="http://tizen.org/privilege/use_ir"/>
+        <check send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.Usbhost"
+            privilege="http://tizen.org/privilege/usb.host"/>
+        <check send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.touch"
+            privilege="http://tizen.org/privilege/internal/default/platform"/>
+        <check send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.Csa"
+            privilege="http://tizen.org/privilege/internal/default/platform"/>
+
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.input"/>
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.Battery"/>
+        <deny send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.Battery" send_member="power_supply"/>
+        <check send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.Battery" send_member="SetLowbatLevel"
+            privilege="http://tizen.org/privilege/systemsettings.admin"/>
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.Core"/>
+        <deny send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.ExtCon"/>
+
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.SysNoti"/>
+        <deny send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.SysNoti" send_member="getcontrol"/>
+        <deny send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.SysNoti" send_member="control"/>
+        <deny send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.SysNoti" send_member="udev"/>
+
+        <deny send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.Tzip"/>
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.Usb"/>
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.UsbHostTest"/>
+        <check send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.PmQos"
+            privilege="http://tizen.org/privilege/internal/default/platform"/>
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.temperature"/>
+        <allow send_destination="org.tizen.system.deviced" send_interface="org.tizen.system.deviced.Board"/>
+
+        <deny send_type="signal"
+            send_path="/Org/Tizen/System/DeviceD/Display"
+            send_interface="org.tizen.system.deviced.display"/>
+        <deny send_type="signal"
+            send_path="/Org/Tizen/System/DeviceD/Time"
+            send_interface="org.tizen.system.deviced.Time"/>
+        <deny send_type="signal"
+            send_path="/Org/Tizen/System/DeviceD/Battery"
+            send_interface="org.tizen.system.deviced.Battery"/>
+    </policy>
+</busconfig>
index b69d32dc84315fa3a1b9b5a05e2c6650b7de3216..42cfc8043c0e5548dd325757ec110aa9b6b88096 100644 (file)
@@ -48,6 +48,7 @@ BuildRequires:  pkgconfig(cmocka)
 BuildRequires:  pkgconfig(gtest)
 BuildRequires:  pkgconfig(gmock)
 BuildRequires:  pkgconfig(security-manager)
+BuildRequires:  pkgconfig(hal-api-common)
 
 Requires: %{name}-tools = %{version}-%{release}
 %{?systemd_requires}
@@ -58,6 +59,13 @@ Requires(preun): %{_sbindir}/update-alternatives
 %description
 Deviced
 
+%package  unified-system-plugin
+Summary:  unified-system plugin
+Requires: %{name} = %{version}-%{release}
+
+%description unified-system-plugin
+unified-system-service plugin
+
 %package -n libdeviced
 Summary:    Deviced library
 Group:      Development/Libraries
@@ -275,6 +283,10 @@ mv %{_sysconfdir}/deviced/power-profile-tv.conf %{_sysconfdir}/deviced/power.con
 mkdir -p %{_libdir}/deviced
 mv %{_libdir}/tv-display.so %{_libdir}/deviced/display.so
 
+%post unified-system-plugin
+mv %{_sysconfdir}/dbus-1/system.d/org.tizen.system.deviced-unified-system-service.conf \
+       %{_sysconfdir}/dbus-1/system.d/org.tizen.system.deviced.conf
+
 %files
 %manifest %{name}.manifest
 %license LICENSE.Apache-2.0
@@ -316,6 +328,44 @@ mv %{_libdir}/tv-display.so %{_libdir}/deviced/display.so
 %{_prefix}/lib/systemd/deviced-shutdown
 %{_sbindir}/deviced-request-shutdown
 
+%files unified-system-plugin
+%manifest %{name}.manifest
+%license LICENSE.Apache-2.0
+%{_libdir}/libunified-system-service-deviced.so
+%{_libdir}/libdeviced-common-private.so
+%dir %{plugindir}
+%if %{?sdb_prestart} == on
+%{_unitdir}/sdb-prestart.service
+%{_unitdir}/basic.target.wants/sdb-prestart.service
+%endif
+%config %{_sysconfdir}/dbus-1/system.d/org.tizen.system.deviced-unified-system-service.conf
+%config %{_sysconfdir}/deviced/init.conf
+%config %{_sysconfdir}/deviced/display.conf
+%if %{?battery_module} == on
+%config %{_sysconfdir}/deviced/battery.conf
+%endif
+# usbhost_test
+%{_sysconfdir}/deviced/usb-host-test/test_gadget.gs
+%{_bindir}/usb-host-ffs-test-daemon
+%{_unitdir}/usb-host-ffs-test-daemon.service
+%{_unitdir}/usb-host-test.socket
+%{_sysconfdir}/deviced/usb-host-test/descs
+%{_sysconfdir}/deviced/usb-host-test/strs
+# dummy mtp-responder
+%{_sysconfdir}/mtp-responder-dummy/strs
+%{_sysconfdir}/mtp-responder-dummy/descs
+%{_unitdir}/mtp-responder-dummy.socket
+%{_unitdir}/mtp-responder-dummy.service
+
+# Assume power module is on (-DPOWER_MODULE=on)
+%{_unitdir}/deviced-request-shutdown@.service
+%{_unitdir}/systemd-reboot.service.d/deviced-request-shutdown-reboot.conf
+%{_unitdir}/systemd-poweroff.service.d/deviced-request-shutdown-poweroff.conf
+%{_unitdir}/systemd-halt.service.d/deviced-request-shutdown-halt.conf
+%{_unitdir}/systemd-exit.service.d/deviced-request-shutdown-exit.conf
+%{_prefix}/lib/systemd/deviced-shutdown
+%{_sbindir}/deviced-request-shutdown
+
 %files -n libdeviced
 %manifest deviced.manifest
 %license LICENSE.Apache-2.0
index 0a20cb18cd9059355a6986287ee488dad3f0c832..d5986307c33f5991feb8b312134f620fed26ebe9 100644 (file)
@@ -27,6 +27,8 @@
 #include <device/board-internal.h>
 #include <argos.h>
 
+#include <unified-system-service-common.h>
+
 #include "core.h"
 #include "log.h"
 #include "resource.h"
@@ -101,7 +103,13 @@ static gboolean watchdog_cb(void *data)
        return G_SOURCE_CONTINUE;
 }
 
-static int deviced_main(int argc, char **argv)
+static int deviced_early_init(void *data)
+{
+       writepid(PIDFILE_PATH);
+       return 0;
+}
+
+static int deviced_init(void *data)
 {
        int ret;
        dbus_handle_h handle = NULL;
@@ -110,7 +118,6 @@ static int deviced_main(int argc, char **argv)
        int retval;
 
        CRITICAL_LOG("Initializing deviced.");
-       mainloop = g_main_loop_new(NULL, FALSE);
 
        ret = poweroff_check_revived();
        if (is_poweroff_state(ret)) {
@@ -158,21 +165,45 @@ static int deviced_main(int argc, char **argv)
                        _E("aw_register failed.");
        }
 
-       /* g_main_loop */
        CRITICAL_LOG("Starting deviced.");
-       g_main_loop_run(mainloop);
-       g_main_loop_unref(mainloop);
 
+       return 0;
+}
+
+static int deviced_exit(void *data)
+{
        devices_exit(NULL);
        resource_exit();
 
        unload_plugins();
+       return 0;
+}
+
+static int deviced_main(int argc, char **argv)
+{
+       mainloop = g_main_loop_new(NULL, FALSE);
+
+       deviced_init(NULL);
+
+       g_main_loop_run(mainloop);
+       g_main_loop_unref(mainloop);
+
+       deviced_exit(NULL);
 
        return 0;
 }
 
 int main(int argc, char **argv)
 {
-       writepid(PIDFILE_PATH);
+       deviced_early_init(NULL);
        return deviced_main(argc, argv);
 }
+
+__attribute__ ((visibility("default")))
+unified_system_service unified_system_service_deviced_data = {
+       .name           = "unified-system-service-deviced",
+       .early_init     = deviced_early_init,
+       .init           = deviced_init,
+       .exit           = deviced_exit,
+       .late_exit      = NULL,
+};