Hide Google services if is not Gapps System Type installed

This commit is contained in:
Florian RICHER 2025-07-12 14:54:24 +02:00
parent a45e9cc56e
commit 8b4b3e22e7
3 changed files with 46 additions and 1 deletions

View file

@ -9,6 +9,7 @@
#include <QClipboard>
#include <QDebug>
#include <QDir>
#include <QGuiApplication>
#include <QProcess>
#include <QRegularExpression>
@ -28,12 +29,14 @@ using namespace Qt::StringLiterals;
static const QRegularExpression sessionRegExp(u"Session:\\s*(\\w+)"_s);
static const QRegularExpression ipAdressRegExp(u"IP address:\\s*(\\d+\\.\\d+\\.\\d+\\.\\d+)"_s);
static const QRegularExpression systemOtaRegExp(u"system_ota\\s*=\\s*(\\S+)"_s);
WaydroidState::WaydroidState(QObject *parent)
: QObject{parent}
{
// Connect it-self to auto-refresh when required status has changed
connect(this, &WaydroidState::statusChanged, this, &WaydroidState::refreshSessionInfo);
connect(this, &WaydroidState::statusChanged, this, &WaydroidState::refreshInstallationInfo);
connect(this, &WaydroidState::sessionStatusChanged, this, &WaydroidState::refreshPropsInfo);
refreshSupportsInfo();
@ -63,6 +66,33 @@ void WaydroidState::refreshSupportsInfo()
Q_EMIT statusChanged();
}
void WaydroidState::refreshInstallationInfo()
{
if (m_status != Initialized) {
return;
}
QFile file("/var/lib/waydroid/waydroid.cfg");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
return;
}
QTextStream in(&file);
const QString fileContent = in.readAll();
const QString systemMatch = extractRegExp(fileContent, systemOtaRegExp);
if (systemMatch.contains("vanilla", Qt::CaseInsensitive)) {
m_systemType = Vanilla;
} else if (systemMatch.contains("gapps", Qt::CaseInsensitive)) {
m_systemType = Gapps;
} else if (systemMatch.contains("foss", Qt::CaseInsensitive)) {
m_systemType = Foss;
} else {
m_systemType = UnknownSystemType;
}
Q_EMIT systemTypeChanged();
}
void WaydroidState::refreshSessionInfo()
{
if (m_status != Initialized) {
@ -164,6 +194,9 @@ void WaydroidState::initialize(const SystemType systemType, const RomType romTyp
case SystemType::Gapps:
systemTypeArg = "GAPPS";
break;
default:
systemTypeArg = "VANILLA";
break;
}
QString romTypeArg;
@ -277,6 +310,11 @@ WaydroidState::SessionStatus WaydroidState::sessionStatus() const
return m_sessionStatus;
}
WaydroidState::SystemType WaydroidState::systemType() const
{
return m_systemType;
}
QString WaydroidState::ipAddress() const
{
return m_ipAddress;

View file

@ -25,6 +25,7 @@ class WaydroidState : public QObject
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
Q_PROPERTY(SessionStatus sessionStatus READ sessionStatus NOTIFY sessionStatusChanged)
Q_PROPERTY(SystemType systemType READ systemType NOTIFY systemTypeChanged)
Q_PROPERTY(QString ipAddress READ ipAddress NOTIFY ipAddressChanged)
Q_PROPERTY(QString androidId READ androidId NOTIFY androidIdChanged)
Q_PROPERTY(QString errorTitle READ errorTitle NOTIFY errorTitleChanged)
@ -66,7 +67,8 @@ public:
enum SystemType {
Vanilla = 0, ///< Vanilla Android system.
Foss, ///< Free and Open Source Software variant.
Gapps ///< Variant with Google Apps included.
Gapps, ///< Variant with Google Apps included.
UnknownSystemType
};
Q_ENUM(SystemType)
@ -83,6 +85,7 @@ public:
Q_ENUM(RomType)
Q_INVOKABLE void refreshSupportsInfo();
Q_INVOKABLE void refreshInstallationInfo();
Q_INVOKABLE void refreshSessionInfo();
Q_INVOKABLE void refreshAndroidId();
Q_INVOKABLE void refreshPropsInfo();
@ -94,6 +97,7 @@ public:
Status status() const;
SessionStatus sessionStatus() const;
SystemType systemType() const;
QString ipAddress() const;
QString androidId() const;
QString errorTitle() const;
@ -108,6 +112,7 @@ public:
Q_SIGNALS:
void statusChanged();
void sessionStatusChanged();
void systemTypeChanged();
void ipAddressChanged();
void multiWindowsChanged();
void suspendChanged();
@ -119,6 +124,7 @@ Q_SIGNALS:
private:
Status m_status{NotInitialized};
SessionStatus m_sessionStatus{SessionStopped};
SystemType m_systemType{SystemType::UnknownSystemType};
QString m_ipAddress{""};
QString m_errorTitle{""};
QString m_errorMessage{""};

View file

@ -43,6 +43,7 @@ ColumnLayout {
FormCard.FormButtonDelegate {
id: quickSettingsButton
visible: AIP.WaydroidState.systemType === AIP.WaydroidState.Gapps
text: i18n("Certify my device for Google Play Protect")
onClicked: kcm.push("WaydroidGooglePlayProtectConfigurationPage.qml")
}