From e6c8216f6423d74b5d6b0f0f8d4ea370f62746c9 Mon Sep 17 00:00:00 2001 From: Lihong Kou Date: Mon, 15 May 2023 04:43:18 +0000 Subject: [PATCH 1/3] cloud: add headers for download file Signed-off-by: Lihong Kou --- .../cloud_downloaded_callback_client.h | 33 ++++++++++++++++ .../include/cloud_downloaded_callback_stub.h | 39 +++++++++++++++++++ .../include/cloud_process_callback_client.h | 33 ++++++++++++++++ .../include/cloud_process_callback_stub.h | 39 +++++++++++++++++++ .../cloud_downloaded_callback.h | 29 ++++++++++++++ .../cloud_process_callback.h | 29 ++++++++++++++ .../cloudsync_kit_inner/cloud_sync_manager.h | 2 + .../i_cloud_downloaded_callback.h | 33 ++++++++++++++++ .../i_cloud_process_callback.h | 33 ++++++++++++++++ 9 files changed, 270 insertions(+) create mode 100644 frameworks/native/cloudsync_kit_inner/include/cloud_downloaded_callback_client.h create mode 100644 frameworks/native/cloudsync_kit_inner/include/cloud_downloaded_callback_stub.h create mode 100644 frameworks/native/cloudsync_kit_inner/include/cloud_process_callback_client.h create mode 100644 frameworks/native/cloudsync_kit_inner/include/cloud_process_callback_stub.h create mode 100644 interfaces/inner_api/native/cloudsync_kit_inner/cloud_downloaded_callback.h create mode 100644 interfaces/inner_api/native/cloudsync_kit_inner/cloud_process_callback.h create mode 100644 interfaces/inner_api/native/cloudsync_kit_inner/i_cloud_downloaded_callback.h create mode 100644 interfaces/inner_api/native/cloudsync_kit_inner/i_cloud_process_callback.h diff --git a/frameworks/native/cloudsync_kit_inner/include/cloud_downloaded_callback_client.h b/frameworks/native/cloudsync_kit_inner/include/cloud_downloaded_callback_client.h new file mode 100644 index 000000000..271f0f4bc --- /dev/null +++ b/frameworks/native/cloudsync_kit_inner/include/cloud_downloaded_callback_client.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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_DOWNLOADED_CALLBACK_CLIENT_H +#define OHOS_FILEMGMT_CLOUD_DOWNLOADED_CALLBACK_CLIENT_H + +#include "cloud_downloaded_callback_stub.h" + +namespace OHOS::FileManagement::CloudSync { +class CloudDownloadedCallbackClient final : public CloudDownloadedCallbackStub { +public: + explicit CloudDownloadedCallbackClient(const std::shared_ptr &callback) : callback_(callback) {} + + void OnDownloadedResult(int32_t result) override; + +private: + std::shared_ptr callback_; +}; +} // namespace OHOS::FileManagement::CloudSync + +#endif // OHOS_FILEMGMT_CLOUD_DOWNLOADED_CALLBACK_CLIENT_H diff --git a/frameworks/native/cloudsync_kit_inner/include/cloud_downloaded_callback_stub.h b/frameworks/native/cloudsync_kit_inner/include/cloud_downloaded_callback_stub.h new file mode 100644 index 000000000..db2184833 --- /dev/null +++ b/frameworks/native/cloudsync_kit_inner/include/cloud_downloaded_callback_stub.h @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2023 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_DOWLOADED_CALLBACK_STUB_H +#define OHOS_FILEMGMT_CLOUD_DOWLOADED_CALLBACK_STUB_H + +#include + +#include "i_cloud_downloaded_callback.h" +#include "iremote_stub.h" + +namespace OHOS::FileManagement::CloudSync { +class CloudDownloadedCallbackStub : public IRemoteStub { +public: + CloudDownloadedCallbackStub(); + virtual ~CloudDownloadedCallbackStub() = default; + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + using ServiceInterface = int32_t (CloudDownloadedCallbackStub::*)(MessageParcel &data, MessageParcel &reply); + std::map opToInterfaceMap_; + + int32_t HandleOnDownloadedResult(MessageParcel &data, MessageParcel &reply); +}; +} // namespace OHOS::FileManagement::CloudSync + +#endif // OHOS_FILEMGMT_CLOUD_DOWNLOADED_CALLBACK_STUB_H diff --git a/frameworks/native/cloudsync_kit_inner/include/cloud_process_callback_client.h b/frameworks/native/cloudsync_kit_inner/include/cloud_process_callback_client.h new file mode 100644 index 000000000..a58d7d8fb --- /dev/null +++ b/frameworks/native/cloudsync_kit_inner/include/cloud_process_callback_client.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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_PROCESS_CALLBACK_CLIENT_H +#define OHOS_FILEMGMT_CLOUD_PROCESS_CALLBACK_CLIENT_H + +#include "cloud_process_callback_stub.h" + +namespace OHOS::FileManagement::CloudSync { +class CloudProcessCallbackClient final : public CloudProcessCallbackStub { +public: + explicit CloudProcessCallbackClient(const std::shared_ptr &callback) : callback_(callback) {} + + void OnDownloadProcess(int64_t downloadedSize, int64_t totalSize) override; + +private: + std::shared_ptr callback_; +}; +} // namespace OHOS::FileManagement::CloudSync + +#endif // OHOS_FILEMGMT_CLOUD_PROCESS_CALLBACK_CLIENT_H diff --git a/frameworks/native/cloudsync_kit_inner/include/cloud_process_callback_stub.h b/frameworks/native/cloudsync_kit_inner/include/cloud_process_callback_stub.h new file mode 100644 index 000000000..9ee18fdce --- /dev/null +++ b/frameworks/native/cloudsync_kit_inner/include/cloud_process_callback_stub.h @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2023 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_PROCESS_CALLBACK_STUB_H +#define OHOS_FILEMGMT_CLOUD_PROCESS_CALLBACK_STUB_H + +#include + +#include "i_cloud_process_callback.h" +#include "iremote_stub.h" + +namespace OHOS::FileManagement::CloudSync { +class CloudProcessCallbackStub : public IRemoteStub { +public: + CloudProcessCallbackStub(); + virtual ~CloudProcessCallbackStub() = default; + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + using ServiceInterface = int32_t (CloudProcessCallbackStub::*)(MessageParcel &data, MessageParcel &reply); + std::map opToInterfaceMap_; + + int32_t HandleOnProcess(MessageParcel &data, MessageParcel &reply); +}; +} // namespace OHOS::FileManagement::CloudSync + +#endif // OHOS_FILEMGMT_CLOUD_PROCESS_CALLBACK_STUB_H diff --git a/interfaces/inner_api/native/cloudsync_kit_inner/cloud_downloaded_callback.h b/interfaces/inner_api/native/cloudsync_kit_inner/cloud_downloaded_callback.h new file mode 100644 index 000000000..315e28caf --- /dev/null +++ b/interfaces/inner_api/native/cloudsync_kit_inner/cloud_downloaded_callback.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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_DOWNLOADED_CALLBACK_H +#define OHOS_FILEMGMT_CLOUD_DOWNLOADED_CALLBACK_H + +#include + +namespace OHOS::FileManagement::CloudSync { +class CloudDownloadedCallback { +public: + virtual ~CloudDownloadedCallback() = default; + virtual void OnDownloadedResult(int32_t result) = 0; +}; +} // namespace OHOS::FileManagement::CloudSync + +#endif // OHOS_FILEMGMT_CLOUD_DOWNLOADED_CALLBACK_H diff --git a/interfaces/inner_api/native/cloudsync_kit_inner/cloud_process_callback.h b/interfaces/inner_api/native/cloudsync_kit_inner/cloud_process_callback.h new file mode 100644 index 000000000..0cb0272c6 --- /dev/null +++ b/interfaces/inner_api/native/cloudsync_kit_inner/cloud_process_callback.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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_PROCESS_CALLBACK_H +#define OHOS_FILEMGMT_CLOUD_PROCESS_CALLBACK_H + +#include + +namespace OHOS::FileManagement::CloudSync { +class CloudProcessCallback { +public: + virtual ~CloudProcessCallback() = default; + virtual void OnDownloadProcess(int64_t downloadedSize, int64_t totalSize) = 0; +}; +} // namespace OHOS::FileManagement::CloudSync + +#endif // OHOS_FILEMGMT_CLOUD_PROCESS_CALLBACK_H diff --git a/interfaces/inner_api/native/cloudsync_kit_inner/cloud_sync_manager.h b/interfaces/inner_api/native/cloudsync_kit_inner/cloud_sync_manager.h index b6d34e582..e224f7d8d 100644 --- a/interfaces/inner_api/native/cloudsync_kit_inner/cloud_sync_manager.h +++ b/interfaces/inner_api/native/cloudsync_kit_inner/cloud_sync_manager.h @@ -18,6 +18,8 @@ #include +#include "cloud_downloaded_callback.h" +#include "cloud_process_callback.h" #include "cloud_sync_callback.h" #include "cloud_sync_common.h" diff --git a/interfaces/inner_api/native/cloudsync_kit_inner/i_cloud_downloaded_callback.h b/interfaces/inner_api/native/cloudsync_kit_inner/i_cloud_downloaded_callback.h new file mode 100644 index 000000000..685b08110 --- /dev/null +++ b/interfaces/inner_api/native/cloudsync_kit_inner/i_cloud_downloaded_callback.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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_DOWNLOADED_CALLBACK_H +#define OHOS_FILEMGMT_I_CLOUD_DOWNLOADED_CALLBACK_H + +#include "cloud_downloaded_callback.h" +#include "iremote_broker.h" + +namespace OHOS::FileManagement::CloudSync { +class ICloudDownloadedCallback : public CloudDownloadedCallback, public IRemoteBroker { +public: + enum { + SERVICE_CMD_ON_DOWNLOADED = 0, + }; + + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Filemanagement.Dfs.ICloudDownloadedCallback") +}; +} // namespace OHOS::FileManagement::CloudSync + +#endif // OHOS_FILEMGMT_I_CLOUD_DOWNLOADED_CALLBACK_H diff --git a/interfaces/inner_api/native/cloudsync_kit_inner/i_cloud_process_callback.h b/interfaces/inner_api/native/cloudsync_kit_inner/i_cloud_process_callback.h new file mode 100644 index 000000000..1eb3aa8c1 --- /dev/null +++ b/interfaces/inner_api/native/cloudsync_kit_inner/i_cloud_process_callback.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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_PROCESS_CALLBACK_H +#define OHOS_FILEMGMT_I_CLOUD_PROCESS_CALLBACK_H + +#include "cloud_process_callback.h" +#include "iremote_broker.h" + +namespace OHOS::FileManagement::CloudSync { +class ICloudProcessCallback : public CloudProcessCallback, public IRemoteBroker { +public: + enum { + SERVICE_CMD_ON_PROCESS = 0, + }; + + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Filemanagement.Dfs.ICloudProcessCallback") +}; +} // namespace OHOS::FileManagement::CloudSync + +#endif // OHOS_FILEMGMT_I_CLOUD_PROCESS_CALLBACK_H -- Gitee From 8d0c5c57564d77c84533f72d585b0959bb540a5a Mon Sep 17 00:00:00 2001 From: Lihong Kou Date: Mon, 15 May 2023 04:45:53 +0000 Subject: [PATCH 2/3] cloud: add inner framework for download file Signed-off-by: Lihong Kou --- .../src/cloud_downloaded_callback_client.cpp | 31 +++++++++ .../src/cloud_downloaded_callback_stub.cpp | 50 +++++++++++++++ .../src/cloud_process_callback_client.cpp | 31 +++++++++ .../src/cloud_process_callback_stub.cpp | 51 +++++++++++++++ .../native/cloudsync_kit_inner/BUILD.gn | 4 ++ services/cloudsyncservice/BUILD.gn | 2 + .../ipc/cloud_downloaded_callback_proxy.h | 35 +++++++++++ .../ipc/cloud_process_callback_proxy.h | 35 +++++++++++ .../ipc/cloud_downloaded_callback_proxy.cpp | 59 +++++++++++++++++ .../src/ipc/cloud_process_callback_proxy.cpp | 63 +++++++++++++++++++ 10 files changed, 361 insertions(+) create mode 100644 frameworks/native/cloudsync_kit_inner/src/cloud_downloaded_callback_client.cpp create mode 100644 frameworks/native/cloudsync_kit_inner/src/cloud_downloaded_callback_stub.cpp create mode 100644 frameworks/native/cloudsync_kit_inner/src/cloud_process_callback_client.cpp create mode 100644 frameworks/native/cloudsync_kit_inner/src/cloud_process_callback_stub.cpp create mode 100644 services/cloudsyncservice/include/ipc/cloud_downloaded_callback_proxy.h create mode 100644 services/cloudsyncservice/include/ipc/cloud_process_callback_proxy.h create mode 100644 services/cloudsyncservice/src/ipc/cloud_downloaded_callback_proxy.cpp create mode 100644 services/cloudsyncservice/src/ipc/cloud_process_callback_proxy.cpp diff --git a/frameworks/native/cloudsync_kit_inner/src/cloud_downloaded_callback_client.cpp b/frameworks/native/cloudsync_kit_inner/src/cloud_downloaded_callback_client.cpp new file mode 100644 index 000000000..9f7dbd434 --- /dev/null +++ b/frameworks/native/cloudsync_kit_inner/src/cloud_downloaded_callback_client.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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_downloaded_callback_client.h" +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudSync { +using namespace std; + +void CloudDownloadedCallbackClient::OnDownloadedResult(int32_t result) +{ + if (!callback_) { + LOGE("callback_ is null, maybe not registered"); + return; + } + callback_->OnDownloadedResult(result); +} + +} // namespace OHOS::FileManagement::CloudSync diff --git a/frameworks/native/cloudsync_kit_inner/src/cloud_downloaded_callback_stub.cpp b/frameworks/native/cloudsync_kit_inner/src/cloud_downloaded_callback_stub.cpp new file mode 100644 index 000000000..229dabc60 --- /dev/null +++ b/frameworks/native/cloudsync_kit_inner/src/cloud_downloaded_callback_stub.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2023 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_downloaded_callback_stub.h" +#include "dfs_error.h" +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudSync { +using namespace std; + +CloudDownloadedCallbackStub::CloudDownloadedCallbackStub() +{ + opToInterfaceMap_[SERVICE_CMD_ON_DOWNLOADED] = &CloudDownloadedCallbackStub::HandleOnDownloadedResult; +} + +int32_t CloudDownloadedCallbackStub::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); + } + return (this->*(interfaceIndex->second))(data, reply); +} + +int32_t CloudDownloadedCallbackStub::HandleOnDownloadedResult(MessageParcel &data, MessageParcel &reply) +{ + int32_t result = data.ReadInt32(); + OnDownloadedResult(result); + return E_OK; +} +} // namespace OHOS::FileManagement::CloudSync diff --git a/frameworks/native/cloudsync_kit_inner/src/cloud_process_callback_client.cpp b/frameworks/native/cloudsync_kit_inner/src/cloud_process_callback_client.cpp new file mode 100644 index 000000000..137ad0c29 --- /dev/null +++ b/frameworks/native/cloudsync_kit_inner/src/cloud_process_callback_client.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023 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_process_callback_client.h" +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudSync { +using namespace std; + +void CloudProcessCallbackClient::OnDownloadProcess(int64_t downloadedSize, int64_t totalSize) +{ + if (!callback_) { + LOGE("callback_ is null, maybe not registered"); + return; + } + callback_->OnDownloadProcess(downloadedSize, totalSize); +} + +} // namespace OHOS::FileManagement::CloudSync diff --git a/frameworks/native/cloudsync_kit_inner/src/cloud_process_callback_stub.cpp b/frameworks/native/cloudsync_kit_inner/src/cloud_process_callback_stub.cpp new file mode 100644 index 000000000..3be742f20 --- /dev/null +++ b/frameworks/native/cloudsync_kit_inner/src/cloud_process_callback_stub.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 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_process_callback_stub.h" +#include "dfs_error.h" +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudSync { +using namespace std; + +CloudProcessCallbackStub::CloudProcessCallbackStub() +{ + opToInterfaceMap_[SERVICE_CMD_ON_PROCESS] = &CloudProcessCallbackStub::HandleOnProcess; +} + +int32_t CloudProcessCallbackStub::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); + } + return (this->*(interfaceIndex->second))(data, reply); +} + +int32_t CloudProcessCallbackStub::HandleOnProcess(MessageParcel &data, MessageParcel &reply) +{ + int64_t downloadedSize = data.ReadInt64(); + int64_t totalSize = data.ReadInt64(); + OnDownloadProcess(downloadedSize, totalSize); + return E_OK; +} +} // namespace OHOS::FileManagement::CloudSync diff --git a/interfaces/inner_api/native/cloudsync_kit_inner/BUILD.gn b/interfaces/inner_api/native/cloudsync_kit_inner/BUILD.gn index a6473dfb3..13724cad3 100644 --- a/interfaces/inner_api/native/cloudsync_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/cloudsync_kit_inner/BUILD.gn @@ -27,6 +27,10 @@ config("private_config") { ohos_shared_library("cloudsync_kit_inner") { sources = [ + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_downloaded_callback_client.cpp", + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_downloaded_callback_stub.cpp", + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_process_callback_client.cpp", + "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_process_callback_stub.cpp", "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_callback_client.cpp", "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_callback_stub.cpp", "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_common.cpp", diff --git a/services/cloudsyncservice/BUILD.gn b/services/cloudsyncservice/BUILD.gn index cd83f632e..73ec8309b 100644 --- a/services/cloudsyncservice/BUILD.gn +++ b/services/cloudsyncservice/BUILD.gn @@ -40,6 +40,8 @@ ohos_shared_library("cloudsync_sa") { ] sources = [ + "src/ipc/cloud_downloaded_callback_proxy.cpp", + "src/ipc/cloud_process_callback_proxy.cpp", "src/ipc/cloud_sync_callback_manager.cpp", "src/ipc/cloud_sync_callback_proxy.cpp", "src/ipc/cloud_sync_service.cpp", diff --git a/services/cloudsyncservice/include/ipc/cloud_downloaded_callback_proxy.h b/services/cloudsyncservice/include/ipc/cloud_downloaded_callback_proxy.h new file mode 100644 index 000000000..a75672a9d --- /dev/null +++ b/services/cloudsyncservice/include/ipc/cloud_downloaded_callback_proxy.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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_DOWNLOADED_CALLBACK_PROXY_H +#define OHOS_FILEMGMT_CLOUD_DOWNLOADED_CALLBACK_PROXY_H + +#include "i_cloud_downloaded_callback.h" + +#include "iremote_proxy.h" + +namespace OHOS::FileManagement::CloudSync { +class CloudDownloadedCallbackProxy : public IRemoteProxy { +public: + explicit CloudDownloadedCallbackProxy(const sptr &impl) : IRemoteProxy(impl) {} + ~CloudDownloadedCallbackProxy() override {} + + void OnDownloadedResult(int32_t result) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace OHOS::FileManagement::CloudSync + +#endif // OHOS_FILEMGMT_CLOUD_DOWNLOADED_CALLBACK_PROXY_H diff --git a/services/cloudsyncservice/include/ipc/cloud_process_callback_proxy.h b/services/cloudsyncservice/include/ipc/cloud_process_callback_proxy.h new file mode 100644 index 000000000..9becbb56d --- /dev/null +++ b/services/cloudsyncservice/include/ipc/cloud_process_callback_proxy.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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_PROCESS_CALLBACK_PROXY_H +#define OHOS_FILEMGMT_CLOUD_PROCESS_CALLBACK_PROXY_H + +#include "i_cloud_process_callback.h" + +#include "iremote_proxy.h" + +namespace OHOS::FileManagement::CloudSync { +class CloudProcessCallbackProxy : public IRemoteProxy { +public: + explicit CloudProcessCallbackProxy(const sptr &impl) : IRemoteProxy(impl) {} + ~CloudProcessCallbackProxy() override {} + + void OnDownloadProcess(int64_t downloadedSize, int64_t totalSize) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace OHOS::FileManagement::CloudSync + +#endif // OHOS_FILEMGMT_CLOUD_PROCESS_CALLBACK_PROXY_H diff --git a/services/cloudsyncservice/src/ipc/cloud_downloaded_callback_proxy.cpp b/services/cloudsyncservice/src/ipc/cloud_downloaded_callback_proxy.cpp new file mode 100644 index 000000000..0816fc46e --- /dev/null +++ b/services/cloudsyncservice/src/ipc/cloud_downloaded_callback_proxy.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2023 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_downloaded_callback_proxy.h" + +#include + +#include "dfs_error.h" +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudSync { +using namespace std; + +void CloudDownloadedCallbackProxy::OnDownloadedResult(int32_t result) +{ + LOGI("Start"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(GetDescriptor())) { + LOGE("Failed to write interface token"); + return; + } + + if (!data.WriteInt32(result)) { + LOGE("Failed to send the resutl"); + return; + } + + auto remote = Remote(); + if (!remote) { + LOGE("remote is nullptr"); + return; + } + int32_t ret = remote->SendRequest(ICloudDownloadedCallback::SERVICE_CMD_ON_DOWNLOADED, data, reply, option); + if (ret != E_OK) { + stringstream ss; + ss << "Failed to send out the requeset, errno:" << ret; + LOGE("%{public}s", ss.str().c_str()); + return; + } + LOGI("End"); + return; +} + +} // namespace OHOS::FileManagement::CloudSync diff --git a/services/cloudsyncservice/src/ipc/cloud_process_callback_proxy.cpp b/services/cloudsyncservice/src/ipc/cloud_process_callback_proxy.cpp new file mode 100644 index 000000000..5748b4ad3 --- /dev/null +++ b/services/cloudsyncservice/src/ipc/cloud_process_callback_proxy.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023 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_process_callback_proxy.h" + +#include + +#include "dfs_error.h" +#include "utils_log.h" + +namespace OHOS::FileManagement::CloudSync { +using namespace std; + +void CloudProcessCallbackProxy::OnDownloadProcess(int64_t downloadedSize, int64_t totalSize) +{ + LOGI("Start"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(GetDescriptor())) { + LOGE("Failed to write interface token"); + return; + } + + if (!data.WriteInt64(downloadedSize)) { + LOGE("Failed to send the type"); + return; + } + + if (!data.WriteInt64(totalSize)) { + LOGE("Failed to send the state"); + return; + } + + auto remote = Remote(); + if (!remote) { + LOGE("remote is nullptr"); + return; + } + int32_t ret = remote->SendRequest(ICloudProcessCallback::SERVICE_CMD_ON_PROCESS, data, reply, option); + if (ret != E_OK) { + stringstream ss; + ss << "Failed to send out the requeset, errno:" << ret; + LOGE("%{public}s", ss.str().c_str()); + return; + } + LOGI("End"); + return; +} +} // namespace OHOS::FileManagement::CloudSync -- Gitee From ba530e253cb9ac7c78f887e432ede58e75407515 Mon Sep 17 00:00:00 2001 From: Lihong Kou Date: Mon, 15 May 2023 06:15:06 +0000 Subject: [PATCH 3/3] cloud: enable download callback Signed-off-by: Lihong Kou --- .../include/cloud_sync_manager_impl.h | 2 + .../include/cloud_sync_service_proxy.h | 2 + .../src/cloud_sync_manager_impl.cpp | 17 +++++++ .../src/cloud_sync_service_proxy.cpp | 49 +++++++++++++++++++ .../cloudsync_kit_inner/cloud_sync_manager.h | 2 + .../i_cloud_sync_service.h | 3 ++ .../include/data_sync/data_handler.h | 2 + .../include/data_sync/data_sync_manager.h | 9 +++- .../include/data_sync/data_syncer.h | 10 ++++ .../gallery_data_sync/file_data_convertor.h | 6 +-- .../gallery_data_sync/file_data_handler.h | 2 + .../gallery_data_sync/gallery_data_syncer.h | 3 ++ .../include/ipc/cloud_sync_service.h | 4 ++ .../include/ipc/cloud_sync_service_stub.h | 1 + .../src/data_sync/data_sync_manager.cpp | 26 +++++++++- .../src/data_sync/data_syncer.cpp | 49 +++++++++++++++++++ .../gallery_data_sync/file_data_convertor.cpp | 10 ++++ .../gallery_data_sync/file_data_handler.cpp | 40 ++++++++++++++- .../gallery_data_sync/gallery_data_syncer.cpp | 7 +++ .../src/ipc/cloud_sync_callback_manager.cpp | 2 +- .../src/ipc/cloud_sync_service.cpp | 16 ++++++ .../src/ipc/cloud_sync_service_stub.cpp | 22 +++++++++ 22 files changed, 276 insertions(+), 8 deletions(-) diff --git a/frameworks/native/cloudsync_kit_inner/include/cloud_sync_manager_impl.h b/frameworks/native/cloudsync_kit_inner/include/cloud_sync_manager_impl.h index e9627947a..660fedbea 100644 --- a/frameworks/native/cloudsync_kit_inner/include/cloud_sync_manager_impl.h +++ b/frameworks/native/cloudsync_kit_inner/include/cloud_sync_manager_impl.h @@ -37,6 +37,8 @@ public: int32_t NotifyDataChange(const std::string &accoutId, const std::string &bundleName) override; int32_t EnableCloud(const std::string &accoutId, const SwitchDataObj &switchData) override; int32_t DisableCloud(const std::string &accoutId) override; + int32_t DownloadFile(const std::string &url, const std::shared_ptr processCallback, + const std::shared_ptr downloadedCallback) override ; private: CloudSyncManagerImpl() = default; void SetDeathRecipient(const sptr &remoteObject); diff --git a/frameworks/native/cloudsync_kit_inner/include/cloud_sync_service_proxy.h b/frameworks/native/cloudsync_kit_inner/include/cloud_sync_service_proxy.h index e8269e09e..a55a021d8 100644 --- a/frameworks/native/cloudsync_kit_inner/include/cloud_sync_service_proxy.h +++ b/frameworks/native/cloudsync_kit_inner/include/cloud_sync_service_proxy.h @@ -38,6 +38,8 @@ public: int32_t NotifyDataChange(const std::string &accoutId, const std::string &bundleName) override; int32_t EnableCloud(const std::string &accoutId, const SwitchDataObj &switchData) override; int32_t DisableCloud(const std::string &accoutId) override; + int32_t DownloadFile(const std::string &url, const sptr &processCallback, + const sptr &downloadedCallback) override; class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { public: diff --git a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp index 5649281a4..60dc860e8 100644 --- a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp +++ b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ +#include "cloud_downloaded_callback_client.h" +#include "cloud_process_callback_client.h" #include "cloud_sync_manager_impl.h" #include "cloud_sync_callback_client.h" #include "cloud_sync_service_proxy.h" @@ -89,6 +91,21 @@ int32_t CloudSyncManagerImpl::NotifyDataChange(const std::string &accoutId, cons return ret; } +int32_t CloudSyncManagerImpl::DownloadFile(const std::string &url, const std::shared_ptr processCallback, + const std::shared_ptr downloadedCallback) +{ + LOGI("Download File start"); + auto CloudSyncServiceProxy = CloudSyncServiceProxy::GetInstance(); + if (!CloudSyncServiceProxy) { + LOGE("proxy is null"); + return E_SA_LOAD_FAILED; + } + int32_t ret = CloudSyncServiceProxy->DownloadFile(url, + sptr(new (std::nothrow) CloudProcessCallbackClient(processCallback)), + sptr(new (std::nothrow) CloudDownloadedCallbackClient(downloadedCallback))); + LOGI("Download file ret %{public}d", ret); + return ret; +} void CloudSyncManagerImpl::SetDeathRecipient(const sptr &remoteObject) { auto deathCallback = [this](const wptr &obj) { diff --git a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_service_proxy.cpp b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_service_proxy.cpp index 783345316..761db206d 100644 --- a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_service_proxy.cpp +++ b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_service_proxy.cpp @@ -305,6 +305,55 @@ int32_t CloudSyncServiceProxy::NotifyDataChange(const std::string &accoutId, con return reply.ReadInt32(); } +int32_t CloudSyncServiceProxy::DownloadFile(const std::string &url, const sptr &processCallback, + const sptr &downloadedCallback) +{ + LOGI("Start DownloadFile"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!processCallback || !downloadedCallback) { + LOGI("Empty callback stub"); + return E_INVAL_ARG; + } + + if (!data.WriteInterfaceToken(GetDescriptor())) { + LOGE("Failed to write interface token"); + return E_BROKEN_IPC; + } + + if (!data.WriteString(url)) { + LOGE("Failed to send the cloud id"); + return E_INVAL_ARG; + } + + if (!data.WriteRemoteObject(processCallback)) { + LOGE("Failed to send the callback stub"); + return E_INVAL_ARG; + } + + if (!data.WriteRemoteObject(downloadedCallback)) { + LOGE("Failed to send the callback stub"); + return E_INVAL_ARG; + } + + auto remote = Remote(); + if (!remote) { + LOGE("remote is nullptr"); + return E_BROKEN_IPC; + } + int32_t ret = remote->SendRequest(ICloudSyncService::SERVICE_CMD_DOWNLOAD_FILE, data, reply, option); + if (ret != E_OK) { + stringstream ss; + ss << "Failed to send out the requeset, errno:" << ret; + LOGE("%{public}s", ss.str().c_str()); + return E_BROKEN_IPC; + } + LOGI("DownloadFile Success"); + return reply.ReadInt32(); +} + sptr CloudSyncServiceProxy::GetInstance() { LOGI("getinstance"); diff --git a/interfaces/inner_api/native/cloudsync_kit_inner/cloud_sync_manager.h b/interfaces/inner_api/native/cloudsync_kit_inner/cloud_sync_manager.h index e224f7d8d..9c432dec2 100644 --- a/interfaces/inner_api/native/cloudsync_kit_inner/cloud_sync_manager.h +++ b/interfaces/inner_api/native/cloudsync_kit_inner/cloud_sync_manager.h @@ -68,6 +68,8 @@ public: * @return int32_t 同步返回执行结果 */ virtual int32_t Clean(const std::string &accountId, const CleanOptions &cleanOptions) = 0; + virtual int32_t DownloadFile(const std::string &url, const std::shared_ptr processCallback, + const std::shared_ptr downloadedCallback)= 0; }; } // namespace OHOS::FileManagement::CloudSync diff --git a/interfaces/inner_api/native/cloudsync_kit_inner/i_cloud_sync_service.h b/interfaces/inner_api/native/cloudsync_kit_inner/i_cloud_sync_service.h index 9b87db0ef..7f483f721 100644 --- a/interfaces/inner_api/native/cloudsync_kit_inner/i_cloud_sync_service.h +++ b/interfaces/inner_api/native/cloudsync_kit_inner/i_cloud_sync_service.h @@ -34,6 +34,7 @@ public: SERVICE_CMD_ENABLE_CLOUD, SERVICE_CMD_DISABLE_CLOUD, SERVICE_CMD_CLEAN, + SERVICE_CMD_DOWNLOAD_FILE, }; DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Filemanagement.Dfs.ICloudSyncService") @@ -46,6 +47,8 @@ public: virtual int32_t NotifyDataChange(const std::string &accoutId, const std::string &bundleName) = 0; virtual int32_t EnableCloud(const std::string &accoutId, const SwitchDataObj &switchData) = 0; virtual int32_t DisableCloud(const std::string &accoutId) = 0; + virtual int32_t DownloadFile(const std::string &url, const sptr &processCallback, + const sptr &downloadedCallback) = 0; }; } // namespace OHOS::FileManagement::CloudSync diff --git a/services/cloudsyncservice/include/data_sync/data_handler.h b/services/cloudsyncservice/include/data_sync/data_handler.h index d943e4b8e..4edfa8797 100644 --- a/services/cloudsyncservice/include/data_sync/data_handler.h +++ b/services/cloudsyncservice/include/data_sync/data_handler.h @@ -38,6 +38,8 @@ public: const DriveKit::DKError &)>> &resultCallback) = 0; virtual int32_t GetRetryRecords(std::vector &records) = 0; + virtual int32_t GetDownloadAsset(std::string cloudId, + std::vector &outAssetsToDownload) = 0; /* upload */ virtual int32_t GetCreatedRecords(std::vector &records) = 0; virtual int32_t GetDeletedRecords(std::vector &records) = 0; diff --git a/services/cloudsyncservice/include/data_sync/data_sync_manager.h b/services/cloudsyncservice/include/data_sync/data_sync_manager.h index 11beda0c1..386c955d5 100644 --- a/services/cloudsyncservice/include/data_sync/data_sync_manager.h +++ b/services/cloudsyncservice/include/data_sync/data_sync_manager.h @@ -21,6 +21,8 @@ #include #include +#include "i_cloud_process_callback.h" +#include "i_cloud_downloaded_callback.h" #include "data_sync/data_syncer.h" namespace OHOS::FileManagement::CloudSync { @@ -39,6 +41,11 @@ public: int32_t TriggerRecoverySync(SyncTriggerType triggerType); std::shared_ptr GetDataSyncer(const std::string bundleName, const int32_t userId); int32_t IsSkipSync(const std::string bundleName, const int32_t userId) const; + int32_t DownloadSourceFile(const std::string bundleName, + const int32_t userId, + const std::string url, + const sptr processCallback, + const sptr downloadedCallback); private: std::vector> dataSyncers_; @@ -48,4 +55,4 @@ private: }; } // namespace OHOS::FileManagement::CloudSync -#endif // OHOS_FILEMGMT_DATA_SYNC_MANAGER_H \ No newline at end of file +#endif // OHOS_FILEMGMT_DATA_SYNC_MANAGER_H diff --git a/services/cloudsyncservice/include/data_sync/data_syncer.h b/services/cloudsyncservice/include/data_sync/data_syncer.h index cf5a5814c..84b124c58 100644 --- a/services/cloudsyncservice/include/data_sync/data_syncer.h +++ b/services/cloudsyncservice/include/data_sync/data_syncer.h @@ -25,6 +25,8 @@ #include "cloud_sync_constants.h" #include "data_handler.h" #include "data_sync/sync_state_manager.h" +#include "i_cloud_downloaded_callback.h" +#include "i_cloud_process_callback.h" #include "sdk_helper.h" #include "task.h" @@ -46,6 +48,9 @@ public: /* sync */ virtual int32_t StartSync(bool forceFlag, SyncTriggerType triggerType); virtual int32_t StopSync(SyncTriggerType triggerType); + virtual int32_t DownloadSourceFile(const std::string url, + const sptr processCallback, + const sptr downloadedCallback); /* properties */ std::string GetBundleName() const; @@ -66,6 +71,11 @@ protected: virtual void Schedule() = 0; void Abort(); + /* download source file */ + int32_t DownloadInner(std::shared_ptr handler, + const std::string url, + const sptr processCallback, + const sptr downloadedCallback); /* notify */ void CompletePull(); void CompletePush(); diff --git a/services/cloudsyncservice/include/data_sync/gallery_data_sync/file_data_convertor.h b/services/cloudsyncservice/include/data_sync/gallery_data_sync/file_data_convertor.h index 445eded7b..7d1d0ea6b 100644 --- a/services/cloudsyncservice/include/data_sync/gallery_data_sync/file_data_convertor.h +++ b/services/cloudsyncservice/include/data_sync/gallery_data_sync/file_data_convertor.h @@ -45,6 +45,9 @@ public: int32_t Convert(DriveKit::DKRecord &record, NativeRdb::ResultSet &resultSet); std::string GetThumbPath(const std::string &path, const std::string &key); + /* path conversion */ + std::string GetLowerPath(const std::string &path); + std::string GetLowerTmpPath(const std::string &path); private: /* record id */ @@ -85,9 +88,6 @@ private: int32_t HandleThumbnail(DriveKit::DKRecordFieldList &list, std::string &path); int32_t HandleLcd(DriveKit::DKRecordFieldList &list, std::string &path); - /* path conversion */ - std::string GetLowerPath(const std::string &path); - /* identifier */ int32_t userId_; std::string bundleName_; diff --git a/services/cloudsyncservice/include/data_sync/gallery_data_sync/file_data_handler.h b/services/cloudsyncservice/include/data_sync/gallery_data_sync/file_data_handler.h index 58c702006..0047fd20c 100644 --- a/services/cloudsyncservice/include/data_sync/gallery_data_sync/file_data_handler.h +++ b/services/cloudsyncservice/include/data_sync/gallery_data_sync/file_data_handler.h @@ -41,6 +41,8 @@ public: const DriveKit::DKError &)>> &downloadResultCallback) override; virtual int32_t GetRetryRecords(std::vector &records) override; + int32_t GetDownloadAsset(std::string cloudId, + std::vector &outAssetsToDownload) override; /* upload */ int32_t GetCreatedRecords(std::vector &records) override; int32_t GetDeletedRecords(std::vector &records) override; diff --git a/services/cloudsyncservice/include/data_sync/gallery_data_sync/gallery_data_syncer.h b/services/cloudsyncservice/include/data_sync/gallery_data_sync/gallery_data_syncer.h index d87fed752..7b8a62564 100644 --- a/services/cloudsyncservice/include/data_sync/gallery_data_sync/gallery_data_syncer.h +++ b/services/cloudsyncservice/include/data_sync/gallery_data_sync/gallery_data_syncer.h @@ -30,6 +30,9 @@ public: virtual ~GalleryDataSyncer() = default; virtual void Schedule() override; + int32_t DownloadSourceFile(const std::string url, + const sptr processCallback, + const sptr downloadedCallback) override; private: enum { diff --git a/services/cloudsyncservice/include/ipc/cloud_sync_service.h b/services/cloudsyncservice/include/ipc/cloud_sync_service.h index 83072f43e..9d3ac52a5 100644 --- a/services/cloudsyncservice/include/ipc/cloud_sync_service.h +++ b/services/cloudsyncservice/include/ipc/cloud_sync_service.h @@ -22,6 +22,8 @@ #include "system_ability.h" #include "cloud_sync_service_stub.h" +#include "i_cloud_downloaded_callback.h" +#include "i_cloud_process_callback.h" #include "i_cloud_sync_callback.h" #include "sync_rule/battery_status_listener.h" @@ -41,6 +43,8 @@ public: int32_t NotifyDataChange(const std::string &accoutId, const std::string &bundleName) override; int32_t EnableCloud(const std::string &accoutId, const SwitchDataObj &switchData) override; int32_t DisableCloud(const std::string &accoutId) override; + int32_t DownloadFile(const std::string &url, const sptr &processCallback, + const sptr &downloadedCallback) override; private: void OnStart() override; diff --git a/services/cloudsyncservice/include/ipc/cloud_sync_service_stub.h b/services/cloudsyncservice/include/ipc/cloud_sync_service_stub.h index b9c4ff2e0..d62a418a5 100644 --- a/services/cloudsyncservice/include/ipc/cloud_sync_service_stub.h +++ b/services/cloudsyncservice/include/ipc/cloud_sync_service_stub.h @@ -38,6 +38,7 @@ private: int32_t HandleNotifyDataChange(MessageParcel &data, MessageParcel &reply); int32_t HandleEnableCloud(MessageParcel &data, MessageParcel &reply); int32_t HandleDisableCloud(MessageParcel &data, MessageParcel &reply); + int32_t HandleDownloadFile(MessageParcel &data, MessageParcel &reply); }; } // namespace OHOS::FileManagement::CloudSync diff --git a/services/cloudsyncservice/src/data_sync/data_sync_manager.cpp b/services/cloudsyncservice/src/data_sync/data_sync_manager.cpp index e5cf4e317..0710aecf6 100644 --- a/services/cloudsyncservice/src/data_sync/data_sync_manager.cpp +++ b/services/cloudsyncservice/src/data_sync/data_sync_manager.cpp @@ -33,6 +33,7 @@ DataSyncManager::DataSyncManager() { bundleNameConversionMap_["com.ohos.medialibrary.medialibrarydata"] = "com.ohos.photos"; bundleNameConversionMap_["com.ohos.photos"] = "com.ohos.photos"; + bundleNameConversionMap_["hdcd"] = "com.ohos.photos"; } int32_t DataSyncManager::TriggerStartSync(const std::string bundleName, @@ -89,6 +90,29 @@ int32_t DataSyncManager::TriggerStopSync(const std::string bundleName, return E_OK; } +int32_t DataSyncManager::DownloadSourceFile(const std::string bundleName, + const int32_t userId, + const std::string url, + const sptr processCallback, + const sptr downloadedCallback) +{ + auto it = bundleNameConversionMap_.find(bundleName); + if (it == bundleNameConversionMap_.end()) { + LOGE("trigger stop sync failed, bundleName: %{private}s, useId: %{private}d", bundleName.c_str(), userId); + return E_INVAL_ARG; + } + std::string appBundleName(it->second); + auto dataSyncer = GetDataSyncer(appBundleName, userId); + if (!dataSyncer) { + LOGE("Get dataSyncer failed, bundleName: %{private}s", appBundleName.c_str()); + return E_SYNCER_NUM_OUT_OF_RANGE; + } + std::thread([dataSyncer, url, processCallback, downloadedCallback]() { + dataSyncer->DownloadSourceFile(url, processCallback, downloadedCallback); + }).detach(); + return E_OK; +} + int32_t DataSyncManager::TriggerRecoverySync(SyncTriggerType triggerType) { std::vector needSyncApps; @@ -153,4 +177,4 @@ int32_t DataSyncManager::IsSkipSync(const std::string bundleName, const int32_t } return E_OK; } -} // namespace OHOS::FileManagement::CloudSync \ No newline at end of file +} // namespace OHOS::FileManagement::CloudSync diff --git a/services/cloudsyncservice/src/data_sync/data_syncer.cpp b/services/cloudsyncservice/src/data_sync/data_syncer.cpp index 9b817a7bb..596687889 100644 --- a/services/cloudsyncservice/src/data_sync/data_syncer.cpp +++ b/services/cloudsyncservice/src/data_sync/data_syncer.cpp @@ -120,6 +120,13 @@ int32_t DataSyncer::StopSync(SyncTriggerType triggerType) return E_OK; } +int32_t DataSyncer::DownloadSourceFile(const std::string url, + const sptr processCallback, + const sptr downloadedCallback) +{ + return E_OK; +} + void DataSyncer::Abort() { LOGI("%{private}d %{private}s aborts", userId_, bundleName_.c_str()); @@ -322,6 +329,48 @@ void DataSyncer::OnFetchRecords(const std::shared_ptr context, std::s } } +int32_t DataSyncer::DownloadInner(std::shared_ptr handler, + const std::string url, + const sptr processCallback, + const sptr downloadedCallback) +{ + DKDownloadId id; + auto ctx = std::make_shared(handler); + std::vector assetsToDownload; + int32_t ret = handler->GetDownloadAsset(url, assetsToDownload); + if (ret != E_OK) { + LOGE("handler on fetch records err %{public}d", ret); + return ret; + } + + auto downloadResultCallback = [downloadedCallback](std::shared_ptr context, + std::shared_ptr database, + const std::map &results, + const DriveKit::DKError &err) { + LOGI("download result %{public}d", err.serverErrorCode); + if (downloadedCallback != nullptr) { + downloadedCallback->OnDownloadedResult(err.serverErrorCode); + } + }; + auto downloadResultPtr = std::make_shared, + std::shared_ptr, + const std::map &, + const DriveKit::DKError &)>>(downloadResultCallback); + auto downloadProcessCallback = [processCallback](std::shared_ptr context, + DKDownloadAsset asset, TotalSize totalSize, + DownloadSize downloadSize) { + if (processCallback != nullptr) { + processCallback->OnDownloadProcess(downloadSize, totalSize); + } + }; + auto downloadProcessPtr = std::make_shared, DKDownloadAsset, TotalSize, DownloadSize)>>(downloadProcessCallback); + + auto dctx = make_shared(handler, assetsToDownload, id, + downloadResultPtr, ctx, nullptr, downloadProcessPtr); + DownloadAssets(static_pointer_cast(dctx)); + return E_OK; +} + void DataSyncer::OnFetchDatabaseChanges(const std::shared_ptr context, std::shared_ptr database, std::shared_ptr> records, DKQueryCursor nextCursor, diff --git a/services/cloudsyncservice/src/data_sync/gallery_data_sync/file_data_convertor.cpp b/services/cloudsyncservice/src/data_sync/gallery_data_sync/file_data_convertor.cpp index fa71f957a..0d55d76e8 100644 --- a/services/cloudsyncservice/src/data_sync/gallery_data_sync/file_data_convertor.cpp +++ b/services/cloudsyncservice/src/data_sync/gallery_data_sync/file_data_convertor.cpp @@ -453,6 +453,16 @@ string FileDataConvertor::GetLowerPath(const std::string &path) sandboxPrefix_.size()); } +string FileDataConvertor::GetLowerTmpPath(const std::string &path) +{ + size_t pos = path.find_first_of(sandboxPrefix_); + if (pos == string::npos) { + LOGE("invalid path %{private}s", path.c_str()); + return ""; + } + return prefix_ + to_string(userId_) + suffix_ + path.substr(pos + + sandboxPrefix_.size()) + ".tmp"; +} string FileDataConvertor::GetThumbPath(const std::string &path, const std::string &key) { diff --git a/services/cloudsyncservice/src/data_sync/gallery_data_sync/file_data_handler.cpp b/services/cloudsyncservice/src/data_sync/gallery_data_sync/file_data_handler.cpp index f8d39b015..fcc4f1ad2 100644 --- a/services/cloudsyncservice/src/data_sync/gallery_data_sync/file_data_handler.cpp +++ b/services/cloudsyncservice/src/data_sync/gallery_data_sync/file_data_handler.cpp @@ -548,8 +548,12 @@ void FileDataHandler::AppendToDownload(const DKRecord &record, } string path; prop[MEDIA_DATA_DB_FILE_PATH].GetString(path); - const string &suffix = fieldKey == "lcd" ? LCD_SUFFIX : THUMB_SUFFIX; - downloadAsset.downLoadPath = createConvertor_.GetThumbPath(path, suffix); + if (fieldKey != "content") { + const string &suffix = fieldKey == "lcd" ? LCD_SUFFIX : THUMB_SUFFIX; + downloadAsset.downLoadPath = createConvertor_.GetThumbPath(path, suffix); + } else { + downloadAsset.downLoadPath = createConvertor_.GetLowerTmpPath(path); + } downloadAsset.asset.assetName = GetFileName(downloadAsset.downLoadPath); downloadAsset.downLoadPath = GetParentDir(downloadAsset.downLoadPath); ForceCreateDirectory(downloadAsset.downLoadPath); @@ -650,6 +654,38 @@ int32_t FileDataHandler::GetMetaModifiedRecords(vector &records) return E_OK; } +int32_t FileDataHandler::GetDownloadAsset(std::string cloudId, vector &outAssetsToDownload) +{ + vector records; + NativeRdb::AbsRdbPredicates predicates = NativeRdb::AbsRdbPredicates(TABLE_NAME); + predicates.SetWhereClause(Media::MEDIA_DATA_DB_CLOUD_ID + " = ?"); + predicates.SetWhereArgs({cloudId}); + predicates.Limit(LIMIT_SIZE); + auto resultSet = Query(predicates, GALLERY_FILE_COLUMNS); + if (resultSet == nullptr) { + LOGE("get nullptr created result"); + return E_RDB; + } + int32_t rowCount = 0; + int32_t ret = resultSet->GetRowCount(rowCount); + if (ret != 0) { + LOGE("result set get row count err %{public}d", ret); + return E_RDB; + } + + ret = localConvertor_.ResultSetToRecords(move(resultSet), records); + if (ret != 0) { + LOGE("result set to records err %{public}d", ret); + return ret; + } + for (const auto &record : records) { + AppendToDownload(record, "content", outAssetsToDownload); + } + + return E_OK; +} + + int32_t FileDataHandler::GetFileModifiedRecords(vector &records) { /* build predicates */ diff --git a/services/cloudsyncservice/src/data_sync/gallery_data_sync/gallery_data_syncer.cpp b/services/cloudsyncservice/src/data_sync/gallery_data_sync/gallery_data_syncer.cpp index 10665df06..cbb172544 100644 --- a/services/cloudsyncservice/src/data_sync/gallery_data_sync/gallery_data_syncer.cpp +++ b/services/cloudsyncservice/src/data_sync/gallery_data_sync/gallery_data_syncer.cpp @@ -55,6 +55,13 @@ GalleryDataSyncer::GalleryDataSyncer(const std::string bundleName, const int32_t fileHandler_ = make_shared(userId, bundleName, rdb_); } +int32_t GalleryDataSyncer::DownloadSourceFile(const std::string url, + const sptr processCallback, + const sptr downloadedCallback) +{ + return DownloadInner(fileHandler_, url, processCallback, downloadedCallback); +} + void GalleryDataSyncer::Schedule() { LOGI("schedule to stage %{public}d", ++stage_); diff --git a/services/cloudsyncservice/src/ipc/cloud_sync_callback_manager.cpp b/services/cloudsyncservice/src/ipc/cloud_sync_callback_manager.cpp index 832388594..8117af2c2 100644 --- a/services/cloudsyncservice/src/ipc/cloud_sync_callback_manager.cpp +++ b/services/cloudsyncservice/src/ipc/cloud_sync_callback_manager.cpp @@ -73,4 +73,4 @@ void CloudSyncCallbackManager::NotifySyncStateChanged(const SyncType type, const auto callback = bind(&CloudSyncCallbackManager::Notify, this, _1, _2, type, state); callbackListMap_.Iterate(callback); } -} // namespace OHOS::FileManagement::CloudSync \ No newline at end of file +} // namespace OHOS::FileManagement::CloudSync diff --git a/services/cloudsyncservice/src/ipc/cloud_sync_service.cpp b/services/cloudsyncservice/src/ipc/cloud_sync_service.cpp index 988346ac1..518e8f0a0 100644 --- a/services/cloudsyncservice/src/ipc/cloud_sync_service.cpp +++ b/services/cloudsyncservice/src/ipc/cloud_sync_service.cpp @@ -145,4 +145,20 @@ int32_t CloudSyncService::Clean(const std::string &accountId, const CleanOptions { return E_OK; } + +int32_t CloudSyncService::DownloadFile(const std::string &url, const sptr &processCallback, const sptr &downloadedCallback) +{ + auto callerUserId = DfsuAccessTokenHelper::GetUserId(); + auto processCb = iface_cast(processCallback); + auto downloadedCb = iface_cast(downloadedCallback); + string bundleName; + LOGI("download file start"); + if (DfsuAccessTokenHelper::GetCallerBundleName(bundleName)) { + return E_INVAL_ARG; + } + if (callerUserId == 0) { + callerUserId = 100; // for root user change id to main user for test + } + return dataSyncManager_->DownloadSourceFile(bundleName, callerUserId, url, processCb, downloadedCb); +} } // namespace OHOS::FileManagement::CloudSync diff --git a/services/cloudsyncservice/src/ipc/cloud_sync_service_stub.cpp b/services/cloudsyncservice/src/ipc/cloud_sync_service_stub.cpp index 23af67c94..a209b5e39 100644 --- a/services/cloudsyncservice/src/ipc/cloud_sync_service_stub.cpp +++ b/services/cloudsyncservice/src/ipc/cloud_sync_service_stub.cpp @@ -30,6 +30,7 @@ CloudSyncServiceStub::CloudSyncServiceStub() opToInterfaceMap_[SERVICE_CMD_NOTIFY_DATA_CHANGE] = &CloudSyncServiceStub::HandleNotifyDataChange; opToInterfaceMap_[SERVICE_CMD_ENABLE_CLOUD] = &CloudSyncServiceStub::HandleEnableCloud; opToInterfaceMap_[SERVICE_CMD_DISABLE_CLOUD] = &CloudSyncServiceStub::HandleDisableCloud; + opToInterfaceMap_[SERVICE_CMD_DOWNLOAD_FILE] = &CloudSyncServiceStub::HandleDownloadFile; } int32_t CloudSyncServiceStub::OnRemoteRequest(uint32_t code, @@ -197,4 +198,25 @@ int32_t CloudSyncServiceStub::HandleEnableCloud(MessageParcel &data, MessageParc LOGI("End EnableCloud"); return res; } + +int32_t CloudSyncServiceStub::HandleDownloadFile(MessageParcel &data, MessageParcel &reply) +{ + LOGI("Begin DownloadFile"); + if (!DfsuAccessTokenHelper::CheckCallerPermission(PERM_CLOUD_SYNC_MANAGER)) { + LOGE("permission denied"); + return E_PERMISSION_DENIED; + } + if (!DfsuAccessTokenHelper::IsSystemApp()) { + LOGE("caller hap is not system hap"); + return E_PERMISSION_SYSTEM; + } + string url = data.ReadString(); + auto processCallback = data.ReadRemoteObject(); + auto downloadedCallback = data.ReadRemoteObject(); + + int32_t res = DownloadFile(url, processCallback, downloadedCallback); + reply.WriteInt32(res); + LOGI("End DownloadFile"); + return res; +} } // namespace OHOS::FileManagement::CloudSync -- Gitee