They manage it with the Apple PSUs somehow.
The airline DC adapter is set to output a specific voltage that tells the Mac to not charge the battery.
The proper PSUs step the voltage up and down depending on the current load from the laptop. This is what alters the green/orange LED in the adapter plug. When the laptop is charging the battery the current is higher, the PSU steps up the voltage ad turns the orange LED on. When charging has finished the curtsy draw goes down, the PSU steps the voltage down, which turs out orange LED and lights the green one.
So with only two wires it is possible for the laptop and PSU to alter their behaviour I response to each other.