Jan Altensen | 1a84336 | 2019-01-20 01:40:51 +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 | |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 17 | #include <android-base/file.h> |
| 18 | #include <android-base/strings.h> |
| 19 | |
| 20 | #include <fstream> |
| 21 | |
Jan Altensen | 1a84336 | 2019-01-20 01:40:51 +0100 | [diff] [blame] | 22 | #include "AdaptiveBacklight.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 | |
Jan Altensen | 1a84336 | 2019-01-20 01:40:51 +0100 | [diff] [blame] | 28 | namespace vendor { |
| 29 | namespace lineage { |
| 30 | namespace livedisplay { |
| 31 | namespace V2_0 { |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 32 | namespace samsung { |
| 33 | |
Jan Altensen | 0003f59 | 2019-07-20 01:01:03 +0200 | [diff] [blame] | 34 | static constexpr const char* kBacklightPath = "/sys/class/lcd/panel/power_reduce"; |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 35 | |
| 36 | bool AdaptiveBacklight::isSupported() { |
| 37 | std::fstream backlight(kBacklightPath, backlight.in | backlight.out); |
| 38 | return backlight.good(); |
| 39 | } |
Jan Altensen | 1a84336 | 2019-01-20 01:40:51 +0100 | [diff] [blame] | 40 | |
| 41 | // Methods from ::vendor::lineage::livedisplay::V2_0::IAdaptiveBacklight follow. |
| 42 | Return<bool> AdaptiveBacklight::isEnabled() { |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 43 | std::string tmp; |
| 44 | int32_t contents = 0; |
| 45 | |
| 46 | if (ReadFileToString(kBacklightPath, &tmp)) { |
| 47 | contents = std::stoi(Trim(tmp)); |
| 48 | } |
| 49 | |
| 50 | return contents > 0; |
Jan Altensen | 1a84336 | 2019-01-20 01:40:51 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | Return<bool> AdaptiveBacklight::setEnabled(bool enabled) { |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 54 | return WriteStringToFile(enabled ? "1" : "0", kBacklightPath, true); |
Jan Altensen | 1a84336 | 2019-01-20 01:40:51 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 57 | } // namespace samsung |
Jan Altensen | 1a84336 | 2019-01-20 01:40:51 +0100 | [diff] [blame] | 58 | } // namespace V2_0 |
| 59 | } // namespace livedisplay |
| 60 | } // namespace lineage |
| 61 | } // namespace vendor |