• 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 namespace OHOS {
19 namespace MMI {
20 namespace {
21 #ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
22 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "DisplayEventMonitor" };
23 #endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
24 } // namespace
25 
DisplayEventMonitor()26 DisplayEventMonitor::DisplayEventMonitor() {}
~DisplayEventMonitor()27 DisplayEventMonitor::~DisplayEventMonitor() {}
28 
29 #ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
30 class DisplyChangedReceiver : public EventFwk::CommonEventSubscriber {
31 public:
DisplyChangedReceiver(const OHOS::EventFwk::CommonEventSubscribeInfo & subscribeInfo)32     explicit DisplyChangedReceiver(const OHOS::EventFwk::CommonEventSubscribeInfo& subscribeInfo)
33         : OHOS::EventFwk::CommonEventSubscriber(subscribeInfo)
34     {
35         MMI_HILOGD("DisplyChangedReceiver register");
36     }
37 
38     virtual ~DisplyChangedReceiver() = default;
39     __attribute__((no_sanitize("cfi")))
OnReceiveEvent(const EventFwk::CommonEventData & eventData)40     void OnReceiveEvent(const EventFwk::CommonEventData &eventData)
41     {
42         CALL_DEBUG_ENTER;
43         std::string action = eventData.GetWant().GetAction();
44         if (action.empty()) {
45             MMI_HILOGE("action is empty");
46             return;
47         }
48         if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON) {
49             MMI_HILOGD("display screen on");
50             if (FINGERSENSE_WRAPPER->enableFingersense_ != nullptr) {
51                 MMI_HILOGD("start enable fingersense");
52                 FINGERSENSE_WRAPPER->enableFingersense_();
53             }
54             DISPLAY_MONITOR->UpdateShieldStatusOnScreenOn();
55         } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF) {
56             MMI_HILOGD("display screen off");
57             if (FINGERSENSE_WRAPPER->disableFingerSense_ != nullptr) {
58                 FINGERSENSE_WRAPPER->disableFingerSense_();
59             }
60             DISPLAY_MONITOR->UpdateShieldStatusOnScreenOff();
61         } else {
62             MMI_HILOGW("Screen changed receiver event: unknown");
63             return;
64         }
65     }
66 };
67 
UpdateShieldStatusOnScreenOn()68 void DisplayEventMonitor::UpdateShieldStatusOnScreenOn()
69 {
70     CALL_DEBUG_ENTER;
71     if (shieldModeBeforeSreenOff_ != SHIELD_MODE::UNSET_MODE) {
72         KeyEventHdr->SetCurrentShieldMode(shieldModeBeforeSreenOff_);
73     } else {
74         MMI_HILOGD("shield mode before screen off: %{public}d", shieldModeBeforeSreenOff_);
75     }
76 }
77 
UpdateShieldStatusOnScreenOff()78 void DisplayEventMonitor::UpdateShieldStatusOnScreenOff()
79 {
80     CALL_DEBUG_ENTER;
81     shieldModeBeforeSreenOff_ = KeyEventHdr->GetCurrentShieldMode();
82     if (shieldModeBeforeSreenOff_ != SHIELD_MODE::UNSET_MODE) {
83         KeyEventHdr->SetCurrentShieldMode(SHIELD_MODE::UNSET_MODE);
84     } else {
85         MMI_HILOGD("shield mode before screen off: %{public}d", shieldModeBeforeSreenOff_);
86     }
87 }
88 
InitCommonEventSubscriber()89 void DisplayEventMonitor::InitCommonEventSubscriber()
90 {
91     CALL_DEBUG_ENTER;
92     if (hasInit_) {
93         MMI_HILOGE("current common event has subscribered");
94         return;
95     }
96     EventFwk::MatchingSkills matchingSkills;
97     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON);
98     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
99     EventFwk::CommonEventSubscribeInfo commonEventSubscribeInfo(matchingSkills);
100     hasInit_ = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(
101         std::make_shared<DisplyChangedReceiver>(commonEventSubscribeInfo));
102 }
103 
IsCommonEventSubscriberInit()104 bool DisplayEventMonitor::IsCommonEventSubscriberInit()
105 {
106     return hasInit_;
107 }
108 #endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
109 } // namespace AppExecFwk
110 } // namespace OHOS