Commit 38f78cae authored by David Rosca's avatar David Rosca
Browse files

Restore adapter powered state after wakeup from suspend

BUG: 314356
parent 62088fd1
......@@ -65,6 +65,7 @@ struct BlueDevilDaemon::Private
QList <DeviceInfo> m_discovered;
QTimer m_timer;
KComponentData m_componentData;
QHash<QString, bool> m_adapterPoweredHash;
};
BlueDevilDaemon::BlueDevilDaemon(QObject *parent, const QList<QVariant>&)
......@@ -106,6 +107,15 @@ BlueDevilDaemon::BlueDevilDaemon(QObject *parent, const QList<QVariant>&)
connect(Manager::self(), SIGNAL(usableAdapterChanged(Adapter*)),
this, SLOT(usableAdapterChanged(Adapter*)));
// Catch suspend/resume events
QDBusConnection::systemBus().connect("org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
"PrepareForSleep",
this,
SLOT(login1PrepareForSleep(bool))
);
d->m_status = Private::Offline;
usableAdapterChanged(Manager::self()->usableAdapter());
......@@ -123,6 +133,40 @@ BlueDevilDaemon::~BlueDevilDaemon()
delete d;
}
static Adapter *adapterForAddress(const QString &address)
{
Q_FOREACH (Adapter *adapter, Manager::self()->adapters()) {
if (adapter->address() == address) {
return adapter;
}
}
return 0;
}
void BlueDevilDaemon::login1PrepareForSleep(bool active)
{
if (active) {
kDebug(dblue()) << "About to suspend";
d->m_adapterPoweredHash.clear();
Q_FOREACH (Adapter *adapter, Manager::self()->adapters()) {
kDebug(dblue()) << "Saving" << adapter->address() << adapter->isPowered();
d->m_adapterPoweredHash.insert(adapter->address(), adapter->isPowered());
}
} else {
kDebug(dblue()) << "About to resume";
QHashIterator<QString, bool> it(d->m_adapterPoweredHash);
while (it.hasNext()) {
it.next();
Adapter *adapter = adapterForAddress(it.key());
if (adapter) {
kDebug(dblue()) << "Restoring" << adapter->address() << it.value();
adapter->setPowered(it.value());
}
}
d->m_adapterPoweredHash.clear();
}
}
bool BlueDevilDaemon::isOnline()
{
if (d->m_status == Private::Offline) {
......@@ -329,4 +373,4 @@ DeviceInfo BlueDevilDaemon::deviceToInfo(Device *const device) const
return info;
}
extern int dblue() { static int s_area = KDebug::registerArea("BlueDaemon", false); return s_area; }
\ No newline at end of file
extern int dblue() { static int s_area = KDebug::registerArea("BlueDaemon", false); return s_area; }
......@@ -87,6 +87,8 @@ private Q_SLOTS:
*/
void agentReleased();
void login1PrepareForSleep(bool active);
void deviceFound(Device*);
void monolithicQuit(QDBusPendingCallWatcher* watcher);
void monolithicFinished(const QString &);
......
Supports Markdown
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