android_adb: add Android ADB backend

The Android adbd daemon running inside Android VMs on the emulator
expect to be able to talk to a backend named "qemud:adb" (for historical
reasons).

The backend will carry out a handshake:
 1. Listen for connections from the host adb server on
    adb_port = <5555 + (2 * emulator instance id)>.
 2. Connect to the local adb server on port 5037 if it's available.
 3. Listen for and accept the beginning of the handshake with the adbd
    daemon (adbd sends 'accept' over the write).
 4. After the adb backend detects a connection on <adb_port>, it sends
    back an "ok" string to adbd.
 5. The adb backend will not send any more data over the pipe until it
    recognizes a 'start' request, which means the adbd is ready to
    receive data from the host ADB server.

Once the above process is complete, the adb backend will consume
everything it receives on the socket connected on <adb_port> and send it
over the adb pipe and will consume everything it receives over the adb
pipe and send it on the socket connected on <adb_port>.

Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---

v2
 - re-write to be more GIOChannel like
 - unify adb_backend_tcp_state into adb_backend_state
 - remove connected, fd and tag fields, just use ->chan and ->listen_chan
 - don't manually clear Source, use return during connect sequence
 - sprinkling of commentary at the salient points
 - added a bunch of asserts to ensure things stay consistent
 - try and pass around &adb_state as *bs where possible
 - squash all fprintf's into DPRINTF
 - link current active chan to adb_pipe->chan

v3
 - rm pointless wakeup and debug state

v4
 - cast to (int) and use %x format for windows

v5
 - clean-up semantics for EAGAIN/EOF behaviour
 - fix potential races with wakeOn calls
 - add adb_server_init() to explicitly start backend
ranchu: Create console and ADB ports automatically

On startup, start listening on the console and ADB ports automatically,
using the same "start at 5554 and work up until we find a pair of
ports which we can listen on" algorithm as the classic emulator.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>