From 3334859f4f356c13979a5e272eb9bd4399b850ef Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Sun, 14 Mar 2021 11:29:05 +0100 Subject: [PATCH] livedisplay: Implement IAntiFlicker interface fragment Change-Id: I1dbc6d8989a80fe7b06d4356aeb717417997a793 --- hidl/livedisplay/Android.bp | 5 ++ hidl/livedisplay/AntiFlicker.cpp | 54 +++++++++++++++++++ hidl/livedisplay/AntiFlicker.h | 47 ++++++++++++++++ .../include/livedisplay/oplus/AntiFlicker.h | 47 ++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 hidl/livedisplay/AntiFlicker.cpp create mode 100644 hidl/livedisplay/AntiFlicker.h create mode 100644 hidl/livedisplay/include/livedisplay/oplus/AntiFlicker.h diff --git a/hidl/livedisplay/Android.bp b/hidl/livedisplay/Android.bp index 5995d47..3fe7bd3 100644 --- a/hidl/livedisplay/Android.bp +++ b/hidl/livedisplay/Android.bp @@ -12,6 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +filegroup { + name: "vendor.lineage.livedisplay@2.1-oplus-af", + srcs: ["AntiFlicker.cpp"], +} + filegroup { name: "vendor.lineage.livedisplay@2.1-oplus-se", srcs: ["SunlightEnhancement.cpp"], diff --git a/hidl/livedisplay/AntiFlicker.cpp b/hidl/livedisplay/AntiFlicker.cpp new file mode 100644 index 0000000..7cab417 --- /dev/null +++ b/hidl/livedisplay/AntiFlicker.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "AntiFlickerService" + +#include +#include +#include + +namespace { + +constexpr const char* kDcDimmingPath = "/sys/kernel/oplus_display/dimlayer_bl_en"; + +} // anonymous namespace + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_1 { +namespace implementation { + +Return AntiFlicker::isEnabled() { + std::string tmp; + int32_t contents = 0; + + if (ReadFileToString(kDcDimmingPath, &tmp)) { + contents = std::stoi(Trim(tmp)); + } + + return contents > 0; +} + +Return AntiFlicker::setEnabled(bool enabled) { + return WriteStringToFile(std::to_string(enabled), kDcDimmingPath, true); +} + +} // namespace implementation +} // namespace V2_1 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/hidl/livedisplay/AntiFlicker.h b/hidl/livedisplay/AntiFlicker.h new file mode 100644 index 0000000..aab7edf --- /dev/null +++ b/hidl/livedisplay/AntiFlicker.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef VENDOR_LINEAGE_LIVEDISPLAY_V2_1_ANTIFLICKER_H +#define VENDOR_LINEAGE_LIVEDISPLAY_V2_1_ANTIFLICKER_H + +#include +#include +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +class AntiFlicker : public IAntiFlicker { + public: + // Methods from ::vendor::lineage::livedisplay::V2_1::IAntiFlicker follow. + Return isEnabled() override; + Return setEnabled(bool enabled) override; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor + +#endif // VENDOR_LINEAGE_LIVEDISPLAY_V2_1_ANTIFLICKER_H diff --git a/hidl/livedisplay/include/livedisplay/oplus/AntiFlicker.h b/hidl/livedisplay/include/livedisplay/oplus/AntiFlicker.h new file mode 100644 index 0000000..aab7edf --- /dev/null +++ b/hidl/livedisplay/include/livedisplay/oplus/AntiFlicker.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2021 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef VENDOR_LINEAGE_LIVEDISPLAY_V2_1_ANTIFLICKER_H +#define VENDOR_LINEAGE_LIVEDISPLAY_V2_1_ANTIFLICKER_H + +#include +#include +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +class AntiFlicker : public IAntiFlicker { + public: + // Methods from ::vendor::lineage::livedisplay::V2_1::IAntiFlicker follow. + Return isEnabled() override; + Return setEnabled(bool enabled) override; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor + +#endif // VENDOR_LINEAGE_LIVEDISPLAY_V2_1_ANTIFLICKER_H