Disable watchdog in bazel, disable crash-log on Android < 21

- Disable the watchdog in bazel: the watchdog should not be enabled
  for SDK users, only for services. There doesn't seem to be a good
  reason for having it enabled in bazel, and it causes problems
  in Google-internal builds (See bug)
- Disable the crash-log feature on Android versions < API 19.
  We target minsdk API 21 in GN builds. However one internal
  blaze user today targets API19. For now disable the crash
  log feature doing minsdk detection until the root problem
  is solved.

Bug: 203795298
Change-Id: Ief5f4249d90620f136a03929b9d456d07ee05e4f
diff --git a/gn/perfetto.gni b/gn/perfetto.gni
index 4520087..3128050 100644
--- a/gn/perfetto.gni
+++ b/gn/perfetto.gni
@@ -175,11 +175,13 @@
         is_perfetto_build_generator
   }
 
-  # Enables base::Watchdog. Is supported only on Linux-based platforms.
+  # Enables base::Watchdog. Is supported only on Linux-based platforms in
+  # standalone GN builds (NOT in bazel/blaze).
   # gn/BUILD.gn further restricts this to OS_LINUX || OS_ANDROID when generating
   # the perfetto_build_flags.h header.
   enable_perfetto_watchdog =
-      perfetto_build_with_android || perfetto_build_standalone
+      perfetto_build_with_android ||
+      (perfetto_build_standalone && !is_perfetto_build_generator)
 
   # Misc host executable under tools/.
   enable_perfetto_tools =
diff --git a/include/perfetto/base/build_configs/bazel/perfetto_build_flags.h b/include/perfetto/base/build_configs/bazel/perfetto_build_flags.h
index e08a103..dba06b3 100644
--- a/include/perfetto/base/build_configs/bazel/perfetto_build_flags.h
+++ b/include/perfetto/base/build_configs/bazel/perfetto_build_flags.h
@@ -26,7 +26,7 @@
 #define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_STANDALONE_BUILD() (1)
 #define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_START_DAEMONS() (1)
 #define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_IPC() (1)
-#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_WATCHDOG() (PERFETTO_BUILDFLAG_DEFINE_PERFETTO_OS_ANDROID() || PERFETTO_BUILDFLAG_DEFINE_PERFETTO_OS_LINUX())
+#define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_WATCHDOG() (0)
 #define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_COMPONENT_BUILD() (0)
 #define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_FORCE_DLOG_ON() (0)
 #define PERFETTO_BUILDFLAG_DEFINE_PERFETTO_FORCE_DLOG_OFF() (0)
diff --git a/include/perfetto/base/logging.h b/include/perfetto/base/logging.h
index 7e991df..eaa5710 100644
--- a/include/perfetto/base/logging.h
+++ b/include/perfetto/base/logging.h
@@ -67,9 +67,15 @@
 // on Android in-tree builds and on standalone builds (mainly for testing).
 // This is deliberately no PERFETTO_OS_ANDROID because we don't want this
 // feature when perfetto is embedded in other Android projects (e.g. SDK).
-#if !defined(PERFETTO_ANDROID_ASYNC_SAFE_LOG) &&   \
-    (PERFETTO_BUILDFLAG(PERFETTO_ANDROID_BUILD) || \
-     PERFETTO_BUILDFLAG(PERFETTO_STANDALONE_BUILD))
+// TODO(b/203795298): TFLite is using the client library in blaze builds and is
+// targeting API 19. For now disable the feature based on API level.
+#if defined(PERFETTO_ANDROID_ASYNC_SAFE_LOG)
+#define PERFETTO_ENABLE_LOG_RING_BUFFER() 0
+#elif PERFETTO_BUILDFLAG(PERFETTO_ANDROID_BUILD)
+#define PERFETTO_ENABLE_LOG_RING_BUFFER() 1
+#elif PERFETTO_BUILDFLAG(PERFETTO_STANDALONE_BUILD) && \
+    (!PERFETTO_BUILDFLAG(PERFETTO_OS_ANDROID) ||       \
+     (defined(__ANDROID_API__) && __ANDROID_API__ >= 21))
 #define PERFETTO_ENABLE_LOG_RING_BUFFER() 1
 #else
 #define PERFETTO_ENABLE_LOG_RING_BUFFER() 0
diff --git a/tools/gen_bazel b/tools/gen_bazel
index 9257d75..dd847ed 100755
--- a/tools/gen_bazel
+++ b/tools/gen_bazel
@@ -40,7 +40,6 @@
     'host_os="linux"',
     'is_debug=false',
     'is_perfetto_build_generator=true',
-    'enable_perfetto_watchdog=true',
     'monolithic_binaries=true',
     'target_os="linux"',
     'enable_perfetto_heapprofd=false',