Skip to content

Commit

Permalink
Load libs from splits by path
Browse files Browse the repository at this point in the history
Summary: [If a library is located under one of the standard paths (for example it is located directly under base.apk!/lib/arm64/ directory) then it can be loaded via path](https://cs.android.com/android/platform/superproject/main/+/main:bionic/linker/linker_namespaces.cpp;l=50). As a result we don't need to load libs by name when the app is installed on sd-card.

Reviewed By: adicatana

Differential Revision: D56573273

fbshipit-source-id: 9b8e485c9742ef1fac93f7a5695bc83792d0588d
  • Loading branch information
michalgr authored and facebook-github-bot committed May 1, 2024
1 parent dc3fbfc commit d0b7b23
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 100 deletions.
32 changes: 17 additions & 15 deletions java/com/facebook/soloader/DirectSplitSoSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.facebook.soloader;

import android.annotation.SuppressLint;
import android.os.Build;
import android.os.StrictMode;
import java.io.File;
Expand All @@ -25,7 +26,7 @@
import java.util.Set;
import javax.annotation.Nullable;

public abstract class DirectSplitSoSource extends SoSource {
public class DirectSplitSoSource extends SoSource {
protected final String mSplitName;

protected @Nullable Manifest mManifest = null;
Expand All @@ -35,19 +36,6 @@ public DirectSplitSoSource(String splitName) {
mSplitName = splitName;
}

public DirectSplitSoSource(String splitName, Manifest manifest) {
mSplitName = splitName;
mManifest = manifest;
mLibs = new HashSet<String>(manifest.libs);
}

public DirectSplitSoSource(
String splitName, @Nullable Manifest manifest, @Nullable Set<String> libs) {
mSplitName = splitName;
mManifest = manifest;
mLibs = libs;
}

Manifest getManifest() {
if (mManifest == null) {
throw new IllegalStateException("prepare not called");
Expand Down Expand Up @@ -78,7 +66,16 @@ public int loadLibrary(String soName, int loadFlags, StrictMode.ThreadPolicy thr
return LOAD_RESULT_NOT_FOUND;
}

protected abstract int loadLibraryImpl(String soName, int loadFlags);
@SuppressLint("MissingSoLoaderLibrary")
protected int loadLibraryImpl(String soName, int loadFlags) {
@Nullable String path = getLibraryPath(soName);
if (path == null) {
throw new NullPointerException();
}

System.load(path);
return LOAD_RESULT_LOADED;
}

@Override
@Nullable
Expand Down Expand Up @@ -154,4 +151,9 @@ public String[] getSoSourceAbis() {
}
return new String[] {mManifest.arch};
}

@Override
public String getName() {
return "DirectSplitSoSource";
}
}
44 changes: 0 additions & 44 deletions java/com/facebook/soloader/DirectSplitSoSourceLoadByName.java

This file was deleted.

40 changes: 0 additions & 40 deletions java/com/facebook/soloader/DirectSplitSoSourceLoadByPath.java

This file was deleted.

2 changes: 1 addition & 1 deletion java/com/facebook/soloader/SoLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private static void initSoSources(Context context, int flags) throws IOException
addSystemLoadWrapperSoSource(context, soSources);
} else if (isEnabledBaseApkSplitSource) {
addSystemLibSoSource(soSources);
soSources.add(0, new DirectSplitSoSourceLoadByName("base"));
soSources.add(0, new DirectSplitSoSource("base"));
} else {
addSystemLibSoSource(soSources);

Expand Down

0 comments on commit d0b7b23

Please sign in to comment.