• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 "service_proxy.h"
17 
18 #include <cstddef>
19 #include <fcntl.h>
20 #include <gtest/gtest.h>
21 #include <sstream>
22 #include <sys/stat.h>
23 #include <sys/types.h>
24 
25 #include "b_error/b_error.h"
26 #include "b_resources/b_constants.h"
27 #include "iremote_object_mock.h"
28 #include "test_manager.h"
29 #include "utils_mock_global_variable.h"
30 
31 namespace OHOS::FileManagement::Backup {
32 using namespace std;
33 
InitRestoreSession(const sptr<IServiceReverse> & remote)34 int32_t ServiceProxy::InitRestoreSession(const sptr<IServiceReverse>& remote)
35 {
36     if (!GetMockInitBackupOrRestoreSession()) {
37         return 1;
38     }
39     return 0;
40 }
41 
InitRestoreSessionWithErrMsg(const sptr<IServiceReverse> & remote,int32_t & errCodeForMsg,std::string & errMsg)42 int32_t ServiceProxy::InitRestoreSessionWithErrMsg(const sptr<IServiceReverse>& remote,
43                                                    int32_t &errCodeForMsg, std::string &errMsg)
44 {
45     if (!GetMockInitBackupOrRestoreSession()) {
46         errCodeForMsg = 1;
47         return 0;
48     }
49     return 0;
50 }
51 
InitBackupSession(const sptr<IServiceReverse> & remote)52 int32_t ServiceProxy::InitBackupSession(const sptr<IServiceReverse>& remote)
53 {
54     if (!GetMockInitBackupOrRestoreSession()) {
55         return 1;
56     }
57     return 0;
58 }
59 
InitBackupSessionWithErrMsg(const sptr<IServiceReverse> & remote,int32_t & errCodeForMsg,std::string & errMsg)60 int32_t ServiceProxy::InitBackupSessionWithErrMsg(const sptr<IServiceReverse>& remote,
61                                                   int32_t &errCodeForMsg, std::string &errMsg)
62 {
63     if (!GetMockInitBackupOrRestoreSession()) {
64         errCodeForMsg = 1;
65         return 0;
66     }
67     return 0;
68 }
69 
Start()70 ErrCode ServiceProxy::Start()
71 {
72     return BError(BError::Codes::OK);
73 }
74 
GetLocalCapabilities(int & fd)75 ErrCode ServiceProxy::GetLocalCapabilities(int &fd)
76 {
77     TestManager tm("ServiceProxyMock_GetFd_0100");
78     string filePath = tm.GetRootDirCurTest().append("tmp");
79     UniqueFd fd_OpenData(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR));
80     fd = fd_OpenData.Release();
81     return BError(BError::Codes::OK);
82 }
83 
PublishFile(const BFileInfo & fileInfo)84 ErrCode ServiceProxy::PublishFile(const BFileInfo &fileInfo)
85 {
86     return BError(BError::Codes::OK);
87 }
88 
AppFileReady(const string & fileName,int fd,int32_t errCode)89 ErrCode ServiceProxy::AppFileReady(const string &fileName, int fd, int32_t errCode)
90 {
91     return BError(BError::Codes::OK);
92 }
93 
AppFileReadyWithoutFd(const string & fileName,int32_t errCode)94 ErrCode ServiceProxy::AppFileReadyWithoutFd(const string &fileName, int32_t errCode)
95 {
96     return BError(BError::Codes::OK);
97 }
98 
AppDone(ErrCode errCode)99 ErrCode ServiceProxy::AppDone(ErrCode errCode)
100 {
101     return BError(BError::Codes::OK);
102 }
103 
ServiceResultReport(const std::string & restoreRetInfo,BackupRestoreScenario scenario,ErrCode errCode)104 ErrCode ServiceProxy::ServiceResultReport(const std::string& restoreRetInfo,
105     BackupRestoreScenario scenario, ErrCode errCode)
106 {
107     return BError(BError::Codes::OK);
108 }
109 
GetFileHandle(const string & bundleName,const string & fileName)110 ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &fileName)
111 {
112     return BError(BError::Codes::OK);
113 }
114 
AppendBundlesRestoreSessionDataByDetail(int fd,const std::vector<std::string> & bundleNames,const std::vector<std::string> & detailInfos,int32_t restoreType,int32_t userId)115 ErrCode ServiceProxy::AppendBundlesRestoreSessionDataByDetail(int fd,
116                                                               const std::vector<std::string> &bundleNames,
117                                                               const std::vector<std::string> &detailInfos,
118                                                               int32_t restoreType,
119                                                               int32_t userId)
120 {
121     return BError(BError::Codes::OK);
122 }
123 
AppendBundlesRestoreSessionData(int fd,const std::vector<std::string> & bundleNames,int32_t restoreType,int32_t userId)124 ErrCode ServiceProxy::AppendBundlesRestoreSessionData(int fd,
125                                                       const std::vector<std::string> &bundleNames,
126                                                       int32_t restoreType,
127                                                       int32_t userId)
128 {
129     return BError(BError::Codes::OK);
130 }
131 
AppendBundlesBackupSession(const vector<BundleName> & bundleNames)132 ErrCode ServiceProxy::AppendBundlesBackupSession(const vector<BundleName> &bundleNames)
133 {
134     return BError(BError::Codes::OK);
135 }
136 
AppendBundlesDetailsBackupSession(const std::vector<BundleName> & bundleNames,const std::vector<std::string> & detailInfos)137 ErrCode ServiceProxy::AppendBundlesDetailsBackupSession(const std::vector<BundleName> &bundleNames,
138                                                         const std::vector<std::string> &detailInfos)
139 {
140     return BError(BError::Codes::OK);
141 }
142 
Finish()143 ErrCode ServiceProxy::Finish()
144 {
145     return BError(BError::Codes::OK);
146 }
147 
Release()148 ErrCode ServiceProxy::Release()
149 {
150     return BError(BError::Codes::OK);
151 }
152 
CancelForResult(const std::string & bundleName,int32_t & result)153 ErrCode ServiceProxy::CancelForResult(const std::string &bundleName, int32_t &result)
154 {
155     result = BError(BError::Codes::OK);
156     return BError(BError::Codes::OK);
157 }
158 
GetLocalCapabilitiesIncremental(const std::vector<BIncrementalData> & bundleNames,int & fd)159 ErrCode ServiceProxy::GetLocalCapabilitiesIncremental(const std::vector<BIncrementalData> &bundleNames, int &fd)
160 {
161     fd = UniqueFd(-1).Get();
162     return BError(BError::Codes::OK);
163 }
164 
GetAppLocalListAndDoIncrementalBackup()165 ErrCode ServiceProxy::GetAppLocalListAndDoIncrementalBackup()
166 {
167     return BError(BError::Codes::OK);
168 }
169 
InitIncrementalBackupSession(const sptr<IServiceReverse> & remote)170 ErrCode ServiceProxy::InitIncrementalBackupSession(const sptr<IServiceReverse>& remote)
171 {
172     return BError(BError::Codes::OK);
173 }
174 
InitIncrementalBackupSessionWithErrMsg(const sptr<IServiceReverse> & remote,int32_t & errCodeForMsg,std::string & errMsg)175 ErrCode ServiceProxy::InitIncrementalBackupSessionWithErrMsg(const sptr<IServiceReverse> &remote,
176                                                              int32_t &errCodeForMsg, std::string &errMsg)
177 {
178     errCodeForMsg = BError(BError::Codes::OK);
179     return BError(BError::Codes::OK);
180 }
181 
AppendBundlesIncrementalBackupSession(const std::vector<BIncrementalData> & bundlesToBackup)182 ErrCode ServiceProxy::AppendBundlesIncrementalBackupSession(const std::vector<BIncrementalData> &bundlesToBackup)
183 {
184     return BError(BError::Codes::OK);
185 }
186 
AppendBundlesIncrementalBackupSessionWithBundleInfos(const std::vector<BIncrementalData> & bundlesToBackup,const std::vector<std::string> & bundleInfos)187 ErrCode ServiceProxy::AppendBundlesIncrementalBackupSessionWithBundleInfos(
188     const std::vector<BIncrementalData> &bundlesToBackup,
189     const std::vector<std::string> &bundleInfos)
190 {
191     return BError(BError::Codes::OK);
192 }
193 
PublishIncrementalFile(const BFileInfo & fileInfo)194 ErrCode ServiceProxy::PublishIncrementalFile(const BFileInfo &fileInfo)
195 {
196     return BError(BError::Codes::OK);
197 }
198 
PublishSAIncrementalFile(const BFileInfo & fileInfo,int fd)199 ErrCode ServiceProxy::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd)
200 {
201     return BError(BError::Codes::OK);
202 }
203 
AppIncrementalFileReady(const string & fileName,int fd,int manifestFd,int32_t errCode)204 ErrCode ServiceProxy::AppIncrementalFileReady(const string &fileName, int fd, int manifestFd, int32_t errCode)
205 {
206     return BError(BError::Codes::OK);
207 }
208 
AppIncrementalFileReadyWithoutFd(const string & fileName,int32_t errCode)209 ErrCode ServiceProxy::AppIncrementalFileReadyWithoutFd(const string &fileName, int32_t errCode)
210 {
211     return BError(BError::Codes::OK);
212 }
213 
AppIncrementalDone(ErrCode errCode)214 ErrCode ServiceProxy::AppIncrementalDone(ErrCode errCode)
215 {
216     return BError(BError::Codes::OK);
217 }
218 
GetIncrementalFileHandle(const std::string & bundleName,const std::string & fileName)219 ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName)
220 {
221     return BError(BError::Codes::OK);
222 }
223 
GetBackupInfo(const std::string & bundleName,std::string & result)224 ErrCode ServiceProxy::GetBackupInfo(const std::string &bundleName, std::string &result)
225 {
226     return BError(BError::Codes::OK);
227 }
228 
UpdateTimer(const BundleName & bundleName,uint32_t timeout,bool & result)229 ErrCode ServiceProxy::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result)
230 {
231     return BError(BError::Codes::OK);
232 }
233 
StartExtTimer(bool & isExtStart)234 ErrCode ServiceProxy::StartExtTimer(bool &isExtStart)
235 {
236     return BError(BError::Codes::OK);
237 }
238 
StartFwkTimer(bool & isFwkStart)239 ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart)
240 {
241     return BError(BError::Codes::OK);
242 }
243 
StopExtTimer(bool & isExtStop)244 ErrCode ServiceProxy::StopExtTimer(bool &isExtStop)
245 {
246     return BError(BError::Codes::OK);
247 }
248 
RefreshDataSize(int64_t totalSize)249 ErrCode ServiceProxy::RefreshDataSize(int64_t totalSize)
250 {
251     return BError(BError::Codes::OK);
252 }
253 
UpdateSendRate(const std::string & bundleName,int32_t sendRate,bool & result)254 ErrCode ServiceProxy::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result)
255 {
256     return BError(BError::Codes::OK);
257 }
258 
ReportAppProcessInfo(const std::string & processInfo,BackupRestoreScenario scenario)259 ErrCode ServiceProxy::ReportAppProcessInfo(const std::string& processInfo, BackupRestoreScenario scenario)
260 {
261     return BError(BError::Codes::OK);
262 }
263 
GetLocalCapabilitiesForBundleInfos(int & fd)264 ErrCode ServiceProxy::GetLocalCapabilitiesForBundleInfos(int& fd)
265 {
266     fd=-1;
267     return fd;
268 }
269 
GetBackupDataSize(bool isPreciseScan,const vector<BIncrementalData> & bundleNameList)270 ErrCode ServiceProxy::GetBackupDataSize(bool isPreciseScan, const vector<BIncrementalData>& bundleNameList)
271 {
272     return BError(BError::Codes::OK);
273 }
274 
CleanBundleTempDir(const std::string & bundleName)275 ErrCode ServiceProxy::CleanBundleTempDir(const std::string& bundleName)
276 {
277     return BError(BError::Codes::OK);
278 }
279 
HandleExtDisconnect(BackupRestoreScenario scenario,bool isAppResultReport,ErrCode errCode)280 ErrCode ServiceProxy::HandleExtDisconnect(BackupRestoreScenario scenario, bool isAppResultReport, ErrCode errCode)
281 {
282     return BError(BError::Codes::OK);
283 }
284 
GetExtOnRelease(bool & isExtOnRelease)285 ErrCode ServiceProxy::GetExtOnRelease(bool &isExtOnRelease)
286 {
287     return BError(BError::Codes::OK);
288 }
289 
GetCompatibilityInfo(const std::string & bundleName,const std::string & extInfo,std::string & compatInfo)290 ErrCode ServiceProxy::GetCompatibilityInfo(const std::string &bundleName, const std::string &extInfo,
291     std::string &compatInfo)
292 {
293     return BError(BError::Codes::OK);
294 }
295 } // namespace OHOS::FileManagement::Backup