Only emit login-visible on ChromeOS device

Goofy presenter is designed to run not only on ChromeOS devices but also
on other Linux devices. Let's not emit ChromeOS-specific login-visible
event if the presenter is not running on ChromeOS devices.

BUG=None
TEST=unit test

Change-Id: Ied6bed031b7cca39c08f9ab24deda517fdc4c33f
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/211032
diff --git a/py/toolkit/installer.py b/py/toolkit/installer.py
index 9edb70b..e9eb632 100755
--- a/py/toolkit/installer.py
+++ b/py/toolkit/installer.py
@@ -15,12 +15,12 @@
 import argparse
 from contextlib import contextmanager
 import os
-import re
 import sys
 import tempfile
 
 import factory_common  # pylint: disable=W0611
 from cros.factory.test import factory
+from cros.factory.test import utils
 from cros.factory.tools import install_symlinks
 from cros.factory.tools.mount_partition import MountPartition
 from cros.factory.utils.process_utils import Spawn
@@ -77,6 +77,10 @@
 -----
 """
 
+# The method to determine whether running on Chrome OS device or not.
+# Override this for unit testing.
+_in_cros_device = utils.in_cros_device
+
 
 class FactoryToolkitInstaller():
   """Factory toolkit installer.
@@ -102,17 +106,12 @@
       self._var_dest = os.path.join(dest, 'var')
 
       # Make sure we're on a CrOS device.
-      lsb_release = self._ReadLSBRelease()
-      is_cros = (
-        lsb_release and
-        re.match('^CHROMEOS_RELEASE', lsb_release, re.MULTILINE) is not None)
-
-      if not is_cros:
+      if not _in_cros_device():
         sys.stderr.write(
-            "ERROR: You're not on a CrOS device (/etc/lsb-release does not\n"
-            "contain CHROMEOS_RELEASE), so you must specify a test image or a\n"
-            "mounted stateful partition on which to install the factory\n"
-            "toolkit.  Please run\n"
+            "ERROR: You're not on a CrOS device (for more details, please\n"
+            "check utils.py:in_cros_device), so you must specify a test\n"
+            "image or a mounted stateful partition on which to install the\n"
+            "factory toolkit.  Please run\n"
             "\n"
             "  install_factory_toolkit.run -- --help\n"
             "\n"
@@ -148,15 +147,6 @@
       raise Exception(
           'This installer must be run from within the factory toolkit!')
 
-  @staticmethod
-  def _ReadLSBRelease():
-    """Returns the contents of /etc/lsb-release, or None if it does not
-    exist."""
-    if os.path.exists('/etc/lsb-release'):
-      with open('/etc/lsb-release') as f:
-        return f.read()
-    return None
-
   def WarningMessage(self, target_test_image=None):
     with open(os.path.join(self._src, 'VERSION')) as f:
       ret = f.read()