Commit 1b2a5937 authored by Thomas Perl's avatar Thomas Perl

[ssudeviceinfo] Get IMEI directly from ofono via D-Bus (+fallback)

This avoids a circular dependency between QtSystems and ssu.

Fallback to /etc/machine-id and some other files if IMEI cannot be
retrieved from ofono, and normalize just like previously.
parent 031aaec6
......@@ -29,7 +29,7 @@ SOURCES = \
CONFIG += link_pkgconfig
QT += network xml dbus
PKGCONFIG += libsystemd-journal boardname Qt5SystemInfo libshadowutils
PKGCONFIG += libsystemd-journal boardname libshadowutils
install_headers.files = $${public_headers}
......
......@@ -9,6 +9,10 @@
#include <QTextStream>
#include <QDir>
#include <QDBusMessage>
#include <QDBusConnection>
#include <QDBusArgument>
#include <sys/utsname.h>
extern "C" {
......@@ -23,8 +27,6 @@ extern "C" {
#include "../constants.h"
#include <QDeviceInfo>
SsuDeviceInfo::SsuDeviceInfo(QString model): QObject(){
boardMappings = new SsuSettings(SSU_BOARD_MAPPING_CONFIGURATION, SSU_BOARD_MAPPING_CONFIGURATION_DIR);
......@@ -275,20 +277,70 @@ QString SsuDeviceInfo::deviceModel(){
return cachedModel;
}
QString SsuDeviceInfo::deviceUid(){
QString IMEI;
QDeviceInfo devInfo;
static QStringList
ofonoGetImeis()
{
QStringList result;
QDBusMessage reply = QDBusConnection::systemBus().call(
QDBusMessage::createMethodCall("org.ofono", "/",
"org.ofono.Manager", "GetModems"));
foreach (const QVariant &v, reply.arguments()) {
if (v.canConvert<QDBusArgument>()) {
const QDBusArgument arg = v.value<QDBusArgument>();
if (arg.currentType() == QDBusArgument::ArrayType) {
arg.beginArray();
while (!arg.atEnd()) {
if (arg.currentType() == QDBusArgument::StructureType) {
QString path;
QVariantMap props;
arg.beginStructure();
arg >> path >> props;
arg.endStructure();
if (props.contains("Serial")) {
result << props["Serial"].toString();
}
}
}
arg.endArray();
}
}
}
/// @todo properly check number of imeis, ...
IMEI = devInfo.imei(0);
return result;
}
// this might not be completely unique (or might change on reflash), but works for now
if (IMEI == ""){
IMEI = devInfo.uniqueDeviceID();
IMEI.replace("-", "");
QString SsuDeviceInfo::deviceUid(){
QStringList imeis = ofonoGetImeis();
if (imeis.size() == 0) {
qWarning() << "Could not get IMEI(s) from ofono, trying fallback";
// The fallback list is taken from QtSystems' qdeviceinfo_linux.cpp
QStringList fallbackFiles;
fallbackFiles << "/sys/devices/virtual/dmi/id/product_uuid";
fallbackFiles << "/etc/machine-id";
fallbackFiles << "/etc/unique-id";
fallbackFiles << "/var/lib/dbus/machine-id";
foreach (const QString &filename, fallbackFiles) {
QFile machineId(filename);
if (machineId.open(QFile::ReadOnly | QFile::Text)) {
QTextStream in(&machineId);
// Normalize by stripping colons, dashes and making it lowercase
return in.readAll().trimmed().replace(":", "").replace("-", "").toLower();
}
}
qCritical() << "Could not read fallback UID - returning empty string";
return "";
}
return IMEI;
return imeis[0];
}
QStringList SsuDeviceInfo::disabledRepos(){
......
......@@ -12,7 +12,6 @@ BuildRequires: pkgconfig(Qt5DBus)
BuildRequires: pkgconfig(Qt5Network)
BuildRequires: pkgconfig(Qt5Xml)
BuildRequires: pkgconfig(Qt5Test)
BuildRequires: pkgconfig(Qt5SystemInfo)
BuildRequires: pkgconfig(libzypp)
BuildRequires: pkgconfig(libsystemd-journal)
BuildRequires: pkgconfig(libshadowutils)
......
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