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 #include "screenlock_notify_test_instance.h"
16
17 #include "sclock_log.h"
18
19 namespace OHOS {
20 namespace ScreenLock {
21 constexpr int32_t LISTEN_MASK_BEGIN_WAKEUP = SCREENLOCK_BEGIN_WAKEUP;
22 constexpr int32_t LISTEN_MASK_END_WAKEUP = SCREENLOCK_END_WAKEUP;
23 constexpr int32_t LISTEN_MASK_BEGIN_SCREEN_ON = SCREENLOCK_BEGIN_SCREEN_ON;
24 constexpr int32_t LISTEN_MASK_END_SCREEN_ON = SCREENLOCK_END_SCREEN_ON;
25 constexpr int32_t LISTEN_MASK_BEGIN_SCREEN_OFF = SCREENLOCK_BEGIN_SCREEN_OFF;
26 constexpr int32_t LISTEN_MASK_END_SCREEN_OFF = SCREENLOCK_END_SCREEN_OFF;
27 constexpr int32_t LISTEN_MASK_UNLOCK_SCREEN = SCREENLOCK_UNLOCK_SCREEN;
28 constexpr int32_t LISTEN_MASK_BEGIN_SLEEP = SCREENLOCK_BEGIN_SLEEP;
29 constexpr int32_t LISTEN_MASK_END_SLEEP = SCREENLOCK_END_SLEEP;
30 constexpr int32_t LISTEN_MASK_CHANGE_USER = SCREENLOCK_CHANGE_USER;
31 constexpr int32_t LISTEN_MASK_SCREENLOCK_ENABLED = SCREENLOCK_SCREENLOCK_ENABLED;
32 constexpr int32_t LISTEN_MASK_EXIT_ANIMATION = SCREENLOCK_EXIT_ANIMATION;
ScreenlockNotifyTestInstance(int32_t eventType,std::list<EventListenerTest> & listenerList)33 ScreenlockNotifyTestInstance::ScreenlockNotifyTestInstance(
34 int32_t eventType, std::list<EventListenerTest> &listenerList)
35 {
36 eventType_ = eventType;
37 listenerList_ = &listenerList;
38 }
39
~ScreenlockNotifyTestInstance()40 ScreenlockNotifyTestInstance::~ScreenlockNotifyTestInstance()
41 {
42 }
43
GetEventType(const std::string & type)44 int32_t ScreenlockNotifyTestInstance::GetEventType(const std::string &type)
45 {
46 if (MatchEventType(type, BEGIN_WAKEUP)) {
47 return LISTEN_MASK_BEGIN_WAKEUP;
48 }
49 if (MatchEventType(type, END_WAKEUP)) {
50 return LISTEN_MASK_END_WAKEUP;
51 }
52 if (MatchEventType(type, BEGIN_SCREEN_ON)) {
53 return LISTEN_MASK_BEGIN_SCREEN_ON;
54 }
55 if (MatchEventType(type, END_SCREEN_ON)) {
56 return LISTEN_MASK_END_SCREEN_ON;
57 }
58 if (MatchEventType(type, BEGIN_SCREEN_OFF)) {
59 return LISTEN_MASK_BEGIN_SCREEN_OFF;
60 }
61 if (MatchEventType(type, END_SCREEN_OFF)) {
62 return LISTEN_MASK_END_SCREEN_OFF;
63 }
64 if (MatchEventType(type, EXIT_ANIMATION)) {
65 return LISTEN_MASK_EXIT_ANIMATION;
66 }
67 if (MatchEventType(type, UNLOCKSCREEN)) {
68 return LISTEN_MASK_UNLOCK_SCREEN;
69 }
70 if (MatchEventType(type, BEGIN_SLEEP)) {
71 return LISTEN_MASK_BEGIN_SLEEP;
72 }
73 if (MatchEventType(type, END_SLEEP)) {
74 return LISTEN_MASK_END_SLEEP;
75 }
76 if (MatchEventType(type, CHANGE_USER)) {
77 return LISTEN_MASK_CHANGE_USER;
78 }
79 if (MatchEventType(type, SCREENLOCK_ENABLED)) {
80 return LISTEN_MASK_SCREENLOCK_ENABLED;
81 }
82 if (MatchEventType(type, SYSTEM_READY)) {
83 return static_cast<uint32_t>(SCREENLOCK_SYSTEM_READY);
84 }
85 return NONE_EVENT_TYPE;
86 }
87
MatchEventType(const std::string & type,const std::string & goalTypeStr)88 bool ScreenlockNotifyTestInstance::MatchEventType(const std::string &type, const std::string &goalTypeStr)
89 {
90 return goalTypeStr.compare(type) == 0;
91 }
92
OnCallBack(const std::string & event,bool result)93 void ScreenlockNotifyTestInstance::OnCallBack(const std::string &event, bool result)
94 {
95 SCLOCK_HILOGD("ScreenlockNotifyTestInstance ONCALLBACK_BOOL event----》%{public}s", event.c_str());
96 SCLOCK_HILOGD("ScreenlockNotifyTestInstance ONCALLBACK_BOOL result----》%{public}d", result);
97 for (auto iter = listenerList_->begin(); iter != listenerList_->end(); iter++) {
98 if (iter->eventType == GetEventType(event)) {
99 SCLOCK_HILOGD(
100 "ScreenlockNotifyTestInstance ONCALLBACK_BOOL eventType----》%{public}d", iter->eventType);
101 }
102 }
103 }
104
OnCallBack(const std::string & event)105 void ScreenlockNotifyTestInstance::OnCallBack(const std::string &event)
106 {
107 for (auto iter = listenerList_->begin(); iter != listenerList_->end(); iter++) {
108 if (iter->eventType == GetEventType(event)) {
109 SCLOCK_HILOGD("ScreenlockNotifyTestInstance OnCallBack eventType----》%{public}d", iter->eventType);
110 }
111 }
112 }
113
OnCallBack(const std::string & event,int result)114 void ScreenlockNotifyTestInstance::OnCallBack(const std::string &event, int result)
115 {
116 for (auto iter = listenerList_->begin(); iter != listenerList_->end(); iter++) {
117 if (iter->eventType == GetEventType(event)) {
118 SCLOCK_HILOGD("ScreenlockNotifyTestInstance OnCallBack eventType----》%{public}d", iter->eventType);
119 }
120 }
121 }
122 } // namespace ScreenLock
123 } // namespace OHOS
124