From ddb46ebd5e62b0fbefe2b38c385bbf01ef1a91f7 Mon Sep 17 00:00:00 2001
From: Thierry Escande <thierry.escande@huawei.com>
Date: Wed, 28 Sep 2022 16:45:20 +0200
Subject: [PATCH] openharmony-3.0: Add OpenHarmony media service

Signed-off-by: Thierry Escande <thierry.escande@huawei.com>
---
 recipes-openharmony/openharmony/files/media.service    | 10 ++++++++++
 .../openharmony/files/openharmony-preinit              | 10 ++++++++++
 .../openharmony/openharmony-standard_3.0.bb            |  7 +++++++
 3 files changed, 27 insertions(+)
 create mode 100644 recipes-openharmony/openharmony/files/media.service

diff --git a/recipes-openharmony/openharmony/files/media.service b/recipes-openharmony/openharmony/files/media.service
new file mode 100644
index 00000000..c592e01f
--- /dev/null
+++ b/recipes-openharmony/openharmony/files/media.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=OpenHarmony media service
+
+[Service]
+Type=oneshot
+ExecStart=/bin/echo "OpenHarmony Media Service"
+RemainAfterExit=yes
+
+[Install]
+WantedBy=multi-user.target
diff --git a/recipes-openharmony/openharmony/files/openharmony-preinit b/recipes-openharmony/openharmony/files/openharmony-preinit
index 4ca1d5c4..51527e19 100644
--- a/recipes-openharmony/openharmony/files/openharmony-preinit
+++ b/recipes-openharmony/openharmony/files/openharmony-preinit
@@ -271,6 +271,16 @@ if systemctl -q is-enabled foundation.service; then
 	sleep "$STARTUP_CMD_SLEEP"
 fi
 
+# trigger: boot
+# "name" : "media_service",
+# "path" : ["/system/bin/sa_main", "/system/profile/media_service.xml"],
+# "uid" : "system",
+# "gid" : ["media_rw", "system"]
+if systemctl -q is-enabled media.service; then
+	/system/bin/sa_main /system/profile/media_service.xml &
+	sleep "$STARTUP_CMD_SLEEP"
+fi
+
 # trigger: boot
 # "name" : "inputmethod_service",
 # "path" : ["/system/bin/sa_main", "/system/profile/inputmethod_service.xml"],
diff --git a/recipes-openharmony/openharmony/openharmony-standard_3.0.bb b/recipes-openharmony/openharmony/openharmony-standard_3.0.bb
index 324d8c40..c3d8b2fd 100644
--- a/recipes-openharmony/openharmony/openharmony-standard_3.0.bb
+++ b/recipes-openharmony/openharmony/openharmony-standard_3.0.bb
@@ -1368,6 +1368,13 @@ FILES:${PN}-multimedia-media = " \
     ${libdir}/module/multimedia/libmedia*${SOLIBS} \
     ${libdir}/openharmony/profile/media_service.xml \
 "
+SYSTEMD_PACKAGES += "${PN}-multimedia-media"
+SYSTEMD_SERVICE:${PN}-multimedia-media = "media.service"
+SRC_URI += "file://media.service"
+do_install:append() {
+    install -d ${D}/${systemd_unitdir}/system
+    install -m 644 ${WORKDIR}/media.service ${D}${systemd_unitdir}/system/
+}
 RDEPENDS:${PN}-multimedia-media += "musl libcxx"
 RDEPENDS:${PN}-multimedia-media += "${PN}-hilog ${PN}-libutils ${PN}-ipc ${PN}-samgr ${PN}-safwk ${PN}-graphic ${PN}-peripheral-display"
 RDEPENDS:${PN}-multimedia-media += "${PN}-multimedia-audio ${PN}-thirdparty-gstreamer ${PN}-thirdparty-glib ${PN}-syspara ${PN}-ace-napi"
-- 
GitLab