blob: 5c3ca51e7fc903fe511abfe09e9cae219ad42018 [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
18#include <android-base/file.h>
19#include <android-base/strings.h>
20
21#include <fstream>
22
Jan Altensen1a843362019-01-20 01:40:51 +010023#include "SunlightEnhancement.h"
24
Jan Altensen4e47a0b2019-01-20 02:40:07 +010025using android::base::ReadFileToString;
26using android::base::Trim;
27using android::base::WriteStringToFile;
28
Jan Altensen1a843362019-01-20 01:40:51 +010029namespace vendor {
30namespace lineage {
31namespace livedisplay {
32namespace V2_0 {
Jan Altensen4e47a0b2019-01-20 02:40:07 +010033namespace samsung {
34
35static constexpr const char *kHBMPath = "/sys/class/lcd/panel/panel/auto_brightness";
36static constexpr const char *kSREPath = "/sys/class/mdnie/mdnie/outdoor";
Jan Altensen1a843362019-01-20 01:40:51 +010037
38// Methods from ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement follow.
Jan Altensen4e47a0b2019-01-20 02:40:07 +010039bool SunlightEnhancement::isSupported() {
40 std::fstream sre(kSREPath, sre.in | sre.out);
41 std::fstream hbm(kHBMPath, hbm.in | hbm.out);
42
43 if (hbm.good()) {
44 mHasHBM = true;
45 }
46
47 return sre.good();
48}
49
50// Methods from ::vendor::lineage::livedisplay::V2_0::IAdaptiveBacklight follow.
Jan Altensen1a843362019-01-20 01:40:51 +010051Return<bool> SunlightEnhancement::isEnabled() {
Jan Altensen4e47a0b2019-01-20 02:40:07 +010052 std::string tmp;
53 int32_t statusSRE = 0;
54 int32_t statusHBM = 0;
55 if (ReadFileToString(kSREPath, &tmp)) {
56 statusSRE = std::stoi(Trim(tmp));
57 }
58
59 if (mHasHBM && ReadFileToString(kHBMPath, &tmp)) {
60 statusHBM = std::stoi(Trim(tmp));
61 }
62
63 return ((statusSRE == 1 && statusHBM == 6) || statusSRE == 1);
Jan Altensen1a843362019-01-20 01:40:51 +010064}
65
66Return<bool> SunlightEnhancement::setEnabled(bool enabled) {
Jan Altensen4e47a0b2019-01-20 02:40:07 +010067 if (mHasHBM) {
68 WriteStringToFile(enabled ? "6" : "0", kHBMPath, true);
69 }
70
71 return WriteStringToFile(enabled ? "1" : "0", kSREPath, true);
Jan Altensen1a843362019-01-20 01:40:51 +010072}
73
Jan Altensen4e47a0b2019-01-20 02:40:07 +010074} // namespace samsung
Jan Altensen1a843362019-01-20 01:40:51 +010075} // namespace V2_0
76} // namespace livedisplay
77} // namespace lineage
78} // namespace vendor