Merge "testframework: systrace c interface changes"
diff --git a/Android.mk b/Android.mk
index b47ec26..aa978ed 100644
--- a/Android.mk
+++ b/Android.mk
@@ -17,6 +17,12 @@
 
 ifdef TARGET_USES_TESTFRAMEWORK
 LOCAL_CFLAGS := -DCUSTOM_EVENTS_TESTFRAMEWORK
+
+ifeq ($(call is-platform-sdk-version-at-least,18),true)
+# JB MR2 or later
+LOCAL_CFLAGS += -DJB_MR2=1
+endif
+
 LOCAL_C_INCLUDES := $(TOP)/vendor/qcom/opensource/testframework
 LOCAL_C_INCLUDES += $(TOP)/frameworks/native/include
 LOCAL_SRC_FILES += \
diff --git a/inc/systracer.h b/inc/systracer.h
index 429a172..4bee5be 100644
--- a/inc/systracer.h
+++ b/inc/systracer.h
@@ -34,7 +34,14 @@
 extern "C" {
 #endif
 
+/*Note: Google came up with c interface for tracer in mr2, can be used
+ *      directly instead of below interface, keeping for compatability
+ *      with older code
+ */
+
+
 // These tags must be kept in sync with frameworks/native/include/utils/Trace.h.
+#ifndef ATRACE_TAG_NEVER
 #define ATRACE_TAG_NEVER            0       // The "never" tag is never enabled.
 #define ATRACE_TAG_ALWAYS           (1<<0)  // The "always" tag is always enabled.
 #define ATRACE_TAG_GRAPHICS         (1<<1)
@@ -48,6 +55,7 @@
 #define ATRACE_TAG_VIDEO            (1<<9)
 #define ATRACE_TAG_CAMERA           (1<<10)
 #define ATRACE_TAG_LAST             ATRACE_TAG_CAMERA
+#endif
 
 //not implemented
 #ifdef ATRACE_CALL
@@ -71,7 +79,9 @@
 #endif
 #define ATRACE_ENABLED() isTagEnabled(ATRACE_TAG)
 
+#undef ATRACE_BEGIN
 #define ATRACE_BEGIN traceBegin
+#undef ATRACE_END
 #define ATRACE_END traceEnd
 
 void traceBegin(uint64_t tag, const char* name);
diff --git a/inc/testframework.h b/inc/testframework.h
index dd83dd1..ce20521 100644
--- a/inc/testframework.h
+++ b/inc/testframework.h
@@ -64,12 +64,12 @@
 
 #define TF_WRITE_IF(cond, buf) \
     ( (CONDITION(cond)) \
-    ? TF_WRITE(buf) \
+    ? (void) TF_WRITE(buf) \
     : (void)0 )
 
 #define TF_PRINT_IF(cond, eventtype, eventgrp, eventid, ...)  \
           ( (CONDITION(cond)) \
-           ? TF_PRINT(eventtype, eventgrp, eventid, __VA_ARGS__) \
+           ? (void) TF_PRINT(eventtype, eventgrp, eventid, __VA_ARGS__) \
            : (void)0 )
 #define TF_TURNON() tf_turnon()
 #define TF_TURNOFF() tf_turnoff()
diff --git a/src/Systracer.cpp b/src/Systracer.cpp
index c741039..7ad786e 100644
--- a/src/Systracer.cpp
+++ b/src/Systracer.cpp
@@ -30,23 +30,43 @@
 #include <utils/Trace.h>
 #include "../inc/systracer.h"
 
+/*Note: Google came up with c interface for tracer in mr2, can be used
+ *      directly instead of below interface
+ */
+
 void traceBegin(uint64_t tag, const char* name) {
+  #if JB_MR2
+  atrace_begin(tag, name);
+  #else
   android::Tracer::traceBegin(tag, name);
+  #endif
   return;
 }
 
 void traceEnd(uint64_t tag) {
+  #if JB_MR2
+  atrace_end(tag);
+  #else
   android::Tracer::traceEnd(tag);
+  #endif
   return;
 }
 
 void traceCounter(uint64_t tag, const char* name, int32_t value) {
+  #if JB_MR2
+  atrace_int(tag, name, value);
+  #else
   android::Tracer::traceCounter(tag, name, value);
+  #endif
   return;
 }
 
 int isTagEnabled(uint64_t tag) {
+  #if JB_MR2
+  return atrace_is_tag_enabled(tag);
+  #else
   return android::Tracer::isTagEnabled(tag);
+  #endif
 }