Escape newlines in `-v printable`. am: 522baf2487 am: 9d25de7017

Original change: https://android-review.googlesource.com/c/platform/system/logging/+/2860428

Change-Id: I9f0933c00a197f57bedd53bf726b89e110aa569e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/logd/LogStatistics.cpp b/logd/LogStatistics.cpp
index 173b733..5295495 100644
--- a/logd/LogStatistics.cpp
+++ b/logd/LogStatistics.cpp
@@ -111,14 +111,21 @@
 }
 
 void LogStatistics::AddTotal(log_id_t log_id, uint16_t size) {
-    auto lock = std::lock_guard{lock_};
+    if (!enable) {
+        return;
+    }
 
+    auto lock = std::lock_guard{lock_};
     mSizesTotal[log_id] += size;
     SizesTotal += size;
     ++mElementsTotal[log_id];
 }
 
 void LogStatistics::Add(LogStatisticsElement element) {
+    if (!enable) {
+        return;
+    }
+
     auto lock = std::lock_guard{lock_};
 
     if (!track_total_size_) {
@@ -181,6 +188,10 @@
 }
 
 void LogStatistics::Subtract(LogStatisticsElement element) {
+    if (!enable) {
+        return;
+    }
+
     auto lock = std::lock_guard{lock_};
 
     if (!track_total_size_) {
@@ -231,6 +242,10 @@
 
 // caller must own and free character string
 const char* LogStatistics::UidToNameLocked(uid_t uid) const {
+    if (!enable) {
+        return strdup("logd");
+    }
+
     // Local hard coded favourites
     if (uid == AID_LOGD) {
         return strdup("auditd");
@@ -572,6 +587,10 @@
 }
 
 std::string LogStatistics::ReportInteresting() const {
+    if (!enable) {
+        return std::string("");
+    }
+
     auto lock = std::lock_guard{lock_};
 
     std::vector<std::string> items;
@@ -597,6 +616,10 @@
 }
 
 std::string LogStatistics::Format(uid_t uid, pid_t pid, unsigned int logMask) const {
+    if (!enable) {
+        return std::string("");
+    }
+
     auto lock = std::lock_guard{lock_};
 
     static const uint16_t spaces_total = 19;
diff --git a/logd/main.cpp b/logd/main.cpp
index 9c270a0..83d3d0f 100644
--- a/logd/main.cpp
+++ b/logd/main.cpp
@@ -108,13 +108,21 @@
 }
 
 // GetBoolProperty that defaults to true if `ro.debuggable == true && ro.config.low_rawm == false`.
-static bool GetBoolPropertyEngSvelteDefault(const std::string& name) {
+static bool GetBoolPropertyDebuggableSvelteDefault(const std::string& name) {
     bool default_value =
             GetBoolProperty("ro.debuggable", false) && !GetBoolProperty("ro.config.low_ram", false);
 
     return GetBoolProperty(name, default_value);
 }
 
+// GetBoolProperty that defaults to true if `ro.build.type == eng && ro.config.low_rawm == false`.
+static bool GetBoolPropertyEngSvelteDefault(const std::string& name) {
+    bool default_value = (GetProperty("ro.build.type", "user").compare("eng") == 0) &&
+                         !GetBoolProperty("ro.config.low_ram", false);
+
+    return GetBoolProperty(name, default_value);
+}
+
 static void readDmesg(LogAudit* al, LogKlog* kl) {
     if (!al && !kl) {
         return;
@@ -219,7 +227,7 @@
     }
 
     int fdPmesg = -1;
-    bool klogd = GetBoolPropertyEngSvelteDefault("ro.logd.kernel");
+    bool klogd = GetBoolPropertyDebuggableSvelteDefault("ro.logd.kernel");
     if (klogd) {
         SetProperty("ro.logd.kernel", "true");
         static const char proc_kmsg[] = "/proc/kmsg";