mirror of
				https://github.com/oplus-giulia-dev/android_hardware_oplus
				synced 2025-11-04 05:45:34 +08:00 
			
		
		
		
	livedisplay: Add IAdaptiveBacklight support
Change-Id: Id11b96f58efb494b05e089d9954139d0c01366be
This commit is contained in:
		@@ -4,6 +4,7 @@
 | 
			
		||||
 | 
			
		||||
| Namespace | Variable | Description | Default |
 | 
			
		||||
| --------- | -------- | ----------- | ------- |
 | 
			
		||||
| OPLUS_LINEAGE_LIVEDISPLAY_HAL | ENABLE_AB | Enable AdaptiveBacklight feature | false |
 | 
			
		||||
| OPLUS_LINEAGE_LIVEDISPLAY_HAL | ENABLE_AF | Enable AntiFlicker feature | false |
 | 
			
		||||
| OPLUS_LINEAGE_LIVEDISPLAY_HAL | ENABLE_DM | Enable DisplayModes feature | false |
 | 
			
		||||
| OPLUS_LINEAGE_LIVEDISPLAY_HAL | ENABLE_PA | Enable PictureAdjustment feature | true |
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										46
									
								
								aidl/livedisplay/AdaptiveBacklight.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								aidl/livedisplay/AdaptiveBacklight.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
			
		||||
/*
 | 
			
		||||
 * SPDX-FileCopyrightText: 2025 The LineageOS Project
 | 
			
		||||
 * SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#define LOG_TAG "AdaptiveBacklightService"
 | 
			
		||||
 | 
			
		||||
#include <android-base/logging.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <livedisplay/oplus/AdaptiveBacklight.h>
 | 
			
		||||
#include <oplus/oplus_display_panel.h>
 | 
			
		||||
 | 
			
		||||
namespace aidl {
 | 
			
		||||
namespace vendor {
 | 
			
		||||
namespace lineage {
 | 
			
		||||
namespace livedisplay {
 | 
			
		||||
 | 
			
		||||
AdaptiveBacklight::AdaptiveBacklight() : mOplusDisplayFd(open("/dev/oplus_display", O_RDWR)) {}
 | 
			
		||||
 | 
			
		||||
ndk::ScopedAStatus AdaptiveBacklight::getEnabled(bool* _aidl_return) {
 | 
			
		||||
    unsigned int value;
 | 
			
		||||
    if (ioctl(mOplusDisplayFd, PANEL_IOCTL_GET_CABC_STATUS, &value) != 0) {
 | 
			
		||||
        LOG(ERROR) << "Failed to read current AdaptiveBacklight state";
 | 
			
		||||
        return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
 | 
			
		||||
    }
 | 
			
		||||
    *_aidl_return = value > 0;
 | 
			
		||||
    return ndk::ScopedAStatus::ok();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ndk::ScopedAStatus AdaptiveBacklight::setEnabled(bool enabled) {
 | 
			
		||||
    bool isEnabled;
 | 
			
		||||
    if (auto status = getEnabled(&isEnabled); !status.isOk()) {
 | 
			
		||||
        return status;
 | 
			
		||||
    }
 | 
			
		||||
    unsigned int value = enabled;
 | 
			
		||||
    if (isEnabled != enabled && ioctl(mOplusDisplayFd, PANEL_IOCTL_SET_CABC_STATUS, &value) != 0) {
 | 
			
		||||
        LOG(ERROR) << "Failed to set AdaptiveBacklight state";
 | 
			
		||||
        return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
 | 
			
		||||
    }
 | 
			
		||||
    return ndk::ScopedAStatus::ok();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}  // namespace livedisplay
 | 
			
		||||
}  // namespace lineage
 | 
			
		||||
}  // namespace vendor
 | 
			
		||||
}  // namespace aidl
 | 
			
		||||
@@ -3,6 +3,11 @@
 | 
			
		||||
// SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
filegroup {
 | 
			
		||||
    name: "vendor.lineage.livedisplay-oplus-ab",
 | 
			
		||||
    srcs: ["AdaptiveBacklight.cpp"],
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
filegroup {
 | 
			
		||||
    name: "vendor.lineage.livedisplay-oplus-af",
 | 
			
		||||
    srcs: ["AntiFlicker.cpp"],
 | 
			
		||||
@@ -27,7 +32,10 @@ cc_library_headers {
 | 
			
		||||
cc_binary {
 | 
			
		||||
    name: "vendor.lineage.livedisplay-service.oplus",
 | 
			
		||||
    init_rc: ["vendor.lineage.livedisplay-service.oplus.rc"],
 | 
			
		||||
    vintf_fragments: select(soong_config_variable("OPLUS_LINEAGE_LIVEDISPLAY_HAL", "ENABLE_AF"), {
 | 
			
		||||
    vintf_fragments: select(soong_config_variable("OPLUS_LINEAGE_LIVEDISPLAY_HAL", "ENABLE_AB"), {
 | 
			
		||||
        "true": ["vendor.lineage.livedisplay-service.oplus-ab.xml"],
 | 
			
		||||
        default: [],
 | 
			
		||||
    }) + select(soong_config_variable("OPLUS_LINEAGE_LIVEDISPLAY_HAL", "ENABLE_AF"), {
 | 
			
		||||
        "true": ["vendor.lineage.livedisplay-service.oplus-af.xml"],
 | 
			
		||||
        default: [],
 | 
			
		||||
    }) + select(soong_config_variable("OPLUS_LINEAGE_LIVEDISPLAY_HAL", "ENABLE_DM"), {
 | 
			
		||||
@@ -44,6 +52,7 @@ cc_binary {
 | 
			
		||||
    srcs: [
 | 
			
		||||
        ":vendor.lineage.livedisplay-sdm-pa",
 | 
			
		||||
        ":vendor.lineage.livedisplay-sdm-utils",
 | 
			
		||||
        ":vendor.lineage.livedisplay-oplus-ab",
 | 
			
		||||
        ":vendor.lineage.livedisplay-oplus-af",
 | 
			
		||||
        ":vendor.lineage.livedisplay-oplus-dm",
 | 
			
		||||
        ":vendor.lineage.livedisplay-oplus-se",
 | 
			
		||||
@@ -61,7 +70,10 @@ cc_binary {
 | 
			
		||||
        "vendor.lineage.livedisplay-sdm-headers",
 | 
			
		||||
        "vendor.lineage.livedisplay-oplus-headers",
 | 
			
		||||
    ],
 | 
			
		||||
    cflags: select(soong_config_variable("OPLUS_LINEAGE_LIVEDISPLAY_HAL", "ENABLE_AF"), {
 | 
			
		||||
    cflags: select(soong_config_variable("OPLUS_LINEAGE_LIVEDISPLAY_HAL", "ENABLE_AB"), {
 | 
			
		||||
        "true": ["-DENABLE_AB=true"],
 | 
			
		||||
        default: ["-DENABLE_AB=false"],
 | 
			
		||||
    }) + select(soong_config_variable("OPLUS_LINEAGE_LIVEDISPLAY_HAL", "ENABLE_AF"), {
 | 
			
		||||
        "true": ["-DENABLE_AF=true"],
 | 
			
		||||
        default: ["-DENABLE_AF=false"],
 | 
			
		||||
    }) + select(soong_config_variable("OPLUS_LINEAGE_LIVEDISPLAY_HAL", "ENABLE_DM"), {
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,30 @@
 | 
			
		||||
/*
 | 
			
		||||
 * SPDX-FileCopyrightText: 2025 The LineageOS Project
 | 
			
		||||
 * SPDX-License-Identifier: Apache-2.0
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <aidl/vendor/lineage/livedisplay/BnAdaptiveBacklight.h>
 | 
			
		||||
 | 
			
		||||
namespace aidl {
 | 
			
		||||
namespace vendor {
 | 
			
		||||
namespace lineage {
 | 
			
		||||
namespace livedisplay {
 | 
			
		||||
 | 
			
		||||
class AdaptiveBacklight : public BnAdaptiveBacklight {
 | 
			
		||||
  public:
 | 
			
		||||
    AdaptiveBacklight();
 | 
			
		||||
 | 
			
		||||
    // Methods from ::aidl::vendor::lineage::livedisplay::BnAdaptiveBacklight follow.
 | 
			
		||||
    ndk::ScopedAStatus getEnabled(bool* _aidl_return) override;
 | 
			
		||||
    ndk::ScopedAStatus setEnabled(bool enabled) override;
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    int mOplusDisplayFd;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
}  // namespace livedisplay
 | 
			
		||||
}  // namespace lineage
 | 
			
		||||
}  // namespace vendor
 | 
			
		||||
}  // namespace aidl
 | 
			
		||||
@@ -9,11 +9,13 @@
 | 
			
		||||
#include <android/binder_manager.h>
 | 
			
		||||
#include <android/binder_process.h>
 | 
			
		||||
#include <binder/ProcessState.h>
 | 
			
		||||
#include <livedisplay/oplus/AdaptiveBacklight.h>
 | 
			
		||||
#include <livedisplay/oplus/AntiFlicker.h>
 | 
			
		||||
#include <livedisplay/oplus/DisplayModes.h>
 | 
			
		||||
#include <livedisplay/oplus/SunlightEnhancement.h>
 | 
			
		||||
#include <livedisplay/sdm/PictureAdjustment.h>
 | 
			
		||||
 | 
			
		||||
using ::aidl::vendor::lineage::livedisplay::AdaptiveBacklight;
 | 
			
		||||
using ::aidl::vendor::lineage::livedisplay::AntiFlicker;
 | 
			
		||||
using ::aidl::vendor::lineage::livedisplay::DisplayModes;
 | 
			
		||||
using ::aidl::vendor::lineage::livedisplay::SunlightEnhancement;
 | 
			
		||||
@@ -29,6 +31,8 @@ int main() {
 | 
			
		||||
    std::shared_ptr<SDMController> controller =
 | 
			
		||||
            ENABLE_DM || ENABLE_PA ? std::make_shared<SDMController>() : nullptr;
 | 
			
		||||
 | 
			
		||||
    std::shared_ptr<AdaptiveBacklight> ab =
 | 
			
		||||
            ENABLE_AB ? ndk::SharedRefBase::make<AdaptiveBacklight>() : nullptr;
 | 
			
		||||
    std::shared_ptr<AntiFlicker> af = ENABLE_AF ? ndk::SharedRefBase::make<AntiFlicker>() : nullptr;
 | 
			
		||||
    std::shared_ptr<DisplayModes> dm =
 | 
			
		||||
            ENABLE_DM ? ndk::SharedRefBase::make<DisplayModes>(controller) : nullptr;
 | 
			
		||||
@@ -37,6 +41,12 @@ int main() {
 | 
			
		||||
    std::shared_ptr<SunlightEnhancement> se =
 | 
			
		||||
            ENABLE_SE ? ndk::SharedRefBase::make<SunlightEnhancement>() : nullptr;
 | 
			
		||||
 | 
			
		||||
    if (ab) {
 | 
			
		||||
        std::string instance = std::string() + AdaptiveBacklight::descriptor + "/default";
 | 
			
		||||
        binder_status_t status = AServiceManager_addService(ab->asBinder().get(), instance.c_str());
 | 
			
		||||
        CHECK_EQ(status, STATUS_OK);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (af) {
 | 
			
		||||
        std::string instance = std::string() + AntiFlicker::descriptor + "/default";
 | 
			
		||||
        binder_status_t status = AServiceManager_addService(af->asBinder().get(), instance.c_str());
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,10 @@
 | 
			
		||||
<manifest version="1.0" type="device">
 | 
			
		||||
    <hal format="aidl">
 | 
			
		||||
        <name>vendor.lineage.livedisplay</name>
 | 
			
		||||
        <version>1</version>
 | 
			
		||||
        <interface>
 | 
			
		||||
            <name>IAdaptiveBacklight</name>
 | 
			
		||||
            <instance>default</instance>
 | 
			
		||||
        </interface>
 | 
			
		||||
    </hal>
 | 
			
		||||
</manifest>
 | 
			
		||||
		Reference in New Issue
	
	Block a user