1 /*
2 * Copyright (c) 2024 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 "asset_recv_callback_proxy.h"
17
18 #include "accesstoken_kit.h"
19 #include "asset/asset_callback_interface_code.h"
20 #include "dfs_error.h"
21 #include "iservice_registry.h"
22 #include "system_ability_definition.h"
23 #include "utils_log.h"
24
25 namespace OHOS {
26 namespace Storage {
27 namespace DistributedFile {
28 using namespace std;
29 using namespace OHOS::Storage;
30 using namespace OHOS::FileManagement;
31
OnStart(const std::string & srcNetworkId,const std::string & destNetworkId,const std::string & sessionId,const std::string & destBundleName)32 int32_t AssetRecvCallbackProxy::OnStart(const std::string &srcNetworkId,
33 const std::string &destNetworkId,
34 const std::string &sessionId,
35 const std::string &destBundleName)
36 {
37 MessageParcel data;
38 MessageParcel reply;
39 MessageOption option;
40 if (!data.WriteInterfaceToken(GetDescriptor())) {
41 LOGE("Failed to write interface token");
42 return E_BROKEN_IPC;
43 }
44 if (!data.WriteString(srcNetworkId)) {
45 LOGE("Failed to send srcNetworkId");
46 return E_INVAL_ARG;
47 }
48 if (!data.WriteString(destNetworkId)) {
49 LOGE("Failed to send destNetworkId");
50 return E_INVAL_ARG;
51 }
52 if (!data.WriteString(sessionId)) {
53 LOGE("Failed to send sessionId");
54 return E_INVAL_ARG;
55 }
56 if (!data.WriteString(destBundleName)) {
57 LOGE("Failed to send destBundleName");
58 return E_INVAL_ARG;
59 }
60 auto remote = Remote();
61 if (remote == nullptr) {
62 LOGE("remote is nullptr");
63 return E_BROKEN_IPC;
64 }
65 int32_t ret = remote->SendRequest(
66 static_cast<uint32_t>(AssetCallbackInterfaceCode::ASSET_CALLBACK_ON_START), data, reply, option);
67 if (ret != E_OK) {
68 LOGE("Failed to send out the request, errno:%{public}d", errno);
69 return E_BROKEN_IPC;
70 }
71 return reply.ReadInt32();
72 }
73
OnFinished(const std::string & srcNetworkId,const sptr<AssetObj> & assetObj,int32_t result)74 int32_t AssetRecvCallbackProxy::OnFinished(const std::string &srcNetworkId,
75 const sptr<AssetObj> &assetObj,
76 int32_t result)
77 {
78 MessageParcel data;
79 MessageParcel reply;
80 MessageOption option;
81 if (!data.WriteInterfaceToken(GetDescriptor())) {
82 LOGE("Failed to write interface token");
83 return E_BROKEN_IPC;
84 }
85 if (!data.WriteString(srcNetworkId)) {
86 LOGE("Failed to send srcNetworkId");
87 return E_INVAL_ARG;
88 }
89
90 if (!data.WriteParcelable(assetObj)) {
91 LOGE("Failed to send the assetInfoObj");
92 return E_INVAL_ARG;
93 }
94
95 if (!data.WriteInt32(result)) {
96 LOGE("Failed to send result");
97 return E_INVAL_ARG;
98 }
99 auto remote = Remote();
100 if (remote == nullptr) {
101 LOGE("remote is nullptr");
102 return E_BROKEN_IPC;
103 }
104 int32_t ret = remote->SendRequest(
105 static_cast<uint32_t>(AssetCallbackInterfaceCode::ASSET_CALLBACK_ON_FINISHED), data, reply, option);
106 if (ret != E_OK) {
107 LOGE("Failed to send out the request, errno:%{public}d", errno);
108 return E_BROKEN_IPC;
109 }
110 return reply.ReadInt32();
111 }
112
113 } // namespace DistributedFile
114 } // namespace Storage
115 } // namespace OHOS