diff --git a/board-mappings.ini b/board-mappings.ini index 2555ad7..97aea77 100644 --- a/board-mappings.ini +++ b/board-mappings.ini @@ -17,18 +17,14 @@ # - boardname.contains -- searches for substring in boardname # NOTE: only use boardname if none of the other options match # use the boardname command to set/check the current value -# - systeminfo.equals -- compares the model returned by QSystemInfo -# with the value provided -# NOTE: systeminfo matching is currently disabled, as this would -# pull in the whole X11 stack, and on Mer/Nemo does cpuinfo -# matching only anyway, which ssu can do better already. +# - hwrelease.device -- Compares MER_HA_DEVICE in /etc/hw-release # - cpuinfo.contains -- searches /proc/cpuinfo for a string # - uname-release.contains -- searches the kernels release string for # a string (uname -r) # - arch.equals -- compares with zyppers arch (like i586) # # Resolve order is: -# file.exists -> systeminfo.equals -> cpuinfo.contains +# file.exists -> cpuinfo.contains -> hwrelease.device # -> uname-release.contains -> arch.equals # # The found model (after resolving variants) will be used as category. The @@ -85,13 +81,15 @@ [file.exists] SDK=/mer-sdk-chroot -[systeminfo.equals] - [cpuinfo.contains] N900=Nokia RX-51 board N950=Nokia RM-680 board N9=Nokia RM-696 board +[hwrelease.device] +mako=mako +grouper=grouper + [arch.equals] generic-x86=i586 diff --git a/libssu/ssudeviceinfo.cpp b/libssu/ssudeviceinfo.cpp index 4cf8544..0cfed02 100644 --- a/libssu/ssudeviceinfo.cpp +++ b/libssu/ssudeviceinfo.cpp @@ -201,29 +201,6 @@ QString SsuDeviceInfo::deviceModel(){ } if (!cachedModel.isEmpty()) return cachedModel; - // check if the QSystemInfo model is useful - //QSystemDeviceInfo devInfo; - // TODO Current Mer SystemDeviceInfo only returns cpuinfo stuff, - // which is what we can do with cpuinfo matching in a more - // flexible way, so there's not really any need to pull in the - // whole X11 stack just for this. Can be enabled once systeminfo - // is less insane - /* - QSystemDeviceInfoLinuxCommonPrivate devInfo; - QString model = devInfo.model(); - boardMappings->beginGroup("systeminfo.equals"); - keys = boardMappings->allKeys(); - foreach (const QString &key, keys){ - QString value = boardMappings->value(key).toString(); - if (model == value){ - cachedModel = key; - break; - } - } - boardMappings->endGroup(); - if (!cachedModel.isEmpty()) return cachedModel; - */ - // check if the device can be identified by a string in /proc/cpuinfo procCpuinfo.setFileName(Sandbox::map("/proc/cpuinfo")); procCpuinfo.open(QIODevice::ReadOnly | QIODevice::Text); @@ -244,6 +221,23 @@ QString SsuDeviceInfo::deviceModel(){ } if (!cachedModel.isEmpty()) return cachedModel; + // mer-hybris adaptations: /etc/hw-release MER_HA_DEVICE variable + QString hwReleaseDevice = hwRelease()["MER_HA_DEVICE"]; + if (!hwReleaseDevice.isEmpty()) { + boardMappings->beginGroup("hwrelease.device"); + keys = boardMappings->allKeys(); + + foreach (const QString &key, keys) { + QString value = boardMappings->value(key).toString(); + if (hwReleaseDevice == value) { + cachedModel = key; + break; + } + } + boardMappings->endGroup(); + } + if (!cachedModel.isEmpty()) return cachedModel; + // check if the device can be identified by the kernel version string struct utsname buf; if (!uname(&buf)){ @@ -451,3 +445,74 @@ QVariant SsuDeviceInfo::value(const QString &key, const QVariant &value){ return value; } + +QMap SsuDeviceInfo::hwRelease() +{ + QMap result; + + // Specification of the format, encoding is similar to /etc/os-release + // http://www.freedesktop.org/software/systemd/man/os-release.html + + QFile hwRelease("/etc/hw-release"); + if (hwRelease.open(QIODevice::ReadOnly | QIODevice::Text)) { + QTextStream in(&hwRelease); + + // "All strings should be in UTF-8 format, and non-printable characters + // should not be used." + in.setCodec("UTF-8"); + + while (!in.atEnd()) { + QString line = in.readLine(); + + // "Lines beginning with "#" shall be ignored as comments." + if (line.startsWith('#')) { + continue; + } + + QString key = line.section('=', 0, 0); + QString value = line.section('=', 1); + + // Remove trailing whitespace in value + value = value.trimmed(); + + // POSIX.1-2001 says uppercase, digits and underscores. + // + // Bash uses "[a-zA-Z_]+[a-zA-Z0-9_]*", so we'll use that too, + // as we can safely assume that "shell-compatible variable + // assignments" means it should be compatible with bash. + // + // see http://stackoverflow.com/a/2821183 + // and http://stackoverflow.com/a/2821201 + if (!QRegExp("[a-zA-Z_]+[a-zA-Z0-9_]*").exactMatch(key)) { + qWarning("Invalid key in input line: '%s'", qPrintable(line)); + continue; + } + + // "Variable assignment values should be enclosed in double or + // single quotes if they include spaces, semicolons or other + // special characters outside of A-Z, a-z, 0-9." + if (((value.at(0) == '\'') || (value.at(0) == '"'))) { + if (value.at(0) != value.at(value.size() - 1)) { + qWarning("Quoting error in input line: '%s'", qPrintable(line)); + continue; + } + + // Remove the quotes + value = value.mid(1, value.size() - 2); + } + + // "If double or single quotes or backslashes are to be used within + // variable assignments, they should be escaped with backslashes, + // following shell style." + value = value.replace("\\\"", "\""); + value = value.replace("\\'", "'"); + value = value.replace("\\\\", "\\"); + + result[key] = value; + } + + hwRelease.close(); + } + + return result; +} diff --git a/libssu/ssudeviceinfo.h b/libssu/ssudeviceinfo.h index 5b08cf8..b50fdbe 100644 --- a/libssu/ssudeviceinfo.h +++ b/libssu/ssudeviceinfo.h @@ -112,5 +112,10 @@ class SsuDeviceInfo: public QObject { QString cachedFamily, cachedModel, cachedVariant; void clearCache(); + + /** + * Return a map of key, value pairs parsed from /etc/hw-release + */ + QMap hwRelease(); }; #endif diff --git a/tests/ut_deviceinfo/testdata/board-mappings.ini b/tests/ut_deviceinfo/testdata/board-mappings.ini index 4648fce..e651055 100644 --- a/tests/ut_deviceinfo/testdata/board-mappings.ini +++ b/tests/ut_deviceinfo/testdata/board-mappings.ini @@ -1,8 +1,6 @@ [file.exists] SDK=/mer-sdk-chroot -[systeminfo.equals] - [cpuinfo.contains] N900=Nokia RX-51 board N950=Nokia RM-680 board diff --git a/tests/ut_rndssucli/testdata/board-mappings.ini b/tests/ut_rndssucli/testdata/board-mappings.ini index 49c0e66..6dad6b5 100644 --- a/tests/ut_rndssucli/testdata/board-mappings.ini +++ b/tests/ut_rndssucli/testdata/board-mappings.ini @@ -1,8 +1,6 @@ [file.exists] SDK=/mer-sdk-chroot -[systeminfo.equals] - [cpuinfo.contains] N900=Nokia RX-51 board N950=Nokia RM-680 board diff --git a/tests/ut_ssuurlresolver/testdata/board-mappings.ini b/tests/ut_ssuurlresolver/testdata/board-mappings.ini index 49c0e66..6dad6b5 100644 --- a/tests/ut_ssuurlresolver/testdata/board-mappings.ini +++ b/tests/ut_ssuurlresolver/testdata/board-mappings.ini @@ -1,8 +1,6 @@ [file.exists] SDK=/mer-sdk-chroot -[systeminfo.equals] - [cpuinfo.contains] N900=Nokia RX-51 board N950=Nokia RM-680 board diff --git a/tests/ut_urlresolver/testdata/board-mappings.ini b/tests/ut_urlresolver/testdata/board-mappings.ini index 49c0e66..6dad6b5 100644 --- a/tests/ut_urlresolver/testdata/board-mappings.ini +++ b/tests/ut_urlresolver/testdata/board-mappings.ini @@ -1,8 +1,6 @@ [file.exists] SDK=/mer-sdk-chroot -[systeminfo.equals] - [cpuinfo.contains] N900=Nokia RX-51 board N950=Nokia RM-680 board