adb: create shell protocol class (take 2).

Adds a new class ShellProtocol to help read and write data with
`adb shell`. This will allow splitting streams and sending out-of-band
data such as exit codes.

Nothing uses the new class yet except the unit tests.

This is the second attempt at this CL, the first is at
http://r.android.com/169600. The problems was using sighandler_t
which is not available on mac. sig_t is used instead which is available
due to _GNU_SOURCE being defined in Android.mk, which causes
_BSD_SOURCE -> __USE_BSD -> sig_t to be defined. Nothing else has been
changed from the original CL.

Bug: http://b/23030641
Change-Id: I7bd7f5a82ad811fbca7a3eee1236d2c55ae57c48
diff --git a/adb/Android.mk b/adb/Android.mk
index 7789035..b0dcfac 100644
--- a/adb/Android.mk
+++ b/adb/Android.mk
@@ -131,6 +131,8 @@
 LOCAL_SRC_FILES := \
     $(LIBADB_TEST_SRCS) \
     $(LIBADB_TEST_linux_SRCS) \
+    shell_service_protocol.cpp \
+    shell_service_protocol_test.cpp \
 
 LOCAL_SANITIZE := $(adb_target_sanitize)
 LOCAL_STATIC_LIBRARIES := libadbd
@@ -145,7 +147,12 @@
 LOCAL_CFLAGS := -DADB_HOST=1 $(LIBADB_CFLAGS)
 LOCAL_CFLAGS_windows := $(LIBADB_windows_CFLAGS)
 LOCAL_CFLAGS_linux := $(LIBADB_linux_CFLAGS)
-LOCAL_SRC_FILES := $(LIBADB_TEST_SRCS) services.cpp
+LOCAL_SRC_FILES := \
+    $(LIBADB_TEST_SRCS) \
+    services.cpp \
+    shell_service_protocol.cpp \
+    shell_service_protocol_test.cpp \
+
 LOCAL_SRC_FILES_linux := $(LIBADB_TEST_linux_SRCS)
 LOCAL_SRC_FILES_darwin := $(LIBADB_TEST_darwin_SRCS)
 LOCAL_SANITIZE := $(adb_host_sanitize)
@@ -201,6 +208,7 @@
     adb_client.cpp \
     services.cpp \
     file_sync_client.cpp \
+    shell_service_protocol.cpp \
 
 LOCAL_CFLAGS += \
     $(ADB_COMMON_CFLAGS) \
@@ -249,6 +257,7 @@
     remount_service.cpp \
     set_verity_enable_state_service.cpp \
     shell_service.cpp \
+    shell_service_protocol.cpp \
 
 LOCAL_CFLAGS := \
     $(ADB_COMMON_CFLAGS) \