Commit e1cc12e2 authored by Bea Lam's avatar Bea Lam

[developermode] Add DeveloperModeSettings::developerModeAccountProvider. Contributes to JB#39097

This value refers to the first known account provider that provides a
service of the "developermode" type.
parent eb2dfc6f
......@@ -26,6 +26,7 @@ BuildRequires: pkgconfig(nemomodels-qt5)
BuildRequires: pkgconfig(libsailfishkeyprovider) >= 0.0.14
BuildRequires: pkgconfig(connman-qt5)
BuildRequires: pkgconfig(ssu-sysinfo) >= 1.1.0
BuildRequires: pkgconfig(sailfishaccounts)
%description
%{summary}.
......
......@@ -32,11 +32,17 @@
#include "developermodesettings.h"
/* libsailfishaccounts */
#include <accountmanager.h>
#include <provider.h>
#include <service.h>
#include <QDebug>
#include <QFile>
#include <QDir>
#include <QDBusReply>
#include <QNetworkInterface>
#include <getdef.h>
#include <pwd.h>
......@@ -55,6 +61,9 @@
/* A file that is provided by the developer mode package */
#define DEVELOPER_MODE_PROVIDED_FILE "/usr/bin/devel-su"
/* The service name for developer mode services offered by an account provider */
#define DEVELOPER_MODE_ACCOUNT_SERVICE "developermode"
/* D-Bus service */
#define PACKAGEKIT_SERVICE "org.freedesktop.PackageKit"
#define PACKAGEKIT_PATH "/org/freedesktop/PackageKit"
......@@ -140,6 +149,7 @@ DeveloperModeSettings::DeveloperModeSettings(QObject *parent)
: QObject(parent)
, m_usbModeDaemon(USB_MODED_SERVICE, USB_MODED_PATH, USB_MODED_INTERFACE,
QDBusConnection::systemBus())
, m_accountManager(new AccountManager(this))
, m_pendingPackageKitCall(nullptr)
, m_packageKitCommand(nullptr)
, m_wlanIpAddress("-")
......@@ -160,6 +170,10 @@ DeveloperModeSettings::DeveloperModeSettings(QObject *parent)
qWarning() << "Failed to return username using getpwuid()";
}
updateAccountProvider();
connect(m_accountManager, &AccountManager::providerNamesChanged,
this, &DeveloperModeSettings::updateAccountProvider);
if (!m_developerModeEnabled) {
m_workerStatus = CheckingStatus;
executePackageKitCommand(&DeveloperModeSettings::resolvePackageId, DEVELOPER_MODE_PACKAGE);
......@@ -194,6 +208,11 @@ DeveloperModeSettings::username() const
return m_username;
}
QString DeveloperModeSettings::developerModeAccountProvider() const
{
return m_developerModeAccountProvider;
}
bool DeveloperModeSettings::developerModeAvailable() const
{
return m_developerModeEnabled || !m_developerModePackageId.isEmpty();
......@@ -539,3 +558,34 @@ void DeveloperModeSettings::transactionFinished(uint exit, uint)
emit workerStatusChanged();
emit workerProgressChanged();
}
void DeveloperModeSettings::updateAccountProvider()
{
// Find all account providers with the developer-mode service. If m_developerModeAccountProvider
// is already set to the name of one of these providers, just return. Otherwise, set it to the
// first provider found with a matching service.
QList<Provider *> accountProviders;
for (const QString &providerName : m_accountManager->providerNames()) {
if (Provider *accountProvider = m_accountManager->provider(providerName)) {
for (const QString &serviceName : accountProvider->serviceNames()) {
if (Service *accountService = m_accountManager->service(serviceName)) {
if (accountService->serviceType() == DEVELOPER_MODE_ACCOUNT_SERVICE) {
if (m_developerModeAccountProvider == providerName) {
return;
} else {
accountProviders.append(accountProvider);
break;
}
}
}
}
}
}
if (!accountProviders.isEmpty()) {
if (m_developerModeAccountProvider != accountProviders.first()->name()) {
m_developerModeAccountProvider = accountProviders.first()->name();
emit developerModeAccountProviderChanged();
}
}
}
......@@ -41,6 +41,7 @@
QT_BEGIN_NAMESPACE
class QDBusPendingCallWatcher;
class AccountManager;
QT_END_NAMESPACE
class SYSTEMSETTINGS_EXPORT DeveloperModeSettings : public QObject
......@@ -64,6 +65,10 @@ class SYSTEMSETTINGS_EXPORT DeveloperModeSettings : public QObject
READ developerModeAvailable
NOTIFY developerModeAvailableChanged)
Q_PROPERTY(QString developerModeAccountProvider
READ developerModeAccountProvider
NOTIFY developerModeAccountProviderChanged)
Q_PROPERTY(bool developerModeEnabled
READ developerModeEnabled
NOTIFY developerModeEnabledChanged)
......@@ -96,6 +101,7 @@ public:
QString username() const;
bool developerModeAvailable() const;
bool developerModeEnabled() const;
QString developerModeAccountProvider() const;
bool remoteLoginEnabled() const;
enum DeveloperModeSettings::Status workerStatus() const;
int workerProgress() const;
......@@ -109,6 +115,7 @@ signals:
void wlanIpAddressChanged();
void usbIpAddressChanged();
void developerModeAvailableChanged();
void developerModeAccountProviderChanged();
void developerModeEnabledChanged();
void remoteLoginEnabledChanged();
void workerWorkingChanged();
......@@ -133,10 +140,12 @@ private:
void executePackageKitCommand(
QDBusPendingCallWatcher *(DeveloperModeSettings::*command)(const QString &),
const QString &argument);
void resolveDeveloperModePackageId();
void updateAccountProvider();
QDBusInterface m_usbModeDaemon;
QDBusObjectPath m_packageKitTransaction;
AccountManager *m_accountManager;
QDBusPendingCallWatcher *m_pendingPackageKitCall;
QDBusPendingCallWatcher *(DeveloperModeSettings::*m_packageKitCommand)(const QString &packageId);
......@@ -145,6 +154,7 @@ private:
QString m_usbIpAddress;
QString m_username;
QString m_developerModePackageId;
QString m_developerModeAccountProvider;
bool m_developerModeEnabled;
bool m_remoteLoginEnabled;
DeveloperModeSettings::Status m_workerStatus;
......
......@@ -6,7 +6,7 @@ QT += qml dbus systeminfo
QT -= gui
CONFIG += c++11 hide_symbols link_pkgconfig
PKGCONFIG += profile mlite5 mce timed-qt5 libshadowutils blkid libcrypto nemomodels-qt5 libsailfishkeyprovider connman-qt5
PKGCONFIG += profile mlite5 mce timed-qt5 libshadowutils blkid libcrypto nemomodels-qt5 libsailfishkeyprovider connman-qt5 sailfishaccounts
PKGCONFIG += ssu-sysinfo
system(qdbusxml2cpp -p mceiface.h:mceiface.cpp mce.xml)
......
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