1 /*
2  * Copyright (c) 2021-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 
16 #ifndef KEY_EVENT_NORMALIZE_H
17 #define KEY_EVENT_NORMALIZE_H
18 
19 #include "singleton.h"
20 
21 #include "i_input_windows_manager.h"
22 #include "key_event.h"
23 #include "util.h"
24 
25 namespace OHOS {
26 namespace MMI {
27 class KeyEventNormalize final {
28     DECLARE_DELAYED_SINGLETON(KeyEventNormalize);
29 public:
30     DISALLOW_COPY_AND_MOVE(KeyEventNormalize);
31     std::shared_ptr<KeyEvent> GetKeyEvent();
32     int32_t Normalize(libinput_event *event, std::shared_ptr<KeyEvent> keyEvent);
33     void ResetKeyEvent(struct libinput_device* device);
34     int32_t SetShieldStatus(int32_t shieldMode, bool isShield);
35     int32_t GetShieldStatus(int32_t shieldMode, bool &isShield);
36     void SetCurrentShieldMode(int32_t shieldMode);
37     int32_t GetCurrentShieldMode();
38 
39 private:
40     int32_t TransformVolumeKey(struct libinput_device *dev, int32_t keyCode, int32_t keyAction) const;
41     void HandleKeyAction(struct libinput_device* device, KeyEvent::KeyItem &item, std::shared_ptr<KeyEvent> keyEvent);
42 
43 private:
44     std::shared_ptr<KeyEvent> keyEvent_ { nullptr };
45     std::map<int32_t, bool> shieldStatus_ {
46         {SHIELD_MODE::FACTORY_MODE, false},
47         {SHIELD_MODE::OOBE_MODE, false},
48     };
49     int32_t lastShieldMode_ { -1 };
50     std::mutex mtx_;
51 };
52 #define KeyEventHdr ::OHOS::DelayedSingleton<KeyEventNormalize>::GetInstance()
53 } // namespace MMI
54 } // namespace OHOS
55 #endif // KEY_EVENT_NORMALIZE_H