liblog: add local_logger

- Create the local-only logger module
- Add LOGGER_LOCAL flag to android_set_log_frontend to enable
- Permit log reader for host compilation

android_set_log_frontend(LOGGER_LOCAL) will result in logs going
into application local memory.  logcat can not retrieve the data,
the user must utilize the log reading interface directly to
acquire their own logs.  Some local logger tests dropped as they
represent testing other liblog facilities.  Other local logger
tests dropped because we make the conscious decision to not
support LOG_ID_SECURITY logging.

ToDo: Some local logger tests dropped because of missing
      functionality associated with blocking reader.

Test: gTest libcutils-tests, logd-unit-tests, liblog-unit-tests,
      logcat-unit-tests, liblog-benchmarks and CtsLiblogTestCases_list
Bug: 27405083
Change-Id: Ia23b932af9e05756eaa60bab9139876b14faf72d
diff --git a/liblog/logger_write.c b/liblog/logger_write.c
index bff77f8..e149e68 100644
--- a/liblog/logger_write.c
+++ b/liblog/logger_write.c
@@ -29,6 +29,7 @@
 #include <private/android_filesystem_config.h>
 #include <private/android_logger.h>
 
+#include "config_read.h" /* __android_log_config_read_close() definition */
 #include "config_write.h"
 #include "log_portability.h"
 #include "logger.h"
@@ -171,6 +172,8 @@
         }
     }
 
+    __android_log_config_write_close();
+
 #if defined(__ANDROID__)
     /*
      * Additional risk here somewhat mitigated by immediately unlock flushing
@@ -639,12 +642,18 @@
 
 /* Following functions need access to our internal write_to_log status */
 
+LIBLOG_HIDDEN int __android_log_frontend;
+
 LIBLOG_ABI_PUBLIC int android_set_log_frontend(int frontend_flag)
 {
+    int retval;
+
     if (frontend_flag < 0) {
         return -EINVAL;
     }
 
+    retval = LOGGER_NULL;
+
     __android_log_lock();
 
     if (frontend_flag & LOGGER_NULL) {
@@ -652,20 +661,30 @@
 
         __android_log_unlock();
 
-        return LOGGER_NULL;
+        return retval;
     }
 
-    /* Anything else, act as if LOGGER_DEFAULT */
+    __android_log_frontend &= LOGGER_LOCAL | LOGGER_LOGD;
 
+    frontend_flag &= LOGGER_LOCAL | LOGGER_LOGD;
+
+    if (__android_log_frontend != frontend_flag) {
+        __android_log_frontend = frontend_flag;
+        __android_log_config_write_close();
+        __android_log_config_read_close();
+
+        write_to_log = __write_to_log_init;
     /* generically we only expect these two values for write_to_log */
-    if ((write_to_log != __write_to_log_init) &&
-        (write_to_log != __write_to_log_daemon)) {
+    } else if ((write_to_log != __write_to_log_init) &&
+               (write_to_log != __write_to_log_daemon)) {
         write_to_log = __write_to_log_init;
     }
 
+    retval = __android_log_frontend;
+
     __android_log_unlock();
 
-    return LOGGER_DEFAULT;
+    return retval;
 }
 
 LIBLOG_ABI_PUBLIC int android_get_log_frontend()
@@ -675,9 +694,13 @@
     __android_log_lock();
     if (write_to_log == __write_to_log_null) {
         ret = LOGGER_NULL;
-    } else if ((write_to_log != __write_to_log_init) &&
-               (write_to_log != __write_to_log_daemon)) {
-        ret = -EINVAL;
+    } else {
+        __android_log_frontend &= LOGGER_LOCAL | LOGGER_LOGD;
+        ret = __android_log_frontend;
+        if ((write_to_log != __write_to_log_init) &&
+            (write_to_log != __write_to_log_daemon)) {
+            ret = -EINVAL;
+        }
     }
     __android_log_unlock();