• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 POWERMGR_SCREEN_SAVER_HANDLER_H
17 #define POWERMGR_SCREEN_SAVER_HANDLER_H
18 
19 #include <mutex>
20 
21 #include <ability_service_interface.h>
22 #include <input_event_listener_proxy.h>
23 
24 #include "power_mgr_time_util.h"
25 #include "power_mgr_timer_util.h"
26 
27 namespace OHOS {
28 class ScreenSaverHandler : public InputEventListenerProxy::RawEventListener {
29 public:
30     ScreenSaverHandler() = default;
31     ~ScreenSaverHandler() override;
32 
33     void Init();
34     void SetInterval(int64_t intervalMsec);
35     int32_t SetState(bool enable);
36     void OnRawEvent(const RawEvent &event) override;
37 
38 private:
39     friend void PowerTimerCallback(void *data);
40 
41     static AmsInterface *GetAmsInterface();
42 
43     bool SetEnableLocked();
44     bool SetDisableLocked();
45     void StartScreenSaver();
46     bool StartScreenSaverLocked();
47 
48     static constexpr int64_t DEFAULT_INTERVAL_MSECS = 5 * MSEC_PER_MIN;
49 
50     std::mutex mutex_;
51     bool enabled_{false};
52     bool screenSaverStarted_{false};
53     int64_t intervalMsec_{DEFAULT_INTERVAL_MSECS};
54     PowerTimer *timer_{nullptr};
55 };
56 } // namespace OHOS
57 #endif // POWERMGR_SCREEN_SAVER_HANDLER_H
58