summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-10-13 10:21:24 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-10-13 11:46:41 +0200
commit749efcde21975bc000da0a8d56c5bd52f9f54443 (patch)
treec1cc320a470bf5caa0bc53229f76139fbf0f2cf1 /app/src/main/java
parent3af2420da9d3b1ee4ba4991b51072e939185c0ae (diff)
SharedLibraryLoader: iterate through all apks for bundles
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java71
1 files changed, 41 insertions, 30 deletions
diff --git a/app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java b/app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java
index 6a9d530f..f3816939 100644
--- a/app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java
+++ b/app/src/main/java/com/wireguard/android/util/SharedLibraryLoader.java
@@ -13,6 +13,9 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -32,40 +35,48 @@ public final class SharedLibraryLoader {
noAbiException = e;
}
- final ZipFile zipFile;
- try {
- zipFile = new ZipFile(new File(context.getApplicationInfo().sourceDir), ZipFile.OPEN_READ);
- } catch (final IOException e) {
- throw new RuntimeException(e);
- }
+ final Collection<String> apks = new HashSet<>();
+ if (context.getApplicationInfo().sourceDir != null)
+ apks.add(context.getApplicationInfo().sourceDir);
+ if (context.getApplicationInfo().splitSourceDirs != null)
+ apks.addAll(Arrays.asList(context.getApplicationInfo().splitSourceDirs));
- final String mappedLibName = System.mapLibraryName(libName);
- final byte[] buffer = new byte[1024 * 32];
- for (final String abi : Build.SUPPORTED_ABIS) {
- final String libZipPath = "lib" + File.separatorChar + abi + File.separatorChar + mappedLibName;
- final ZipEntry zipEntry = zipFile.getEntry(libZipPath);
- if (zipEntry == null)
- continue;
- File f = null;
+ for (final String apk : apks) {
+ final ZipFile zipFile;
try {
- f = File.createTempFile("lib", ".so", context.getCacheDir());
- Log.d(TAG, "Extracting apk:/" + libZipPath + " to " + f.getAbsolutePath() + " and loading");
- try (final FileOutputStream out = new FileOutputStream(f);
- final InputStream in = zipFile.getInputStream(zipEntry)) {
- int len;
- while ((len = in.read(buffer)) != -1) {
- out.write(buffer, 0, len);
+ zipFile = new ZipFile(new File(apk), ZipFile.OPEN_READ);
+ } catch (final IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ final String mappedLibName = System.mapLibraryName(libName);
+ final byte[] buffer = new byte[1024 * 32];
+ for (final String abi : Build.SUPPORTED_ABIS) {
+ final String libZipPath = "lib" + File.separatorChar + abi + File.separatorChar + mappedLibName;
+ final ZipEntry zipEntry = zipFile.getEntry(libZipPath);
+ if (zipEntry == null)
+ continue;
+ File f = null;
+ try {
+ f = File.createTempFile("lib", ".so", context.getCacheDir());
+ Log.d(TAG, "Extracting apk:/" + libZipPath + " to " + f.getAbsolutePath() + " and loading");
+ try (final FileOutputStream out = new FileOutputStream(f);
+ final InputStream in = zipFile.getInputStream(zipEntry)) {
+ int len;
+ while ((len = in.read(buffer)) != -1) {
+ out.write(buffer, 0, len);
+ }
}
+ System.load(f.getAbsolutePath());
+ return;
+ } catch (final Exception e) {
+ Log.d(TAG, "Failed to load library apk:/" + libZipPath, e);
+ noAbiException = e;
+ } finally {
+ if (f != null)
+ // noinspection ResultOfMethodCallIgnored
+ f.delete();
}
- System.load(f.getAbsolutePath());
- return;
- } catch (final Exception e) {
- Log.d(TAG, "Failed to load library apk:/" + libZipPath, e);
- noAbiException = e;
- } finally {
- if (f != null)
- // noinspection ResultOfMethodCallIgnored
- f.delete();
}
}
if (noAbiException instanceof RuntimeException)