Ignore the edits unrelated to Android dev in the edit monitor

1) Do not log edit events for files that does not belong to a git
project. 2) Do not log edit events for hidden files or files under a
hidden dir.

Test: atest edit_monitor_test
bug: 365617369
Change-Id: I73a79d9fb2ec3759ff58bded1666d68cff696353
diff --git a/tools/edit_monitor/edit_monitor.py b/tools/edit_monitor/edit_monitor.py
index 386daf7..defc841 100644
--- a/tools/edit_monitor/edit_monitor.py
+++ b/tools/edit_monitor/edit_monitor.py
@@ -17,6 +17,7 @@
 import logging
 import multiprocessing.connection
 import os
+import pathlib
 import platform
 import time
 
@@ -65,10 +66,22 @@
   def _log_edit_event(
       self, event: FileSystemEvent, edit_type: edit_event_pb2.EditEvent.EditType
   ):
-    event_time = time.time()
-
-    logging.info("%s: %s", event.event_type, event.src_path)
     try:
+      event_time = time.time()
+
+      if self._is_hidden_file(pathlib.Path(event.src_path)):
+        logging.debug("ignore hidden file: %s.", event.src_path)
+        return
+
+      if not self._is_under_git_project(pathlib.Path(event.src_path)):
+        logging.debug(
+            "ignore file %s which does not belong to a git project",
+            event.src_path,
+        )
+        return
+
+      logging.info("%s: %s", event.event_type, event.src_path)
+
       event_proto = edit_event_pb2.EditEvent(
           user_name=self.user_name,
           host_name=self.host_name,
@@ -88,6 +101,19 @@
     except Exception:
       logging.exception("Failed to log edit event.")
 
+  def _is_hidden_file(self, file_path: pathlib.Path) -> bool:
+    return any(
+        part.startswith(".")
+        for part in file_path.relative_to(self.root_monitoring_path).parts
+    )
+
+  def _is_under_git_project(self, file_path: pathlib.Path) -> bool:
+    root_path = pathlib.Path(self.root_monitoring_path).resolve()
+    return any(
+        root_path.joinpath(dir).joinpath('.git').exists()
+        for dir in file_path.relative_to(root_path).parents
+    )
+
 
 def start(
     path: str,