Make install.py print device name for each message in -a -p mode.

- Add device prefix for each adb subprocess message. This makes
  it possible to know which device failed the install.

Change-Id: I4a116e17df1073913abfb6dd9fee1c9ef1e62ed9
diff --git a/android/scripts/common.py b/android/scripts/common.py
index cc66dce..241cecf 100644
--- a/android/scripts/common.py
+++ b/android/scripts/common.py
@@ -110,10 +110,20 @@
 	if retcode != 0:
 		raise Exception("Failed to execute '%s', got %d" % (str(args), retcode))
 
-def execArgsInDirectory (args, cwd):
-	# Make sure previous stdout prints have been written out.
-	sys.stdout.flush()
-	process = subprocess.Popen(args, cwd=cwd)
+def execArgsInDirectory (args, cwd, linePrefix=""):
+
+	def readApplyPrefixAndPrint (source, prefix, sink):
+		while True:
+			line = source.readline()
+			if len(line) == 0: # EOF
+				break;
+			sink.write(prefix + line)
+
+	process = subprocess.Popen(args, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+	stdoutJob = threading.Thread(target=readApplyPrefixAndPrint, args=(process.stdout, linePrefix, sys.stdout))
+	stderrJob = threading.Thread(target=readApplyPrefixAndPrint, args=(process.stdout, linePrefix, sys.stderr))
+	stdoutJob.start()
+	stderrJob.start()
 	retcode = process.wait()
 	if retcode != 0:
 		raise Exception("Failed to execute '%s', got %d" % (str(args), retcode))
diff --git a/android/scripts/install.py b/android/scripts/install.py
index 89e60f5..1bf63fd 100644
--- a/android/scripts/install.py
+++ b/android/scripts/install.py
@@ -32,7 +32,7 @@
 	common.execArgsInDirectory([common.ADB_BIN] + extraArgs + [
 			'uninstall',
 			'com.drawelements.deqp'
-		], common.ANDROID_DIR)
+		], common.ANDROID_DIR, printPrefix)
 	print printPrefix + "Remove complete\n",
 
 	print printPrefix + "Installing dEQP Package...\n",
@@ -40,11 +40,15 @@
 			'install',
 			'-r',
 			'package/bin/dEQP-debug.apk'
-		], common.ANDROID_DIR)
+		], common.ANDROID_DIR, printPrefix)
 	print printPrefix + "Install complete\n",
 
 def installToDevice (device, printPrefix=""):
-	print printPrefix + "Installing to %s (%s)...\n" % (device.serial, device.model),
+	if len(printPrefix) == 0:
+		print "Installing to %s (%s)...\n" % (device.serial, device.model),
+	else:
+		print printPrefix + "Installing to %s\n" % device.serial,
+
 	install(['-s', device.serial], printPrefix)
 
 def installToAllDevices (doParallel):