• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
BackupOnScanningInfo(std::string scannedInfo)132 void ServiceReverseProxy::BackupOnScanningInfo(std::string scannedInfo)
133 {
134     BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
135     MessageParcel data;
136     if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(scannedInfo)) {
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_BACKUP_ON_SCANNED_INFO), data,
144         reply, option);
145         err != ERR_OK) {
146         throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
147     }
148 }
149 
RestoreOnBundleStarted(int32_t errCode,string bundleName)150 void ServiceReverseProxy::RestoreOnBundleStarted(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_STARTED), data, reply,
162         option);
163         err != ERR_OK) {
164         throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
165     }
166 }
167 
RestoreOnBundleFinished(int32_t errCode,string bundleName)168 void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundleName)
169 {
170     BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
171     MessageParcel data;
172     if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) {
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_SUB_TASK_FINISHED), data, reply,
180         option);
181         err != ERR_OK) {
182         throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
183     }
184 }
185 
RestoreOnAllBundlesFinished(int32_t errCode)186 void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode)
187 {
188     BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
189     MessageParcel data;
190     if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode)) {
191         throw BError(BError::Codes::SA_BROKEN_IPC);
192     }
193 
194     MessageParcel reply;
195     MessageOption option;
196     if (int err = Remote()->SendRequest(
197         static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_TASK_FINISHED), data, reply,
198         option);
199         err != ERR_OK) {
200         throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
201     }
202 }
203 
RestoreOnFileReady(string bundleName,string fileName,int fd,int32_t errCode)204 void ServiceReverseProxy::RestoreOnFileReady(string bundleName, string fileName, int fd, int32_t errCode)
205 {
206     BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
207     MessageParcel data;
208     bool fdFlag = fd < 0 ? false : true;
209     if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(fileName) ||
210         !data.WriteBool(fdFlag) || (fdFlag == true && !data.WriteFileDescriptor(fd)) || !data.WriteInt32(errCode)) {
211         throw BError(BError::Codes::SA_BROKEN_IPC);
212     }
213 
214     MessageParcel reply;
215     MessageOption option;
216     if (int err = Remote()->SendRequest(
217         static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_FILE_READY), data, reply, option);
218         err != ERR_OK) {
219         throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
220     }
221 }
222 
RestoreOnResultReport(string result,std::string bundleName,ErrCode errCode)223 void ServiceReverseProxy::RestoreOnResultReport(string result, std::string bundleName, ErrCode errCode)
224 {
225     HILOGI("ServiceReverseProxy::RestoreOnResultReport Begin with result: %s", result.c_str());
226     BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
227     MessageParcel data;
228     if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(result) ||
229         !data.WriteString(bundleName) || !data.WriteInt32(errCode)) {
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_RESULT_REPORT), data, reply,
237         option);
238         err != ERR_OK) {
239         throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
240     }
241 }
242 
RestoreOnProcessInfo(std::string bundleName,std::string processInfo)243 void ServiceReverseProxy::RestoreOnProcessInfo(std::string bundleName, std::string processInfo)
244 {
245     BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
246     MessageParcel data;
247     if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(processInfo)) {
248         throw BError(BError::Codes::SA_BROKEN_IPC);
249     }
250 
251     MessageParcel reply;
252     MessageOption option;
253     if (int err = Remote()->SendRequest(
254         static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_PROCESS_INFO), data, reply, option);
255         err != ERR_OK) {
256         throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
257     }
258 }
259 } // namespace OHOS::FileManagement::Backup