Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3b38376 authored by Emerson Pinter's avatar Emerson Pinter Committed by Gerrit Code Review
Browse files

liblog: add required function

Some Motorola proprietaries require a function named __android_log_loggable. This
change adds the function and solves problems with radio and other
binaries on qualcomm based Motorola phones. This code is activated with
TARGET_USES_MOTOROLA_LOG:=true

Change-Id: I722b42d34198c027f265c3cf9f220d9798814915
parent 10766dbb
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -64,15 +64,20 @@ LOCAL_LDLIBS := -lpthread
LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -m64
include $(BUILD_HOST_STATIC_LIBRARY)

ifeq ($(TARGET_USES_MOTOROLA_LOG),true)
LIBLOG_CFLAGS := -DMOTOROLA_LOG
endif

# Shared and static library for target
# ========================================================
include $(CLEAR_VARS)
LOCAL_CFLAGS += $(LIBLOG_CFLAGS)
LOCAL_MODULE := liblog
LOCAL_SRC_FILES := $(liblog_sources)
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_CFLAGS += $(LIBLOG_CFLAGS)
LOCAL_MODULE := liblog
LOCAL_WHOLE_STATIC_LIBRARIES := liblog
include $(BUILD_SHARED_LIBRARY)
+96 −0
Original line number Diff line number Diff line
@@ -25,6 +25,12 @@
#include <stdlib.h>
#include <stdarg.h>

#ifdef MOTOROLA_LOG
#if HAVE_LIBC_SYSTEM_PROPERTIES
#include <sys/system_properties.h>
#endif
#endif

#include <cutils/logger.h>
#include <cutils/logd.h>
#include <cutils/log.h>
@@ -87,6 +93,96 @@ int __htclog_print_private(int a1, const char *a2, const char *fmt, ...)
}
#endif

#ifdef MOTOROLA_LOG
/* Fallback when there is neither log.tag.<tag> nor log.tag.DEFAULT.
 * this is compile-time defaulted to "info". The log startup code
 * looks at the build tags to see about whether it should be DEBUG...
 * -- just as is done in frameworks/base/core/jni/android_util_Log.cpp
 */
static int prio_fallback = ANDROID_LOG_INFO;

/*
 * public interface so native code can see "should i log this"
 * and behave similar to java Log.isLoggable() calls.
 *
 * NB: we have (level,tag) here to match the other __android_log entries.
 * The Java side uses (tag,level) for its ordering.
 * since the args are (int,char*) vs (char*,char*) we won't get strange
 * swapped-the-strings errors.
 */

#define	LOGGING_PREFIX	"log.tag."
#define	LOGGING_DEFAULT	"log.tag.DEFAULT"

int __android_log_loggable(int prio, const char *tag)
{
    int nprio;

#if	HAVE_LIBC_SYSTEM_PROPERTIES
    char keybuf[PROP_NAME_MAX];
    char results[PROP_VALUE_MAX];
    int n;

    /* we can NOT cache the log.tag.<tag> and log.tag.DEFAULT
     * values because either one can be changed dynamically.
     *
     * damn, says the performance compulsive.
     */

    n = 0;
    results[0] = '\0';
    if (tag) {
	memcpy (keybuf, LOGGING_PREFIX, strlen (LOGGING_PREFIX) + 1);
	/* watch out for buffer overflow */
	strncpy (keybuf + strlen (LOGGING_PREFIX), tag,
		 sizeof (keybuf) - strlen (LOGGING_PREFIX));
	keybuf[sizeof (keybuf) - 1] = '\0';
	n = __system_property_get (keybuf, results);
    }
    if (n == 0) {
	/* nothing yet, look for the global */
	memcpy (keybuf, LOGGING_DEFAULT, sizeof (LOGGING_DEFAULT));
	n = __system_property_get (keybuf, results);
    }

    if (n == 0) {
	nprio = prio_fallback;
    } else {
	switch (results[0])
	{
	case 'E':
	    nprio = ANDROID_LOG_ERROR;
	    break;
	case 'W':
	    nprio = ANDROID_LOG_WARN;
	    break;
	case 'I':
	    nprio = ANDROID_LOG_INFO;
	    break;
	case 'D':
	    nprio = ANDROID_LOG_DEBUG;
	    break;
	case 'V':
	    nprio = ANDROID_LOG_VERBOSE;
	    break;
	case 'S':
	    nprio = ANDROID_LOG_SILENT;
	    break;
	default:
	    /* unspecified or invalid */
	    nprio = prio_fallback;
	    break;
	}
    }
#else
    /* no system property routines, fallback to a default */
    nprio = prio_fallback;
#endif

    return ((prio >= nprio) ? 1 : 0);
}
#endif

static int __write_to_log_null(log_id_t log_fd, struct iovec *vec, size_t nr)
{
    return -1;