1/*
2 * Copyright (c) 2022-2023 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#include "battery_backlight.h"
17
18#include "charger_log.h"
19#include "hdf_base.h"
20
21namespace OHOS {
22namespace PowerMgr {
23namespace {
24constexpr uint32_t BACKLIGHT_ON = 128;
25}
26
27BatteryBacklight::BatteryBacklight()
28{
29    if (composer_ == nullptr) {
30        composer_.reset(V1_2::IDisplayComposerInterface::Get());
31        if (composer_ == nullptr) {
32            return;
33        }
34    }
35}
36
37BatteryBacklight::~BatteryBacklight()
38{
39}
40
41void BatteryBacklight::TurnOnScreen()
42{
43    if (screenState_ != SCREEN_ON) {
44        BATTERY_HILOGD(FEATURE_CHARGING, "turn on screen");
45        uint32_t devId = 0;
46        composer_->SetDisplayPowerStatus(devId, V1_0::POWER_STATUS_ON);
47        composer_->SetDisplayBacklight(devId, BACKLIGHT_ON);
48        screenState_ = SCREEN_ON;
49    }
50}
51
52void BatteryBacklight::TurnOffScreen()
53{
54    if (screenState_ != SCREEN_OFF) {
55        BATTERY_HILOGD(FEATURE_CHARGING, "turn off screen");
56        uint32_t devId = 0;
57        composer_->SetDisplayPowerStatus(devId, V1_0::POWER_STATUS_OFF);
58        screenState_ = SCREEN_OFF;
59    }
60}
61
62int32_t BatteryBacklight::GetScreenState()
63{
64    return screenState_;
65}
66} // namespace PowerMgr
67} // namespace OHOS
68