Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +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 | |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 17 | #include <fstream> |
| 18 | |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 19 | #include "KeyDisabler.h" |
| 20 | |
| 21 | namespace vendor { |
| 22 | namespace lineage { |
| 23 | namespace touch { |
| 24 | namespace V1_0 { |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 25 | namespace samsung { |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 26 | |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 27 | bool KeyDisabler::isSupported() { |
| 28 | std::ofstream file("/sys/class/sec/sec_touchkey/input/enabled"); |
| 29 | return file.good(); |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 30 | } |
| 31 | |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 32 | // Methods from ::vendor::lineage::touch::V1_0::IKeyDisabler follow. |
| 33 | Return<bool> KeyDisabler::isEnabled() { |
| 34 | std::ifstream file("/sys/class/sec/sec_touchkey/input/enabled"); |
| 35 | int status = -1; |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 36 | |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 37 | if (file.is_open()) { |
| 38 | file >> status; |
| 39 | } |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 40 | |
Paul Keith | 2b27b27 | 2019-01-09 00:11:40 +0100 | [diff] [blame] | 41 | return file.good() && status == 0; |
| 42 | } |
| 43 | |
| 44 | Return<bool> KeyDisabler::setEnabled(bool enabled) { |
| 45 | std::ofstream file("/sys/class/sec/sec_touchkey/input/enabled"); |
| 46 | file << (enabled ? "0" : "1"); |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | } // namespace samsung |
Paul Keith | 5b3bd86 | 2019-01-08 23:45:03 +0100 | [diff] [blame] | 51 | } // namespace V1_0 |
| 52 | } // namespace touch |
| 53 | } // namespace lineage |
| 54 | } // namespace vendor |