Commit c6b7c714 authored by Xingang Li's avatar Xingang Li Committed by Nate Graham
Browse files

Improved backlight devices selection

1. Change backlight devices selection order, return more early;
2. Only check raw type devices's enable attribute. If no raw
device available, we will search again without above checking.

BUG: 399646


(cherry picked from commit 401e3ed8)
parent 4146b284
Pipeline #141856 passed with stage
in 1 minute and 23 seconds
......@@ -74,6 +74,17 @@ void BacklightHelper::init()
void BacklightHelper::initUsingBacklightType()
{
QDir ledsDir(LED_SYSFS_PATH);
ledsDir.setFilter(QDir::Dirs | QDir::NoDot | QDir::NoDotDot | QDir::NoDotAndDotDot | QDir::Readable);
ledsDir.setNameFilters({QStringLiteral("*lcd*"), QStringLiteral("*wled*")});
QStringList ledInterfaces = ledsDir.entryList();
if (!ledInterfaces.isEmpty()) {
m_dirname = LED_SYSFS_PATH + ledInterfaces.constFirst();
return;
}
QDir backlightDir(BACKLIGHT_SYSFS_PATH);
backlightDir.setFilter(QDir::AllDirs | QDir::NoDot | QDir::NoDotDot | QDir::NoDotAndDotDot | QDir::Readable);
backlightDir.setSorting(QDir::Name | QDir::Reversed);// Reverse is needed to priorize acpi_video1 over 0
......@@ -82,18 +93,9 @@ void BacklightHelper::initUsingBacklightType()
QFile file;
QByteArray buffer;
QStringList firmware, platform, raw, leds;
QStringList firmware, platform, raw;
for (const QString & interface : interfaces) {
QFile enabled(BACKLIGHT_SYSFS_PATH + interface + "/device/enabled");
if (enabled.open(QIODevice::ReadOnly | QIODevice::Text)) {
if (enabled.readLine().trimmed() != "enabled") {
// this backlight device isn't connected to a display, so move on
// to the next one and see if it does.
continue;
}
}
file.setFileName(BACKLIGHT_SYSFS_PATH + interface + "/type");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
continue;
......@@ -105,7 +107,13 @@ void BacklightHelper::initUsingBacklightType()
} else if(buffer == "platform") {
platform.append(interface);
} else if (buffer == "raw") {
raw.append(interface);
QFile enabled(BACKLIGHT_SYSFS_PATH + interface + "/device/enabled");
if (enabled.open(QIODevice::ReadOnly | QIODevice::Text) &&
enabled.readLine().trimmed() == "enabled") {
// this backlight device is connected to a display, so append
// it to raw list
raw.append(interface);
}
} else {
qCWarning(POWERDEVIL) << "Interface type not handled" << buffer;
}
......@@ -113,16 +121,6 @@ void BacklightHelper::initUsingBacklightType()
file.close();
}
QDir ledsDir(LED_SYSFS_PATH);
ledsDir.setFilter(QDir::Dirs | QDir::NoDot | QDir::NoDotDot | QDir::NoDotAndDotDot | QDir::Readable);
ledsDir.setNameFilters({QStringLiteral("*lcd*"), QStringLiteral("*wled*")});
QStringList ledInterfaces = ledsDir.entryList();
if (!ledInterfaces.isEmpty()) {
m_dirname = LED_SYSFS_PATH + ledInterfaces.constFirst();
return;
}
if (!firmware.isEmpty()) {
m_dirname = BACKLIGHT_SYSFS_PATH + firmware.constFirst();
......@@ -134,11 +132,25 @@ void BacklightHelper::initUsingBacklightType()
return;
}
if (raw.isEmpty()) {
// if no raw type backlight device found, let's fall back and try again
for (const QString &interface : interfaces) {
file.setFileName(BACKLIGHT_SYSFS_PATH + interface + "/type");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
continue;
}
buffer = file.readLine().trimmed();
if (buffer == "raw") {
raw.append(interface);
}
}
}
if (!raw.isEmpty()) {
m_dirname = BACKLIGHT_SYSFS_PATH + raw.constFirst();
return;
}
}
void BacklightHelper::initUsingSysctl()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment