• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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 #include "delegate_interface.h"
18 #include "input_windows_manager.h"
19 #include "i_pointer_drawing_manager.h"
20 #include "setting_datashare.h"
21 #include "system_ability_definition.h"
22 
23 #ifdef OHOS_BUILD_ENABLE_COMBINATION_KEY
24 #include "stylus_key_handler.h"
25 #endif // OHOS_BUILD_ENABLE_COMBINATION_KEY
26 
27 #undef MMI_LOG_DOMAIN
28 #define MMI_LOG_DOMAIN MMI_LOG_SERVER
29 #undef MMI_LOG_TAG
30 #define MMI_LOG_TAG "DisplayEventMonitor"
31 
32 namespace OHOS {
33 namespace MMI {
DisplayEventMonitor()34 DisplayEventMonitor::DisplayEventMonitor() {}
~DisplayEventMonitor()35 DisplayEventMonitor::~DisplayEventMonitor() {}
36 
37 #ifdef OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
38 class DisplyChangedReceiver : public EventFwk::CommonEventSubscriber {
39 public:
DisplyChangedReceiver(const OHOS::EventFwk::CommonEventSubscribeInfo & subscribeInfo)40     explicit DisplyChangedReceiver(const OHOS::EventFwk::CommonEventSubscribeInfo& subscribeInfo)
41         : OHOS::EventFwk::CommonEventSubscriber(subscribeInfo)
42     {
43         MMI_HILOGD("DisplyChangedReceiver register");
44     }
45 
46     virtual ~DisplyChangedReceiver() = default;
OnReceiveEvent(const EventFwk::CommonEventData & eventData)47     void OnReceiveEvent(const EventFwk::CommonEventData &eventData)
48     {
49         CALL_DEBUG_ENTER;
50         std::string action = eventData.GetWant().GetAction();
51         if (action.empty()) {
52             MMI_HILOGE("Action is empty");
53             return;
54         }
55         MMI_HILOGD("Received screen status:%{public}s", action.c_str());
56         if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON) {
57             MMI_HILOGD("Display screen on");
58             DISPLAY_MONITOR->SetScreenStatus(action);
59 #ifdef OHOS_BUILD_ENABLE_COMBINATION_KEY
60             STYLUS_HANDLER->IsLaunchAbility();
61 #endif // OHOS_BUILD_ENABLE_COMBINATION_KEY
62             CHKPV(FINGERSENSE_WRAPPER);
63             if (FINGERSENSE_WRAPPER->enableFingersense_ != nullptr) {
64                 MMI_HILOGI("Start enable fingersense");
65                 FINGERSENSE_WRAPPER->enableFingersense_();
66             }
67             DISPLAY_MONITOR->UpdateShieldStatusOnScreenOn();
68         } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF) {
69             MMI_HILOGD("Display screen off");
70             DISPLAY_MONITOR->SetScreenStatus(action);
71             CHKPV(FINGERSENSE_WRAPPER);
72             if (FINGERSENSE_WRAPPER->disableFingerSense_ != nullptr) {
73                 MMI_HILOGI("Disable fingersense");
74                 FINGERSENSE_WRAPPER->disableFingerSense_();
75             }
76             DISPLAY_MONITOR->UpdateShieldStatusOnScreenOff();
77         } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED) {
78             MMI_HILOGD("Display screen locked");
79             DISPLAY_MONITOR->SetScreenLocked(true);
80             DISPLAY_MONITOR->SendCancelEventWhenLock();
81         } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED) {
82             MMI_HILOGD("Display screen unlocked");
83             DISPLAY_MONITOR->SetScreenLocked(false);
84         } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_DATA_SHARE_READY) {
85             if (SettingDataShare::GetInstance(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID).CheckIfSettingsDataReady()) {
86                 IPointerDrawingManager::GetInstance()->InitPointerObserver();
87             }
88         } else {
89             MMI_HILOGW("Screen changed receiver event: unknown");
90         }
91     }
92 };
93 
UpdateShieldStatusOnScreenOn()94 void DisplayEventMonitor::UpdateShieldStatusOnScreenOn()
95 {
96     CALL_DEBUG_ENTER;
97 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
98     if (shieldModeBeforeSreenOff_ != SHIELD_MODE::UNSET_MODE) {
99         KeyEventHdr->SetCurrentShieldMode(shieldModeBeforeSreenOff_);
100     } else {
101         MMI_HILOGD("Shield mode before screen off:%{public}d", shieldModeBeforeSreenOff_);
102     }
103 #else
104     MMI_HILOGW("Keyboard device does not support");
105 #endif // OHOS_BUILD_ENABLE_KEYBOARD
106 }
107 
UpdateShieldStatusOnScreenOff()108 void DisplayEventMonitor::UpdateShieldStatusOnScreenOff()
109 {
110     CALL_DEBUG_ENTER;
111 #ifdef OHOS_BUILD_ENABLE_KEYBOARD
112     shieldModeBeforeSreenOff_ = KeyEventHdr->GetCurrentShieldMode();
113     if (shieldModeBeforeSreenOff_ != SHIELD_MODE::UNSET_MODE) {
114         KeyEventHdr->SetCurrentShieldMode(SHIELD_MODE::UNSET_MODE);
115     } else {
116         MMI_HILOGD("Shield mode before screen off:%{public}d", shieldModeBeforeSreenOff_);
117     }
118 #else
119     MMI_HILOGW("Keyboard device does not support");
120 #endif // OHOS_BUILD_ENABLE_KEYBOARD
121 }
122 
InitCommonEventSubscriber()123 void DisplayEventMonitor::InitCommonEventSubscriber()
124 {
125     CALL_DEBUG_ENTER;
126     if (hasInit_) {
127         MMI_HILOGE("Current common event has subscribered");
128         return;
129     }
130     EventFwk::MatchingSkills matchingSkills;
131     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON);
132     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF);
133     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED);
134     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED);
135     matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DATA_SHARE_READY);
136     EventFwk::CommonEventSubscribeInfo commonEventSubscribeInfo(matchingSkills);
137     hasInit_ = OHOS::EventFwk::CommonEventManager::SubscribeCommonEvent(
138         std::make_shared<DisplyChangedReceiver>(commonEventSubscribeInfo));
139 }
140 
IsCommonEventSubscriberInit()141 bool DisplayEventMonitor::IsCommonEventSubscriberInit()
142 {
143     return hasInit_;
144 }
145 
SendCancelEventWhenLock()146 void DisplayEventMonitor::SendCancelEventWhenLock()
147 {
148     CHKPV(delegateProxy_);
149 #ifdef OHOS_BUILD_ENABLE_TOUCH
150     delegateProxy_->OnPostSyncTask([] {
151         WIN_MGR->SendCancelEventWhenLock();
152         return RET_OK;
153     });
154 #endif // OHOS_BUILD_ENABLE_TOUCH
155 }
156 #endif // OHOS_BUILD_ENABLE_FINGERSENSE_WRAPPER
157 } // namespace AppExecFwk
158 } // namespace OHOS