From 9dc6a21ba7b373d51c9540f42def5037371a8ff1 Mon Sep 17 00:00:00 2001 From: Felka Chang Date: Wed, 28 Jul 2021 09:23:04 +0800 Subject: [PATCH] Post tasks back to PackageInstaller thread When PackageManagerService return the verification result back to PackageInstallerSession, PackageInstallerSession use PackageManagerService's worker thread to generate the install parameter. When the verification tasks are completed, PackageInstaller's worker thread should execute the following tasks. This patch should make the benchmark better if PackageManagerService's worker thread is busy. The benchmark reports that to post runnable is faster than the original Test: TID="PackageManagerPerfTests" ; \ atest \ ${TID}:android.content.pm.PackageInstallerBenchmark Bug: 194755410 Change-Id: I0e9b123b999dc3f908819ee40850397a1f3fd9e0 --- .../android/server/pm/PackageInstallerSession.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java index fdbcf850cbbd5..3d63dcf7868ff 100644 --- a/services/core/java/com/android/server/pm/PackageInstallerSession.java +++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java @@ -2615,11 +2615,13 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { @Override public void onPackageInstalled(String basePackageName, int returnCode, String msg, Bundle extras) { - if (returnCode == INSTALL_SUCCEEDED) { - onVerificationComplete(); - } else { - onSessionVerificationFailure(returnCode, msg); - } + mHandler.post(() -> { + if (returnCode == INSTALL_SUCCEEDED) { + onVerificationComplete(); + } else { + onSessionVerificationFailure(returnCode, msg); + } + }); } }; } else { @@ -2639,6 +2641,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { mInstallSource, mInstallerUid, mSigningDetails, sessionId, mPackageLite, mPm); } + @WorkerThread private void onVerificationComplete() { // APK verification is done. Continue the installation depending on whether it is a // staged session or not. For a staged session, we will hand it over to the staging