From 676e082b65cbf2e1185431ec95695f685933b64f Mon Sep 17 00:00:00 2001 From: ComixHe Date: Wed, 6 Mar 2024 14:34:04 +0800 Subject: [PATCH] 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 --- api/dbus/org.desktopspec.ProcessGuesser1.xml | 9 -- src/dbus/CMakeLists.txt | 1 - src/dbus/applicationmanager1service.cpp | 6 - src/dbus/processguesser1service.cpp | 116 ------------------- src/dbus/processguesser1service.h | 36 ------ 5 files changed, 168 deletions(-) delete mode 100644 api/dbus/org.desktopspec.ProcessGuesser1.xml delete mode 100644 src/dbus/processguesser1service.cpp delete mode 100644 src/dbus/processguesser1service.h diff --git a/api/dbus/org.desktopspec.ProcessGuesser1.xml b/api/dbus/org.desktopspec.ProcessGuesser1.xml deleted file mode 100644 index 002d5c1..0000000 --- a/api/dbus/org.desktopspec.ProcessGuesser1.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/src/dbus/CMakeLists.txt b/src/dbus/CMakeLists.txt index 5006efe..92ffdd6 100644 --- a/src/dbus/CMakeLists.txt +++ b/src/dbus/CMakeLists.txt @@ -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} diff --git a/src/dbus/applicationmanager1service.cpp b/src/dbus/applicationmanager1service.cpp index 659891c..c2748b0 100644 --- a/src/dbus/applicationmanager1service.cpp +++ b/src/dbus/applicationmanager1service.cpp @@ -10,7 +10,6 @@ #include "propertiesForwarder.h" #include "applicationHooks.h" #include "desktopfilegenerator.h" -#include "processguesser1service.h" #include #include #include @@ -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(); diff --git a/src/dbus/processguesser1service.cpp b/src/dbus/processguesser1service.cpp deleted file mode 100644 index 2ab84c6..0000000 --- a/src/dbus/processguesser1service.cpp +++ /dev/null @@ -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 &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; -} diff --git a/src/dbus/processguesser1service.h b/src/dbus/processguesser1service.h deleted file mode 100644 index 82a67ca..0000000 --- a/src/dbus/processguesser1service.h +++ /dev/null @@ -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 -#include -#include -#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(QObject::parent()); } - [[nodiscard]] const ApplicationManager1Service *myParent() const - { - return dynamic_cast(QObject::parent()); - } - -public Q_SLOTS: - QString GuessApplicationId(const QDBusUnixFileDescriptor &pidfd) noexcept; - -private: - [[nodiscard]] static bool checkTryExec(QString tryExec) noexcept; -}; - -#endif