1cb69b360Sopenharmony_ci/* 2cb69b360Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3cb69b360Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4cb69b360Sopenharmony_ci * you may not use this file except in compliance with the License. 5cb69b360Sopenharmony_ci * You may obtain a copy of the License at 6cb69b360Sopenharmony_ci * 7cb69b360Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8cb69b360Sopenharmony_ci * 9cb69b360Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10cb69b360Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11cb69b360Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12cb69b360Sopenharmony_ci * See the License for the specific language governing permissions and 13cb69b360Sopenharmony_ci * limitations under the License. 14cb69b360Sopenharmony_ci */ 15cb69b360Sopenharmony_ci 16cb69b360Sopenharmony_ci#ifndef POWERMGR_SCREEN_SAVER_HANDLER_H 17cb69b360Sopenharmony_ci#define POWERMGR_SCREEN_SAVER_HANDLER_H 18cb69b360Sopenharmony_ci 19cb69b360Sopenharmony_ci#include <mutex> 20cb69b360Sopenharmony_ci 21cb69b360Sopenharmony_ci#include <ability_service_interface.h> 22cb69b360Sopenharmony_ci#include <input_event_listener_proxy.h> 23cb69b360Sopenharmony_ci 24cb69b360Sopenharmony_ci#include "power_mgr_time_util.h" 25cb69b360Sopenharmony_ci#include "power_mgr_timer_util.h" 26cb69b360Sopenharmony_ci 27cb69b360Sopenharmony_cinamespace OHOS { 28cb69b360Sopenharmony_ciclass ScreenSaverHandler : public InputEventListenerProxy::RawEventListener { 29cb69b360Sopenharmony_cipublic: 30cb69b360Sopenharmony_ci ScreenSaverHandler() = default; 31cb69b360Sopenharmony_ci ~ScreenSaverHandler() override; 32cb69b360Sopenharmony_ci 33cb69b360Sopenharmony_ci void Init(); 34cb69b360Sopenharmony_ci void SetInterval(int64_t intervalMsec); 35cb69b360Sopenharmony_ci int32_t SetState(bool enable); 36cb69b360Sopenharmony_ci void OnRawEvent(const RawEvent &event) override; 37cb69b360Sopenharmony_ci 38cb69b360Sopenharmony_ciprivate: 39cb69b360Sopenharmony_ci friend void PowerTimerCallback(void *data); 40cb69b360Sopenharmony_ci 41cb69b360Sopenharmony_ci static AmsInterface *GetAmsInterface(); 42cb69b360Sopenharmony_ci 43cb69b360Sopenharmony_ci bool SetEnableLocked(); 44cb69b360Sopenharmony_ci bool SetDisableLocked(); 45cb69b360Sopenharmony_ci void StartScreenSaver(); 46cb69b360Sopenharmony_ci bool StartScreenSaverLocked(); 47cb69b360Sopenharmony_ci 48cb69b360Sopenharmony_ci static constexpr int64_t DEFAULT_INTERVAL_MSECS = 5 * MSEC_PER_MIN; 49cb69b360Sopenharmony_ci 50cb69b360Sopenharmony_ci std::mutex mutex_; 51cb69b360Sopenharmony_ci bool enabled_{false}; 52cb69b360Sopenharmony_ci bool screenSaverStarted_{false}; 53cb69b360Sopenharmony_ci int64_t intervalMsec_{DEFAULT_INTERVAL_MSECS}; 54cb69b360Sopenharmony_ci PowerTimer *timer_{nullptr}; 55cb69b360Sopenharmony_ci}; 56cb69b360Sopenharmony_ci} // namespace OHOS 57cb69b360Sopenharmony_ci#endif // POWERMGR_SCREEN_SAVER_HANDLER_H 58