From b84179a1250abcc61ef544c38163461744cf3ec9 Mon Sep 17 00:00:00 2001
From: Thierry Escande <thierry.escande@huawei.com>
Date: Wed, 10 Aug 2022 02:25:55 +0200
Subject: [PATCH] openharmony-standard-3.0: Add System Ability services

These are services using the System Ability framework through the
executable sa_main. These services depend on and are started after the
System Ability Manager service (samgr).

Most of them are noop for now. No process is created after sa_main exits
for all of these services.

Signed-off-by: Thierry Escande <thierry.escande@huawei.com>
---
 .../openharmony/files/accountmgr.service      | 12 ++++
 .../files/accountmgr.service.license          |  3 +
 .../files/distributed_data.service            | 13 +++++
 .../files/distributed_data.service.license    |  3 +
 .../files/distributedsched.service            | 12 ++++
 .../files/distributedsched.service.license    |  3 +
 .../openharmony/files/dsoftbus.service        |  3 +-
 .../openharmony/files/huks.service            | 12 ++++
 .../openharmony/files/huks.service.license    |  3 +
 .../openharmony/files/inputmethod.service     | 12 ++++
 .../files/inputmethod.service.license         |  3 +
 .../openharmony/files/time.service            | 12 ++++
 .../openharmony/files/time.service.license    |  3 +
 .../openharmony/openharmony-standard_3.0.bb   | 56 +++++++++++++++++++
 14 files changed, 149 insertions(+), 1 deletion(-)
 create mode 100644 recipes-openharmony/openharmony/files/accountmgr.service
 create mode 100644 recipes-openharmony/openharmony/files/accountmgr.service.license
 create mode 100644 recipes-openharmony/openharmony/files/distributed_data.service
 create mode 100644 recipes-openharmony/openharmony/files/distributed_data.service.license
 create mode 100644 recipes-openharmony/openharmony/files/distributedsched.service
 create mode 100644 recipes-openharmony/openharmony/files/distributedsched.service.license
 create mode 100644 recipes-openharmony/openharmony/files/huks.service
 create mode 100644 recipes-openharmony/openharmony/files/huks.service.license
 create mode 100644 recipes-openharmony/openharmony/files/inputmethod.service
 create mode 100644 recipes-openharmony/openharmony/files/inputmethod.service.license
 create mode 100644 recipes-openharmony/openharmony/files/time.service
 create mode 100644 recipes-openharmony/openharmony/files/time.service.license

diff --git a/recipes-openharmony/openharmony/files/accountmgr.service b/recipes-openharmony/openharmony/files/accountmgr.service
new file mode 100644
index 00000000..d10e896d
--- /dev/null
+++ b/recipes-openharmony/openharmony/files/accountmgr.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=OpenHarmony Account Manager service
+Requires=appspawn.service
+After=appspawn.service
+
+[Service]
+Type=exec
+# should run as system:system
+ExecStart=/usr/bin/sa_main /system/profile/accountmgr.xml
+
+[Install]
+WantedBy=multi-user.target
diff --git a/recipes-openharmony/openharmony/files/accountmgr.service.license b/recipes-openharmony/openharmony/files/accountmgr.service.license
new file mode 100644
index 00000000..98a0b3f4
--- /dev/null
+++ b/recipes-openharmony/openharmony/files/accountmgr.service.license
@@ -0,0 +1,3 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
diff --git a/recipes-openharmony/openharmony/files/distributed_data.service b/recipes-openharmony/openharmony/files/distributed_data.service
new file mode 100644
index 00000000..5abbc235
--- /dev/null
+++ b/recipes-openharmony/openharmony/files/distributed_data.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=OpenHarmony Distributed Data service
+Requires=appspawn.service
+After=appspawn.service
+
+[Service]
+Type=exec
+CapabilityBoundingSet=CAP_DAC_READ_SEARCH
+# should run as system:system
+ExecStart=/usr/bin/sa_main /system/profile/distributeddata.xml
+
+[Install]
+WantedBy=multi-user.target
diff --git a/recipes-openharmony/openharmony/files/distributed_data.service.license b/recipes-openharmony/openharmony/files/distributed_data.service.license
new file mode 100644
index 00000000..98a0b3f4
--- /dev/null
+++ b/recipes-openharmony/openharmony/files/distributed_data.service.license
@@ -0,0 +1,3 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
diff --git a/recipes-openharmony/openharmony/files/distributedsched.service b/recipes-openharmony/openharmony/files/distributedsched.service
new file mode 100644
index 00000000..3464d205
--- /dev/null
+++ b/recipes-openharmony/openharmony/files/distributedsched.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=OpenHarmony Distributed Schedule service
+Requires=appspawn.service
+After=appspawn.service
+
+[Service]
+Type=exec
+# should run as system:system
+ExecStart=/usr/bin/sa_main /system/profile/distributedsched.xml
+
+[Install]
+WantedBy=multi-user.target
diff --git a/recipes-openharmony/openharmony/files/distributedsched.service.license b/recipes-openharmony/openharmony/files/distributedsched.service.license
new file mode 100644
index 00000000..98a0b3f4
--- /dev/null
+++ b/recipes-openharmony/openharmony/files/distributedsched.service.license
@@ -0,0 +1,3 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
diff --git a/recipes-openharmony/openharmony/files/dsoftbus.service b/recipes-openharmony/openharmony/files/dsoftbus.service
index 5c00011b..4eb198de 100644
--- a/recipes-openharmony/openharmony/files/dsoftbus.service
+++ b/recipes-openharmony/openharmony/files/dsoftbus.service
@@ -1,6 +1,7 @@
 [Unit]
 Description=OpenHarmony DSoftBus services
-Requires=samgr.service
+Requires=appspawn.service
+After=appspawn.service
 
 [Service]
 Type=exec
diff --git a/recipes-openharmony/openharmony/files/huks.service b/recipes-openharmony/openharmony/files/huks.service
new file mode 100644
index 00000000..09bec8b9
--- /dev/null
+++ b/recipes-openharmony/openharmony/files/huks.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=OpenHarmony huks service
+Requires=appspawn.service
+After=appspawn.service
+
+[Service]
+Type=exec
+# should run as system:system
+ExecStart=/usr/bin/sa_main /system/profile/huks_service.xml
+
+[Install]
+WantedBy=multi-user.target
diff --git a/recipes-openharmony/openharmony/files/huks.service.license b/recipes-openharmony/openharmony/files/huks.service.license
new file mode 100644
index 00000000..98a0b3f4
--- /dev/null
+++ b/recipes-openharmony/openharmony/files/huks.service.license
@@ -0,0 +1,3 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
diff --git a/recipes-openharmony/openharmony/files/inputmethod.service b/recipes-openharmony/openharmony/files/inputmethod.service
new file mode 100644
index 00000000..5d4ae0a8
--- /dev/null
+++ b/recipes-openharmony/openharmony/files/inputmethod.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=OpenHarmony input method services
+Requires=appspawn.service
+After=appspawn.service
+
+[Service]
+Type=exec
+# should run as system:system
+ExecStart=/usr/bin/sa_main /system/profile/inputmethod_service.xml
+
+[Install]
+WantedBy=multi-user.target
diff --git a/recipes-openharmony/openharmony/files/inputmethod.service.license b/recipes-openharmony/openharmony/files/inputmethod.service.license
new file mode 100644
index 00000000..98a0b3f4
--- /dev/null
+++ b/recipes-openharmony/openharmony/files/inputmethod.service.license
@@ -0,0 +1,3 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
diff --git a/recipes-openharmony/openharmony/files/time.service b/recipes-openharmony/openharmony/files/time.service
new file mode 100644
index 00000000..41e94446
--- /dev/null
+++ b/recipes-openharmony/openharmony/files/time.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=OpenHarmony Time service
+Requires=appspawn.service
+After=appspawn.service
+
+[Service]
+Type=exec
+# should run as system:system
+ExecStart=/usr/bin/sa_main /system/profile/time_service.xml
+
+[Install]
+WantedBy=multi-user.target
diff --git a/recipes-openharmony/openharmony/files/time.service.license b/recipes-openharmony/openharmony/files/time.service.license
new file mode 100644
index 00000000..98a0b3f4
--- /dev/null
+++ b/recipes-openharmony/openharmony/files/time.service.license
@@ -0,0 +1,3 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
diff --git a/recipes-openharmony/openharmony/openharmony-standard_3.0.bb b/recipes-openharmony/openharmony/openharmony-standard_3.0.bb
index dbd7c187..fc84d2dc 100644
--- a/recipes-openharmony/openharmony/openharmony-standard_3.0.bb
+++ b/recipes-openharmony/openharmony/openharmony-standard_3.0.bb
@@ -666,6 +666,14 @@ RDEPENDS:${PN}-ptest += "${PN}-ipc-ptest"
 
 # //foundation/communication/dsoftbus
 PACKAGES =+ "${PN}-dsoftbus"
+SYSTEMD_PACKAGES += "${PN}-dsoftbus"
+SYSTEMD_SERVICE:${PN}-dsoftbus = "dsoftbus.service"
+SRC_URI += "file://dsoftbus.service"
+do_install:append() {
+    install -d ${D}/${systemd_unitdir}/system
+    install -m 644 ${WORKDIR}/dsoftbus.service ${D}${systemd_unitdir}/system/
+    rm -f ${D}${sysconfdir}/openharmony/init/softbus_server.cfg
+}
 FILES:${PN}-dsoftbus = " \
     ${libdir}/libsoftbus*${SOLIBS} \
     ${libdir}/libnstackx*${SOLIBS} \
@@ -788,6 +796,14 @@ RDEPENDS:${PN}-ptest += "${PN}-appdatamgr-ptest"
 
 # //foundation/distributeddatamgr/distributeddatamgr
 PACKAGES =+ "${PN}-distributeddatamgr"
+SYSTEMD_PACKAGES += "${PN}-distributeddatamgr"
+SYSTEMD_SERVICE:${PN}-distributeddatamgr = "distributed_data.service"
+SRC_URI += "file://distributed_data.service"
+do_install:append() {
+    install -d ${D}/${systemd_unitdir}/system
+    install -m 644 ${WORKDIR}/distributed_data.service ${D}${systemd_unitdir}/system/
+    rm -f ${D}${sysconfdir}/openharmony/init/distributed_data.cfg
+}
 FILES:${PN}-distributeddatamgr = " \
     ${libdir}/libdistributeddata*${SOLIBS} \
     ${libdir}/libapp_distributeddata*${SOLIBS} \
@@ -820,6 +836,14 @@ RDEPENDS:${PN}-ptest += "${PN}-distributeddatamgr-ptest"
 
 # //base/account/os_account
 PACKAGES =+ "${PN}-os-account"
+SYSTEMD_PACKAGES += "${PN}-os-account"
+SYSTEMD_SERVICE:${PN}-os-account = "accountmgr.service"
+SRC_URI += "file://accountmgr.service"
+do_install:append() {
+    install -d ${D}/${systemd_unitdir}/system
+    install -m 644 ${WORKDIR}/accountmgr.service ${D}${systemd_unitdir}/system/
+    rm -f ${D}${sysconfdir}/openharmony/init/accountmgr.cfg
+}
 FILES:${PN}-os-account = " \
     ${libdir}/libaccount*${SOLIBS} \
     ${libdir}/module/account/*${SOLIBS} \
@@ -855,6 +879,14 @@ RDEPENDS:${PN} += "${PN}-security-dataclassification"
 
 # //foundation/distributedschedule/dmsfwk
 PACKAGES =+ "${PN}-dmsfwk"
+SYSTEMD_PACKAGES += "${PN}-dmsfwk"
+SYSTEMD_SERVICE:${PN}-dmsfwk = "distributedsched.service"
+SRC_URI += "file://distributedsched.service"
+do_install:append() {
+    install -d ${D}/${systemd_unitdir}/system
+    install -m 644 ${WORKDIR}/distributedsched.service ${D}${systemd_unitdir}/system/
+    rm -f ${D}${sysconfdir}/openharmony/init/distributedsched.cfg
+}
 FILES:${PN}-dmsfwk = " \
     ${libdir}/libdistributedschedsvr*${SOLIBS} \
     ${libdir}/libzuri*${SOLIBS} \
@@ -903,6 +935,14 @@ RDEPENDS:${PN}-ptest += "${PN}-security-permission-ptest"
 
 # //base/security/huks
 PACKAGES =+ "${PN}-security-huks"
+SYSTEMD_PACKAGES += "${PN}-security-huks"
+SYSTEMD_SERVICE:${PN}-security-huks = "huks.service"
+SRC_URI += "file://huks.service"
+do_install:append() {
+    install -d ${D}/${systemd_unitdir}/system
+    install -m 644 ${WORKDIR}/huks.service ${D}${systemd_unitdir}/system/
+    rm -f ${D}${sysconfdir}/openharmony/init/huks_service.cfg
+}
 FILES:${PN}-security-huks = " \
     ${libdir}/libhuks*${SOLIBS} \
     ${libdir}/openharmony/profile/huks_service.xml \
@@ -1023,6 +1063,14 @@ RDEPENDS:${PN} += "${PN}-peripheral-input"
 
 # //base/miscservices/time
 PACKAGES =+ "${PN}-timeservice"
+SYSTEMD_PACKAGES += "${PN}-timeservice"
+SYSTEMD_SERVICE:${PN}-timeservice = "time.service"
+SRC_URI += "file://time.service"
+do_install:append() {
+    install -d ${D}/${systemd_unitdir}/system
+    install -m 644 ${WORKDIR}/time.service ${D}${systemd_unitdir}/system/
+    rm -f ${D}${sysconfdir}/openharmony/init/timeservice.cfg
+}
 FILES:${PN}-timeservice = " \
     ${libdir}/libtime_service*${SOLIBS} \
     ${libdir}/module/libsystemtime*${SOLIBS} \
@@ -1169,6 +1217,14 @@ RDEPENDS:${PN} += "${PN}-ace-napi"
 
 # //base/miscservices/inputmethod
 PACKAGES =+ "${PN}-inputmethod"
+SYSTEMD_PACKAGES += "${PN}-inputmethod"
+SYSTEMD_SERVICE:${PN}-inputmethod = "inputmethod.service"
+SRC_URI += "file://inputmethod.service"
+do_install:append() {
+    install -d ${D}/${systemd_unitdir}/system
+    install -m 644 ${WORKDIR}/inputmethod.service ${D}${systemd_unitdir}/system/
+    rm -f ${D}${sysconfdir}/openharmony/init/inputmethodservice.cfg
+}
 FILES:${PN}-inputmethod = " \
     ${libdir}/libinputmethod_*${SOLIBS} \
     ${libdir}/module/libinputmethodengine*${SOLIBS} \
-- 
GitLab