Skip to content

Commit

Permalink
Switch SoLoader implementation to use NativeLoader
Browse files Browse the repository at this point in the history
Summary:
Changed the way .so's are loaded.
Using the NativeLoader which takes in a delegate and requires init on app start. Existing SoLoader init already calls NativeLoader init.
Oculus apps can now call NativeLoader init directly with the provided SystemDelegate.
This now enabled us to remove the SoLoader dep for all oculus apps.

Reviewed By: swiftcoder

Differential Revision: D20301277

fbshipit-source-id: 43a1fb69c9a7161d5cd0d1180c382b1bffa6463a
  • Loading branch information
Bhavin Modi authored and facebook-github-bot committed Mar 21, 2020
1 parent 21071b4 commit 47b5b4c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
11 changes: 11 additions & 0 deletions java/com/facebook/soloader/NativeLoaderToSoLoaderDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,22 @@
package com.facebook.soloader;

import com.facebook.soloader.nativeloader.NativeLoaderDelegate;
import java.io.IOException;

/** Class that connects SoLoader to NativeLoader */
public class NativeLoaderToSoLoaderDelegate implements NativeLoaderDelegate {
@Override
public boolean loadLibrary(final String shortName) {
return SoLoader.loadLibrary(shortName);
}

@Override
public String getLibraryPath(String libName) throws IOException {
return SoLoader.getLibraryPath(libName);
}

@Override
public int getSoSourcesVersion() {
return SoLoader.getSoSourcesVersion();
}
}
39 changes: 39 additions & 0 deletions java/com/facebook/soloader/nativeloader/NativeLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.facebook.soloader.nativeloader;

import java.io.IOException;

/** Facade to load native libraries for android */
public class NativeLoader {

Expand Down Expand Up @@ -44,6 +46,43 @@ public static boolean loadLibrary(String shortName) {
return sDelegate.loadLibrary(shortName);
}

/**
* Get the path of a loaded shared library.
*
* @param shortName Name of library to find, without "lib" prefix or ".so" suffix
* @return The path for the loaded library, null otherwise.
*/
public static String getLibraryPath(String shortName) throws IOException {
synchronized (NativeLoader.class) {
if (sDelegate == null) {
throw new IllegalStateException(
"NativeLoader has not been initialized. "
+ "To use standard native library loading, call "
+ "NativeLoader.init(new SystemDelegate()).");
}
}

return sDelegate.getLibraryPath(shortName);
}

/**
* Get the version of the loader used.
*
* @return The version number for the loader.
*/
public static int getSoSourcesVersion() {
synchronized (NativeLoader.class) {
if (sDelegate == null) {
throw new IllegalStateException(
"NativeLoader has not been initialized. "
+ "To use standard native library loading, call "
+ "NativeLoader.init(new SystemDelegate()).");
}
}

return sDelegate.getSoSourcesVersion();
}

/**
* Initializes native code loading for this app. Should be called only once, before any calls to
* {@link #loadLibrary(String)}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@

package com.facebook.soloader.nativeloader;

import java.io.IOException;

/** Interface used to connect chosen loader of native libraries to NativeLoader */
public interface NativeLoaderDelegate {
/** @see com.facebook.soloader.nativeloader.NativeLoader#loadLibrary(String) */
boolean loadLibrary(String shortName);
/** @see com.facebook.soloader.nativeloader.NativeLoader#getLibraryPath(String) */
String getLibraryPath(String libName) throws IOException;
/** @see com.facebook.soloader.nativeloader.NativeLoader#getSoSourcesVersion() */
int getSoSourcesVersion();
}
10 changes: 10 additions & 0 deletions java/com/facebook/soloader/nativeloader/SystemDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ public boolean loadLibrary(final String shortName) {
// so let's just always assume it was.
return true;
}

@Override
public String getLibraryPath(String libName) {
return null;
}

@Override
public int getSoSourcesVersion() {
return 0;
}
}

0 comments on commit 47b5b4c

Please sign in to comment.