adb_host: Wait for package service & map product name to target.

* Updated install_apk to wait for the package service to be running.
* Update get_board_name to check a product to build target map.

BUG=b:27934416,b:27804717
TEST=Used test_droid and a custom test to verify functionality.

Change-Id: Ie898d0fc78158462ce70a1fe154cc724302bc0c7
Reviewed-on: https://chromium-review.googlesource.com/336904
Commit-Ready: Simran Basi <sbasi@chromium.org>
Tested-by: Simran Basi <sbasi@chromium.org>
Reviewed-by: Kris Rambish <krisr@chromium.org>
Reviewed-by: Dan Shi <dshi@google.com>
diff --git a/server/hosts/adb_host.py b/server/hosts/adb_host.py
index 52a6a50..fd01a24 100644
--- a/server/hosts/adb_host.py
+++ b/server/hosts/adb_host.py
@@ -11,6 +11,7 @@
 
 import common
 
+from autotest_lib.client.bin import utils as client_utils
 from autotest_lib.client.common_lib import error
 from autotest_lib.client.common_lib import global_config
 from autotest_lib.client.common_lib.cros import dev_server
@@ -98,6 +99,14 @@
 # All image files to be flashed to an Android device.
 ANDROID_IMAGES = ANDROID_STANDALONE_IMAGES + ANDROID_ZIPPED_IMAGES
 
+# Map of product names to build target name.
+PRODUCT_TARGET_MAP = {'dragon' : 'ryu',
+                      'flo' : 'razor',
+                      'flo_lte' : 'razorg',
+                      'gm4g_sprout' : 'seed_l8150',
+                      'flounder' : 'volantis',
+                      'flounder_lte' : 'volantisg'}
+
 # Command to provision a Brillo device.
 # os_image_dir: The full path of the directory that contains all the Android image
 # files (from the image zip file).
@@ -340,7 +349,8 @@
     def get_board_name(self):
         """Get the name of the board, e.g., shamu, dragonboard etc.
         """
-        return self.run_output('getprop %s' % BOARD_FILE)
+        product = self.run_output('getprop %s' % BOARD_FILE)
+        return PRODUCT_TARGET_MAP.get(product, product)
 
 
     @label_decorator()
@@ -1309,6 +1319,10 @@
 
         @returns a CMDResult object.
         """
+        client_utils.poll_for_condition(
+                lambda: self.run('pm list packages',
+                                 ignore_status=True).exit_status == 0,
+                timeout=120)
         return self.adb_run('install %s -d %s' %
                             ('-r' if force_reinstall else '', apk))