Update stable to r4888.

git-svn-id: http://webrtc.googlecode.com/svn/stable/talk@4889 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/app/webrtc/java/jni/peerconnection_jni.cc b/app/webrtc/java/jni/peerconnection_jni.cc
index de7e3dd..e364b3a 100644
--- a/app/webrtc/java/jni/peerconnection_jni.cc
+++ b/app/webrtc/java/jni/peerconnection_jni.cc
@@ -76,6 +76,11 @@
 #include "webrtc/video_engine/include/vie_base.h"
 #include "webrtc/voice_engine/include/voe_base.h"
 
+#ifdef ANDROID
+#include "webrtc/system_wrappers/interface/logcat_trace_context.h"
+using webrtc::LogcatTraceContext;
+#endif
+
 using icu::UnicodeString;
 using webrtc::AudioSourceInterface;
 using webrtc::AudioTrackInterface;
@@ -101,7 +106,6 @@
 using webrtc::VideoSourceInterface;
 using webrtc::VideoTrackInterface;
 using webrtc::VideoTrackVector;
-using webrtc::VideoRendererInterface;
 
 // Abort the process if |x| is false, emitting |msg|.
 #define CHECK(x, msg)                                                          \
@@ -1152,9 +1156,19 @@
     jint nativeSeverity) {
   std::string path = JavaToStdString(jni, j_path);
   if (nativeLevels != webrtc::kTraceNone) {
-    CHECK(!webrtc::Trace::SetTraceFile(path.c_str(), false),
-          "SetTraceFile failed");
     webrtc::Trace::set_level_filter(nativeLevels);
+#ifdef ANDROID
+    if (path != "logcat:") {
+#endif
+      CHECK(webrtc::Trace::SetTraceFile(path.c_str(), false) == 0,
+            "SetTraceFile failed");
+#ifdef ANDROID
+    } else {
+      // Intentionally leak this to avoid needing to reason about its lifecycle.
+      // It keeps no state and functions only as a dispatch point.
+      static LogcatTraceContext* g_trace_callback = new LogcatTraceContext();
+    }
+#endif
   }
   talk_base::LogMessage::LogToDebug(nativeSeverity);
 }
diff --git a/app/webrtc/java/src/org/webrtc/Logging.java b/app/webrtc/java/src/org/webrtc/Logging.java
index f6918b8..8b23daf 100644
--- a/app/webrtc/java/src/org/webrtc/Logging.java
+++ b/app/webrtc/java/src/org/webrtc/Logging.java
@@ -65,7 +65,8 @@
   };
 
 
-  // Enable tracing to |path| at |levels| and |severity|.
+  // Enable tracing to |path| of messages of |levels| and |severity|.
+  // On Android, use "logcat:" for |path| to send output there.
   public static void enableTracing(
       String path, EnumSet<TraceLevel> levels, Severity severity) {
     int nativeLevel = 0;
diff --git a/app/webrtc/javatests/src/org/webrtc/PeerConnectionTest.java b/app/webrtc/javatests/src/org/webrtc/PeerConnectionTest.java
index 3d3e6c4..d7380e0 100644
--- a/app/webrtc/javatests/src/org/webrtc/PeerConnectionTest.java
+++ b/app/webrtc/javatests/src/org/webrtc/PeerConnectionTest.java
@@ -478,17 +478,18 @@
 
   @Test
   public void testCompleteSession() throws Exception {
-    // Uncomment to get ALL WebRTC tracing and SENSITIVE libjingle logging.
-    // Logging.enableTracing(
-    //     "/tmp/PeerConnectionTest-log.txt",
-    //     EnumSet.of(Logging.TraceLevel.TRACE_ALL),
-    //     Logging.Severity.LS_SENSITIVE);
-
     CountDownLatch testDone = new CountDownLatch(1);
     System.gc();  // Encourage any GC-related threads to start up.
     TreeSet<String> threadsBeforeTest = allThreads();
 
     PeerConnectionFactory factory = new PeerConnectionFactory();
+    // Uncomment to get ALL WebRTC tracing and SENSITIVE libjingle logging.
+    // NOTE: this _must_ happen while |factory| is alive!
+    // Logging.enableTracing(
+    //     "/tmp/PeerConnectionTest-log.txt",
+    //     EnumSet.of(Logging.TraceLevel.TRACE_ALL),
+    //     Logging.Severity.LS_SENSITIVE);
+
     MediaConstraints pcConstraints = new MediaConstraints();
     pcConstraints.mandatory.add(
         new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));
diff --git a/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java b/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java
index 7c673d8..b89e9ac 100644
--- a/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java
+++ b/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java
@@ -104,12 +104,6 @@
           }
         });
 
-    // Uncomment to get ALL WebRTC tracing and SENSITIVE libjingle logging.
-    // Logging.enableTracing(
-    //     "/sdcard/trace.txt",
-    //     EnumSet.of(Logging.TraceLevel.TRACE_ALL),
-    //     Logging.Severity.LS_SENSITIVE);
-
     PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
     wakeLock = powerManager.newWakeLock(
         PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "AppRTCDemo");
@@ -191,6 +185,13 @@
     pc = factory.createPeerConnection(
         iceServers, appRtcClient.pcConstraints(), pcObserver);
 
+    // Uncomment to get ALL WebRTC tracing and SENSITIVE libjingle logging.
+    // NOTE: this _must_ happen while |factory| is alive!
+    // Logging.enableTracing(
+    //     "logcat:",
+    //     EnumSet.of(Logging.TraceLevel.TRACE_ALL),
+    //     Logging.Severity.LS_SENSITIVE);
+
     {
       final PeerConnection finalPC = pc;
       final Runnable repeatedStatsLogger = new Runnable() {