Alessandro Astone | 8011ada | 2021-03-30 11:34:38 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 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 "PowerShare.h" |
| 18 | #include <fstream> |
| 19 | |
| 20 | #define WLC_DEV_DIR "/sys/class/power_supply/wireless/device" |
| 21 | #define RTX_ENABLE_PATH WLC_DEV_DIR "/rtx" |
| 22 | |
| 23 | /* |
| 24 | * Write value to path and close file. |
| 25 | */ |
| 26 | template <typename T> |
| 27 | static void set(const std::string& path, const T& value) { |
| 28 | std::ofstream file(path); |
| 29 | file << value; |
| 30 | } |
| 31 | |
| 32 | template <typename T> |
| 33 | static T get(const std::string& path, const T& def) { |
| 34 | std::ifstream file(path); |
| 35 | T result; |
| 36 | |
| 37 | file >> result; |
| 38 | return file.fail() ? def : result; |
| 39 | } |
| 40 | |
| 41 | namespace vendor::lineage::powershare::pixel { |
| 42 | |
| 43 | Return<bool> PowerShare::isEnabled() { |
| 44 | return get(RTX_ENABLE_PATH, 0) == 1; |
| 45 | } |
| 46 | |
| 47 | Return<bool> PowerShare::setEnabled(bool enable) { |
| 48 | set(RTX_ENABLE_PATH, enable ? 1 : 0); |
| 49 | return isEnabled(); |
| 50 | } |
| 51 | |
| 52 | Return<uint32_t> PowerShare::getMinBattery() { |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | Return<uint32_t> PowerShare::setMinBattery(uint32_t) { |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | } // namespace vendor::lineage::powershare::pixel |