diff --git a/device_framework_matrix.xml b/device_framework_matrix.xml index 63985ae..d9c0651 100644 --- a/device_framework_matrix.xml +++ b/device_framework_matrix.xml @@ -196,6 +196,10 @@ vendor.lineage.livedisplay 2.1 + + IAntiFlicker + default + IDisplayModes default diff --git a/livedisplay/Android.bp b/livedisplay/Android.bp index a4c736d..bdb82ad 100644 --- a/livedisplay/Android.bp +++ b/livedisplay/Android.bp @@ -22,6 +22,7 @@ cc_binary { srcs: [ ":vendor.lineage.livedisplay@2.0-sdm-pa", ":vendor.lineage.livedisplay@2.0-sdm-utils", + "AntiFlicker.cpp", "DisplayModes.cpp", "SunlightEnhancement.cpp", "service.cpp", diff --git a/livedisplay/AntiFlicker.cpp b/livedisplay/AntiFlicker.cpp new file mode 100644 index 0000000..17bbf85 --- /dev/null +++ b/livedisplay/AntiFlicker.cpp @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#define LOG_TAG "AntiFlickerService" + +#include "AntiFlicker.h" +#include +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_1 { +namespace implementation { + +static constexpr const char* kDcDimmingPath = + "/sys/devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/card0-DSI-1/dimlayer_bl_en"; + +Return AntiFlicker::isEnabled() { + std::ifstream file(kDcDimmingPath); + int result = -1; + file >> result; + LOG(DEBUG) << "Got result " << result << " fail " << file.fail(); + return !file.fail() && result > 0; +} + +Return AntiFlicker::setEnabled(bool enabled) { + std::ofstream file(kDcDimmingPath); + file << (enabled ? "1" : "0"); + LOG(DEBUG) << "setEnabled fail " << file.fail(); + return !file.fail(); +} + +} // 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..aab7edf --- /dev/null +++ b/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/livedisplay/service.cpp b/livedisplay/service.cpp index c4dc161..5f42064 100644 --- a/livedisplay/service.cpp +++ b/livedisplay/service.cpp @@ -22,6 +22,7 @@ #include #include +#include "AntiFlicker.h" #include "DisplayModes.h" #include "SunlightEnhancement.h" @@ -33,9 +34,11 @@ using android::hardware::joinRpcThreadpool; using ::vendor::lineage::livedisplay::V2_0::sdm::PictureAdjustment; using ::vendor::lineage::livedisplay::V2_0::sdm::SDMController; +using ::vendor::lineage::livedisplay::V2_1::IAntiFlicker; using ::vendor::lineage::livedisplay::V2_1::IDisplayModes; using ::vendor::lineage::livedisplay::V2_1::IPictureAdjustment; using ::vendor::lineage::livedisplay::V2_1::ISunlightEnhancement; +using ::vendor::lineage::livedisplay::V2_1::implementation::AntiFlicker; using ::vendor::lineage::livedisplay::V2_1::implementation::DisplayModes; using ::vendor::lineage::livedisplay::V2_1::implementation::SunlightEnhancement; @@ -47,12 +50,20 @@ int main() { LOG(INFO) << "LiveDisplay HAL service is starting."; std::shared_ptr controller = std::make_shared(); + sp af = new AntiFlicker(); sp dm = new DisplayModes(); sp pa = new PictureAdjustment(controller); sp se = new SunlightEnhancement(); configureRpcThreadpool(1, true /*callerWillJoin*/); + status = af->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Could not register service for LiveDisplay HAL AntiFlicker Iface (" + << status << ")"; + goto shutdown; + } + status = dm->registerAsService(); if (status != OK) { LOG(ERROR) << "Could not register service for LiveDisplay HAL DisplayModes Iface (" diff --git a/livedisplay/vendor.lineage.livedisplay@2.1-service.oneplus_kona.rc b/livedisplay/vendor.lineage.livedisplay@2.1-service.oneplus_kona.rc index 12d8e41..3f17302 100644 --- a/livedisplay/vendor.lineage.livedisplay@2.1-service.oneplus_kona.rc +++ b/livedisplay/vendor.lineage.livedisplay@2.1-service.oneplus_kona.rc @@ -1,5 +1,6 @@ on init chown system graphics /sys/class/drm/card0-DSI-1/DCI_P3 + chown system graphics /sys/class/drm/card0-DSI-1/dimlayer_bl_en chown system graphics /sys/class/drm/card0-DSI-1/hbm chown system graphics /sys/class/drm/card0-DSI-1/night_mode chown system graphics /sys/class/drm/card0-DSI-1/native_display_loading_effect_mode @@ -7,6 +8,7 @@ on init chown system graphics /sys/class/drm/card0-DSI-1/native_display_srgb_color_mode chown system graphics /sys/class/drm/card0-DSI-1/native_display_wide_color_mode chmod 0666 /sys/class/drm/card0-DSI-1/DCI_P3 + chmod 0666 /sys/class/drm/card0-DSI-1/dimlayer_bl_en chmod 0666 /sys/class/drm/card0-DSI-1/hbm chmod 0666 /sys/class/drm/card0-DSI-1/night_mode chmod 0666 /sys/class/drm/card0-DSI-1/native_display_loading_effect_mode diff --git a/livedisplay/vendor.lineage.livedisplay@2.1-service.oneplus_kona.xml b/livedisplay/vendor.lineage.livedisplay@2.1-service.oneplus_kona.xml index 0e3a630..e40d430 100644 --- a/livedisplay/vendor.lineage.livedisplay@2.1-service.oneplus_kona.xml +++ b/livedisplay/vendor.lineage.livedisplay@2.1-service.oneplus_kona.xml @@ -3,6 +3,10 @@ vendor.lineage.livedisplay hwbinder 2.1 + + IAntiFlicker + default + IDisplayModes default diff --git a/sepolicy/vendor/genfs_contexts b/sepolicy/vendor/genfs_contexts index efb1542..330ebcd 100644 --- a/sepolicy/vendor/genfs_contexts +++ b/sepolicy/vendor/genfs_contexts @@ -29,6 +29,7 @@ genfscon proc /wireless/rx_voltage u:object_r:procfs_oem_wirele genfscon sysfs /devices/platform/soc/a8c000.i2c/i2c-3/3-005a/leds/vibrator u:object_r:sysfs_leds:s0 genfscon sysfs /devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/card0-DSI-1/DCI_P3 u:object_r:sysfs_livedisplay_tuneable:s0 genfscon sysfs /devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/card0-DSI-1/dim_alpha u:object_r:sysfs_fod:s0 +genfscon sysfs /devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/card0-DSI-1/dimlayer_bl_en u:object_r:sysfs_livedisplay_tuneable:s0 genfscon sysfs /devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/card0-DSI-1/hbm u:object_r:sysfs_livedisplay_tuneable:s0 genfscon sysfs /devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/card0-DSI-1/native_display_loading_effect_mode u:object_r:sysfs_livedisplay_tuneable:s0 genfscon sysfs /devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/card0-DSI-1/native_display_p3_mode u:object_r:sysfs_livedisplay_tuneable:s0