diff --git a/livedisplay/Android.bp b/livedisplay/Android.bp index d703560..8133df6 100644 --- a/livedisplay/Android.bp +++ b/livedisplay/Android.bp @@ -20,6 +20,7 @@ cc_binary { init_rc: ["vendor.lineage.livedisplay@2.0-service.xiaomi_sm6150.rc"], relative_install_path: "hw", srcs: [ + "AntiFlicker.cpp", "SunlightEnhancement.cpp", "service.cpp", ], diff --git a/livedisplay/AntiFlicker.cpp b/livedisplay/AntiFlicker.cpp new file mode 100644 index 0000000..4eb0448 --- /dev/null +++ b/livedisplay/AntiFlicker.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2020 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 + +#include "AntiFlicker.h" + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_0 { +namespace implementation { + +static constexpr const char* kAntiFlickerStatusPath = + "/sys/devices/platform/soc/soc:qcom,dsi-display/msm_fb_ea_enable"; + +Return AntiFlicker::isEnabled() { + std::string buf; + if (!android::base::ReadFileToString(kAntiFlickerStatusPath, &buf)) { + LOG(ERROR) << "Failed to read " << kAntiFlickerStatusPath; + return false; + } + return std::stoi(android::base::Trim(buf)) == 1; +} + +Return AntiFlicker::setEnabled(bool enabled) { + if (!android::base::WriteStringToFile((enabled ? "1" : "0"), kAntiFlickerStatusPath)) { + LOG(ERROR) << "Failed to write " << kAntiFlickerStatusPath; + return false; + } + return true; +} + +} // namespace implementation +} // namespace V2_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/livedisplay/AntiFlicker.h b/livedisplay/AntiFlicker.h new file mode 100644 index 0000000..3f4f8b6 --- /dev/null +++ b/livedisplay/AntiFlicker.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2020 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_0_ANTIFLICKER_H +#define VENDOR_LINEAGE_LIVEDISPLAY_V2_0_ANTIFLICKER_H + +#include +#include +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_0 { +namespace implementation { + +using ::android::sp; +using ::android::hardware::Return; +using ::android::hardware::Void; + +class AntiFlicker : public IAntiFlicker { + public: + // Methods from ::vendor::lineage::livedisplay::V2_0::IAntiFlicker follow. + Return isEnabled() override; + Return setEnabled(bool enabled) override; +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor + +#endif // VENDOR_LINEAGE_LIVEDISPLAY_V2_0_ANTIFLICKER_H diff --git a/livedisplay/service.cpp b/livedisplay/service.cpp index 604f220..5b7b954 100644 --- a/livedisplay/service.cpp +++ b/livedisplay/service.cpp @@ -20,16 +20,24 @@ #include #include +#include "AntiFlicker.h" #include "SunlightEnhancement.h" +using ::vendor::lineage::livedisplay::V2_0::IAntiFlicker; using ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement; +using ::vendor::lineage::livedisplay::V2_0::implementation::AntiFlicker; using ::vendor::lineage::livedisplay::V2_0::implementation::SunlightEnhancement; int main() { + android::sp antiFlicker = new AntiFlicker(); android::sp sunlightEnhancement = new SunlightEnhancement(); android::hardware::configureRpcThreadpool(1, true /*callerWillJoin*/); + if (antiFlicker->registerAsService() != android::OK) { + LOG(ERROR) << "Cannot register anti flicker HAL service."; + return 1; + } if (sunlightEnhancement->registerAsService() != android::OK) { LOG(ERROR) << "Cannot register sunlight enhancement HAL service."; return 1; diff --git a/livedisplay/vendor.lineage.livedisplay@2.0-service.xiaomi_sm6150.rc b/livedisplay/vendor.lineage.livedisplay@2.0-service.xiaomi_sm6150.rc index 5877b3a..7a82169 100644 --- a/livedisplay/vendor.lineage.livedisplay@2.0-service.xiaomi_sm6150.rc +++ b/livedisplay/vendor.lineage.livedisplay@2.0-service.xiaomi_sm6150.rc @@ -1,6 +1,9 @@ on boot chown system system /sys/devices/platform/soc/soc:qcom,dsi-display/hbm + chown system system /sys/devices/platform/soc/soc:qcom,dsi-display/msm_fb_ea_enable + chmod 0660 /sys/devices/platform/soc/soc:qcom,dsi-display/hbm + chmod 0660 /sys/devices/platform/soc/soc:qcom,dsi-display/msm_fb_ea_enable service vendor.livedisplay-hal-2-0 /vendor/bin/hw/vendor.lineage.livedisplay@2.0-service.xiaomi_sm6150 class hal diff --git a/livedisplay/vendor.lineage.livedisplay@2.0-service.xiaomi_sm6150.xml b/livedisplay/vendor.lineage.livedisplay@2.0-service.xiaomi_sm6150.xml index 45cd462..c01b835 100644 --- a/livedisplay/vendor.lineage.livedisplay@2.0-service.xiaomi_sm6150.xml +++ b/livedisplay/vendor.lineage.livedisplay@2.0-service.xiaomi_sm6150.xml @@ -3,6 +3,10 @@ vendor.lineage.livedisplay hwbinder 2.0 + + IAntiFlicker + default + IPictureAdjustment default diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index 13c7609..46cc340 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -4,6 +4,7 @@ # Display /sys/devices/platform/soc/[a-f0-9]+.qcom,mdss_mdp/drm/card([0-3])+/card([0-3])+-DSI-1/panel_info u:object_r:vendor_sysfs_graphics:s0 /sys/devices/platform/soc/soc:qcom,dsi-display/hbm u:object_r:sysfs_hbm:s0 +/sys/devices/platform/soc/soc:qcom,dsi-display/msm_fb_ea_enable u:object_r:sysfs_anti_flicker:s0 # Fingerprint /dev/goodix_fp u:object_r:fingerprint_device:s0 diff --git a/sepolicy/vendor/hal_lineage_livedisplay_qti.te b/sepolicy/vendor/hal_lineage_livedisplay_qti.te index 9d783d9..097cd46 100644 --- a/sepolicy/vendor/hal_lineage_livedisplay_qti.te +++ b/sepolicy/vendor/hal_lineage_livedisplay_qti.te @@ -1,3 +1,5 @@ +type sysfs_anti_flicker, sysfs_type, fs_type; type sysfs_hbm, sysfs_type, fs_type; +allow hal_lineage_livedisplay_qti sysfs_anti_flicker:file rw_file_perms; allow hal_lineage_livedisplay_qti sysfs_hbm:file rw_file_perms;