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