Skip to content

Commit 6677c04

Browse files
committed
feat: implement optical disc sharing service
Add new D-Bus service for optical disc state and attribute sharing between processes. Replace file-based persistence with D-Bus service to enable cross-process optical disc information sharing. The service provides methods for managing burn states and attributes with proper access control and signal notifications. Key changes: 1. Added new D-Bus service org.deepin.Filemanager.OpticalShare with system bus connection 2. Implemented OpticalShareProxy for client-side D-Bus communication 3. Replaced Settings-based persistence with D-Bus service calls 4. Added proper cleanup when optical devices are removed 5. Included caller UID and timestamp tracking for security Log: Added optical disc sharing service for cross-process state management Influence: 1. Test optical disc detection and state persistence 2. Verify burn state changes are properly communicated between processes 3. Test optical device removal cleanup 4. Verify D-Bus service availability and error handling 5. Test multi-user access control and security 6. Validate signal notifications for state changes feat: 实现光盘共享服务 新增用于进程间光盘状态和属性共享的 D-Bus 服务。将基于文件的持久化存储替 换为 D-Bus 服务,以实现跨进程的光盘信息共享。该服务提供管理刻录状态和属 性的方法,具有适当的访问控制和信号通知功能。 主要变更: 1. 新增系统总线连接的 D-Bus 服务 org.deepin.Filemanager.OpticalShare 2. 实现客户端 D-Bus 通信的 OpticalShareProxy 3. 将基于 Settings 的持久化存储替换为 D-Bus 服务调用 4. 添加光盘设备移除时的正确清理机制 5. 包含调用者 UID 和时间戳跟踪以增强安全性 Log: 新增光盘共享服务,支持跨进程状态管理 Influence: 1. 测试光盘检测和状态持久化功能 2. 验证刻录状态变更在进程间正确通信 3. 测试光盘设备移除的清理机制 4. 验证 D-Bus 服务可用性和错误处理 5. 测试多用户访问控制和安全性 6. 验证状态变更的信号通知功能 Bug: https://pms.uniontech.com/bug-view-355565.html
1 parent 46386e0 commit 6677c04

24 files changed

+704
-78
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
2+
<node>
3+
<interface name="org.deepin.Filemanager.OpticalShare">
4+
<signal name="BurnStateChanged">
5+
<arg name="dev" type="s" direction="out"/>
6+
<arg name="state" type="a{sv}" direction="out"/>
7+
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/>
8+
</signal>
9+
<signal name="BurnAttributeChanged">
10+
<arg name="tag" type="s" direction="out"/>
11+
<arg name="attribute" type="a{sv}" direction="out"/>
12+
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/>
13+
</signal>
14+
<method name="GetBurnState">
15+
<arg type="a{sv}" direction="out"/>
16+
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
17+
<arg name="dev" type="s" direction="in"/>
18+
</method>
19+
<method name="GetBurnStates">
20+
<arg type="a{sv}" direction="out"/>
21+
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
22+
</method>
23+
<method name="SetBurnState">
24+
<arg type="b" direction="out"/>
25+
<arg name="dev" type="s" direction="in"/>
26+
<arg name="state" type="a{sv}" direction="in"/>
27+
<annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/>
28+
</method>
29+
<method name="ClearBurnState">
30+
<arg type="b" direction="out"/>
31+
<arg name="dev" type="s" direction="in"/>
32+
</method>
33+
<method name="GetBurnAttribute">
34+
<arg type="a{sv}" direction="out"/>
35+
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
36+
<arg name="tag" type="s" direction="in"/>
37+
</method>
38+
<method name="SetBurnAttribute">
39+
<arg type="b" direction="out"/>
40+
<arg name="tag" type="s" direction="in"/>
41+
<arg name="attribute" type="a{sv}" direction="in"/>
42+
<annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/>
43+
</method>
44+
<method name="ClearBurnAttribute">
45+
<arg type="b" direction="out"/>
46+
<arg name="tag" type="s" direction="in"/>
47+
</method>
48+
</interface>
49+
</node>

src/dfm-base/base/application/application.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(Settings, asGlobal, ("deepin/dde-file-manager/dde-file
2121

2222
Q_GLOBAL_STATIC_WITH_ARGS(Settings, gosGlobal, ("deepin/dde-file-manager.obtusely", Settings::kGenericConfig))
2323
Q_GLOBAL_STATIC_WITH_ARGS(Settings, aosGlobal, ("deepin/dde-file-manager/dde-file-manager.obtusely", Settings::kGenericConfig))
24-
25-
static constexpr char DP_GLOBAL_FILE[] { "/tmp/.config/deepin/dde-file-manager/dde-file-manager.dp" };
26-
Q_GLOBAL_STATIC_WITH_ARGS(Settings, dpGlobal, ("", "", DP_GLOBAL_FILE))
24+
Q_GLOBAL_STATIC_WITH_ARGS(Settings, dpGlobal, ("deepin/dde-file-manager/dde-file-manager.dp", Settings::kGenericConfig))
2725

2826
// blumia: since dde-desktop now also do show file selection dialog job, thus dde-desktop should share the same config file
2927
// with dde-file-manager, so we use GenericConfig with specify path to simulate AppConfig.
@@ -298,11 +296,6 @@ Settings *Application::dataPersistence()
298296
#ifndef DFM_NO_FILE_WATCHER
299297
dpGlobal->setWatchChanges(true);
300298
#endif
301-
// By default, files created under /tmp have a permission mode of 644,
302-
// which prevents new users from accessing the file after creation.
303-
// This restricts usage updates under new user accounts.
304-
QFile f(DP_GLOBAL_FILE);
305-
f.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::WriteGroup | QFile::ReadOther | QFile::WriteOther);
306299
}
307300

308301
return dpGlobal;

src/dfm-base/base/device/deviceutils.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <dfm-base/base/application/application.h>
99
#include <dfm-base/base/application/settings.h>
1010
#include <dfm-base/dbusservice/global_server_defines.h>
11+
#include <dfm-base/dbusservice/opticalshareproxy.h>
1112
#include <dfm-base/utils/finallyutil.h>
1213
#include <dfm-base/utils/universalutils.h>
1314
#include <dfm-base/utils/networkutils.h>
@@ -188,34 +189,23 @@ bool DeviceUtils::isAutoMountAndOpenEnable()
188189

189190
bool DeviceUtils::isWorkingOpticalDiscDev(const QString &dev)
190191
{
191-
static constexpr char kBurnStateGroup[] { "BurnState" };
192-
static constexpr char kWoringKey[] { "Working" };
193-
194192
if (dev.isEmpty())
195193
return false;
196194

197-
if (Application::dataPersistence()->keys(kBurnStateGroup).contains(dev)) {
198-
const QMap<QString, QVariant> &info = Application::dataPersistence()->value(kBurnStateGroup, dev).toMap();
199-
return info.value(kWoringKey).toBool();
200-
}
201-
return false;
195+
const QVariantMap info = OpticalShareProxy::instance().burnState(dev);
196+
return info.value(GlobalServerDefines::OpticalShareField::kWorking).toBool();
202197
}
203198

204199
bool DeviceUtils::isWorkingOpticalDiscId(const QString &id)
205200
{
206-
static constexpr char kBurnStateGroup[] { "BurnState" };
207-
static constexpr char kWoringKey[] { "Working" };
208-
static constexpr char kID[] { "id" };
209-
210201
if (id.isEmpty())
211202
return false;
212203

213-
auto &&keys { Application::dataPersistence()->keys(kBurnStateGroup) };
214-
for (const QString &dev : keys) {
215-
const QMap<QString, QVariant> &info = Application::dataPersistence()->value(kBurnStateGroup, dev).toMap();
216-
QString &&devID { info.value(kID).toString() };
217-
if (devID == id)
218-
return info.value(kWoringKey).toBool();
204+
const QVariantMap states = OpticalShareProxy::instance().burnStates();
205+
for (auto iter = states.cbegin(); iter != states.cend(); ++iter) {
206+
const QVariantMap info = iter.value().toMap();
207+
if (info.value(GlobalServerDefines::OpticalShareField::kId).toString() == id)
208+
return info.value(GlobalServerDefines::OpticalShareField::kWorking).toBool();
219209
}
220210

221211
return false;

src/dfm-base/base/device/private/devicehelper.cpp

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
#include "defendercontroller.h"
77

88
#include <dfm-base/dfm_global_defines.h>
9-
#include <dfm-base/dbusservice/global_server_defines.h>
10-
#include <dfm-base/base/application/application.h>
11-
#include <dfm-base/base/application/settings.h>
129
#include <dfm-base/base/device/deviceutils.h>
1310
#include <dfm-base/base/configs/dconfig/dconfigmanager.h>
1411
#include <dfm-base/dbusservice/global_server_defines.h>
12+
#include <dfm-base/dbusservice/opticalshareproxy.h>
1513
#include <dfm-base/dialogs/mountpasswddialog/mountaskpassworddialog.h>
1614
#include <dfm-base/utils/universalutils.h>
1715
#include <dfm-base/utils/dialogmanager.h>
@@ -34,12 +32,6 @@
3432
#include <dfm-burn/dburn_global.h>
3533
#include <sys/statvfs.h>
3634

37-
static constexpr char kBurnAttribute[] { "BurnAttribute" };
38-
static constexpr char kBurnTotalSize[] { "BurnTotalSize" };
39-
static constexpr char kBurnUsedSize[] { "BurnUsedSize" };
40-
static constexpr char kBurnMediaType[] { "BurnMediaType" };
41-
static constexpr char kBurnWriteSpeed[] { "BurnWriteSpeed" };
42-
4335
using namespace dfmbase;
4436

4537
namespace {
@@ -462,32 +454,39 @@ void DeviceHelper::persistentOpticalInfo(const QVariantMap &datas)
462454
QVariantMap info;
463455
QString tag { datas.value(DeviceProperty::kDevice).toString().mid(5) };
464456

465-
info[kBurnTotalSize] = datas.value(DeviceProperty::kSizeTotal);
466-
info[kBurnUsedSize] = datas.value(DeviceProperty::kSizeUsed);
467-
info[kBurnMediaType] = datas.value(DeviceProperty::kOpticalMediaType);
468-
info[kBurnWriteSpeed] = datas.value(DeviceProperty::kOpticalWriteSpeed);
457+
info[OpticalShareField::kTotalSize] = datas.value(DeviceProperty::kSizeTotal);
458+
info[OpticalShareField::kUsedSize] = datas.value(DeviceProperty::kSizeUsed);
459+
info[OpticalShareField::kMediaType] = datas.value(DeviceProperty::kOpticalMediaType);
460+
info[OpticalShareField::kWriteSpeed] = datas.value(DeviceProperty::kOpticalWriteSpeed);
469461

470-
Application::dataPersistence()->setValue(kBurnAttribute, tag, info);
471-
Application::dataPersistence()->sync();
462+
OpticalShareProxy::instance().setBurnAttribute(tag, info);
472463

473464
qCDebug(logDFMBase) << "Optical device usage info persisted for device:" << tag
474-
<< "total size:" << info[kBurnTotalSize].toULongLong()
475-
<< "used size:" << info[kBurnUsedSize].toULongLong();
465+
<< "total size:" << info[OpticalShareField::kTotalSize].toULongLong()
466+
<< "used size:" << info[OpticalShareField::kUsedSize].toULongLong();
467+
}
468+
469+
void DeviceHelper::clearOpticalInfo(const QString &tag)
470+
{
471+
if (tag.isEmpty())
472+
return;
473+
474+
OpticalShareProxy::instance().clearBurnAttribute(tag);
476475
}
477476

478477
void DeviceHelper::readOpticalInfo(QVariantMap &datas)
479478
{
480479
using namespace GlobalServerDefines;
481480
QString tag { datas.value(DeviceProperty::kDevice).toString().mid(5) };
481+
const QVariantMap info = OpticalShareProxy::instance().burnAttribute(tag);
482+
if (info.isEmpty())
483+
return;
482484

483-
if (Application::dataPersistence()->keys(kBurnAttribute).contains(tag)) {
484-
const QMap<QString, QVariant> &info = Application::dataPersistence()->value(kBurnAttribute, tag).toMap();
485-
datas[DeviceProperty::kSizeTotal] = static_cast<qint64>(info.value(kBurnTotalSize).toULongLong());
486-
datas[DeviceProperty::kSizeUsed] = static_cast<qint64>(info.value(kBurnUsedSize).toULongLong());
487-
datas[DeviceProperty::kSizeFree] = datas[DeviceProperty::kSizeTotal].toULongLong() - datas[DeviceProperty::kSizeUsed].toULongLong();
488-
datas[DeviceProperty::kOpticalMediaType] = info.value(kBurnMediaType).toInt();
489-
datas[DeviceProperty::kOpticalWriteSpeed] = info.value(kBurnWriteSpeed).toStringList();
490-
}
485+
datas[DeviceProperty::kSizeTotal] = static_cast<qint64>(info.value(OpticalShareField::kTotalSize).toULongLong());
486+
datas[DeviceProperty::kSizeUsed] = static_cast<qint64>(info.value(OpticalShareField::kUsedSize).toULongLong());
487+
datas[DeviceProperty::kSizeFree] = datas[DeviceProperty::kSizeTotal].toULongLong() - datas[DeviceProperty::kSizeUsed].toULongLong();
488+
datas[DeviceProperty::kOpticalMediaType] = info.value(OpticalShareField::kMediaType).toInt();
489+
datas[DeviceProperty::kOpticalWriteSpeed] = info.value(OpticalShareField::kWriteSpeed).toStringList();
491490
}
492491

493492
bool DeviceHelper::checkNetworkConnection(const QString &id)

src/dfm-base/base/device/private/devicehelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class DeviceHelper
6565
static QString castFromDFMMountProperty(DFMMOUNT::Property property);
6666

6767
static void persistentOpticalInfo(const QVariantMap &datas);
68+
static void clearOpticalInfo(const QString &tag);
6869
static void readOpticalInfo(QVariantMap &datas);
6970

7071
private:

src/dfm-base/base/device/private/devicewatcher.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ void DeviceWatcher::onBlkDevAdded(const QString &id)
323323
void DeviceWatcher::onBlkDevRemoved(const QString &id)
324324
{
325325
qCInfo(logDFMBase) << "Block device removed:" << id;
326+
const QString device = d->allBlockInfos.value(id).value(DeviceProperty::kDevice).toString();
327+
if (device.startsWith("/dev/"))
328+
DeviceHelper::clearOpticalInfo(device.mid(5));
326329
QString oldMpt = d->allBlockInfos.value(id).value(DeviceProperty::kMountPoint).toString();
327330
d->allBlockInfos.remove(id);
328331
emit DevMngIns->blockDevRemoved(id, oldMpt);
@@ -413,6 +416,7 @@ void DeviceWatcher::onBlkDevPropertiesChanged(const QString &id, const QMap<Prop
413416
if (name == DeviceProperty::kMountPoints)
414417
item[DeviceProperty::kMountPoint] = var.toStringList().isEmpty() ? item[DeviceProperty::kMountPoint] : var.toStringList().first();
415418
if (name == DeviceProperty::kOptical && !var.toBool()) {
419+
DeviceHelper::clearOpticalInfo(item.value(DeviceProperty::kDevice).toString().mid(5));
416420
item[DeviceProperty::kOpticalMediaType] = "";
417421
item[DeviceProperty::kOpticalWriteSpeed] = QStringList();
418422
item[DeviceProperty::kSizeTotal] = 0;

src/dfm-base/dbusservice/global_server_defines.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,28 @@ inline constexpr char kAnonymous[] { "anonymous" };
130130
inline constexpr char kMessage[] { "message" };
131131
} // namespace NetworkMountParamKey
132132

133+
namespace OpticalShareDBusInfo {
134+
inline constexpr char kService[] { "org.deepin.Filemanager.OpticalShare" };
135+
inline constexpr char kPath[] { "/org/deepin/Filemanager/OpticalShare" };
136+
inline constexpr char kInterface[] { "org.deepin.Filemanager.OpticalShare" };
137+
} // namespace OpticalShareDBusInfo
138+
139+
namespace OpticalShareGroup {
140+
inline constexpr char kBurnState[] { "BurnState" };
141+
inline constexpr char kBurnAttribute[] { "BurnAttribute" };
142+
} // namespace OpticalShareGroup
143+
144+
namespace OpticalShareField {
145+
inline constexpr char kId[] { "id" };
146+
inline constexpr char kWorking[] { "Working" };
147+
inline constexpr char kOwnerUid[] { "ownerUid" };
148+
inline constexpr char kTimestamp[] { "timestamp" };
149+
inline constexpr char kTotalSize[] { "totalSize" };
150+
inline constexpr char kUsedSize[] { "usedSize" };
151+
inline constexpr char kMediaType[] { "mediaType" };
152+
inline constexpr char kWriteSpeed[] { "writeSpeed" };
153+
} // namespace OpticalShareField
154+
133155
} // namespace GlobalServerDefines
134156

135157
#endif // GLOBAL_SERVER_DEFINES_H

0 commit comments

Comments
 (0)