From 0168b59ecc6d14f8e1fba665e029246bc4592385 Mon Sep 17 00:00:00 2001 From: tlbl Date: Fri, 22 Aug 2025 16:29:40 +0800 Subject: [PATCH] test sa Signed-off-by: tlbl --- BUILD.gn | 2 + services/5207.json | 19 +++ services/BUILD.gn | 5 + services/clouddiskservice/BUILD.gn | 117 ++++++++++++++++++ .../clouddiskservice/CloudDiskService.idl | 17 +++ .../include/ipc/cloud_disk_service.h | 56 +++++++++ .../src/ipc/cloud_disk_service.cpp | 93 ++++++++++++++ services/distributedfile.cfg | 9 ++ 8 files changed, 318 insertions(+) create mode 100644 services/5207.json create mode 100644 services/clouddiskservice/BUILD.gn create mode 100644 services/clouddiskservice/CloudDiskService.idl create mode 100644 services/clouddiskservice/include/ipc/cloud_disk_service.h create mode 100644 services/clouddiskservice/src/ipc/cloud_disk_service.cpp diff --git a/BUILD.gn b/BUILD.gn index e77869cad..e34086a73 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -16,6 +16,7 @@ import("//foundation/filemanagement/dfs_service/distributedfile.gni") group("services_target") { deps = [ + "${services_path}:clouddiskservice_sa_profile", "${services_path}:cloudsyncservice.para", "${services_path}:cloudsyncservice.para.dac", "${services_path}:distributed_file.para", @@ -24,6 +25,7 @@ group("services_target") { "${services_path}/clouddisk_database:clouddisk_database", "${services_path}/cloudfiledaemon:cloudfiledaemon", "${services_path}/cloudsyncservice:cloudsync_sa", + "${services_path}/clouddiskservice:clouddiskservice_sa", ] if (dfs_service_feature_enable_dist_file_daemon) { diff --git a/services/5207.json b/services/5207.json new file mode 100644 index 000000000..ecd254f9b --- /dev/null +++ b/services/5207.json @@ -0,0 +1,19 @@ +{ + "process": "clouddiskservice", + "systemability": [ + { + "name": 5207, + "libpath": "libclouddiskservice_sa.z.so", + "run-on-create": false, + "distributed": false, + "dump-level": 1, + "start-on-demand": { + "commonevent": [ + { + "name": "usual.event.SCREEN_OFF" + } + ] + } + } + ] +} \ No newline at end of file diff --git a/services/BUILD.gn b/services/BUILD.gn index 0eec280de..f3b113a9c 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -25,6 +25,11 @@ ohos_sa_profile("distributedfile_sa_profile") { part_name = "dfs_service" } +ohos_sa_profile("clouddiskservice_sa_profile") { + sources = [ "5207.json" ] + part_name = "dfs_service" +} + ohos_prebuilt_etc("distributedfile_etc") { source = "distributedfile.cfg" relative_install_dir = "init" diff --git a/services/clouddiskservice/BUILD.gn b/services/clouddiskservice/BUILD.gn new file mode 100644 index 000000000..9ccedf66a --- /dev/null +++ b/services/clouddiskservice/BUILD.gn @@ -0,0 +1,117 @@ +# Copyright (C) 2025 Huawei Device 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. + +import("//build/config/components/idl_tool/idl.gni") +import("//build/ohos.gni") +import("//foundation/filemanagement/dfs_service/distributedfile.gni") + +config("optimize-size") { + cflags = [ + "-fdata-sections", + "-ffunction-sections", + "-Oz", + ] + cflags_cc = [ + "-fvisibility-inlines-hidden", + "-Oz", + ] +} + +config("cloud_disk_service_public_config") { + include_dirs = [ "${target_gen_dir}" ] +} + +idl_gen_interface("cloud_disk_service") { + sources = [ + "ICloudDiskService.idl", + ] + sources_cpp = [] + sub_include = [] + configs = [] + innerapi_tags = [ "platformsdk" ] + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + log_domainid = "0xD003900" + log_tag = "CloudDiskService" + subsystem_name = "dfs_service" + part_name = "filemanagement" +} + +ohos_shared_library("clouddiskservice_sa") { + branch_protector_ret = "pac_ret" + configs = [ ":optimize-size" ] + public_configs = [ ":cloud_disk_service_public_config" ] + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + include_dirs = [ + "include", + "include/ipc", + ] + + sources = [ + # "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_common.cpp", + "src/ipc/cloud_disk_service.cpp", + ] + + output_values = get_target_outputs(":cloud_disk_service") + sources += filter_include(output_values, [ "*_stub.cpp" ]) + + defines = [ + "LOG_DOMAIN=0xD004308", + "LOG_TAG=\"CLOUDDISKSERVICE_SA\"", + ] + + deps = [ + ":cloud_disk_service", + "${utils_path}:libdistributedfiledentry", + "${utils_path}:libdistributedfileutils", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "app_file_service:sandbox_helper_native", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "dsoftbus:softbus_client", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "ipc:ipc_single", + "libfuse:libfuse", + "memmgr:memmgrclient", + "netmanager_base:net_conn_manager_if", + "os_account:os_account_innerkits", + "preferences:native_preferences", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + use_exceptions = true + part_name = "dfs_service" + subsystem_name = "filemanagement" +} diff --git a/services/clouddiskservice/CloudDiskService.idl b/services/clouddiskservice/CloudDiskService.idl new file mode 100644 index 000000000..59d97ae6e --- /dev/null +++ b/services/clouddiskservice/CloudDiskService.idl @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 Huawei Device 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. + */ + +interface OHOS.FileManagement.CloudDisk.ICloudDiskService { +} \ No newline at end of file diff --git a/services/clouddiskservice/include/ipc/cloud_disk_service.h b/services/clouddiskservice/include/ipc/cloud_disk_service.h new file mode 100644 index 000000000..13cba050c --- /dev/null +++ b/services/clouddiskservice/include/ipc/cloud_disk_service.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2025 Huawei Device 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 OHOS_FILEMGMT_CLOUD_DISK_SERVICE_H +#define OHOS_FILEMGMT_CLOUD_DISK_SERVICE_H + +#include +#include +#include + +#include "iremote_stub.h" +#include "nocopyable.h" +#include "refbase.h" +#include "system_ability.h" + +#include "cloud_disk_service_stub.h" +#include "icloud_disk_service.h" + +namespace OHOS::FileManagement::CloudDisk { +enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; +class CloudDiskService final : public SystemAbility, public CloudDiskServiceStub, protected NoCopyable { + DECLARE_SYSTEM_ABILITY(CloudDiskService); + +public: + explicit CloudDiskService(int32_t saID, bool runOnCreate = true); + virtual ~CloudDiskService() = default; + + void OnStart() override; + void OnStop() override; + ServiceRunningState QueryServiceState() const + { + return state_; + } +private: + CloudDiskService(); + ServiceRunningState state_ { ServiceRunningState::STATE_NOT_START }; + static sptr instance_; + static std::mutex instanceLock_; + bool registerToService_ { false }; + void PublishSA(); +}; +} // namespace OHOS::FileManagement::CloudDisk + +#endif // OHOS_FILEMGMT_CLOUD_DISK_SERVICE_H diff --git a/services/clouddiskservice/src/ipc/cloud_disk_service.cpp b/services/clouddiskservice/src/ipc/cloud_disk_service.cpp new file mode 100644 index 000000000..086c6e932 --- /dev/null +++ b/services/clouddiskservice/src/ipc/cloud_disk_service.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2023~2025 Huawei Device 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 "cloud_disk_service.h" + +#include +#include +#include +#include +#include +#include + +#include "dfs_error.h" +#include "ffrt_inner.h" +#include "iremote_object.h" +#include "parameters.h" +#include "system_ability_definition.h" +#include "utils_directory.h" +#include "utils_log.h" +#ifdef HICOLLIE_ENABLE +#include "xcollie_helper.h" +#endif + +namespace OHOS { +namespace FileManagement { +namespace CloudDisk { +using namespace std; +using namespace OHOS; + +namespace { +} +REGISTER_SYSTEM_ABILITY_BY_ID(CloudDiskService, 5207, true); + +CloudDiskService::CloudDiskService(int32_t saID, bool runOnCreate) : SystemAbility(saID, runOnCreate) +{ +} + +void CloudDiskService::PublishSA() +{ + LOGI("Begin to init"); + if (!registerToService_) { + bool ret = SystemAbility::Publish(this); + if (!ret) { + throw runtime_error("Failed to publish the daemon"); + } + registerToService_ = true; + } + LOGI("Init finished successfully"); +} + +void CloudDiskService::OnStart() +{ + LOGI("Begin to start service"); + if (state_ == ServiceRunningState::STATE_RUNNING) { + LOGI("Daemon has already started"); + return; + } + + try { + PublishSA(); + mode_t mode = 002; + umask(mode); + } catch (const exception &e) { + LOGE("%{public}s", e.what()); + } + + state_ = ServiceRunningState::STATE_RUNNING; + + LOGI("Start service successfully"); +} + +void CloudDiskService::OnStop() +{ + LOGI("Begin to stop"); + state_ = ServiceRunningState::STATE_NOT_START; + registerToService_ = false; + LOGI("Stop finished successfully"); +} +} // namespace CloudFile +} // namespace FileManagement +} // namespace OHOS diff --git a/services/distributedfile.cfg b/services/distributedfile.cfg index 4464a8acb..7003cdaa4 100644 --- a/services/distributedfile.cfg +++ b/services/distributedfile.cfg @@ -64,5 +64,14 @@ "ohos.permission.WRITE_ALL_PHOTO", "ohos.permission.MEMOSPACE_SYNC" ] + }, { + "name": "clouddiskservice", + "path": ["/system/bin/sa_main", "/system/profile/clouddiskservice.json"], + "uid": "1009", + "gid": ["dfs", "user_data_rw", "ddms", "dfs_share", "readproc"], + "sandbox": 0, + "secon": "u:r:cloudfiledaemon:s0", + "apl": "system_basic", + "ondemand": true }] } \ No newline at end of file -- Gitee