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 <QClipboard>
#include <QDebug> #include <QDebug>
#include <QDir>
#include <QGuiApplication> #include <QGuiApplication>
#include <QProcess> #include <QProcess>
#include <QRegularExpression> #include <QRegularExpression>
@ -28,12 +29,14 @@ using namespace Qt::StringLiterals;
static const QRegularExpression sessionRegExp(u"Session:\\s*(\\w+)"_s); 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 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) WaydroidState::WaydroidState(QObject *parent)
: QObject{parent} : QObject{parent}
{ {
// Connect it-self to auto-refresh when required status has changed // Connect it-self to auto-refresh when required status has changed
connect(this, &WaydroidState::statusChanged, this, &WaydroidState::refreshSessionInfo); connect(this, &WaydroidState::statusChanged, this, &WaydroidState::refreshSessionInfo);
connect(this, &WaydroidState::statusChanged, this, &WaydroidState::refreshInstallationInfo);
connect(this, &WaydroidState::sessionStatusChanged, this, &WaydroidState::refreshPropsInfo); connect(this, &WaydroidState::sessionStatusChanged, this, &WaydroidState::refreshPropsInfo);
refreshSupportsInfo(); refreshSupportsInfo();
@ -63,6 +66,33 @@ void WaydroidState::refreshSupportsInfo()
Q_EMIT statusChanged(); 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() void WaydroidState::refreshSessionInfo()
{ {
if (m_status != Initialized) { if (m_status != Initialized) {
@ -164,6 +194,9 @@ void WaydroidState::initialize(const SystemType systemType, const RomType romTyp
case SystemType::Gapps: case SystemType::Gapps:
systemTypeArg = "GAPPS"; systemTypeArg = "GAPPS";
break; break;
default:
systemTypeArg = "VANILLA";
break;
} }
QString romTypeArg; QString romTypeArg;
@ -277,6 +310,11 @@ WaydroidState::SessionStatus WaydroidState::sessionStatus() const
return m_sessionStatus; return m_sessionStatus;
} }
WaydroidState::SystemType WaydroidState::systemType() const
{
return m_systemType;
}
QString WaydroidState::ipAddress() const QString WaydroidState::ipAddress() const
{ {
return m_ipAddress; return m_ipAddress;

View file

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

View file

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