blob: 950342ada0e8425b0963b2d8a570738852bb3fd5 [file] [log] [blame]
Jan Altensen4e47a0b2019-01-20 02:40:07 +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
17#include <android-base/file.h>
18#include <android-base/strings.h>
19
20#include <fstream>
21
22#include "SunlightEnhancementExynos.h"
23
Jan Altensen4e47a0b2019-01-20 02:40:07 +010024using android::base::ReadFileToString;
25using android::base::Trim;
26using android::base::WriteStringToFile;
27
28namespace vendor {
29namespace lineage {
30namespace livedisplay {
31namespace V2_0 {
32namespace samsung {
33
Jan Altensen0003f592019-07-20 01:01:03 +020034static constexpr const char* kLUXPath = "/sys/class/mdnie/mdnie/lux";
Jan Altensen4e47a0b2019-01-20 02:40:07 +010035
36// Methods from ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement follow.
37bool SunlightEnhancementExynos::isSupported() {
38 std::fstream file(kLUXPath, file.in | file.out);
39 return file.good();
40}
41
42// Methods from ::vendor::lineage::livedisplay::V2_0::IAdaptiveBacklight follow.
43Return<bool> SunlightEnhancementExynos::isEnabled() {
44 std::string tmp;
45 int32_t contents = 0;
46
47 if (ReadFileToString(kLUXPath, &tmp)) {
48 contents = std::stoi(Trim(tmp));
49 }
50
51 return contents > 0;
52}
53
54Return<bool> SunlightEnhancementExynos::setEnabled(bool enabled) {
55 /* see drivers/video/fbdev/exynos/decon_7880/panels/mdnie_lite_table*, get_hbm_index */
56 return WriteStringToFile(enabled ? "40000" : "0", kLUXPath, true);
57}
58
59} // namespace samsung
60} // namespace V2_0
61} // namespace livedisplay
62} // namespace lineage
63} // namespace vendor