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 
OnStart()29 void Service::OnStart() {}
30 
OnStop()31 void Service::OnStop() {}
32 
GetLocalCapabilities()33 UniqueFd Service::GetLocalCapabilities()
34 {
35     return UniqueFd(-1);
36 }
37 
StopAll(const wptr<IRemoteObject> & obj,bool force)38 void Service::StopAll(const wptr<IRemoteObject> &obj, bool force) {}
39 
VerifyCallerAndGetCallerName()40 string Service::VerifyCallerAndGetCallerName()
41 {
42     return "";
43 }
44 
InitRestoreSession(sptr<IServiceReverse> remote)45 ErrCode Service::InitRestoreSession(sptr<IServiceReverse> remote)
46 {
47     return BError(BError::Codes::OK);
48 }
49 
InitBackupSession(sptr<IServiceReverse> remote)50 ErrCode Service::InitBackupSession(sptr<IServiceReverse> remote)
51 {
52     return BError(BError::Codes::OK);
53 }
54 
Start()55 ErrCode Service::Start()
56 {
57     return BError(BError::Codes::OK);
58 }
59 
PublishFile(const BFileInfo & fileInfo)60 ErrCode Service::PublishFile(const BFileInfo &fileInfo)
61 {
62     return BError(BError::Codes::OK);
63 }
64 
AppFileReady(const string & fileName,UniqueFd fd,int32_t errCode)65 ErrCode Service::AppFileReady(const string &fileName, UniqueFd fd, int32_t errCode)
66 {
67     return BError(BError::Codes::OK);
68 }
69 
AppDone(ErrCode errCode)70 ErrCode Service::AppDone(ErrCode errCode)
71 {
72     return BError(BError::Codes::OK);
73 }
74 
ServiceResultReport(const std::string restoreRetInfo,BackupRestoreScenario sennario,ErrCode errCode)75 ErrCode Service::ServiceResultReport(const std::string restoreRetInfo,
76     BackupRestoreScenario sennario, ErrCode errCode)
77 {
78     return BError(BError::Codes::OK);
79 }
80 
AppendBundlesRestoreSession(UniqueFd fd,const std::vector<BundleName> & bundleNames,const std::vector<std::string> & detailInfos,RestoreTypeEnum restoreType,int32_t userId)81 ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const std::vector<BundleName> &bundleNames,
82     const std::vector<std::string> &detailInfos, RestoreTypeEnum restoreType, int32_t userId)
83 {
84     return BError(BError::Codes::OK);
85 }
86 
AppendBundlesRestoreSession(UniqueFd fd,const std::vector<BundleName> & bundleNames,RestoreTypeEnum restoreType,int32_t userId)87 ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd,
88                                              const std::vector<BundleName> &bundleNames,
89                                              RestoreTypeEnum restoreType,
90                                              int32_t userId)
91 {
92     return BError(BError::Codes::OK);
93 }
94 
AppendBundlesBackupSession(const std::vector<BundleName> & bundleNames)95 ErrCode Service::AppendBundlesBackupSession(const std::vector<BundleName> &bundleNames)
96 {
97     return BError(BError::Codes::OK);
98 }
99 
AppendBundlesDetailsBackupSession(const std::vector<BundleName> & bundleNames,const std::vector<std::string> & bundleInfos)100 ErrCode Service::AppendBundlesDetailsBackupSession(const std::vector<BundleName> &bundleNames,
101     const std::vector<std::string> &bundleInfos)
102 {
103     return BError(BError::Codes::OK);
104 }
105 
Finish()106 ErrCode Service::Finish()
107 {
108     return BError(BError::Codes::OK);
109 }
110 
LaunchBackupExtension(const BundleName & bundleName)111 ErrCode Service::LaunchBackupExtension(const BundleName &bundleName)
112 {
113     return BError(BError::Codes::OK);
114 }
115 
LaunchBackupSAExtension(const BundleName & bundleName)116 ErrCode Service::LaunchBackupSAExtension(const BundleName &bundleName)
117 {
118     return BError(BError::Codes::OK);
119 }
120 
GetFileHandle(const string & bundleName,const string & fileName)121 ErrCode Service::GetFileHandle(const string &bundleName, const string &fileName)
122 {
123     return BError(BError::Codes::OK);
124 }
125 
OnBackupExtensionDied(const string && bundleName,bool isSecondCalled)126 void Service::OnBackupExtensionDied(const string &&bundleName, bool isSecondCalled) {}
127 
ExtConnectDied(const string & callName)128 void Service::ExtConnectDied(const string &callName) {}
129 
ExtStart(const string & bundleName)130 void Service::ExtStart(const string &bundleName) {}
131 
Dump(int fd,const vector<u16string> & args)132 int Service::Dump(int fd, const vector<u16string> &args)
133 {
134     return 0;
135 }
136 
ExtConnectFailed(const string & bundleName,ErrCode ret)137 void Service::ExtConnectFailed(const string &bundleName, ErrCode ret)
138 {
139     GTEST_LOG_(INFO) << "ExtConnectFailed is OK";
140 }
141 
ExtConnectDone(string bundleName)142 void Service::ExtConnectDone(string bundleName) {}
143 
ClearSessionAndSchedInfo(const string & bundleName)144 void Service::ClearSessionAndSchedInfo(const string &bundleName) {}
145 
VerifyCaller()146 void Service::VerifyCaller() {}
147 
VerifyCaller(IServiceReverse::Scenario scenario)148 void Service::VerifyCaller(IServiceReverse::Scenario scenario) {}
149 
OnAllBundlesFinished(ErrCode errCode)150 void Service::OnAllBundlesFinished(ErrCode errCode) {}
151 
OnStartSched()152 void Service::OnStartSched() {}
153 
SendStartAppGalleryNotify(const BundleName & bundleName)154 void Service::SendStartAppGalleryNotify(const BundleName &bundleName) {}
155 
SessionDeactive()156 void Service::SessionDeactive() {}
157 
Release()158 ErrCode Service::Release()
159 {
160     return BError(BError::Codes::OK);
161 }
162 
GetLocalCapabilitiesIncremental(const std::vector<BIncrementalData> & bundleNames)163 UniqueFd Service::GetLocalCapabilitiesIncremental(const std::vector<BIncrementalData> &bundleNames)
164 {
165     return UniqueFd(-1);
166 }
167 
GetAppLocalListAndDoIncrementalBackup()168 ErrCode Service::GetAppLocalListAndDoIncrementalBackup()
169 {
170     return BError(BError::Codes::OK);
171 }
172 
InitIncrementalBackupSession(sptr<IServiceReverse> remote)173 ErrCode Service::InitIncrementalBackupSession(sptr<IServiceReverse> remote)
174 {
175     return BError(BError::Codes::OK);
176 }
177 
AppendBundlesIncrementalBackupSession(const std::vector<BIncrementalData> & bundlesToBackup)178 ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector<BIncrementalData> &bundlesToBackup)
179 {
180     return BError(BError::Codes::OK);
181 }
182 
AppendBundlesIncrementalBackupSession(const std::vector<BIncrementalData> & bundlesToBackup,const std::vector<std::string> & infos)183 ErrCode Service::AppendBundlesIncrementalBackupSession(const std::vector<BIncrementalData> &bundlesToBackup,
184     const std::vector<std::string> &infos)
185 {
186     return BError(BError::Codes::OK);
187 }
188 
PublishIncrementalFile(const BFileInfo & fileInfo)189 ErrCode Service::PublishIncrementalFile(const BFileInfo &fileInfo)
190 {
191     return BError(BError::Codes::OK);
192 }
193 
PublishSAIncrementalFile(const BFileInfo & fileInfo,UniqueFd fd)194 ErrCode Service::PublishSAIncrementalFile(const BFileInfo &fileInfo, UniqueFd fd)
195 {
196     return BError(BError::Codes::OK);
197 }
198 
AppIncrementalFileReady(const string & fileName,UniqueFd fd,UniqueFd manifestFd,int32_t errCode)199 ErrCode Service::AppIncrementalFileReady(const string &fileName, UniqueFd fd, UniqueFd manifestFd, int32_t errCode)
200 {
201     return BError(BError::Codes::OK);
202 }
203 
AppIncrementalDone(ErrCode errCode)204 ErrCode Service::AppIncrementalDone(ErrCode errCode)
205 {
206     return BError(BError::Codes::OK);
207 }
208 
GetIncrementalFileHandle(const string & bundleName,const string & fileName)209 ErrCode Service::GetIncrementalFileHandle(const string &bundleName, const string &fileName)
210 {
211     return BError(BError::Codes::OK);
212 }
213 
GetBackupInfo(BundleName & bundleName,std::string & result)214 ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result)
215 {
216     return BError(BError::Codes::OK);
217 }
218 
StartExtTimer(bool & isExtStart)219 ErrCode Service::StartExtTimer(bool &isExtStart)
220 {
221     return BError(BError::Codes::OK);
222 }
223 
StartFwkTimer(bool & isFwkStart)224 ErrCode Service::StartFwkTimer(bool &isFwkStart)
225 {
226     return BError(BError::Codes::OK);
227 }
228 
UpdateTimer(BundleName & bundleName,uint32_t timeout,bool & result)229 ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result)
230 {
231     return BError(BError::Codes::OK);
232 }
233 
UpdateSendRate(std::string & bundleName,int32_t sendRate,bool & result)234 ErrCode Service::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result)
235 {
236     return BError(BError::Codes::OK);
237 }
238 
ReportAppProcessInfo(const std::string processInfo,const BackupRestoreScenario sennario)239 ErrCode Service::ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario)
240 {
241     return BError(BError::Codes::OK);
242 }
243 
OnSABackup(const std::string & bundleName,const int & fd,const std::string & result,const ErrCode & errCode)244 void Service::OnSABackup(const std::string &bundleName,
245                          const int &fd,
246                          const std::string &result,
247                          const ErrCode &errCode)
248 {
249 }
250 
OnSARestore(const std::string & bundleName,const std::string & result,const ErrCode & errCode)251 void Service::OnSARestore(const std::string &bundleName, const std::string &result, const ErrCode &errCode) {}
252 
ClearResidualBundleData(const std::string & bundleName)253 ErrCode Service::ClearResidualBundleData(const std::string &bundleName)
254 {
255     return BError(BError::Codes::OK);
256 }
257 
GetExtensionMutex(const BundleName & bundleName)258 std::shared_ptr<ExtensionMutexInfo> Service::GetExtensionMutex(const BundleName &bundleName)
259 {
260     return nullptr;
261 }
262 
RemoveExtensionMutex(const BundleName & bundleName)263 void Service::RemoveExtensionMutex(const BundleName &bundleName)
264 {
265 }
266 
CreateDirIfNotExist(const std::string & path)267 void Service::CreateDirIfNotExist(const std::string &path)
268 {
269 }
270 
OnBundleStarted(BError error,sptr<SvcSessionManager> session,const BundleName & bundleName)271 void Service::OnBundleStarted(BError error, sptr<SvcSessionManager> session, const BundleName &bundleName) {}
272 
HandleExceptionOnAppendBundles(sptr<SvcSessionManager> session,const vector<BundleName> & appendBundleNames,const vector<BundleName> & restoreBundleNames)273 void Service::HandleExceptionOnAppendBundles(sptr<SvcSessionManager> session,
274     const vector<BundleName> &appendBundleNames, const vector<BundleName> &restoreBundleNames) {}
275 
BundleBeginRadarReport(const std::string & bundleName,const ErrCode errCode,const IServiceReverse::Scenario scenario)276 void Service::BundleBeginRadarReport(const std::string &bundleName, const ErrCode errCode,
277     const IServiceReverse::Scenario scenario) {}
278 
BundleEndRadarReport(const std::string & bundleName,const ErrCode errCode,const IServiceReverse::Scenario scenario)279 void Service::BundleEndRadarReport(const std::string &bundleName, const ErrCode errCode,
280     const IServiceReverse::Scenario scenario) {}
281 
FileReadyRadarReport(const std::string & bundleName,const std::string & fileName,const ErrCode errCode,const IServiceReverse::Scenario scenario)282 void Service::FileReadyRadarReport(const std::string &bundleName, const std::string &fileName, const ErrCode errCode,
283     const IServiceReverse::Scenario scenario) {}
284 
ExtensionConnectFailRadarReport(const std::string & bundleName,const ErrCode errCode,const IServiceReverse::Scenario scenario)285 void Service::ExtensionConnectFailRadarReport(const std::string &bundleName, const ErrCode errCode,
286     const IServiceReverse::Scenario scenario) {}
287 
UpdateFailedBundles(const std::string & bundleName,BundleTaskInfo taskInfo)288 void Service::UpdateFailedBundles(const std::string &bundleName, BundleTaskInfo taskInfo) {}
289 
ClearFailedBundles()290 void Service::ClearFailedBundles() {}
291 
StartRunningTimer(const std::string & bundleName)292 void Service::StartRunningTimer(const std::string &bundleName) {}
GetSupportBackupBundleNames(vector<BJsonEntityCaps::BundleInfo> &,bool,const vector<string> &)293 std::vector<std::string> Service::GetSupportBackupBundleNames(vector<BJsonEntityCaps::BundleInfo>&, bool,
294     const vector<string>&)
295 {
296     return {};
297 }
HandleNotSupportBundleNames(const vector<string> &,vector<string> &,bool)298 void Service::HandleNotSupportBundleNames(const vector<string>&, vector<string>&, bool) {}
SetBundleIncDataInfo(const std::vector<BIncrementalData> &,std::vector<std::string> &)299 void Service::SetBundleIncDataInfo(const std::vector<BIncrementalData>&, std::vector<std::string>&) {}
300 } // namespace OHOS::FileManagement::Backup
301