refact: remove processguesser1service
BREAKING CHANGE: due to we couldn't guess the most of processes in a right way, so we remove it. Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
		@ -14,7 +14,6 @@ qt_add_dbus_adaptor(dde_am_dbus_SOURCE ${PROJECT_SOURCE_DIR}/api/dbus/org.deskto
 | 
			
		||||
qt_add_dbus_adaptor(dde_am_dbus_SOURCE ${PROJECT_SOURCE_DIR}/api/dbus/org.desktopspec.ObjectManager1.xml dbus/applicationmanager1service.h ApplicationManager1Service AMobjectmanager1adaptor AMObjectManagerAdaptor)
 | 
			
		||||
qt_add_dbus_adaptor(dde_am_dbus_SOURCE ${PROJECT_SOURCE_DIR}/api/dbus/org.desktopspec.ObjectManager1.xml dbus/applicationservice.h ApplicationService APPobjectmanager1adaptor APPObjectManagerAdaptor)
 | 
			
		||||
qt_add_dbus_adaptor(dde_am_dbus_SOURCE ${PROJECT_SOURCE_DIR}/api/dbus/org.desktopspec.MimeManager1.xml dbus/mimemanager1service.h MimeManager1Service)
 | 
			
		||||
qt_add_dbus_adaptor(dde_am_dbus_SOURCE ${PROJECT_SOURCE_DIR}/api/dbus/org.desktopspec.ProcessGuesser1.xml dbus/processguesser1service.h ProcessGuesser1Service)
 | 
			
		||||
 | 
			
		||||
target_sources(dde_am_dbus PRIVATE
 | 
			
		||||
    ${dde_am_dbus_SOURCE}
 | 
			
		||||
 | 
			
		||||
@ -10,7 +10,6 @@
 | 
			
		||||
#include "propertiesForwarder.h"
 | 
			
		||||
#include "applicationHooks.h"
 | 
			
		||||
#include "desktopfilegenerator.h"
 | 
			
		||||
#include "processguesser1service.h"
 | 
			
		||||
#include <QFile>
 | 
			
		||||
#include <QHash>
 | 
			
		||||
#include <QDBusMessage>
 | 
			
		||||
@ -36,11 +35,6 @@ void ApplicationManager1Service::initService(QDBusConnection &connection) noexce
 | 
			
		||||
        qFatal("%s", connection.lastError().message().toLocal8Bit().data());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (auto *tmp = new (std::nothrow) ProcessGuesser1Service{connection, this}; tmp == nullptr) {
 | 
			
		||||
        qCritical() << "new ProcessGuesser1Service failed.";
 | 
			
		||||
        std::terminate();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (auto *tmp = new (std::nothrow) ApplicationManager1Adaptor{this}; tmp == nullptr) {
 | 
			
		||||
        qCritical() << "new Application Manager Adaptor failed.";
 | 
			
		||||
        std::terminate();
 | 
			
		||||
 | 
			
		||||
@ -1,116 +0,0 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: LGPL-3.0-or-later
 | 
			
		||||
 | 
			
		||||
#include "processguesser1adaptor.h"
 | 
			
		||||
#include "applicationservice.h"
 | 
			
		||||
#include "global.h"
 | 
			
		||||
 | 
			
		||||
ProcessGuesser1Service::ProcessGuesser1Service(QDBusConnection &connection, ApplicationManager1Service *parent) noexcept
 | 
			
		||||
    : QObject(parent)
 | 
			
		||||
{
 | 
			
		||||
    if (!connection.registerService("org.desktopspec.ProcessGuesser1")) {
 | 
			
		||||
        qFatal("%s", connection.lastError().message().toLocal8Bit().data());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    auto *adaptor = new (std::nothrow) ProcessGuesser1Adaptor{this};
 | 
			
		||||
    if (adaptor == nullptr or
 | 
			
		||||
        !registerObjectToDBus(this, "/org/desktopspec/ProcessGuesser1", "org.desktopspec.ProcessGuesser1")) {
 | 
			
		||||
        std::terminate();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ProcessGuesser1Service::checkTryExec(QString tryExec) noexcept
 | 
			
		||||
{
 | 
			
		||||
    if (!tryExec.isEmpty()) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QFileInfo exeBin{tryExec};
 | 
			
		||||
    if (!exeBin.isAbsolute()) {
 | 
			
		||||
        tryExec = QStandardPaths::findExecutable(tryExec);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!tryExec.isEmpty()) {
 | 
			
		||||
        exeBin.setFile(tryExec);
 | 
			
		||||
        if (!exeBin.exists() or !exeBin.isFile() or !exeBin.isExecutable()) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString ProcessGuesser1Service::GuessApplicationId(const QDBusUnixFileDescriptor &pidfd) noexcept
 | 
			
		||||
{
 | 
			
		||||
    if (!pidfd.isValid()) {
 | 
			
		||||
        sendErrorReply(QDBusError::InvalidArgs);
 | 
			
		||||
        return {};
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    auto pid = getPidFromPidFd(pidfd);
 | 
			
		||||
    if (pid == 0) {
 | 
			
		||||
        sendErrorReply(QDBusError::Failed, "Pid is invalid");
 | 
			
		||||
        return {};
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QString exePath = QString{"/proc/%1/exe"}.arg(pid);
 | 
			
		||||
    QFileInfo info{exePath};
 | 
			
		||||
 | 
			
		||||
    if (!info.exists()) {
 | 
			
		||||
        sendErrorReply(QDBusError::Failed, "Pid is invalid.");
 | 
			
		||||
        return {};
 | 
			
		||||
    }
 | 
			
		||||
    const auto &binary = info.symLinkTarget();
 | 
			
		||||
 | 
			
		||||
    const auto &applications = myParent()->Applications();
 | 
			
		||||
    QString appId;
 | 
			
		||||
 | 
			
		||||
    for (const QSharedPointer<ApplicationService> &app : applications) {
 | 
			
		||||
        auto tryExec = app->findEntryValue(DesktopFileEntryKey, "TryExec", EntryValueType::String).toString();
 | 
			
		||||
        if (!tryExec.isEmpty() and !checkTryExec(tryExec)) {
 | 
			
		||||
            qWarning() << "Couldn't find the binary which corresponding with process.";
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        auto exec = app->findEntryValue(DesktopFileEntryKey, "Exec", EntryValueType::String).toString();
 | 
			
		||||
        if (exec.isEmpty()) {  // NOTE: Exec is not required in desktop file.
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        auto opt = ApplicationService::unescapeExecArgs(exec);
 | 
			
		||||
        if (!opt) {
 | 
			
		||||
            qWarning() << app->id() << "unescape exec failed, skip.";
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        auto execList = std::move(opt).value();
 | 
			
		||||
        if (execList.isEmpty()) {
 | 
			
		||||
            qWarning() << "exec is empty,skip.";
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        auto execBin = execList.first();
 | 
			
		||||
        QFileInfo execInfo{execBin};
 | 
			
		||||
        if (!execInfo.isAbsolute()) {
 | 
			
		||||
            execBin = QStandardPaths::findExecutable(execBin);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!execBin.isEmpty() and execBin == binary) {
 | 
			
		||||
            if (!appId.isEmpty()) {
 | 
			
		||||
                auto msg = QString{"Multiple binary have been detected."};
 | 
			
		||||
                qWarning() << msg << appId << app->id();
 | 
			
		||||
                sendErrorReply(QDBusError::Failed, msg);
 | 
			
		||||
                return {};
 | 
			
		||||
            }
 | 
			
		||||
            appId = app->id();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (appId.isEmpty()) {
 | 
			
		||||
        sendErrorReply(QDBusError::Failed, "Couldn't found application.");
 | 
			
		||||
        return {};
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return appId;
 | 
			
		||||
}
 | 
			
		||||
@ -1,36 +0,0 @@
 | 
			
		||||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
 | 
			
		||||
//
 | 
			
		||||
// SPDX-License-Identifier: LGPL-3.0-or-later
 | 
			
		||||
 | 
			
		||||
#ifndef PROCESSGUESSER1SERVICE_H
 | 
			
		||||
#define PROCESSGUESSER1SERVICE_H
 | 
			
		||||
 | 
			
		||||
#include <QObject>
 | 
			
		||||
#include <QDBusContext>
 | 
			
		||||
#include <QDBusUnixFileDescriptor>
 | 
			
		||||
#include "applicationmanager1service.h"
 | 
			
		||||
 | 
			
		||||
class ProcessGuesser1Service : public QObject, protected QDBusContext
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    ProcessGuesser1Service(QDBusConnection &connection, ApplicationManager1Service *parent) noexcept;
 | 
			
		||||
    ~ProcessGuesser1Service() override = default;
 | 
			
		||||
    ProcessGuesser1Service(const ProcessGuesser1Service &) = delete;
 | 
			
		||||
    ProcessGuesser1Service(ProcessGuesser1Service &&) = delete;
 | 
			
		||||
    ProcessGuesser1Service &operator=(const ProcessGuesser1Service &) = delete;
 | 
			
		||||
    ProcessGuesser1Service &operator=(ProcessGuesser1Service &&) = delete;
 | 
			
		||||
    ApplicationManager1Service *myParent() { return dynamic_cast<ApplicationManager1Service *>(QObject::parent()); }
 | 
			
		||||
    [[nodiscard]] const ApplicationManager1Service *myParent() const
 | 
			
		||||
    {
 | 
			
		||||
        return dynamic_cast<ApplicationManager1Service *>(QObject::parent());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
public Q_SLOTS:
 | 
			
		||||
    QString GuessApplicationId(const QDBusUnixFileDescriptor &pidfd) noexcept;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    [[nodiscard]] static bool checkTryExec(QString tryExec) noexcept;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
		Reference in New Issue
	
	Block a user