• 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.h"
17 
18 #include <algorithm>
19 #include <cerrno>
20 #include <cstring>
21 #include <gtest/gtest.h>
22 
23 #include "b_error/b_error.h"
24 #include "b_resources/b_constants.h"
25 
26 namespace OHOS::FileManagement::Backup {
27 using namespace std;
28 
GetUserIdDefault()29 int32_t Service::GetUserIdDefault()
30 {
31     return 0;
32 }
33 
OnStart()34 void Service::OnStart() {}
35 
OnStop()36 void Service::OnStop() {}
37 
GetLocalCapabilities(int & fd)38 ErrCode Service::GetLocalCapabilities(int &fd)
39 {
40     return BError(BError::Codes::OK);
41 }
42 
GetLocalCapabilitiesForBundleInfos(int & fd)43 ErrCode Service::GetLocalCapabilitiesForBundleInfos(int &fd)
44 {
45     return UniqueFd(-1);
46 }
47 
StopAll(const wptr<IRemoteObject> & obj,bool force)48 void Service::StopAll(const wptr<IRemoteObject> &obj, bool force) {}
49 
VerifyCallerAndGetCallerName(std::string & bundleName)50 ErrCode Service::VerifyCallerAndGetCallerName(std::string &bundleName)
51 {
52     return BError(BError::Codes::OK);
53 }
54 
InitRestoreSession(const sptr<IServiceReverse> & remote)55 ErrCode Service::InitRestoreSession(const sptr<IServiceReverse> &remote)
56 {
57     return BError(BError::Codes::OK);
58 }
59 
InitRestoreSessionWithErrMsg(const sptr<IServiceReverse> & reverseIpcRemoteObject,int32_t & errCodeForMsg,std::string & errMsg)60 ErrCode Service::InitRestoreSessionWithErrMsg(const sptr<IServiceReverse> &reverseIpcRemoteObject,
61                                               int32_t &errCodeForMsg, std::string &errMsg)
62 {
63     errCodeForMsg = BError(BError::Codes::OK);
64     return BError(BError::Codes::OK);
65 }
66 
InitBackupSession(const sptr<IServiceReverse> & remote)67 ErrCode Service::InitBackupSession(const sptr<IServiceReverse> &remote)
68 {
69     return BError(BError::Codes::OK);
70 }
71 
InitBackupSessionWithErrMsg(const sptr<IServiceReverse> & remote,int32_t & errCodeForMsg,std::string & errMsg)72 ErrCode Service::InitBackupSessionWithErrMsg(const sptr<IServiceReverse> &remote,
73                                              int32_t &errCodeForMsg, std::string &errMsg)
74 {
75     errCodeForMsg = BError(BError::Codes::OK);
76     return BError(BError::Codes::OK);
77 }
78 
Start()79 ErrCode Service::Start()
80 {
81     return BError(BError::Codes::OK);
82 }
83 
PublishFile(const BFileInfo & fileInfo)84 ErrCode Service::PublishFile(const BFileInfo &fileInfo)
85 {
86     return BError(BError::Codes::OK);
87 }
88 
AppFileReady(const string & fileName,int fd,int32_t errCode)89 ErrCode Service::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 Service::AppFileReadyWithoutFd(const string &fileName, int32_t errCode)
95 {
96     return BError(BError::Codes::OK);
97 }
98 
AppDone(ErrCode errCode)99 ErrCode Service::AppDone(ErrCode errCode)
100 {
101     return BError(BError::Codes::OK);
102 }
103 
ServiceResultReport(const std::string & restoreRetInfo,BackupRestoreScenario sennario,ErrCode errCode)104 ErrCode Service::ServiceResultReport(const std::string &restoreRetInfo,
105     BackupRestoreScenario sennario, ErrCode errCode)
106 {
107     return BError(BError::Codes::OK);
108 }
109 
AppendBundlesRestoreSessionDataByDetail(int fd,const std::vector<std::string> & bundleNames,const std::vector<std::string> & detailInfos,int32_t restoreType,int32_t userId)110 ErrCode Service::AppendBundlesRestoreSessionDataByDetail(int fd,
111                                                          const std::vector<std::string> &bundleNames,
112                                                          const std::vector<std::string> &detailInfos,
113                                                          int32_t restoreType,
114                                                          int32_t userId)
115 {
116     return BError(BError::Codes::OK);
117 }
118 
AppendBundlesRestoreSessionData(int fd,const std::vector<std::string> & bundleNames,int32_t restoreType,int32_t userId)119 ErrCode Service::AppendBundlesRestoreSessionData(int fd,
120                                                  const std::vector<std::string> &bundleNames,
121                                                  int32_t restoreType,
122                                                  int32_t userId)
123 {
124     return BError(BError::Codes::OK);
125 }
126 
AppendBundlesBackupSession(const std::vector<BundleName> & bundleNames)127 ErrCode Service::AppendBundlesBackupSession(const std::vector<BundleName> &bundleNames)
128 {
129     return BError(BError::Codes::OK);
130 }
131 
AppendBundlesDetailsBackupSession(const std::vector<BundleName> & bundleNames,const std::vector<std::string> & bundleInfos)132 ErrCode Service::AppendBundlesDetailsBackupSession(const std::vector<BundleName> &bundleNames,
133                                                    const std::vector<std::string> &bundleInfos)
134 {
135     return BError(BError::Codes::OK);
136 }
137 
Finish()138 ErrCode Service::Finish()
139 {
140     return BError(BError::Codes::OK);
141 }
142 
LaunchBackupExtension(const BundleName & bundleName)143 ErrCode Service::LaunchBackupExtension(const BundleName &bundleName)
144 {
145     return BError(BError::Codes::OK);
146 }
147 
LaunchBackupSAExtension(const BundleName & bundleName)148 ErrCode Service::LaunchBackupSAExtension(const BundleName &bundleName)
149 {
150     return BError(BError::Codes::OK);
151 }
152 
GetFileHandle(const string & bundleName,const string & fileName)153 ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName)
154 {
155     return BError(BError::Codes::OK);
156 }
157 
OnBackupExtensionDied(const string && bundleName,bool isCleanCalled)158 void Service::OnBackupExtensionDied(const string &&bundleName, bool isCleanCalled) {}
159 
ExtConnectDied(const string & callName)160 void Service::ExtConnectDied(const string &callName) {}
161 
ExtStart(const string & bundleName)162 void Service::ExtStart(const string &bundleName) {}
163 
Dump(int fd,const vector<u16string> & args)164 int Service::Dump(int fd, const vector<u16string> &args)
165 {
166     return 0;
167 }
168 
ExtConnectFailed(const string & bundleName,ErrCode ret)169 void Service::ExtConnectFailed(const string &bundleName, ErrCode ret)
170 {
171     GTEST_LOG_(INFO) << "ExtConnectFailed is OK";
172 }
173 
ExtConnectDone(string bundleName)174 void Service::ExtConnectDone(string bundleName) {}
175 
ClearSessionAndSchedInfo(const string & bundleName)176 void Service::ClearSessionAndSchedInfo(const string &bundleName) {}
177 
VerifyCaller()178 ErrCode Service::VerifyCaller()
179 {
180     return BError(BError::Codes::OK);
181 }
182 
VerifyCaller(IServiceReverseType::Scenario scenario)183 ErrCode Service::VerifyCaller(IServiceReverseType::Scenario scenario)
184 {
185     return BError(BError::Codes::OK);
186 }
187 
OnAllBundlesFinished(ErrCode errCode)188 void Service::OnAllBundlesFinished(ErrCode errCode) {}
189 
OnStartSched()190 void Service::OnStartSched() {}
191 
SendStartAppGalleryNotify(const BundleName & bundleName)192 void Service::SendStartAppGalleryNotify(const BundleName &bundleName) {}
193 
SessionDeactive()194 void Service::SessionDeactive() {}
195 
Release()196 ErrCode Service::Release()
197 {
198     return BError(BError::Codes::OK);
199 }
200 
CancelForResult(const std::string & bundleName,int32_t & result)201 ErrCode Service::CancelForResult(const std::string &bundleName, int32_t &result)
202 {
203     result = BError(BError::Codes::OK);
204     return BError(BError::Codes::OK);
205 }
206 
GetLocalCapabilitiesIncremental(const std::vector<BIncrementalData> & bundleNames,int & fd)207 ErrCode Service::GetLocalCapabilitiesIncremental(const std::vector<BIncrementalData> &bundleNames, int &fd)
208 {
209     return BError(BError::Codes::OK);
210 }
211 
GetAppLocalListAndDoIncrementalBackup()212 ErrCode Service::GetAppLocalListAndDoIncrementalBackup()
213 {
214     return BError(BError::Codes::OK);
215 }
216 
InitIncrementalBackupSession(const sptr<IServiceReverse> & remote)217 ErrCode Service::InitIncrementalBackupSession(const sptr<IServiceReverse> &remote)
218 {
219     return BError(BError::Codes::OK);
220 }
221 
InitIncrementalBackupSessionWithErrMsg(const sptr<IServiceReverse> & remote,int32_t & errCodeForMsg,std::string & errMsg)222 ErrCode Service::InitIncrementalBackupSessionWithErrMsg(const sptr<IServiceReverse> &remote,
223                                                         int32_t &errCodeForMsg, std::string &errMsg)
224 {
225     errCodeForMsg = BError(BError::Codes::OK);
226     return BError(BError::Codes::OK);
227 }
228 
AppendBundlesIncrementalBackupSession(const std::vector<BIncrementalData> & bundlesToBackup)229 ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector<BIncrementalData> &bundlesToBackup)
230 {
231     return BError(BError::Codes::OK);
232 }
233 
AppendBundlesIncrementalBackupSessionWithBundleInfos(const std::vector<BIncrementalData> & bundlesToBackup,const std::vector<std::string> & bundleInfos)234 ErrCode Service::AppendBundlesIncrementalBackupSessionWithBundleInfos(
235     const std::vector<BIncrementalData> &bundlesToBackup,
236     const std::vector<std::string> &bundleInfos)
237 {
238     return BError(BError::Codes::OK);
239 }
240 
PublishIncrementalFile(const BFileInfo & fileInfo)241 ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo)
242 {
243     return BError(BError::Codes::OK);
244 }
245 
PublishSAIncrementalFile(const BFileInfo & fileInfo,int fd)246 ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, int fd)
247 {
248     return BError(BError::Codes::OK);
249 }
250 
AppIncrementalFileReady(const std::string & fileName,int fd,int manifestFd,int32_t appIncrementalFileReadyErrCode)251 ErrCode Service::AppIncrementalFileReady(const std::string &fileName,
252                                          int fd,
253                                          int manifestFd,
254                                          int32_t appIncrementalFileReadyErrCode)
255 {
256     return BError(BError::Codes::OK);
257 }
258 
AppIncrementalFileReadyWithoutFd(const std::string & fileName,int32_t appIncrementalFileReadyErrCode)259 ErrCode Service::AppIncrementalFileReadyWithoutFd(const std::string &fileName,
260                                                   int32_t appIncrementalFileReadyErrCode)
261 {
262     return BError(BError::Codes::OK);
263 }
264 
AppIncrementalDone(ErrCode errCode)265 ErrCode Service::AppIncrementalDone(ErrCode errCode)
266 {
267     return BError(BError::Codes::OK);
268 }
269 
GetIncrementalFileHandle(const string & bundleName,const string & fileName)270 ErrCode Service::GetIncrementalFileHandle(const string &bundleName, const string &fileName)
271 {
272     return BError(BError::Codes::OK);
273 }
274 
GetBackupInfo(const BundleName & bundleName,std::string & result)275 ErrCode Service::GetBackupInfo(const BundleName &bundleName, std::string &result)
276 {
277     return BError(BError::Codes::OK);
278 }
279 
StartExtTimer(bool & isExtStart)280 ErrCode Service::StartExtTimer(bool &isExtStart)
281 {
282     return BError(BError::Codes::OK);
283 }
284 
StartFwkTimer(bool & isFwkStart)285 ErrCode Service::StartFwkTimer(bool &isFwkStart)
286 {
287     return BError(BError::Codes::OK);
288 }
289 
StopExtTimer(bool & isExtStop)290 ErrCode Service::StopExtTimer(bool &isExtStop)
291 {
292     return BError(BError::Codes::OK);
293 }
294 
RefreshDataSize(int64_t totalDatasize)295 ErrCode Service::RefreshDataSize(int64_t totalDatasize)
296 {
297     return BError(BError::Codes::OK);
298 }
299 
UpdateTimer(const BundleName & bundleName,uint32_t timeout,bool & result)300 ErrCode Service::UpdateTimer(const BundleName &bundleName, uint32_t timeout, bool &result)
301 {
302     return BError(BError::Codes::OK);
303 }
304 
UpdateSendRate(const std::string & bundleName,int32_t sendRate,bool & result)305 ErrCode Service::UpdateSendRate(const std::string &bundleName, int32_t sendRate, bool &result)
306 {
307     return BError(BError::Codes::OK);
308 }
309 
ReportAppProcessInfo(const std::string & processInfo,const BackupRestoreScenario sennario)310 ErrCode Service::ReportAppProcessInfo(const std::string &processInfo, const BackupRestoreScenario sennario)
311 {
312     return BError(BError::Codes::OK);
313 }
314 
OnSABackup(const std::string & bundleName,const int & fd,const std::string & result,const ErrCode & errCode)315 void Service::OnSABackup(const std::string &bundleName,
316                          const int &fd,
317                          const std::string &result,
318                          const ErrCode &errCode)
319 {
320 }
321 
OnSARestore(const std::string & bundleName,const std::string & result,const ErrCode & errCode)322 void Service::OnSARestore(const std::string &bundleName, const std::string &result, const ErrCode &errCode) {}
323 
ClearResidualBundleData(const std::string & bundleName)324 ErrCode Service::ClearResidualBundleData(const std::string &bundleName)
325 {
326     return BError(BError::Codes::OK);
327 }
328 
GetExtensionMutex(const BundleName & bundleName)329 std::shared_ptr<ExtensionMutexInfo> Service::GetExtensionMutex(const BundleName &bundleName)
330 {
331     return make_shared<ExtensionMutexInfo>(bundleName);
332 }
333 
RemoveExtensionMutex(const BundleName & bundleName)334 void Service::RemoveExtensionMutex(const BundleName &bundleName)
335 {
336 }
337 
OnBundleStarted(BError error,sptr<SvcSessionManager> session,const BundleName & bundleName)338 void Service::OnBundleStarted(BError error, sptr<SvcSessionManager> session, const BundleName &bundleName) {}
339 
HandleExceptionOnAppendBundles(sptr<SvcSessionManager> session,const vector<BundleName> & appendBundleNames,const vector<BundleName> & restoreBundleNames)340 void Service::HandleExceptionOnAppendBundles(sptr<SvcSessionManager> session,
341     const vector<BundleName> &appendBundleNames, const vector<BundleName> &restoreBundleNames) {}
342 
BundleBeginRadarReport(const std::string & bundleName,const ErrCode errCode,const IServiceReverseType::Scenario scenario)343 void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode,
344     const IServiceReverseType::Scenario scenario) {}
345 
BundleEndRadarReport(const std::string & bundleName,ErrCode errCode,const IServiceReverseType::Scenario scenario)346 void Service::BundleEndRadarReport(const std::string &bundleName, ErrCode errCode,
347     const IServiceReverseType::Scenario scenario) {}
348 
FileReadyRadarReport(const std::string & bundleName,const std::string & fileName,const ErrCode errCode,const IServiceReverseType::Scenario scenario)349 void Service::FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode,
350     const IServiceReverseType::Scenario scenario) {}
351 
ExtensionConnectFailRadarReport(const std::string & bundleName,const ErrCode errCode,const IServiceReverseType::Scenario scenario)352 void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode,
353     const IServiceReverseType::Scenario scenario) {}
354 
PermissionCheckFailRadar(const std::string & info,const std::string & func)355 void Service::PermissionCheckFailRadar(const std::string &info, const std::string &func) {}
356 
OnStartResRadarReport(const std::vector<std::string> & bundleNameList,int32_t stage)357 void Service::OnStartResRadarReport(const std::vector<std::string> &bundleNameList, int32_t stage) {}
358 
GetCallerName()359 std::string Service::GetCallerName()
360 {
361     return "";
362 }
363 
IsReportBundleExecFail(const std::string & bundleName)364 bool Service::IsReportBundleExecFail(const std::string &bundleName)
365 {
366     return true;
367 }
368 
ClearBundleRadarReport()369 void Service::ClearBundleRadarReport() {}
370 
UpdateBundleRadarReport(const std::string & bundleName)371 void Service::UpdateBundleRadarReport(const std::string &bundleName) {}
372 
IsReportFileReadyFail(const std::string & bundleName)373 bool Service::IsReportFileReadyFail(const std::string &bundleName)
374 {
375     return true;
376 }
377 
ClearFileReadyRadarReport()378 void Service::ClearFileReadyRadarReport() {}
379 
UpdateFailedBundles(const std::string & bundleName,BundleTaskInfo taskInfo)380 void Service::UpdateFailedBundles(const std::string &bundleName, BundleTaskInfo taskInfo) {}
381 
ClearFailedBundles()382 void Service::ClearFailedBundles() {}
383 
GetOldDeviceBackupVersion()384 void Service::GetOldDeviceBackupVersion() {}
385 
CreateDirIfNotExist(const std::string & path)386 void Service::CreateDirIfNotExist(const std::string &path)
387 {
388 }
389 
GetSupportBackupBundleNames(vector<BJsonEntityCaps::BundleInfo> &,bool,const vector<string> &)390 std::vector<std::string> Service::GetSupportBackupBundleNames(vector<BJsonEntityCaps::BundleInfo>&, bool,
391     const vector<string>&)
392 {
393     return {};
394 }
395 
StartRunningTimer(const std::string & bundleName)396 void Service::StartRunningTimer(const std::string &bundleName) {}
397 
HandleNotSupportBundleNames(const vector<string> &,vector<string> &,bool)398 void Service::HandleNotSupportBundleNames(const vector<string>&, vector<string>&, bool) {}
399 
SetBundleIncDataInfo(const std::vector<BIncrementalData> &,std::vector<std::string> &)400 void Service::SetBundleIncDataInfo(const std::vector<BIncrementalData>&, std::vector<std::string>&) {}
401 
CancelTask(std::string bundleName,wptr<Service> ptr)402 void Service::CancelTask(std::string bundleName, wptr<Service> ptr) {}
403 
SetUserIdAndRestoreType(RestoreTypeEnum restoreType,int32_t userId)404 void SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {}
405 
CallOnBundleEndByScenario(const std::string & bundleName,BackupRestoreScenario scenario,ErrCode errCode)406 void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario,
407     ErrCode errCode) {}
408 
SetUserIdAndRestoreType(RestoreTypeEnum restoreType,int32_t userId)409 void Service::SetUserIdAndRestoreType(RestoreTypeEnum restoreType, int32_t userId) {}
410 
GetBackupDataSize(bool isPreciseScan,const std::vector<BIncrementalData> & bundleNameList)411 ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector<BIncrementalData> &bundleNameList)
412 {
413     return BError(BError::Codes::OK);
414 }
415 
CleanBundleTempDir(const std::string & bundleName)416 ErrCode Service::CleanBundleTempDir(const std::string& bundleName)
417 {
418     return BError(BError::Codes::OK);
419 }
420 
GetDataSizeStepByStep(bool isPreciseScan,vector<BIncrementalData> bundleNameList,string & scanning)421 void Service::GetDataSizeStepByStep(bool isPreciseScan, vector<BIncrementalData> bundleNameList, string &scanning) {}
422 
GetPresumablySize(vector<BIncrementalData> bundleNameList,string & scanning)423 void Service::GetPresumablySize(vector<BIncrementalData> bundleNameList, string &scanning) {}
424 
GetPrecisesSize(vector<BIncrementalData> bundleNameList,string & scanning)425 void Service::GetPrecisesSize(vector<BIncrementalData> bundleNameList, string &scanning) {}
426 
WriteToList(BJsonUtil::BundleDataSize bundleDataSize)427 void Service::WriteToList(BJsonUtil::BundleDataSize bundleDataSize) {}
428 
DeleteFromList(size_t scannedSize)429 void Service::DeleteFromList(size_t scannedSize) {}
430 
WriteScannedInfoToList(const string & bundleName,int64_t dataSize,int64_t incDataSize)431 void Service::WriteScannedInfoToList(const string &bundleName, int64_t dataSize, int64_t incDataSize) {}
432 
SendScannedInfo(const string & scannendInfos,sptr<SvcSessionManager> session)433 void Service::SendScannedInfo(const string&scannendInfos, sptr<SvcSessionManager> session) {}
434 
CyclicSendScannedInfo(bool isPreciseScan,vector<BIncrementalData> bundleNameList)435 void Service::CyclicSendScannedInfo(bool isPreciseScan, vector<BIncrementalData> bundleNameList) {}
436 
GetScanningInfo(wptr<Service> obj,size_t scannedSize,string & scanning)437 bool Service::GetScanningInfo(wptr<Service> obj, size_t scannedSize, string &scanning)
438 {
439     return true;
440 }
441 
SetScanningInfo(string & scanning,string name)442 void Service::SetScanningInfo(string &scanning, string name) {}
443 
HandleExtDisconnect(BackupRestoreScenario scenario,bool isAppResultReport,ErrCode errCode)444 ErrCode Service::HandleExtDisconnect(BackupRestoreScenario scenario, bool isAppResultReport, ErrCode errCode)
445 {
446     return BError(BError::Codes::OK);
447 }
448 
GetExtOnRelease(bool & isExtOnRelease)449 ErrCode Service::GetExtOnRelease(bool &isExtOnRelease)
450 {
451     return BError(BError::Codes::OK);
452 }
453 
GetCompatibilityInfo(const std::string & bundleName,const std::string & extInfo,std::string & compatInfo)454 ErrCode Service::GetCompatibilityInfo(const std::string &bundleName, const std::string &extInfo,
455     std::string &compatInfo)
456 {
457     return BError(BError::Codes::OK);
458 }
459 
DoNoticeClientFinish(const std::string & bundleName,ErrCode errCode,bool isRestoreEnd)460 void Service::DoNoticeClientFinish(const std::string &bundleName, ErrCode errCode, bool isRestoreEnd) {}
461 } // namespace OHOS::FileManagement::Backup
462