From 827709dec0cc4806518e81941e8d7bd7cdb87293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=98=8A=E5=A4=A9?= Date: Sat, 30 Aug 2025 19:32:43 +0800 Subject: [PATCH] all disk code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘昊天 --- BUILD.gn | 13 + bundle.json | 17 + distributedfile.gni | 1 + .../cloud_disk_service_callback_client.h | 48 +++ .../cloud_disk_service_callback_stub.h | 39 ++ .../include/cloud_disk_service_manager_impl.h | 50 +++ .../include/service_proxy.h | 45 +++ .../src/cloud_disk_common.cpp | 242 +++++++++++++ .../cloud_disk_service_callback_client.cpp | 19 + .../src/cloud_disk_service_callback_stub.cpp | 68 ++++ .../src/cloud_disk_service_manager.cpp | 24 ++ .../src/cloud_disk_service_manager_impl.cpp | 209 +++++++++++ .../src/cloud_disk_service_task_manager.cpp | 152 ++++++++ .../src/service_proxy.cpp | 114 ++++++ .../clouddiskservice_kit_inner/BUILD.gn | 104 ++++++ .../cloud_disk_common.h | 97 +++++ .../cloud_disk_service_callback.h | 30 ++ .../cloud_disk_service_manager.h | 39 ++ .../cloud_disk_service_task_manager.h | 71 ++++ .../i_cloud_disk_service_callback.h | 36 ++ .../svc_death_recipient.h | 41 +++ services/5207.json | 12 + services/BUILD.gn | 12 + services/clouddiskservice.cfg | 12 + services/clouddiskservice/BUILD.gn | 124 +++++++ .../clouddiskservice/ICloudDiskService.idl | 26 ++ .../include/ipc/cloud_disk_service.h | 69 ++++ .../ipc/cloud_disk_service_callback_manager.h | 37 ++ .../ipc/cloud_disk_service_callback_proxy.h | 36 ++ .../include/monitor/disk_monitor.h | 66 ++++ .../include/monitor/disk_notifier.h | 39 ++ .../include/monitor/disk_types.h | 69 ++++ .../src/ipc/cloud_disk_service.cpp | 269 ++++++++++++++ .../cloud_disk_service_callback_manager.cpp | 45 +++ .../ipc/cloud_disk_service_callback_proxy.cpp | 97 +++++ .../src/monitor/disk_monitor.cpp | 327 +++++++++++++++++ .../src/monitor/disk_notifier.cpp | 75 ++++ .../src/seccomp_policy/BUILD.gn | 15 + .../clouddiskservice.seccomp.policy | 341 ++++++++++++++++++ .../system/include/dfsu_access_token_helper.h | 1 + 40 files changed, 3131 insertions(+) create mode 100644 frameworks/native/clouddiskservice_kit_inner/include/cloud_disk_service_callback_client.h create mode 100644 frameworks/native/clouddiskservice_kit_inner/include/cloud_disk_service_callback_stub.h create mode 100644 frameworks/native/clouddiskservice_kit_inner/include/cloud_disk_service_manager_impl.h create mode 100644 frameworks/native/clouddiskservice_kit_inner/include/service_proxy.h create mode 100644 frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_common.cpp create mode 100644 frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_callback_client.cpp create mode 100644 frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_callback_stub.cpp create mode 100644 frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_manager.cpp create mode 100644 frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_manager_impl.cpp create mode 100644 frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_task_manager.cpp create mode 100644 frameworks/native/clouddiskservice_kit_inner/src/service_proxy.cpp create mode 100644 interfaces/inner_api/native/clouddiskservice_kit_inner/BUILD.gn create mode 100644 interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_common.h create mode 100644 interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_service_callback.h create mode 100644 interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_service_manager.h create mode 100644 interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_service_task_manager.h create mode 100644 interfaces/inner_api/native/clouddiskservice_kit_inner/i_cloud_disk_service_callback.h create mode 100644 interfaces/inner_api/native/clouddiskservice_kit_inner/svc_death_recipient.h create mode 100644 services/5207.json create mode 100644 services/clouddiskservice.cfg create mode 100644 services/clouddiskservice/BUILD.gn create mode 100644 services/clouddiskservice/ICloudDiskService.idl create mode 100644 services/clouddiskservice/include/ipc/cloud_disk_service.h create mode 100644 services/clouddiskservice/include/ipc/cloud_disk_service_callback_manager.h create mode 100644 services/clouddiskservice/include/ipc/cloud_disk_service_callback_proxy.h create mode 100644 services/clouddiskservice/include/monitor/disk_monitor.h create mode 100644 services/clouddiskservice/include/monitor/disk_notifier.h create mode 100644 services/clouddiskservice/include/monitor/disk_types.h create mode 100644 services/clouddiskservice/src/ipc/cloud_disk_service.cpp create mode 100644 services/clouddiskservice/src/ipc/cloud_disk_service_callback_manager.cpp create mode 100644 services/clouddiskservice/src/ipc/cloud_disk_service_callback_proxy.cpp create mode 100644 services/clouddiskservice/src/monitor/disk_monitor.cpp create mode 100644 services/clouddiskservice/src/monitor/disk_notifier.cpp create mode 100644 services/clouddiskservice/src/seccomp_policy/BUILD.gn create mode 100644 services/clouddiskservice/src/seccomp_policy/clouddiskservice.seccomp.policy diff --git a/BUILD.gn b/BUILD.gn index e77869cad..855dcdb21 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -33,6 +33,14 @@ group("services_target") { if (dfs_service_feature_enable_cloud_adapter) { deps += [ "${services_path}:cloudfiledaemon_etc" ] } + if (dfs_service_feature_enable_cloud_disk) { + deps += [ + "${services_path}:clouddiskservice_sa_profile", + "${services_path}/clouddiskservice:clouddiskservice_sa", + "${services_path}:clouddiskservice_etc", + "${services_path}/clouddiskservice/src/seccomp_policy:disk_monitor_seccomp_filter", + ] + } } group("cloudsync_kit_inner_target") { @@ -50,6 +58,11 @@ group("cloud_file_kit_inner_target") { deps = [ "interfaces/inner_api/native/cloud_file_kit_inner:cloudfile_kit" ] } +group("clouddiskservice_kit_inner_target") { + deps = + [ "interfaces/inner_api/native/clouddiskservice_kit_inner:clouddiskservice_kit_inner" ] +} + group("cloudsync_asset_kit_inner_target") { deps = [ "interfaces/inner_api/native/cloudsync_kit_inner:cloudsync_asset_kit_inner", diff --git a/bundle.json b/bundle.json index 5460115ae..591987158 100644 --- a/bundle.json +++ b/bundle.json @@ -20,6 +20,7 @@ ], "features": [ "dfs_service_feature_enable_cloud_adapter", + "dfs_service_feature_enable_cloud_disk", "dfs_service_feature_enable_dist_file_daemon" ], "adapted_system_type": [ @@ -71,6 +72,7 @@ "thermal_manager", "os_account", "power_manager", + "user_file_service", "libfuse", "zlib" ], @@ -82,6 +84,7 @@ "fwk_group": [], "service_group": [ "//foundation/filemanagement/dfs_service:services_target", + "//foundation/filemanagement/dfs_service:clouddiskservice_kit_inner_target", "//foundation/filemanagement/dfs_service:cloudsync_kit_inner_target", "//foundation/filemanagement/dfs_service:cloud_daemon_kit_inner_target", "//foundation/filemanagement/dfs_service:cloud_file_kit_inner_target", @@ -108,6 +111,20 @@ "header_base": "//foundation/filemanagement/dfs_service/interfaces/inner_api/native/cloudsync_kit_inner" } }, + { + "name": "//foundation/filemanagement/dfs_service/interfaces/inner_api/native/clouddiskservice_kit_inner:clouddiskservice_kit_inner", + "header": { + "header_files": [ + "cloud_disk_common.h", + "cloud_disk_service_callback.h", + "cloud_disk_service_manager.h", + "cloud_disk_service_task_manager.h", + "i_cloud_disk_service_callback.h", + "svc_death_recipient.h" + ], + "header_base": "//foundation/filemanagement/dfs_service/interfaces/inner_api/native/clouddiskservice_kit_inner" + } + }, { "name": "//foundation/filemanagement/dfs_service/interfaces/inner_api/native/cloudsync_kit_inner:cloudsync_asset_kit_inner", "header": { diff --git a/distributedfile.gni b/distributedfile.gni index 2e8d8a0c1..3dafabb3b 100644 --- a/distributedfile.gni +++ b/distributedfile.gni @@ -37,6 +37,7 @@ declare_args() { cloudsync_service_power = false } dfs_service_feature_enable_cloud_adapter = false + dfs_service_feature_enable_cloud_disk = true dfs_service_feature_enable_dist_file_daemon = true if (defined(global_parts_info) && diff --git a/frameworks/native/clouddiskservice_kit_inner/include/cloud_disk_service_callback_client.h b/frameworks/native/clouddiskservice_kit_inner/include/cloud_disk_service_callback_client.h new file mode 100644 index 000000000..52536415b --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/include/cloud_disk_service_callback_client.h @@ -0,0 +1,48 @@ +/* + * 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_CALLBACK_CLIENT_H +#define OHOS_FILEMGMT_CLOUD_DISK_SERVICE_CALLBACK_CLIENT_H + +#include "cloud_disk_service_callback.h" +#include "cloud_disk_service_callback_stub.h" +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudDiskService { +class CloudDiskServiceCallbackClient final : public CloudDiskServiceCallbackStub { +public: + explicit CloudDiskServiceCallbackClient(const std::shared_ptr &callback) + :callback_(callback) {} + + void OnChangeData(std::vector& changeData) override { + if (callback_ == nullptr) { + LOGE("callback_ is nullptr"); + return; + } + callback_->OnChangeData(changeData); + } +private: + std::shared_ptr callback_{ nullptr }; +}; + +class CloudDiskServiceCallbackImpl final : public CloudDiskServiceCallback { +public: + void OnChangeData(std::vector& changeData) override { + LOGE("start in client"); + } +}; +} // namespace OHOS::FileManagement::CloudDiskService + +#endif // OHOS_FILEMGMT_CLOUD_DISK_SERVICE_CALLBACK_CLIENT_H \ No newline at end of file diff --git a/frameworks/native/clouddiskservice_kit_inner/include/cloud_disk_service_callback_stub.h b/frameworks/native/clouddiskservice_kit_inner/include/cloud_disk_service_callback_stub.h new file mode 100644 index 000000000..452e0013d --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/include/cloud_disk_service_callback_stub.h @@ -0,0 +1,39 @@ +/* +* 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_CALLBACK_STUB_H +#define OHOS_FILEMGMT_CLOUD_DISK_SERVICE_CALLBACK_STUB_H + +#include + +#include "i_cloud_disk_service_callback.h" +#include "iremote_stub.h" + +namespace OHOS::FileManagement::CloudDiskService { +using ServiceInterface = std::function; +class CloudDiskServiceCallbackStub : public IRemoteStub { +public: + CloudDiskServiceCallbackStub(); + virtual ~CloudDiskServiceCallbackStub() = default; + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + std::map opToInterfaceMap_; + + int32_t HandleOnChangeData(MessageParcel &data, MessageParcel &reply); +}; +} // namespace OHOS::FileManagement::CloudDiskService + +#endif // OHOS_FILEMGMT_CLOUD_DISK_SERVICE_CALLBACK_STUB_H \ No newline at end of file diff --git a/frameworks/native/clouddiskservice_kit_inner/include/cloud_disk_service_manager_impl.h b/frameworks/native/clouddiskservice_kit_inner/include/cloud_disk_service_manager_impl.h new file mode 100644 index 000000000..71aa69d25 --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/include/cloud_disk_service_manager_impl.h @@ -0,0 +1,50 @@ +/* + * 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_MANAGER_IMPL_H +#define OHOS_FILEMGMT_CLOUD_DISK_SERVICE_MANAGER_IMPL_H + +#include + +#include "nocopyable.h" + +#include "cloud_disk_service_manager.h" +#include "cloud_disk_service_callback_client.h" +#include "svc_death_recipient.h" + +namespace OHOS::FileManagement::CloudDiskService { +class CloudDiskServiceManagerImpl final : public CloudDiskServiceManager, public NoCopyable { +public: + static CloudDiskServiceManagerImpl &GetInstance(); + + int32_t RegisterSyncFolderChanges(const std::string& uri, + const std::shared_ptr& callback, std::string& syncFolderIndex) override; + int32_t UnregisterSyncFolderChanges(const std::string& uri) override; + int32_t GetSyncFolderChanges(const std::string &uri, uint64_t count, uint64_t startUSN, ChangesResult& changesResult) override; + int32_t SetFileSyncStates(const std::string& uri, const std::vector& fileSyncStates, std::vector& failedList) override; + int32_t GetFileSyncStates(const std::string& uri, const std::vector& uris, std::vector& resultList) override; + int32_t RegisterSyncFolder(const int32_t& userId, const std::string& bundleName, const std::string path) override; + int32_t UnregisterSyncFolder(const int32_t& userId, const std::string& bundleName, const std::string path) override; + +private: + void SetDeathRecipient(const sptr &remoteObject); + std::shared_ptr callback_; + sptr deathRecipient_; + std::mutex callbackMutex_; + std::atomic_flag isFirstCall_{false}; +}; +} // namespace OHOS::FileManagement::CloudDiskService + +#endif // OHOS_FILEMGMT_CLOUD_DISK_SERVICE_MANAGER_IMPL_H diff --git a/frameworks/native/clouddiskservice_kit_inner/include/service_proxy.h b/frameworks/native/clouddiskservice_kit_inner/include/service_proxy.h new file mode 100644 index 000000000..23b900812 --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/include/service_proxy.h @@ -0,0 +1,45 @@ +/* + * 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_SERVICE_PROXY_H +#define OHOS_FILEMGMT_SERVICE_PROXY_H + +#include "icloud_disk_service.h" +#include "iremote_proxy.h" +#include "system_ability_load_callback_stub.h" + +namespace OHOS::FileManagement::CloudDiskService { +class ServiceProxy : public IRemoteProxy { +public: + static sptr GetInstance(); + static void InvaildInstance(); + + // class CloudDiskServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { + // public: + // void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const sptr &remoteObject) override; + // void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; + + // std::condition_variable proxyConVar_; + // std::atomic isLoadSuccess_{false}; + // }; + +private: + // static inline std::mutex proxyMutex_; + static inline std::mutex instanceMutex_; + static inline sptr serviceProxy_; +}; +} // namespace OHOS::FileManagement::CloudDiskService + +#endif // OHOS_FILEMGMT_SERVICE_PROXY_H diff --git a/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_common.cpp b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_common.cpp new file mode 100644 index 000000000..b136aa740 --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_common.cpp @@ -0,0 +1,242 @@ +/* + * 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. + */ + +#include "cloud_disk_common.h" + +#include + +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudDiskService { + +CloudDiskCommon &CloudDiskCommon::GetInstance() +{ + static CloudDiskCommon instance; + return instance; +} + + +bool FileSyncState::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteString(uri)) { + LOGE("failed to write uri"); + return false; + } + + if (!parcel.WriteInt32(static_cast(syncState))) { + LOGE("failed to write syncState"); + return false; + } + + return true; +} + +FileSyncState *FileSyncState::Unmarshalling(Parcel &parcel) +{ + FileSyncState *info = new (std::nothrow) FileSyncState(); + if ((info != nullptr) && (!info->ReadFromParcel(parcel))) { + LOGW("read from parcel failed"); + delete info; + info = nullptr; + } + return info; +} + +bool FileSyncState::ReadFromParcel(Parcel &parcel) +{ + if (!parcel.ReadString(uri)) { + LOGE("failed to write uri"); + return false; + } + + int32_t readState = 0; + if (!parcel.ReadInt32(readState)) { + LOGE("failed to write syncState"); + return false; + } + syncState = static_cast(readState); + + return true; +} + + +bool ChangeData::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteUint64(updateSequenceNumber)) { + LOGE("failed to write updateSequenceNumber"); + return false; + } + + if (!parcel.WriteString(fileId)) { + LOGE("failed to write fileId"); + return false; + } + + if (!parcel.WriteString(parentFileId)) { + LOGE("failed to write parentFileId"); + return false; + } + + if (!parcel.WriteString(syncFolderIndex)) { + LOGE("failed to write syncFolderIndex"); + return false; + } + + if (!parcel.WriteString(relativePath)) { + LOGE("failed to write relativePath"); + return false; + } + + if (!parcel.WriteInt32(static_cast(operationType))) { + LOGE("failed to write operationType"); + return false; + } + + if (!parcel.WriteUint64(size)) { + LOGE("failed to write size"); + return false; + } + + if (!parcel.WriteUint64(mtime)) { + LOGE("failed to write mtime"); + return false; + } + + if (!parcel.WriteUint64(timeStamp)) { + LOGE("failed to write timeStamp"); + return false; + } + + return true; +} + +ChangeData *ChangeData::Unmarshalling(Parcel &parcel) +{ + ChangeData *info = new (std::nothrow) ChangeData(); + if ((info != nullptr) && (!info->ReadFromParcel(parcel))) { + LOGW("read from parcel failed"); + delete info; + info = nullptr; + } + return info; +} + +bool ChangeData::ReadFromParcel(Parcel &parcel) +{ + if (!parcel.ReadUint64(updateSequenceNumber)) { + LOGE("failed to read updateSequenceNumber"); + return false; + } + + if (!parcel.ReadString(fileId)) { + LOGE("failed to read fileId"); + return false; + } + + if (!parcel.ReadString(parentFileId)) { + LOGE("failed to read parentFileId"); + return false; + } + + if (!parcel.ReadString(syncFolderIndex)) { + LOGE("failed to read syncFolderIndex"); + return false; + } + + if (!parcel.ReadString(relativePath)) { + LOGE("failed to read relativePath"); + return false; + } + + int32_t readType = 0; + if (!parcel.ReadInt32(readType)) { + LOGE("failed to write operationType"); + return false; + } + operationType = static_cast(readType); + + if (!parcel.ReadUint64(size)) { + LOGE("failed to read size"); + return false; + } + + if (!parcel.ReadUint64(mtime)) { + LOGE("failed to read mtime"); + return false; + } + + if (!parcel.ReadUint64(timeStamp)) { + LOGE("failed to read timeStamp"); + return false; + } + + return true; +} + +bool ChangesResult::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteUint64(nextUSN)) { + LOGE("failed to write uri"); + return false; + } + + if (!parcel.WriteInt32(static_cast(changesData.size()))) { + LOGE("failed to write uri"); + return false; + } + + for(auto& item : changesData) { + item.Marshalling(parcel); + } + + return true; +} + +ChangesResult *ChangesResult::Unmarshalling(Parcel &parcel) +{ + ChangesResult *info = new (std::nothrow) ChangesResult(); + if ((info != nullptr) && (!info->ReadFromParcel(parcel))) { + LOGW("read from parcel failed"); + delete info; + info = nullptr; + } + return info; +} + +bool ChangesResult::ReadFromParcel(Parcel &parcel) +{ + if (!parcel.ReadUint64(nextUSN)) { + LOGE("failed to read uri"); + return false; + } + + int32_t size = 0; + if (!parcel.ReadInt32(size)) { + LOGE("failed to read uri"); + return false; + } + for(int32_t i = 0; i < size; ++i) { + ChangeData changeData; + changeData.ReadFromParcel(parcel); + changesData.push_back(changeData); + } + // for(auto& item : changesData) { + // item.ReadFromParcel(parcel); + // } + + return true; +} + +} // namespace OHOS::FileManagement::CloudDiskService diff --git a/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_callback_client.cpp b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_callback_client.cpp new file mode 100644 index 000000000..148c3423c --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_callback_client.cpp @@ -0,0 +1,19 @@ +/* + * 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. + */ + +#include "cloud_disk_service_callback_client.h" + +namespace OHOS::FileManagement::CloudDiskService { +} // namespace OHOS::FileManagement::CloudDiskService diff --git a/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_callback_stub.cpp b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_callback_stub.cpp new file mode 100644 index 000000000..bef26f978 --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_callback_stub.cpp @@ -0,0 +1,68 @@ +/* + * 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. + */ + +#include "cloud_disk_service_callback_stub.h" +#include "dfs_error.h" +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudDiskService { +using namespace std; + +CloudDiskServiceCallbackStub::CloudDiskServiceCallbackStub() +{ + opToInterfaceMap_[SERVICE_CMD_ON_PROCESS] = [this](MessageParcel &data, MessageParcel &reply) { + return this->HandleOnChangeData(data, reply); + }; +} + +int32_t CloudDiskServiceCallbackStub::OnRemoteRequest(uint32_t code, + MessageParcel &data, + MessageParcel &reply, + MessageOption &option) +{ + if (data.ReadInterfaceToken() != GetDescriptor()) { + return E_SERVICE_DESCRIPTOR_IS_EMPTY; + } + auto interfaceIndex = opToInterfaceMap_.find(code); + if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) { + LOGE("Cannot response request %d: unknown tranction", code); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + auto memberFunc = interfaceIndex->second; + return memberFunc(data, reply); +} + +int32_t CloudDiskServiceCallbackStub::HandleOnChangeData(MessageParcel &data, MessageParcel &reply) +{ + // sptr> progress = data.ReadInt32>(); + std::vector changesData; + auto size = data.ReadInt32(); + if (size > static_cast(VECTOR_MAX_SIZE)) { + return ERR_INVALID_DATA; + } + for (int i = 0; i < size; ++i) { + std::unique_ptr value(data.ReadParcelable()); + if(!value) { + LOGE("object of ChangeData is nullptr"); + return E_INVAL_ARG; + } + changesData.push_back(*value); + } + + OnChangeData(changesData); + LOGI("OnChangeData"); + return E_OK; +} +} // namespace OHOS::FileManagement::CloudDiskService \ No newline at end of file diff --git a/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_manager.cpp b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_manager.cpp new file mode 100644 index 000000000..808ff75d8 --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_manager.cpp @@ -0,0 +1,24 @@ +/* + * 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. + */ + +#include "cloud_disk_service_manager_impl.h" + +namespace OHOS::FileManagement::CloudDiskService { +using namespace std; +CloudDiskServiceManager &CloudDiskServiceManager::GetInstance() +{ + return CloudDiskServiceManagerImpl::GetInstance(); +} +} // namespace OHOS::FileManagement::CloudDiskService \ No newline at end of file diff --git a/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_manager_impl.cpp b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_manager_impl.cpp new file mode 100644 index 000000000..a96e932d8 --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_manager_impl.cpp @@ -0,0 +1,209 @@ +/* + * 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. + */ + +#include "cloud_disk_service_manager_impl.h" + +#include "dfsu_access_token_helper.h" +#include "cloud_disk_service_callback_client.h" +#include "dfs_error.h" +#include "iservice_registry.h" +#include "service_proxy.h" +#include "system_ability_definition.h" +#include "utils_directory.h" +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudDiskService { +using namespace std; +CloudDiskServiceManagerImpl &CloudDiskServiceManagerImpl::GetInstance() +{ + static CloudDiskServiceManagerImpl instance; + return instance; +} + +int32_t CloudDiskServiceManagerImpl::RegisterSyncFolderChanges(const std::string& uri, + const std::shared_ptr& callback, std::string& syncFolderIndex) +{ +#ifdef SUPPORT_CLOUD_DISK_SERVICE + if (!callback) { + LOGE("callback is null"); + return E_INVAL_ARG; + } + auto serviceProxy = ServiceProxy::GetInstance(); + if (!serviceProxy) { + LOGE("proxy is null"); + return E_SA_LOAD_FAILED; + } + auto ret = serviceProxy->RegisterSyncFolderChangesInner(uri, + sptr(new (std::nothrow) CloudDiskServiceCallbackClient(callback)), syncFolderIndex); + { + unique_lock lock(callbackMutex_); + callback_ = callback; + } + SetDeathRecipient(serviceProxy->AsObject()); + LOGI("RegisterSyncFolderChanges ret %{public}d", ret); + return ret; +#else + return 0; +#endif +} + +int32_t CloudDiskServiceManagerImpl::UnregisterSyncFolderChanges(const std::string& uri) +{ +#ifdef SUPPORT_CLOUD_DISK_SERVICE + auto serviceProxy = ServiceProxy::GetInstance(); + if (!serviceProxy) { + LOGE("proxy is null"); + return E_SA_LOAD_FAILED; + } + + auto ret = serviceProxy->UnregisterSyncFolderChangesInner(uri); + if (!ret) { + { + unique_lock lock(callbackMutex_); + callback_ = nullptr; + } + } + SetDeathRecipient(serviceProxy->AsObject()); + LOGI("UnregisterSyncFolderChanges ret %{public}d", ret); + return ret; +#else + return 0; +#endif +} + +int32_t CloudDiskServiceManagerImpl::GetSyncFolderChanges(const std::string &uri, uint64_t count, uint64_t startUSN, ChangesResult& changesResult) +{ +#ifdef SUPPORT_CLOUD_DISK_SERVICE + auto serviceProxy = ServiceProxy::GetInstance(); + if (!serviceProxy) { + LOGE("proxy is null"); + return E_SA_LOAD_FAILED; + } + + auto ret = serviceProxy->GetSyncFolderChangesInner(uri, count, startUSN, changesResult); + if (!ret) { + { + unique_lock lock(callbackMutex_); + callback_ = nullptr; + } + } + SetDeathRecipient(serviceProxy->AsObject()); + LOGI("GetSyncFolderChangesInner ret %{public}d", ret); + return ret; +#else + return 0; +#endif +} + +int32_t CloudDiskServiceManagerImpl::SetFileSyncStates(const std::string& uri, const std::vector& fileSyncStates, std::vector& failedList) +{ +#ifdef SUPPORT_CLOUD_DISK_SERVICE + LOGI("start SetXattr in impl"); + + auto serviceProxy = ServiceProxy::GetInstance(); + if (!serviceProxy) { + LOGE("proxy is null"); + return E_SA_LOAD_FAILED; + } + + auto ret = serviceProxy->SetFileSyncStatesInner(uri, fileSyncStates, failedList); + if (!ret) { + { + unique_lock lock(callbackMutex_); + callback_ = nullptr; + } + } + SetDeathRecipient(serviceProxy->AsObject()); + LOGI("SetFileSyncState, ret %{public}d", ret); + return ret; +#else + return 0; +#endif +} + +int32_t CloudDiskServiceManagerImpl::GetFileSyncStates(const std::string& uri, const std::vector& uris, std::vector& resultList) +{ +#ifdef SUPPORT_CLOUD_DISK_SERVICE + LOGI("start GetXattr in impl"); + + auto serviceProxy = ServiceProxy::GetInstance(); + if (!serviceProxy) { + LOGE("proxy is null"); + return E_SA_LOAD_FAILED; + } + + auto ret = serviceProxy->GetFileSyncStatesInner(uri, uris, resultList); + if (!ret) { + { + unique_lock lock(callbackMutex_); + callback_ = nullptr; + } + } + SetDeathRecipient(serviceProxy->AsObject()); + LOGI("GetFileSyncState, ret %{public}d", ret); + return ret; +#else + return 0; +#endif +} + +int32_t CloudDiskServiceManagerImpl::RegisterSyncFolder(const int32_t& userId, const std::string& bundleName, const std::string path) +{ +#ifdef SUPPORT_CLOUD_DISK_SERVICE + // RETURN_ON_ERR(CheckPermissions(PERM_CLOUD_DISK_SERVICE, true)); + LOGI("start RegisterSyncFolder in impl"); + int ret = 0; + + LOGI("RegisterSyncFolder, ret %{public}d", ret); + return ret; +#else + return 0; +#endif +} + +int32_t CloudDiskServiceManagerImpl::UnregisterSyncFolder(const int32_t& userId, const std::string& bundleName, const std::string path) +{ +#ifdef SUPPORT_CLOUD_DISK_SERVICE + // RETURN_ON_ERR(CheckPermissions(PERM_CLOUD_DISK_SERVICE, true)); + LOGI("start UnregisterSyncFolder in impl"); + int ret = 0; + + LOGI("UnregisterSyncFolder, ret %{public}d", ret); + return ret; +#else + return 0; +#endif +} + +void CloudDiskServiceManagerImpl::SetDeathRecipient(const sptr &remoteObject) +{ + if (!isFirstCall_.test_and_set()) { + auto deathCallback = [this](const wptr &obj) { + LOGE("service died."); + ServiceProxy::InvaildInstance(); + if (callback_) { + callback_->OnDeathRecipient(); + } + isFirstCall_.clear(); + }; + deathRecipient_ = sptr(new SvcDeathRecipient(deathCallback)); + if (!remoteObject->AddDeathRecipient(deathRecipient_)) { + LOGE("add death recipient failed"); + isFirstCall_.clear(); + } + } +} + +} // namespace OHOS::FileManagement::CloudDiskService diff --git a/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_task_manager.cpp b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_task_manager.cpp new file mode 100644 index 000000000..145c3a0b0 --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_task_manager.cpp @@ -0,0 +1,152 @@ +/* + * 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. + */ + +#include "cloud_disk_service_task_manager.h" + +#include "iservice_registry.h" +#include "mem_mgr_client.h" +#include "parameters.h" +#include "system_ability_definition.h" +#include "utils_log.h" + +namespace OHOS { +namespace FileManagement { +namespace CloudDiskService { +using namespace std; + +const int32_t DELAY_TIME = 90000; // ms +const int32_t SYSTEM_LOAD_DELAY_TIME = 600000; // ms + +CloudDiskServiceTaskManager &CloudDiskServiceTaskManager::GetInstance() +{ + static CloudDiskServiceTaskManager instance; + return instance; +} + +CloudDiskServiceTaskManager::CloudDiskServiceTaskManager() : queue_("unloadTask") +{ +} + +void CloudDiskServiceTaskManager::StartTask(TaskKey key, TaskType task) +{ + CancelUnloadTask(); + std::lock_guard lock(taskMapsMutex_); + if (criticalStatus_ == false) { + int32_t ret = Memory::MemMgrClient::GetInstance().SetCritical(getpid(), + true, FILEMANAGEMENT_CLOUD_DISK_SERVICE_SA_ID); + if (ret == ERR_OK) { + criticalStatus_ = true; + } + } + auto iterator = taskMaps_.find(key); + if (iterator == taskMaps_.end()) { + taskMaps_[key] = static_cast(task); + return; + } + auto taskState = iterator->second | static_cast(task); + taskMaps_[key] = taskState; +} + +void CloudDiskServiceTaskManager::CompleteTask(TaskKey key, TaskType task) +{ + std::lock_guard lock(taskMapsMutex_); + auto iterator = taskMaps_.find(key); + if (iterator == taskMaps_.end()) { + LOGE("task is not started"); + } else { + taskMaps_[key] = iterator->second & ~static_cast(task); + if (taskMaps_[key] == 0) { + LOGI("start erase"); + taskMaps_.erase(key); + } + } + // if (taskMaps_.empty()) { + // DelayUnloadTask(true); + // } +} + +void CloudDiskServiceTaskManager::StartTask() +{ + std::lock_guard lock(taskMapsMutex_); + // if (taskMaps_.empty()) { + // DelayUnloadTask(false); + // } +} + +bool CloudDiskServiceTaskManager::HasTask(TaskKey key, TaskType task) +{ + std::lock_guard lock(taskMapsMutex_); + auto iterator = taskMaps_.find(key); + if (iterator != taskMaps_.end()) { + if (taskMaps_[key] & static_cast(task)) { + return true; + } + } + return false; +} + + +void CloudDiskServiceTaskManager::CancelUnloadTask() +{ + std::lock_guard lock(unloadTaskMutex_); + if (unloadTaskHandle_ == nullptr) { + return; + } + LOGD("cancel unload task"); + queue_.cancel(unloadTaskHandle_); + unloadTaskHandle_ = nullptr; +} + +// void CloudDiskServiceTaskManager::DelayUnloadTask(bool needSetCritical) +// { +// LOGI("delay unload task begin"); +// auto delayTime = DELAY_TIME; + +// if (needSetCritical == true && criticalStatus_ == true) { +// int32_t ret = Memory::MemMgrClient::GetInstance().SetCritical(getpid(), +// false, FILEMANAGEMENT_CLOUD_DISK_SERVICE_SA_ID); +// if (ret == ERR_OK) { +// criticalStatus_ = false; +// } +// } +// auto task = [this]() { +// LOGI("do unload task"); +// { +// std::lock_guard lock(unloadTaskMutex_); +// unloadTaskHandle_ = nullptr; +// } + +// auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); +// if (samgrProxy == nullptr) { +// LOGE("get samgr failed"); +// return; +// } +// // system::SetParameter(CLOUD_FILE_SERVICE_SA_STATUS_FLAG, CLOUD_FILE_SERVICE_SA_END); +// int32_t ret = samgrProxy->UnloadSystemAbility(FILEMANAGEMENT_CLOUD_DISK_SERVICE_SA_ID); +// if (ret != ERR_OK) { +// LOGE("remove system ability failed"); +// return; +// } +// }; + +// CancelUnloadTask(); +// std::lock_guard lock(unloadTaskMutex_); +// std::chrono::milliseconds ms(delayTime); +// auto us = std::chrono::duration_cast(ms); +// unloadTaskHandle_ = queue_.submit_h(task, ffrt::task_attr().delay(us.count())); +// } +} // namespace CloudDiskService +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/clouddiskservice_kit_inner/src/service_proxy.cpp b/frameworks/native/clouddiskservice_kit_inner/src/service_proxy.cpp new file mode 100644 index 000000000..9fa81d389 --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/src/service_proxy.cpp @@ -0,0 +1,114 @@ +/* + * 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. + */ +#include "service_proxy.h" + +#include + +#include "cloud_disk_service_proxy.h" +#include "dfs_error.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudDiskService { +using namespace std; + +// constexpr int LOAD_SA_TIMEOUT_MS = 2000; + +sptr ServiceProxy::GetInstance() +{ + LOGD("getinstance"); + unique_lock lock(instanceMutex_); + if (serviceProxy_ != nullptr) { + if (serviceProxy_->AsObject() != nullptr && !serviceProxy_->AsObject()->IsObjectDead()) { + return serviceProxy_; + } + } + + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + LOGE("Samgr is nullptr"); + return nullptr; + } + + auto object = samgr->CheckSystemAbility(FILEMANAGEMENT_CLOUD_DISK_SERVICE_SA_ID); + if (object == nullptr) { + LOGE("CloudDiskService::Connect object == nullptr"); + return nullptr; + } + + serviceProxy_ = iface_cast(object); + if (serviceProxy_ == nullptr) { + LOGE("CloudDiskService::Connect service == nullptr"); + return nullptr; + } + + // sptr cloudDiskServiceLoadCallback = new CloudDiskServiceProxyLoadCallback(); + // if (cloudDiskServiceLoadCallback == nullptr) { + // LOGE("cloudDiskServiceLoadCallback is nullptr"); + // return nullptr; + // } + + // int32_t ret = samgr->LoadSystemAbility(FILEMANAGEMENT_CLOUD_DISK_SERVICE_SA_ID, cloudDiskServiceLoadCallback); + // if (ret != E_OK) { + // LOGE("Failed to Load systemAbility, systemAbilityId:%{public}d, ret code:%{public}d", + // FILEMANAGEMENT_CLOUD_DISK_SERVICE_SA_ID, ret); + // return nullptr; + // } + + + // unique_lock proxyLock(proxyMutex_); + // auto waitStatus = cloudDiskServiceLoadCallback->proxyConVar_.wait_for( + // proxyLock, std::chrono::milliseconds(LOAD_SA_TIMEOUT_MS), + // [cloudDiskServiceLoadCallback]() { return cloudDiskServiceLoadCallback->isLoadSuccess_.load(); }); + // if (!waitStatus) { + // LOGE("Load CloudDiskService SA timeout"); + // return nullptr; + // } + return serviceProxy_; +} + +void ServiceProxy::InvaildInstance() +{ + LOGI("invalid instance"); + unique_lock lock(instanceMutex_); + serviceProxy_ = nullptr; +} + +// void ServiceProxy::CloudDiskServiceProxyLoadCallback::OnLoadSystemAbilitySuccess( +// int32_t systemAbilityId, +// const sptr &remoteObject) +// { +// LOGI("Load CloudSync SA success,systemAbilityId:%{public}d, remoteObj result:%{private}s", systemAbilityId, +// (remoteObject == nullptr ? "false" : "true")); +// unique_lock lock(proxyMutex_); +// if (serviceProxy_ != nullptr) { +// LOGE("CloudDiskService SA proxy has been loaded"); +// } else { +// serviceProxy_ = iface_cast(remoteObject); +// } +// isLoadSuccess_.store(true); +// proxyConVar_.notify_one(); +// } + +// void ServiceProxy::CloudDiskServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) +// { +// LOGI("Load CloudDiskService SA failed,systemAbilityId:%{public}d", systemAbilityId); +// unique_lock lock(proxyMutex_); +// serviceProxy_ = nullptr; +// isLoadSuccess_.store(false); +// proxyConVar_.notify_one(); +// } +} // namespace OHOS::FileManagement::CloudDiskService diff --git a/interfaces/inner_api/native/clouddiskservice_kit_inner/BUILD.gn b/interfaces/inner_api/native/clouddiskservice_kit_inner/BUILD.gn new file mode 100644 index 000000000..d05f1358e --- /dev/null +++ b/interfaces/inner_api/native/clouddiskservice_kit_inner/BUILD.gn @@ -0,0 +1,104 @@ +# 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/ohos.gni") +import("//foundation/filemanagement/dfs_service/distributedfile.gni") + +config("public_config") { + include_dirs = [ + ".", + "${distributedfile_path}/interfaces/inner_api/native/clouddiskservice_kit_inner", + ] +} + +config("private_config") { + include_dirs = [ + "${distributedfile_path}/frameworks/native/clouddiskservice_kit_inner/include", + "${distributedfile_path}/interfaces/inner_api/native/clouddiskservice_kit_inner", + "${distributedfile_path}/utils/log/include", + ] +} + +config("optimize-size") { + cflags = [ + "-fdata-sections", + "-ffunction-sections", + "-Oz", + ] + cflags_cc = [ + "-fvisibility-inlines-hidden", + "-Oz", + ] +} + +ohos_shared_library("clouddiskservice_kit_inner") { + branch_protector_ret = "pac_ret" + configs = [ ":optimize-size" ] + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + sources = [ + "${distributedfile_path}/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_common.cpp", + "${distributedfile_path}/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_callback_stub.cpp", + "${distributedfile_path}/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_manager.cpp", + "${distributedfile_path}/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_manager_impl.cpp", + "${distributedfile_path}/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_task_manager.cpp", + "${distributedfile_path}/frameworks/native/clouddiskservice_kit_inner/src/service_proxy.cpp", + "${distributedfile_path}/utils/log/src/utils_log.cpp", + ] + + defines = [ + "LOG_DOMAIN=0xD004309", + "LOG_TAG=\"CLOUDDISKSERVICE_API\"", + ] + + if (dfs_service_feature_enable_cloud_disk) { + defines += [ "SUPPORT_CLOUD_DISK_SERVICE "] + } + + configs += [ ":private_config" ] + public_configs = [ + ":public_config", + "${services_path}/clouddiskservice:cloud_disk_service_public_config", + ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:dataobs_manager", + "c_utils:utils", + "ffrt:libffrt", + "hilog:libhilog", + "ipc:ipc_single", + "memmgr:memmgrclient", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + deps = [ + "${services_path}/clouddiskservice:libcloud_disk_service_proxy", + "${utils_path}:libdistributedfiledentry", + "${utils_path}:libdistributedfileutils", + ] + + + use_exceptions = true + part_name = "dfs_service" + subsystem_name = "filemanagement" +} + diff --git a/interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_common.h b/interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_common.h new file mode 100644 index 000000000..1d0d9fb40 --- /dev/null +++ b/interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_common.h @@ -0,0 +1,97 @@ +/* + * 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_COMMON_H +#define OHOS_FILEMGMT_CLOUD_DISK_COMMON_H + +#include +#include + +#include "parcel.h" + +namespace OHOS::FileManagement::CloudDiskService { + +class CloudDiskCommon { +public: + static CloudDiskCommon &GetInstance(); + struct SyncFolderValue { + std::string bundleName; + std::string uri; + int32_t state; + }; + std::map valueMap; +}; + +/* +When adding new enumeration values, pay attention to the maximum enumeration value judgment of the getxattr method in clouddiskservice.cpp +*/ +enum class SyncState { + IDLE = 0, + SYNCING, + SYNC_SUCCESSED, + SYNC_FAILED, + SYNC_CANCELED, + SYNC_CONFLICTED, +}; + +enum class OperationType { + CREATE = 0, + DELETE, + MOVE_FROM, + MOVE_TO, + ATTR_CHANGE, + CLOSE_WRITE, +}; + +struct FileSyncState : public Parcelable{ + std::string uri; + SyncState syncState; + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static FileSyncState *Unmarshalling(Parcel &parcel); +}; + +struct ChangeData : public Parcelable { + uint64_t updateSequenceNumber; + std::string fileId; + std::string parentFileId; + std::string syncFolderIndex; + std::string relativePath; + OperationType operationType; + uint64_t size; + uint64_t mtime; + uint64_t timeStamp; + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static ChangeData *Unmarshalling(Parcel &parcel); +}; + +struct ChangesResult : public Parcelable { + uint64_t nextUSN; + std::vector changesData; + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static ChangesResult *Unmarshalling(Parcel &parcel); +}; + +#define RETURN_ON_ERR(ret) \ + do { \ + int32_t res = ret; \ + if ((res) != E_OK) { \ + return res; \ + } \ + } while (0) +} // namespace OHOS::FileManagement::CloudDiskService +#endif // OHOS_FILEMGMT_CLOUD_DISK_COMMON_H diff --git a/interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_service_callback.h b/interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_service_callback.h new file mode 100644 index 000000000..a84eccb9e --- /dev/null +++ b/interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_service_callback.h @@ -0,0 +1,30 @@ +/* + * 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_CALLBACK_H +#define OHOS_FILEMGMT_CLOUD_DISK_SERVICE_CALLBACK_H + +#include "cloud_disk_common.h" + +namespace OHOS::FileManagement::CloudDiskService { +class CloudDiskServiceCallback { +public: + virtual ~CloudDiskServiceCallback() = default; + virtual void OnChangeData(std::vector &changeData) = 0; + virtual void OnDeathRecipient() {}; +}; +} // namespace OHOS::FileManagement::CloudDiskService + +#endif // OHOS_FILEMGMT_CLOUD_DISK_SERVICE_CALLBACK_H \ No newline at end of file diff --git a/interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_service_manager.h b/interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_service_manager.h new file mode 100644 index 000000000..6c08c07a7 --- /dev/null +++ b/interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_service_manager.h @@ -0,0 +1,39 @@ +/* + * 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_MANAGER_H +#define OHOS_FILEMGMT_CLOUD_DISK_SERVICE_MANAGER_H + +#include + +#include "cloud_disk_service_callback.h" + +namespace OHOS::FileManagement::CloudDiskService { +class CloudDiskServiceManager { +public: + static CloudDiskServiceManager &GetInstance(); + + virtual int32_t RegisterSyncFolderChanges(const std::string& uri, + const std::shared_ptr &callback, std::string &syncFolderIndex) = 0; + virtual int32_t UnregisterSyncFolderChanges(const std::string& uri) = 0; + virtual int32_t GetSyncFolderChanges(const std::string &uri, uint64_t count, uint64_t startUSN, ChangesResult& changesResult) = 0; + virtual int32_t SetFileSyncStates(const std::string& uri, const std::vector& fileSyncStates, std::vector& failedList) = 0; + virtual int32_t GetFileSyncStates(const std::string& uri, const std::vector& uris, std::vector& resultList) = 0; + virtual int32_t RegisterSyncFolder(const int32_t& userId, const std::string& bundleName, const std::string path) = 0; + virtual int32_t UnregisterSyncFolder(const int32_t& userId, const std::string& bundleName, const std::string path) = 0; +}; +} // namespace OHOS::FileManagement::CloudDiskService + +#endif // OHOS_FILEMGMT_CLOUD_DISK_SERVICE_MANAGER_H diff --git a/interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_service_task_manager.h b/interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_service_task_manager.h new file mode 100644 index 000000000..b65c3e841 --- /dev/null +++ b/interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_service_task_manager.h @@ -0,0 +1,71 @@ +/* + * 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_TASK_MANAGER_H +#define OHOS_FILEMGMT_CLOUD_DISK_SERVICE_TASK_MANAGER_H + +#include +#include +#include "ffrt_inner.h" + +namespace OHOS::FileManagement::CloudDiskService { +// static const std::string CLOUD_FILE_SERVICE_SA_STATUS_FLAG = "persist.kernel.medialibrarydata.stopflag"; +// static const std::string CLOUD_FILE_SERVICE_SA_START = "0"; +// static const std::string CLOUD_FILE_SERVICE_SA_END = "1"; +enum class TaskType : uint64_t { + REGISTER_TASK = 1, + UNREGISTER_TASK = 1 << 1, + GET_TASK = 1 << 2, +}; + +struct TaskKey { + std::string bundleName; + std::string syncChronousRootPath; + + bool operator ==(const TaskKey& other) const { + return bundleName == other.bundleName && + syncChronousRootPath == other.syncChronousRootPath; + } + + struct Hash { + size_t operator()(const TaskKey& key) const { + auto hasher = std::hash(); + return hasher(key.bundleName) ^ (hasher(key.syncChronousRootPath) << 1); + } + }; +}; + +class CloudDiskServiceTaskManager : public NoCopyable { +public: + static CloudDiskServiceTaskManager &GetInstance(); + ~CloudDiskServiceTaskManager() = default; + void StartTask(TaskKey key, TaskType task); + void CompleteTask(TaskKey key, TaskType task); + bool HasTask(TaskKey key, TaskType task); + void StartTask(); +private: + CloudDiskServiceTaskManager(); + void DelayUnloadTask(bool needSetCritical); + void CancelUnloadTask(); + + bool criticalStatus_ = true; + std::mutex taskMapsMutex_; + std::unordered_map taskMaps_; + ffrt::queue queue_; + ffrt::task_handle unloadTaskHandle_; + ffrt::mutex unloadTaskMutex_; +}; +} // namespace OHOS::FileManagement::CloudDiskService +#endif // OHOS_FILEMGMT_CLOUD_DISK_SERVICE_TASK_MANAGER_H \ No newline at end of file diff --git a/interfaces/inner_api/native/clouddiskservice_kit_inner/i_cloud_disk_service_callback.h b/interfaces/inner_api/native/clouddiskservice_kit_inner/i_cloud_disk_service_callback.h new file mode 100644 index 000000000..60c471fcd --- /dev/null +++ b/interfaces/inner_api/native/clouddiskservice_kit_inner/i_cloud_disk_service_callback.h @@ -0,0 +1,36 @@ +/* + * 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_I_CLOUD_DISK_SERVICE_CALLBACK_H +#define OHOS_FILEMGMT_I_CLOUD_DISK_SERVICE_CALLBACK_H + +#include "iremote_broker.h" +#include "cloud_disk_service_callback.h" + +namespace OHOS::FileManagement::CloudDiskService { +class ICloudDiskServiceCallback : public CloudDiskServiceCallback, public IRemoteBroker { +public: + enum { + SERVICE_CMD_ON_PROCESS = 0, + }; + + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Filemanagement.Dfs.ICloudDiskServiceCallback") + +protected : + const int VECTOR_MAX_SIZE = 102400; +}; +} // namespace OHOS::FileManagement::CloudDiskService + +#endif // OHOS_FILEMGMT_I_CLOUD_DISK_SERVICE_CALLBACK_H \ No newline at end of file diff --git a/interfaces/inner_api/native/clouddiskservice_kit_inner/svc_death_recipient.h b/interfaces/inner_api/native/clouddiskservice_kit_inner/svc_death_recipient.h new file mode 100644 index 000000000..bd5b79a3f --- /dev/null +++ b/interfaces/inner_api/native/clouddiskservice_kit_inner/svc_death_recipient.h @@ -0,0 +1,41 @@ +/* + * 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_SVC_DEATH_RECIPIENT_H +#define OHOS_FILEMGMT_SVC_DEATH_RECIPIENT_H + +#include + +#include "iremote_object.h" + +namespace OHOS::FileManagement::CloudDiskService { +class SvcDeathRecipient : public IRemoteObject::DeathRecipient { +public: + explicit SvcDeathRecipient(std::function &)> functor) : functor_(functor){}; + void OnRemoteDied(const wptr &object) override + { + if (object == nullptr) { + return; + } + object->RemoveDeathRecipient(this); + functor_(object); + } + +private: + std::function &)> functor_; +}; +} // namespace OHOS::FileManagement::CloudDiskService + +#endif // OHOS_FILEMGMT_SVC_DEATH_RECIPIENT_H \ No newline at end of file diff --git a/services/5207.json b/services/5207.json new file mode 100644 index 000000000..62f22ff23 --- /dev/null +++ b/services/5207.json @@ -0,0 +1,12 @@ +{ + "process": "clouddiskservice", + "systemability": [ + { + "name": 5207, + "libpath": "libclouddiskservice_sa.z.so", + "run-on-create": true, + "distributed": false, + "dump-level": 1 + } + ] +} \ No newline at end of file diff --git a/services/BUILD.gn b/services/BUILD.gn index 0eec280de..01f49084f 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" @@ -32,6 +37,13 @@ ohos_prebuilt_etc("distributedfile_etc") { subsystem_name = "filemanagement" } +ohos_prebuilt_etc("clouddiskservice_etc") { + source = "clouddiskservice.cfg" + relative_install_dir = "init" + part_name = "dfs_service" + subsystem_name = "filemanagement" +} + ohos_prebuilt_etc("cloudfiledaemon_etc") { source = "cloudfiledaemon.cfg" relative_install_dir = "init" diff --git a/services/clouddiskservice.cfg b/services/clouddiskservice.cfg new file mode 100644 index 000000000..cb0d09c6f --- /dev/null +++ b/services/clouddiskservice.cfg @@ -0,0 +1,12 @@ +{ + "services": [ { + "name": "clouddiskservice", + "path": ["/system/bin/sa_main", "/system/profile/clouddiskservice.json"], + "uid": "6161", + "gid": ["6161", "dfs", "1006"], + "sandbox": 0, + "secon": "u:r:clouddiskservice:s0", + "caps": ["CAP_SYS_ADMIN", "CAP_DAC_READ_SEARCH"], + "apl": "system_basic" + }] +} \ No newline at end of file diff --git a/services/clouddiskservice/BUILD.gn b/services/clouddiskservice/BUILD.gn new file mode 100644 index 000000000..30bc59367 --- /dev/null +++ b/services/clouddiskservice/BUILD.gn @@ -0,0 +1,124 @@ +# 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 = [ + "${distributedfile_path}/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_common.cpp", + "${distributedfile_path}/utils/log/src/utils_log.cpp", + ] + sub_include = [ + "${distributedfile_path}/utils/log/include", + "${innerkits_native_path}/clouddiskservice_kit_inner", + ] + configs = [] + + sequenceable_ext_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + + 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 = "filemanagement" + part_name = "dfs_service" +} + +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", + # "${innerkits_native_path}/clouddiskservice_kit_inner", + ] + + sources = [ + "src/ipc/cloud_disk_service.cpp", + "src/ipc/cloud_disk_service_callback_manager.cpp", + "src/ipc/cloud_disk_service_callback_proxy.cpp", + "${distributedfile_path}/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_common.cpp", + "${distributedfile_path}/utils/log/src/utils_log.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", + ":libcloud_disk_service_proxy", + "${innerkits_native_path}/clouddiskservice_kit_inner:clouddiskservice_kit_inner", + "${utils_path}:libdistributedfiledentry", + "${utils_path}:libdistributedfileutils", + ] + + external_deps = [ + "c_utils:utils", + "ffrt:libffrt", + "e2fsprogs:libext2_uuid", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_single", + "samgr:samgr_proxy", + "safwk:system_ability_fwk", + # "user_file_service:cloud_disk_manager_kit", + ] + + use_exceptions = true + part_name = "dfs_service" + subsystem_name = "filemanagement" +} diff --git a/services/clouddiskservice/ICloudDiskService.idl b/services/clouddiskservice/ICloudDiskService.idl new file mode 100644 index 000000000..e760c7560 --- /dev/null +++ b/services/clouddiskservice/ICloudDiskService.idl @@ -0,0 +1,26 @@ +/* + * 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. + */ +sequenceable OHOS.IRemoteObject; +sequenceable cloud_disk_common..OHOS.FileManagement.CloudDiskService.ChangesResult; +sequenceable cloud_disk_common..OHOS.FileManagement.CloudDiskService.FileSyncState; + +interface OHOS.FileManagement.CloudDiskService.ICloudDiskService +{ + String RegisterSyncFolderChangesInner([in] String uri, [in] IRemoteObject remoteobject); + void UnregisterSyncFolderChangesInner([in] String uri); + ChangesResult GetSyncFolderChangesInner([in] String uri, [in] unsigned long count, [in] unsigned long startUSN); + List SetFileSyncStatesInner([in] String uri, [in] List fileSyncStates); + List GetFileSyncStatesInner([in] String uri, [in] List uris); +} 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..baac0cdeb --- /dev/null +++ b/services/clouddiskservice/include/ipc/cloud_disk_service.h @@ -0,0 +1,69 @@ +/* + * 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 CLOUD_DISK_SERVICE_H +#define 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 "dfsu_access_token_helper.h" +#include "icloud_disk_service.h" +#include "i_cloud_disk_service_callback.h" + +namespace OHOS { +namespace FileManagement { +namespace CloudDiskService { +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; + ErrCode RegisterSyncFolderChangesInner(const std::string& uri, + const sptr& remoteObject, std::string &syncFolderIndex) override; + ErrCode UnregisterSyncFolderChangesInner(const std::string& uri) override; + ErrCode GetSyncFolderChangesInner(const std::string &uri, uint64_t count, uint64_t startUSN, ChangesResult& changesResult) override; + ErrCode SetFileSyncStatesInner(const std::string& uri, const std::vector& fileSyncStates, std::vector& failedList) override; + ErrCode GetFileSyncStatesInner(const std::string& uri, const std::vector& uris, std::vector& resultList) 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 CloudDiskService +} // namespace FileManagement +} // namespace OHOS +#endif // CLOUD_DISK_SERVICE_H diff --git a/services/clouddiskservice/include/ipc/cloud_disk_service_callback_manager.h b/services/clouddiskservice/include/ipc/cloud_disk_service_callback_manager.h new file mode 100644 index 000000000..3e2d47f91 --- /dev/null +++ b/services/clouddiskservice/include/ipc/cloud_disk_service_callback_manager.h @@ -0,0 +1,37 @@ +/* + * 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_CALLBACK_MANAGER_H +#define OHOS_FILEMGMT_CLOUD_DISK_SERVICE_CALLBACK_MANAGER_H + +#include "nocopyable.h" + +#include "i_cloud_disk_service_callback.h" +#include "svc_death_recipient.h" + +namespace OHOS::FileManagement::CloudDiskService { +class CloudDiskServiceCallbackManager final : public NoCopyable { +public: + using TaskId = uint64_t; + static CloudDiskServiceCallbackManager &GetInstance(); + void AddCallback(const sptr &callback); + +private: + sptr callbackProxy_; + sptr deathRecipient_; +}; +} // namespace OHOS::FileManagement::CloudDiskService + +#endif // OHOS_FILEMGMT_CLOUD_DISK_SERVICE_CALLBACK_MANAGER_H \ No newline at end of file diff --git a/services/clouddiskservice/include/ipc/cloud_disk_service_callback_proxy.h b/services/clouddiskservice/include/ipc/cloud_disk_service_callback_proxy.h new file mode 100644 index 000000000..0f915bf08 --- /dev/null +++ b/services/clouddiskservice/include/ipc/cloud_disk_service_callback_proxy.h @@ -0,0 +1,36 @@ +/* + * 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_CALLBACK_PROXY_H +#define OHOS_FILEMGMT_CLOUD_DISK_SERVICE_CALLBACK_PROXY_H + +#include "iremote_proxy.h" + +#include "i_cloud_disk_service_callback.h" + +namespace OHOS::FileManagement::CloudDiskService { +class CloudDiskServiceCallbackProxy : public IRemoteProxy { +public: + explicit CloudDiskServiceCallbackProxy(const sptr &impl) : IRemoteProxy(impl) {} + ~CloudDiskServiceCallbackProxy() override {} + + void OnChangeData(std::vector &changeData) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace OHOS::FileManagement::CloudDiskService + +#endif // OHOS_FILEMGMT_CLOUD_DISK_SERVICE_CALLBACK_PROXY_H \ No newline at end of file diff --git a/services/clouddiskservice/include/monitor/disk_monitor.h b/services/clouddiskservice/include/monitor/disk_monitor.h new file mode 100644 index 000000000..a5a5ecffc --- /dev/null +++ b/services/clouddiskservice/include/monitor/disk_monitor.h @@ -0,0 +1,66 @@ +/* + * 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_FILEMANAGEMENT_DISK_MONITOR_H +#define OHOS_FILEMANAGEMENT_DISK_MONITOR_H + +#include +#include +#include +#include + +#include "disk_types.h" + +namespace OHOS::FileManagement::CloudDiskService { +class DiskMonitor { +public: + static DiskMonitor &GetInstance(); + bool Init(); + +private: + bool InitFanotify(); + void CollectEvents(); + void HandleEvents(int32_t mountFd, char eventsBuf[], size_t dataLen); + void EventProcess(struct fanotify_event_metadata *metaData, const std::string &filePath); + void HandleCreate(const std::string &filePath); + void HandleDelete(const std::string &filePath); + void HandleMoveFrom(const std::string &filePath); + void HandleMoveTo(const std::string &filePath); + void HandleCloseWrite(const std::string &filePath); + // 1. events handle + bool ExtractFileName(int type, std::string &fileName, struct file_handle *fileHandle); + std::string GetFilePath(int32_t eventFd, const std::string &fileName); + int32_t GetSyncRootIndex(const std::string &filePath); + // 2. utils + // closeFd + // closeDir + std::string FolderAddSlash(bool isDir, const std::string &path); + bool IsInSyncRoots(const std::string &path); + bool IsInBlackList(const std::string &path); + // debug + void PrintEventInfo(EventInfo info); + +private: + // watcher status + int32_t userId_{-1}; + int32_t fanotifyFd_{-1}; + int32_t mountFd_{-1}; + DIR *mountFp_{nullptr}; + bool isRunning_{true}; + // event handle + EventInfo oldEventInfo_; +}; +} // namespace OHOS::FileManagement::CloudDiskService +#endif diff --git a/services/clouddiskservice/include/monitor/disk_notifier.h b/services/clouddiskservice/include/monitor/disk_notifier.h new file mode 100644 index 000000000..f27ac784b --- /dev/null +++ b/services/clouddiskservice/include/monitor/disk_notifier.h @@ -0,0 +1,39 @@ +/* + * 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_FILEMANAGEMENT_DISK_NOTIFIER_H +#define OHOS_FILEMANAGEMENT_DISK_NOTIFIER_H + +#include +#include + +#include "disk_types.h" +#include "ffrt_inner.h" + +namespace OHOS::FileManagement::CloudDiskService { +class DiskNotifier { +public: + static DiskNotifier &GetInstance(); + void PostEvent(EventInfo eventInfo); + +private: + void NotifyAllEvent(); + static void CallBack(void *data); +private: + std::vector eventList_; + ffrt_timer_t handle_{-1}; + ffrt::mutex mutex_; +}; +} // namespace OHOS::FileManagement::CloudDiskService +#endif \ No newline at end of file diff --git a/services/clouddiskservice/include/monitor/disk_types.h b/services/clouddiskservice/include/monitor/disk_types.h new file mode 100644 index 000000000..ec3a1e90f --- /dev/null +++ b/services/clouddiskservice/include/monitor/disk_types.h @@ -0,0 +1,69 @@ +/* + * 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_FILEMANAGEMENT_DISK_TYPES_H +#define OHOS_FILEMANAGEMENT_DISK_TYPES_H +#include +#include +#include + +namespace OHOS::FileManagement::CloudDiskService { +constexpr int64_t SECOND_TO_MILLISECOND = 1e3; +constexpr int64_t MILLISECOND_TO_NANOSECOND = 1e6; +enum class OperationType : uint8_t { + NONE = 0, + CREATE, + DELETE, + MOVE_FROM, + MOVE_TO, + ATTR_CHANGE, + CLOSE_WRITE, +}; + +static uint64_t UTCTimeMilliSeconds() +{ + struct timespec t; + clock_gettime(CLOCK_REALTIME, &t); + return t.tv_sec * SECOND_TO_MILLISECOND + t.tv_nsec / MILLISECOND_TO_NANOSECOND; +} + +struct EventInfo { + int32_t userId{-1}; + int32_t syncRootIndex{-1}; + std::string path{""}; + std::string name{""}; + uint8_t operateType{static_cast(OperationType::NONE)}; + uint64_t timestamp{0}; + EventInfo() {} + EventInfo(int32_t uid, int32_t syncRoot, OperationType type, const std::string &filePath) + : userId(uid), syncRootIndex(syncRoot), operateType(static_cast(type)) + { + path = std::filesystem::path(filePath).parent_path().string(); + name = std::filesystem::path(filePath).filename().string(); + timestamp = UTCTimeMilliSeconds(); + } + + void Reset() + { + userId = -1; + syncRootIndex = -1; + path = ""; + name = ""; + operateType = static_cast(OperationType::NONE); + timestamp = 0; + } +}; +} // namespace OHOS::FileManagement::CloudDiskService +#endif \ No newline at end of file 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..1225dd490 --- /dev/null +++ b/services/clouddiskservice/src/ipc/cloud_disk_service.cpp @@ -0,0 +1,269 @@ +/* + * 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. + */ + +#include "cloud_disk_service.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "cloud_disk_service_callback_manager.h" +#include "cloud_disk_service_task_manager.h" +// #include "cloud_disk_manager.h" +#include "dfs_error.h" +#include "ffrt_inner.h" +#include "iremote_object.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 CloudDiskService { +using namespace std; + +const int32_t GET_FILE_SYNC_MAX = 100; +constexpr const char* FILE_SYNC_STATE = "user.clouddisk.filesyncstate"; + +namespace { +} +REGISTER_SYSTEM_ABILITY_BY_ID(CloudDiskService, FILEMANAGEMENT_CLOUD_DISK_SERVICE_SA_ID, 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("CloudDiskService has already started"); + return; + } + + try { + PublishSA(); + } catch (const exception &e) { + LOGE("%{public}s", e.what()); + } + + CloudDiskCommon::SyncFolderValue syncFolderValue; + syncFolderValue.bundleName = "testBundleName"; + syncFolderValue.uri = "testURI"; + syncFolderValue.state = 1; + CloudDiskCommon::GetInstance().valueMap.insert({0, syncFolderValue}); + + // std::vector OHOS::FileManagement::CloudDiskManager::GetInstance().GetAllSyncFoldersForSa(); + CloudDiskServiceTaskManager::GetInstance().StartTask(); + 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"); +} + +static int32_t CheckPermissions(const string &permission, bool isSystemApp) +{ + if (!permission.empty() && !DfsuAccessTokenHelper::CheckCallerPermission(permission)) { + LOGE("permission denied"); + return E_PERMISSION_DENIED; + } + return E_OK; +} + +int32_t CloudDiskService::RegisterSyncFolderChangesInner(const std::string& uri, + const sptr& remoteObject, std::string &syncFolderIndex) +{ + LOGI("Begin RegisterSyncFolderChangesInner"); + LOGI("RegisterSyncFolderChangesInner start uri:%{public}s", uri.c_str()); + LOGI("RegisterSyncFolderChangesInner start syncFolderIndex:%{public}s", syncFolderIndex.c_str()); + // RETURN_ON_ERR(CheckPermissions(PERM_CLOUD_DISK_SERVICE, true)); + // URI校验 + + syncFolderIndex = "test"; + + if (remoteObject == nullptr) { + LOGE("remoteObject is nullptr"); + return E_INVAL_ARG; + } + + TaskKey taskKey; + taskKey.bundleName = "test"; + taskKey.syncChronousRootPath = "test"; + CloudDiskServiceTaskManager::GetInstance().StartTask(taskKey, TaskType::REGISTER_TASK); + + auto callback = iface_cast(remoteObject); + LOGI("callback is null : %{public}s", callback == nullptr? "true" : "false"); + CloudDiskServiceCallbackManager::GetInstance().AddCallback(callback); + CloudDiskServiceTaskManager::GetInstance().CompleteTask(taskKey, TaskType::REGISTER_TASK); + LOGI("RegisterSyncFolderChangesInner end syncFolderIndex:%{public}s", syncFolderIndex.c_str()); + LOGI("End RegisterSyncFolderChangesInner"); + return 0; +} + +int32_t CloudDiskService::UnregisterSyncFolderChangesInner(const std::string& uri) +{ + LOGI("Begin UnregisterSyncFolderChangesInner"); + LOGI("UnregisterSyncFolderChangesInner start uri:%{public}s", uri.c_str()); + // RETURN_ON_ERR(CheckPermissions(PERM_CLOUD_DISK_SERVICE, true)); + // URI校验 + + TaskKey taskKey; + taskKey.bundleName = "test"; + taskKey.syncChronousRootPath = "test"; + CloudDiskServiceTaskManager::GetInstance().StartTask(taskKey, TaskType::REGISTER_TASK); + + CloudDiskServiceTaskManager::GetInstance().CompleteTask(taskKey, TaskType::REGISTER_TASK); + LOGI("End UnregisterSyncFolderChangesInner"); + return 0; +} + +int32_t CloudDiskService::GetSyncFolderChangesInner(const std::string &uri, uint64_t count, uint64_t startUSN, ChangesResult& changesResult) +{ + LOGI("Begin GetSyncFolderChangesInner"); + LOGI("GetSyncFolderChangesInner start uri:%{public}s", uri.c_str()); + LOGI("GetSyncFolderChangesInner start count:%{public}ld", count); + LOGI("GetSyncFolderChangesInner start startUSN:%{public}ld", startUSN); + LOGI("GetSyncFolderChangesInner start changesResult.nextUSN:%{public}ld", changesResult.nextUSN); + // RETURN_ON_ERR(CheckPermissions(PERM_CLOUD_DISK_SERVICE, true)); + // URI校验 + + TaskKey taskKey; + taskKey.bundleName = "test"; + taskKey.syncChronousRootPath = "test"; + CloudDiskServiceTaskManager::GetInstance().StartTask(taskKey, TaskType::REGISTER_TASK); + + ChangeData changeData; + changeData.updateSequenceNumber = 1; + changeData.fileId = "1"; + changeData.parentFileId = "1"; + changeData.syncFolderIndex = "test"; + changeData.relativePath = "test"; + changeData.operationType = OperationType::CREATE; + changeData.size = 1; + changeData.mtime = 1; + changeData.timeStamp = 1; + changeData.timeStamp = 1; + changesResult.nextUSN = 1; + changesResult.changesData.push_back(changeData); + + CloudDiskServiceTaskManager::GetInstance().CompleteTask(taskKey, TaskType::REGISTER_TASK); + LOGI("GetSyncFolderChangesInner end changesResult.nextUSN:%{public}ld", changesResult.nextUSN); + LOGI("End GetSyncFolderChangesInner"); + return 0; +} + +int32_t CloudDiskService::SetFileSyncStatesInner(const std::string& uri, const std::vector& fileSyncStates, std::vector& failedList) +{ + LOGI("Begin SetXattrInner"); + // URI校验 + + int32_t ret = 0; + if (fileSyncStates.empty() || fileSyncStates.size() > GET_FILE_SYNC_MAX) { + LOGE("Invalid parameter"); + return E_PARAMS_; + } + + for (auto& item : fileSyncStates) { + uint8_t state = static_cast(item.syncState); + if (state > static_cast(SyncState::SYNC_CONFLICTED)) { + LOGE("Invalid state for %{public}s", item.uri.c_str()); + failedList.push_back(item.uri); + continue; + } + if (setxattr(item.uri.c_str(), FILE_SYNC_STATE, &state, sizeof(state), 0) != 0) { + LOGE("Failed to set xattr for file:%{public}s, err: %{public}d", item.uri.c_str(), errno); + failedList.push_back(item.uri); + } + } + + if (!failedList.empty()) { + return E_IPCSS; + } + + LOGI("End SetXattrInner"); + return 0; +} + +int32_t CloudDiskService::GetFileSyncStatesInner(const std::string& uri, const std::vector& uris, std::vector& resultList) +{ + LOGI("Begin GetXattrInner"); + // URI校验 + + if (uris.empty() || uris.size() > GET_FILE_SYNC_MAX) { + LOGE("Invalid parameter"); + return E_PARAMS_; + } + + for (auto& item : uris) { + auto xattrValueSize = getxattr(item.c_str(), FILE_SYNC_STATE, nullptr, 0); + if (xattrValueSize < 0) { + LOGE("getxattr failed, errno : %{public}d", errno); + return E_IPCSS; + } + std::unique_ptr xattrValue = std::make_unique((long)xattrValueSize + 1); + if (xattrValue == nullptr) { + LOGE("Failed to allocate memory for xattrValue, errno : %{public}d", errno); + return E_IPCSS; + } + xattrValueSize = getxattr(item.c_str(), FILE_SYNC_STATE, xattrValue.get(), xattrValueSize); + if (xattrValueSize <= 0) { + LOGE("getxattr failed, errno : %{public}d", errno); + return E_IPCSS; + } + uint8_t rawState = static_cast(xattrValue[0]); + if (rawState > static_cast(SyncState::SYNC_CONFLICTED)) { + LOGE("get invalid number"); + return E_IPCSS; + } + FileSyncState fileSyncState; + fileSyncState.uri = uri; + fileSyncState.syncState = static_cast(rawState); + resultList.push_back(fileSyncState); + } + + LOGI("End GetXattrInner"); + return 0; +} + +} // namespace CloudDiskService +} // namespace FileManagement +} // namespace OHOS diff --git a/services/clouddiskservice/src/ipc/cloud_disk_service_callback_manager.cpp b/services/clouddiskservice/src/ipc/cloud_disk_service_callback_manager.cpp new file mode 100644 index 000000000..87405f0dc --- /dev/null +++ b/services/clouddiskservice/src/ipc/cloud_disk_service_callback_manager.cpp @@ -0,0 +1,45 @@ +/* + * 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. + */ +#include "ipc/cloud_disk_service_callback_manager.h" + +#include + +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudDiskService { +using namespace std; + +CloudDiskServiceCallbackManager &CloudDiskServiceCallbackManager::GetInstance() +{ + static CloudDiskServiceCallbackManager instance; + return instance; +} + +void CloudDiskServiceCallbackManager::AddCallback(const sptr &callback) +{ + if (callback == nullptr) { + return; + } + callbackProxy_ = callback; + auto remoteObject = callback->AsObject(); + auto deathCb = [this](const wptr &obj) { + callbackProxy_ = nullptr; + LOGE("client died"); + }; + deathRecipient_ = sptr(new SvcDeathRecipient(deathCb)); + remoteObject->AddDeathRecipient(deathRecipient_); +} + +} // namespace OHOS::FileManagement::CloudDiskService \ No newline at end of file diff --git a/services/clouddiskservice/src/ipc/cloud_disk_service_callback_proxy.cpp b/services/clouddiskservice/src/ipc/cloud_disk_service_callback_proxy.cpp new file mode 100644 index 000000000..6026f0b95 --- /dev/null +++ b/services/clouddiskservice/src/ipc/cloud_disk_service_callback_proxy.cpp @@ -0,0 +1,97 @@ +/* + * 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. + */ + +#include "cloud_disk_service_callback_proxy.h" + +#include "cloud_file_error.h" +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudDiskService { +using namespace std; + +void CloudDiskServiceCallbackProxy::OnChangeData(std::vector &changeData) +{ + LOGI("Start"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(GetDescriptor())) { + LOGE("Failed to write interface token"); + return; + } + + if (changeData.size() > static_cast(VECTOR_MAX_SIZE)) { + return; + } + data.WriteInt32(changeData.size()); + for (auto item = changeData.begin(); item != changeData.end(); ++item) { + if (!data.WriteParcelable(&(*item))) { + return; + } + // if (!data.WriteUint64(item.updateSequenceNumber)) { + // LOGE("failed to send updateSequenceNumber"); + // return false; + // } + + // if (!data.WriteString(item.fileId)) { + // LOGE("failed to send fileId"); + // return false; + // } + + // if (!data.WriteString(item.parentFileId)) { + // LOGE("failed to send parentFileId"); + // return false; + // } + + // if (!data.WriteString(item.syncFolderIndex)) { + // LOGE("failed to send syncFolderIndex"); + // return false; + // } + + // if (!data.WriteString(item.relativePath)) { + // LOGE("failed to send relativePath"); + // return false; + // } + + // if (!data.WriteUint64(item.size)) { + // LOGE("failed to send size"); + // return false; + // } + + // if (!data.WriteUint64(item.mtime)) { + // LOGE("failed to send mtime"); + // return false; + // } + + // if (!data.WriteUint64(item.timeStamp)) { + // LOGE("failed to send timeStamp"); + // return false; + // } + } + auto remote = Remote(); + if (!remote) { + LOGE("remote is nullptr"); + return; + } + int32_t ret = remote->SendRequest(ICloudDiskServiceCallback::SERVICE_CMD_ON_PROCESS, data, reply, option); + if (ret != E_OK) { + LOGE("Failed to send out the requeset, ret:%{public}d", ret); + return; + } + LOGI("End"); + return; +} +} // namespace OHOS::FileManagement::CloudDiskService \ No newline at end of file diff --git a/services/clouddiskservice/src/monitor/disk_monitor.cpp b/services/clouddiskservice/src/monitor/disk_monitor.cpp new file mode 100644 index 000000000..887f84304 --- /dev/null +++ b/services/clouddiskservice/src/monitor/disk_monitor.cpp @@ -0,0 +1,327 @@ +/* + * 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. + */ +#include "disk_monitor.h" + +#include +#include +#include +#include + +#include "disk_notifier.h" +#include "ffrt_inner.h" +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudDiskService { +using namespace std; +namespace{ +constexpr uint32_t INIT_FLAGS = FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME | FAN_UNLIMITED_QUEUE; +constexpr uint32_t INIT_EVENT_FLAGS = O_RDONLY | O_LARGEFILE; +constexpr uint32_t MARK_FLAGS = FAN_MARK_ADD | FAN_MARK_FILESYSTEM; +constexpr uint64_t MARK_MASK = FAN_CREATE | FAN_DELETE | FAN_MOVED_FROM | FAN_MOVED_TO | FAN_ONDIR | FAN_CLOSE_WRITE; +const string MOUNT_PATH = "/data/service"; +const string PROC_SELF_FD = "/proc/self/fd/"; +const map SYNC_ROOTS = {{66666666, "/data/service/el2/100/hmdfs/account/files/Docs/Documents"}, + {11111111, "/data/service/el2/100/hmdfs/account/files/Docs/Download"}}; +const vector BLACK_PATHS = {"/data/service/el2/100/hmdfs/account/files/Docs/.Trash", + "/data/service/el2/100/hmdfs/account/files/Docs/.Recent", + "/data/service/el2/100/hmdfs/account/files/Docs/.thumbs"}; +} + +DiskMonitor &DiskMonitor::GetInstance() +{ + static DiskMonitor instance_; + return instance_; +} + +bool DiskMonitor::Init() +{ + if(!InitFanotify()){ + return false; + } + ffrt::submit([this] { this->CollectEvents(); }); + return true; +} + +bool DiskMonitor::InitFanotify() +{ + LOGI("init start"); + fanotifyFd_ = fanotify_init(INIT_FLAGS, INIT_EVENT_FLAGS); + if (fanotifyFd_ == -1) { + LOGE("disk monitor init failed, errno: %{public}d", errno); + return false; + } + if (fanotify_mark(fanotifyFd_, MARK_FLAGS, MARK_MASK, AT_FDCWD, MOUNT_PATH.c_str()) == -1) { + LOGE("fanotify_mark failed, errno: %{public}d", errno); + close(fanotifyFd_); + fanotifyFd_ = -1; + return false; + } + mountFp_ = opendir(MOUNT_PATH.c_str()); + if (mountFp_ == nullptr) { + LOGE("open dir failed, errno: %{public}d", errno); + close(fanotifyFd_); + fanotifyFd_ = -1; + return false; + } + mountFd_ = dirfd(mountFp_); + if (mountFd_ == -1) { + LOGE("get dirfd failed, errno: %{public}d", errno); + close(fanotifyFd_); + fanotifyFd_ = -1; + closedir(mountFp_); + mountFp_ = nullptr; + return false; + } + LOGI("Init end"); + return true; +} + +void DiskMonitor::CollectEvents() +{ + while (isRunning_) { + char eventsBuf[4096]{}; + ssize_t dataLen = read(fanotifyFd_, eventsBuf, sizeof(eventsBuf)); + if (dataLen == -1 && errno != EAGAIN) { + LOGE("read failed, errno: %{public}d", errno); + continue; + } + if (dataLen == 0) { + LOGI("no data to read"); + continue; + } + // TODO: check current user is active(unlock) + HandleEvents(mountFd_, eventsBuf, dataLen); + } +} + +void DiskMonitor::HandleEvents(int32_t mountFd, char eventsBuf[], size_t dataLen) +{ + for (struct fanotify_event_metadata *metaData = reinterpret_cast(eventsBuf); + FAN_EVENT_OK(metaData, dataLen); metaData = FAN_EVENT_NEXT(metaData, dataLen)) { + struct fanotify_event_info_fid *fID = reinterpret_cast(metaData + 1); + struct file_handle *fileHandle = reinterpret_cast(fID->handle); + if (fileHandle == nullptr) { + LOGE("fileHandle is null"); + continue; + } + + // get file name + string fileName; + if (!ExtractFileName(fID->hdr.info_type, fileName, fileHandle)) { + continue; + } + bool isDir = metaData->mask & FAN_ONDIR; + // other info + int eventFd = open_by_handle_at(mountFd, fileHandle, O_RDONLY); + if (eventFd == -1) { + LOGE("open_by_handle_at, errno: %{public}d", errno); + continue; + } + + string filePath = GetFilePath(eventFd, fileName); + if (filePath.empty()) { + close(eventFd); + continue; + } + // filePath = FolderAddSlash(isDir, filePath); + + EventProcess(metaData, filePath); + + close(eventFd); + } +} + +void DiskMonitor::EventProcess(struct fanotify_event_metadata *metaData, const string &filePath) +{ + if (metaData->mask & FAN_CREATE) { + HandleCreate(filePath); + } else if (metaData->mask & FAN_DELETE) { + HandleDelete(filePath); + } else if (metaData->mask & FAN_MOVED_FROM) { + HandleMoveFrom(filePath); + } else if (metaData->mask & FAN_MOVED_TO) { + HandleMoveTo(filePath); + } else if (metaData->mask & FAN_CLOSE_WRITE) { + HandleCloseWrite(filePath); + } + if (IsInSyncRoots(filePath) && !IsInBlackList(filePath)) { + LOGD("mask: %{public}llu, path: %{public}s", metaData->mask, filePath.c_str()); + } +} + +void DiskMonitor::HandleCreate(const std::string &filePath) +{ + int32_t syncRootIndex = GetSyncRootIndex(filePath); + if (syncRootIndex == -1) { + return; + } + auto eventInfo = EventInfo(userId_, syncRootIndex, OperationType::CREATE, filePath); + // POST EVENT + DiskNotifier::GetInstance().PostEvent(eventInfo); + PrintEventInfo(eventInfo); +} + +void DiskMonitor::HandleDelete(const std::string &filePath) +{ + int32_t syncRootIndex = GetSyncRootIndex(filePath); + if (syncRootIndex == -1) { + return; + } + auto eventInfo = EventInfo(userId_, syncRootIndex, OperationType::DELETE, filePath); + DiskNotifier::GetInstance().PostEvent(eventInfo); + PrintEventInfo(eventInfo); +} + +void DiskMonitor::HandleMoveFrom(const std::string &filePath) +{ + oldEventInfo_ = EventInfo(userId_, GetSyncRootIndex(filePath), OperationType::MOVE_FROM, filePath); +} + +// 1. old 不在同步根中,new 在同步根 => 通知 create->new +// 2. old 在同步根中,new 不在同步根中 => 通知 delete -> delete +// 3. old 不在同步根中,new 不在同步跟中 => 忽略 +// 4. old 在同步根中,new 在同步根中;同步根相同 -> 通知 move_from->old + move_to->new +// 4. old 在同步根中,new 在同步根中;同步根不相同 -> 通知 delete->old + create->new +void DiskMonitor::HandleMoveTo(const std::string &filePath) +{ + auto eventInfo = EventInfo(userId_, GetSyncRootIndex(filePath), OperationType::MOVE_TO, filePath); + do { + if (oldEventInfo_.syncRootIndex == -1) { + if (eventInfo.syncRootIndex == -1) { + break; + } + eventInfo.operateType = static_cast(OperationType::CREATE); + // POST EVENT + DiskNotifier::GetInstance().PostEvent(eventInfo); + PrintEventInfo(eventInfo); + break; + } + // oldEventInfo_->syncRootIndex != -1) + if (eventInfo.syncRootIndex == -1) { + oldEventInfo_.operateType = static_cast(OperationType::DELETE); + // POST DELETE oldEventInfo + DiskNotifier::GetInstance().PostEvent(oldEventInfo_); + PrintEventInfo(oldEventInfo_); + break; + } + if (oldEventInfo_.syncRootIndex == eventInfo.syncRootIndex) { + oldEventInfo_.operateType = static_cast(OperationType::MOVE_FROM); + eventInfo.operateType = static_cast(OperationType::MOVE_TO); + // POST MOVE_FROM oldEventInfo + // POST MOVE_TO eventInfo + DiskNotifier::GetInstance().PostEvent(oldEventInfo_); + DiskNotifier::GetInstance().PostEvent(eventInfo); + PrintEventInfo(oldEventInfo_); + PrintEventInfo(eventInfo); + break; + } + oldEventInfo_.operateType = static_cast(OperationType::DELETE); + eventInfo.operateType = static_cast(OperationType::CREATE); + // POST DELETE oldEventInfo + // POST CREATE eventInfo + DiskNotifier::GetInstance().PostEvent(oldEventInfo_); + DiskNotifier::GetInstance().PostEvent(eventInfo); + PrintEventInfo(oldEventInfo_); + PrintEventInfo(eventInfo); + } while (0); + oldEventInfo_.Reset(); +} + +void DiskMonitor::HandleCloseWrite(const std::string &filePath) +{ + int32_t syncRootIndex = GetSyncRootIndex(filePath); + if (syncRootIndex == -1) { + return; + } + auto eventInfo = EventInfo(userId_, syncRootIndex, OperationType::CLOSE_WRITE, filePath); + DiskNotifier::GetInstance().PostEvent(eventInfo); + PrintEventInfo(eventInfo); +} + +bool DiskMonitor::ExtractFileName(int type, string &fileName, struct file_handle *fileHandle) +{ + if (type == FAN_EVENT_INFO_TYPE_FID || type == FAN_EVENT_INFO_TYPE_DFID) { + fileName.clear(); + } else if (type == FAN_EVENT_INFO_TYPE_DFID_NAME) { + fileName = reinterpret_cast(fileHandle->f_handle + fileHandle->handle_bytes); + } else { + return false; + } + return true; +} + +string DiskMonitor::GetFilePath(int32_t eventFd, const string &fileName) +{ + char eventFilePath[PATH_MAX + 1]; + string procFdPath = PROC_SELF_FD + std::to_string(eventFd); + ssize_t pathLen = readlink(procFdPath.c_str(), eventFilePath, sizeof(eventFilePath) - 1); + if (pathLen == -1 || pathLen > PATH_MAX) { + LOGI("readlink failed , errno: %{public}d", errno); + return ""; + } + eventFilePath[pathLen] = '\0'; + + string filePath(eventFilePath); + if (!fileName.empty() && fileName.compare(".") != 0) { + filePath += "/" + fileName; + } + return filePath; +} + +int32_t DiskMonitor::GetSyncRootIndex(const std::string &filePath) +{ + for (auto &it : SYNC_ROOTS) { + if (filePath.find(it.second) == 0) { + return it.first; + } + } + return -1; +} + +string DiskMonitor::FolderAddSlash(bool isDir, const string &path) +{ + if (path.empty() || path.back() == '/') { + return path; + } + return isDir ? path + "/" : path; +} + +bool DiskMonitor::IsInSyncRoots(const string &path) +{ + for (auto &it : SYNC_ROOTS) { + if (path.find(it.second) == 0) { + return true; + } + } + return false; +} + +bool DiskMonitor::IsInBlackList(const string &path) +{ + + for (auto &it : BLACK_PATHS) { + if (path.find(it) == 0) { + return true; + } + } + return false; +} + +// debug +void DiskMonitor::PrintEventInfo(EventInfo info) +{ + LOGD("opt: %{public}d path: %{public}s name: %{public}s", info.operateType, info.path.c_str(), info.name.c_str()); +} +} // namespace OHOS::FileManagement::CloudDiskService \ No newline at end of file diff --git a/services/clouddiskservice/src/monitor/disk_notifier.cpp b/services/clouddiskservice/src/monitor/disk_notifier.cpp new file mode 100644 index 000000000..0878fe206 --- /dev/null +++ b/services/clouddiskservice/src/monitor/disk_notifier.cpp @@ -0,0 +1,75 @@ +/* + * 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. + */ +#include "disk_notifier.h" + +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudDiskService { +using namespace std; +namespace{ +constexpr uint32_t MAX_EVENT_NUM = 10 * 1000; +constexpr uint64_t NOTIFY_TIMEOUT_MS = 200; +} +DiskNotifier &DiskNotifier::GetInstance() +{ + static DiskNotifier instance_; + return instance_; +} + +void DiskNotifier::PostEvent(EventInfo eventInfo) +{ + // 1. list 为空,首次收到事件 -> 启动定时器 + // 2. list 到达最大容量 -> 通知事件 -> 重置定时器 + if (eventList_.size() > MAX_EVENT_NUM || eventList_.empty()) { + ffrt_timer_stop(ffrt_qos_default, handle_); + NotifyAllEvent(); + handle_ = ffrt_timer_start(ffrt_qos_default, NOTIFY_TIMEOUT_MS, this, CallBack, false); + } + { + lock_guard lock(mutex_); + // 最后一条 type path name 都相同,则仅仅更新时间 + if (!eventList_.empty() && eventList_.back().operateType == eventInfo.operateType && + eventList_.back().path == eventInfo.path && eventList_.back().name == eventInfo.name) { + eventList_.back().timestamp = eventInfo.timestamp; + return; + } + eventList_.push_back(eventInfo); + } +} + +void DiskNotifier::NotifyAllEvent() +{ + vector tempEventList; + { + lock_guard lock(mutex_); + if (eventList_.empty()) { + return; + } + eventList_.swap(tempEventList); + eventList_.clear(); + } + // call LOG_MOUDLE -> tempEventList; + LOGI("NOTIFY_ALL: size: %{public}zu", tempEventList.size()); +} + +void DiskNotifier::CallBack(void *data) +{ + if (data == nullptr) { + return; + } + auto notifier = reinterpret_cast(data); + notifier->NotifyAllEvent(); +} +} // namespace OHOS::FileManagement::CloudDiskService \ No newline at end of file diff --git a/services/clouddiskservice/src/seccomp_policy/BUILD.gn b/services/clouddiskservice/src/seccomp_policy/BUILD.gn new file mode 100644 index 000000000..3a2587f26 --- /dev/null +++ b/services/clouddiskservice/src/seccomp_policy/BUILD.gn @@ -0,0 +1,15 @@ +import("//build/config/components/init/seccomp/scripts/seccomp_policy_fixer.gni") + +ohos_prebuilt_seccomp("disk_monitor_seccomp_filter") { + sources = [ "clouddiskservice.seccomp.policy" ] + + filtername = "clouddiskservice" + + process_type = "system" + + part_name = "dfs_service" + subsystem_name = "filemanagement" + + install_enable = true + install_images = [ "system" ] +} diff --git a/services/clouddiskservice/src/seccomp_policy/clouddiskservice.seccomp.policy b/services/clouddiskservice/src/seccomp_policy/clouddiskservice.seccomp.policy new file mode 100644 index 000000000..ccb4fe499 --- /dev/null +++ b/services/clouddiskservice/src/seccomp_policy/clouddiskservice.seccomp.policy @@ -0,0 +1,341 @@ +# 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. + +# For now, it supports architechture of ['arm', 'arm64', 'riscv64']. + +@returnValue +TRAP + +@allowList +io_setup;all +io_destroy;all +io_submit;all +io_cancel;all +io_getevents;all +setxattr;all +lsetxattr;all +fsetxattr;all +getxattr;all +lgetxattr;all +fgetxattr;all +listxattr;all +llistxattr;all +flistxattr;all +removexattr;all +lremovexattr;all +fremovexattr;all +getcwd;all +eventfd2;all +epoll_create1;all +epoll_ctl;all +epoll_pwait;all +dup;all +dup3;all +fcntl;arm64 +inotify_init1;all +inotify_add_watch;all +inotify_rm_watch;all +ioctl;all +ioprio_set;arm64 +ioprio_get;arm64 +flock;all +mknodat;all +mkdirat;all +unlinkat;all +symlinkat;all +linkat;all +renameat;arm +renameat;arm64 +umount2;all +mount;all +pivot_root;all +statfs;arm64 +fstatfs;arm64 +truncate;all +ftruncate;arm64 +fallocate;all +faccessat;all +faccessat2;all +chdir;all +fchdir;all +chroot;all +fchmod;all +fchmodat;all +fchownat;all +fchown;arm64 +openat;all +close;all +pipe2;all +quotactl;all +getdents64;all +lseek;all +read;all +write;all +readv;all +writev;all +pread64;all +pwrite64;all +preadv;all +pwritev;all +sendfile;all +pselect6;all +ppoll;all +signalfd4;all +vmsplice;all +splice;all +tee;all +readlinkat;all +newfstatat;arm64 +fstat;arm64 +sync;all +fsync;all +fdatasync;all +sync_file_range;arm64 +timerfd_create;all +timerfd_settime;all +timerfd_gettime;all +utimensat;all +acct;all +capget;all +capset;all +personality;all +exit;all +exit_group;all +waitid;all +set_tid_address;all +unshare;all +futex;all +set_robust_list;all +get_robust_list;all +nanosleep;all +getitimer;all +setitimer;all +init_module;all +delete_module;all +timer_create;all +timer_gettime;all +timer_getoverrun;all +timer_settime;all +timer_delete;all +clock_settime;all +clock_gettime;all +clock_getres;all +clock_nanosleep;all +syslog;all +ptrace;all +sched_setparam;all +sched_setscheduler;all +sched_getscheduler;all +sched_getparam;all +sched_setaffinity;all +sched_getaffinity;all +sched_yield;all +sched_get_priority_max;all +sched_get_priority_min;all +sched_rr_get_interval;all +restart_syscall;all +kill;all +tkill;all +tgkill;all +sigaltstack;all +rt_sigsuspend;all +rt_sigaction;all +rt_sigprocmask;all +rt_sigpending;all +rt_sigtimedwait;all +rt_sigqueueinfo;all +rt_sigreturn;all +setpriority;all +getpriority;all +reboot;all +setregid;arm64 +setgid;arm64 +setreuid;arm64 +setuid;arm64 +setresuid;arm64 +getresuid;arm64 +setresgid;arm64 +getresgid;arm64 +setfsuid;all +setfsgid;all +times;all +setpgid;all +getpgid;all +getsid;all +setsid;all +getgroups;arm64 +setgroups;arm64 +uname;all +sethostname;all +setdomainname;all +getrlimit;arm64 +setrlimit;all +getrusage;all +umask;all +prctl;all +getcpu;all +gettimeofday;all +settimeofday;all +adjtimex;all +getpid;all +getppid;all +getuid;arm64 +geteuid;arm64 +getgid;arm64 +getegid;arm64 +gettid;all +sysinfo;all +semget;all +shmget;all +shmctl;all +shmat;all +shmdt;all +socket;all +socketpair;all +bind;all +listen;all +accept;all +connect;all +getsockname;all +getpeername;all +sendto;all +recvfrom;all +setsockopt;all +getsockopt;all +shutdown;all +sendmsg;all +recvmsg;all +readahead;all +brk;all +munmap;all +mremap;all +add_key;all +keyctl;all +clone;all +execve;all +mmap;arm64 +fadvise64;arm64 +mprotect;all +msync;all +mlock;all +munlock;all +mlockall;all +munlockall;all +mincore;all +madvise;all +rt_tgsigqueueinfo;all +perf_event_open;all +accept4;all +recvmmsg;all +wait4;all +prlimit64;all +clock_adjtime;all +syncfs;all +setns;all +sendmmsg;all +process_vm_readv;all +process_vm_writev;all +finit_module;all +sched_setattr;all +sched_getattr;all +renameat2;all +seccomp;all +getrandom;all +memfd_create;all +bpf;all +execveat;all +userfaultfd;all +membarrier;all +mlock2;all +copy_file_range;all +preadv2;all +pwritev2;all +statx;all +pidfd_send_signal;all +pidfd_open;all +close_range;all +pidfd_getfd;all +process_madvise;all +fork;arm +open;arm +unlink;arm +mknod;arm +chmod;arm +access;arm +rename;arm +mkdir;arm +rmdir;arm +pipe;arm +dup2;arm +sigaction;arm +symlink;arm +readlink;arm +stat;arm +sigreturn;arm +_llseek;arm +_newselect;arm +poll;arm +vfork;arm +ugetrlimit;arm +mmap2;arm +truncate64;arm +ftruncate64;arm +stat64;arm +fstat64;arm +lchown32;arm +getuid32;arm +getgid32;arm +geteuid32;arm +getegid32;arm +setreuid32;arm +setregid32;arm +chown32;arm +getgroups32;arm +setgroups32;arm +fchown32;arm +setresuid32;arm +getresuid32;arm +setresgid32;arm +getresgid32;arm +setuid32;arm +setgid32;arm +fcntl64;arm +sendfile64;arm +statfs64;arm +fstatfs64;arm +fadvise64_64;arm +fstatat64;arm +sync_file_range2;arm +clock_gettime64;arm +clock_settime64;arm +clock_adjtime64;arm +clock_getres_time64;arm +clock_nanosleep_time64;arm +timer_gettime64;arm +timer_settime64;arm +timerfd_gettime64;arm +timerfd_settime64;arm +utimensat_time64;arm +pselect6_time64;arm +ppoll_time64;arm +recvmmsg_time64;arm +semtimedop_time64;arm +rt_sigtimedwait_time64;arm +futex_time64;arm +sched_rr_get_interval_time64;arm +cacheflush;arm +set_tls;arm +mbind;all +fanotify_init;arm64 +fanotify_mark;arm64 +open_by_handle_at;arm64 diff --git a/utils/system/include/dfsu_access_token_helper.h b/utils/system/include/dfsu_access_token_helper.h index 3d7398930..f5697e320 100644 --- a/utils/system/include/dfsu_access_token_helper.h +++ b/utils/system/include/dfsu_access_token_helper.h @@ -19,6 +19,7 @@ #include namespace OHOS::FileManagement { +inline const std::string PERM_CLOUD_DISK_SERVICE = "ohos.permission.ACCESS_CLOUD_DISK_INFO"; inline const std::string PERM_CLOUD_SYNC_MANAGER = "ohos.permission.CLOUDFILE_SYNC_MANAGER"; inline const std::string PERM_CLOUD_SYNC = "ohos.permission.CLOUDFILE_SYNC"; inline const std::string PERM_AUTH_URI = "ohos.permission.PROXY_AUTHORIZATION_URI"; -- Gitee