From c177168d1e5df4c8683d13d065ea8d27f32b7d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Kalliom=C3=A4ki?= Date: Wed, 4 Oct 2017 23:23:42 +0200 Subject: [PATCH] Add back loading native library in Logging.java. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some applications enable logging before using PeerConnectionFactory. Not loading native library in Logging.java broke these applications. TBR=magjed@webrtc.org Bug: webrtc:7474, b/67419105 Change-Id: I5984d2241cfb76e0edb5b5da0974c8693bf50603 Reviewed-on: https://webrtc-review.googlesource.com/6600 Reviewed-by: Sami Kalliomäki Commit-Queue: Sami Kalliomäki Cr-Commit-Position: refs/heads/master@{#20151} --- rtc_base/java/src/org/webrtc/Logging.java | 31 +++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/rtc_base/java/src/org/webrtc/Logging.java b/rtc_base/java/src/org/webrtc/Logging.java index d1cc2f05ac..347d495429 100644 --- a/rtc_base/java/src/org/webrtc/Logging.java +++ b/rtc_base/java/src/org/webrtc/Logging.java @@ -30,6 +30,8 @@ import java.util.logging.Logger; public class Logging { private static final Logger fallbackLogger = createFallbackLogger(); private static volatile boolean loggingEnabled; + private static enum NativeLibStatus { UNINITIALIZED, LOADED, FAILED } + private static volatile NativeLibStatus nativeLibStatus = NativeLibStatus.UNINITIALIZED; private static Logger createFallbackLogger() { final Logger fallbackLogger = Logger.getLogger("org.webrtc.Logging"); @@ -37,6 +39,19 @@ public class Logging { return fallbackLogger; } + private static boolean loadNativeLibrary() { + if (nativeLibStatus == NativeLibStatus.UNINITIALIZED) { + try { + System.loadLibrary("jingle_peerconnection_so"); + nativeLibStatus = NativeLibStatus.LOADED; + } catch (UnsatisfiedLinkError t) { + nativeLibStatus = NativeLibStatus.FAILED; + fallbackLogger.log(Level.WARNING, "Failed to load jingle_peerconnection_so: ", t); + } + } + return nativeLibStatus == NativeLibStatus.LOADED; + } + // TODO(solenberg): Remove once dependent projects updated. @Deprecated public enum TraceLevel { @@ -66,22 +81,34 @@ public class Logging { public enum Severity { LS_SENSITIVE, LS_VERBOSE, LS_INFO, LS_WARNING, LS_ERROR, LS_NONE } public static void enableLogThreads() { + if (!loadNativeLibrary()) { + fallbackLogger.log(Level.WARNING, "Cannot enable log thread because native lib not loaded."); + return; + } nativeEnableLogThreads(); } public static void enableLogTimeStamps() { + if (!loadNativeLibrary()) { + fallbackLogger.log( + Level.WARNING, "Cannot enable log timestamps because native lib not loaded."); + return; + } nativeEnableLogTimeStamps(); } // TODO(solenberg): Remove once dependent projects updated. @Deprecated - public static void enableTracing(String path, EnumSet levels) { - } + public static void enableTracing(String path, EnumSet levels) {} // Enable diagnostic logging for messages of |severity| to the platform debug // output. On Android, the output will be directed to Logcat. // Note: this function starts collecting the output of the LOG() macros. public static synchronized void enableLogToDebugOutput(Severity severity) { + if (!loadNativeLibrary()) { + fallbackLogger.log(Level.WARNING, "Cannot enable logging because native lib not loaded."); + return; + } nativeEnableLogToDebugOutput(severity.ordinal()); loggingEnabled = true; }