From: Jan Altensen Date: Fri, 7 May 2021 18:29:10 +0000 (+0200) Subject: exynos9610: add livedisplay implementation X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=104e2518519579174b0eab4f6cedf274dd655492;p=GitHub%2FLineageOS%2Fandroid_device_motorola_exynos9610-common.git exynos9610: add livedisplay implementation Change-Id: Ia8ef756e0211691d5eeac6c7347930effb5d1eb3 --- diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk index 8fd0c0d..6c74301 100644 --- a/BoardConfigCommon.mk +++ b/BoardConfigCommon.mk @@ -135,6 +135,8 @@ BOARD_VNDK_VERSION := current USE_XML_AUDIO_POLICY_CONF := 1 # sepolicy +include device/lineage/sepolicy/exynos/sepolicy.mk + BOARD_SEPOLICY_TEE_FLAVOR := mobicore include device/samsung_slsi/sepolicy/sepolicy.mk diff --git a/common.mk b/common.mk index 744df38..2b15a72 100644 --- a/common.mk +++ b/common.mk @@ -180,6 +180,10 @@ PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \ android.hardware.light@2.0-service.samsung +# Livedisplay +PRODUCT_PACKAGES += \ + vendor.lineage.livedisplay@2.0-service.exynos9610 + # MotoActions PRODUCT_PACKAGES += \ MotoActions diff --git a/hidl/livedisplay/AdaptiveBacklight.cpp b/hidl/livedisplay/AdaptiveBacklight.cpp new file mode 100644 index 0000000..8e98e30 --- /dev/null +++ b/hidl/livedisplay/AdaptiveBacklight.cpp @@ -0,0 +1,55 @@ +/* + * 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. + */ + +#include +#include + +#include + +#include "AdaptiveBacklight.h" + +using android::base::ReadFileToString; +using android::base::Trim; +using android::base::WriteStringToFile; + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_0 { +namespace implementation { + +static constexpr const char* kCABCPath = "/sys/class/panel/panel/cabc_mode"; + +Return AdaptiveBacklight::isEnabled() { + std::string tmp; + std::string contents = 0; + + if (ReadFileToString(kCABCPath, &tmp)) { + contents = Trim(tmp); + } + + return !contents.compare("cabc_mode = 3, ret = 0"); +} + +Return AdaptiveBacklight::setEnabled(bool enabled) { + return WriteStringToFile(enabled ? "3" : "0", kCABCPath, true); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/hidl/livedisplay/AdaptiveBacklight.h b/hidl/livedisplay/AdaptiveBacklight.h new file mode 100644 index 0000000..6c07dd8 --- /dev/null +++ b/hidl/livedisplay/AdaptiveBacklight.h @@ -0,0 +1,50 @@ +/* + * 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_0_ADAPTIVEBACKLIGHT_H +#define VENDOR_LINEAGE_LIVEDISPLAY_V2_0_ADAPTIVEBACKLIGHT_H + +#include +#include +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +class AdaptiveBacklight : public IAdaptiveBacklight { + public: + 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_ADAPTIVEBACKLIGHT_H diff --git a/hidl/livedisplay/Android.bp b/hidl/livedisplay/Android.bp new file mode 100644 index 0000000..6ca4226 --- /dev/null +++ b/hidl/livedisplay/Android.bp @@ -0,0 +1,37 @@ +// 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. + +cc_binary { + name: "vendor.lineage.livedisplay@2.0-service.exynos9610", + init_rc: ["vendor.lineage.livedisplay@2.0-service.exynos9610.rc"], + vintf_fragments: ["vendor.lineage.livedisplay@2.0-service.exynos9610.xml"], + defaults: ["hidl_defaults"], + relative_install_path: "hw", + vendor: true, + srcs: [ + "AdaptiveBacklight.cpp", + "DisplayModes.cpp", + "SunlightEnhancement.cpp", + "service.cpp", + ], + shared_libs: [ + "libbase", + "libbinder", + "libdl", + "libcutils", + "libhidlbase", + "libutils", + "vendor.lineage.livedisplay@2.0", + ], +} diff --git a/hidl/livedisplay/DisplayModes.cpp b/hidl/livedisplay/DisplayModes.cpp new file mode 100644 index 0000000..bafb21c --- /dev/null +++ b/hidl/livedisplay/DisplayModes.cpp @@ -0,0 +1,232 @@ +/* + * 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 "DisplayModesService" + +#include "DisplayModes.h" + +#include +#include +#include +#include +#include + +using ::android::base::ReadFileToString; +using ::android::base::StringPrintf; +using ::android::base::Trim; +using ::android::hardware::Void; + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_0 { +namespace implementation { + +static constexpr const char* kDefaultPath = "/data/vendor/display/.displaymodedefault"; + +#define COLOR_MODE_SYSFS_PATH "/sys/class/dqe/dqe/aosp_colors" +#define PANEL_SUPPLIER_SYSFS_PATH "/sys/class/panel/panel/panel_supplier" +#define TUNE_MODE1_SYSFS_PATH "/sys/class/dqe/dqe/tune_mode1" +#define TUNE_MODE2_SYSFS_PATH "/sys/class/dqe/dqe/tune_mode2" +#define TUNE_ONOFF_SYSFS_PATH "/sys/class/dqe/dqe/tune_onoff" + +const std::map DisplayModes::kModeMap = { + // clang-format off + {0, "Natural"}, + {1, "Boosted"}, + {2, "Saturated"}, +/* + {90, "mode0 (bypass)"}, // seems to be default/off (visually the same as Saturated) + {91, "mode1 (sRGB)"}, // same as Natural + {92, "mode2 (Native)"}, // same as Boosted + {93, "onoff (DCI-P3)"}, // same as Saturated +*/ + // clang-format on +}; + +// clang-format off +const std::map>> DisplayModes::kDataMap = { + { + "hix83112a", { // from /vendor/etc/dqe/hixmax-hix83112a.xml + { + "mode1", { + { "cgc", "255,58,33,117,255,76,0,20,255,104,255,243,255,61,231,255,244,72,255,255,255,0,0,0,0,0,255,58,33,117,255,76,0,20,255,104,255,243,255,61,231,255,244,72,255,255,255,0,0,0" }, + { "gamma", "0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254" }, + { "hsc", "1,32,0,-20,-12,0,0,1,15,1,0,1,0,0,0,0,0,0,0,5,-10,0,10,30,170,230,240,155,70,32,0,10,64,51,204" } + } + }, + { + "mode2", { + { "cgc", "255,20,0,0,255,20,0,20,255,0,255,223,255,20,222,251,255,0,255,255,255,0,0,0,0,0,255,20,0,0,255,20,0,20,255,0,255,223,255,20,222,251,255,0,255,255,255,0,0,0" }, + { "gamma", "0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254" }, + { "hsc", "1,56,0,0,0,0,0,1,15,1,-52,1,0,0,0,0,0,0,0,5,-10,0,10,30,170,230,240,155,70,32,0,10,64,51,204" } + } + }, + { + "onoff", { + { "cgc", "255,0,0,0,255,0,0,0,255,0,255,254,255,20,245,252,255,0,255,255,255,0,0,0,0,0,255,0,0,0,255,0,0,0,255,0,255,254,255,20,245,252,255,0,255,255,255,0,0,0" }, + { "gamma", "0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254" }, + { "hsc", "1,0,0,0,0,0,0,1,15,1,0,1,0,0,0,0,0,0,0,5,-10,0,10,30,170,230,240,155,70,32,0,10,64,51,204" } + }, + }, + } + }, + { + "nov36672a", { // from /vendor/etc/dqe/novatek-nov36672a.xml + { + "mode1", { + { "cgc", "255,61,33,119,255,74,0,28,255,104,255,239,255,65,228,255,244,72,254,255,253,0,0,0,0,0,255,61,33,119,255,74,0,28,255,104,255,239,255,65,228,255,244,72,254,255,253,0,0,0" }, + { "gamma", "0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254" }, + { "hsc", "1,54,0,0,0,0,0,1,15,1,0,1,0,0,0,0,0,0,0,5,-10,0,10,30,170,230,240,155,70,32,0,10,64,51,204" } + } + }, + { + "mode2", { + { "cgc", "255,0,0,0,255,0,0,0,255,0,255,254,255,20,245,252,255,0,255,255,255,0,0,0,0,0,255,0,0,0,255,0,0,0,255,0,255,254,255,20,245,252,255,0,255,255,255,0,0,0" }, + { "gamma", "0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254" }, + { "hsc", "1,26,0,0,0,0,0,1,15,1,-43,1,1,0,0,0,0,0,-12,5,-10,0,10,30,170,230,240,155,70,32,0,10,64,51,204" } + } + }, + { + "onoff", { + { "cgc", "255,0,0,0,255,0,0,0,255,0,255,254,255,20,245,252,255,0,255,255,255,0,0,0,0,0,255,0,0,0,255,0,0,0,255,0,255,254,255,20,245,252,255,0,255,255,255,0,0,0" }, + { "gamma", "0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254,0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,254" }, + { "hsc", "1,56,0,56,0,0,0,1,15,1,29,1,1,0,-12,0,0,0,-11,5,-10,0,10,30,170,230,240,155,70,32,0,10,64,51,204" } + }, + }, + } + } +}; +// clang-format on + +/* + * Write value to path and close file. + */ +template +static void set(const std::string& path, const T& value) { + std::ofstream file(path); + file << value << std::endl; +} + +template +static T get(const std::string& path, const T& def) { + std::ifstream file(path); + T result; + + file >> result; + return file.fail() ? def : result; +} + +DisplayModes::DisplayModes() : mCurrentModeId(0), mDefaultModeId(0) { + initialize(); + std::ifstream defaultFile(kDefaultPath); + int value; + + defaultFile >> value; + LOG(DEBUG) << "Default file read result " << value << " fail " << defaultFile.fail(); + if (defaultFile.fail()) { + return; + } + + for (const auto& entry : kModeMap) { + if (value == entry.first) { + mDefaultModeId = entry.first; + break; + } + } + + setDisplayMode(mDefaultModeId, false); +} + +// Methods from ::vendor::lineage::livedisplay::V2_0::IDisplayModes follow. +Return DisplayModes::getDisplayModes(getDisplayModes_cb resultCb) { + std::vector modes; + + for (const auto& entry : kModeMap) { + if (entry.first < 3) modes.push_back({entry.first, entry.second}); + } + + resultCb(modes); + return Void(); +} + +Return DisplayModes::getCurrentDisplayMode(getCurrentDisplayMode_cb resultCb) { + // decon_dqe_aosp_color_show always returns 0 so we have to keep track ourselves + + resultCb({mCurrentModeId, kModeMap.at(mCurrentModeId)}); + + return Void(); +} + +Return DisplayModes::getDefaultDisplayMode(getDefaultDisplayMode_cb resultCb) { + resultCb({mDefaultModeId, kModeMap.at(mDefaultModeId)}); + return Void(); +} + +Return DisplayModes::setDisplayMode(int32_t modeID, bool makeDefault) { + const auto iter = kModeMap.find(modeID); + if (iter == kModeMap.end()) { + return false; + } + std::ofstream modeFile(COLOR_MODE_SYSFS_PATH); + modeFile << iter->first; + if (modeFile.fail()) { + return false; + } + + if (makeDefault) { + std::ofstream defaultFile(kDefaultPath); + defaultFile << iter->first; + if (defaultFile.fail()) { + return false; + } + mDefaultModeId = iter->first; + } + + mCurrentModeId = iter->first; + + return true; +} + +void DisplayModes::initialize() { + std::string panel = get(PANEL_SUPPLIER_SYSFS_PATH, std::string("")); + + if (panel.empty()) + return; + + for (const auto& entry : kDataMap) { + if (!panel.compare(std::string(entry.first))) { + auto data = entry.second; + auto mode1 = data["mode1"]; + set(TUNE_MODE1_SYSFS_PATH, StringPrintf("%s,%s,%s,", mode1["cgc"].c_str(), mode1["gamma"].c_str(), mode1["hsc"].c_str())); + + auto mode2 = data["mode2"]; + set(TUNE_MODE2_SYSFS_PATH, StringPrintf("%s,%s,%s,", mode2["cgc"].c_str(), mode2["gamma"].c_str(), mode2["hsc"].c_str())); + + auto onoff = data["onoff"]; + set(TUNE_ONOFF_SYSFS_PATH, StringPrintf("%s,%s,%s,", onoff["cgc"].c_str(), onoff["gamma"].c_str(), onoff["hsc"].c_str())); + break; + } + } +} + +// Methods from ::android::hidl::base::V1_0::IBase follow. + +} // namespace implementation +} // namespace V2_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/hidl/livedisplay/DisplayModes.h b/hidl/livedisplay/DisplayModes.h new file mode 100644 index 0000000..1aaaa4f --- /dev/null +++ b/hidl/livedisplay/DisplayModes.h @@ -0,0 +1,64 @@ +/* + * 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_0_DISPLAYMODES_H +#define VENDOR_LINEAGE_LIVEDISPLAY_V2_0_DISPLAYMODES_H + +#include +#include +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +class DisplayModes : public IDisplayModes { + public: + DisplayModes(); + + // Methods from ::vendor::lineage::livedisplay::V2_0::IDisplayModes follow. + Return getDisplayModes(getDisplayModes_cb resultCb) override; + Return getCurrentDisplayMode(getCurrentDisplayMode_cb resultCb) override; + Return getDefaultDisplayMode(getDefaultDisplayMode_cb resultCb) override; + Return setDisplayMode(int32_t modeID, bool makeDefault) override; + + // Methods from ::android::hidl::base::V1_0::IBase follow. + private: + void initialize(); + + static const std::map kModeMap; + static const std::map>> kDataMap; + int32_t mCurrentModeId; + int32_t mDefaultModeId; +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor + +#endif // VENDOR_LINEAGE_LIVEDISPLAY_V2_0_DISPLAYMODES_H diff --git a/hidl/livedisplay/SunlightEnhancement.cpp b/hidl/livedisplay/SunlightEnhancement.cpp new file mode 100644 index 0000000..34d278a --- /dev/null +++ b/hidl/livedisplay/SunlightEnhancement.cpp @@ -0,0 +1,55 @@ +/* + * 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. + */ + +#include +#include + +#include + +#include "SunlightEnhancement.h" + +using android::base::ReadFileToString; +using android::base::Trim; +using android::base::WriteStringToFile; + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_0 { +namespace implementation { + +static constexpr const char* kHBMPath = "/sys/class/backlight/hbm/hbm_mode"; + +Return SunlightEnhancement::isEnabled() { + std::string tmp; + int32_t contents = 0; + + if (ReadFileToString(kHBMPath, &tmp)) { + contents = std::stoi(Trim(tmp)); + } + + return contents > 0; +} + +Return SunlightEnhancement::setEnabled(bool enabled) { + return WriteStringToFile(enabled ? "1" : "0", kHBMPath, true); +} + +} // namespace implementation +} // namespace V2_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/hidl/livedisplay/SunlightEnhancement.h b/hidl/livedisplay/SunlightEnhancement.h new file mode 100644 index 0000000..5651562 --- /dev/null +++ b/hidl/livedisplay/SunlightEnhancement.h @@ -0,0 +1,50 @@ +/* + * 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_0_SUNLIGHTENHANCEMENT_H +#define VENDOR_LINEAGE_LIVEDISPLAY_V2_0_SUNLIGHTENHANCEMENT_H + +#include +#include +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_0 { +namespace implementation { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +class SunlightEnhancement : public ISunlightEnhancement { + public: + 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_SUNLIGHTENHANCEMENT_H diff --git a/hidl/livedisplay/service.cpp b/hidl/livedisplay/service.cpp new file mode 100644 index 0000000..0096f9c --- /dev/null +++ b/hidl/livedisplay/service.cpp @@ -0,0 +1,99 @@ +/* + * 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 "vendor.lineage.livedisplay@2.0-service.exynos9610" + +#include +#include +#include + +#include "AdaptiveBacklight.h" +#include "DisplayModes.h" +#include "SunlightEnhancement.h" + +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; +using android::OK; +using android::sp; +using android::status_t; + +using vendor::lineage::livedisplay::V2_0::IAdaptiveBacklight; +using vendor::lineage::livedisplay::V2_0::IDisplayModes; +using vendor::lineage::livedisplay::V2_0::implementation::AdaptiveBacklight; +using vendor::lineage::livedisplay::V2_0::implementation::DisplayModes; +using vendor::lineage::livedisplay::V2_0::implementation::SunlightEnhancement; +using vendor::lineage::livedisplay::V2_0::ISunlightEnhancement; + +int main() { + sp adaptiveBacklight; + sp displayModes; + sp sunlightEnhancement; + status_t status; + + LOG(INFO) << "LiveDisplay HAL service is starting."; + + adaptiveBacklight = new AdaptiveBacklight(); + if (adaptiveBacklight == nullptr) { + LOG(ERROR) + << "Can not create an instance of LiveDisplay HAL AdaptiveBacklight Iface, exiting."; + goto shutdown; + } + + displayModes = new DisplayModes(); + if (displayModes == nullptr) { + LOG(ERROR) << "Can not create an instance of LiveDisplay HAL DisplayModes Iface, exiting."; + goto shutdown; + } + + sunlightEnhancement = new SunlightEnhancement(); + if (sunlightEnhancement == nullptr) { + LOG(ERROR) + << "Can not create an instance of LiveDisplay HAL SunlightEnhancement Iface, exiting."; + goto shutdown; + } + + configureRpcThreadpool(1, true /*callerWillJoin*/); + + status = adaptiveBacklight->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Could not register service for LiveDisplay HAL AdaptiveBacklight Iface (" + << status << ")"; + goto shutdown; + } + + status = displayModes->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Could not register service for LiveDisplay HAL DisplayModes Iface (" + << status << ")"; + goto shutdown; + } + + status = sunlightEnhancement->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Could not register service for LiveDisplay HAL SunlightEnhancement Iface (" + << status << ")"; + goto shutdown; + } + + LOG(INFO) << "LiveDisplay HAL service is ready."; + joinRpcThreadpool(); + // Should not pass this line + +shutdown: + // 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/hidl/livedisplay/vendor.lineage.livedisplay@2.0-service.exynos9610.rc b/hidl/livedisplay/vendor.lineage.livedisplay@2.0-service.exynos9610.rc new file mode 100644 index 0000000..0940e49 --- /dev/null +++ b/hidl/livedisplay/vendor.lineage.livedisplay@2.0-service.exynos9610.rc @@ -0,0 +1,7 @@ +on post-fs-data + mkdir /data/vendor/display 0770 system system + +service vendor.livedisplay-hal-2-0-exynos9610 /vendor/bin/hw/vendor.lineage.livedisplay@2.0-service.exynos9610 + class hal + user system + group system \ No newline at end of file diff --git a/hidl/livedisplay/vendor.lineage.livedisplay@2.0-service.exynos9610.xml b/hidl/livedisplay/vendor.lineage.livedisplay@2.0-service.exynos9610.xml new file mode 100644 index 0000000..83bfb68 --- /dev/null +++ b/hidl/livedisplay/vendor.lineage.livedisplay@2.0-service.exynos9610.xml @@ -0,0 +1,19 @@ + + + vendor.lineage.livedisplay + hwbinder + 2.0 + + IAdaptiveBacklight + default + + + IDisplayModes + default + + + ISunlightEnhancement + default + + + diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml index 4bd806d..e204f62 100644 --- a/overlay/frameworks/base/core/res/res/values/config.xml +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -204,7 +204,7 @@ true true - true + true true true true diff --git a/sepolicy/vendor/exynos-thermald.te b/sepolicy/vendor/exynos-thermald.te index de389fc..d5631c4 100644 --- a/sepolicy/vendor/exynos-thermald.te +++ b/sepolicy/vendor/exynos-thermald.te @@ -3,6 +3,7 @@ type exynos-thermald_exec, exec_type, file_type, vendor_file_type; init_daemon_domain(exynos-thermald) r_dir_file(exynos-thermald, sysfs_battery) +r_dir_file(exynos-thermald, sysfs_panel) r_dir_file(exynos-thermald, sysfs_thermal) allow exynos-thermald { diff --git a/sepolicy/vendor/file.te b/sepolicy/vendor/file.te index 1cad0b7..1c361b5 100644 --- a/sepolicy/vendor/file.te +++ b/sepolicy/vendor/file.te @@ -1,6 +1,7 @@ # data types type camera_vendor_data_file, file_type, data_file_type; type chargeonly_data_file, file_type, data_file_type; +type display_vendor_data_file, file_type, data_file_type; type mediadrm_vendor_data_file, file_type, data_file_type; type misc_vendor_data_file, file_type, data_file_type; type mobicore_data_registry_file, file_type, data_file_type; @@ -36,9 +37,12 @@ type sysfs_chipid, sysfs_type, r_fs_type, fs_type; type sysfs_cpuhotplug_writable, sysfs_type, rw_fs_type, fs_type; type sysfs_decon, sysfs_type, r_fs_type, fs_type; type sysfs_decon_writable, sysfs_type, rw_fs_type, fs_type; +type sysfs_dqe, sysfs_type, rw_fs_type, fs_type; type sysfs_fimc_writable, sysfs_type, rw_fs_type, fs_type; +type sysfs_hbm, sysfs_type, rw_fs_type, fs_type; type sysfs_mali_writable, sysfs_type, rw_fs_type, fs_type; type sysfs_nanohub, sysfs_type, r_fs_type, fs_type; +type sysfs_panel, sysfs_type, rw_fs_type, fs_type; type sysfs_rbs, fs_type, sysfs_type; type sysfs_scheduler, fs_type, sysfs_type; type sysfs_socinfo, fs_type, sysfs_type; diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts index 3d822c5..dba60f6 100644 --- a/sepolicy/vendor/file_contexts +++ b/sepolicy/vendor/file_contexts @@ -14,6 +14,7 @@ # Data Files /data/vendor/camera(/.*)? u:object_r:camera_vendor_data_file:s0 +/data/vendor/display(/.*)? u:object_r:display_vendor_data_file:s0 /data/vendor/mediadrm(/.*)? u:object_r:mediadrm_vendor_data_file:s0 /data/vendor/misc(/.*)? u:object_r:misc_vendor_data_file:s0 /data/vendor/sensor(/.*)? u:object_r:sensor_vendor_data_file:s0 @@ -90,6 +91,7 @@ /(vendor|system/vendor)/bin/hw/android.hardware.nfc@1.2-service.samsung u:object_r:hal_nfc_default_exec:s0 /(vendor|system/vendor)/bin/hw/android.hardware.secure_element@1.1-service-uicc u:object_r:hal_secure_element_default_exec:s0 /(vendor|system/vendor)/bin/hw/android.hardware.vibrator@1.0-service.exynos9610 u:object_r:hal_vibrator_default_exec:s0 +/(vendor|system/vendor)/bin/hw/vendor.lineage.livedisplay@2.0-service.exynos9610 u:object_r:hal_lineage_livedisplay_exynos_exec:s0 /(vendor|system/vendor)/bin/hw/vendor.samsung.hardware.gnss@1.0-service u:object_r:hal_gnss_default_exec:s0 #################################### diff --git a/sepolicy/vendor/genfs_contexts b/sepolicy/vendor/genfs_contexts index 31337d1..b47d62d 100644 --- a/sepolicy/vendor/genfs_contexts +++ b/sepolicy/vendor/genfs_contexts @@ -55,8 +55,10 @@ genfscon sysfs /devices/platform/13840000.i2c/i2c-9/9-003d/s2mu00x-battery/power genfscon sysfs /devices/platform/13840000.i2c/i2c-9/9-003d/s2mu106-charger/power_supply u:object_r:sysfs_battery:s0 genfscon sysfs /devices/platform/13840000.i2c/i2c-9/9-003d/s2mu106-powermeter/power_supply/s2mu106_pmeter/type u:object_r:sysfs_battery:s0 genfscon sysfs /devices/platform/14490000.fimc_is/debug/fixed_sensor_fps u:object_r:sysfs_fimc_writable:s0 +genfscon sysfs /devices/platform/148b0000.decon_f/dqe/dqe u:object_r:sysfs_dqe:s0 genfscon sysfs /devices/platform/148b0000.decon_f/psr_info u:object_r:sysfs_decon:s0 genfscon sysfs /devices/platform/148b0000.decon_f/vsync u:object_r:sysfs_decon_writable:s0 +genfscon sysfs /devices/platform/148e0000.dsim/panel/panel u:object_r:sysfs_panel:s0 genfscon sysfs /devices/platform/148e0000.dsim/panel/panel/max_brightness u:object_r:sysfs_backlight_writable:s0 genfscon sysfs /devices/platform/14a50000.abox/service u:object_r:sysfs_abox_writable:s0 genfscon sysfs /devices/platform/egis_input/navigation_event u:object_r:sysfs_rbs:s0 @@ -65,6 +67,7 @@ genfscon sysfs /devices/soc0/revision genfscon sysfs /devices/system/chip-id/revision u:object_r:sysfs_chipid:s0 genfscon sysfs /devices/virtual/backlight/backlight_0/brightness u:object_r:sysfs_backlight_writable:s0 genfscon sysfs /devices/virtual/backlight/backlight_0/max_brightness u:object_r:sysfs_backlight_writable:s0 +genfscon sysfs /devices/virtual/backlight/hbm u:object_r:sysfs_hbm:s0 genfscon sysfs /devices/virtual/nanohub/nanohub/sensortype u:object_r:sysfs_nanohub:s0 genfscon sysfs /module/scsc_bt/parameters/bluetooth_address u:object_r:sysfs_bt_writable:s0 genfscon sysfs /power/cpuhp/set_online_cpu u:object_r:sysfs_cpuhotplug_writable:s0 diff --git a/sepolicy/vendor/hal_lineage_livedisplay_exynos.te b/sepolicy/vendor/hal_lineage_livedisplay_exynos.te new file mode 100644 index 0000000..7a1d25b --- /dev/null +++ b/sepolicy/vendor/hal_lineage_livedisplay_exynos.te @@ -0,0 +1,12 @@ +allow hal_lineage_livedisplay_exynos { + sysfs_panel + sysfs_dqe + sysfs_hbm +}:dir search; + +allow hal_lineage_livedisplay_exynos { + sysfs_panel + sysfs_dqe + sysfs_hbm +}:file rw_file_perms; +