From ad0e3bf6d2da31249aba90225778ce68ca85dc21 Mon Sep 17 00:00:00 2001 From: Alex Petrescu Date: Fri, 20 Mar 2020 23:58:24 -0700 Subject: [PATCH] Use OSSDK foreground app information Summary: The OSSDK gives us a better API for getting the current foreground app. It doesn't seem to have the issues of the previous implementation. Differential Revision: D20568949 fbshipit-source-id: e76dda627b66ff4e4f2dd1525de19b225c9a57a9 --- java/com/facebook/soloader/SoLoader.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/java/com/facebook/soloader/SoLoader.java b/java/com/facebook/soloader/SoLoader.java index cfc14fb..de7bc4b 100644 --- a/java/com/facebook/soloader/SoLoader.java +++ b/java/com/facebook/soloader/SoLoader.java @@ -159,6 +159,9 @@ public class SoLoader { */ public static final int SOLOADER_SKIP_MERGED_JNI_ONLOAD = (1 << 4); + /** System Apps ignore PREFER_ANDROID_LIBS_DIRECTORY. Don't do that for this app. */ + public static final int SOLOADER_DONT_TREAT_AS_SYSTEMAPP = (1 << 5); + @GuardedBy("sSoSourcesLock") private static int sFlags; @@ -192,7 +195,7 @@ public static void init(Context context, int flags, @Nullable SoFileLoader soFil throws IOException { StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); try { - isSystemApp = checkIfSystemApp(context); + isSystemApp = checkIfSystemApp(context, flags); initSoLoader(soFileLoader); initSoSources(context, flags, soFileLoader); if (!NativeLoader.isInitialized()) { @@ -444,7 +447,11 @@ private static Method getNativeLoadRuntimeMethod() { } } - private static boolean checkIfSystemApp(Context context) { + private static boolean checkIfSystemApp(Context context, int flags) { + if ((flags & SOLOADER_DONT_TREAT_AS_SYSTEMAPP) != 0) { + return false; + } + return (context != null) && (context.getApplicationInfo().flags & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP))