blob: 986ab1254cd0239b892e2dbfdf9b4ec066ec1b1f [file] [log] [blame]
Jan Altensen1a843362019-01-20 01:40:51 +01001/*
2 * Copyright (C) 2019 The LineageOS Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jan Altensen4e47a0b2019-01-20 02:40:07 +010017#include <android-base/file.h>
18#include <android-base/strings.h>
19
20#include <fstream>
21
Jan Altensen1a843362019-01-20 01:40:51 +010022#include "AdaptiveBacklight.h"
23
Jan Altensen4e47a0b2019-01-20 02:40:07 +010024using android::base::ReadFileToString;
25using android::base::Trim;
26using android::base::WriteStringToFile;
27
Jan Altensen1a843362019-01-20 01:40:51 +010028namespace vendor {
29namespace lineage {
30namespace livedisplay {
31namespace V2_0 {
Jan Altensen4e47a0b2019-01-20 02:40:07 +010032namespace samsung {
33
Jan Altensen0003f592019-07-20 01:01:03 +020034static constexpr const char* kBacklightPath = "/sys/class/lcd/panel/power_reduce";
Jan Altensen4e47a0b2019-01-20 02:40:07 +010035
36bool AdaptiveBacklight::isSupported() {
37 std::fstream backlight(kBacklightPath, backlight.in | backlight.out);
38 return backlight.good();
39}
Jan Altensen1a843362019-01-20 01:40:51 +010040
41// Methods from ::vendor::lineage::livedisplay::V2_0::IAdaptiveBacklight follow.
42Return<bool> AdaptiveBacklight::isEnabled() {
Jan Altensen4e47a0b2019-01-20 02:40:07 +010043 std::string tmp;
44 int32_t contents = 0;
45
46 if (ReadFileToString(kBacklightPath, &tmp)) {
47 contents = std::stoi(Trim(tmp));
48 }
49
50 return contents > 0;
Jan Altensen1a843362019-01-20 01:40:51 +010051}
52
53Return<bool> AdaptiveBacklight::setEnabled(bool enabled) {
Jan Altensen4e47a0b2019-01-20 02:40:07 +010054 return WriteStringToFile(enabled ? "1" : "0", kBacklightPath, true);
Jan Altensen1a843362019-01-20 01:40:51 +010055}
56
Jan Altensen4e47a0b2019-01-20 02:40:07 +010057} // namespace samsung
Jan Altensen1a843362019-01-20 01:40:51 +010058} // namespace V2_0
59} // namespace livedisplay
60} // namespace lineage
61} // namespace vendor