Base: Add INTERNAL_FATAL to logging severity

Add the INTERNAL_FATAL level. It will print 'F' like FATAL, but
does not abort after logging.

Add a test to logging_test.

Bug: 31338270
Test: m
Test: mmma system/core/base && adb sync && adb shell /data/nativetest/libbase_test/libbase_test32
Change-Id: Idf74c08e8516881efccaefc58fa3f41d57e56396
diff --git a/base/include/android-base/logging.h b/base/include/android-base/logging.h
index 721ecce..c626fc3 100644
--- a/base/include/android-base/logging.h
+++ b/base/include/android-base/logging.h
@@ -41,6 +41,7 @@
   INFO,
   WARNING,
   ERROR,
+  FATAL_WITHOUT_ABORT,
   FATAL,
 };
 
diff --git a/base/logging.cpp b/base/logging.cpp
index 1f47a9f..86d3b4d 100644
--- a/base/logging.cpp
+++ b/base/logging.cpp
@@ -188,14 +188,18 @@
 #if defined(__linux__)
 void KernelLogger(android::base::LogId, android::base::LogSeverity severity,
                   const char* tag, const char*, unsigned int, const char* msg) {
+  // clang-format off
   static constexpr int kLogSeverityToKernelLogLevel[] = {
-    [android::base::VERBOSE] = 7, // KERN_DEBUG (there is no verbose kernel log level)
-    [android::base::DEBUG]   = 7, // KERN_DEBUG
-    [android::base::INFO]    = 6, // KERN_INFO
-    [android::base::WARNING] = 4, // KERN_WARNING
-    [android::base::ERROR]   = 3, // KERN_ERROR
-    [android::base::FATAL]   = 2, // KERN_CRIT
+      [android::base::VERBOSE] = 7,              // KERN_DEBUG (there is no verbose kernel log
+                                                 //             level)
+      [android::base::DEBUG] = 7,                // KERN_DEBUG
+      [android::base::INFO] = 6,                 // KERN_INFO
+      [android::base::WARNING] = 4,              // KERN_WARNING
+      [android::base::ERROR] = 3,                // KERN_ERROR
+      [android::base::FATAL_WITHOUT_ABORT] = 2,  // KERN_CRIT
+      [android::base::FATAL] = 2,                // KERN_CRIT
   };
+  // clang-format on
   static_assert(arraysize(kLogSeverityToKernelLogLevel) == android::base::FATAL + 1,
                 "Mismatch in size of kLogSeverityToKernelLogLevel and values in LogSeverity");
 
@@ -235,7 +239,7 @@
   char timestamp[32];
   strftime(timestamp, sizeof(timestamp), "%m-%d %H:%M:%S", &now);
 
-  static const char log_characters[] = "VDIWEF";
+  static const char log_characters[] = "VDIWEFF";
   static_assert(arraysize(log_characters) - 1 == FATAL + 1,
                 "Mismatch in size of log_characters and values in LogSeverity");
   char severity_char = log_characters[severity];
@@ -252,8 +256,9 @@
                             const char* file, unsigned int line,
                             const char* message) {
   static constexpr android_LogPriority kLogSeverityToAndroidLogPriority[] = {
-    ANDROID_LOG_VERBOSE, ANDROID_LOG_DEBUG, ANDROID_LOG_INFO,
-    ANDROID_LOG_WARN,    ANDROID_LOG_ERROR, ANDROID_LOG_FATAL,
+      ANDROID_LOG_VERBOSE, ANDROID_LOG_DEBUG, ANDROID_LOG_INFO,
+      ANDROID_LOG_WARN,    ANDROID_LOG_ERROR, ANDROID_LOG_FATAL,
+      ANDROID_LOG_FATAL,
   };
   static_assert(arraysize(kLogSeverityToAndroidLogPriority) == FATAL + 1,
                 "Mismatch in size of kLogSeverityToAndroidLogPriority and values in LogSeverity");
@@ -325,12 +330,12 @@
           gMinimumLogSeverity = ERROR;
           continue;
         case 'f':
-          gMinimumLogSeverity = FATAL;
+          gMinimumLogSeverity = FATAL_WITHOUT_ABORT;
           continue;
         // liblog will even suppress FATAL if you say 's' for silent, but that's
         // crazy!
         case 's':
-          gMinimumLogSeverity = FATAL;
+          gMinimumLogSeverity = FATAL_WITHOUT_ABORT;
           continue;
       }
     }
diff --git a/base/logging_test.cpp b/base/logging_test.cpp
index 6a321fc..3fde302 100644
--- a/base/logging_test.cpp
+++ b/base/logging_test.cpp
@@ -122,7 +122,9 @@
 
 static std::string make_log_pattern(android::base::LogSeverity severity,
                                     const char* message) {
-  static const char* log_characters = "VDIWEF";
+  static const char log_characters[] = "VDIWEFF";
+  static_assert(arraysize(log_characters) - 1 == android::base::FATAL + 1,
+                "Mismatch in size of log_characters and values in LogSeverity");
   char log_char = log_characters[severity];
   std::string holder(__FILE__);
   return android::base::StringPrintf(
@@ -164,6 +166,14 @@
   ASSERT_DEATH({SuppressAbortUI(); LOG(FATAL) << "foobar";}, "foobar");
 }
 
+TEST(logging, LOG_FATAL_WITHOUT_ABORT_disabled) {
+  CHECK_LOG_DISABLED(FATAL_WITHOUT_ABORT);
+}
+
+TEST(logging, LOG_FATAL_WITHOUT_ABORT_enabled) {
+  CHECK_LOG_ENABLED(FATAL_WITHOUT_ABORT);
+}
+
 TEST(logging, LOG_ERROR_disabled) {
   CHECK_LOG_DISABLED(ERROR);
 }
@@ -260,6 +270,18 @@
   PLOG(severity) << "foobar"; \
   CheckMessage(cap2, android::base::severity, "foobar: No such file or directory"); \
 
+TEST(logging, PLOG_FATAL) {
+  ASSERT_DEATH({SuppressAbortUI(); PLOG(FATAL) << "foobar";}, "foobar");
+}
+
+TEST(logging, PLOG_FATAL_WITHOUT_ABORT_disabled) {
+  CHECK_PLOG_DISABLED(FATAL_WITHOUT_ABORT);
+}
+
+TEST(logging, PLOG_FATAL_WITHOUT_ABORT_enabled) {
+  CHECK_PLOG_ENABLED(FATAL_WITHOUT_ABORT);
+}
+
 TEST(logging, PLOG_ERROR_disabled) {
   CHECK_PLOG_DISABLED(ERROR);
 }