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 | |
| 18 | #include <android-base/file.h> |
| 19 | #include <android-base/strings.h> |
| 20 | |
| 21 | #include <fstream> |
| 22 | |
Jan Altensen | 1a84336 | 2019-01-20 01:40:51 +0100 | [diff] [blame] | 23 | #include "SunlightEnhancement.h" |
| 24 | |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 25 | using android::base::ReadFileToString; |
| 26 | using android::base::Trim; |
| 27 | using android::base::WriteStringToFile; |
| 28 | |
Jan Altensen | 1a84336 | 2019-01-20 01:40:51 +0100 | [diff] [blame] | 29 | namespace vendor { |
| 30 | namespace lineage { |
| 31 | namespace livedisplay { |
| 32 | namespace V2_0 { |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 33 | namespace samsung { |
| 34 | |
| 35 | static constexpr const char *kHBMPath = "/sys/class/lcd/panel/panel/auto_brightness"; |
| 36 | static constexpr const char *kSREPath = "/sys/class/mdnie/mdnie/outdoor"; |
Jan Altensen | 1a84336 | 2019-01-20 01:40:51 +0100 | [diff] [blame] | 37 | |
| 38 | // Methods from ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement follow. |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 39 | bool 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 Altensen | 1a84336 | 2019-01-20 01:40:51 +0100 | [diff] [blame] | 51 | Return<bool> SunlightEnhancement::isEnabled() { |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 52 | 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 Altensen | 1a84336 | 2019-01-20 01:40:51 +0100 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | Return<bool> SunlightEnhancement::setEnabled(bool enabled) { |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 67 | if (mHasHBM) { |
| 68 | WriteStringToFile(enabled ? "6" : "0", kHBMPath, true); |
| 69 | } |
| 70 | |
| 71 | return WriteStringToFile(enabled ? "1" : "0", kSREPath, true); |
Jan Altensen | 1a84336 | 2019-01-20 01:40:51 +0100 | [diff] [blame] | 72 | } |
| 73 | |
Jan Altensen | 4e47a0b | 2019-01-20 02:40:07 +0100 | [diff] [blame] | 74 | } // namespace samsung |
Jan Altensen | 1a84336 | 2019-01-20 01:40:51 +0100 | [diff] [blame] | 75 | } // namespace V2_0 |
| 76 | } // namespace livedisplay |
| 77 | } // namespace lineage |
| 78 | } // namespace vendor |