Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
#include "wakeuputils.h"
#include "DDLog.h"

#include <QLoggingCategory>

Check warning on line 16 in deepin-devicemanager-server/deepin-devicecontrol/src/controlinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLoggingCategory> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QProcess>

Check warning on line 17 in deepin-devicemanager-server/deepin-devicecontrol/src/controlinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QProcess> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QThread>

Check warning on line 18 in deepin-devicemanager-server/deepin-devicecontrol/src/controlinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QThread> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDir>

Check warning on line 19 in deepin-devicemanager-server/deepin-devicecontrol/src/controlinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDir> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusConnection>

Check warning on line 20 in deepin-devicemanager-server/deepin-devicecontrol/src/controlinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusConnection> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFile>

Check warning on line 21 in deepin-devicemanager-server/deepin-devicecontrol/src/controlinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFile> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusConnectionInterface>

#include <polkit-qt5-1/PolkitQt1/Authority>
Expand Down Expand Up @@ -332,16 +333,24 @@
}
if (enable_device) {
/*
启用的流程为:以 /devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.0 为例
第一步: 向 /sys/devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.0/authorized 文件中写 1
第二步: 向 /sys/devices/pci0000:00/0000:00:14.0/usb1/1-5/authorized 文件中写 0
第三步: 向 /sys/devices/pci0000:00/0000:00:14.0/usb1/1-5/authorized 文件中写 1
启用流程需等价于物理拔插的「断开—重连」,使 usbhid 重新绑定、
输入节点重建,否则鼠标启用后仍无响应(PMS 341577)。
以 /devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.0 为例
(path 为接口级路径 1-5:1.0,禁用时已向其 authorized 写 0):
第一步: 向父设备 1-5/authorized 写 0,整设备去授权(断开等价),
解绑所有接口驱动并销毁输入节点。
第二步: 等待内核完成去授权清理,避免与重新授权竞态导致输入
设备无法恢复。
第三步: 向父设备 1-5/authorized 写 1,整设备重新授权(重连等价),
重新枚举并探测接口驱动。
第四步: 向接口 1-5:1.0/authorized 写 1(禁用的直接逆操作),确保
接口已授权(sysfs 条目在设备重新枚举后已重建,需重新打开)。
第五步: 触发 udev 重新处理该设备及其接口的 add 事件,模拟物理
拔插产生的 udev 事件,确保输入设备节点被重建。
*/
// 第一步
file.write("1");
file.close();

// 第二步
// 第一步:父设备去授权
QFileInfo fi(path);
QString pop = fi.path();
QFile fpop("/sys" + pop + QString("/authorized"));
Expand All @@ -350,12 +359,25 @@
fpop.write("0");
fpop.close();

// 第三步
// 第二步:等待去授权清理完成,避免去授权-重新授权竞态
QThread::msleep(100);

// 第三步:父设备重新授权
if (!fpop.open(QIODevice::ReadWrite))
return false;
fpop.write("1");
fpop.close();

// 第四步:显式重新授权接口(禁用的直接逆操作)
if (file.open(QIODevice::ReadWrite)) {
file.write("1");
file.close();
}

// 第五步:触发 udev 重新处理设备添加事件,确保输入设备节点重建
QProcess::execute("udevadm", QStringList() << "trigger"
<< "--action=add" << ("--syspath=" + QString("/sys") + pop));

EnableSqlManager::getInstance()->removeDataFromAuthorizedTable(unique_id);
} else {
file.write("0");
Expand Down
Loading