blob: cdb021d98c91c5e740622238110ca138cf55d186 [file] [log] [blame]
Paul Keith8475e6c2019-02-06 21:04:23 -06001/*
dianlujitao8888a4b2020-06-24 23:17:30 +08002 * Copyright (C) 2019-2020 The LineageOS Project
Paul Keith8475e6c2019-02-06 21:04:23 -06003 *
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
dianlujitaob8ca32c2020-06-25 13:24:44 +080017#include "livedisplay/sysfs/SunlightEnhancement.h"
LuK1337588974a2020-01-07 14:15:27 +010018
Paul Keith8d138032019-02-07 09:57:05 -060019#include <android-base/file.h>
20#include <android-base/strings.h>
21
dianlujitaob1a97e02020-06-24 23:35:18 +080022namespace {
23constexpr const char* kFileHbm = "/sys/class/graphics/fb0/hbm";
24constexpr const char* kFileSre = "/sys/class/graphics/fb0/sre";
25}; // anonymous namespace
26
dianlujitao8a01e722020-06-25 12:05:03 +080027using ::android::base::ReadFileToString;
28using ::android::base::Trim;
29using ::android::base::WriteStringToFile;
Paul Keith8d138032019-02-07 09:57:05 -060030
Paul Keith733de0b2019-02-06 20:58:34 -060031namespace vendor {
32namespace lineage {
33namespace livedisplay {
34namespace V2_0 {
Paul Keith8475e6c2019-02-06 21:04:23 -060035namespace sysfs {
Paul Keith733de0b2019-02-06 20:58:34 -060036
dianlujitao22462db2020-06-25 14:18:20 +080037SunlightEnhancement::SunlightEnhancement() {
dianlujitaod0580f32020-06-25 10:14:28 +080038 if (!access(kFileHbm, R_OK | W_OK)) {
dianlujitaob1a97e02020-06-24 23:35:18 +080039 file_ = kFileHbm;
dianlujitao8888a4b2020-06-24 23:17:30 +080040 enabled_mode_ = 1;
dianlujitaod0580f32020-06-25 10:14:28 +080041 } else if (!access(kFileSre, R_OK | W_OK)) {
dianlujitaob1a97e02020-06-24 23:35:18 +080042 file_ = kFileSre;
dianlujitao8888a4b2020-06-24 23:17:30 +080043 enabled_mode_ = 2;
dianlujitaod0580f32020-06-25 10:14:28 +080044 } else {
dianlujitao22462db2020-06-25 14:18:20 +080045 file_ = nullptr;
Paul Keith8d138032019-02-07 09:57:05 -060046 }
dianlujitao22462db2020-06-25 14:18:20 +080047}
Paul Keith8d138032019-02-07 09:57:05 -060048
dianlujitao22462db2020-06-25 14:18:20 +080049bool SunlightEnhancement::isSupported() {
50 return file_ != nullptr;
Paul Keith8d138032019-02-07 09:57:05 -060051}
52
Paul Keith733de0b2019-02-06 20:58:34 -060053// Methods from ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement follow.
54Return<bool> SunlightEnhancement::isEnabled() {
Paul Keith8d138032019-02-07 09:57:05 -060055 std::string tmp;
56 int32_t contents = 0;
57
dianlujitao8888a4b2020-06-24 23:17:30 +080058 if (ReadFileToString(file_, &tmp)) {
Paul Keith8d138032019-02-07 09:57:05 -060059 contents = std::stoi(Trim(tmp));
60 }
61
62 return contents > 0;
Paul Keith733de0b2019-02-06 20:58:34 -060063}
64
65Return<bool> SunlightEnhancement::setEnabled(bool enabled) {
dianlujitao8888a4b2020-06-24 23:17:30 +080066 return WriteStringToFile(enabled ? std::to_string(enabled_mode_) : "0", file_, true);
Paul Keith733de0b2019-02-06 20:58:34 -060067}
68
Paul Keith8475e6c2019-02-06 21:04:23 -060069} // namespace sysfs
Paul Keith733de0b2019-02-06 20:58:34 -060070} // namespace V2_0
71} // namespace livedisplay
72} // namespace lineage
73} // namespace vendor