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/SimpleLogBuffer.cpp b/logd/SimpleLogBuffer.cpp
index 5ab8e09..b4b3546 100644
--- a/logd/SimpleLogBuffer.cpp
+++ b/logd/SimpleLogBuffer.cpp
@@ -61,11 +61,8 @@
     int prio = ANDROID_LOG_INFO;
     const char* tag = nullptr;
     size_t tag_len = 0;
-    if (log_id == LOG_ID_EVENTS || log_id == LOG_ID_STATS) {
-        if (len < sizeof(android_event_header_t)) {
-            return false;
-        }
-        int32_t numeric_tag = reinterpret_cast<const android_event_header_t*>(msg)->tag;
+    if (IsBinary(log_id)) {
+        int32_t numeric_tag = MsgToTag(msg, len);
         tag = tags_->tagToName(numeric_tag);
         if (tag) {
             tag_len = strlen(tag);
@@ -105,7 +102,7 @@
     log_id_t log_id = elem.log_id();
 
     logs_.emplace_back(std::move(elem));
-    stats_->Add(logs_.back());
+    stats_->Add(logs_.back().ToLogStatisticsElement());
     MaybePrune(log_id);
     reader_list_->NotifyNewLog(1 << log_id);
 }
@@ -317,7 +314,7 @@
             return true;
         }
 
-        stats_->Subtract(element);
+        stats_->Subtract(element.ToLogStatisticsElement());
         it = Erase(it);
         if (--prune_rows == 0) {
             return false;