15ccb8f90Sopenharmony_ci/*
25ccb8f90Sopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
35ccb8f90Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
45ccb8f90Sopenharmony_ci * you may not use this file except in compliance with the License.
55ccb8f90Sopenharmony_ci * You may obtain a copy of the License at
65ccb8f90Sopenharmony_ci *
75ccb8f90Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
85ccb8f90Sopenharmony_ci *
95ccb8f90Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
105ccb8f90Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
115ccb8f90Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
125ccb8f90Sopenharmony_ci * See the License for the specific language governing permissions and
135ccb8f90Sopenharmony_ci * limitations under the License.
145ccb8f90Sopenharmony_ci */
155ccb8f90Sopenharmony_ci
165ccb8f90Sopenharmony_ci#ifndef POWER_MODE_THREAD_H
175ccb8f90Sopenharmony_ci#define POWER_MODE_THREAD_H
185ccb8f90Sopenharmony_ci
195ccb8f90Sopenharmony_ci#include <common_event_data.h>
205ccb8f90Sopenharmony_ci#include <common_event_manager.h>
215ccb8f90Sopenharmony_ci#include <common_event_publish_info.h>
225ccb8f90Sopenharmony_ci#include <common_event_support.h>
235ccb8f90Sopenharmony_ci
245ccb8f90Sopenharmony_ci#include "ipower_mode_callback.h"
255ccb8f90Sopenharmony_ci
265ccb8f90Sopenharmony_ci#define FLAG_FALSE (-1)
275ccb8f90Sopenharmony_ci#define LAST_MODE_FLAG 0
285ccb8f90Sopenharmony_ci#define SETTINGS_PRIVIDER_VALUE_LCD_BRIGHTNESS 99
295ccb8f90Sopenharmony_ci#define SETTINGS_PRIVIDER_VALUE_VIBRATION 1
305ccb8f90Sopenharmony_ci#define SETTINGS_PRIVIDER_VALUE_ROTATION 1
315ccb8f90Sopenharmony_ci
325ccb8f90Sopenharmony_cinamespace OHOS {
335ccb8f90Sopenharmony_cinamespace PowerMgr {
345ccb8f90Sopenharmony_ciclass PowerModeModule {
355ccb8f90Sopenharmony_cipublic:
365ccb8f90Sopenharmony_ci    PowerModeModule();
375ccb8f90Sopenharmony_ci    ~PowerModeModule() = default;
385ccb8f90Sopenharmony_ci    void InitPowerMode();
395ccb8f90Sopenharmony_ci    void SetModeItem(PowerMode mode);
405ccb8f90Sopenharmony_ci    PowerMode GetModeItem();
415ccb8f90Sopenharmony_ci    void EnableMode(PowerMode mode, bool isBoot = false);
425ccb8f90Sopenharmony_ci    void AddPowerModeCallback(const sptr<IPowerModeCallback>& callback);
435ccb8f90Sopenharmony_ci    void DelPowerModeCallback(const sptr<IPowerModeCallback>& callback);
445ccb8f90Sopenharmony_ci
455ccb8f90Sopenharmony_ciprivate:
465ccb8f90Sopenharmony_ci    using IntentWant = OHOS::AAFwk::Want;
475ccb8f90Sopenharmony_ci
485ccb8f90Sopenharmony_ci    class CallbackManager : public IRemoteObject::DeathRecipient {
495ccb8f90Sopenharmony_ci    public:
505ccb8f90Sopenharmony_ci        void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
515ccb8f90Sopenharmony_ci        void AddCallback(const sptr<IPowerModeCallback>& callback);
525ccb8f90Sopenharmony_ci        void RemoveCallback(const sptr<IPowerModeCallback>& callback);
535ccb8f90Sopenharmony_ci        void WaitingCallback();
545ccb8f90Sopenharmony_ci
555ccb8f90Sopenharmony_ci    private:
565ccb8f90Sopenharmony_ci        std::mutex mutex_;
575ccb8f90Sopenharmony_ci        std::set<sptr<IRemoteObject>> callbacks_;
585ccb8f90Sopenharmony_ci    };
595ccb8f90Sopenharmony_ci
605ccb8f90Sopenharmony_ci    PowerMode mode_;
615ccb8f90Sopenharmony_ci    uint32_t lastMode_;
625ccb8f90Sopenharmony_ci    bool observerRegisted_ = false;
635ccb8f90Sopenharmony_ci
645ccb8f90Sopenharmony_ci    void Prepare();
655ccb8f90Sopenharmony_ci    void PublishPowerModeEvent();
665ccb8f90Sopenharmony_ci    void UnregisterSaveModeObserver();
675ccb8f90Sopenharmony_ci    void RegisterSaveModeObserver();
685ccb8f90Sopenharmony_ci    void RegisterAutoAdjustBrightnessObserver();
695ccb8f90Sopenharmony_ci    void RegisterAutoWindowRotationObserver();
705ccb8f90Sopenharmony_ci    void RegisterVibrateStateObserver();
715ccb8f90Sopenharmony_ci    void RegisterIntellVoiceObserver();
725ccb8f90Sopenharmony_ci
735ccb8f90Sopenharmony_ci    sptr<CallbackManager> callbackMgr_;
745ccb8f90Sopenharmony_ci    void UpdateModepolicy();
755ccb8f90Sopenharmony_ci    void RunAction(bool isBoot);
765ccb8f90Sopenharmony_ci    static void SetDisplayOffTime(bool isBoot);
775ccb8f90Sopenharmony_ci    static void SetSleepTime([[maybe_unused]] bool isBoot);
785ccb8f90Sopenharmony_ci    static void SetAutoAdjustBrightness(bool isBoot);
795ccb8f90Sopenharmony_ci    static void SetLcdBrightness(bool isBoot);
805ccb8f90Sopenharmony_ci    static void SetVibration(bool isBoot);
815ccb8f90Sopenharmony_ci    static void SetWindowRotation(bool isBoot);
825ccb8f90Sopenharmony_ci    static void SetIntellVoiceState(bool isBoot);
835ccb8f90Sopenharmony_ci
845ccb8f90Sopenharmony_ci    std::atomic<bool> started_;
855ccb8f90Sopenharmony_ci    std::mutex mutex_;
865ccb8f90Sopenharmony_ci};
875ccb8f90Sopenharmony_ci} // namespace PowerMgr
885ccb8f90Sopenharmony_ci} // namespace OHOS
895ccb8f90Sopenharmony_ci#endif // POWER_MODE_THREAD_H
90