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

Commit 2a7a09dc authored by TYM Tsai's avatar TYM Tsai Committed by Android (Google) Code Review
Browse files

Merge "Move the logic of extracting native libraries out of the io thread" into main

parents 2e97644b 09c17528
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -213,7 +213,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;
@@ -249,6 +248,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;
@@ -3189,7 +3189,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();
@@ -3219,7 +3231,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                    mMetrics.onNativeLibExtractionFinished();
                }
            }
        });
        }, highPriorityExecutor);
    }

    /**