logd: Drop the LogStatistics dependency on LogBufferElement

Other log buffers may not use LogBufferElement, so we should decouple
the two classes.  This uses an intermediate LogStatisticsElement
structs instead of passing a large number of parameters to each
function.

This additionally moves IsBinary() and the GetTag() functions out into
LogUtils.h since they can be used generically by other users.

Test: logging unit tests
Change-Id: I71f53257342c067bcccd5aa00bae47f714cd7c66
diff --git a/logd/LogBufferElement.cpp b/logd/LogBufferElement.cpp
index 172a757..ef9f1cf 100644
--- a/logd/LogBufferElement.cpp
+++ b/logd/LogBufferElement.cpp
@@ -86,7 +86,7 @@
 
 uint32_t LogBufferElement::GetTag() const {
     // Binary buffers have no tag.
-    if (!IsBinary()) {
+    if (!IsBinary(log_id())) {
         return 0;
     }
 
@@ -95,12 +95,21 @@
         return tag_;
     }
 
-    // For non-dropped messages, we get the tag from the message header itself.
-    if (msg_len_ < sizeof(android_event_header_t)) {
-        return 0;
-    }
+    return MsgToTag(msg(), msg_len());
+}
 
-    return reinterpret_cast<const android_event_header_t*>(msg_)->tag;
+LogStatisticsElement LogBufferElement::ToLogStatisticsElement() const {
+    return LogStatisticsElement{
+            .uid = uid(),
+            .pid = pid(),
+            .tid = tid(),
+            .tag = GetTag(),
+            .realtime = realtime(),
+            .msg = msg(),
+            .msg_len = msg_len(),
+            .dropped_count = dropped_count(),
+            .log_id = log_id(),
+    };
 }
 
 uint16_t LogBufferElement::SetDropped(uint16_t value) {
@@ -218,7 +227,7 @@
                           type, dropped_count(), (dropped_count() > 1) ? "s" : "");
 
     size_t hdrLen;
-    if (IsBinary()) {
+    if (IsBinary(log_id())) {
         hdrLen = sizeof(android_log_event_string_t);
     } else {
         hdrLen = 1 + sizeof(tag);
@@ -232,7 +241,7 @@
     }
 
     size_t retval = hdrLen + len;
-    if (IsBinary()) {
+    if (IsBinary(log_id())) {
         android_log_event_string_t* event =
             reinterpret_cast<android_log_event_string_t*>(buffer);