Okay, I figured it out
Yes, this can be fixed in software.
Turns out that the needed functionality was already in the kernel of the Xperia X (and possibly all devices?):
echo 1 > lrc_enable
and echo 70 > lrc_socmax
instructs the kernel to stop charging at 70%.
On both devices the charging current falls to 0 when this limit is reached โ battery is neither drained nor charged while being connected to a charger.
At least as long as the device does not draw more power than provided by the charger.
See takimata / harbour-battery-charging-control ยท GitLab more details and an app automating this.
So the fact that echo 0 > charging_enabled
starts to drain the battery on the 10 II is only a kernel quirk. But the LRC charging was the stuff I wanted right from the start, so Iโm not that eager to fix the kernel any more