diff --git a/distributedfile.gni b/distributedfile.gni index 2e8d8a0c1b8901c4cc35dc43bcfb4959e42ba503..d911e73d719c128789ebca3de0070ac21f9d1a85 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 = false 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 0000000000000000000000000000000000000000..b128c686476b82ed73207900d49cd6e19609747e --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/include/cloud_disk_service_callback_client.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_CLIENT_H +#define OHOS_FILEMGMT_CLOUD_DISK_SERVICE_CALLBACK_CLIENT_H + +#include "cloud_disk_service_callback.h" +#include "cloud_disk_service_callback_stub.h" + +namespace OHOS::FileManagement::CloudDiskService { +class CloudDiskServiceCallbackClient final : public CloudDiskServiceCallbackStub { +public: + explicit CloudDiskServiceCallbackClient(const std::shared_ptr &callback) + : callback_(callback) + { + } + + void OnChangeData(const std::string &sandboxPath, const std::vector &changeData) override; + +private: + std::shared_ptr callback_{nullptr}; +}; +} // 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 0000000000000000000000000000000000000000..452e0013d03f62b894ff031f67ba322bd734e8d0 --- /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 0000000000000000000000000000000000000000..eb838083238f786295a5a4db1412f0691ff433da --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/include/cloud_disk_service_manager_impl.h @@ -0,0 +1,59 @@ +/* + * 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_callback_client.h" +#include "cloud_disk_service_manager.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 &syncFolder, + const std::shared_ptr callback) override; + int32_t UnregisterSyncFolderChanges(const std::string &syncFolder) override; + int32_t GetSyncFolderChanges(const std::string &syncFolder, + uint64_t count, + uint64_t startUsn, + ChangesResult &changesResult) override; + int32_t SetFileSyncStates(const std::string &syncFolder, + const std::vector &fileSyncStates, + std::vector &failedList) override; + int32_t GetFileSyncStates(const std::string &syncFolder, + const std::vector &pathArray, + std::vector &resultList) override; + int32_t RegisterSyncFolder(int32_t userId, const std::string &bundleName, const std::string &path) override; + int32_t UnregisterSyncFolder(int32_t userId, const std::string &bundleName, const std::string &path) override; + + int32_t UnregisterForSa(int32_t userId, 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 0000000000000000000000000000000000000000..11ea4e20c930d5ed742baa4eef5dce37d8f4fe3a --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/include/service_proxy.h @@ -0,0 +1,35 @@ +/* + * 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(); + +private: + 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 0000000000000000000000000000000000000000..0c2d39644c2ef54f3a2223c55ebd05f6bd858ad8 --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_common.cpp @@ -0,0 +1,343 @@ +/* + * 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 { + +bool FileSyncState::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteString(path)) { + LOGE("failed to write path"); + return false; + } + + if (!parcel.WriteInt32(static_cast(state))) { + LOGE("failed to write state"); + 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(path)) { + LOGE("failed to write path"); + return false; + } + + int32_t readState = 0; + if (!parcel.ReadInt32(readState)) { + LOGE("failed to write state"); + return false; + } + state = 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(relativePath)) { + LOGE("failed to write relativePath"); + return false; + } + + if (!parcel.WriteUint8(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(relativePath)) { + LOGE("failed to read relativePath"); + return false; + } + + uint8_t readType = 0; + if (!parcel.ReadUint8(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 nextUsn"); + return false; + } + + if (!parcel.WriteInt32(static_cast(isEof))) { + LOGE("failed to write isEof"); + return false; + } + + if (!parcel.WriteInt32(static_cast(changesData.size()))) { + LOGE("failed to write changeData"); + 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 nextUSN"); + return false; + } + + int32_t readIsEof = 0; + if (!parcel.ReadInt32(readIsEof)) { + LOGE("failed to read isEof"); + return false; + } + isEof = readIsEof; + + int32_t size = 0; + if (!parcel.ReadInt32(size)) { + LOGE("failed to read changeData size"); + return false; + } + for (int32_t i = 0; i < size; ++i) { + ChangeData changeData; + changeData.ReadFromParcel(parcel); + changesData.push_back(changeData); + } + + return true; +} + +bool FailedList::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteString(path)) { + LOGE("failed to write path"); + return false; + } + + if (!parcel.WriteInt32(static_cast(error))) { + LOGE("failed to write error"); + return false; + } + + return true; +} + +FailedList *FailedList::Unmarshalling(Parcel &parcel) +{ + FailedList *info = new (std::nothrow) FailedList(); + if ((info != nullptr) && (!info->ReadFromParcel(parcel))) { + LOGW("read from parcel failed"); + delete info; + info = nullptr; + } + return info; +} + +bool FailedList::ReadFromParcel(Parcel &parcel) +{ + if (!parcel.ReadString(path)) { + LOGE("failed to read path"); + return false; + } + + int32_t readError = 0; + if (!parcel.ReadInt32(readError)) { + LOGE("failed to write errno"); + return false; + } + error = static_cast(readError); + + return true; +} + +bool ResultList::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteInt32(static_cast(isSuccess))) { + LOGE("failed to write isSuccess"); + return false; + } + + if (!parcel.WriteInt32(static_cast(state))) { + LOGE("failed to write state"); + return false; + } + + if (!parcel.WriteString(path)) { + LOGE("failed to write path"); + return false; + } + + if (!parcel.WriteInt32(static_cast(error))) { + LOGE("failed to write error"); + return false; + } + + return true; +} + +ResultList *ResultList::Unmarshalling(Parcel &parcel) +{ + ResultList *info = new (std::nothrow) ResultList(); + if ((info != nullptr) && (!info->ReadFromParcel(parcel))) { + LOGW("read from parcel failed"); + delete info; + info = nullptr; + } + return info; +} + +bool ResultList::ReadFromParcel(Parcel &parcel) +{ + int32_t readIsSuccess = 0; + if (!parcel.ReadInt32(readIsSuccess)) { + LOGE("failed to write isSuccess"); + return false; + } + isSuccess = readIsSuccess; + + int32_t readState = 0; + if (!parcel.ReadInt32(readState)) { + LOGE("failed to write state"); + return false; + } + state = static_cast(readState); + + if (!parcel.ReadString(path)) { + LOGE("failed to write path"); + return false; + } + + int32_t readError = 0; + if (!parcel.ReadInt32(readError)) { + LOGE("failed to write state"); + return false; + } + error = static_cast(readError); + + 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 0000000000000000000000000000000000000000..724b9da696f34efb9fde5e0c8e12dbdd89a01284 --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_callback_client.cpp @@ -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. + */ + +#include "cloud_disk_service_callback_client.h" +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudDiskService { + +void CloudDiskServiceCallbackClient::OnChangeData(const std::string &sandboxPath, + const std::vector &changeData) +{ + if (callback_ == nullptr) { + LOGE("callback_ is nullptr"); + return; + } + callback_->OnChangeData(sandboxPath, changeData); +} +} // 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 0000000000000000000000000000000000000000..28f16252936532382c9382d472571b71b5590523 --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_callback_stub.cpp @@ -0,0 +1,70 @@ +/* + * 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 "cloud_disk_service_error.h" +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudDiskService { +using namespace std; + +CloudDiskServiceCallbackStub::CloudDiskServiceCallbackStub() +{ + opToInterfaceMap_[SERVICE_CMD_ON_CHANGE_DATA] = [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_INTERNAL_ERROR; + } + 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) +{ + std::vector changesData; + + std::string sandboxPath = data.ReadString(); + 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_INVALID_ARG; + } + changesData.push_back(*value); + } + + OnChangeData(sandboxPath, changesData); + LOGI("HandleOnChangeData end"); + 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 0000000000000000000000000000000000000000..808ff75d89c515e6e61d9ef1859af1b4838ae9f7 --- /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 0000000000000000000000000000000000000000..f9c69ac6bf0255522c8330f9fe265e775127dc56 --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_manager_impl.cpp @@ -0,0 +1,229 @@ +/* + * 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 "cloud_disk_service_callback_client.h" +#include "cloud_disk_service_error.h" +#include "cloud_file_utils.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 &syncFolder, + const std::shared_ptr callback) +{ +#ifdef SUPPORT_CLOUD_DISK_SERVICE + if (!callback) { + LOGE("callback is null"); + return E_INVALID_ARG; + } + auto serviceProxy = ServiceProxy::GetInstance(); + if (!serviceProxy) { + LOGE("proxy is null"); + return E_IPC_FAILED; + } + auto ret = serviceProxy->RegisterSyncFolderChangesInner( + syncFolder, sptr(new (std::nothrow) CloudDiskServiceCallbackClient(callback))); + { + unique_lock lock(callbackMutex_); + callback_ = callback; + } + SetDeathRecipient(serviceProxy->AsObject()); + LOGI("RegisterSyncFolderChanges ret %{public}d", ret); + return ret; +#else + return E_NOT_SUPPORTED; +#endif +} + +int32_t CloudDiskServiceManagerImpl::UnregisterSyncFolderChanges(const std::string &syncFolder) +{ +#ifdef SUPPORT_CLOUD_DISK_SERVICE + auto serviceProxy = ServiceProxy::GetInstance(); + if (!serviceProxy) { + LOGE("proxy is null"); + return E_IPC_FAILED; + } + + auto ret = serviceProxy->UnregisterSyncFolderChangesInner(syncFolder); + { + unique_lock lock(callbackMutex_); + callback_ = nullptr; + } + SetDeathRecipient(serviceProxy->AsObject()); + LOGI("UnregisterSyncFolderChanges ret %{public}d", ret); + return ret; +#else + return E_NOT_SUPPORTED; +#endif +} + +int32_t CloudDiskServiceManagerImpl::GetSyncFolderChanges(const std::string &syncFolder, + 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_IPC_FAILED; + } + + auto ret = serviceProxy->GetSyncFolderChangesInner(syncFolder, count, startUsn, changesResult); + SetDeathRecipient(serviceProxy->AsObject()); + LOGI("GetSyncFolderChangesInner ret %{public}d", ret); + return ret; +#else + return E_NOT_SUPPORTED; +#endif +} + +int32_t CloudDiskServiceManagerImpl::SetFileSyncStates(const std::string &syncFolder, + 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_IPC_FAILED; + } + + auto ret = serviceProxy->SetFileSyncStatesInner(syncFolder, fileSyncStates, failedList); + SetDeathRecipient(serviceProxy->AsObject()); + LOGI("SetFileSyncState, ret %{public}d", ret); + return ret; +#else + return E_NOT_SUPPORTED; +#endif +} + +int32_t CloudDiskServiceManagerImpl::GetFileSyncStates(const std::string &syncFolder, + const std::vector &pathArray, + 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_IPC_FAILED; + } + + auto ret = serviceProxy->GetFileSyncStatesInner(syncFolder, pathArray, resultList); + SetDeathRecipient(serviceProxy->AsObject()); + LOGI("GetFileSyncState, ret %{public}d", ret); + return ret; +#else + return E_NOT_SUPPORTED; +#endif +} + +int32_t CloudDiskServiceManagerImpl::RegisterSyncFolder(int32_t userId, + const std::string &bundleName, + const std::string &path) +{ +#ifdef SUPPORT_CLOUD_DISK_SERVICE + LOGI("start RegisterSyncFolder in impl"); + auto serviceProxy = ServiceProxy::GetInstance(); + if (!serviceProxy) { + LOGE("proxy is null"); + return E_IPC_FAILED; + } + + auto ret = serviceProxy->RegisterSyncFolderInner(userId, bundleName, path); + SetDeathRecipient(serviceProxy->AsObject()); + LOGI("RegisterSyncFolder, ret %{public}d", ret); + return ret; +#else + return E_NOT_SUPPORTED; +#endif +} + +int32_t CloudDiskServiceManagerImpl::UnregisterSyncFolder(int32_t userId, + const std::string &bundleName, + const std::string &path) +{ +#ifdef SUPPORT_CLOUD_DISK_SERVICE + LOGI("start UnregisterSyncFolder in impl"); + auto serviceProxy = ServiceProxy::GetInstance(); + if (!serviceProxy) { + LOGE("proxy is null"); + return E_IPC_FAILED; + } + + auto ret = serviceProxy->UnregisterSyncFolderInner(userId, bundleName, path); + SetDeathRecipient(serviceProxy->AsObject()); + LOGI("UnregisterSyncFolder, ret %{public}d", ret); + return ret; +#else + return E_NOT_SUPPORTED; +#endif +} + +int32_t CloudDiskServiceManagerImpl::UnregisterForSa(int32_t userId, const std::string &path) +{ +#ifdef SUPPORT_CLOUD_DISK_SERVICE + LOGI("start UnregisterForSa in impl"); + auto serviceProxy = ServiceProxy::GetInstance(); + if (!serviceProxy) { + LOGE("proxy is null"); + return E_IPC_FAILED; + } + + auto ret = serviceProxy->UnregisterForSaInner(userId, path); + SetDeathRecipient(serviceProxy->AsObject()); + LOGI("UnregisterForSa, ret %{public}d", ret); + return ret; +#else + return E_NOT_SUPPORTED; +#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 0000000000000000000000000000000000000000..d9fbba2df06cbeccce41ed4945f47aec0f79bccd --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/src/cloud_disk_service_task_manager.cpp @@ -0,0 +1,101 @@ +/* + * 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; + +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); + } + } +} + +void CloudDiskServiceTaskManager::StartTask() +{ + std::lock_guard lock(taskMapsMutex_); +} + +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; +} +} // 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 0000000000000000000000000000000000000000..0fd3937975808d2966e4ab46ccbec8352152aa01 --- /dev/null +++ b/frameworks/native/clouddiskservice_kit_inner/src/service_proxy.cpp @@ -0,0 +1,64 @@ +/* + * 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; + +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; + } + return serviceProxy_; +} + +void ServiceProxy::InvaildInstance() +{ + LOGI("invalid instance"); + unique_lock lock(instanceMutex_); + serviceProxy_ = nullptr; +} +} // 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 0000000000000000000000000000000000000000..5fac61981921ec0cecb8e92f8bfbb7a0a69c71c2 --- /dev/null +++ b/interfaces/inner_api/native/clouddiskservice_kit_inner/BUILD.gn @@ -0,0 +1,106 @@ +# 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 + } + include_dirs = [ + "${distributedfile_path}/services/clouddiskservice/utils/include", + ] + 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_client.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", + ] + + 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 0000000000000000000000000000000000000000..46606f9e04fed50ecde62b4381f2808d7bcd5223 --- /dev/null +++ b/interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_common.h @@ -0,0 +1,112 @@ +/* + * 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 { + +/* +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 : uint8_t { + CREATE = 0, + DELETE, + MOVE_FROM, + MOVE_TO, + CLOSE_WRITE, + SYNC_FOLDER_INVALID, + OPERATION_MAX, +}; + +struct FileSyncState : public Parcelable { + std::string path; + SyncState state; + 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 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; + bool isEof; + std::vector changesData; + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static ChangesResult *Unmarshalling(Parcel &parcel); +}; + +enum class ErrorReason { + INVALID_ARGUMENT = 0, + NO_SUCH_FILE, + NO_SPACE_LEFT, + OUT_OF_RANGE, + NO_SYNC_STATE, +}; + +struct FailedList : public Parcelable { + std::string path; + ErrorReason error; + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static FailedList *Unmarshalling(Parcel &parcel); +}; + +struct ResultList : public FailedList { + bool isSuccess; + SyncState state; + bool ReadFromParcel(Parcel &parcel); + bool Marshalling(Parcel &parcel) const override; + static ResultList *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 0000000000000000000000000000000000000000..112d6457ff9762bd38730792a05d0675cc13e065 --- /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(const std::string &sandboxPath, const 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 0000000000000000000000000000000000000000..c4e8f03dbb62cc61a5fcd275262f89cba540ba28 --- /dev/null +++ b/interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_service_manager.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_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 &syncFolder, + const std::shared_ptr callback) = 0; + virtual int32_t UnregisterSyncFolderChanges(const std::string &syncFolder) = 0; + virtual int32_t GetSyncFolderChanges(const std::string &syncFolder, + uint64_t count, + uint64_t startUsn, + ChangesResult &changesResult) = 0; + virtual int32_t SetFileSyncStates(const std::string &syncFolder, + const std::vector &fileSyncStates, + std::vector &failedList) = 0; + virtual int32_t GetFileSyncStates(const std::string &syncFolder, + const std::vector &pathArray, + std::vector &resultList) = 0; + virtual int32_t RegisterSyncFolder(int32_t userId, const std::string &bundleName, const std::string &path) = 0; + virtual int32_t UnregisterSyncFolder(int32_t userId, const std::string &bundleName, const std::string &path) = 0; + + virtual int32_t UnregisterForSa(int32_t userId, 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 0000000000000000000000000000000000000000..a311e7ef4b3b8a066b4010657b91297e5b8c9491 --- /dev/null +++ b/interfaces/inner_api/native/clouddiskservice_kit_inner/cloud_disk_service_task_manager.h @@ -0,0 +1,70 @@ +/* + * 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 "ffrt_inner.h" +#include +#include + +namespace OHOS::FileManagement::CloudDiskService { +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 0000000000000000000000000000000000000000..ad53374d3e1ad9300120cd29d1717066d44414a6 --- /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_CHANGE_DATA = 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 0000000000000000000000000000000000000000..bd5b79a3fb85de81c0f4ebb10a6d4b77d32d9f29 --- /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 0000000000000000000000000000000000000000..62f22ff23631f03be7e6369976ae665a4a74a4cc --- /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 0eec280de075da48f950ae818cfb7345b8d178d0..01f49084f2f1422b4ff3a7af440fbbe24a60eb21 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 0000000000000000000000000000000000000000..cfde3e2ec5395fe2d32501ef944adcccbd24776b --- /dev/null +++ b/services/clouddiskservice.cfg @@ -0,0 +1,15 @@ +{ + "services": [ { + "name": "clouddiskservice", + "path": ["/system/bin/sa_main", "/system/profile/clouddiskservice.json"], + "uid": "6161", + "gid": ["cloud_disk_service", "dfs", "file_manager"], + "sandbox": 0, + "secon": "u:r:clouddiskservice:s0", + "caps": ["CAP_SYS_ADMIN", "CAP_DAC_READ_SEARCH"], + "apl": "system_basic", + "permission" : [ + "ohos.permission.ACCESS_CLOUD_DISK_INFO" + ] + }] +} \ No newline at end of file diff --git a/utils/system/include/dfsu_access_token_helper.h b/utils/system/include/dfsu_access_token_helper.h index 3d7398930178a0ee13ac1f6bfbca8a08b7cdfc23..f5697e3202afaea4ee886c84c35da92a68fc87b4 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";