From 3c0cba0748b3006db6b9325ec49ae5bfff47dbde Mon Sep 17 00:00:00 2001 From: SGCMarkus Date: Sun, 6 Mar 2022 23:02:20 +0100 Subject: [PATCH] sm8250-common: livedisplay: uprev to 2.1 --- BoardConfigCommon.mk | 2 +- livedisplay/AdaptiveBacklight.cpp | 12 ++-- livedisplay/AdaptiveBacklight.h | 14 ++-- livedisplay/Android.bp | 6 +- livedisplay/AntiFlicker.cpp | 69 +++++++++++++++++++ livedisplay/AntiFlicker.h | 47 +++++++++++++ livedisplay/SunlightEnhancement.cpp | 12 ++-- livedisplay/SunlightEnhancement.h | 14 ++-- livedisplay/service.cpp | 35 +++++++++- ....livedisplay@2.1-service.motorola_kona.rc} | 4 +- sepolicy/vendor/file_contexts | 3 + sepolicy/vendor/genfs_contexts | 6 ++ .../vendor/hal_lineage_livedisplay_qti.te | 1 + sm8250.mk | 3 +- 14 files changed, 193 insertions(+), 35 deletions(-) create mode 100644 livedisplay/AntiFlicker.cpp create mode 100644 livedisplay/AntiFlicker.h rename livedisplay/{vendor.lineage.livedisplay@2.0-service-sysfs.motorola_kona.rc => vendor.lineage.livedisplay@2.1-service.motorola_kona.rc} (68%) create mode 100644 sepolicy/vendor/hal_lineage_livedisplay_qti.te diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk index 507163f..eef43c9 100644 --- a/BoardConfigCommon.mk +++ b/BoardConfigCommon.mk @@ -164,7 +164,7 @@ DEVICE_FRAMEWORK_COMPATIBILITY_MATRIX_FILE := \ $(COMMON_PATH)/device_framework_matrix.xml \ vendor/lineage/config/device_framework_matrix.xml DEVICE_MATRIX_FILE := $(COMMON_PATH)/compatibility_matrix.xml -DEVICE_MANIFEST_FILE := $(COMMON_PATH)/manifest.xml +DEVICE_MANIFEST_FILE += $(COMMON_PATH)/manifest.xml # Metadata BOARD_USES_METADATA_PARTITION := true diff --git a/livedisplay/AdaptiveBacklight.cpp b/livedisplay/AdaptiveBacklight.cpp index 8f0c826..94ed2fc 100644 --- a/livedisplay/AdaptiveBacklight.cpp +++ b/livedisplay/AdaptiveBacklight.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 The LineageOS Project + * Copyright (C) 2019-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. @@ -34,8 +34,8 @@ namespace { namespace vendor { namespace lineage { namespace livedisplay { -namespace V2_0 { -namespace sysfs { +namespace V2_1 { +namespace implementation { AdaptiveBacklight::AdaptiveBacklight() { if (!access(kFileAcl, R_OK | W_OK)) { @@ -54,7 +54,7 @@ bool AdaptiveBacklight::isSupported() { return true; } -// Methods from ::vendor::lineage::livedisplay::V2_0::IAdaptiveBacklight follow. +// Methods from ::vendor::lineage::livedisplay::V2_1::IAdaptiveBacklight follow. Return AdaptiveBacklight::isEnabled() { std::string tmp; int32_t contents = 0; @@ -70,8 +70,8 @@ Return AdaptiveBacklight::setEnabled(bool enabled) { return WriteStringToFile(std::to_string(enabled), file_, true); } -} // namespace sysfs -} // namespace V2_0 +} // namespace implementation +} // namespace V2_1 } // namespace livedisplay } // namespace lineage } // namespace vendor diff --git a/livedisplay/AdaptiveBacklight.h b/livedisplay/AdaptiveBacklight.h index 1bd986c..e47c935 100644 --- a/livedisplay/AdaptiveBacklight.h +++ b/livedisplay/AdaptiveBacklight.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 The LineageOS Project + * Copyright (C) 2019-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. @@ -16,13 +16,13 @@ #pragma once -#include +#include namespace vendor { namespace lineage { namespace livedisplay { -namespace V2_0 { -namespace sysfs { +namespace V2_1 { +namespace implementation { using ::android::hardware::Return; @@ -31,7 +31,7 @@ class AdaptiveBacklight : public IAdaptiveBacklight { AdaptiveBacklight(); bool isSupported(); - // Methods from ::vendor::lineage::livedisplay::V2_0::IAdaptiveBacklight follow. + // Methods from ::vendor::lineage::livedisplay::V2_1::IAdaptiveBacklight follow. Return isEnabled() override; Return setEnabled(bool enabled) override; @@ -39,8 +39,8 @@ class AdaptiveBacklight : public IAdaptiveBacklight { const char* file_; }; -} // namespace sysfs -} // namespace V2_0 +} // namespace implementation +} // namespace V2_1 } // namespace livedisplay } // namespace lineage } // namespace vendor diff --git a/livedisplay/Android.bp b/livedisplay/Android.bp index d0f9c5f..dc8f38b 100644 --- a/livedisplay/Android.bp +++ b/livedisplay/Android.bp @@ -20,6 +20,7 @@ cc_defaults { ":vendor.lineage.livedisplay@2.0-sdm-pa", ":vendor.lineage.livedisplay@2.0-sdm-utils", "AdaptiveBacklight.cpp", + "AntiFlicker.cpp", "SunlightEnhancement.cpp", "service.cpp", ], @@ -31,6 +32,7 @@ cc_defaults { "libhidlbase", "libutils", "vendor.lineage.livedisplay@2.0", + "vendor.lineage.livedisplay@2.1", ], header_libs: [ "vendor.lineage.livedisplay@2.0-sdm-headers", @@ -38,8 +40,8 @@ cc_defaults { } cc_binary { - name: "vendor.lineage.livedisplay@2.0-service-sysfs.motorola_kona", - init_rc: ["vendor.lineage.livedisplay@2.0-service-sysfs.motorola_kona.rc"], + name: "vendor.lineage.livedisplay@2.1-service.motorola_kona", + init_rc: ["vendor.lineage.livedisplay@2.1-service.motorola_kona.rc"], defaults: ["livedisplay_motorola_kona"], vendor: true, } diff --git a/livedisplay/AntiFlicker.cpp b/livedisplay/AntiFlicker.cpp new file mode 100644 index 0000000..3b9db40 --- /dev/null +++ b/livedisplay/AntiFlicker.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2019-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. + */ + +#include "AntiFlicker.h" + +#include +#include + +namespace { + constexpr const char *kFileDc = "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_dc"; +}; // anonymous namespace + +using ::android::base::ReadFileToString; +using ::android::base::Trim; +using ::android::base::WriteStringToFile; + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_1 { +namespace implementation { + +AntiFlicker::AntiFlicker() { + if (!access(kFileDc, R_OK | W_OK)) { + file_ = kFileDc; + enabled_mode_ = 1; + } else { + file_ = nullptr; + } +} + +bool AntiFlicker::isSupported() { + return file_ != nullptr; +} + +// Methods from ::vendor::lineage::livedisplay::V2_1::IAntiFlicker follow. +Return AntiFlicker::isEnabled() { + std::string tmp; + int32_t contents = 0; + + if (ReadFileToString(file_, &tmp)) { + contents = std::stoi(Trim(tmp)); + } + + return contents > 0; +} + +Return AntiFlicker::setEnabled(bool enabled) { + return WriteStringToFile(enabled ? std::to_string(enabled_mode_) : "0", file_, true); +} + +} // namespace implementation +} // namespace V2_1 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/livedisplay/AntiFlicker.h b/livedisplay/AntiFlicker.h new file mode 100644 index 0000000..80842f0 --- /dev/null +++ b/livedisplay/AntiFlicker.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2019-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. + */ + +#pragma once + +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::Return; + +class AntiFlicker : public IAntiFlicker { + public: + AntiFlicker(); + bool isSupported(); + + // Methods from ::vendor::lineage::livedisplay::V2_1::IAntiFlicker follow. + Return isEnabled() override; + Return setEnabled(bool enabled) override; + + private: + const char* file_; + int32_t enabled_mode_; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/livedisplay/SunlightEnhancement.cpp b/livedisplay/SunlightEnhancement.cpp index cc0435e..9b41538 100644 --- a/livedisplay/SunlightEnhancement.cpp +++ b/livedisplay/SunlightEnhancement.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 The LineageOS Project + * Copyright (C) 2019-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. @@ -30,8 +30,8 @@ using ::android::base::WriteStringToFile; namespace vendor { namespace lineage { namespace livedisplay { -namespace V2_0 { -namespace sysfs { +namespace V2_1 { +namespace implementation { SunlightEnhancement::SunlightEnhancement() { if (!access(kFileHbm, R_OK | W_OK)) { @@ -46,7 +46,7 @@ bool SunlightEnhancement::isSupported() { return file_ != nullptr; } -// Methods from ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement follow. +// Methods from ::vendor::lineage::livedisplay::V2_1::ISunlightEnhancement follow. Return SunlightEnhancement::isEnabled() { std::string tmp; int32_t contents = 0; @@ -62,8 +62,8 @@ Return SunlightEnhancement::setEnabled(bool enabled) { return WriteStringToFile(enabled ? std::to_string(enabled_mode_) : "0", file_, true); } -} // namespace sysfs -} // namespace V2_0 +} // namespace implementation +} // namespace V2_1 } // namespace livedisplay } // namespace lineage } // namespace vendor diff --git a/livedisplay/SunlightEnhancement.h b/livedisplay/SunlightEnhancement.h index e43d952..73c9641 100644 --- a/livedisplay/SunlightEnhancement.h +++ b/livedisplay/SunlightEnhancement.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 The LineageOS Project + * Copyright (C) 2019-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. @@ -16,13 +16,13 @@ #pragma once -#include +#include namespace vendor { namespace lineage { namespace livedisplay { -namespace V2_0 { -namespace sysfs { +namespace V2_1 { +namespace implementation { using ::android::hardware::Return; @@ -31,7 +31,7 @@ class SunlightEnhancement : public ISunlightEnhancement { SunlightEnhancement(); bool isSupported(); - // Methods from ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement follow. + // Methods from ::vendor::lineage::livedisplay::V2_1::ISunlightEnhancement follow. Return isEnabled() override; Return setEnabled(bool enabled) override; @@ -40,8 +40,8 @@ class SunlightEnhancement : public ISunlightEnhancement { int32_t enabled_mode_; }; -} // namespace sysfs -} // namespace V2_0 +} // namespace implementation +} // namespace V2_1 } // namespace livedisplay } // namespace lineage } // namespace vendor diff --git a/livedisplay/service.cpp b/livedisplay/service.cpp index 81d8c5e..f520015 100644 --- a/livedisplay/service.cpp +++ b/livedisplay/service.cpp @@ -14,11 +14,15 @@ * limitations under the License. */ -#define LOG_TAG "vendor.lineage.livedisplay@2.0-service-sysfs.motorola_kona" +#define LOG_TAG "vendor.lineage.livedisplay@2.1-service.motorola_kona" #include +#include #include +#include +#include #include "AdaptiveBacklight.h" +#include "AntiFlicker.h" #include "SunlightEnhancement.h" using ::android::OK; @@ -27,8 +31,12 @@ using ::android::status_t; using ::android::hardware::configureRpcThreadpool; using ::android::hardware::joinRpcThreadpool; -using ::vendor::lineage::livedisplay::V2_0::sysfs::AdaptiveBacklight; -using ::vendor::lineage::livedisplay::V2_0::sysfs::SunlightEnhancement; +using ::vendor::lineage::livedisplay::V2_0::sdm::PictureAdjustment; +using ::vendor::lineage::livedisplay::V2_0::sdm::SDMController; +using ::vendor::lineage::livedisplay::V2_1::IPictureAdjustment; +using ::vendor::lineage::livedisplay::V2_1::implementation::AdaptiveBacklight; +using ::vendor::lineage::livedisplay::V2_1::implementation::AntiFlicker; +using ::vendor::lineage::livedisplay::V2_1::implementation::SunlightEnhancement; status_t RegisterAsServices() { status_t status = OK; @@ -52,11 +60,32 @@ status_t RegisterAsServices() { return status; } } + + sp af = new AntiFlicker(); + if (af->isSupported()) { + status = af->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Could not register service for LiveDisplay HAL AntiFlicker Iface" + << " (" << status << ")"; + return status; + } + } + + std::shared_ptr controller = std::make_shared(); + sp pa = new PictureAdjustment(controller); + status = pa->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Could not register service for LiveDisplay HAL PictureAdjustment Iface (" + << status << ")"; + return status; + } return OK; } int main() { + android::ProcessState::initWithDriver("/dev/vndbinder"); + LOG(DEBUG) << "LiveDisplay HAL service is starting."; configureRpcThreadpool(1, true /*callerWillJoin*/); diff --git a/livedisplay/vendor.lineage.livedisplay@2.0-service-sysfs.motorola_kona.rc b/livedisplay/vendor.lineage.livedisplay@2.1-service.motorola_kona.rc similarity index 68% rename from livedisplay/vendor.lineage.livedisplay@2.0-service-sysfs.motorola_kona.rc rename to livedisplay/vendor.lineage.livedisplay@2.1-service.motorola_kona.rc index c8bb81a..13c40c5 100644 --- a/livedisplay/vendor.lineage.livedisplay@2.0-service-sysfs.motorola_kona.rc +++ b/livedisplay/vendor.lineage.livedisplay@2.1-service.motorola_kona.rc @@ -6,8 +6,10 @@ on init chmod 0660 /sys/devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_cabc chown system system /sys/devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_hbm chmod 0660 /sys/devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_hbm + chown system system /sys/devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_dc + chmod 0660 /sys/devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_dc -service vendor.livedisplay-hal-2-0-sysfs /vendor/bin/hw/vendor.lineage.livedisplay@2.0-service-sysfs.motorola_kona +service vendor.livedisplay-hal-2-1 /vendor/bin/hw/vendor.lineage.livedisplay@2.1-service.motorola_kona class hal user system group system diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index 5be5724..13910d4 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -56,6 +56,9 @@ # Lights /(vendor|system/vendor)/bin/hw/android\.hardware\.lights-service\.motokona u:object_r:hal_light_default_exec:s0 +# LiveDisplay +/(vendor|system/vendor)/bin/hw/vendor\.lineage\.livedisplay@2\.1-service\.motorola_kona u:object_r:hal_lineage_livedisplay_qti_exec:s0 + # Motobox /(vendor|system/vendor)/bin/motobox u:object_r:vendor_motobox_exec:s0 diff --git a/sepolicy/vendor/genfs_contexts b/sepolicy/vendor/genfs_contexts index 09e1653..0b6055e 100644 --- a/sepolicy/vendor/genfs_contexts +++ b/sepolicy/vendor/genfs_contexts @@ -18,6 +18,12 @@ genfscon sysfs /devices/virtual/input # Lights genfscon sysfs /devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-05/c440000.qcom,spmi:qcom,pm8150l@5:qcom,leds@d000/leds/charging u:object_r:sysfs_leds:s0 +# LiveDisplay +genfscon sysfs /devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_acl u:object_r:sysfs_livedisplay_tuneable:s0 +genfscon sysfs /devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_cabc u:object_r:sysfs_livedisplay_tuneable:s0 +genfscon sysfs /devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_hbm u:object_r:sysfs_livedisplay_tuneable:s0 +genfscon sysfs /devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_dc u:object_r:sysfs_livedisplay_tuneable:s0 + # Motorola genfscon proc /bootinfo u:object_r:proc_moto_boot:s0 genfscon proc /config u:object_r:vendor_proc_hw:s0 diff --git a/sepolicy/vendor/hal_lineage_livedisplay_qti.te b/sepolicy/vendor/hal_lineage_livedisplay_qti.te new file mode 100644 index 0000000..afbf316 --- /dev/null +++ b/sepolicy/vendor/hal_lineage_livedisplay_qti.te @@ -0,0 +1 @@ +allow hal_lineage_livedisplay_qti sysfs_livedisplay_tuneable:file rw_file_perms; \ No newline at end of file diff --git a/sm8250.mk b/sm8250.mk index b166b81..9560196 100644 --- a/sm8250.mk +++ b/sm8250.mk @@ -250,8 +250,7 @@ PRODUCT_PACKAGES += \ # LiveDisplay PRODUCT_PACKAGES += \ - vendor.lineage.livedisplay@2.0-service-sdm \ - vendor.lineage.livedisplay@2.0-service-sysfs.motorola_kona + vendor.lineage.livedisplay@2.1-service.motorola_kona # Media PRODUCT_COPY_FILES += \