• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "display_event_monitor.h"
17 
18 #include "common_event_data.h"
19 #include "common_event_manager.h"
20 #include "common_event_support.h"
21 #include "define_multimodal.h"
22 #include "fingersense_manager.h"
23 #include "fingersense_wrapper.h"
24 #include "mmi_log.h"
25 #include "want.h"
26 
27 namespace OHOS {
28 namespace MMI {
29 namespace {
30 #ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
31 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "DisplayEventMonitor" };
32 #endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
33 } // namespace
34 
DisplayEventMonitor()35 DisplayEventMonitor::DisplayEventMonitor() {}
~DisplayEventMonitor()36 DisplayEventMonitor::~DisplayEventMonitor() {}
37 
38 #ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
39 class DisplyChangedReceiver : public EventFwk::CommonEventSubscriber {
40 public:
DisplyChangedReceiver(const OHOS::EventFwk::CommonEventSubscribeInfo & subscribeInfo)41     explicit DisplyChangedReceiver(const OHOS::EventFwk::CommonEventSubscribeInfo& subscribeInfo)
42         : OHOS::EventFwk::CommonEventSubscriber(subscribeInfo)
43     {
44         MMI_HILOGD("DisplyChangedReceiver register");
45     }
46 
47     virtual ~DisplyChangedReceiver() = default;
48 
OnReceiveEvent(const EventFwk::CommonEventData & eventData)49     void OnReceiveEvent(const EventFwk::CommonEventData &eventData)
50     {
51         CALL_DEBUG_ENTER;
52         std::string action = eventData.GetWant().GetAction();
53         if (action.empty()) {
54             MMI_HILOGE("action is empty");
55             return;
56         }
57         if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON) {
58             MMI_HILOGD("display screen on");
59             if (FINGERSENSE_WRAPPER->enableFingersense_ != nullptr) {
60                 MMI_HILOGD("start enable fingersense");
61                 FINGERSENSE_WRAPPER->enableFingersense_();
62             }
63         } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF) {
64             MMI_HILOGD("display screen off");
65             if (FINGERSENSE_WRAPPER->disableFingerSense_ != nullptr) {
66                 FINGERSENSE_WRAPPER->disableFingerSense_();
67             }
68         } else {
69             MMI_HILOGW("Screen changed receiver event: unknown");
70             return;
71         }
72     }
73 };
74 
InitCommonEventSubscriber()75 void DisplayEventMonitor::InitCommonEventSubscriber()
76 {
77     CALL_DEBUG_ENTER;
78     if (hasInit_) {
79         MMI_HILOGE("current common event has subscribered");
80         return;
81     }
82     EventFwk::MatchingSkills matchingSkills;
83     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON);
84     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
85     EventFwk::CommonEventSubscribeInfo commonEventSubscribeInfo(matchingSkills);
86     hasInit_ = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(
87         std::make_shared<DisplyChangedReceiver>(commonEventSubscribeInfo));
88 }
89 #endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
90 } // namespace AppExecFwk
91 } // namespace OHOS