Do not start edit monitor under cog workspace

Edit monitor for cog workspace is not supported, stop the edit monitor
directly if it identifies the cog environment.

Test: atest daemon_manager_test
Bug: 365617369
Change-Id: I0113983b917490bcc0e5a92d6539626b4dbec6d8
diff --git a/tools/edit_monitor/daemon_manager.py b/tools/edit_monitor/daemon_manager.py
index 445d849..892c292 100644
--- a/tools/edit_monitor/daemon_manager.py
+++ b/tools/edit_monitor/daemon_manager.py
@@ -70,6 +70,10 @@
       logging.warning("Block sign found, exiting...")
       return
 
+    if self.binary_path.startswith('/google/cog/'):
+      logging.warning("Edit monitor for cog is not supported, exiting...")
+      return
+
     self._stop_any_existing_instance()
     self._write_pid_to_pidfile()
     self._start_daemon_process()
diff --git a/tools/edit_monitor/daemon_manager_test.py b/tools/edit_monitor/daemon_manager_test.py
index d62eade..72442c6 100644
--- a/tools/edit_monitor/daemon_manager_test.py
+++ b/tools/edit_monitor/daemon_manager_test.py
@@ -131,6 +131,13 @@
     # Verify no daemon process is started.
     self.assertIsNone(dm.daemon_process)
 
+  def test_start_return_directly_if_in_cog_env(self):
+    dm = daemon_manager.DaemonManager(
+        '/google/cog/cloud/user/workspace/edit_monitor')
+    dm.start()
+    # Verify no daemon process is started.
+    self.assertIsNone(dm.daemon_process)
+
   @mock.patch('os.kill')
   def test_start_failed_to_kill_existing_instance(self, mock_kill):
     mock_kill.side_effect = OSError('Unknown OSError')