blob: a0a330cba10124d8bc53fc53a9e326766f5a7f9a [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
24
25using android::base::ReadFileToString;
26using android::base::Trim;
27using android::base::WriteStringToFile;
28
29namespace vendor {
30namespace lineage {
31namespace livedisplay {
32namespace V2_0 {
33namespace samsung {
34
35static constexpr const char *kLUXPath = "/sys/class/mdnie/mdnie/lux";
36
37// Methods from ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement follow.
38bool SunlightEnhancementExynos::isSupported() {
39 std::fstream file(kLUXPath, file.in | file.out);
40 return file.good();
41}
42
43// Methods from ::vendor::lineage::livedisplay::V2_0::IAdaptiveBacklight follow.
44Return<bool> SunlightEnhancementExynos::isEnabled() {
45 std::string tmp;
46 int32_t contents = 0;
47
48 if (ReadFileToString(kLUXPath, &tmp)) {
49 contents = std::stoi(Trim(tmp));
50 }
51
52 return contents > 0;
53}
54
55Return<bool> SunlightEnhancementExynos::setEnabled(bool enabled) {
56 /* see drivers/video/fbdev/exynos/decon_7880/panels/mdnie_lite_table*, get_hbm_index */
57 return WriteStringToFile(enabled ? "40000" : "0", kLUXPath, true);
58}
59
60} // namespace samsung
61} // namespace V2_0
62} // namespace livedisplay
63} // namespace lineage
64} // namespace vendor