blob: 077672ec92777cd53b30db7c0f04d7d3e539f39a [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 "SunlightEnhancement.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* kHBMPath = "/sys/class/lcd/panel/panel/auto_brightness";
35static constexpr const char* kSREPath = "/sys/class/mdnie/mdnie/outdoor";
Jan Altensen1a843362019-01-20 01:40:51 +010036
37// Methods from ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement follow.
Jan Altensen4e47a0b2019-01-20 02:40:07 +010038bool SunlightEnhancement::isSupported() {
39 std::fstream sre(kSREPath, sre.in | sre.out);
40 std::fstream hbm(kHBMPath, hbm.in | hbm.out);
41
42 if (hbm.good()) {
43 mHasHBM = true;
44 }
45
46 return sre.good();
47}
48
49// Methods from ::vendor::lineage::livedisplay::V2_0::IAdaptiveBacklight follow.
Jan Altensen1a843362019-01-20 01:40:51 +010050Return<bool> SunlightEnhancement::isEnabled() {
Jan Altensen4e47a0b2019-01-20 02:40:07 +010051 std::string tmp;
52 int32_t statusSRE = 0;
53 int32_t statusHBM = 0;
54 if (ReadFileToString(kSREPath, &tmp)) {
55 statusSRE = std::stoi(Trim(tmp));
56 }
57
58 if (mHasHBM && ReadFileToString(kHBMPath, &tmp)) {
59 statusHBM = std::stoi(Trim(tmp));
60 }
Jan Altensen0003f592019-07-20 01:01:03 +020061
Jan Altensen4e47a0b2019-01-20 02:40:07 +010062 return ((statusSRE == 1 && statusHBM == 6) || statusSRE == 1);
Jan Altensen1a843362019-01-20 01:40:51 +010063}
64
65Return<bool> SunlightEnhancement::setEnabled(bool enabled) {
Jan Altensen4e47a0b2019-01-20 02:40:07 +010066 if (mHasHBM) {
67 WriteStringToFile(enabled ? "6" : "0", kHBMPath, true);
68 }
69
70 return WriteStringToFile(enabled ? "1" : "0", kSREPath, true);
Jan Altensen1a843362019-01-20 01:40:51 +010071}
72
Jan Altensen4e47a0b2019-01-20 02:40:07 +010073} // namespace samsung
Jan Altensen1a843362019-01-20 01:40:51 +010074} // namespace V2_0
75} // namespace livedisplay
76} // namespace lineage
77} // namespace vendor