1 /*
2 * Copyright (c) 2022 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 "mock_iability_monitor.h"
17 #include "hilog_tag_wrapper.h"
18
19 namespace {
20 const std::string ABILITY_NAME = "com.example.myapplication.MainAbility";
21 }
22
23 namespace OHOS {
24 namespace AppExecFwk {
MockIabilityMonitor(const std::string & abilityName)25 MockIabilityMonitor::MockIabilityMonitor(const std::string& abilityName) : IAbilityMonitor(abilityName)
26 {
27 start_ = false;
28 foreground_ = false;
29 background_ = false;
30 stop_ = false;
31 windowStageCreate_ = false;
32 windowStageRestore_ = false;
33 windowStageDestroy_ = false;
34 }
35
OnAbilityStart(const std::weak_ptr<NativeReference> & abilityObj)36 void MockIabilityMonitor::OnAbilityStart(const std::weak_ptr<NativeReference>& abilityObj)
37 {
38 TAG_LOGI(AAFwkTag::TEST, "MockIabilityMonitor::OnAbilityStart is called");
39 start_ = true;
40 }
41
OnAbilityForeground(const std::weak_ptr<NativeReference> & abilityObj)42 void MockIabilityMonitor::OnAbilityForeground(const std::weak_ptr<NativeReference>& abilityObj)
43 {
44 TAG_LOGI(AAFwkTag::TEST, "MockIabilityMonitor::OnAbilityForeground is called");
45 foreground_ = true;
46 }
47
OnAbilityBackground(const std::weak_ptr<NativeReference> & abilityObj)48 void MockIabilityMonitor::OnAbilityBackground(const std::weak_ptr<NativeReference>& abilityObj)
49 {
50 TAG_LOGI(AAFwkTag::TEST, "MockIabilityMonitor::OnAbilityBackground is called");
51 background_ = true;
52 }
53
OnAbilityStop(const std::weak_ptr<NativeReference> & abilityObj)54 void MockIabilityMonitor::OnAbilityStop(const std::weak_ptr<NativeReference>& abilityObj)
55 {
56 TAG_LOGI(AAFwkTag::TEST, "MockIabilityMonitor::OnAbilityStop is called");
57 stop_ = true;
58 }
59
OnWindowStageCreate(const std::weak_ptr<NativeReference> & abilityObj)60 void MockIabilityMonitor::OnWindowStageCreate(const std::weak_ptr<NativeReference>& abilityObj)
61 {
62 TAG_LOGI(AAFwkTag::TEST, "MockIabilityMonitor::OnWindowStageCreate is called");
63 windowStageCreate_ = true;
64 }
65
OnWindowStageRestore(const std::weak_ptr<NativeReference> & abilityObj)66 void MockIabilityMonitor::OnWindowStageRestore(const std::weak_ptr<NativeReference>& abilityObj)
67 {
68 TAG_LOGI(AAFwkTag::TEST, "MockIabilityMonitor::OnWindowStageRestore is called");
69 windowStageRestore_ = true;
70 }
71
OnWindowStageDestroy(const std::weak_ptr<NativeReference> & abilityObj)72 void MockIabilityMonitor::OnWindowStageDestroy(const std::weak_ptr<NativeReference>& abilityObj)
73 {
74 TAG_LOGI(AAFwkTag::TEST, "MockIabilityMonitor::OnWindowStageDestroy is called");
75 windowStageDestroy_ = true;
76 }
77
Match(const std::shared_ptr<ADelegatorAbilityProperty> & ability,bool isNotify)78 bool MockIabilityMonitor::Match(const std::shared_ptr<ADelegatorAbilityProperty>& ability, bool isNotify)
79 {
80 TAG_LOGI(AAFwkTag::TEST, "MockIabilityMonitor::Match is called");
81
82 bool ret = false;
83
84 if (ability->name_ == ABILITY_NAME) {
85 ret = true;
86 }
87 return ret;
88 }
89 } // namespace AppExecFwk
90 } // namespace OHOS
91