diff --git a/java/com/facebook/soloader/SoLoader.java b/java/com/facebook/soloader/SoLoader.java index 2b6f5ba..b3573b4 100644 --- a/java/com/facebook/soloader/SoLoader.java +++ b/java/com/facebook/soloader/SoLoader.java @@ -149,6 +149,8 @@ public class SoLoader { @GuardedBy("sSoSourcesLock") private static int sFlags; + private static boolean isSystemApp; + static { boolean shouldSystrace = false; try { @@ -177,6 +179,7 @@ private static void init(Context context, int flags, @Nullable SoFileLoader soFi throws IOException { StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); try { + isSystemApp = checkIfSystemApp(context); initSoLoader(soFileLoader); initSoSources(context, flags, soFileLoader); } finally { @@ -239,12 +242,8 @@ private static void initSoSources(Context context, int flags, @Nullable SoFileLo Log.d(TAG, "adding exo package source: " + SO_STORE_NAME_MAIN); soSources.add(0, new ExoSoSource(context, SO_STORE_NAME_MAIN)); } else { - ApplicationInfo applicationInfo = context.getApplicationInfo(); - boolean isSystemApplication = - (applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 - && (applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0; int apkSoSourceFlags; - if (isSystemApplication) { + if (isSystemApp) { apkSoSourceFlags = 0; } else { apkSoSourceFlags = ApkSoSource.PREFER_ANDROID_LIBS_DIRECTORY; @@ -429,6 +428,13 @@ private static Method getNativeLoadRuntimeMethod() { } } + private static boolean checkIfSystemApp(Context context) { + return (context != null) + && (context.getApplicationInfo().flags + & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) + != 0; + } + /** Turn shared-library loading into a no-op. Useful in special circumstances. */ public static void setInTestMode() { setSoSources(new SoSource[] {new NoopSoSource()}); @@ -545,6 +551,13 @@ public static boolean loadLibrary(String shortName, int loadFlags) throws Unsati sSoSourcesLock.readLock().unlock(); } + // This is to account for the fact that we want to load .so files from the apk itself when it is + // a system app. + if (isSystemApp && sSystemLoadLibraryWrapper != null) { + sSystemLoadLibraryWrapper.loadLibrary(shortName); + return true; + } + String mergedLibName = MergedSoMapping.mapLibName(shortName); String soName = mergedLibName != null ? mergedLibName : shortName;