mirror of https://github.com/linuxdeepin/dtkcore
fix: app blocked when AM is unavailable
We don't block application when AM is unavailable.
This commit is contained in:
parent
fea15882e9
commit
af8b7666ff
|
@ -14,6 +14,7 @@
|
|||
#include <QDBusReply>
|
||||
#include <QRegularExpression>
|
||||
#include <QLoggingCategory>
|
||||
#include <QDBusConnectionInterface>
|
||||
|
||||
#include <DDBusInterface>
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue