1 /*
2 * Copyright (c) 2022-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 "module_ipc/service_reverse_proxy.h"
17
18 #include "b_error/b_error.h"
19 #include "b_error/b_excep_utils.h"
20 #include "filemgmt_libhilog.h"
21
22 namespace OHOS::FileManagement::Backup {
23 using namespace std;
24
BackupOnFileReady(string bundleName,string fileName,int fd,int32_t errCode)25 void ServiceReverseProxy::BackupOnFileReady(string bundleName, string fileName, int fd, int32_t errCode)
26 {
27 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
28 MessageParcel data;
29 bool fdFlag = fd < 0 ? false : true;
30 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(fileName) ||
31 !data.WriteBool(fdFlag) || (fdFlag == true && !data.WriteFileDescriptor(fd)) || !data.WriteInt32(errCode)) {
32 throw BError(BError::Codes::SA_BROKEN_IPC);
33 }
34
35 MessageParcel reply;
36 MessageOption option;
37 if (int err = Remote()->SendRequest(
38 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_FILE_READY), data, reply, option);
39 err != ERR_OK) {
40 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
41 }
42 }
43
BackupOnBundleStarted(int32_t errCode,string bundleName)44 void ServiceReverseProxy::BackupOnBundleStarted(int32_t errCode, string bundleName)
45 {
46 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
47 MessageParcel data;
48 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) {
49 throw BError(BError::Codes::SA_BROKEN_IPC);
50 };
51
52 MessageParcel reply;
53 MessageOption option;
54 if (int err = Remote()->SendRequest(
55 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_STARTED), data, reply,
56 option);
57 err != ERR_OK) {
58 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
59 }
60 }
61
BackupOnResultReport(std::string result,std::string bundleName)62 void ServiceReverseProxy::BackupOnResultReport(std::string result, std::string bundleName)
63 {
64 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
65 MessageParcel data;
66 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(result) || !data.WriteString(bundleName)) {
67 throw BError(BError::Codes::SA_BROKEN_IPC);
68 };
69
70 MessageParcel reply;
71 MessageOption option;
72 if (int err = Remote()->SendRequest(
73 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_RESULT_REPORT), data, reply,
74 option);
75 err != ERR_OK) {
76 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
77 }
78 }
79
BackupOnBundleFinished(int32_t errCode,string bundleName)80 void ServiceReverseProxy::BackupOnBundleFinished(int32_t errCode, string bundleName)
81 {
82 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
83 MessageParcel data;
84 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) {
85 throw BError(BError::Codes::SA_BROKEN_IPC);
86 }
87
88 MessageParcel reply;
89 MessageOption option;
90 if (int err = Remote()->SendRequest(
91 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_FINISHED), data, reply,
92 option);
93 err != ERR_OK) {
94 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
95 }
96 }
97
BackupOnAllBundlesFinished(int32_t errCode)98 void ServiceReverseProxy::BackupOnAllBundlesFinished(int32_t errCode)
99 {
100 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
101 MessageParcel data;
102 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode)) {
103 throw BError(BError::Codes::SA_BROKEN_IPC);
104 }
105
106 MessageParcel reply;
107 MessageOption option;
108 if (int err = Remote()->SendRequest(
109 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_TASK_FINISHED), data, reply, option);
110 err != ERR_OK) {
111 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
112 }
113 }
114
BackupOnProcessInfo(std::string bundleName,std::string processInfo)115 void ServiceReverseProxy::BackupOnProcessInfo(std::string bundleName, std::string processInfo)
116 {
117 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
118 MessageParcel data;
119 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(processInfo)) {
120 throw BError(BError::Codes::SA_BROKEN_IPC);
121 }
122
123 MessageParcel reply;
124 MessageOption option;
125 if (int err = Remote()->SendRequest(
126 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_PROCESS_INFO), data, reply, option);
127 err != ERR_OK) {
128 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
129 }
130 }
131
RestoreOnBundleStarted(int32_t errCode,string bundleName)132 void ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, string bundleName)
133 {
134 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
135 MessageParcel data;
136 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) {
137 throw BError(BError::Codes::SA_BROKEN_IPC);
138 }
139
140 MessageParcel reply;
141 MessageOption option;
142 if (int err = Remote()->SendRequest(
143 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_STARTED), data, reply,
144 option);
145 err != ERR_OK) {
146 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
147 }
148 }
149
RestoreOnBundleFinished(int32_t errCode,string bundleName)150 void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundleName)
151 {
152 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
153 MessageParcel data;
154 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) {
155 throw BError(BError::Codes::SA_BROKEN_IPC);
156 }
157
158 MessageParcel reply;
159 MessageOption option;
160 if (int err = Remote()->SendRequest(
161 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_FINISHED), data, reply,
162 option);
163 err != ERR_OK) {
164 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
165 }
166 }
167
RestoreOnAllBundlesFinished(int32_t errCode)168 void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode)
169 {
170 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
171 MessageParcel data;
172 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode)) {
173 throw BError(BError::Codes::SA_BROKEN_IPC);
174 }
175
176 MessageParcel reply;
177 MessageOption option;
178 if (int err = Remote()->SendRequest(
179 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_TASK_FINISHED), data, reply,
180 option);
181 err != ERR_OK) {
182 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
183 }
184 }
185
RestoreOnFileReady(string bundleName,string fileName,int fd,int32_t errCode)186 void ServiceReverseProxy::RestoreOnFileReady(string bundleName, string fileName, int fd, int32_t errCode)
187 {
188 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
189 MessageParcel data;
190 bool fdFlag = fd < 0 ? false : true;
191 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(fileName) ||
192 !data.WriteBool(fdFlag) || (fdFlag == true && !data.WriteFileDescriptor(fd)) || !data.WriteInt32(errCode)) {
193 throw BError(BError::Codes::SA_BROKEN_IPC);
194 }
195
196 MessageParcel reply;
197 MessageOption option;
198 if (int err = Remote()->SendRequest(
199 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_FILE_READY), data, reply, option);
200 err != ERR_OK) {
201 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
202 }
203 }
204
RestoreOnResultReport(string result,std::string bundleName,ErrCode errCode)205 void ServiceReverseProxy::RestoreOnResultReport(string result, std::string bundleName, ErrCode errCode)
206 {
207 HILOGI("ServiceReverseProxy::RestoreOnResultReport Begin with result: %s", result.c_str());
208 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
209 MessageParcel data;
210 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(result) ||
211 !data.WriteString(bundleName) || !data.WriteInt32(errCode)) {
212 throw BError(BError::Codes::SA_BROKEN_IPC);
213 }
214
215 MessageParcel reply;
216 MessageOption option;
217 if (int err = Remote()->SendRequest(
218 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_RESULT_REPORT), data, reply,
219 option);
220 err != ERR_OK) {
221 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
222 }
223 }
224
RestoreOnProcessInfo(std::string bundleName,std::string processInfo)225 void ServiceReverseProxy::RestoreOnProcessInfo(std::string bundleName, std::string processInfo)
226 {
227 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
228 MessageParcel data;
229 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(processInfo)) {
230 throw BError(BError::Codes::SA_BROKEN_IPC);
231 }
232
233 MessageParcel reply;
234 MessageOption option;
235 if (int err = Remote()->SendRequest(
236 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_PROCESS_INFO), data, reply, option);
237 err != ERR_OK) {
238 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
239 }
240 }
241 } // namespace OHOS::FileManagement::Backup