shift-shell/components/waydroidintegrationplugin/kauth/waydroidhelper.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.6 KiB
C++
Raw Normal View History

kcm: Implement minimal Waydroid support I prefer create MR now to avoid biggest merge request. It add minimalist implementation: - First configuration of Waydroid - Stop / Start Waydroid session - Configure properties of Waydroid - Display current ip of Waydroid | Not installed | First initialization | initializing | SessionNotStarted | SessionStarting | SessionStarted | | ------ | ------ | ------ | ------ | ------ | ------ | | ![Copie_d_écran_20250705_162112](/uploads/66844057ee6c955803288993809616fa/Copie_d_écran_20250705_162112.png) | ![Copie_d_écran_20250707_234822](/uploads/133779f8d4a70551a321938a7193aa3d/Copie_d_écran_20250707_234822.png) | ![Copie_d_écran_20250707_234829](/uploads/bacecd42875e3afd48dba2f9472b0f13/Copie_d_écran_20250707_234829.png) | ![Copie_d_écran_20250707_234908](/uploads/c6eff9833e33f30797088e327fcf6ea3/Copie_d_écran_20250707_234908.png) | ![Copie_d_écran_20250707_234919](/uploads/1927e2334d7e3b5790e5fab9037feff7/Copie_d_écran_20250707_234919.png) | ![Copie_d_écran_20250707_235239](/uploads/9be45b0a7b5f988de0e9ac297a2447c8/Copie_d_écran_20250707_235239.png) | Linked to https://invent.kde.org/teams/plasma-mobile/issues/-/issues/307 **Note for Reviewer**: In my local environment, i need to add manually the KAuth files otherwise polkit not recognize the implementation. ``` sudo cp ~/kde/usr/share/dbus-1/system-services/org.kde.plasma.mobileshell.waydroidhelper.service /usr/share/dbus-1/system-services/ sudo cp ~/kde/usr/share/dbus-1/system.d/org.kde.plasma.mobileshell.waydroidhelper.conf /usr/share/dbus-1/system.d/ sudo cp ~/kde/usr/share/polkit-1/actions/org.kde.plasma.mobileshell.waydroidhelper.policy /usr/share/polkit-1/actions/ ```
2025-07-10 16:00:41 +00:00
/*
* SPDX-FileCopyrightText: 2025 Florian RICHER <florian.richer@protonmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "waydroidhelper_debug.h"
#include <KAuth/ActionReply>
#include <KAuth/HelperSupport>
#include <QDebug>
#include <QFile>
#include <QFileInfo>
#include <QLoggingCategory>
#include <QObject>
#include <QProcess>
using namespace Qt::StringLiterals;
#define WAYDROID_COMMAND "waydroid"
class WaydroidHelper : public QObject
{
Q_OBJECT
public Q_SLOTS:
KAuth::ActionReply initialize(const QVariantMap &args);
};
KAuth::ActionReply WaydroidHelper::initialize(const QVariantMap &args)
{
const QString systemType = args.value("systemType"_L1).toString();
const QString romType = args.value("romType"_L1).toString();
const bool forced = args.value("forced"_L1, false).toBool();
QStringList arguments{u"init"_s, u"-s"_s, systemType, u"-r"_s, romType};
if (forced) {
arguments << "-f";
}
QProcess *process = new QProcess(this);
process->start(WAYDROID_COMMAND, arguments);
process->waitForFinished();
if (process->exitCode() == 0) {
return KAuth::ActionReply::SuccessReply();
} else {
QByteArray errorData = process->readAllStandardError();
QString errorString = QString::fromUtf8(errorData);
qCWarning(WAYDROIDHELPER) << "Failed to initialize Waydroid: " << errorString;
KAuth::ActionReply reply = KAuth::ActionReply::HelperErrorReply();
reply.setErrorDescription(errorString);
return reply;
}
}
KAUTH_HELPER_MAIN("org.kde.plasma.mobileshell.waydroidhelper", WaydroidHelper)
#include "waydroidhelper.moc"