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 "hilog_tag_wrapper.h"
17 #include "mock_ability_delegator_stub.h"
18
19 namespace OHOS {
20 namespace AAFwk {
21 namespace {
22 const std::string STRING_BUNDLENAME_EX = "com.example.myapplication1";
23 }
24
25 bool MockAbilityDelegatorStub::finishFlag_ = false;
26
MockAbilityDelegatorStub()27 MockAbilityDelegatorStub::MockAbilityDelegatorStub()
28 {}
29
StartAbility(const Want & want,int32_t userId,int requestCode)30 int MockAbilityDelegatorStub::StartAbility(const Want& want, int32_t userId, int requestCode)
31 {
32 return 0;
33 }
34
CloseAbility(const sptr<IRemoteObject> & token,int resultCode,const Want * resultWant)35 int MockAbilityDelegatorStub::CloseAbility(const sptr<IRemoteObject>& token, int resultCode, const Want* resultWant)
36 {
37 return 0;
38 }
39
StartAbility(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,int requestCode,int32_t userId)40 int MockAbilityDelegatorStub::StartAbility(const Want& want, const StartOptions& startOptions,
41 const sptr<IRemoteObject>& callerToken, int requestCode, int32_t userId)
42 {
43 return 0;
44 }
45
StartAbilityAsCaller(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,sptr<IRemoteObject> asCallerSourceToken,int requestCode,int32_t userId)46 int MockAbilityDelegatorStub::StartAbilityAsCaller(const Want& want, const StartOptions& startOptions,
47 const sptr<IRemoteObject>& callerToken, sptr<IRemoteObject> asCallerSourceToken,
48 int requestCode, int32_t userId)
49 {
50 return 0;
51 }
52
MinimizeAbility(const sptr<IRemoteObject> & token,bool fromUser)53 int MockAbilityDelegatorStub::MinimizeAbility(const sptr<IRemoteObject>& token, bool fromUser)
54 {
55 return 0;
56 }
57
DumpState(const std::string & args,std::vector<std::string> & state)58 void MockAbilityDelegatorStub::DumpState(const std::string& args, std::vector<std::string>& state)
59 {
60 return;
61 }
62
StartUser(int userId,sptr<IUserCallback> callback)63 int MockAbilityDelegatorStub::StartUser(int userId, sptr<IUserCallback> callback)
64 {
65 return 0;
66 }
67
StopUser(int userId,const sptr<IUserCallback> & callback)68 int MockAbilityDelegatorStub::StopUser(int userId, const sptr<IUserCallback>& callback)
69 {
70 return 0;
71 }
72
LogoutUser(int32_t userId)73 int MockAbilityDelegatorStub::LogoutUser(int32_t userId)
74 {
75 return 0;
76 }
77
StartSyncRemoteMissions(const std::string & devId,bool fixConflict,int64_t tag)78 int MockAbilityDelegatorStub::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag)
79 {
80 return 0;
81 }
82
StopSyncRemoteMissions(const std::string & devId)83 int MockAbilityDelegatorStub::StopSyncRemoteMissions(const std::string& devId)
84 {
85 return 0;
86 }
87
RegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)88 int MockAbilityDelegatorStub::RegisterMissionListener(const std::string& deviceId,
89 const sptr<IRemoteMissionListener>& listener)
90 {
91 return 0;
92 }
93
UnRegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)94 int MockAbilityDelegatorStub::UnRegisterMissionListener(const std::string& deviceId,
95 const sptr<IRemoteMissionListener>& listener)
96 {
97 return 0;
98 }
99
StartAbilityByCall(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,int32_t accountId)100 int MockAbilityDelegatorStub::StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
101 const sptr<IRemoteObject>& callerToken, int32_t accountId)
102 {
103 return 0;
104 }
105
CallRequestDone(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & callStub)106 void MockAbilityDelegatorStub::CallRequestDone(
107 const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callStub)
108 {
109 return;
110 }
111
ReleaseCall(const sptr<IAbilityConnection> & connect,const AppExecFwk::ElementName & element)112 int MockAbilityDelegatorStub::ReleaseCall(const sptr<IAbilityConnection>& connect,
113 const AppExecFwk::ElementName& element)
114 {
115 return 0;
116 }
117
GetMissionSnapshot(const std::string & deviceId,int32_t missionId,MissionSnapshot & snapshot,bool isLowResolution)118 int MockAbilityDelegatorStub::GetMissionSnapshot(const std::string& deviceId, int32_t missionId,
119 MissionSnapshot& snapshot, bool isLowResolution)
120 {
121 return 0;
122 }
123
RegisterSnapshotHandler(const sptr<ISnapshotHandler> & handler)124 int MockAbilityDelegatorStub::RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
125 {
126 return 0;
127 }
128
ReportDrawnCompleted(const sptr<IRemoteObject> & callerToken)129 int32_t MockAbilityDelegatorStub::ReportDrawnCompleted(const sptr<IRemoteObject>& callerToken)
130 {
131 return 0;
132 }
133
SetAbilityController(const sptr<AppExecFwk::IAbilityController> & abilityController,bool imAStabilityTest)134 int MockAbilityDelegatorStub::SetAbilityController(const sptr<AppExecFwk::IAbilityController>& abilityController,
135 bool imAStabilityTest)
136 {
137 return 0;
138 }
139
IsRunningInStabilityTest()140 bool MockAbilityDelegatorStub::IsRunningInStabilityTest()
141 {
142 return true;
143 }
144
DumpSysState(const std::string & args,std::vector<std::string> & info,bool isClient,bool isUserID,int UserID)145 void MockAbilityDelegatorStub::DumpSysState(
146 const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int UserID)
147 {
148 return;
149 }
150
StartUserTest(const Want & want,const sptr<IRemoteObject> & observer)151 int MockAbilityDelegatorStub::StartUserTest(const Want& want, const sptr<IRemoteObject>& observer)
152 {
153 if (want.GetStringParam("-p") == STRING_BUNDLENAME_EX) {
154 return ERR_INVALID_VALUE;
155 }
156 return OHOS::ERR_OK;
157 }
158
StopServiceAbility(const Want & want,int32_t userId,const sptr<IRemoteObject> & token)159 int MockAbilityDelegatorStub::StopServiceAbility(const Want& want, int32_t userId, const sptr<IRemoteObject> &token)
160 {
161 return 0;
162 }
163
GetTopAbility(sptr<IRemoteObject> & token)164 int MockAbilityDelegatorStub::GetTopAbility(sptr<IRemoteObject>& token)
165 {
166 TAG_LOGI(AAFwkTag::TEST, "MockAbilityDelegatorStub::GetTopAbility is called");
167 token = sptr<IRemoteObject>(new MockAbilityDelegatorStub);
168 return OHOS::ERR_OK;
169 }
170
DelegatorDoAbilityForeground(const sptr<IRemoteObject> & token)171 int MockAbilityDelegatorStub::DelegatorDoAbilityForeground(const sptr<IRemoteObject>& token)
172 {
173 TAG_LOGI(AAFwkTag::TEST, "MockAbilityDelegatorStub::DelegatorDoAbilityForeground is called");
174 return OHOS::ERR_OK;
175 }
176
DelegatorDoAbilityBackground(const sptr<IRemoteObject> & token)177 int MockAbilityDelegatorStub::DelegatorDoAbilityBackground(const sptr<IRemoteObject>& token)
178 {
179 TAG_LOGI(AAFwkTag::TEST, "MockAbilityDelegatorStub::DelegatorDoAbilityBackground is called");
180 return OHOS::ERR_OK;
181 }
182
FinishUserTest(const std::string & msg,const int64_t & resultCode,const std::string & bundleName)183 int MockAbilityDelegatorStub::FinishUserTest(const std::string& msg,
184 const int64_t& resultCode, const std::string& bundleName)
185 {
186 TAG_LOGI(AAFwkTag::TEST, "MockAbilityDelegatorStub::FinishUserTest is called");
187 finishFlag_ = true;
188 return OHOS::ERR_OK;
189 }
190
DoAbilityForeground(const sptr<IRemoteObject> & token,uint32_t flag)191 int MockAbilityDelegatorStub::DoAbilityForeground(const sptr<IRemoteObject>& token, uint32_t flag)
192 {
193 return 0;
194 }
195
DoAbilityBackground(const sptr<IRemoteObject> & token,uint32_t flag)196 int MockAbilityDelegatorStub::DoAbilityBackground(const sptr<IRemoteObject>& token, uint32_t flag)
197 {
198 return 0;
199 }
200
GetMissionIdByToken(const sptr<IRemoteObject> & token)201 int32_t MockAbilityDelegatorStub::GetMissionIdByToken(const sptr<IRemoteObject>& token)
202 {
203 return 0;
204 }
205
GetAbilityTokenByCalleeObj(const sptr<IRemoteObject> & callStub,sptr<IRemoteObject> & token)206 void MockAbilityDelegatorStub::GetAbilityTokenByCalleeObj(const sptr<IRemoteObject> &callStub,
207 sptr<IRemoteObject> &token)
208 {
209 return;
210 }
211
212 bool MockAbilityDelegatorStub2::finishFlag_ = false;
213 TESTCASE_BRANCH MockAbilityDelegatorStub2::testcaseBranch_ = TESTCASE_BRANCH::BRANCH_1;
214
MockAbilityDelegatorStub2()215 MockAbilityDelegatorStub2::MockAbilityDelegatorStub2()
216 {}
217
StartAbility(const Want & want,int32_t userId,int requestCode)218 int MockAbilityDelegatorStub2::StartAbility(const Want& want, int32_t userId, int requestCode)
219 {
220 return 0;
221 }
222
StartAbility(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,int requestCode,int32_t userId)223 int MockAbilityDelegatorStub2::StartAbility(const Want& want, const StartOptions& startOptions,
224 const sptr<IRemoteObject>& callerToken, int requestCode, int32_t userId)
225 {
226 return 0;
227 }
228
StartAbilityAsCaller(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,sptr<IRemoteObject> asCallerSourceToken,int requestCode,int32_t userId)229 int MockAbilityDelegatorStub2::StartAbilityAsCaller(const Want& want, const StartOptions& startOptions,
230 const sptr<IRemoteObject>& callerToken, sptr<IRemoteObject> asCallerSourceToken,
231 int requestCode, int32_t userId)
232 {
233 return 0;
234 }
235
CloseAbility(const sptr<IRemoteObject> & token,int resultCode,const Want * resultWant)236 int MockAbilityDelegatorStub2::CloseAbility(const sptr<IRemoteObject>& token, int resultCode, const Want* resultWant)
237 {
238 return 0;
239 }
240
MinimizeAbility(const sptr<IRemoteObject> & token,bool fromUser)241 int MockAbilityDelegatorStub2::MinimizeAbility(const sptr<IRemoteObject>& token, bool fromUser)
242 {
243 return 0;
244 }
245
DumpState(const std::string & args,std::vector<std::string> & state)246 void MockAbilityDelegatorStub2::DumpState(const std::string& args, std::vector<std::string>& state)
247 {
248 return;
249 }
250
StopServiceAbility(const Want & want,int32_t userId,const sptr<IRemoteObject> & token)251 int MockAbilityDelegatorStub2::StopServiceAbility(const Want& want, int32_t userId, const sptr<IRemoteObject> &token)
252 {
253 return 0;
254 }
255
StartUser(int userId,sptr<IUserCallback> callback)256 int MockAbilityDelegatorStub2::StartUser(int userId, sptr<IUserCallback> callback)
257 {
258 return 0;
259 }
260
StopUser(int userId,const sptr<IUserCallback> & callback)261 int MockAbilityDelegatorStub2::StopUser(int userId, const sptr<IUserCallback>& callback)
262 {
263 return 0;
264 }
265
LogoutUser(int32_t userId)266 int MockAbilityDelegatorStub2::LogoutUser(int32_t userId)
267 {
268 return 0;
269 }
270
StartSyncRemoteMissions(const std::string & devId,bool fixConflict,int64_t tag)271 int MockAbilityDelegatorStub2::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag)
272 {
273 return 0;
274 }
275
StopSyncRemoteMissions(const std::string & devId)276 int MockAbilityDelegatorStub2::StopSyncRemoteMissions(const std::string& devId)
277 {
278 return 0;
279 }
280
RegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)281 int MockAbilityDelegatorStub2::RegisterMissionListener(const std::string& deviceId,
282 const sptr<IRemoteMissionListener>& listener)
283 {
284 return 0;
285 }
286
UnRegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)287 int MockAbilityDelegatorStub2::UnRegisterMissionListener(const std::string& deviceId,
288 const sptr<IRemoteMissionListener>& listener)
289 {
290 return 0;
291 }
292
StartAbilityByCall(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,int32_t accountId)293 int MockAbilityDelegatorStub2::StartAbilityByCall(const Want& want, const sptr<IAbilityConnection>& connect,
294 const sptr<IRemoteObject>& callerToken, int32_t accountId)
295 {
296 return 0;
297 }
298
CallRequestDone(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & callStub)299 void MockAbilityDelegatorStub2::CallRequestDone(
300 const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callStub)
301 {
302 return;
303 }
304
ReleaseCall(const sptr<IAbilityConnection> & connect,const AppExecFwk::ElementName & element)305 int MockAbilityDelegatorStub2::ReleaseCall(const sptr<IAbilityConnection>& connect,
306 const AppExecFwk::ElementName& element)
307 {
308 return 0;
309 }
310
GetMissionSnapshot(const std::string & deviceId,int32_t missionId,MissionSnapshot & snapshot,bool isLowResolution)311 int MockAbilityDelegatorStub2::GetMissionSnapshot(const std::string& deviceId, int32_t missionId,
312 MissionSnapshot& snapshot, bool isLowResolution)
313 {
314 return 0;
315 }
316
RegisterSnapshotHandler(const sptr<ISnapshotHandler> & handler)317 int MockAbilityDelegatorStub2::RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
318 {
319 return 0;
320 }
321
SetAbilityController(const sptr<AppExecFwk::IAbilityController> & abilityController,bool imAStabilityTest)322 int MockAbilityDelegatorStub2::SetAbilityController(const sptr<AppExecFwk::IAbilityController>& abilityController,
323 bool imAStabilityTest)
324 {
325 return 0;
326 }
327
IsRunningInStabilityTest()328 bool MockAbilityDelegatorStub2::IsRunningInStabilityTest()
329 {
330 return true;
331 }
332
DumpSysState(const std::string & args,std::vector<std::string> & info,bool isClient,bool isUserID,int UserID)333 void MockAbilityDelegatorStub2::DumpSysState(
334 const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int UserID)
335 {
336 return;
337 }
338
StartUserTest(const Want & want,const sptr<IRemoteObject> & observer)339 int MockAbilityDelegatorStub2::StartUserTest(const Want& want, const sptr<IRemoteObject>& observer)
340 {
341 if (want.GetStringParam("-p") == STRING_BUNDLENAME_EX) {
342 return ERR_INVALID_VALUE;
343 }
344 return OHOS::ERR_OK;
345 }
346
GetTopAbility(sptr<IRemoteObject> & token)347 int MockAbilityDelegatorStub2::GetTopAbility(sptr<IRemoteObject>& token)
348 {
349 TAG_LOGI(AAFwkTag::TEST, "MockAbilityDelegatorStub2::GetTopAbility is called");
350 return OHOS::ERR_INVALID_VALUE;
351 }
352
GetTopAbility(bool isNeedLocalDeviceId)353 AppExecFwk::ElementName MockAbilityDelegatorStub2::GetTopAbility(bool isNeedLocalDeviceId)
354 {
355 TAG_LOGI(AAFwkTag::TEST, "GetTopAbility.");
356 AppExecFwk::ElementName elementName = {};
357
358 if (testcaseBranch_ == TESTCASE_BRANCH::BRANCH_2) {
359 elementName = AppExecFwk::ElementName("deviceId", "com.ohos.bundleName", "EntryAbility", "entry");
360 } else if (testcaseBranch_ == TESTCASE_BRANCH::BRANCH_3) {
361 elementName = AppExecFwk::ElementName("deviceId", "com.example.myapplication",
362 "com.example.myapplication.MainAbility", "entry");
363 } else {
364 TAG_LOGI(AAFwkTag::TEST, "Empty top ability.");
365 }
366
367 return elementName;
368 }
369
DelegatorDoAbilityForeground(const sptr<IRemoteObject> & token)370 int MockAbilityDelegatorStub2::DelegatorDoAbilityForeground(const sptr<IRemoteObject>& token)
371 {
372 TAG_LOGI(AAFwkTag::TEST, "MockAbilityDelegatorStub2::DelegatorDoAbilityForeground is called");
373 return OHOS::ERR_INVALID_VALUE;
374 }
375
DelegatorDoAbilityBackground(const sptr<IRemoteObject> & token)376 int MockAbilityDelegatorStub2::DelegatorDoAbilityBackground(const sptr<IRemoteObject>& token)
377 {
378 TAG_LOGI(AAFwkTag::TEST, "MockAbilityDelegatorStub2::DelegatorDoAbilityBackground is called");
379 return OHOS::ERR_INVALID_VALUE;
380 }
381
FinishUserTest(const std::string & msg,const int64_t & resultCode,const std::string & bundleName)382 int MockAbilityDelegatorStub2::FinishUserTest(const std::string& msg,
383 const int64_t& resultCode, const std::string& bundleName)
384 {
385 TAG_LOGI(AAFwkTag::TEST, "MockAbilityDelegatorStub2::FinishUserTest is called");
386 finishFlag_ = false;
387 return OHOS::ERR_INVALID_VALUE;
388 }
389
DoAbilityForeground(const sptr<IRemoteObject> & token,uint32_t flag)390 int MockAbilityDelegatorStub2::DoAbilityForeground(const sptr<IRemoteObject>& token, uint32_t flag)
391 {
392 return 0;
393 }
394
DoAbilityBackground(const sptr<IRemoteObject> & token,uint32_t flag)395 int MockAbilityDelegatorStub2::DoAbilityBackground(const sptr<IRemoteObject>& token, uint32_t flag)
396 {
397 return 0;
398 }
399
GetMissionIdByToken(const sptr<IRemoteObject> & token)400 int32_t MockAbilityDelegatorStub2::GetMissionIdByToken(const sptr<IRemoteObject>& token)
401 {
402 return 0;
403 }
404
GetAbilityTokenByCalleeObj(const sptr<IRemoteObject> & callStub,sptr<IRemoteObject> & token)405 void MockAbilityDelegatorStub2::GetAbilityTokenByCalleeObj(const sptr<IRemoteObject> &callStub,
406 sptr<IRemoteObject> &token)
407 {
408 return;
409 }
410
ReportDrawnCompleted(const sptr<IRemoteObject> & callerToken)411 int32_t MockAbilityDelegatorStub2::ReportDrawnCompleted(const sptr<IRemoteObject>& callerToken)
412 {
413 return 0;
414 }
415
416 #ifdef ABILITY_COMMAND_FOR_TEST
ForceTimeoutForTest(const std::string & abilityName,const std::string & state)417 int MockAbilityDelegatorStub::ForceTimeoutForTest(const std::string& abilityName, const std::string& state)
418 {
419 return 0;
420 }
421
ForceTimeoutForTest(const std::string & abilityName,const std::string & state)422 int MockAbilityDelegatorStub2::ForceTimeoutForTest(const std::string& abilityName, const std::string& state)
423 {
424 return 0;
425 }
426 #endif
427
428 #ifdef SUPPORT_GRAPHICS
SetMissionIcon(const sptr<IRemoteObject> & token,const std::shared_ptr<OHOS::Media::PixelMap> & icon)429 int MockAbilityDelegatorStub::SetMissionIcon(
430 const sptr<IRemoteObject>& token, const std::shared_ptr<OHOS::Media::PixelMap>& icon)
431 {
432 return 0;
433 }
434
RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler> & handler,bool animationEnabled)435 int MockAbilityDelegatorStub::RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler,
436 bool animationEnabled)
437 {
438 return 0;
439 }
440
SetMissionIcon(const sptr<IRemoteObject> & token,const std::shared_ptr<OHOS::Media::PixelMap> & icon)441 int MockAbilityDelegatorStub2::SetMissionIcon(
442 const sptr<IRemoteObject>& token, const std::shared_ptr<OHOS::Media::PixelMap>& icon)
443 {
444 return 0;
445 }
446
RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler> & handler,bool animationEnabled)447 int MockAbilityDelegatorStub2::RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler,
448 bool animationEnabled)
449 {
450 return 0;
451 }
452 #endif
453 } // namespace AAFwk
454 } // namespace OHOS
455