Allow passing in a custom native library loader.
All previous initialize methods are deprecated and a new initialize that uses a builder pattern is added. This gives us full control over the order of initialization. Bug: webrtc:7474 Change-Id: I006190e50f2e75c5015f0be75b86d367676db2cc Reviewed-on: https://webrtc-review.googlesource.com/4160 Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20037}
This commit is contained in:

committed by
Commit Bot

parent
7bcfc3b232
commit
5cd1cfb7c4
@ -23,17 +23,13 @@ public class ContextUtils {
|
||||
|
||||
/**
|
||||
* Stores the application context that will be returned by getApplicationContext. This is called
|
||||
* by PeerConnectionFactory.initializeAndroidGlobals.
|
||||
* by PeerConnectionFactory.initialize. The application context must be set before creating
|
||||
* a PeerConnectionFactory and must not be modified while it is alive.
|
||||
*/
|
||||
public static void initialize(Context applicationContext) {
|
||||
if (ContextUtils.applicationContext != null) {
|
||||
// TODO(sakal): Re-enable after the migration period.
|
||||
// throw new RuntimeException("Multiple ContextUtils.initialize calls.");
|
||||
Logging.e(
|
||||
TAG, "Calling ContextUtils.initialize multiple times, this will crash in the future!");
|
||||
}
|
||||
if (applicationContext == null) {
|
||||
throw new RuntimeException("Application context cannot be null for ContextUtils.initialize.");
|
||||
throw new IllegalArgumentException(
|
||||
"Application context cannot be null for ContextUtils.initialize.");
|
||||
}
|
||||
ContextUtils.applicationContext = applicationContext;
|
||||
}
|
||||
|
@ -30,8 +30,6 @@ public class Logging {
|
||||
private static final Logger fallbackLogger = createFallbackLogger();
|
||||
private static volatile boolean tracingEnabled;
|
||||
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");
|
||||
@ -39,19 +37,6 @@ 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;
|
||||
}
|
||||
|
||||
// Keep in sync with webrtc/common_types.h:TraceLevel.
|
||||
public enum TraceLevel {
|
||||
TRACE_NONE(0x0000),
|
||||
@ -80,19 +65,10 @@ 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();
|
||||
}
|
||||
|
||||
@ -100,11 +76,6 @@ public class Logging {
|
||||
// On Android, use "logcat:" for |path| to send output there.
|
||||
// Note: this function controls the output of the WEBRTC_TRACE() macros.
|
||||
public static synchronized void enableTracing(String path, EnumSet<TraceLevel> levels) {
|
||||
if (!loadNativeLibrary()) {
|
||||
fallbackLogger.log(Level.WARNING, "Cannot enable tracing because native lib not loaded.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (tracingEnabled) {
|
||||
return;
|
||||
}
|
||||
@ -120,10 +91,6 @@ public class Logging {
|
||||
// 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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user