Skip to content

Commit 9cd59b7

Browse files
committed
feat: [Update Delivery] Merge update delivery related functionality into Control Center update client
Integrate the update delivery logic from v20 into the v25 Control Center update module: Add an update delivery master switch in the Control Center update advanced settings interface. When the switch is enabled, the interface displays two sub-items: Update Delivery - Upload Speed Limit and Update Delivery - Download Speed Limit. Each sub-item has its own control switch and speed limit input field. Simultaneously, call the relevant SetP2pEnable interface of lastore-daemon, which will attempt to start the upgrade-delivery system service during the next update check of lastore. The switches and input fields for Update Delivery - Upload Speed Limit and Update Delivery - Download Speed Limit independently control the enabling/disabling of upload/download speed limits and their specific values. These values are set by calling the SetDeliveryUploadSpeedLimit and SetDeliveryDownloadSpeedLimit interfaces of lastore-daemon, which are then applied by lastore. The update delivery speed limit configuration supports backend-driven busy/idle time speed limit policies via the update platform. When such policies are active, the Control Center will gray out the Update Delivery - Upload Speed Limit and Update Delivery - Download Speed Limit sub-items accordingly, preventing user modifications. Each operation on the master switch triggers a refresh of the status values for various sub-items. The status values are read from the upgrade-delivery service. Log: Integrate v20 update delivery functionality into v25 Task: https://pms.uniontech.com/task-view-387713.html Influence: New update delivery logic added to the Control Center update module feat: 【更新传递】控制中心更新客户端合入更新传递相关功能 v20的更新传递逻辑合入v25控制中心更新模块 1.添加更新传递总开关在控制中心更新高级设置界面。当开关打开时,界面展示更新传递-上传限速、更新传递-下载限速两个子项,每个子项有各自的控制开关和限速值输入框,同时调用lastore-daemon的SetP2pEnable相关接口,在lastore的下次检查更新时尝试拉起upgrade-delivery系统服务 2.更新传递-上传限速、更新传递-下载限速两个子项的开关和输入框各自控制上传、下载限速的开启和关闭以及具体数值,具体通过调用lastore-daemon的SetDeliveryUploadSpeedLimit和SetDeliveryDownloadSpeedLimit接口交由lastore来实际设置值。 3.更新传递的限速配置支持通过更新平台后端下发忙闲时的限速策略,此时控制中心会根据这一策略适时置灰更新传递-上传限速、更新传递-下载限速两个子项,禁止用户修改 4.每次操作总开关时会适时的刷新各种子项的状态值,具体是从upgrade-delivery服务中读取对应的属性值 Log: v20更新传递功能合入v25 Task: https://pms.uniontech.com/task-view-387713.html Influence: 控制中心更新模块新增更新传递逻辑
1 parent 80a07bc commit 9cd59b7

19 files changed

Lines changed: 853 additions & 157 deletions
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
#include "updateassistant.h"
5+
6+
UpdateAssistant::UpdateAssistant(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
7+
: QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
8+
, d_ptr(new UpdateAssistantPrivate)
9+
{
10+
QDBusConnection::systemBus().connect("org.deepin.upgradedelivery", "/org/deepin/upgradedelivery", "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(onPropertyChanged(QString, QVariantMap, QStringList)));
11+
}
12+
13+
UpdateAssistant::~UpdateAssistant()
14+
{
15+
}
16+
17+
void UpdateAssistant::onPropertyChanged(const QString& interfaceName,
18+
const QVariantMap& changedProperties,
19+
const QStringList& invalidatedProperties)
20+
{
21+
if (interfaceName != staticInterfaceName())
22+
return;
23+
24+
if (changedProperties.contains("UploadLimitSpeed")) {
25+
Q_EMIT UploadLimitSpeedChanged(uploadLimitSpeed());
26+
}
27+
if (changedProperties.contains("DownloadLimitSpeed")) {
28+
Q_EMIT DownloadLimitSpeedChanged(downloadLimitSpeed());
29+
}
30+
31+
return;
32+
}
33+
34+
void UpdateAssistant::CallQueued(const QString &callName, const QList<QVariant> &args)
35+
{
36+
if (d_ptr->m_waittingCalls.contains(callName)) {
37+
d_ptr->m_waittingCalls[callName] = args;
38+
return;
39+
}
40+
if (d_ptr->m_processingCalls.contains(callName)) {
41+
d_ptr->m_waittingCalls.insert(callName, args);
42+
} else {
43+
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(asyncCallWithArgumentList(callName, args));
44+
connect(watcher, &QDBusPendingCallWatcher::finished, this, &UpdateAssistant::onPendingCallFinished);
45+
d_ptr->m_processingCalls.insert(callName, watcher);
46+
}
47+
}
48+
49+
void UpdateAssistant::onPendingCallFinished(QDBusPendingCallWatcher *w)
50+
{
51+
if (!w)
52+
return;
53+
w->deleteLater();
54+
const auto callName = d_ptr->m_processingCalls.key(w);
55+
Q_ASSERT(!callName.isEmpty());
56+
if (callName.isEmpty())
57+
return;
58+
d_ptr->m_processingCalls.remove(callName);
59+
if (!d_ptr->m_waittingCalls.contains(callName))
60+
return;
61+
const auto args = d_ptr->m_waittingCalls.take(callName);
62+
CallQueued(callName, args);
63+
}

src/common/dbus/updateassistant.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
#ifndef UPDATEASSISTANT_H
5+
#define UPDATEASSISTANT_H
6+
7+
#include <QtCore/QObject>
8+
#include <QtCore/QByteArray>
9+
#include <QtCore/QList>
10+
#include <QtCore/QMap>
11+
#include <QtCore/QString>
12+
#include <QtCore/QStringList>
13+
#include <QtCore/QVariant>
14+
#include <QtDBus/QtDBus>
15+
16+
class UpdateAssistantPrivate
17+
{
18+
public:
19+
UpdateAssistantPrivate() = default;
20+
21+
public:
22+
QMap<QString, QDBusPendingCallWatcher *> m_processingCalls;
23+
QMap<QString, QList<QVariant>> m_waittingCalls;
24+
};
25+
26+
/*
27+
* Proxy class for interface org.deepin.updateassistant
28+
*/
29+
class UpdateAssistant: public QDBusAbstractInterface
30+
{
31+
Q_OBJECT
32+
public:
33+
static inline const char *staticInterfaceName()
34+
{ return "org.deepin.upgradedelivery"; }
35+
36+
public:
37+
UpdateAssistant(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr);
38+
39+
~UpdateAssistant();
40+
41+
Q_PROPERTY(QString UploadLimitSpeed READ uploadLimitSpeed NOTIFY UploadLimitSpeedChanged)
42+
inline QString uploadLimitSpeed() const
43+
{ return qvariant_cast<QString>(internalPropGet("UploadLimitSpeed")); }
44+
45+
Q_PROPERTY(QString DownloadLimitSpeed READ downloadLimitSpeed NOTIFY DownloadLimitSpeedChanged)
46+
inline QString downloadLimitSpeed() const
47+
{ return qvariant_cast<QString>(internalPropGet("DownloadLimitSpeed")); }
48+
49+
public Q_SLOTS: // METHODS
50+
51+
inline QDBusPendingReply<void> SetUploadRateLimit(int speed)
52+
{
53+
QList<QVariant> argumentList;
54+
argumentList << QVariant::fromValue(speed);
55+
return asyncCallWithArgumentList(QStringLiteral("SetUploadRateLimit"), argumentList);
56+
}
57+
58+
inline QDBusPendingReply<void> SetDownloadRateLimit(int speed)
59+
{
60+
QList<QVariant> argumentList;
61+
argumentList << QVariant::fromValue(speed);
62+
return asyncCallWithArgumentList(QStringLiteral("SetDownloadRateLimit"), argumentList);
63+
}
64+
65+
Q_SIGNALS: // SIGNALS
66+
// begin property changed signals
67+
void propertyChanged(const QString &propertyName, const QVariant &value);
68+
void UploadLimitSpeedChanged(const QString & speed) const;
69+
void DownloadLimitSpeedChanged(const QString & speed) const;
70+
71+
public Q_SLOTS:
72+
void CallQueued(const QString &callName, const QList<QVariant> &args);
73+
74+
private Q_SLOTS:
75+
void onPendingCallFinished(QDBusPendingCallWatcher *w);
76+
void onPropertyChanged(const QString& interfaceName,
77+
const QVariantMap& changedProperties,
78+
const QStringList& invalidatedProperties);
79+
80+
private:
81+
UpdateAssistantPrivate *d_ptr;
82+
};
83+
84+
#endif // UPDATEASSISTANT_H

src/common/dbus/updatedbusproxy.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ QString UpdateDBusProxy::updateStatus()
207207
return qvariant_cast<QString>(m_managerInter->property("UpdateStatus"));
208208
}
209209

210+
bool UpdateDBusProxy::p2PUpdateEnable()
211+
{
212+
return qvariant_cast<bool>(m_managerInter->property("P2PUpdateEnable"));
213+
}
214+
215+
bool UpdateDBusProxy::p2PUpdateSupport()
216+
{
217+
return qvariant_cast<bool>(m_managerInter->property("P2PUpdateSupport"));
218+
}
219+
210220
bool UpdateDBusProxy::immutableAutoRecovery()
211221
{
212222
return qvariant_cast<bool>(m_managerInter->property("ImmutableAutoRecovery"));
@@ -387,6 +397,36 @@ QDBusPendingReply<QString> UpdateDBusProxy::GetUpdateLogs(int updateType)
387397
return m_managerInter->asyncCallWithArgumentList(QStringLiteral("GetUpdateLogs"), argumentList);
388398
}
389399

400+
QDBusPendingReply<void> UpdateDBusProxy::SetUpgradeDeliveryEnable(bool enable)
401+
{
402+
qCDebug(logCommon) << "Setting upgrade delivery enable :" << enable;
403+
QList<QVariant> argumentList;
404+
argumentList << QVariant::fromValue(enable);
405+
return m_updateInter->asyncCallWithArgumentList(QStringLiteral("SetP2PUpdateEnable"), argumentList);
406+
}
407+
408+
QDBusPendingReply<void> UpdateDBusProxy::SetUpgradeDeliveryDownloadSpeedLimit(const QString& downloadLimit)
409+
{
410+
qCDebug(logCommon) << "Setting upgrade delivery download speed limit : " << downloadLimit;
411+
QList<QVariant> argumentList;
412+
argumentList << QVariant::fromValue(downloadLimit);
413+
return m_updateInter->asyncCallWithArgumentList(QStringLiteral("SetDeliveryDownloadSpeedLimit"), argumentList);
414+
}
415+
416+
QDBusPendingReply<void> UpdateDBusProxy::SetUpgradeDeliveryUploadSpeedLimit(const QString& uploadLimit)
417+
{
418+
qCDebug(logCommon) << "Setting upgrade delivery upload speed limit : " << uploadLimit;
419+
QList<QVariant> argumentList;
420+
argumentList << QVariant::fromValue(uploadLimit);
421+
return m_updateInter->asyncCallWithArgumentList(QStringLiteral("SetDeliveryUploadSpeedLimit"), argumentList);
422+
}
423+
424+
QDBusPendingReply<void> UpdateDBusProxy::ClearUpgradeDeliveryCache()
425+
{
426+
qCDebug(logCommon) << "Clearing upgrade delivery cache";
427+
return m_updateInter->asyncCall(QStringLiteral("CleanTransmissionFiles"));
428+
}
429+
390430
QDBusPendingReply<void> UpdateDBusProxy::SetIdleDownloadConfig(const QString& config)
391431
{
392432
qCDebug(logCommon) << "Setting idle download config:" << config;

src/common/dbus/updatedbusproxy.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class UpdateDBusProxy : public QObject
7070
Q_PROPERTY(bool ImmutableAutoRecovery READ immutableAutoRecovery NOTIFY ImmutableAutoRecoveryChanged)
7171
bool immutableAutoRecovery();
7272

73+
Q_PROPERTY(bool P2PUpdateEnable READ p2PUpdateEnable NOTIFY P2PUpdateEnableChanged)
74+
bool p2PUpdateEnable();
75+
76+
Q_PROPERTY(bool P2PUpdateSupport READ p2PUpdateSupport NOTIFY P2PUpdateSupportChanged)
77+
bool p2PUpdateSupport();
78+
7379
QString hardwareId();
7480

7581
quint64 checkUpdateMode();
@@ -103,6 +109,10 @@ class UpdateDBusProxy : public QObject
103109
QDBusPendingReply<void> SetDownloadSpeedLimit(const QString &config);
104110
QDBusPendingReply<qlonglong> QueryAllSizeWithSource(int updateType);
105111
QDBusPendingReply<QString> GetUpdateLogs(int updateType);
112+
QDBusPendingReply<void> SetUpgradeDeliveryEnable(bool enable);
113+
QDBusPendingReply<void> SetUpgradeDeliveryDownloadSpeedLimit(const QString& downloadLimit);
114+
QDBusPendingReply<void> SetUpgradeDeliveryUploadSpeedLimit(const QString& uploadLimit);
115+
QDBusPendingReply<void> ClearUpgradeDeliveryCache();
106116
QDBusPendingReply<void> SetIdleDownloadConfig(const QString &config);
107117
QDBusPendingReply<QDBusObjectPath> PrepareDistUpgradePartly(int updateMode);
108118
QDBusPendingReply<QDBusObjectPath> fixError(const QString &errorType);
@@ -137,6 +147,7 @@ class UpdateDBusProxy : public QObject
137147
void AutoInstallUpdatesChanged(bool value) const;
138148
void AutoInstallUpdateTypeChanged(qulonglong value) const;
139149
void MirrorSourceChanged(const QString &value) const;
150+
void UpgradeDeliveryEnabledChanged(bool value) const;
140151
void AutoCheckUpdatesChanged(bool value) const;
141152
void ClassifiedUpdatablePackagesChanged(LastoreUpdatePackagesInfo value) const;
142153

@@ -146,6 +157,8 @@ class UpdateDBusProxy : public QObject
146157
void UpdateModeChanged(qulonglong value) const;
147158
void UpdateStatusChanged(QString value) const;
148159
void ImmutableAutoRecoveryChanged(bool value) const;
160+
void P2PUpdateEnableChanged(bool value) const;
161+
void P2PUpdateSupportChanged(bool value) const;
149162
void managerInterServiceValidChanged(bool value) const;
150163

151164
// Power

src/dcc-update-plugin/operation/updatedatastructs.h

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2011 - 2023 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2011-2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -65,12 +65,14 @@ struct IdleDownloadConfig {
6565
struct DownloadSpeedLimitConfig {
6666
bool downloadSpeedLimitEnabled = false;
6767
QString limitSpeed = "10240";
68+
bool isOnlineSpeedLimit = false;
6869

6970
QString toJson() const
7071
{
7172
QJsonObject obj;
7273
obj.insert("DownloadSpeedLimitEnabled", downloadSpeedLimitEnabled);
7374
obj.insert("LimitSpeed", limitSpeed);
75+
obj.insert("IsOnlineSpeedLimit", isOnlineSpeedLimit);
7476
QJsonDocument doc;
7577
doc.setObject(obj);
7678
return doc.toJson();
@@ -89,11 +91,130 @@ struct DownloadSpeedLimitConfig {
8991
QJsonObject obj = doc.object();
9092
config.downloadSpeedLimitEnabled = obj.contains("DownloadSpeedLimitEnabled") ? obj.value("DownloadSpeedLimitEnabled").toBool() : false;
9193
config.limitSpeed = obj.contains("LimitSpeed") ? obj.value("LimitSpeed").toString() : "10240";
94+
config.isOnlineSpeedLimit = obj.contains("IsOnlineSpeedLimit") ? obj.value("IsOnlineSpeedLimit").toBool() : false;
9295

9396
return config;
9497
}
9598
};
9699

100+
/**
101+
* @brief 通过lastore修改upgrade服务限速配置的数据结构
102+
*/
103+
struct LastoreUpgradeSpeedLimitConfig {
104+
bool speedLimitEnabled = false;
105+
QString limitSpeed = "10240";
106+
bool isOnlineSpeedLimit = false;
107+
108+
QString toJson() const
109+
{
110+
QJsonObject obj;
111+
obj.insert("SpeedLimitEnabled", speedLimitEnabled);
112+
obj.insert("LimitSpeed", limitSpeed);
113+
obj.insert("IsOnlineSpeedLimit", isOnlineSpeedLimit);
114+
QJsonDocument doc;
115+
doc.setObject(obj);
116+
return doc.toJson();
117+
}
118+
119+
static LastoreUpgradeSpeedLimitConfig fromJson(const QByteArray& configStr)
120+
{
121+
LastoreUpgradeSpeedLimitConfig config;
122+
QJsonParseError jsonParseError;
123+
const QJsonDocument doc = QJsonDocument::fromJson(configStr, &jsonParseError);
124+
if (jsonParseError.error != QJsonParseError::NoError || doc.isEmpty()) {
125+
qWarning() << "Parse download speed limit config failed: " << jsonParseError.errorString();
126+
return config;
127+
}
128+
129+
QJsonObject obj = doc.object();
130+
config.speedLimitEnabled = obj.contains("SpeedLimitEnabled") ? obj.value("SpeedLimitEnabled").toBool() : false;
131+
config.limitSpeed = obj.contains("LimitSpeed") ? obj.value("LimitSpeed").toString() : "10240";
132+
config.isOnlineSpeedLimit = obj.contains("IsOnlineSpeedLimit") ? obj.value("IsOnlineSpeedLimit").toBool() : false;
133+
134+
return config;
135+
}
136+
};
137+
138+
/**
139+
* @brief 传递优化upgrade服务上传下载限速配置
140+
*/
141+
struct UpgradeSpeedLimitConfig {
142+
int currentRate = 102400;
143+
int limitRate = 102400;
144+
int limitType = 0; // 限速类型
145+
int rateType = 0; // 速率类型
146+
int speed = 10240; // 速度值
147+
QDateTime startTime; // 开始时间
148+
QDateTime endTime; // 结束时间
149+
150+
bool ifInOnlineLimit() const {
151+
if (limitType != 3) {
152+
return false;
153+
}
154+
155+
if (!startTime.isValid() || !endTime.isValid()) {
156+
return false;
157+
}
158+
159+
QDateTime currentTime = QDateTime::currentDateTime();
160+
return currentTime >= startTime && currentTime <= endTime;
161+
}
162+
163+
bool shouldLimitRate() const {
164+
if (ifInOnlineLimit()) {
165+
return true;
166+
}
167+
return limitType == 1;
168+
}
169+
170+
QString toJson() const
171+
{
172+
QJsonObject obj;
173+
obj.insert("CurrentRate", currentRate);
174+
obj.insert("LimitRate", limitRate);
175+
obj.insert("LimitType", limitType);
176+
obj.insert("RateType", rateType);
177+
obj.insert("Speed", speed);
178+
obj.insert("StartTime", startTime.toString(Qt::ISODate));
179+
obj.insert("EndTime", endTime.toString(Qt::ISODate));
180+
181+
QJsonDocument doc;
182+
doc.setObject(obj);
183+
return doc.toJson();
184+
}
185+
186+
static UpgradeSpeedLimitConfig fromJson(const QByteArray& configStr)
187+
{
188+
UpgradeSpeedLimitConfig config;
189+
QJsonParseError jsonParseError;
190+
const QJsonDocument doc = QJsonDocument::fromJson(configStr, &jsonParseError);
191+
192+
if (jsonParseError.error != QJsonParseError::NoError || doc.isEmpty()) {
193+
// qCWarning(logDccUpdatePlugin) << "Parse upgrade speed limit config failed: " << jsonParseError.errorString();
194+
return config;
195+
}
196+
197+
QJsonObject obj = doc.object();
198+
config.currentRate = obj.contains("CurrentRate") ? obj.value("CurrentRate").toInt() : 10240;
199+
config.limitRate = obj.contains("LimitRate") ? obj.value("LimitRate").toInt() : 10240;
200+
config.limitType = obj.contains("LimitType") ? obj.value("LimitType").toInt() : 0;
201+
config.rateType = obj.contains("RateType") ? obj.value("RateType").toInt() : 0;
202+
config.speed = obj.contains("Speed") ? obj.value("Speed").toInt() : 10240;
203+
204+
if (obj.contains("StartTime") && obj.value("StartTime").isString()) {
205+
QString startTimeStr = obj.value("StartTime").toString();
206+
config.startTime = QDateTime::fromString(startTimeStr, Qt::ISODate);
207+
}
208+
209+
if (obj.contains("EndTime") && obj.value("EndTime").isString()) {
210+
QString endTimeStr = obj.value("EndTime").toString();
211+
config.endTime = QDateTime::fromString(endTimeStr, Qt::ISODate);
212+
}
213+
214+
return config;
215+
}
216+
};
217+
97218
struct LastoreDaemonUpdateStatus {
98219
UpdatesStatus backupStatus = UpdatesStatus::Default;
99220
UpdateErrorType backupError = UpdateErrorType::NoError;

0 commit comments

Comments
 (0)