Skip to content

Commit

Permalink
fix: app blocked when AM is unavailable
Browse files Browse the repository at this point in the history
  We don't block application when AM is unavailable.
  • Loading branch information
18202781743 committed Dec 8, 2023
1 parent fea1588 commit af8b766
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/dsgapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <QDBusReply>
#include <QRegularExpression>
#include <QLoggingCategory>
#include <QDBusConnectionInterface>

#include <DDBusInterface>

Expand All @@ -33,6 +34,19 @@ static inline QByteArray getSelfAppId() {
return DSGApplication::getId(QCoreApplication::applicationPid());
}

static bool isServiceActivatable(const QString &service)
{
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(service))
return false;

const QDBusReply<QStringList> activatableNames = QDBusConnection::sessionBus().interface()->
callWithArgumentList(QDBus::AutoDetect,
QLatin1String("ListActivatableNames"),
QList<QVariant>());

return activatableNames.value().contains(service);
}

QByteArray DSGApplication::id()
{
static QByteArray selfId = getSelfAppId();
Expand All @@ -52,6 +66,11 @@ QByteArray DSGApplication::id()

QByteArray DSGApplication::getId(qint64 pid)
{
if (!isServiceActivatable("org.desktopspec.ApplicationManager1")) {
qCInfo(dsgApp) << "Can't getId from AM for the " << pid << ", because AM is unavailable.";
return QByteArray();
}

int pidfd = syscall(SYS_pidfd_open, pid, 0);
if (pidfd < 0) {
qCWarning(dsgApp) << "pidfd open failed:" << strerror(errno);
Expand All @@ -69,7 +88,9 @@ QByteArray DSGApplication::getId(qint64 pid)
return QByteArray();
}

return reply.value().toLatin1();
const QByteArray appId = reply.value().toLatin1();
qCInfo(dsgApp) << "AppId is fetched from AM, and value is " << appId;
return appId;
}

DCORE_END_NAMESPACE

0 comments on commit af8b766

Please sign in to comment.