livedisplay: Migrate to ioctl()

Change-Id: I2039c94eb3239f2d88ab67076b52f58493d9b43e
This commit is contained in:
LuK1337
2022-07-11 12:08:45 +02:00
committed by jabashque
parent 33b71bd0c3
commit 7b65e6e8d9
7 changed files with 32 additions and 45 deletions

View File

@@ -49,6 +49,7 @@ cc_binary {
"vendor.lineage.livedisplay@2.1", "vendor.lineage.livedisplay@2.1",
], ],
header_libs: [ header_libs: [
"kernel_headers.oplus",
"vendor.lineage.livedisplay@2.0-sdm-headers", "vendor.lineage.livedisplay@2.0-sdm-headers",
"vendor.lineage.livedisplay@2.1-oplus-headers", "vendor.lineage.livedisplay@2.1-oplus-headers",
], ],

View File

@@ -14,21 +14,9 @@
* limitations under the License. * limitations under the License.
*/ */
#define LOG_TAG "AntiFlickerService" #include <fcntl.h>
#include <android-base/file.h>
#include <android-base/strings.h>
#include <livedisplay/oplus/AntiFlicker.h> #include <livedisplay/oplus/AntiFlicker.h>
#include <oplus/oplus_display_panel.h>
using ::android::base::ReadFileToString;
using ::android::base::Trim;
using ::android::base::WriteStringToFile;
namespace {
constexpr const char* kDcDimmingPath = "/sys/kernel/oplus_display/dimlayer_bl_en";
} // anonymous namespace
namespace vendor { namespace vendor {
namespace lineage { namespace lineage {
@@ -36,19 +24,16 @@ namespace livedisplay {
namespace V2_1 { namespace V2_1 {
namespace implementation { namespace implementation {
AntiFlicker::AntiFlicker() : mOplusDisplayFd(open("/dev/oplus_display", O_RDWR)) {}
Return<bool> AntiFlicker::isEnabled() { Return<bool> AntiFlicker::isEnabled() {
std::string tmp; unsigned int value;
int32_t contents = 0; return ioctl(mOplusDisplayFd, PANEL_IOCTL_GET_DIMLAYER_BL_EN, &value) == 0 && value > 0;
if (ReadFileToString(kDcDimmingPath, &tmp)) {
contents = std::stoi(Trim(tmp));
}
return contents > 0;
} }
Return<bool> AntiFlicker::setEnabled(bool enabled) { Return<bool> AntiFlicker::setEnabled(bool enabled) {
return WriteStringToFile(std::to_string(enabled), kDcDimmingPath, true); unsigned int value = enabled;
return ioctl(mOplusDisplayFd, PANEL_IOCTL_SET_DIMLAYER_BL_EN, &value) == 0;
} }
} // namespace implementation } // namespace implementation

View File

@@ -14,19 +14,9 @@
* limitations under the License. * limitations under the License.
*/ */
#include <android-base/file.h> #include <fcntl.h>
#include <android-base/strings.h>
#include <livedisplay/oplus/SunlightEnhancement.h> #include <livedisplay/oplus/SunlightEnhancement.h>
#include <oplus/oplus_display_panel.h>
using ::android::base::ReadFileToString;
using ::android::base::Trim;
using ::android::base::WriteStringToFile;
namespace {
constexpr const char* kHbmPath = "/sys/kernel/oplus_display/hbm";
} // anonymous namespace
namespace vendor { namespace vendor {
namespace lineage { namespace lineage {
@@ -34,19 +24,16 @@ namespace livedisplay {
namespace V2_1 { namespace V2_1 {
namespace implementation { namespace implementation {
SunlightEnhancement::SunlightEnhancement() : mOplusDisplayFd(open("/dev/oplus_display", O_RDWR)) {}
Return<bool> SunlightEnhancement::isEnabled() { Return<bool> SunlightEnhancement::isEnabled() {
std::string tmp; unsigned int value;
int32_t contents = 0; return ioctl(mOplusDisplayFd, PANEL_IOCTL_GET_HBM, &value) == 0 && value > 0;
if (ReadFileToString(kHbmPath, &tmp)) {
contents = std::stoi(Trim(tmp));
}
return contents > 0;
} }
Return<bool> SunlightEnhancement::setEnabled(bool enabled) { Return<bool> SunlightEnhancement::setEnabled(bool enabled) {
return WriteStringToFile(std::to_string(enabled), kHbmPath, true); unsigned int value = enabled;
return ioctl(mOplusDisplayFd, PANEL_IOCTL_SET_HBM, &value) == 0;
} }
} // namespace implementation } // namespace implementation

View File

@@ -32,9 +32,14 @@ using ::android::hardware::Void;
class AntiFlicker : public IAntiFlicker { class AntiFlicker : public IAntiFlicker {
public: public:
AntiFlicker();
// Methods from ::vendor::lineage::livedisplay::V2_1::IAntiFlicker follow. // Methods from ::vendor::lineage::livedisplay::V2_1::IAntiFlicker follow.
Return<bool> isEnabled() override; Return<bool> isEnabled() override;
Return<bool> setEnabled(bool enabled) override; Return<bool> setEnabled(bool enabled) override;
private:
int mOplusDisplayFd;
}; };
} // namespace implementation } // namespace implementation

View File

@@ -32,9 +32,14 @@ using ::android::hardware::Void;
class SunlightEnhancement : public ISunlightEnhancement { class SunlightEnhancement : public ISunlightEnhancement {
public: public:
SunlightEnhancement();
// Methods from ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement follow. // Methods from ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement follow.
Return<bool> isEnabled() override; Return<bool> isEnabled() override;
Return<bool> setEnabled(bool enabled) override; Return<bool> setEnabled(bool enabled) override;
private:
int mOplusDisplayFd;
}; };
} // namespace implementation } // namespace implementation

View File

@@ -20,5 +20,9 @@
#define OPLUS_PANEL_IOCTL_BASE 'o' #define OPLUS_PANEL_IOCTL_BASE 'o'
#define PANEL_IOCTL_SET_HBM _IOW(OPLUS_PANEL_IOCTL_BASE, 0x0F, unsigned int)
#define PANEL_IOCTL_GET_HBM _IOWR(OPLUS_PANEL_IOCTL_BASE, 0x10, unsigned int)
#define PANEL_IOCTL_SET_DIMLAYER_HBM _IOW(OPLUS_PANEL_IOCTL_BASE, 0x1F, unsigned int) #define PANEL_IOCTL_SET_DIMLAYER_HBM _IOW(OPLUS_PANEL_IOCTL_BASE, 0x1F, unsigned int)
#define PANEL_IOCTL_SET_DIMLAYER_BL_EN _IOW(OPLUS_PANEL_IOCTL_BASE, 0x21, unsigned int)
#define PANEL_IOCTL_GET_DIMLAYER_BL_EN _IOWR(OPLUS_PANEL_IOCTL_BASE, 0x22, unsigned int)
#define PANEL_IOCTL_SET_FP_PRESS _IOW(OPLUS_PANEL_IOCTL_BASE, 0x29, unsigned int) #define PANEL_IOCTL_SET_FP_PRESS _IOW(OPLUS_PANEL_IOCTL_BASE, 0x29, unsigned int)

View File

@@ -1 +1 @@
rw_dir_file(hal_lineage_livedisplay_qti, vendor_sysfs_graphics) allow hal_lineage_livedisplay_qti graphics_device:chr_file rw_file_perms;