exynos9610: add livedisplay implementation
authorJan Altensen <info@stricted.net>
Fri, 7 May 2021 18:29:10 +0000 (20:29 +0200)
committerJan Altensen <info@stricted.net>
Mon, 10 May 2021 05:03:27 +0000 (07:03 +0200)
Change-Id: Ia8ef756e0211691d5eeac6c7347930effb5d1eb3

18 files changed:
BoardConfigCommon.mk
common.mk
hidl/livedisplay/AdaptiveBacklight.cpp [new file with mode: 0644]
hidl/livedisplay/AdaptiveBacklight.h [new file with mode: 0644]
hidl/livedisplay/Android.bp [new file with mode: 0644]
hidl/livedisplay/DisplayModes.cpp [new file with mode: 0644]
hidl/livedisplay/DisplayModes.h [new file with mode: 0644]
hidl/livedisplay/SunlightEnhancement.cpp [new file with mode: 0644]
hidl/livedisplay/SunlightEnhancement.h [new file with mode: 0644]
hidl/livedisplay/service.cpp [new file with mode: 0644]
hidl/livedisplay/vendor.lineage.livedisplay@2.0-service.exynos9610.rc [new file with mode: 0644]
hidl/livedisplay/vendor.lineage.livedisplay@2.0-service.exynos9610.xml [new file with mode: 0644]
overlay/frameworks/base/core/res/res/values/config.xml
sepolicy/vendor/exynos-thermald.te
sepolicy/vendor/file.te
sepolicy/vendor/file_contexts
sepolicy/vendor/genfs_contexts
sepolicy/vendor/hal_lineage_livedisplay_exynos.te [new file with mode: 0644]

index 8fd0c0d2960c9dc7b99fe3ec335c59ba88ef2f4e..6c74301116408a80e40cf63b2035e51f7a09f278 100644 (file)
@@ -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
 
index 744df38eaa7bf83d0ad9669ed8e3dbc38876d6c5..2b15a722ddf48d19e452704ef3c5a032c3cb0138 100644 (file)
--- 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 (file)
index 0000000..8e98e30
--- /dev/null
@@ -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 <android-base/file.h>
+#include <android-base/strings.h>
+
+#include <fstream>
+
+#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<bool> 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<bool> 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 (file)
index 0000000..6c07dd8
--- /dev/null
@@ -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 <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+#include <vendor/lineage/livedisplay/2.0/IAdaptiveBacklight.h>
+
+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<bool> isEnabled() override;
+    Return<bool> 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 (file)
index 0000000..6ca4226
--- /dev/null
@@ -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 (file)
index 0000000..bafb21c
--- /dev/null
@@ -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 <android-base/file.h>
+#include <android-base/logging.h>
+#include <android-base/stringprintf.h>
+#include <android-base/strings.h>
+#include <fstream>
+
+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<int32_t, std::string> 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<std::string, std::map<std::string, std::map<std::string, std::string>>> 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 <typename T>
+static void set(const std::string& path, const T& value) {
+    std::ofstream file(path);
+    file << value << std::endl;
+}
+
+template <typename T>
+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<void> DisplayModes::getDisplayModes(getDisplayModes_cb resultCb) {
+    std::vector<DisplayMode> modes;
+
+    for (const auto& entry : kModeMap) {
+        if (entry.first < 3) modes.push_back({entry.first, entry.second});
+    }
+
+    resultCb(modes);
+    return Void();
+}
+
+Return<void> 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<void> DisplayModes::getDefaultDisplayMode(getDefaultDisplayMode_cb resultCb) {
+    resultCb({mDefaultModeId, kModeMap.at(mDefaultModeId)});
+    return Void();
+}
+
+Return<bool> 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 (file)
index 0000000..1aaaa4f
--- /dev/null
@@ -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 <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+#include <vendor/lineage/livedisplay/2.0/IDisplayModes.h>
+
+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<void> getDisplayModes(getDisplayModes_cb resultCb) override;
+    Return<void> getCurrentDisplayMode(getCurrentDisplayMode_cb resultCb) override;
+    Return<void> getDefaultDisplayMode(getDefaultDisplayMode_cb resultCb) override;
+    Return<bool> setDisplayMode(int32_t modeID, bool makeDefault) override;
+
+    // Methods from ::android::hidl::base::V1_0::IBase follow.
+  private:
+    void initialize();
+
+    static const std::map<int32_t, std::string> kModeMap;
+    static const std::map<std::string, std::map<std::string, std::map<std::string, std::string>>> 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 (file)
index 0000000..34d278a
--- /dev/null
@@ -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 <android-base/file.h>
+#include <android-base/strings.h>
+
+#include <fstream>
+
+#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<bool> SunlightEnhancement::isEnabled() {
+    std::string tmp;
+    int32_t contents = 0;
+
+    if (ReadFileToString(kHBMPath, &tmp)) {
+        contents = std::stoi(Trim(tmp));
+    }
+
+    return contents > 0;
+}
+
+Return<bool> 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 (file)
index 0000000..5651562
--- /dev/null
@@ -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 <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+#include <vendor/lineage/livedisplay/2.0/ISunlightEnhancement.h>
+
+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<bool> isEnabled() override;
+    Return<bool> 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 (file)
index 0000000..0096f9c
--- /dev/null
@@ -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 <android-base/logging.h>
+#include <binder/ProcessState.h>
+#include <hidl/HidlTransportSupport.h>
+
+#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<IAdaptiveBacklight> adaptiveBacklight;
+    sp<IDisplayModes> displayModes;
+    sp<ISunlightEnhancement> 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 (file)
index 0000000..0940e49
--- /dev/null
@@ -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 (file)
index 0000000..83bfb68
--- /dev/null
@@ -0,0 +1,19 @@
+<manifest version="1.0" type="device">
+    <hal format="hidl" override="true">
+        <name>vendor.lineage.livedisplay</name>
+        <transport>hwbinder</transport>
+        <version>2.0</version>
+        <interface>
+            <name>IAdaptiveBacklight</name>
+            <instance>default</instance>
+        </interface>
+        <interface>
+            <name>IDisplayModes</name>
+            <instance>default</instance>
+        </interface>
+        <interface>
+            <name>ISunlightEnhancement</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+</manifest>
index 4bd806dbd29d3471244e867b7bb4f97b517deabf..e204f629bd99d0436373e674b7dbdd9e4832cee8 100644 (file)
 
     <bool name="config_bluetooth_hfp_inband_ringing_support">true</bool>
     <bool name="config_hotswapCapable">true</bool>
-    <bool name="config_setColorTransformAccelerated">true</bool>
+    <bool name="config_nightDisplayAvailable">true</bool>
     <bool name="config_showNavigationBar">true</bool>
     <bool name="config_supportSystemNavigationKeys">true</bool>
     <bool name="config_unplugTurnsOnScreen">true</bool>
index de389fc1fbec7de0b81e6e357a39b821fd02fc73..d5631c449a097179c61f1a6390faded9ef0eeea8 100644 (file)
@@ -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 {
index 1cad0b70b2c65b07fd50540d64d95a2acb6f7a24..1c361b5a2e3f19e2a76490d03ed6f1ef4cf2461a 100644 (file)
@@ -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;
index 3d822c51525867db8f0381cccd426e02bbfb47e9..dba60f6cc99610565772b4e6d24d82c0b7eed9e4 100644 (file)
@@ -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
 
 ####################################
index 31337d107b2e4b3ce34ebdc5b1027b6f639ef1e6..b47d62db13b9bd90979821ef0b9ebc4ce25275b2 100644 (file)
@@ -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 (file)
index 0000000..7a1d25b
--- /dev/null
@@ -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;
+