Paul Keith | 8475e6c | 2019-02-06 21:04:23 -0600 | [diff] [blame] | 1 | /* |
dianlujitao | 8888a4b | 2020-06-24 23:17:30 +0800 | [diff] [blame] | 2 | * Copyright (C) 2019-2020 The LineageOS Project |
Paul Keith | 8475e6c | 2019-02-06 21:04:23 -0600 | [diff] [blame] | 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 | |
dianlujitao | b8ca32c | 2020-06-25 13:24:44 +0800 | [diff] [blame] | 17 | #include "livedisplay/sysfs/SunlightEnhancement.h" |
LuK1337 | 588974a | 2020-01-07 14:15:27 +0100 | [diff] [blame] | 18 | |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 19 | #include <android-base/file.h> |
| 20 | #include <android-base/strings.h> |
| 21 | |
dianlujitao | b1a97e0 | 2020-06-24 23:35:18 +0800 | [diff] [blame] | 22 | namespace { |
| 23 | constexpr const char* kFileHbm = "/sys/class/graphics/fb0/hbm"; |
| 24 | constexpr const char* kFileSre = "/sys/class/graphics/fb0/sre"; |
| 25 | }; // anonymous namespace |
| 26 | |
dianlujitao | 8a01e72 | 2020-06-25 12:05:03 +0800 | [diff] [blame] | 27 | using ::android::base::ReadFileToString; |
| 28 | using ::android::base::Trim; |
| 29 | using ::android::base::WriteStringToFile; |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 30 | |
Paul Keith | 733de0b | 2019-02-06 20:58:34 -0600 | [diff] [blame] | 31 | namespace vendor { |
| 32 | namespace lineage { |
| 33 | namespace livedisplay { |
| 34 | namespace V2_0 { |
Paul Keith | 8475e6c | 2019-02-06 21:04:23 -0600 | [diff] [blame] | 35 | namespace sysfs { |
Paul Keith | 733de0b | 2019-02-06 20:58:34 -0600 | [diff] [blame] | 36 | |
dianlujitao | 22462db | 2020-06-25 14:18:20 +0800 | [diff] [blame] | 37 | SunlightEnhancement::SunlightEnhancement() { |
dianlujitao | d0580f3 | 2020-06-25 10:14:28 +0800 | [diff] [blame] | 38 | if (!access(kFileHbm, R_OK | W_OK)) { |
dianlujitao | b1a97e0 | 2020-06-24 23:35:18 +0800 | [diff] [blame] | 39 | file_ = kFileHbm; |
dianlujitao | 8888a4b | 2020-06-24 23:17:30 +0800 | [diff] [blame] | 40 | enabled_mode_ = 1; |
dianlujitao | d0580f3 | 2020-06-25 10:14:28 +0800 | [diff] [blame] | 41 | } else if (!access(kFileSre, R_OK | W_OK)) { |
dianlujitao | b1a97e0 | 2020-06-24 23:35:18 +0800 | [diff] [blame] | 42 | file_ = kFileSre; |
dianlujitao | 8888a4b | 2020-06-24 23:17:30 +0800 | [diff] [blame] | 43 | enabled_mode_ = 2; |
dianlujitao | d0580f3 | 2020-06-25 10:14:28 +0800 | [diff] [blame] | 44 | } else { |
dianlujitao | 22462db | 2020-06-25 14:18:20 +0800 | [diff] [blame] | 45 | file_ = nullptr; |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 46 | } |
dianlujitao | 22462db | 2020-06-25 14:18:20 +0800 | [diff] [blame] | 47 | } |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 48 | |
dianlujitao | 22462db | 2020-06-25 14:18:20 +0800 | [diff] [blame] | 49 | bool SunlightEnhancement::isSupported() { |
| 50 | return file_ != nullptr; |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 51 | } |
| 52 | |
Paul Keith | 733de0b | 2019-02-06 20:58:34 -0600 | [diff] [blame] | 53 | // Methods from ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement follow. |
| 54 | Return<bool> SunlightEnhancement::isEnabled() { |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 55 | std::string tmp; |
| 56 | int32_t contents = 0; |
| 57 | |
dianlujitao | 8888a4b | 2020-06-24 23:17:30 +0800 | [diff] [blame] | 58 | if (ReadFileToString(file_, &tmp)) { |
Paul Keith | 8d13803 | 2019-02-07 09:57:05 -0600 | [diff] [blame] | 59 | contents = std::stoi(Trim(tmp)); |
| 60 | } |
| 61 | |
| 62 | return contents > 0; |
Paul Keith | 733de0b | 2019-02-06 20:58:34 -0600 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | Return<bool> SunlightEnhancement::setEnabled(bool enabled) { |
dianlujitao | 8888a4b | 2020-06-24 23:17:30 +0800 | [diff] [blame] | 66 | return WriteStringToFile(enabled ? std::to_string(enabled_mode_) : "0", file_, true); |
Paul Keith | 733de0b | 2019-02-06 20:58:34 -0600 | [diff] [blame] | 67 | } |
| 68 | |
Paul Keith | 8475e6c | 2019-02-06 21:04:23 -0600 | [diff] [blame] | 69 | } // namespace sysfs |
Paul Keith | 733de0b | 2019-02-06 20:58:34 -0600 | [diff] [blame] | 70 | } // namespace V2_0 |
| 71 | } // namespace livedisplay |
| 72 | } // namespace lineage |
| 73 | } // namespace vendor |