Commit e1db3107 authored by spiiroin's avatar spiiroin

[systemsettings] Add DeviceInfo interface for hw feature queries. JB#40282

There is a C api in libssusysinfo (version 1.1.0 onwards) for querying
available hw features and hw keys, but it is not suitable for use from
QML applications.

Provide wrapper class that converts data made available by ssusysinfo
in more Qt friendly form and expose DeviceInfo objects for making
queries from QML applications.
Signed-off-by: spiiroin's avatarSimo Piiroinen <simo.piiroinen@jollamobile.com>
parent 273ea613
......@@ -25,6 +25,7 @@ BuildRequires: pkgconfig(libcrypto)
BuildRequires: pkgconfig(nemomodels-qt5)
BuildRequires: pkgconfig(libsailfishkeyprovider) >= 0.0.14
BuildRequires: pkgconfig(connman-qt5)
BuildRequires: pkgconfig(ssu-sysinfo) >= 1.1.0
%description
%{summary}.
......
/*
* Copyright (C) 2017 Jolla Ltd. <simo.piiroinen@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/
#include "deviceinfo.h"
#include <QSet>
#include <ssusysinfo.h>
class DeviceInfoPrivate
{
public:
DeviceInfoPrivate();
~DeviceInfoPrivate();
QSet<DeviceInfo::Feature> m_features;
QSet<Qt::Key> m_keys;
};
DeviceInfoPrivate::DeviceInfoPrivate()
{
ssusysinfo_t *si = ssusysinfo_create();
hw_feature_t *features = ssusysinfo_get_hw_features(si);
if (features) {
for (size_t i = 0; features[i]; ++i) {
m_features.insert(static_cast<DeviceInfo::Feature>(features[i]));
}
free(features);
}
hw_key_t *keys = ssusysinfo_get_hw_keys(si);
if (keys) {
for (size_t i = 0; keys[i]; ++i) {
m_keys.insert(static_cast<Qt::Key>(keys[i]));
}
free(keys);
}
ssusysinfo_delete(si);
}
DeviceInfoPrivate::~DeviceInfoPrivate()
{
}
DeviceInfo::DeviceInfo(QObject *parent)
: QObject(parent)
, d_ptr(new DeviceInfoPrivate())
{
}
DeviceInfo::~DeviceInfo()
{
delete d_ptr;
d_ptr = 0;
}
bool DeviceInfo::hasFeature(DeviceInfo::Feature feature) const
{
Q_D(const DeviceInfo);
return d->m_features.contains(feature);
}
bool DeviceInfo::hasHardwareKey(Qt::Key key) const
{
Q_D(const DeviceInfo);
return d->m_keys.contains(key);
}
/*
* Copyright (C) 2017 Jolla Ltd. <simo.piiroinen@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/
#ifndef DEVICEINFO_H
#define DEVICEINFO_H
#include <QObject>
#include "systemsettingsglobal.h"
class QQmlEngine;
class QJSEngine;
class DeviceInfoPrivate;
class SYSTEMSETTINGS_EXPORT DeviceInfo: public QObject
{
Q_OBJECT
public:
enum Feature {
/* Duplicates information declared in ssusysinfo.h to
* avoid build time dependencies to libssusysinfo and
* ease use from Qt/QML applications. */
FeatureInvalid,
FeatureMicrophone1,
FeatureMicrophone2,
FeatureBackCamera,
FeatureBackCameraFlashlight,
FeatureDisplayBacklight,
FeatureBattery,
FeatureBluetooth,
FeatureCellularData,
FeatureCellularVoice,
FeatureCompassSensor,
FeatureFMRadioReceiver,
FeatureFrontCamera,
FeatureFrontCameraFlashlight,
FeatureGPS,
FeatureCellInfo,
FeatureAccelerationSensor,
FeatureGyroSensor,
FeatureCoverSensor,
FeatureFingerprintSensor,
FeatureHeadset,
FeatureHardwareKeys,
FeatureDisplay,
FeatureNotificationLED,
FeatureButtonBacklight,
FeatureLightSensor,
FeatureLoudspeaker,
FeatureTheOtherHalf,
FeatureProximitySensor,
FeatureAudioPlayback,
FeatureMemoryCardSlot,
FeatureSIMCardSlot,
FeatureStereoLoudspeaker,
FeatureTouchScreen,
FeatureTouchScreenSelfTest,
FeatureUSBCharging,
FeatureUSBOTG,
FeatureVibrator,
FeatureWLAN,
FeatureNFC,
FeatureVideoPlayback,
FeatureSuspend,
FeatureReboot,
};
Q_ENUM(Feature)
DeviceInfo(QObject *parent = 0);
~DeviceInfo();
Q_INVOKABLE bool hasFeature(DeviceInfo::Feature feature) const;
Q_INVOKABLE bool hasHardwareKey(Qt::Key key) const;
private:
DeviceInfoPrivate *d_ptr;
Q_DISABLE_COPY(DeviceInfo)
Q_DECLARE_PRIVATE(DeviceInfo)
};
#endif /* DEVICEINFO_H */
......@@ -49,6 +49,7 @@
#include "certificatemodel.h"
#include "vpnmodel.h"
#include "locationsettings.h"
#include "deviceinfo.h"
static QObject *vpnmodel_api_factory(QQmlEngine *, QJSEngine *)
{
......@@ -85,6 +86,7 @@ public:
qmlRegisterType<BatteryStatus>(uri, 1, 0, "BatteryStatus");
qmlRegisterType<DiskUsage>(uri, 1, 0, "DiskUsage");
qmlRegisterType<LocationSettings>(uri, 1, 0, "LocationSettings");
qmlRegisterType<DeviceInfo>(uri, 1, 0, "DeviceInfo");
}
};
......
......@@ -7,6 +7,7 @@ QT -= gui
CONFIG += c++11 hide_symbols link_pkgconfig
PKGCONFIG += profile mlite5 mce timed-qt5 libshadowutils blkid libcrypto nemomodels-qt5 libsailfishkeyprovider connman-qt5
PKGCONFIG += ssu-sysinfo
system(qdbusxml2cpp -p mceiface.h:mceiface.cpp mce.xml)
system(qdbusxml2cpp -c ConnmanVpnProxy -p connmanvpnproxy ../dbus/net.connman.vpn.xml -i qdbusxml2cpp_dbus_types.h)
......@@ -31,6 +32,7 @@ SOURCES += \
partition.cpp \
partitionmanager.cpp \
partitionmodel.cpp \
deviceinfo.cpp \
locationsettings.cpp \
timezoneinfo.cpp
......@@ -53,6 +55,7 @@ PUBLIC_HEADERS = \
partitionmanager.h \
partitionmodel.h \
systemsettingsglobal.h \
deviceinfo.h \
locationsettings.h \
timezoneinfo.h
......
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