blob: 3880c43ca32f1f44434b2defbde2e2ebfa3af299 [file] [log] [blame]
Jan Altensen1a843362019-01-20 01:40:51 +01001/*
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 Altensen4e47a0b2019-01-20 02:40:07 +010017#include <android-base/file.h>
18#include <android-base/strings.h>
19
20#include <fstream>
21
Jan Altensen1a843362019-01-20 01:40:51 +010022#include "ReadingEnhancement.h"
23
Jan Altensen4e47a0b2019-01-20 02:40:07 +010024using android::base::ReadFileToString;
25using android::base::Trim;
26using android::base::WriteStringToFile;
27
Jan Altensen1a843362019-01-20 01:40:51 +010028namespace vendor {
29namespace lineage {
30namespace livedisplay {
31namespace V2_0 {
Jan Altensen4e47a0b2019-01-20 02:40:07 +010032namespace samsung {
33
Jan Altensen0003f592019-07-20 01:01:03 +020034static constexpr const char* kREPath = "/sys/class/mdnie/mdnie/accessibility";
Jan Altensen4e47a0b2019-01-20 02:40:07 +010035
36// Methods from ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement follow.
37bool ReadingEnhancement::isSupported() {
38 std::fstream re(kREPath, re.in | re.out);
39 return re.good();
40}
Jan Altensen1a843362019-01-20 01:40:51 +010041
42// Methods from ::vendor::lineage::livedisplay::V2_0::IReadingEnhancement follow.
43Return<bool> ReadingEnhancement::isEnabled() {
Jan Altensen4e47a0b2019-01-20 02:40:07 +010044 std::string contents;
45
46 if (ReadFileToString(kREPath, &contents)) {
47 contents = Trim(contents);
48 }
49
LuK1337bf999782019-07-10 10:36:49 +020050 return !contents.compare("Current accessibility : DSI0 : GRAYSCALE") || !contents.compare("4");
Jan Altensen1a843362019-01-20 01:40:51 +010051}
52
53Return<bool> ReadingEnhancement::setEnabled(bool enabled) {
Jan Altensen4e47a0b2019-01-20 02:40:07 +010054 return WriteStringToFile(enabled ? "4" : "0", kREPath, true);
Jan Altensen1a843362019-01-20 01:40:51 +010055}
56
Jan Altensen1a843362019-01-20 01:40:51 +010057// Methods from ::android::hidl::base::V1_0::IBase follow.
58
Jan Altensen4e47a0b2019-01-20 02:40:07 +010059} // namespace samsung
Jan Altensen1a843362019-01-20 01:40:51 +010060} // namespace V2_0
61} // namespace livedisplay
62} // namespace lineage
63} // namespace vendor