diff --git a/livedisplay/Android.bp b/livedisplay/Android.bp new file mode 100644 index 0000000..125f2de --- /dev/null +++ b/livedisplay/Android.bp @@ -0,0 +1,35 @@ +// +// Copyright (C) 2022 The LineageOS Project +// +// Licensed under the Apache License, Version 2.1 (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.1 +// +// 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. + +cc_binary { + name: "vendor.lineage.livedisplay@2.1-service.sdm710", + defaults: ["hidl_defaults"], + vintf_fragments: ["vendor.lineage.livedisplay@2.1-service.sdm710.xml"], + init_rc: ["vendor.lineage.livedisplay@2.1-service.sdm710.rc"], + relative_install_path: "hw", + srcs: [ + "SunlightEnhancement.cpp", + "service.cpp", + ], + vendor: true, + shared_libs: [ + "libbase", + "libbinder", + "libhidlbase", + "libutils", + "vendor.lineage.livedisplay@2.0", + "vendor.lineage.livedisplay@2.1", + ], +} diff --git a/livedisplay/SunlightEnhancement.cpp b/livedisplay/SunlightEnhancement.cpp new file mode 100644 index 0000000..16a7744 --- /dev/null +++ b/livedisplay/SunlightEnhancement.cpp @@ -0,0 +1,62 @@ +/* + * 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 "SunlightEnhancementService" + +#include +#include +#include +#include + +#include "SunlightEnhancement.h" + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_1 { +namespace implementation { + +static constexpr const char* kHbmPath = "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/hbm"; + +bool SunlightEnhancement::isSupported() { + std::ofstream hbm_file(kHbmPath); + if (!hbm_file.is_open()) { + LOG(ERROR) << "Failed to open " << kHbmPath << ", error=" << errno + << " (" << strerror(errno) << ")"; + } + return !hbm_file.fail(); +} + +Return SunlightEnhancement::isEnabled() { + std::ifstream hbm_file(kHbmPath); + int result = -1; + hbm_file >> result; + return !hbm_file.fail() && result > 0; +} + +Return SunlightEnhancement::setEnabled(bool enabled) { + std::ofstream hbm_file(kHbmPath); + hbm_file << (enabled ? '1' : '0'); + if (hbm_file.fail()) + LOG(ERROR) << "Failed to write " << kHbmPath; + return !hbm_file.fail(); +} + +} // namespace implementation +} // namespace V2_1 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/livedisplay/SunlightEnhancement.h b/livedisplay/SunlightEnhancement.h new file mode 100644 index 0000000..612eb9a --- /dev/null +++ b/livedisplay/SunlightEnhancement.h @@ -0,0 +1,44 @@ +/* + * 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. + */ + +#pragma once + +#include +#include +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_1 { +namespace implementation { + +using ::android::hardware::Return; + +class SunlightEnhancement : public ISunlightEnhancement { + public: + bool isSupported(); + + // Methods from ::vendor::lineage::livedisplay::V2_1::ISunlightEnhancement follow. + Return isEnabled() override; + Return setEnabled(bool enabled) override; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/livedisplay/service.cpp b/livedisplay/service.cpp new file mode 100644 index 0000000..f102dc3 --- /dev/null +++ b/livedisplay/service.cpp @@ -0,0 +1,45 @@ +/* + * 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 "vendor.lineage.livedisplay@2.1-service.sdm710" + +#include +#include +#include +#include "SunlightEnhancement.h" + +using ::vendor::lineage::livedisplay::V2_1::implementation::SunlightEnhancement; + +int main() { + android::sp sunlightEnhancement = new SunlightEnhancement(); + + android::hardware::configureRpcThreadpool(1, true /*callerWillJoin*/); + + if (sunlightEnhancement->isSupported()) { + if (sunlightEnhancement->registerAsService() != android::OK) { + LOG(ERROR) << "Cannot register sunlight enhancement HAL service."; + return 1; + } + } + + LOG(INFO) << "LiveDisplay HAL service is ready."; + + android::hardware::joinRpcThreadpool(); + + LOG(ERROR) << "LiveDisplay HAL service failed to join thread pool."; + + return 1; +} diff --git a/livedisplay/vendor.lineage.livedisplay@2.1-service.sdm710.rc b/livedisplay/vendor.lineage.livedisplay@2.1-service.sdm710.rc new file mode 100644 index 0000000..01b6f4c --- /dev/null +++ b/livedisplay/vendor.lineage.livedisplay@2.1-service.sdm710.rc @@ -0,0 +1,7 @@ +on boot + chown system system /sys/devices/platform/soc/soc:qcom,dsi-display-primary/hbm + +service vendor.livedisplay-hal-2-1 /vendor/bin/hw/vendor.lineage.livedisplay@2.1-service.sdm710 + class late_start + user system + group system diff --git a/livedisplay/vendor.lineage.livedisplay@2.1-service.sdm710.xml b/livedisplay/vendor.lineage.livedisplay@2.1-service.sdm710.xml new file mode 100644 index 0000000..4ddd2c3 --- /dev/null +++ b/livedisplay/vendor.lineage.livedisplay@2.1-service.sdm710.xml @@ -0,0 +1,7 @@ + + + vendor.lineage.livedisplay + hwbinder + @2.1::ISunlightEnhancement/default + + diff --git a/sdm710.mk b/sdm710.mk index bea5030..b5267f0 100644 --- a/sdm710.mk +++ b/sdm710.mk @@ -220,6 +220,10 @@ PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \ android.hardware.light-service.xiaomi +# LiveDisplay +PRODUCT_PACKAGES += \ + vendor.lineage.livedisplay@2.1-service.sdm710 + # Media PRODUCT_PACKAGES += \ libavservices_minijail \ diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index e76236f..02383db 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -16,6 +16,7 @@ /sys/devices/platform/soc/[a-z0-9]+.qcom,mdss_mdp/drm/card([0-3])+/card([0-3])+-DSI-1/hbm_status u:object_r:sysfs_graphics:s0 /sys/devices/platform/soc/[a-z0-9]+.qcom,mdss_mdp/drm/card([0-3])+/card([0-3])+-DSI-1/panel_info u:object_r:sysfs_graphics:s0 /sys/devices/platform/soc/[a-z0-9]+.qcom,mdss_mdp/drm/card([0-3])+/card([0-3])+-DSI-1/smart_fps_value u:object_r:sysfs_graphics:s0 +/vendor/bin/hw/vendor\.lineage\.livedisplay@2\.1-service\.sdm710 u:object_r:hal_lineage_livedisplay_qti_exec:s0 # Fingerprint /vendor/bin/hw/android\.hardware\.biometrics\.fingerprint@2\.3-service\.xiaomi u:object_r:hal_fingerprint_default_exec: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..a413f5d --- /dev/null +++ b/sepolicy/vendor/hal_lineage_livedisplay_qti.te @@ -0,0 +1,2 @@ +allow hal_lineage_livedisplay_qti sysfs_graphics:dir search; +allow hal_lineage_livedisplay_qti sysfs_graphics:file rw_file_perms;