diff --git a/livedisplay/AdaptiveBacklight.cpp b/livedisplay/AdaptiveBacklight.cpp new file mode 100644 index 0000000..8f0c826 --- /dev/null +++ b/livedisplay/AdaptiveBacklight.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2019-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. + */ + +#include "AdaptiveBacklight.h" + +#include +#include +#include + +using ::android::base::GetBoolProperty; +using ::android::base::ReadFileToString; +using ::android::base::Trim; +using ::android::base::WriteStringToFile; + +namespace { + constexpr const char *kFileAcl = "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_acl"; + constexpr const char *kFileCabc = "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_cabc"; + constexpr const char *kFossProperty = "ro.vendor.display.foss"; +} // anonymous namespace + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_0 { +namespace sysfs { + +AdaptiveBacklight::AdaptiveBacklight() { + if (!access(kFileAcl, R_OK | W_OK)) { + file_ = kFileAcl; + } else if (!access(kFileCabc, R_OK | W_OK)) { + file_ = kFileCabc; + } else { + file_ = nullptr; + } +} + +bool AdaptiveBacklight::isSupported() { + if (GetBoolProperty(kFossProperty, false) || file_ == nullptr) { + return false; + } + return true; +} + +// Methods from ::vendor::lineage::livedisplay::V2_0::IAdaptiveBacklight follow. +Return AdaptiveBacklight::isEnabled() { + std::string tmp; + int32_t contents = 0; + + if (ReadFileToString(file_, &tmp)) { + contents = std::stoi(Trim(tmp)); + } + + return contents > 0; +} + +Return AdaptiveBacklight::setEnabled(bool enabled) { + return WriteStringToFile(std::to_string(enabled), file_, true); +} + +} // namespace sysfs +} // namespace V2_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/livedisplay/AdaptiveBacklight.h b/livedisplay/AdaptiveBacklight.h new file mode 100644 index 0000000..1bd986c --- /dev/null +++ b/livedisplay/AdaptiveBacklight.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2019-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. + */ + +#pragma once + +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_0 { +namespace sysfs { + +using ::android::hardware::Return; + +class AdaptiveBacklight : public IAdaptiveBacklight { + public: + AdaptiveBacklight(); + bool isSupported(); + + // Methods from ::vendor::lineage::livedisplay::V2_0::IAdaptiveBacklight follow. + Return isEnabled() override; + Return setEnabled(bool enabled) override; + + private: + const char* file_; +}; + +} // namespace sysfs +} // namespace V2_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/livedisplay/Android.bp b/livedisplay/Android.bp new file mode 100644 index 0000000..cadf01b --- /dev/null +++ b/livedisplay/Android.bp @@ -0,0 +1,46 @@ +// Copyright (C) 2019-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. + +cc_defaults { + name: "livedisplay_motorola_lito", + defaults: ["hidl_defaults"], + relative_install_path: "hw", + srcs: [ + ":vendor.lineage.livedisplay@2.0-sdm-pa", + ":vendor.lineage.livedisplay@2.0-sdm-utils", + "AdaptiveBacklight.cpp", + "SunlightEnhancement.cpp", + "service.cpp", + ], + shared_libs: [ + "libbase", + "libbinder", + "libcutils", + "libdl", + "libhidlbase", + "libhidltransport", + "libutils", + "vendor.lineage.livedisplay@2.0", + ], + header_libs: [ + "vendor.lineage.livedisplay@2.0-sdm-headers", + ], +} + +cc_binary { + name: "vendor.lineage.livedisplay@2.0-service-sysfs.motorola_lito", + init_rc: ["vendor.lineage.livedisplay@2.0-service-sysfs.motorola_lito.rc"], + defaults: ["livedisplay_motorola_lito"], + vendor: true, +} diff --git a/livedisplay/SunlightEnhancement.cpp b/livedisplay/SunlightEnhancement.cpp new file mode 100644 index 0000000..cc0435e --- /dev/null +++ b/livedisplay/SunlightEnhancement.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2019-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. + */ + +#include "SunlightEnhancement.h" + +#include +#include + +namespace { + constexpr const char *kFileHbm = "/sys/devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_hbm"; +}; // anonymous namespace + +using ::android::base::ReadFileToString; +using ::android::base::Trim; +using ::android::base::WriteStringToFile; + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_0 { +namespace sysfs { + +SunlightEnhancement::SunlightEnhancement() { + if (!access(kFileHbm, R_OK | W_OK)) { + file_ = kFileHbm; + enabled_mode_ = 1; + } else { + file_ = nullptr; + } +} + +bool SunlightEnhancement::isSupported() { + return file_ != nullptr; +} + +// Methods from ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement follow. +Return SunlightEnhancement::isEnabled() { + std::string tmp; + int32_t contents = 0; + + if (ReadFileToString(file_, &tmp)) { + contents = std::stoi(Trim(tmp)); + } + + return contents > 0; +} + +Return SunlightEnhancement::setEnabled(bool enabled) { + return WriteStringToFile(enabled ? std::to_string(enabled_mode_) : "0", file_, true); +} + +} // namespace sysfs +} // namespace V2_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/livedisplay/SunlightEnhancement.h b/livedisplay/SunlightEnhancement.h new file mode 100644 index 0000000..e43d952 --- /dev/null +++ b/livedisplay/SunlightEnhancement.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2019-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. + */ + +#pragma once + +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_0 { +namespace sysfs { + +using ::android::hardware::Return; + +class SunlightEnhancement : public ISunlightEnhancement { + public: + SunlightEnhancement(); + bool isSupported(); + + // Methods from ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement follow. + Return isEnabled() override; + Return setEnabled(bool enabled) override; + + private: + const char* file_; + int32_t enabled_mode_; +}; + +} // namespace sysfs +} // namespace V2_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/livedisplay/service.cpp b/livedisplay/service.cpp new file mode 100644 index 0000000..371e53c --- /dev/null +++ b/livedisplay/service.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2019-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 "vendor.lineage.livedisplay@2.0-service-sysfs.motorola_lito" + +#include +#include +#include "AdaptiveBacklight.h" +#include "SunlightEnhancement.h" + +using ::android::OK; +using ::android::sp; +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; + +status_t RegisterAsServices() { + status_t status = OK; + + sp ab = new AdaptiveBacklight(); + if (ab->isSupported()) { + status = ab->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Could not register service for LiveDisplay HAL AdaptiveBacklight Iface (" + << status << ")"; + return status; + } + } + + sp se = new SunlightEnhancement(); + if (se->isSupported()) { + status = se->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Could not register service for LiveDisplay HAL SunlightEnhancement Iface" + << " (" << status << ")"; + return status; + } + } + + return OK; +} + +int main() { + LOG(DEBUG) << "LiveDisplay HAL service is starting."; + + configureRpcThreadpool(1, true /*callerWillJoin*/); + + if (RegisterAsServices() == OK) { + LOG(DEBUG) << "LiveDisplay HAL service is ready."; + joinRpcThreadpool(); + } else { + LOG(ERROR) << "Could not register service for LiveDisplay HAL"; + } + + // In normal operation, we don't expect the thread pool to shutdown + LOG(ERROR) << "LiveDisplay HAL service is shutting down."; + return 1; +} diff --git a/livedisplay/vendor.lineage.livedisplay@2.0-service-sysfs.motorola_lito.rc b/livedisplay/vendor.lineage.livedisplay@2.0-service-sysfs.motorola_lito.rc new file mode 100644 index 0000000..4cb3e73 --- /dev/null +++ b/livedisplay/vendor.lineage.livedisplay@2.0-service-sysfs.motorola_lito.rc @@ -0,0 +1,13 @@ +on init + # LiveDisplay sysfs + chown system system /sys/devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_acl + chmod 0660 /sys/devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_acl + chown system system /sys/devices/platform/soc/soc:qcom,dsi-display-primary/dsi_display_cabc + 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 + +service vendor.livedisplay-hal-2-0-sysfs /vendor/bin/hw/vendor.lineage.livedisplay@2.0-service-sysfs.motorola_lito + class hal + user system + group system diff --git a/manifest.xml b/manifest.xml index b28d248..77837bc 100644 --- a/manifest.xml +++ b/manifest.xml @@ -230,6 +230,14 @@ IPictureAdjustment default + + ISunlightEnhancement + default + + + IAdaptiveBacklight + default + vendor.qti.data.factory diff --git a/sm8250.mk b/sm8250.mk index 29197c3..b33cd11 100644 --- a/sm8250.mk +++ b/sm8250.mk @@ -250,7 +250,8 @@ PRODUCT_PACKAGES += \ # LiveDisplay PRODUCT_PACKAGES += \ - vendor.lineage.livedisplay@2.0-service-sdm + vendor.lineage.livedisplay@2.0-service-sdm \ + vendor.lineage.livedisplay@2.0-service-sysfs.motorola_lito # Media PRODUCT_COPY_FILES += \