1 /*
2 * Copyright (c) 2022-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 "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)25 void ServiceReverseProxy::BackupOnFileReady(string bundleName, string fileName, int fd)
26 {
27 HILOGI("Begin");
28 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
29 MessageParcel data;
30 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(fileName) ||
31 !data.WriteFileDescriptor(fd)) {
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 HILOGI("Begin");
47 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
48 MessageParcel data;
49 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) {
50 throw BError(BError::Codes::SA_BROKEN_IPC);
51 };
52
53 MessageParcel reply;
54 MessageOption option;
55 if (int err = Remote()->SendRequest(
56 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_STARTED), data, reply,
57 option);
58 err != ERR_OK) {
59 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
60 }
61 }
62
BackupOnBundleFinished(int32_t errCode,string bundleName)63 void ServiceReverseProxy::BackupOnBundleFinished(int32_t errCode, string bundleName)
64 {
65 HILOGI("Begin");
66 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
67 MessageParcel data;
68 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) {
69 throw BError(BError::Codes::SA_BROKEN_IPC);
70 }
71
72 MessageParcel reply;
73 MessageOption option;
74 if (int err = Remote()->SendRequest(
75 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_SUB_TASK_FINISHED), data, reply,
76 option);
77 err != ERR_OK) {
78 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
79 }
80 }
81
BackupOnAllBundlesFinished(int32_t errCode)82 void ServiceReverseProxy::BackupOnAllBundlesFinished(int32_t errCode)
83 {
84 HILOGI("Begin");
85 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
86 MessageParcel data;
87 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode)) {
88 throw BError(BError::Codes::SA_BROKEN_IPC);
89 }
90
91 MessageParcel reply;
92 MessageOption option;
93 if (int err = Remote()->SendRequest(
94 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_BACKUP_ON_TASK_FINISHED), data, reply, option);
95 err != ERR_OK) {
96 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
97 }
98 }
99
RestoreOnBundleStarted(int32_t errCode,string bundleName)100 void ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, string bundleName)
101 {
102 HILOGI("Begin");
103 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
104 MessageParcel data;
105 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) {
106 throw BError(BError::Codes::SA_BROKEN_IPC);
107 }
108
109 MessageParcel reply;
110 MessageOption option;
111 if (int err = Remote()->SendRequest(
112 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_STARTED), data, reply,
113 option);
114 err != ERR_OK) {
115 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
116 }
117 }
118
RestoreOnBundleFinished(int32_t errCode,string bundleName)119 void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundleName)
120 {
121 HILOGI("Begin");
122 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
123 MessageParcel data;
124 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode) || !data.WriteString(bundleName)) {
125 throw BError(BError::Codes::SA_BROKEN_IPC);
126 }
127
128 MessageParcel reply;
129 MessageOption option;
130 if (int err = Remote()->SendRequest(
131 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_SUB_TASK_FINISHED), data, reply,
132 option);
133 err != ERR_OK) {
134 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
135 }
136 }
137
RestoreOnAllBundlesFinished(int32_t errCode)138 void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode)
139 {
140 HILOGI("Begin");
141 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
142 MessageParcel data;
143 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(errCode)) {
144 throw BError(BError::Codes::SA_BROKEN_IPC);
145 }
146
147 MessageParcel reply;
148 MessageOption option;
149 if (int err = Remote()->SendRequest(
150 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_TASK_FINISHED), data, reply,
151 option);
152 err != ERR_OK) {
153 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
154 }
155 }
156
RestoreOnFileReady(string bundleName,string fileName,int fd)157 void ServiceReverseProxy::RestoreOnFileReady(string bundleName, string fileName, int fd)
158 {
159 HILOGI("Begin");
160 BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr");
161 MessageParcel data;
162 if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteString(fileName) ||
163 !data.WriteFileDescriptor(fd)) {
164 throw BError(BError::Codes::SA_BROKEN_IPC);
165 }
166
167 MessageParcel reply;
168 MessageOption option;
169 if (int err = Remote()->SendRequest(
170 static_cast<uint32_t>(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_FILE_READY), data, reply, option);
171 err != ERR_OK) {
172 throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err));
173 }
174 }
175 } // namespace OHOS::FileManagement::Backup