根据我之前的 SO 问题,我仍在努力通过 Java 应用程序中的 dbus 控制 NetworkManager。我想激活现有的无线连接,所以这是我的代码,尽可能地去除无关紧要:
DBusInterface iface = ...;
var nmIface = (NetworkManagerIface) instance.getRemoteObject(NetworkManagerIface._NM_IFACE, NetworkManagerIface._NM_PATH, NetworkManagerIface.class);
System.out.println("Attempting connection to " + iface.getObjectPath());
var result = nmIface.ActivateConnection(new DBusPath(iface.getObjectPath()), new DBusPath("/"), new DBusPath("/"));
System.out.println("Activate Connection " + result.getPath());
这里在NetworkManagerIface
哪里。这运行正常并打印:
Attempting connection to /org/freedesktop/NetworkManager/Settings/4
Activate Connection /org/freedesktop/NetworkManager/ActiveConnection/4
所以看起来调用成功了ActivateConnection
,因为它返回了一些合理的东西。但是,该命令nmcli c show
将连接显示为未使用。
NetworkManager 在我们的系统中拥有八个连接:
# dbus-send --system --print-reply --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/Settings org.freedesktop.DBus.Properties.Get string:org.freedesktop.NetworkManager.Settings string:Connections
method return time=1575940954.061910 sender=:1.8 -> destination=:1.70 serial=9361 reply_serial=2
variant array [
object path "/org/freedesktop/NetworkManager/Settings/2"
object path "/org/freedesktop/NetworkManager/Settings/7"
object path "/org/freedesktop/NetworkManager/Settings/3"
object path "/org/freedesktop/NetworkManager/Settings/5"
object path "/org/freedesktop/NetworkManager/Settings/4"
object path "/org/freedesktop/NetworkManager/Settings/8"
object path "/org/freedesktop/NetworkManager/Settings/1"
object path "/org/freedesktop/NetworkManager/Settings/6"
]
现有连接是有线(以太网)连接,我想添加无线连接。为什么我的ActivateConnection
电话不这样做?