Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09c17528 authored by TYM Tsai's avatar TYM Tsai
Browse files

Move the logic of extracting native libraries out of the io thread

This unblocks the android.io thread and provides an opportunity to
allow other tasks to execute on android.io without waiting too long
for the native library extract to complete.

Bug: 393698598
Flag: EXEMPT fix bug
Test: atest CtsPackageInstallTestCases
Test: atest CtsPackageManagerTestCases
Change-Id: I4f00a08882fe2484760a9cddbf594aed38f93d62
parent f3a349d9
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -212,7 +212,6 @@ import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.Preconditions;
import com.android.modules.utils.TypedXmlPullParser;
import com.android.modules.utils.TypedXmlSerializer;
import com.android.server.IoThread;
import com.android.server.LocalServices;
import com.android.server.Watchdog;
import com.android.server.art.ArtManagedInstallFileHelper;
@@ -247,6 +246,7 @@ import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
@@ -3185,7 +3185,19 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    }

    private void runExtractNativeLibraries() {
        IoThread.getHandler().post(() -> {
        // We create a new thread for this operation instead of using the shared `IoThread`
        // because native library extraction can be a long-running I/O-intensive task.
        // Using a dedicated thread prevents blocking other critical system operations that
        // rely on the `IoThread`.
        final Executor highPriorityExecutor = runnable -> {
            Thread t = new Thread(() -> {
                android.os.Process.setThreadPriority(
                        android.os.Process.THREAD_PRIORITY_FOREGROUND);
                runnable.run();
            }, "extractNativeLibraries");
            t.start();
        };
        CompletableFuture.runAsync(() -> {
            try {
                synchronized (mMetrics) {
                    mMetrics.onNativeLibExtractionStarted();
@@ -3215,7 +3227,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                    mMetrics.onNativeLibExtractionFinished();
                }
            }
        });
        }, highPriorityExecutor);
    }

    /**