Skip to content

Commit

Permalink
Merge pull request #32 from thp/ofono-dbus-imei
Browse files Browse the repository at this point in the history
[ssudeviceinfo] Get IMEI directly from ofono via D-Bus
  • Loading branch information
thp committed Jul 10, 2014
2 parents 031aaec + 1b2a593 commit dfc9706
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 14 deletions.
2 changes: 1 addition & 1 deletion libssu/libssu.pro
Expand Up @@ -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}

Expand Down
76 changes: 64 additions & 12 deletions libssu/ssudeviceinfo.cpp
Expand Up @@ -9,6 +9,10 @@
#include <QTextStream>
#include <QDir>

#include <QDBusMessage>
#include <QDBusConnection>
#include <QDBusArgument>

#include <sys/utsname.h>

extern "C" {
Expand All @@ -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);
Expand Down Expand Up @@ -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(){
Expand Down
1 change: 0 additions & 1 deletion rpm/ssu.spec
Expand Up @@ -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)
Expand Down

0 comments on commit dfc9706

Please sign in to comment.