Skip to content

Commit 93133cc

Browse files
epinterGerrit Code Review
authored and
Gerrit Code Review
committed
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
1 parent b305452 commit 93133cc

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

liblog/Android.mk

+5
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,20 @@ LOCAL_LDLIBS := -lpthread
6464
LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -m64
6565
include $(BUILD_HOST_STATIC_LIBRARY)
6666

67+
ifeq ($(TARGET_USES_MOTOROLA_LOG),true)
68+
LIBLOG_CFLAGS := -DMOTOROLA_LOG
69+
endif
6770

6871
# Shared and static library for target
6972
# ========================================================
7073
include $(CLEAR_VARS)
74+
LOCAL_CFLAGS += $(LIBLOG_CFLAGS)
7175
LOCAL_MODULE := liblog
7276
LOCAL_SRC_FILES := $(liblog_sources)
7377
include $(BUILD_STATIC_LIBRARY)
7478

7579
include $(CLEAR_VARS)
80+
LOCAL_CFLAGS += $(LIBLOG_CFLAGS)
7681
LOCAL_MODULE := liblog
7782
LOCAL_WHOLE_STATIC_LIBRARIES := liblog
7883
include $(BUILD_SHARED_LIBRARY)

liblog/logd_write.c

+96
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
#include <stdlib.h>
2626
#include <stdarg.h>
2727

28+
#ifdef MOTOROLA_LOG
29+
#if HAVE_LIBC_SYSTEM_PROPERTIES
30+
#include <sys/system_properties.h>
31+
#endif
32+
#endif
33+
2834
#include <cutils/logger.h>
2935
#include <cutils/logd.h>
3036
#include <cutils/log.h>
@@ -87,6 +93,96 @@ int __htclog_print_private(int a1, const char *a2, const char *fmt, ...)
8793
}
8894
#endif
8995

96+
#ifdef MOTOROLA_LOG
97+
/* Fallback when there is neither log.tag.<tag> nor log.tag.DEFAULT.
98+
* this is compile-time defaulted to "info". The log startup code
99+
* looks at the build tags to see about whether it should be DEBUG...
100+
* -- just as is done in frameworks/base/core/jni/android_util_Log.cpp
101+
*/
102+
static int prio_fallback = ANDROID_LOG_INFO;
103+
104+
/*
105+
* public interface so native code can see "should i log this"
106+
* and behave similar to java Log.isLoggable() calls.
107+
*
108+
* NB: we have (level,tag) here to match the other __android_log entries.
109+
* The Java side uses (tag,level) for its ordering.
110+
* since the args are (int,char*) vs (char*,char*) we won't get strange
111+
* swapped-the-strings errors.
112+
*/
113+
114+
#define LOGGING_PREFIX "log.tag."
115+
#define LOGGING_DEFAULT "log.tag.DEFAULT"
116+
117+
int __android_log_loggable(int prio, const char *tag)
118+
{
119+
int nprio;
120+
121+
#if HAVE_LIBC_SYSTEM_PROPERTIES
122+
char keybuf[PROP_NAME_MAX];
123+
char results[PROP_VALUE_MAX];
124+
int n;
125+
126+
/* we can NOT cache the log.tag.<tag> and log.tag.DEFAULT
127+
* values because either one can be changed dynamically.
128+
*
129+
* damn, says the performance compulsive.
130+
*/
131+
132+
n = 0;
133+
results[0] = '\0';
134+
if (tag) {
135+
memcpy (keybuf, LOGGING_PREFIX, strlen (LOGGING_PREFIX) + 1);
136+
/* watch out for buffer overflow */
137+
strncpy (keybuf + strlen (LOGGING_PREFIX), tag,
138+
sizeof (keybuf) - strlen (LOGGING_PREFIX));
139+
keybuf[sizeof (keybuf) - 1] = '\0';
140+
n = __system_property_get (keybuf, results);
141+
}
142+
if (n == 0) {
143+
/* nothing yet, look for the global */
144+
memcpy (keybuf, LOGGING_DEFAULT, sizeof (LOGGING_DEFAULT));
145+
n = __system_property_get (keybuf, results);
146+
}
147+
148+
if (n == 0) {
149+
nprio = prio_fallback;
150+
} else {
151+
switch (results[0])
152+
{
153+
case 'E':
154+
nprio = ANDROID_LOG_ERROR;
155+
break;
156+
case 'W':
157+
nprio = ANDROID_LOG_WARN;
158+
break;
159+
case 'I':
160+
nprio = ANDROID_LOG_INFO;
161+
break;
162+
case 'D':
163+
nprio = ANDROID_LOG_DEBUG;
164+
break;
165+
case 'V':
166+
nprio = ANDROID_LOG_VERBOSE;
167+
break;
168+
case 'S':
169+
nprio = ANDROID_LOG_SILENT;
170+
break;
171+
default:
172+
/* unspecified or invalid */
173+
nprio = prio_fallback;
174+
break;
175+
}
176+
}
177+
#else
178+
/* no system property routines, fallback to a default */
179+
nprio = prio_fallback;
180+
#endif
181+
182+
return ((prio >= nprio) ? 1 : 0);
183+
}
184+
#endif
185+
90186
static int __write_to_log_null(log_id_t log_fd, struct iovec *vec, size_t nr)
91187
{
92188
return -1;

0 commit comments

Comments
 (0)