1 /*
2  * Copyright (c) 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 #ifndef DISPLAY_EVENT_MONITOR_H
17 #define DISPLAY_EVENT_MONITOR_H
18 
19 #include "nocopyable.h"
20 #include "singleton.h"
21 
22 #include "common_event_data.h"
23 #include "common_event_manager.h"
24 #include "common_event_support.h"
25 #include "want.h"
26 
27 #include "define_multimodal.h"
28 #include "fingersense_manager.h"
29 #include "fingersense_wrapper.h"
30 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
31 #include "key_event_normalize.h"
32 #endif // OHOS_BUILD_ENABLE_KEYBOARD
33 #include "mmi_log.h"
34 #include "util.h"
35 
36 namespace OHOS {
37 namespace MMI {
38 class DelegateInterface;
39 class DisplayEventMonitor final {
40     DECLARE_DELAYED_SINGLETON(DisplayEventMonitor);
41     public:
42         DISALLOW_COPY_AND_MOVE(DisplayEventMonitor);
43 
44         void UpdateShieldStatusOnScreenOn();
45         void UpdateShieldStatusOnScreenOff();
46         void InitCommonEventSubscriber();
47         bool IsCommonEventSubscriberInit();
SetScreenStatus(const std::string & screenStatus)48         void SetScreenStatus(const std::string &screenStatus)
49         {
50             screenStatus_ = screenStatus;
51         }
GetScreenStatus()52         const std::string GetScreenStatus()
53         {
54             return screenStatus_;
55         }
SetScreenLocked(bool isLocked)56         void SetScreenLocked(bool isLocked)
57         {
58             isScreenLocked_ = isLocked;
59         }
GetScreenLocked()60         bool GetScreenLocked() const
61         {
62             return isScreenLocked_;
63         }
SetDelegateProxy(std::shared_ptr<DelegateInterface> proxy)64         void SetDelegateProxy(std::shared_ptr<DelegateInterface> proxy)
65         {
66             delegateProxy_ = proxy;
67         }
68         void SendCancelEventWhenLock();
69     private:
70         int32_t shieldModeBeforeSreenOff_ { -1 };
71         std::atomic<bool> hasInit_ { false };
72         std::string screenStatus_;
73         bool isScreenLocked_ { true };
74         std::shared_ptr<DelegateInterface> delegateProxy_ {nullptr};
75 };
76 #define DISPLAY_MONITOR ::OHOS::DelayedSingleton<DisplayEventMonitor>::GetInstance()
77 } // namespace MMI
78 } // namespace OHOS
79 #endif // DISPLAY_EVENT_MONITOR_H
80