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 "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 #include "module_app_gallery/app_gallery_dispose_proxy.h"
22
23 namespace OHOS::FileManagement::Backup {
24 using namespace std;
25
IncrementalBackupOnFileReady(string bundleName,string fileName,int fd,int manifestFd,int32_t errCode)26 void ServiceReverseProxy::IncrementalBackupOnFileReady(string bundleName, string fileName, int fd, int manifestFd,
27 int32_t errCode)
28 {
29 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
30 MessageParcel data;
31 bool fdFlag = true;
32 if (fd < 0 || manifestFd < 0) {
33 fdFlag = false;
34 }
35 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) ||
36 !data.WriteString(fileName) || !data.WriteBool(fdFlag) ||
37 (fdFlag == true && (!data.WriteFileDescriptor(fd) || !data.WriteFileDescriptor(manifestFd))) ||
38 !data.WriteInt32(errCode)) {
39 throw BError(BError::Codes::SA_BROKEN_IPC);
40 }
41
42 MessageParcel reply;
43 MessageOption option;
44 if (int err = Remote()->SendRequest(
45 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_FILE_READY), data, reply,
46 option);
47 err != ERR_OK) {
48 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
49 }
50 }
51
IncrementalBackupOnBundleStarted(int32_t errCode,string bundleName)52 void ServiceReverseProxy::IncrementalBackupOnBundleStarted(int32_t errCode, string bundleName)
53 {
54 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
55 MessageParcel data;
56 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) {
57 throw BError(BError::Codes::SA_BROKEN_IPC);
58 };
59
60 MessageParcel reply;
61 MessageOption option;
62 if (int err = Remote()->SendRequest(
63 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_STARTED), data,
64 reply, option);
65 err != ERR_OK) {
66 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
67 }
68 }
69
IncrementalBackupOnResultReport(std::string result,std::string bundleName)70 void ServiceReverseProxy::IncrementalBackupOnResultReport(std::string result, std::string bundleName)
71 {
72 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
73 MessageParcel data;
74 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(result) || !data.WriteString(bundleName)) {
75 throw BError(BError::Codes::SA_BROKEN_IPC);
76 };
77
78 MessageParcel reply;
79 MessageOption option;
80 if (int err = Remote()->SendRequest(
81 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_RESULT_REPORT), data,
82 reply, option);
83 err != ERR_OK) {
84 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
85 }
86 }
87
IncrementalBackupOnBundleFinished(int32_t errCode,string bundleName)88 void ServiceReverseProxy::IncrementalBackupOnBundleFinished(int32_t errCode, string bundleName)
89 {
90 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
91 MessageParcel data;
92 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) {
93 throw BError(BError::Codes::SA_BROKEN_IPC);
94 }
95
96 MessageParcel reply;
97 MessageOption option;
98 if (int err = Remote()->SendRequest(
99 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_FINISHED), data,
100 reply, option);
101 err != ERR_OK) {
102 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
103 }
104 }
105
IncrementalBackupOnAllBundlesFinished(int32_t errCode)106 void ServiceReverseProxy::IncrementalBackupOnAllBundlesFinished(int32_t errCode)
107 {
108 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
109 MessageParcel data;
110 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode)) {
111 throw BError(BError::Codes::SA_BROKEN_IPC);
112 }
113
114 MessageParcel reply;
115 MessageOption option;
116 if (int err = Remote()->SendRequest(
117 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_TASK_FINISHED), data,
118 reply, option);
119 err != ERR_OK) {
120 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
121 }
122 }
123
IncrementalBackupOnProcessInfo(std::string bundleName,std::string processInfo)124 void ServiceReverseProxy::IncrementalBackupOnProcessInfo(std::string bundleName, std::string processInfo)
125 {
126 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
127 MessageParcel data;
128 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(processInfo)) {
129 throw BError(BError::Codes::SA_BROKEN_IPC);
130 }
131
132 MessageParcel reply;
133 MessageOption option;
134 if (int err = Remote()->SendRequest(
135 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_PROCESS_INFO), data,
136 reply, option);
137 err != ERR_OK) {
138 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
139 }
140 }
141
IncrementalBackupOnScanningInfo(std::string scannedInfo)142 void ServiceReverseProxy::IncrementalBackupOnScanningInfo(std::string scannedInfo)
143 {
144 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
145 MessageParcel data;
146 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(scannedInfo)) {
147 throw BError(BError::Codes::SA_BROKEN_IPC);
148 }
149
150 MessageParcel reply;
151 MessageOption option;
152 if (int err = Remote()->SendRequest(
153 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_SCANNED_INFO), data,
154 reply, option);
155 err != ERR_OK) {
156 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
157 }
158 }
159
IncrementalRestoreOnBundleStarted(int32_t errCode,string bundleName)160 void ServiceReverseProxy::IncrementalRestoreOnBundleStarted(int32_t errCode, string bundleName)
161 {
162 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
163 MessageParcel data;
164 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) {
165 throw BError(BError::Codes::SA_BROKEN_IPC);
166 }
167
168 MessageParcel reply;
169 MessageOption option;
170 if (int err = Remote()->SendRequest(
171 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_STARTED), data,
172 reply, option);
173 err != ERR_OK) {
174 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
175 }
176 }
177
IncrementalRestoreOnBundleFinished(int32_t errCode,string bundleName)178 void ServiceReverseProxy::IncrementalRestoreOnBundleFinished(int32_t errCode, string bundleName)
179 {
180 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
181 MessageParcel data;
182 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) {
183 throw BError(BError::Codes::SA_BROKEN_IPC);
184 }
185
186 MessageParcel reply;
187 MessageOption option;
188 if (int err = Remote()->SendRequest(
189 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_SUB_TASK_FINISHED),
190 data, reply, option);
191 err != ERR_OK) {
192 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
193 }
194 }
195
IncrementalRestoreOnAllBundlesFinished(int32_t errCode)196 void ServiceReverseProxy::IncrementalRestoreOnAllBundlesFinished(int32_t errCode)
197 {
198 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
199 MessageParcel data;
200 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode)) {
201 throw BError(BError::Codes::SA_BROKEN_IPC);
202 }
203
204 MessageParcel reply;
205 MessageOption option;
206 if (int err = Remote()->SendRequest(
207 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_TASK_FINISHED), data,
208 reply, option);
209 err != ERR_OK) {
210 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
211 }
212 }
213
IncrementalRestoreOnResultReport(std::string result,std::string bundleName,ErrCode errCode)214 void ServiceReverseProxy::IncrementalRestoreOnResultReport(std::string result,
215 std::string bundleName, ErrCode errCode)
216 {
217 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
218 MessageParcel data;
219 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(result) ||
220 !data.WriteString(bundleName) || !data.WriteInt32(errCode)) {
221 throw BError(BError::Codes::SA_BROKEN_IPC);
222 }
223
224 MessageParcel reply;
225 MessageOption option;
226 if (int err = Remote()->SendRequest(
227 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_RESULT_REPORT), data,
228 reply, option);
229 err != ERR_OK) {
230 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
231 }
232 }
233
IncrementalRestoreOnFileReady(string bundleName,string fileName,int fd,int manifestFd,int32_t errCode)234 void ServiceReverseProxy::IncrementalRestoreOnFileReady(string bundleName, string fileName, int fd, int manifestFd,
235 int32_t errCode)
236 {
237 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
238 MessageParcel data;
239 bool fdFlag = (fd < 0 || manifestFd < 0) ? false : true;
240 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) ||
241 !data.WriteString(fileName) || !data.WriteBool(fdFlag) ||
242 (fdFlag == true && (!data.WriteFileDescriptor(fd) || !data.WriteFileDescriptor(manifestFd))) ||
243 !data.WriteInt32(errCode)) {
244 throw BError(BError::Codes::SA_BROKEN_IPC);
245 }
246
247 MessageParcel reply;
248 MessageOption option;
249 if (int err = Remote()->SendRequest(
250 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_FILE_READY), data,
251 reply, option);
252 err != ERR_OK) {
253 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
254 }
255 }
256
IncrementalRestoreOnProcessInfo(std::string bundleName,std::string processInfo)257 void ServiceReverseProxy::IncrementalRestoreOnProcessInfo(std::string bundleName, std::string processInfo)
258 {
259 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
260 MessageParcel data;
261 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(processInfo)) {
262 throw BError(BError::Codes::SA_BROKEN_IPC);
263 }
264
265 MessageParcel reply;
266 MessageOption option;
267 if (int err = Remote()->SendRequest(
268 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_RESTORE_ON_PROCESS_INFO), data,
269 reply, option);
270 err != ERR_OK) {
271 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
272 }
273 }
274 } // namespace OHOS::FileManagement::Backup