• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "cloud_download_callback_stub.h"
17 #include "cloud_download_uri_manager.h"
18 #include "dfs_error.h"
19 #include "utils_log.h"
20 
21 namespace OHOS::FileManagement::CloudSync {
22 using namespace std;
23 
CloudDownloadCallbackStub()24 CloudDownloadCallbackStub::CloudDownloadCallbackStub()
25 {
26     opToInterfaceMap_[SERVICE_CMD_ON_PROCESS] = &CloudDownloadCallbackStub::HandleOnProcess;
27 }
28 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int32_t CloudDownloadCallbackStub::OnRemoteRequest(uint32_t code,
30                                                    MessageParcel &data,
31                                                    MessageParcel &reply,
32                                                    MessageOption &option)
33 {
34     if (data.ReadInterfaceToken() != GetDescriptor()) {
35         return E_SERVICE_DESCRIPTOR_IS_EMPTY;
36     }
37     auto interfaceIndex = opToInterfaceMap_.find(code);
38     if (interfaceIndex == opToInterfaceMap_.end() || !interfaceIndex->second) {
39         LOGE("Cannot response request %d: unknown tranction", code);
40         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
41     }
42     return (this->*(interfaceIndex->second))(data, reply);
43 }
44 
HandleOnProcess(MessageParcel & data,MessageParcel & reply)45 int32_t CloudDownloadCallbackStub::HandleOnProcess(MessageParcel &data, MessageParcel &reply)
46 {
47     sptr<DownloadProgressObj> progress = data.ReadParcelable<DownloadProgressObj>();
48     if (!progress) {
49         LOGE("object of DownloadProgressObj is nullptr");
50         return E_INVAL_ARG;
51     }
52 
53     CloudDownloadUriManager& uriMgr = CloudDownloadUriManager::GetInstance();
54     std::string path = progress->path;
55     std::string uri = uriMgr.GetUri(path);
56     if (uri.empty()) {
57         LOGE("CloudDownloadCallbackStub path %{public}s trans to uri error", path.c_str());
58         return E_INVAL_ARG;
59     }
60 
61     progress->path = uri;
62 
63     if (progress->state != DownloadProgressObj::RUNNING) {
64         uriMgr.RemoveUri(path);
65     }
66 
67     OnDownloadProcess(*progress);
68     return E_OK;
69 }
70 
71 } // namespace OHOS::FileManagement::CloudSync
72