• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 SERVICES_INCLUDE_SCLOCK_EVENT_HANDLER_H
17 #define SERVICES_INCLUDE_SCLOCK_EVENT_HANDLER_H
18 
19 #include <string>
20 
21 #include "screenlock_system_ability.h"
22 
23 namespace OHOS {
24 namespace ScreenLock {
25 using namespace std;
26 class SystemEvent {
27 public:
SystemEvent()28     SystemEvent(){};
~SystemEvent()29     ~SystemEvent(){};
30 
31     int eventCode_ = 0;
32     std::string eventName_;
33     int eventParams1_ = 0;
34     int eventParams2_ = 0;
35     int eventParams3_ = 0;
36 };
37 class SystemEventHandler {
38 public:
SystemEventHandler()39     SystemEventHandler(){};
~SystemEventHandler()40     ~SystemEventHandler(){};
SendSystemEvent(const SystemEvent event)41     bool SendSystemEvent(const SystemEvent event)
42     {
43         switch (event.eventCode_) {
44             case ON_BEGIN_WAKE_UP:
45                 ScreenLockSystemAbility::GetInstance()->OnBeginWakeUp();
46                 return true;
47             case ON_END_WAKE_UP:
48                 ScreenLockSystemAbility::GetInstance()->OnEndWakeUp();
49                 return true;
50             case ON_BEGIN_SCREEN_ON:
51                 ScreenLockSystemAbility::GetInstance()->OnBeginScreenOn();
52                 return true;
53             case ON_END_SCREEN_ON:
54                 ScreenLockSystemAbility::GetInstance()->OnEndScreenOn();
55                 return true;
56             case ON_BEGIN_SLEEP:
57                 ScreenLockSystemAbility::GetInstance()->OnBeginSleep(event.eventParams1_);
58                 return true;
59             case ON_END_SLEEP:
60                 ScreenLockSystemAbility::GetInstance()->OnEndSleep(event.eventParams1_, event.eventParams2_);
61                 return true;
62             case ON_BEGIN_SCREEN_OFF:
63                 ScreenLockSystemAbility::GetInstance()->OnBeginScreenOff();
64                 return true;
65             case ON_END_SCREEN_OFF:
66                 ScreenLockSystemAbility::GetInstance()->OnEndScreenOff();
67                 return true;
68             case ON_CHANGE_USER:
69                 ScreenLockSystemAbility::GetInstance()->OnChangeUser(event.eventParams1_);
70                 return true;
71             case ON_SCREENLOCK_ENABLED:
72                 ScreenLockSystemAbility::GetInstance()->OnScreenlockEnabled(event.eventParams1_);
73                 return true;
74             case ON_EXIT_ANIMATION:
75                 ScreenLockSystemAbility::GetInstance()->OnExitAnimation();
76                 return true;
77             case REQUEST_UNLOCK:
78                 ScreenLockSystemAbility::GetInstance()->RequestUnlock();
79                 return true;
80             case REQUEST_LOCK:
81                 ScreenLockSystemAbility::GetInstance()->RequestLock();
82                 return true;
83             default:
84                 SCLOCK_HILOGE("SystemEventHandler::SendSystemEvent is no matching code .");
85                 return false;
86         }
87     }
88 
89 private:
90     enum {
91         ON_BEGIN_WAKE_UP = 0,
92         ON_END_WAKE_UP = 1,
93         ON_BEGIN_SCREEN_ON = 2,
94         ON_END_SCREEN_ON = 3,
95         ON_BEGIN_SLEEP = 4,
96         ON_END_SLEEP = 5,
97         ON_BEGIN_SCREEN_OFF = 6,
98         ON_END_SCREEN_OFF = 7,
99         ON_CHANGE_USER = 8,
100         ON_SCREENLOCK_ENABLED = 9,
101         ON_EXIT_ANIMATION = 10,
102         REQUEST_UNLOCK = 11,
103         REQUEST_LOCK = 12,
104     };
105 };
106 } // namespace ScreenLock
107 } // namespace OHOS
108 #endif