Skip to content

Commit

Permalink
Fix crash for 4.1 devices
Browse files Browse the repository at this point in the history
Summary:
4.1 devices are crashing pretty bad i.e. right after login is complete, making app pretty useless.

Following a lead on what could be going on here.

Reviewed By: oprisnik

Differential Revision: D20577707

fbshipit-source-id: 29aafcc26230904a487d1f8595d1b222744f721f
  • Loading branch information
aay-gup authored and facebook-github-bot committed Mar 24, 2020
1 parent ad0e3bf commit 6dce279
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
/** Class that connects SoLoader to NativeLoader */
public class NativeLoaderToSoLoaderDelegate implements NativeLoaderDelegate {
@Override
public boolean loadLibrary(final String shortName) {
return SoLoader.loadLibrary(shortName);
public boolean loadLibrary(String shortName, int flags) {
int soLoaderFlags = 0;
soLoaderFlags |=
((flags & SKIP_MERGED_JNI_ONLOAD) != 0) ? SoLoader.SOLOADER_SKIP_MERGED_JNI_ONLOAD : 0;
return SoLoader.loadLibrary(shortName, soLoaderFlags);
}

@Override
Expand Down
13 changes: 9 additions & 4 deletions java/com/facebook/soloader/nativeloader/NativeLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ public class NativeLoader {
/** Blocked default constructor */
private NativeLoader() {}

public static boolean loadLibrary(String shortName) {
return loadLibrary(shortName, 0);
}

/**
* Load a shared library, initializing any JNI binding it contains.
* Load a shared library, initializing any JNI binding it contains. Depending upon underlying
* loader, behavior can be customized based on passed in flag
*
* @param shortName Name of library to find, without "lib" prefix or ".so" suffix
* @param flags 0 for default behavior, otherwise NativeLoaderDelegate defines other behaviors.
* @return Whether the library was loaded as a result of this call (true), or was already loaded
* through a previous call (false).
*/
public static boolean loadLibrary(String shortName) {
public static boolean loadLibrary(String shortName, int flags) {
synchronized (NativeLoader.class) {
if (sDelegate == null) {
throw new IllegalStateException(
Expand All @@ -42,8 +48,7 @@ public static boolean loadLibrary(String shortName) {
+ "NativeLoader.init(new SystemDelegate()).");
}
}

return sDelegate.loadLibrary(shortName);
return sDelegate.loadLibrary(shortName, flags);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@

/** 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);
/**
* Skip calling JNI_OnLoad if the library is merged. This is necessary for libraries that don't
* define JNI_OnLoad and are only loaded for their side effects (like static constructors
* registering callbacks). DO NOT use this to allow implicit JNI registration (by naming your
* methods Java_com_facebook_whatever) because that is buggy on Android.
*/
int SKIP_MERGED_JNI_ONLOAD = 1;
/** @see com.facebook.soloader.nativeloader.NativeLoader#loadLibrary(String, int) */
boolean loadLibrary(String shortName, int flags);
/** @see com.facebook.soloader.nativeloader.NativeLoader#getLibraryPath(String) */
String getLibraryPath(String libName) throws IOException;
/** @see com.facebook.soloader.nativeloader.NativeLoader#getSoSourcesVersion() */
Expand Down
3 changes: 2 additions & 1 deletion java/com/facebook/soloader/nativeloader/SystemDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
/** Class which connects system's native library loader to NativeLoader */
public class SystemDelegate implements NativeLoaderDelegate {
@Override
public boolean loadLibrary(final String shortName) {
public boolean loadLibrary(String shortName, int flags) {
// System.loadLibrary don't support flags so ignore them.
System.loadLibrary(shortName);
// System.loadLibrary doesn't indicate whether this was a first-time load,
// so let's just always assume it was.
Expand Down

0 comments on commit 6dce279

Please sign in to comment.