Allow app zygote to keep APK / shared libs open across fork.
It appears that a recent change in ART causes the application APK to be
held open as a file descriptor as soon as the class loader for that
application is instantiated. This creates issues for the application
zygote, which pre-creates the class loader and forks later. For now,
allow the app APK and shared libs to be open as file descriptors when
forking.
Bug: 111434506
Test: atest CtsApptestCases:ServiceTest
Change-Id: I5f3f4fb41a037362b4f0999ddd20402cbe56f025
diff --git a/core/java/com/android/internal/os/Zygote.java b/core/java/com/android/internal/os/Zygote.java
index 069413f..1190709 100644
--- a/core/java/com/android/internal/os/Zygote.java
+++ b/core/java/com/android/internal/os/Zygote.java
@@ -20,6 +20,7 @@
import static com.android.internal.os.ZygoteConnectionConstants.MAX_ZYGOTE_ARGC;
+import android.content.pm.ApplicationInfo;
import android.net.Credentials;
import android.net.LocalServerSocket;
import android.net.LocalSocket;
@@ -372,6 +373,27 @@
protected static native void nativeAllowFileAcrossFork(String path);
/**
+ * Lets children of the zygote inherit open file descriptors that belong to the
+ * ApplicationInfo that is passed in.
+ *
+ * @param appInfo ApplicationInfo of the application
+ */
+ protected static void allowAppFilesAcrossFork(ApplicationInfo appInfo) {
+ Zygote.nativeAllowFileAcrossFork(appInfo.sourceDir);
+ if (appInfo.splitSourceDirs != null) {
+ for (String path : appInfo.splitSourceDirs) {
+ Zygote.nativeAllowFileAcrossFork(path);
+ }
+ }
+ // As well as its shared libs
+ if (appInfo.sharedLibraryFiles != null) {
+ for (String path : appInfo.sharedLibraryFiles) {
+ Zygote.nativeAllowFileAcrossFork(path);
+ }
+ }
+ }
+
+ /**
* Installs a seccomp filter that limits setresuid()/setresgid() to the passed-in range
* @param uidGidMin The smallest allowed uid/gid
* @param uidGidMax The largest allowed uid/gid