android: backport pty implementation from aosp/master

Change-Id: I4ee6e7752eab84de4566ae86a90171b8241fcaea
Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>