diff --git a/README.md b/README.md index 148b8e68df..7636624664 100644 --- a/README.md +++ b/README.md @@ -251,6 +251,23 @@ looks glitchy or slow; a 710/720/722 gets it on its own) and **Zink: lazy descri try when they are slow while games are fast). The `steamdeck-tu-debug` and `steamdeck-env` files in Downloads still win over both. +## Networking and the client's own network page + +The session uses the phone's connection directly - proot makes no network namespace, so IPv4 and +IPv6 both pass through - and the app writes the runtime's `/etc/resolv.conf` from the active +network's own DNS servers whenever the link changes. + +The client's **Settings → Internet** page and its connection indicator are a different matter: +they are built on NetworkManager, which the client looks for on the system bus as it starts. Without +one, that page stopped with *"StartScanningForNetworks is not a function"* under a header showing no +connection even while downloads ran. The session now starts a small system bus and a **stand-in that +answers for NetworkManager**, reporting what is true and nothing more - one connection that is up +while Android has a route out - and refusing what it cannot do, since nothing in this runtime can +scan for or join a network. The session log says `network: system bus up, NetworkManager stand-in +running` when it is working. + +That stand-in is **maxjivi05's**, from WinNative, by way of Bannerlator. + ## Compatibility tools **Compatibility tools** (main screen and drawer) installs GE-Proton or proton-cachyos — native diff --git a/app/build.gradle b/app/build.gradle index a336bad757..180bee3b54 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -18,8 +18,8 @@ android { // file out of its own data directory, and this app's entire job is to exec a rootfs: // proot, gamescope, the Steam client and everything it launches all live under files/. targetSdkVersion 28 - versionCode 3 - versionName "0.1.2" + versionCode 4 + versionName "0.1.3" ndk { abiFilters 'arm64-v8a' diff --git a/app/src/main/java/com/steamdeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/steamdeck/launcher/session/SessionFiles.kt index 0719803d4b..2ade38db07 100644 --- a/app/src/main/java/com/steamdeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/steamdeck/launcher/session/SessionFiles.kt @@ -33,6 +33,7 @@ object SessionFiles { "usr/local/bin/bannerlator-steam-library" to "usr/local/bin/bannerlator-steam-library", "usr/local/bin/bannerlator-seed-redists" to "usr/local/bin/bannerlator-seed-redists", "usr/local/bin/bannerlator-proton-extra" to "usr/local/bin/bannerlator-proton-extra", + "usr/local/bin/bannerlator-netmanager" to "usr/local/bin/bannerlator-netmanager", ) // The desktop's launcher and labwc defaults, only where the desktop package is installed: // staging them into a runtime without it would make the desktop look present when it is not. diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-netmanager b/tools/linuxfs/overlay/usr/local/bin/bannerlator-netmanager new file mode 100755 index 0000000000..f47fe058c3 --- /dev/null +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-netmanager @@ -0,0 +1,246 @@ +#!/usr/bin/python3 +# Ported from WinNative (maxjivi05, feature/wayland-gamescope e7a224ae), GPL-3.0, with thanks. +# Renamed again for this app; the answers themselves are his. +# +# Answers for NetworkManager on the runtime's system bus, for the Steam client: +# bannerlator-netmanager +# +# The client's network page and its connection indicator are built on NetworkManager. It asks for +# one over the system bus as it starts, and without an answer it leaves out half of what its +# interface then calls: Settings > Internet stops with "StartScanningForNetworks is not a function" +# and the header shows no connection while downloads run. +# +# The network here is Android's: the app has no say in Wi-Fi, and nothing in this runtime could +# scan or join one. So this reports what is true and no more - one connection that is up while +# Android has a route out, under the address the app was given - and refuses what it cannot do. +import socket +import sys + +import gi + +gi.require_version("Gio", "2.0") +from gi.repository import Gio, GLib # noqa: E402 + +NAME = "org.freedesktop.NetworkManager" +ROOT = "/org/freedesktop/NetworkManager" +SETTINGS = ROOT + "/Settings" +DEVICE = ROOT + "/Devices/1" +ACTIVE = ROOT + "/ActiveConnection/1" +IP4 = ROOT + "/IP4Config/1" +PROFILE = SETTINGS + "/1" +UUID = "b1d0c8e4-57f0-4c0e-9d60-77696e6e6174" +CHECK_SECONDS = 10 + +# NetworkManager's own numbers. +NM_STATE_DISCONNECTED, NM_STATE_CONNECTED_GLOBAL = 20, 70 +NM_CONNECTIVITY_NONE, NM_CONNECTIVITY_FULL = 1, 4 +NM_DEVICE_TYPE_ETHERNET = 1 +NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_ACTIVATED = 30, 100 +NM_ACTIVE_CONNECTION_STATE_ACTIVATED = 2 + +INTROSPECTION = """ + + + + + + + + + + + + + + + + + + + + +""" + + +def address(): + """The address Android routes out by, or None without a route. Nothing is sent.""" + try: + with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: + s.connect(("192.0.2.1", 9)) + return s.getsockname()[0] + except OSError: + return None + + +def v(signature, value): + return GLib.Variant(signature, value) + + +def objects(ip): + """Every object NetworkManager would export, as its ObjectManager describes them.""" + up = ip is not None + found = { + ROOT: {NAME: { + "Devices": v("ao", [DEVICE]), + "AllDevices": v("ao", [DEVICE]), + "ActiveConnections": v("ao", [ACTIVE] if up else []), + "PrimaryConnection": v("o", ACTIVE if up else "/"), + "PrimaryConnectionType": v("s", "802-3-ethernet" if up else ""), + "ActivatingConnection": v("o", "/"), + "NetworkingEnabled": v("b", True), + "WirelessEnabled": v("b", False), + "WirelessHardwareEnabled": v("b", False), + "WwanEnabled": v("b", False), + "WwanHardwareEnabled": v("b", False), + "Startup": v("b", False), + "Version": v("s", "1.46.0"), + "State": v("u", NM_STATE_CONNECTED_GLOBAL if up else NM_STATE_DISCONNECTED), + "Connectivity": v("u", NM_CONNECTIVITY_FULL if up else NM_CONNECTIVITY_NONE), + "ConnectivityCheckAvailable": v("b", False), + "ConnectivityCheckEnabled": v("b", False), + "Metered": v("u", 0), + }}, + SETTINGS: {NAME + ".Settings": { + "Connections": v("ao", [PROFILE]), + "Hostname": v("s", socket.gethostname()), + "CanModify": v("b", False), + }}, + PROFILE: {NAME + ".Settings.Connection": { + "Unsaved": v("b", False), + "Flags": v("u", 0), + "Filename": v("s", ""), + }}, + DEVICE: { + NAME + ".Device": { + "Interface": v("s", "android"), + "IpInterface": v("s", "android" if up else ""), + "Driver": v("s", "android"), + "DeviceType": v("u", NM_DEVICE_TYPE_ETHERNET), + "State": v("u", NM_DEVICE_STATE_ACTIVATED if up else NM_DEVICE_STATE_DISCONNECTED), + "StateReason": v("(uu)", (NM_DEVICE_STATE_ACTIVATED if up else NM_DEVICE_STATE_DISCONNECTED, 0)), + "ActiveConnection": v("o", ACTIVE if up else "/"), + "Ip4Config": v("o", IP4 if up else "/"), + "Ip6Config": v("o", "/"), + "Dhcp4Config": v("o", "/"), + "Dhcp6Config": v("o", "/"), + "AvailableConnections": v("ao", [PROFILE]), + "Managed": v("b", True), + "Autoconnect": v("b", True), + "Real": v("b", True), + "Capabilities": v("u", 1), + "Mtu": v("u", 1500), + "HwAddress": v("s", ""), + }, + NAME + ".Device.Wired": { + "HwAddress": v("s", ""), + "PermHwAddress": v("s", ""), + "Speed": v("u", 0), + "Carrier": v("b", up), + }, + }, + } + if up: + found[ACTIVE] = {NAME + ".Connection.Active": { + "Connection": v("o", PROFILE), + "SpecificObject": v("o", "/"), + "Id": v("s", "Android"), + "Uuid": v("s", UUID), + "Type": v("s", "802-3-ethernet"), + "Devices": v("ao", [DEVICE]), + "State": v("u", NM_ACTIVE_CONNECTION_STATE_ACTIVATED), + "StateFlags": v("u", 0), + "Default": v("b", True), + "Ip4Config": v("o", IP4), + "Dhcp4Config": v("o", "/"), + "Default6": v("b", False), + "Ip6Config": v("o", "/"), + "Dhcp6Config": v("o", "/"), + "Vpn": v("b", False), + "Master": v("o", "/"), + }} + found[IP4] = {NAME + ".IP4Config": { + # The one address the app can see; the prefix says only that much is known. + "AddressData": v("aa{sv}", [{"address": v("s", ip), "prefix": v("u", 32)}]), + "Addresses": v("aau", []), + "Gateway": v("s", ""), + "RouteData": v("aa{sv}", []), + "Routes": v("aau", []), + "NameserverData": v("aa{sv}", []), + "Nameservers": v("au", []), + "Domains": v("as", []), + "Searches": v("as", []), + "DnsOptions": v("as", []), + "DnsPriority": v("i", 0), + "WinsServerData": v("as", []), + "WinsServers": v("au", []), + }} + return found + + +class NetworkManager: + def __init__(self, bus): + self.bus = bus + self.ip = address() + node = Gio.DBusNodeInfo.new_for_xml(INTROSPECTION) + manager, root, profile, device = node.interfaces + for path, interface in (("/org/freedesktop", manager), (ROOT, root), (PROFILE, profile), (DEVICE, device)): + bus.register_object_with_closures2(path, interface, self.call, None, None) + GLib.timeout_add_seconds(CHECK_SECONDS, self.check) + + def call(self, bus, sender, path, interface, method, args, invocation): + if method == "GetManagedObjects": + invocation.return_value(v("(a{oa{sa{sv}}})", (objects(self.ip),))) + elif method == "GetPermissions": + invocation.return_value(v("(a{ss})", ({},))) + elif method == "CheckConnectivity": + self.check() + invocation.return_value(v("(u)", (NM_CONNECTIVITY_FULL if self.ip else NM_CONNECTIVITY_NONE,))) + elif method == "GetSettings": + # The name the client shows the connection under. + invocation.return_value(v("(a{sa{sv}})", ({"connection": { + "id": v("s", "Android"), "uuid": v("s", UUID), "type": v("s", "802-3-ethernet")}},))) + else: + invocation.return_value(v("(ao)", ([DEVICE],))) + + def check(self): + """Tells the bus when Android gains or loses its route, as NetworkManager would.""" + ip = address() + if (ip is None) != (self.ip is None) or (ip and ip != self.ip): + before, after = objects(self.ip), objects(ip) + self.ip = ip + for path in before.keys() - after.keys(): + self.announce("InterfacesRemoved", path, v("(oas)", (path, list(before[path])))) + for path in after.keys() - before.keys(): + self.announce("InterfacesAdded", path, v("(oa{sa{sv}})", (path, after[path]))) + for path in after.keys() & before.keys(): + for interface, values in after[path].items(): + self.bus.emit_signal(None, path, "org.freedesktop.DBus.Properties", "PropertiesChanged", + v("(sa{sv}as)", (interface, values, []))) + state = after[ROOT][NAME]["State"].unpack() + device = after[DEVICE][NAME + ".Device"]["State"].unpack() + was = before[DEVICE][NAME + ".Device"]["State"].unpack() + self.bus.emit_signal(None, ROOT, NAME, "StateChanged", v("(u)", (state,))) + self.bus.emit_signal(None, DEVICE, NAME + ".Device", "StateChanged", v("(uuu)", (device, was, 0))) + return True + + def announce(self, signal, path, body): + self.bus.emit_signal(None, "/org/freedesktop", "org.freedesktop.DBus.ObjectManager", signal, body) + + +def main(): + loop = GLib.MainLoop() + state = {} + + def acquired(bus, name): + state["manager"] = NetworkManager(bus) + + def lost(bus, name): + print("== netmanager: the system bus is gone", file=sys.stderr) + loop.quit() + + Gio.bus_own_name(Gio.BusType.SYSTEM, NAME, Gio.BusNameOwnerFlags.NONE, acquired, None, lost) + loop.run() + + +if __name__ == "__main__": + main() diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-session b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session index 07f90b6c07..538d2050be 100755 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-session +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session @@ -264,6 +264,48 @@ case $mode in echo "== autolaunch $_bl_url" set -- "$@" "$_bl_url" fi + # The client builds Settings > Internet and its connection indicator on NetworkManager, which + # it looks for on the SYSTEM bus as it starts. This runtime has neither, so the page failed + # ("StartScanningForNetworks is not a function") under a header that showed no connection even + # while downloads ran. A system bus and a stand-in that reports Android's connection - and + # refuses what it cannot do, since the app has no say over Wi-Fi - answer what the client asks. + # The bus config is written here rather than shipped, so a runtime installed earlier gets this + # from the app's copy of the session scripts without a re-host. (WinNative, maxjivi05, e7a224ae.) + if command -v dbus-daemon >/dev/null 2>&1 && command -v bannerlator-netmanager >/dev/null 2>&1; then + mkdir -p /run/dbus /usr/local/share/bannerlator + cat > /usr/local/share/bannerlator/system-bus.conf <<'BUSCONF' + + + system + unix:path=/run/dbus/system_bus_socket + EXTERNAL + + + + + + + +BUSCONF + rm -f /run/dbus/system_bus_socket + dbus-daemon --config-file=/usr/local/share/bannerlator/system-bus.conf --nofork --nopidfile & + system_bus=$! + for _ in $(seq 1 50); do + [ -S /run/dbus/system_bus_socket ] && break + sleep 0.1 + done + if [ -S /run/dbus/system_bus_socket ]; then + bannerlator-netmanager & + netmanager=$! + echo "== network: system bus up, NetworkManager stand-in running" + else + echo "== network: the system bus did not come up; the client will show no connection" + fi + else + echo "== network: no dbus-daemon or netmanager in this runtime; the client will show no connection" + fi + export STEAM_RUNTIME=1 export LD_LIBRARY_PATH=$steam_root/steamrtarm64:$steam_root/steamrtarm64/panorama${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} export SDL_VIDEO_X11_DGAMOUSE=0