feat: 指定服务slice、接口类私有化封装处理
指定服务slice、接口类私有化封装处理 Log: 指定服务slice、接口类私有化封装处理 Task: https://pms.uniontech.com/task-view-109315.html Influence: 无 Change-Id: I7111960eab2cb49e439905aac67ac0f83165f6d8
This commit is contained in:
parent
08d9f4895b
commit
68f52fe831
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
CMakeLists.txt.user
|
||||
build/
|
@ -6,3 +6,4 @@ Type=simple
|
||||
Environment="DAM_TASK_HASH=%I"
|
||||
Environment="DAM_TASK_TYPE=freedesktop"
|
||||
ExecStart=/usr/bin/deepin-application-loader
|
||||
Slice=applications.slice
|
@ -5,3 +5,4 @@ Description=Deepin Application Manager service
|
||||
Type=DBus
|
||||
BusName=org.deskspec.ApplicationManager
|
||||
ExecStart=/usr/bin/deepin-application-service
|
||||
Slice=services.slice
|
@ -10,17 +10,17 @@ pkg_check_modules(X11 REQUIRED IMPORTED_TARGET x11)
|
||||
pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
|
||||
|
||||
qt5_add_dbus_adaptor(ADAPTER_SOURCES
|
||||
../../DBus/org.desktopspec.ApplicationManager.xml
|
||||
../../dbus/org.desktopspec.ApplicationManager.xml
|
||||
impl/application_manager.h
|
||||
ApplicationManager)
|
||||
|
||||
qt5_add_dbus_adaptor(ADAPTER_SOURCES
|
||||
../../DBus/org.desktopspec.Application.xml
|
||||
../../dbus/org.desktopspec.Application.xml
|
||||
impl/application.h
|
||||
Application)
|
||||
|
||||
qt5_add_dbus_adaptor(ADAPTER_SOURCES
|
||||
../../DBus/org.desktopspec.ApplicationInstance.xml
|
||||
../../dbus/org.desktopspec.ApplicationInstance.xml
|
||||
impl/application_instance.h
|
||||
ApplicationInstance)
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "../../modules/methods/registe.hpp"
|
||||
#include "../../modules/methods/task.hpp"
|
||||
#include "../../modules/socket/server.h"
|
||||
#include "../../modules/startmanager/startmanager.h"
|
||||
#include "application.h"
|
||||
#include "application_instance.h"
|
||||
#include "applicationinstanceadaptor.h"
|
||||
@ -32,8 +33,13 @@ class ApplicationManagerPrivate : public QObject
|
||||
Socket::Server server;
|
||||
std::multimap<std::string, QSharedPointer<ApplicationInstance>> tasks;
|
||||
|
||||
StartManager *startManager;
|
||||
|
||||
public:
|
||||
ApplicationManagerPrivate(ApplicationManager *parent) : QObject(parent), q_ptr(parent)
|
||||
ApplicationManagerPrivate(ApplicationManager *parent)
|
||||
: QObject(parent)
|
||||
, q_ptr(parent)
|
||||
, startManager(new StartManager(this))
|
||||
{
|
||||
const QString socketPath{QString("/run/user/%1/deepin-application-manager.socket").arg(getuid())};
|
||||
connect(&server, &Socket::Server::onReadyRead, this, &ApplicationManagerPrivate::recvClientData, Qt::QueuedConnection);
|
||||
@ -41,6 +47,12 @@ public:
|
||||
}
|
||||
~ApplicationManagerPrivate() {}
|
||||
|
||||
bool checkDMsgUid()
|
||||
{
|
||||
QDBusReply<uint> reply = q_ptr->connection().interface()->serviceUid(q_ptr->message().service());
|
||||
return reply.isValid() && (reply.value() == getuid());
|
||||
}
|
||||
|
||||
private:
|
||||
void recvClientData(int socket, const std::vector<char> &data)
|
||||
{
|
||||
@ -110,12 +122,18 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
ApplicationManager* ApplicationManager::Instance() {
|
||||
static ApplicationManager manager;
|
||||
return &manager;
|
||||
}
|
||||
|
||||
ApplicationManager::ApplicationManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
, dd_ptr(new ApplicationManagerPrivate(this))
|
||||
, startManager(new StartManager(this))
|
||||
{
|
||||
connect(startManager, &StartManager::autostartChanged, this, &ApplicationManager::AutostartChanged);
|
||||
Q_D(ApplicationManager);
|
||||
|
||||
connect(d->startManager, &StartManager::autostartChanged, this, &ApplicationManager::AutostartChanged);
|
||||
}
|
||||
|
||||
ApplicationManager::~ApplicationManager() {}
|
||||
@ -131,7 +149,7 @@ QDBusObjectPath ApplicationManager::GetInformation(const QString &id)
|
||||
{
|
||||
Q_D(ApplicationManager);
|
||||
|
||||
if (!checkDMsgUid())
|
||||
if (!d->checkDMsgUid())
|
||||
return {};
|
||||
|
||||
for (const QSharedPointer<Application> &app : d->applications) {
|
||||
@ -144,8 +162,8 @@ QDBusObjectPath ApplicationManager::GetInformation(const QString &id)
|
||||
|
||||
QList<QDBusObjectPath> ApplicationManager::GetInstances(const QString &id)
|
||||
{
|
||||
Q_D(const ApplicationManager);
|
||||
if (!checkDMsgUid())
|
||||
Q_D(ApplicationManager);
|
||||
if (!d->checkDMsgUid())
|
||||
return {};
|
||||
|
||||
for (const auto &app : d->applications) {
|
||||
@ -160,7 +178,7 @@ QList<QDBusObjectPath> ApplicationManager::GetInstances(const QString &id)
|
||||
QDBusObjectPath ApplicationManager::Run(const QString &id)
|
||||
{
|
||||
Q_D(ApplicationManager);
|
||||
if (!checkDMsgUid())
|
||||
if (!d->checkDMsgUid())
|
||||
return {};
|
||||
|
||||
// 创建一个实例
|
||||
@ -186,98 +204,110 @@ QDBusObjectPath ApplicationManager::Run(const QString &id)
|
||||
|
||||
bool ApplicationManager::AddAutostart(QString fileName)
|
||||
{
|
||||
if (!checkDMsgUid())
|
||||
Q_D(ApplicationManager);
|
||||
if (!d->checkDMsgUid())
|
||||
return false;
|
||||
|
||||
return startManager->addAutostart(fileName);
|
||||
return d->startManager->addAutostart(fileName);
|
||||
}
|
||||
|
||||
bool ApplicationManager::RemoveAutostart(QString fileName)
|
||||
{
|
||||
if (!checkDMsgUid())
|
||||
Q_D(ApplicationManager);
|
||||
if (!d->checkDMsgUid())
|
||||
return false;
|
||||
|
||||
return startManager->removeAutostart(fileName);
|
||||
return d->startManager->removeAutostart(fileName);
|
||||
}
|
||||
|
||||
QStringList ApplicationManager::AutostartList()
|
||||
{
|
||||
if (!checkDMsgUid())
|
||||
Q_D(ApplicationManager);
|
||||
if (!d->checkDMsgUid())
|
||||
return {};
|
||||
|
||||
return startManager->autostartList();
|
||||
return d->startManager->autostartList();
|
||||
}
|
||||
|
||||
QString ApplicationManager::DumpMemRecord()
|
||||
{
|
||||
if (!checkDMsgUid())
|
||||
return {};
|
||||
Q_D(ApplicationManager);
|
||||
if (!d->checkDMsgUid())
|
||||
return "";
|
||||
|
||||
return startManager->dumpMemRecord();
|
||||
return d->startManager->dumpMemRecord();
|
||||
}
|
||||
|
||||
bool ApplicationManager::IsAutostart(QString fileName)
|
||||
{
|
||||
if (!checkDMsgUid())
|
||||
Q_D(ApplicationManager);
|
||||
if (!d->checkDMsgUid())
|
||||
return false;
|
||||
|
||||
return startManager->isAutostart(fileName);
|
||||
return d->startManager->isAutostart(fileName);
|
||||
}
|
||||
|
||||
bool ApplicationManager::IsMemSufficient()
|
||||
{
|
||||
if (!checkDMsgUid())
|
||||
return true;
|
||||
Q_D(ApplicationManager);
|
||||
if (!d->checkDMsgUid())
|
||||
return false;
|
||||
|
||||
return startManager->isMemSufficient();
|
||||
return d->startManager->isMemSufficient();
|
||||
}
|
||||
|
||||
void ApplicationManager::LaunchApp(QString desktopFile, uint32_t timestamp, QStringList files)
|
||||
{
|
||||
if (!checkDMsgUid())
|
||||
Q_D(ApplicationManager);
|
||||
if (!d->checkDMsgUid())
|
||||
return;
|
||||
|
||||
startManager->launchApp(desktopFile, timestamp, files);
|
||||
d->startManager->launchApp(desktopFile, timestamp, files);
|
||||
}
|
||||
|
||||
void ApplicationManager::LaunchAppAction(QString desktopFile, QString action, uint32_t timestamp)
|
||||
{
|
||||
if (!checkDMsgUid())
|
||||
Q_D(ApplicationManager);
|
||||
if (!d->checkDMsgUid())
|
||||
return;
|
||||
|
||||
startManager->launchAppAction(desktopFile, action, timestamp);
|
||||
d->startManager->launchAppAction(desktopFile, action, timestamp);
|
||||
}
|
||||
|
||||
void ApplicationManager::LaunchAppWithOptions(QString desktopFile, uint32_t timestamp, QStringList files, QMap<QString, QString> options)
|
||||
{
|
||||
if (!checkDMsgUid())
|
||||
Q_D(ApplicationManager);
|
||||
if (!d->checkDMsgUid())
|
||||
return;
|
||||
|
||||
startManager->launchAppWithOptions(desktopFile, timestamp, files, options);
|
||||
d->startManager->launchAppWithOptions(desktopFile, timestamp, files, options);
|
||||
}
|
||||
|
||||
void ApplicationManager::RunCommand(QString exe, QStringList args)
|
||||
{
|
||||
if (!checkDMsgUid())
|
||||
Q_D(ApplicationManager);
|
||||
if (!d->checkDMsgUid())
|
||||
return;
|
||||
|
||||
startManager->runCommand(exe, args);
|
||||
d->startManager->runCommand(exe, args);
|
||||
}
|
||||
|
||||
void ApplicationManager::RunCommandWithOptions(QString exe, QStringList args, QMap<QString, QString> options)
|
||||
{
|
||||
if (!checkDMsgUid())
|
||||
Q_D(ApplicationManager);
|
||||
if (!d->checkDMsgUid())
|
||||
return;
|
||||
|
||||
startManager->runCommandWithOptions(exe, args, options);
|
||||
d->startManager->runCommandWithOptions(exe, args, options);
|
||||
}
|
||||
|
||||
void ApplicationManager::TryAgain(bool launch)
|
||||
{
|
||||
if (!checkDMsgUid())
|
||||
Q_D(ApplicationManager);
|
||||
if (!d->checkDMsgUid())
|
||||
return;
|
||||
|
||||
startManager->tryAgain(launch);
|
||||
d->startManager->tryAgain(launch);
|
||||
}
|
||||
|
||||
QList<QDBusObjectPath> ApplicationManager::instances() const
|
||||
@ -305,10 +335,4 @@ QList<QDBusObjectPath> ApplicationManager::list() const
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ApplicationManager::checkDMsgUid()
|
||||
{
|
||||
QDBusReply<uint> reply = connection().interface()->serviceUid(message().service());
|
||||
return reply.isValid() && (reply.value() == getuid());
|
||||
}
|
||||
|
||||
#include "application_manager.moc"
|
||||
|
@ -1,8 +1,6 @@
|
||||
#ifndef A2862DC7_5DA3_4129_9796_671D88015BED
|
||||
#define A2862DC7_5DA3_4129_9796_671D88015BED
|
||||
|
||||
#include "../../modules/startmanager/startmanager.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusObjectPath>
|
||||
#include <QList>
|
||||
@ -20,17 +18,10 @@ class ApplicationManager : public QObject, public QDBusContext
|
||||
QScopedPointer<ApplicationManagerPrivate> dd_ptr;
|
||||
Q_DECLARE_PRIVATE_D(qGetPtrHelper(dd_ptr), ApplicationManager)
|
||||
|
||||
ApplicationManager(QObject *parent = nullptr);
|
||||
bool checkDMsgUid();
|
||||
|
||||
StartManager *startManager;
|
||||
|
||||
public:
|
||||
ApplicationManager(QObject *parent = nullptr);
|
||||
~ApplicationManager() override;
|
||||
static ApplicationManager* Instance() {
|
||||
static ApplicationManager manager;
|
||||
return &manager;
|
||||
}
|
||||
static ApplicationManager* Instance();
|
||||
|
||||
void addApplication(const QList<QSharedPointer<Application>> &list);
|
||||
|
||||
@ -62,6 +53,7 @@ public Q_SLOTS: // METHODS
|
||||
void RunCommand(QString exe, QStringList args);
|
||||
void RunCommandWithOptions(QString exe, QStringList args, QMap<QString, QString> options);
|
||||
void TryAgain(bool launch);
|
||||
|
||||
};
|
||||
|
||||
#endif /* A2862DC7_5DA3_4129_9796_671D88015BED */
|
||||
|
Loading…
Reference in New Issue
Block a user