Skip to content

Commit

Permalink
Adding annotations on Success or Fail for each library load
Browse files Browse the repository at this point in the history
Summary:
The purpose of this diff is to add annotations when a library is loaded for the first time, false if else.

Also added the necessary tests after these changes

Differential Revision:
D57977300

Privacy Context Container: L1138447

fbshipit-source-id: c84cdd0730338d5d29bae3f981df713ed8acdc37
  • Loading branch information
Jerry Yan authored and facebook-github-bot committed Jun 4, 2024
1 parent d0b7b23 commit 7ccbe20
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
21 changes: 15 additions & 6 deletions java/com/facebook/soloader/SoLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -793,14 +793,17 @@ private static boolean loadLibraryOnAndroid(String shortName, int loadFlags) {
String mergedLibName = MergedSoMapping.mapLibName(shortName);
String soName = mergedLibName != null ? mergedLibName : shortName;
ObserverHolder.onLoadLibraryStart(shortName, mergedLibName, loadFlags);
boolean wasLoaded = false;
try {
return loadLibraryBySoName(
System.mapLibraryName(soName), shortName, mergedLibName, loadFlags, null);
wasLoaded =
loadLibraryBySoName(
System.mapLibraryName(soName), shortName, mergedLibName, loadFlags, null);
return wasLoaded;
} catch (Throwable t) {
failure = t;
throw t;
} finally {
ObserverHolder.onLoadLibraryEnd(failure);
ObserverHolder.onLoadLibraryEnd(failure, wasLoaded);
}
}

Expand Down Expand Up @@ -851,14 +854,20 @@ private static boolean loadLibraryOnAndroid(String shortName, int loadFlags) {
String soName, int loadFlags, StrictMode.ThreadPolicy oldPolicy) {
@Nullable Throwable failure = null;
ObserverHolder.onLoadDependencyStart(soName, loadFlags);
boolean wasLoaded = false;
try {
loadLibraryBySoNameImpl(
soName, null, null, loadFlags | SoSource.LOAD_FLAG_ALLOW_IMPLICIT_PROVISION, oldPolicy);
wasLoaded =
loadLibraryBySoNameImpl(
soName,
null,
null,
loadFlags | SoSource.LOAD_FLAG_ALLOW_IMPLICIT_PROVISION,
oldPolicy);
} catch (Throwable t) {
failure = t;
throw t;
} finally {
ObserverHolder.onLoadDependencyEnd(failure);
ObserverHolder.onLoadDependencyEnd(failure, wasLoaded);
}
}

Expand Down
4 changes: 2 additions & 2 deletions java/com/facebook/soloader/observer/Observer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
public interface Observer {
void onLoadLibraryStart(String library, @Nullable String mergedLibrary, int flags);

void onLoadLibraryEnd(@Nullable Throwable t);
void onLoadLibraryEnd(@Nullable Throwable t, boolean wasLoaded);

void onLoadDependencyStart(String library, int flags);

void onLoadDependencyEnd(@Nullable Throwable t);
void onLoadDependencyEnd(@Nullable Throwable t, boolean wasLoaded);

void onSoSourceLoadLibraryStart(SoSource source);

Expand Down
8 changes: 4 additions & 4 deletions java/com/facebook/soloader/observer/ObserverHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public static void onLoadLibraryStart(String library, @Nullable String mergedLib
}
}

public static void onLoadLibraryEnd(@Nullable Throwable t) {
public static void onLoadLibraryEnd(@Nullable Throwable t, boolean wasLoaded) {
Observer[] observers = sObservers.get();
if (observers != null) {
for (Observer observer : observers) {
observer.onLoadLibraryEnd(t);
observer.onLoadLibraryEnd(t, wasLoaded);
}
}
}
Expand All @@ -72,11 +72,11 @@ public static void onLoadDependencyStart(String library, int flags) {
}
}

public static void onLoadDependencyEnd(@Nullable Throwable t) {
public static void onLoadDependencyEnd(@Nullable Throwable t, boolean wasLoaded) {
Observer[] observers = sObservers.get();
if (observers != null) {
for (Observer observer : observers) {
observer.onLoadDependencyEnd(t);
observer.onLoadDependencyEnd(t, wasLoaded);
}
}
}
Expand Down

0 comments on commit 7ccbe20

Please sign in to comment.